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 "gtkaccelmap.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;
535 guint use_forall : 1;
538 /* --- prototypes --- */
539 static void gtk_widget_base_class_init (gpointer g_class);
540 static void gtk_widget_class_init (GtkWidgetClass *klass);
541 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
542 static void gtk_widget_init (GtkWidget *widget);
543 static void gtk_widget_set_property (GObject *object,
547 static void gtk_widget_get_property (GObject *object,
551 static void gtk_widget_dispose (GObject *object);
552 static void gtk_widget_real_destroy (GtkWidget *object);
553 static void gtk_widget_finalize (GObject *object);
554 static void gtk_widget_real_show (GtkWidget *widget);
555 static void gtk_widget_real_hide (GtkWidget *widget);
556 static void gtk_widget_real_map (GtkWidget *widget);
557 static void gtk_widget_real_unmap (GtkWidget *widget);
558 static void gtk_widget_real_realize (GtkWidget *widget);
559 static void gtk_widget_real_unrealize (GtkWidget *widget);
560 static void gtk_widget_real_size_allocate (GtkWidget *widget,
561 GtkAllocation *allocation);
562 static void gtk_widget_real_style_set (GtkWidget *widget,
563 GtkStyle *previous_style);
564 static void gtk_widget_real_direction_changed(GtkWidget *widget,
565 GtkTextDirection previous_direction);
567 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
568 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
571 gboolean keyboard_tip,
572 GtkTooltip *tooltip);
573 static void gtk_widget_real_style_updated (GtkWidget *widget);
574 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
575 GtkWidgetHelpType help_type);
577 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
579 GParamSpec **pspecs);
580 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
582 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
584 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
585 GdkEventFocus *event);
586 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
587 GdkEventFocus *event);
588 static gboolean gtk_widget_real_focus (GtkWidget *widget,
589 GtkDirectionType direction);
590 static void gtk_widget_real_move_focus (GtkWidget *widget,
591 GtkDirectionType direction);
592 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
593 GtkDirectionType direction);
594 #ifdef G_ENABLE_DEBUG
595 static void gtk_widget_verify_invariants (GtkWidget *widget);
596 static void gtk_widget_push_verify_invariants (GtkWidget *widget);
597 static void gtk_widget_pop_verify_invariants (GtkWidget *widget);
599 #define gtk_widget_verify_invariants(widget)
600 #define gtk_widget_push_verify_invariants(widget)
601 #define gtk_widget_pop_verify_invariants(widget)
603 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
604 static void gtk_widget_update_pango_context (GtkWidget *widget);
605 static void gtk_widget_propagate_state (GtkWidget *widget,
608 static gint gtk_widget_event_internal (GtkWidget *widget,
610 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
611 gboolean group_cycling);
612 static void gtk_widget_real_get_width (GtkWidget *widget,
615 static void gtk_widget_real_get_height (GtkWidget *widget,
618 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
620 gint *minimum_height,
621 gint *natural_height);
622 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
625 gint *natural_width);
626 static void gtk_widget_real_state_flags_changed (GtkWidget *widget,
627 GtkStateFlags old_state);
628 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
629 static GtkWidgetAuxInfo* gtk_widget_get_aux_info (GtkWidget *widget,
631 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
632 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
633 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
634 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
635 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
636 cairo_region_t *region);
637 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
638 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
639 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
642 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
643 gboolean has_tooltip,
645 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
646 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
648 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
649 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
651 const gchar *childname);
652 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
655 const GValue *value);
656 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
659 const gchar *tagname,
660 GMarkupParser *parser,
662 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
665 const gchar *tagname,
667 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
668 GtkBuilder *builder);
670 static GtkSizeRequestMode gtk_widget_real_get_request_mode (GtkWidget *widget);
671 static void gtk_widget_real_get_width (GtkWidget *widget,
674 static void gtk_widget_real_get_height (GtkWidget *widget,
678 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
681 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
682 GtkOrientation orientation,
685 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
686 GtkOrientation orientation,
690 gint *allocated_size);
692 static void gtk_widget_set_usize_internal (GtkWidget *widget,
695 GtkQueueResizeFlags flags);
697 static void gtk_widget_add_events_internal (GtkWidget *widget,
700 static void gtk_widget_set_device_enabled_internal (GtkWidget *widget,
705 /* --- variables --- */
706 static gpointer gtk_widget_parent_class = NULL;
707 static guint widget_signals[LAST_SIGNAL] = { 0 };
708 static guint composite_child_stack = 0;
709 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
710 static GParamSpecPool *style_property_spec_pool = NULL;
712 static GQuark quark_property_parser = 0;
713 static GQuark quark_aux_info = 0;
714 static GQuark quark_accel_path = 0;
715 static GQuark quark_accel_closures = 0;
716 static GQuark quark_event_mask = 0;
717 static GQuark quark_device_event_mask = 0;
718 static GQuark quark_parent_window = 0;
719 static GQuark quark_pointer_window = 0;
720 static GQuark quark_shape_info = 0;
721 static GQuark quark_input_shape_info = 0;
722 static GQuark quark_pango_context = 0;
723 static GQuark quark_accessible_object = 0;
724 static GQuark quark_mnemonic_labels = 0;
725 static GQuark quark_tooltip_markup = 0;
726 static GQuark quark_has_tooltip = 0;
727 static GQuark quark_tooltip_window = 0;
728 static GQuark quark_visual = 0;
729 static GQuark quark_modifier_style = 0;
730 static GQuark quark_enabled_devices = 0;
731 static GQuark quark_size_groups = 0;
732 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
733 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
735 /* --- functions --- */
737 gtk_widget_get_type (void)
739 static GType widget_type = 0;
741 if (G_UNLIKELY (widget_type == 0))
743 const GTypeInfo widget_info =
745 sizeof (GtkWidgetClass),
746 gtk_widget_base_class_init,
747 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
748 (GClassInitFunc) gtk_widget_class_init,
749 NULL, /* class_finalize */
750 NULL, /* class_init */
753 (GInstanceInitFunc) gtk_widget_init,
754 NULL, /* value_table */
757 const GInterfaceInfo accessibility_info =
759 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
760 (GInterfaceFinalizeFunc) NULL,
761 NULL /* interface data */
764 const GInterfaceInfo buildable_info =
766 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
767 (GInterfaceFinalizeFunc) NULL,
768 NULL /* interface data */
771 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
772 &widget_info, G_TYPE_FLAG_ABSTRACT);
774 g_type_add_class_private (widget_type, sizeof (GtkWidgetClassPrivate));
776 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
777 &accessibility_info) ;
778 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
786 gtk_widget_base_class_init (gpointer g_class)
788 GtkWidgetClass *klass = g_class;
790 klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
794 child_property_notify_dispatcher (GObject *object,
798 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
801 /* We guard against the draw signal callbacks modifying the state of the
802 * cairo context by surounding it with save/restore.
803 * Maybe we should also cairo_new_path() just to be sure?
806 gtk_widget_draw_marshaller (GClosure *closure,
807 GValue *return_value,
808 guint n_param_values,
809 const GValue *param_values,
810 gpointer invocation_hint,
811 gpointer marshal_data)
813 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
817 _gtk_marshal_BOOLEAN__BOXED (closure,
828 gtk_widget_class_init (GtkWidgetClass *klass)
830 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
831 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
832 GtkBindingSet *binding_set;
834 gtk_widget_parent_class = g_type_class_peek_parent (klass);
836 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
837 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
838 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
839 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
840 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
841 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
842 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
843 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
844 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
845 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
846 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
847 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
848 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
849 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
850 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
851 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
852 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
853 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
854 quark_enabled_devices = g_quark_from_static_string ("gtk-widget-enabled-devices");
855 quark_size_groups = g_quark_from_static_string ("gtk-widget-size-groups");
857 style_property_spec_pool = g_param_spec_pool_new (FALSE);
858 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
859 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
860 cpn_context.dispatcher = child_property_notify_dispatcher;
861 _gtk_widget_child_property_notify_context = &cpn_context;
863 gobject_class->dispose = gtk_widget_dispose;
864 gobject_class->finalize = gtk_widget_finalize;
865 gobject_class->set_property = gtk_widget_set_property;
866 gobject_class->get_property = gtk_widget_get_property;
868 klass->destroy = gtk_widget_real_destroy;
870 klass->activate_signal = 0;
871 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
872 klass->show = gtk_widget_real_show;
873 klass->show_all = gtk_widget_show;
874 klass->hide = gtk_widget_real_hide;
875 klass->map = gtk_widget_real_map;
876 klass->unmap = gtk_widget_real_unmap;
877 klass->realize = gtk_widget_real_realize;
878 klass->unrealize = gtk_widget_real_unrealize;
879 klass->size_allocate = gtk_widget_real_size_allocate;
880 klass->get_request_mode = gtk_widget_real_get_request_mode;
881 klass->get_preferred_width = gtk_widget_real_get_width;
882 klass->get_preferred_height = gtk_widget_real_get_height;
883 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
884 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
885 klass->state_changed = NULL;
886 klass->state_flags_changed = gtk_widget_real_state_flags_changed;
887 klass->parent_set = NULL;
888 klass->hierarchy_changed = NULL;
889 klass->style_set = gtk_widget_real_style_set;
890 klass->direction_changed = gtk_widget_real_direction_changed;
891 klass->grab_notify = NULL;
892 klass->child_notify = NULL;
894 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
895 klass->grab_focus = gtk_widget_real_grab_focus;
896 klass->focus = gtk_widget_real_focus;
897 klass->move_focus = gtk_widget_real_move_focus;
898 klass->keynav_failed = gtk_widget_real_keynav_failed;
900 klass->button_press_event = NULL;
901 klass->button_release_event = NULL;
902 klass->motion_notify_event = NULL;
903 klass->delete_event = NULL;
904 klass->destroy_event = NULL;
905 klass->key_press_event = gtk_widget_real_key_press_event;
906 klass->key_release_event = gtk_widget_real_key_release_event;
907 klass->enter_notify_event = NULL;
908 klass->leave_notify_event = NULL;
909 klass->configure_event = NULL;
910 klass->focus_in_event = gtk_widget_real_focus_in_event;
911 klass->focus_out_event = gtk_widget_real_focus_out_event;
912 klass->map_event = NULL;
913 klass->unmap_event = NULL;
914 klass->window_state_event = NULL;
915 klass->property_notify_event = _gtk_selection_property_notify;
916 klass->selection_clear_event = _gtk_selection_clear;
917 klass->selection_request_event = _gtk_selection_request;
918 klass->selection_notify_event = _gtk_selection_notify;
919 klass->selection_received = NULL;
920 klass->proximity_in_event = NULL;
921 klass->proximity_out_event = NULL;
922 klass->drag_begin = NULL;
923 klass->drag_end = NULL;
924 klass->drag_data_delete = NULL;
925 klass->drag_leave = NULL;
926 klass->drag_motion = NULL;
927 klass->drag_drop = NULL;
928 klass->drag_data_received = NULL;
929 klass->screen_changed = NULL;
930 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
931 klass->grab_broken_event = NULL;
932 klass->query_tooltip = gtk_widget_real_query_tooltip;
933 klass->style_updated = gtk_widget_real_style_updated;
935 klass->show_help = gtk_widget_real_show_help;
937 /* Accessibility support */
938 klass->priv->accessible_type = GTK_TYPE_ACCESSIBLE;
939 klass->priv->accessible_role = ATK_ROLE_INVALID;
940 klass->get_accessible = gtk_widget_real_get_accessible;
942 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
943 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
945 g_object_class_install_property (gobject_class,
947 g_param_spec_string ("name",
949 P_("The name of the widget"),
951 GTK_PARAM_READWRITE));
952 g_object_class_install_property (gobject_class,
954 g_param_spec_object ("parent",
956 P_("The parent widget of this widget. Must be a Container widget"),
958 GTK_PARAM_READWRITE));
960 g_object_class_install_property (gobject_class,
962 g_param_spec_int ("width-request",
964 P_("Override for width request of the widget, or -1 if natural request should be used"),
968 GTK_PARAM_READWRITE));
969 g_object_class_install_property (gobject_class,
971 g_param_spec_int ("height-request",
972 P_("Height request"),
973 P_("Override for height request of the widget, or -1 if natural request should be used"),
977 GTK_PARAM_READWRITE));
978 g_object_class_install_property (gobject_class,
980 g_param_spec_boolean ("visible",
982 P_("Whether the widget is visible"),
984 GTK_PARAM_READWRITE));
985 g_object_class_install_property (gobject_class,
987 g_param_spec_boolean ("sensitive",
989 P_("Whether the widget responds to input"),
991 GTK_PARAM_READWRITE));
992 g_object_class_install_property (gobject_class,
994 g_param_spec_boolean ("app-paintable",
995 P_("Application paintable"),
996 P_("Whether the application will paint directly on the widget"),
998 GTK_PARAM_READWRITE));
999 g_object_class_install_property (gobject_class,
1001 g_param_spec_boolean ("can-focus",
1003 P_("Whether the widget can accept the input focus"),
1005 GTK_PARAM_READWRITE));
1006 g_object_class_install_property (gobject_class,
1008 g_param_spec_boolean ("has-focus",
1010 P_("Whether the widget has the input focus"),
1012 GTK_PARAM_READWRITE));
1013 g_object_class_install_property (gobject_class,
1015 g_param_spec_boolean ("is-focus",
1017 P_("Whether the widget is the focus widget within the toplevel"),
1019 GTK_PARAM_READWRITE));
1020 g_object_class_install_property (gobject_class,
1022 g_param_spec_boolean ("can-default",
1024 P_("Whether the widget can be the default widget"),
1026 GTK_PARAM_READWRITE));
1027 g_object_class_install_property (gobject_class,
1029 g_param_spec_boolean ("has-default",
1031 P_("Whether the widget is the default widget"),
1033 GTK_PARAM_READWRITE));
1034 g_object_class_install_property (gobject_class,
1035 PROP_RECEIVES_DEFAULT,
1036 g_param_spec_boolean ("receives-default",
1037 P_("Receives default"),
1038 P_("If TRUE, the widget will receive the default action when it is focused"),
1040 GTK_PARAM_READWRITE));
1041 g_object_class_install_property (gobject_class,
1042 PROP_COMPOSITE_CHILD,
1043 g_param_spec_boolean ("composite-child",
1044 P_("Composite child"),
1045 P_("Whether the widget is part of a composite widget"),
1047 GTK_PARAM_READABLE));
1048 g_object_class_install_property (gobject_class,
1050 g_param_spec_object ("style",
1052 P_("The style of the widget, which contains information about how it will look (colors etc)"),
1054 GTK_PARAM_READWRITE));
1055 g_object_class_install_property (gobject_class,
1057 g_param_spec_flags ("events",
1059 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1060 GDK_TYPE_EVENT_MASK,
1062 GTK_PARAM_READWRITE));
1063 g_object_class_install_property (gobject_class,
1065 g_param_spec_boolean ("no-show-all",
1067 P_("Whether gtk_widget_show_all() should not affect this widget"),
1069 GTK_PARAM_READWRITE));
1072 * GtkWidget:has-tooltip:
1074 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1075 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1076 * the widget will be queried using #GtkWidget::query-tooltip to determine
1077 * whether it will provide a tooltip or not.
1079 * Note that setting this property to %TRUE for the first time will change
1080 * the event masks of the GdkWindows of this widget to include leave-notify
1081 * and motion-notify events. This cannot and will not be undone when the
1082 * property is set to %FALSE again.
1086 g_object_class_install_property (gobject_class,
1088 g_param_spec_boolean ("has-tooltip",
1090 P_("Whether this widget has a tooltip"),
1092 GTK_PARAM_READWRITE));
1094 * GtkWidget:tooltip-text:
1096 * Sets the text of tooltip to be the given string.
1098 * Also see gtk_tooltip_set_text().
1100 * This is a convenience property which will take care of getting the
1101 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1102 * will automatically be set to %TRUE and there will be taken care of
1103 * #GtkWidget::query-tooltip in the default signal handler.
1107 g_object_class_install_property (gobject_class,
1109 g_param_spec_string ("tooltip-text",
1111 P_("The contents of the tooltip for this widget"),
1113 GTK_PARAM_READWRITE));
1115 * GtkWidget:tooltip-markup:
1117 * Sets the text of tooltip to be the given string, which is marked up
1118 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1119 * Also see gtk_tooltip_set_markup().
1121 * This is a convenience property which will take care of getting the
1122 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1123 * will automatically be set to %TRUE and there will be taken care of
1124 * #GtkWidget::query-tooltip in the default signal handler.
1128 g_object_class_install_property (gobject_class,
1129 PROP_TOOLTIP_MARKUP,
1130 g_param_spec_string ("tooltip-markup",
1131 P_("Tooltip markup"),
1132 P_("The contents of the tooltip for this widget"),
1134 GTK_PARAM_READWRITE));
1139 * The widget's window if it is realized, %NULL otherwise.
1143 g_object_class_install_property (gobject_class,
1145 g_param_spec_object ("window",
1147 P_("The widget's window if it is realized"),
1149 GTK_PARAM_READABLE));
1152 * GtkWidget:double-buffered
1154 * Whether the widget is double buffered.
1158 g_object_class_install_property (gobject_class,
1159 PROP_DOUBLE_BUFFERED,
1160 g_param_spec_boolean ("double-buffered",
1161 P_("Double Buffered"),
1162 P_("Whether the widget is double buffered"),
1164 GTK_PARAM_READWRITE));
1169 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1173 g_object_class_install_property (gobject_class,
1175 g_param_spec_enum ("halign",
1176 P_("Horizontal Alignment"),
1177 P_("How to position in extra horizontal space"),
1180 GTK_PARAM_READWRITE));
1185 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1189 g_object_class_install_property (gobject_class,
1191 g_param_spec_enum ("valign",
1192 P_("Vertical Alignment"),
1193 P_("How to position in extra vertical space"),
1196 GTK_PARAM_READWRITE));
1199 * GtkWidget:margin-left
1201 * Margin on left side of widget.
1203 * This property adds margin outside of the widget's normal size
1204 * request, the margin will be added in addition to the size from
1205 * gtk_widget_set_size_request() for example.
1209 g_object_class_install_property (gobject_class,
1211 g_param_spec_int ("margin-left",
1212 P_("Margin on Left"),
1213 P_("Pixels of extra space on the left side"),
1217 GTK_PARAM_READWRITE));
1220 * GtkWidget:margin-right
1222 * Margin on right side of widget.
1224 * This property adds margin outside of the widget's normal size
1225 * request, the margin will be added in addition to the size from
1226 * gtk_widget_set_size_request() for example.
1230 g_object_class_install_property (gobject_class,
1232 g_param_spec_int ("margin-right",
1233 P_("Margin on Right"),
1234 P_("Pixels of extra space on the right side"),
1238 GTK_PARAM_READWRITE));
1241 * GtkWidget:margin-top
1243 * Margin on top side of widget.
1245 * This property adds margin outside of the widget's normal size
1246 * request, the margin will be added in addition to the size from
1247 * gtk_widget_set_size_request() for example.
1251 g_object_class_install_property (gobject_class,
1253 g_param_spec_int ("margin-top",
1254 P_("Margin on Top"),
1255 P_("Pixels of extra space on the top side"),
1259 GTK_PARAM_READWRITE));
1262 * GtkWidget:margin-bottom
1264 * Margin on bottom side of widget.
1266 * This property adds margin outside of the widget's normal size
1267 * request, the margin will be added in addition to the size from
1268 * gtk_widget_set_size_request() for example.
1272 g_object_class_install_property (gobject_class,
1274 g_param_spec_int ("margin-bottom",
1275 P_("Margin on Bottom"),
1276 P_("Pixels of extra space on the bottom side"),
1280 GTK_PARAM_READWRITE));
1285 * Sets all four sides' margin at once. If read, returns max
1286 * margin on any side.
1290 g_object_class_install_property (gobject_class,
1292 g_param_spec_int ("margin",
1294 P_("Pixels of extra space on all four sides"),
1298 GTK_PARAM_READWRITE));
1301 * GtkWidget::destroy:
1302 * @object: the object which received the signal
1304 * Signals that all holders of a reference to the widget should release
1305 * the reference that they hold. May result in finalization of the widget
1306 * if all references are released.
1308 widget_signals[DESTROY] =
1309 g_signal_new (I_("destroy"),
1310 G_TYPE_FROM_CLASS (gobject_class),
1311 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1312 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1314 _gtk_marshal_VOID__VOID,
1320 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1324 g_object_class_install_property (gobject_class,
1326 g_param_spec_boolean ("hexpand",
1327 P_("Horizontal Expand"),
1328 P_("Whether widget wants more horizontal space"),
1330 GTK_PARAM_READWRITE));
1333 * GtkWidget:hexpand-set
1335 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1339 g_object_class_install_property (gobject_class,
1341 g_param_spec_boolean ("hexpand-set",
1342 P_("Horizontal Expand Set"),
1343 P_("Whether to use the hexpand property"),
1345 GTK_PARAM_READWRITE));
1350 * Whether to expand vertically. See gtk_widget_set_vexpand().
1354 g_object_class_install_property (gobject_class,
1356 g_param_spec_boolean ("vexpand",
1357 P_("Vertical Expand"),
1358 P_("Whether widget wants more vertical space"),
1360 GTK_PARAM_READWRITE));
1363 * GtkWidget:vexpand-set
1365 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1369 g_object_class_install_property (gobject_class,
1371 g_param_spec_boolean ("vexpand-set",
1372 P_("Vertical Expand Set"),
1373 P_("Whether to use the vexpand property"),
1375 GTK_PARAM_READWRITE));
1380 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1384 g_object_class_install_property (gobject_class,
1386 g_param_spec_boolean ("expand",
1388 P_("Whether widget wants to expand in both directions"),
1390 GTK_PARAM_READWRITE));
1394 * @widget: the object which received the signal.
1396 widget_signals[SHOW] =
1397 g_signal_new (I_("show"),
1398 G_TYPE_FROM_CLASS (gobject_class),
1400 G_STRUCT_OFFSET (GtkWidgetClass, show),
1402 _gtk_marshal_VOID__VOID,
1407 * @widget: the object which received the signal.
1409 widget_signals[HIDE] =
1410 g_signal_new (I_("hide"),
1411 G_TYPE_FROM_CLASS (gobject_class),
1413 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1415 _gtk_marshal_VOID__VOID,
1420 * @widget: the object which received the signal.
1422 widget_signals[MAP] =
1423 g_signal_new (I_("map"),
1424 G_TYPE_FROM_CLASS (gobject_class),
1426 G_STRUCT_OFFSET (GtkWidgetClass, map),
1428 _gtk_marshal_VOID__VOID,
1433 * @widget: the object which received the signal.
1435 widget_signals[UNMAP] =
1436 g_signal_new (I_("unmap"),
1437 G_TYPE_FROM_CLASS (gobject_class),
1439 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1441 _gtk_marshal_VOID__VOID,
1445 * GtkWidget::realize:
1446 * @widget: the object which received the signal.
1448 widget_signals[REALIZE] =
1449 g_signal_new (I_("realize"),
1450 G_TYPE_FROM_CLASS (gobject_class),
1452 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1454 _gtk_marshal_VOID__VOID,
1458 * GtkWidget::unrealize:
1459 * @widget: the object which received the signal.
1461 widget_signals[UNREALIZE] =
1462 g_signal_new (I_("unrealize"),
1463 G_TYPE_FROM_CLASS (gobject_class),
1465 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1467 _gtk_marshal_VOID__VOID,
1471 * GtkWidget::size-allocate:
1472 * @widget: the object which received the signal.
1475 widget_signals[SIZE_ALLOCATE] =
1476 g_signal_new (I_("size-allocate"),
1477 G_TYPE_FROM_CLASS (gobject_class),
1479 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1481 _gtk_marshal_VOID__BOXED,
1483 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1486 * GtkWidget::state-changed:
1487 * @widget: the object which received the signal.
1488 * @state: the previous state
1490 * The ::state-changed signal is emitted when the widget state changes.
1491 * See gtk_widget_get_state().
1493 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1495 widget_signals[STATE_CHANGED] =
1496 g_signal_new (I_("state-changed"),
1497 G_TYPE_FROM_CLASS (gobject_class),
1499 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1501 _gtk_marshal_VOID__ENUM,
1503 GTK_TYPE_STATE_TYPE);
1506 * GtkWidget::state-flags-changed:
1507 * @widget: the object which received the signal.
1508 * @flags: The previous state flags.
1510 * The ::state-flags-changed signal is emitted when the widget state
1511 * changes, see gtk_widget_get_state_flags().
1515 widget_signals[STATE_FLAGS_CHANGED] =
1516 g_signal_new (I_("state-flags-changed"),
1517 G_TYPE_FROM_CLASS (gobject_class),
1519 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1521 _gtk_marshal_VOID__FLAGS,
1523 GTK_TYPE_STATE_FLAGS);
1526 * GtkWidget::parent-set:
1527 * @widget: the object on which the signal is emitted
1528 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1529 * just got its initial parent.
1531 * The ::parent-set signal is emitted when a new parent
1532 * has been set on a widget.
1534 widget_signals[PARENT_SET] =
1535 g_signal_new (I_("parent-set"),
1536 G_TYPE_FROM_CLASS (gobject_class),
1538 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1540 _gtk_marshal_VOID__OBJECT,
1545 * GtkWidget::hierarchy-changed:
1546 * @widget: the object on which the signal is emitted
1547 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1548 * if the widget was previously unanchored
1550 * The ::hierarchy-changed signal is emitted when the
1551 * anchored state of a widget changes. A widget is
1552 * <firstterm>anchored</firstterm> when its toplevel
1553 * ancestor is a #GtkWindow. This signal is emitted when
1554 * a widget changes from un-anchored to anchored or vice-versa.
1556 widget_signals[HIERARCHY_CHANGED] =
1557 g_signal_new (I_("hierarchy-changed"),
1558 G_TYPE_FROM_CLASS (gobject_class),
1560 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1562 _gtk_marshal_VOID__OBJECT,
1567 * GtkWidget::style-set:
1568 * @widget: the object on which the signal is emitted
1569 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1570 * just got its initial style
1572 * The ::style-set signal is emitted when a new style has been set
1573 * on a widget. Note that style-modifying functions like
1574 * gtk_widget_modify_base() also cause this signal to be emitted.
1576 * Note that this signal is emitted for changes to the deprecated
1577 * #GtkStyle. To track changes to the #GtkStyleContext associated
1578 * with a widget, use the #GtkWidget::style-updated signal.
1580 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1582 widget_signals[STYLE_SET] =
1583 g_signal_new (I_("style-set"),
1584 G_TYPE_FROM_CLASS (gobject_class),
1586 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1588 _gtk_marshal_VOID__OBJECT,
1593 * GtkWidget::style-updated:
1594 * @widget: the object on which the signal is emitted
1596 * The ::style-updated signal is emitted when the #GtkStyleContext
1597 * of a widget is changed. Note that style-modifying functions like
1598 * gtk_widget_override_color() also cause this signal to be emitted.
1602 widget_signals[STYLE_UPDATED] =
1603 g_signal_new (I_("style-updated"),
1604 G_TYPE_FROM_CLASS (gobject_class),
1606 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1608 g_cclosure_marshal_VOID__VOID,
1612 * GtkWidget::direction-changed:
1613 * @widget: the object on which the signal is emitted
1614 * @previous_direction: the previous text direction of @widget
1616 * The ::direction-changed signal is emitted when the text direction
1617 * of a widget changes.
1619 widget_signals[DIRECTION_CHANGED] =
1620 g_signal_new (I_("direction-changed"),
1621 G_TYPE_FROM_CLASS (gobject_class),
1623 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1625 _gtk_marshal_VOID__ENUM,
1627 GTK_TYPE_TEXT_DIRECTION);
1630 * GtkWidget::grab-notify:
1631 * @widget: the object which received the signal
1632 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1633 * if it becomes unshadowed
1635 * The ::grab-notify signal is emitted when a widget becomes
1636 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1637 * another widget, or when it becomes unshadowed due to a grab
1640 * A widget is shadowed by a gtk_grab_add() when the topmost
1641 * grab widget in the grab stack of its window group is not
1644 widget_signals[GRAB_NOTIFY] =
1645 g_signal_new (I_("grab-notify"),
1646 G_TYPE_FROM_CLASS (gobject_class),
1648 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1650 _gtk_marshal_VOID__BOOLEAN,
1655 * GtkWidget::child-notify:
1656 * @widget: the object which received the signal
1657 * @pspec: the #GParamSpec of the changed child property
1659 * The ::child-notify signal is emitted for each
1660 * <link linkend="child-properties">child property</link> that has
1661 * changed on an object. The signal's detail holds the property name.
1663 widget_signals[CHILD_NOTIFY] =
1664 g_signal_new (I_("child-notify"),
1665 G_TYPE_FROM_CLASS (gobject_class),
1666 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1667 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1669 g_cclosure_marshal_VOID__PARAM,
1675 * @widget: the object which received the signal
1676 * @cr: the cairo context to draw to
1678 * This signal is emitted when a widget is supposed to render itself.
1679 * The @widget's top left corner must be painted at the origin of
1680 * the passed in context and be sized to the values returned by
1681 * gtk_widget_get_allocated_width() and
1682 * gtk_widget_get_allocated_height().
1684 * Signal handlers connected to this signal can modify the cairo
1685 * context passed as @cr in any way they like and don't need to
1686 * restore it. The signal emission takes care of calling cairo_save()
1687 * before and cairo_restore() after invoking the handler.
1691 widget_signals[DRAW] =
1692 g_signal_new (I_("draw"),
1693 G_TYPE_FROM_CLASS (gobject_class),
1695 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1696 _gtk_boolean_handled_accumulator, NULL,
1697 gtk_widget_draw_marshaller,
1699 CAIRO_GOBJECT_TYPE_CONTEXT);
1702 * GtkWidget::mnemonic-activate:
1703 * @widget: the object which received the signal.
1706 widget_signals[MNEMONIC_ACTIVATE] =
1707 g_signal_new (I_("mnemonic-activate"),
1708 G_TYPE_FROM_CLASS (gobject_class),
1710 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1711 _gtk_boolean_handled_accumulator, NULL,
1712 _gtk_marshal_BOOLEAN__BOOLEAN,
1717 * GtkWidget::grab-focus:
1718 * @widget: the object which received the signal.
1720 widget_signals[GRAB_FOCUS] =
1721 g_signal_new (I_("grab-focus"),
1722 G_TYPE_FROM_CLASS (gobject_class),
1723 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1724 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1726 _gtk_marshal_VOID__VOID,
1731 * @widget: the object which received the signal.
1734 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1736 widget_signals[FOCUS] =
1737 g_signal_new (I_("focus"),
1738 G_TYPE_FROM_CLASS (klass),
1740 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1741 _gtk_boolean_handled_accumulator, NULL,
1742 _gtk_marshal_BOOLEAN__ENUM,
1744 GTK_TYPE_DIRECTION_TYPE);
1747 * GtkWidget::move-focus:
1748 * @widget: the object which received the signal.
1751 widget_signals[MOVE_FOCUS] =
1752 g_signal_new (I_("move-focus"),
1753 G_TYPE_FROM_CLASS (klass),
1754 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1755 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1757 _gtk_marshal_VOID__ENUM,
1760 GTK_TYPE_DIRECTION_TYPE);
1763 * GtkWidget::keynav-failed:
1764 * @widget: the object which received the signal
1765 * @direction: the direction of movement
1767 * Gets emitted if keyboard navigation fails.
1768 * See gtk_widget_keynav_failed() for details.
1770 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1771 * if the emitting widget should try to handle the keyboard
1772 * navigation attempt in its parent container(s).
1776 widget_signals[KEYNAV_FAILED] =
1777 g_signal_new (I_("keynav-failed"),
1778 G_TYPE_FROM_CLASS (klass),
1780 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1781 _gtk_boolean_handled_accumulator, NULL,
1782 _gtk_marshal_BOOLEAN__ENUM,
1784 GTK_TYPE_DIRECTION_TYPE);
1788 * @widget: the object which received the signal.
1789 * @event: the #GdkEvent which triggered this signal
1791 * The GTK+ main loop will emit three signals for each GDK event delivered
1792 * to a widget: one generic ::event signal, another, more specific,
1793 * signal that matches the type of event delivered (e.g.
1794 * #GtkWidget::key-press-event) and finally a generic
1795 * #GtkWidget::event-after signal.
1797 * Returns: %TRUE to stop other handlers from being invoked for the event
1798 * and to cancel the emission of the second specific ::event signal.
1799 * %FALSE to propagate the event further and to allow the emission of
1800 * the second signal. The ::event-after signal is emitted regardless of
1803 widget_signals[EVENT] =
1804 g_signal_new (I_("event"),
1805 G_TYPE_FROM_CLASS (klass),
1807 G_STRUCT_OFFSET (GtkWidgetClass, event),
1808 _gtk_boolean_handled_accumulator, NULL,
1809 _gtk_marshal_BOOLEAN__BOXED,
1811 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1814 * GtkWidget::event-after:
1815 * @widget: the object which received the signal.
1816 * @event: the #GdkEvent which triggered this signal
1818 * After the emission of the #GtkWidget::event signal and (optionally)
1819 * the second more specific signal, ::event-after will be emitted
1820 * regardless of the previous two signals handlers return values.
1823 widget_signals[EVENT_AFTER] =
1824 g_signal_new (I_("event-after"),
1825 G_TYPE_FROM_CLASS (klass),
1829 _gtk_marshal_VOID__BOXED,
1831 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1834 * GtkWidget::button-press-event:
1835 * @widget: the object which received the signal.
1836 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1839 * The ::button-press-event signal will be emitted when a button
1840 * (typically from a mouse) is pressed.
1842 * To receive this signal, the #GdkWindow associated to the
1843 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1845 * This signal will be sent to the grab widget if there is one.
1847 * Returns: %TRUE to stop other handlers from being invoked for the event.
1848 * %FALSE to propagate the event further.
1850 widget_signals[BUTTON_PRESS_EVENT] =
1851 g_signal_new (I_("button-press-event"),
1852 G_TYPE_FROM_CLASS (klass),
1854 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1855 _gtk_boolean_handled_accumulator, NULL,
1856 _gtk_marshal_BOOLEAN__BOXED,
1858 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1861 * GtkWidget::button-release-event:
1862 * @widget: the object which received the signal.
1863 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1866 * The ::button-release-event signal will be emitted when a button
1867 * (typically from a mouse) is released.
1869 * To receive this signal, the #GdkWindow associated to the
1870 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1872 * This signal will be sent to the grab widget if there is one.
1874 * Returns: %TRUE to stop other handlers from being invoked for the event.
1875 * %FALSE to propagate the event further.
1877 widget_signals[BUTTON_RELEASE_EVENT] =
1878 g_signal_new (I_("button-release-event"),
1879 G_TYPE_FROM_CLASS (klass),
1881 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1882 _gtk_boolean_handled_accumulator, NULL,
1883 _gtk_marshal_BOOLEAN__BOXED,
1885 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1888 * GtkWidget::scroll-event:
1889 * @widget: the object which received the signal.
1890 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1893 * The ::scroll-event signal is emitted when a button in the 4 to 7
1894 * range is pressed. Wheel mice are usually configured to generate
1895 * button press events for buttons 4 and 5 when the wheel is turned.
1897 * To receive this signal, the #GdkWindow associated to the widget needs
1898 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1900 * This signal will be sent to the grab widget if there is one.
1902 * Returns: %TRUE to stop other handlers from being invoked for the event.
1903 * %FALSE to propagate the event further.
1905 widget_signals[SCROLL_EVENT] =
1906 g_signal_new (I_("scroll-event"),
1907 G_TYPE_FROM_CLASS (klass),
1909 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1910 _gtk_boolean_handled_accumulator, NULL,
1911 _gtk_marshal_BOOLEAN__BOXED,
1913 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1916 * GtkWidget::motion-notify-event:
1917 * @widget: the object which received the signal.
1918 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1921 * The ::motion-notify-event signal is emitted when the pointer moves
1922 * over the widget's #GdkWindow.
1924 * To receive this signal, the #GdkWindow associated to the widget
1925 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1927 * This signal will be sent to the grab widget if there is one.
1929 * Returns: %TRUE to stop other handlers from being invoked for the event.
1930 * %FALSE to propagate the event further.
1932 widget_signals[MOTION_NOTIFY_EVENT] =
1933 g_signal_new (I_("motion-notify-event"),
1934 G_TYPE_FROM_CLASS (klass),
1936 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1937 _gtk_boolean_handled_accumulator, NULL,
1938 _gtk_marshal_BOOLEAN__BOXED,
1940 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1943 * GtkWidget::composited-changed:
1944 * @widget: the object on which the signal is emitted
1946 * The ::composited-changed signal is emitted when the composited
1947 * status of @widget<!-- -->s screen changes.
1948 * See gdk_screen_is_composited().
1950 widget_signals[COMPOSITED_CHANGED] =
1951 g_signal_new (I_("composited-changed"),
1952 G_TYPE_FROM_CLASS (klass),
1953 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1954 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1956 _gtk_marshal_VOID__VOID,
1960 * GtkWidget::delete-event:
1961 * @widget: the object which received the signal
1962 * @event: the event which triggered this signal
1964 * The ::delete-event signal is emitted if a user requests that
1965 * a toplevel window is closed. The default handler for this signal
1966 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1967 * this signal will cause the window to be hidden instead, so that
1968 * it can later be shown again without reconstructing it.
1970 * Returns: %TRUE to stop other handlers from being invoked for the event.
1971 * %FALSE to propagate the event further.
1973 widget_signals[DELETE_EVENT] =
1974 g_signal_new (I_("delete-event"),
1975 G_TYPE_FROM_CLASS (klass),
1977 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1978 _gtk_boolean_handled_accumulator, NULL,
1979 _gtk_marshal_BOOLEAN__BOXED,
1981 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1984 * GtkWidget::destroy-event:
1985 * @widget: the object which received the signal.
1986 * @event: the event which triggered this signal
1988 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1989 * You rarely get this signal, because most widgets disconnect themselves
1990 * from their window before they destroy it, so no widget owns the
1991 * window at destroy time.
1993 * To receive this signal, the #GdkWindow associated to the widget needs
1994 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1995 * automatically for all new windows.
1997 * Returns: %TRUE to stop other handlers from being invoked for the event.
1998 * %FALSE to propagate the event further.
2000 widget_signals[DESTROY_EVENT] =
2001 g_signal_new (I_("destroy-event"),
2002 G_TYPE_FROM_CLASS (klass),
2004 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
2005 _gtk_boolean_handled_accumulator, NULL,
2006 _gtk_marshal_BOOLEAN__BOXED,
2008 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2011 * GtkWidget::key-press-event:
2012 * @widget: the object which received the signal
2013 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2015 * The ::key-press-event signal is emitted when a key is pressed. The signal
2016 * emission will reoccur at the key-repeat rate when the key is kept pressed.
2018 * To receive this signal, the #GdkWindow associated to the widget needs
2019 * to enable the #GDK_KEY_PRESS_MASK mask.
2021 * This signal will be sent to the grab widget if there is one.
2023 * Returns: %TRUE to stop other handlers from being invoked for the event.
2024 * %FALSE to propagate the event further.
2026 widget_signals[KEY_PRESS_EVENT] =
2027 g_signal_new (I_("key-press-event"),
2028 G_TYPE_FROM_CLASS (klass),
2030 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
2031 _gtk_boolean_handled_accumulator, NULL,
2032 _gtk_marshal_BOOLEAN__BOXED,
2034 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2037 * GtkWidget::key-release-event:
2038 * @widget: the object which received the signal
2039 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2041 * The ::key-release-event signal is emitted when a key is released.
2043 * To receive this signal, the #GdkWindow associated to the widget needs
2044 * to enable the #GDK_KEY_RELEASE_MASK mask.
2046 * This signal will be sent to the grab widget if there is one.
2048 * Returns: %TRUE to stop other handlers from being invoked for the event.
2049 * %FALSE to propagate the event further.
2051 widget_signals[KEY_RELEASE_EVENT] =
2052 g_signal_new (I_("key-release-event"),
2053 G_TYPE_FROM_CLASS (klass),
2055 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2056 _gtk_boolean_handled_accumulator, NULL,
2057 _gtk_marshal_BOOLEAN__BOXED,
2059 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2062 * GtkWidget::enter-notify-event:
2063 * @widget: the object which received the signal
2064 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2067 * The ::enter-notify-event will be emitted when the pointer enters
2068 * the @widget's window.
2070 * To receive this signal, the #GdkWindow associated to the widget needs
2071 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2073 * This signal will be sent to the grab widget if there is one.
2075 * Returns: %TRUE to stop other handlers from being invoked for the event.
2076 * %FALSE to propagate the event further.
2078 widget_signals[ENTER_NOTIFY_EVENT] =
2079 g_signal_new (I_("enter-notify-event"),
2080 G_TYPE_FROM_CLASS (klass),
2082 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2083 _gtk_boolean_handled_accumulator, NULL,
2084 _gtk_marshal_BOOLEAN__BOXED,
2086 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2089 * GtkWidget::leave-notify-event:
2090 * @widget: the object which received the signal
2091 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2094 * The ::leave-notify-event will be emitted when the pointer leaves
2095 * the @widget's window.
2097 * To receive this signal, the #GdkWindow associated to the widget needs
2098 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2100 * This signal will be sent to the grab widget if there is one.
2102 * Returns: %TRUE to stop other handlers from being invoked for the event.
2103 * %FALSE to propagate the event further.
2105 widget_signals[LEAVE_NOTIFY_EVENT] =
2106 g_signal_new (I_("leave-notify-event"),
2107 G_TYPE_FROM_CLASS (klass),
2109 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2110 _gtk_boolean_handled_accumulator, NULL,
2111 _gtk_marshal_BOOLEAN__BOXED,
2113 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2116 * GtkWidget::configure-event:
2117 * @widget: the object which received the signal
2118 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2121 * The ::configure-event signal will be emitted when the size, position or
2122 * stacking of the @widget's window has changed.
2124 * To receive this signal, the #GdkWindow associated to the widget needs
2125 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2126 * automatically for all new windows.
2128 * Returns: %TRUE to stop other handlers from being invoked for the event.
2129 * %FALSE to propagate the event further.
2131 widget_signals[CONFIGURE_EVENT] =
2132 g_signal_new (I_("configure-event"),
2133 G_TYPE_FROM_CLASS (klass),
2135 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2136 _gtk_boolean_handled_accumulator, NULL,
2137 _gtk_marshal_BOOLEAN__BOXED,
2139 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2142 * GtkWidget::focus-in-event:
2143 * @widget: the object which received the signal
2144 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2147 * The ::focus-in-event signal will be emitted when the keyboard focus
2148 * enters the @widget's window.
2150 * To receive this signal, the #GdkWindow associated to the widget needs
2151 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2153 * Returns: %TRUE to stop other handlers from being invoked for the event.
2154 * %FALSE to propagate the event further.
2156 widget_signals[FOCUS_IN_EVENT] =
2157 g_signal_new (I_("focus-in-event"),
2158 G_TYPE_FROM_CLASS (klass),
2160 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2161 _gtk_boolean_handled_accumulator, NULL,
2162 _gtk_marshal_BOOLEAN__BOXED,
2164 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2167 * GtkWidget::focus-out-event:
2168 * @widget: the object which received the signal
2169 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2172 * The ::focus-out-event signal will be emitted when the keyboard focus
2173 * leaves the @widget's window.
2175 * To receive this signal, the #GdkWindow associated to the widget needs
2176 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2178 * Returns: %TRUE to stop other handlers from being invoked for the event.
2179 * %FALSE to propagate the event further.
2181 widget_signals[FOCUS_OUT_EVENT] =
2182 g_signal_new (I_("focus-out-event"),
2183 G_TYPE_FROM_CLASS (klass),
2185 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2186 _gtk_boolean_handled_accumulator, NULL,
2187 _gtk_marshal_BOOLEAN__BOXED,
2189 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2192 * GtkWidget::map-event:
2193 * @widget: the object which received the signal
2194 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2196 * The ::map-event signal will be emitted when the @widget's window is
2197 * mapped. A window is mapped when it becomes visible on the screen.
2199 * To receive this signal, the #GdkWindow associated to the widget needs
2200 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2201 * automatically for all new windows.
2203 * Returns: %TRUE to stop other handlers from being invoked for the event.
2204 * %FALSE to propagate the event further.
2206 widget_signals[MAP_EVENT] =
2207 g_signal_new (I_("map-event"),
2208 G_TYPE_FROM_CLASS (klass),
2210 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2211 _gtk_boolean_handled_accumulator, NULL,
2212 _gtk_marshal_BOOLEAN__BOXED,
2214 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2217 * GtkWidget::unmap-event:
2218 * @widget: the object which received the signal
2219 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2221 * The ::unmap-event signal will be emitted when the @widget's window is
2222 * unmapped. A window is unmapped when it becomes invisible on the screen.
2224 * To receive this signal, the #GdkWindow associated to the widget needs
2225 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2226 * automatically for all new windows.
2228 * Returns: %TRUE to stop other handlers from being invoked for the event.
2229 * %FALSE to propagate the event further.
2231 widget_signals[UNMAP_EVENT] =
2232 g_signal_new (I_("unmap-event"),
2233 G_TYPE_FROM_CLASS (klass),
2235 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2236 _gtk_boolean_handled_accumulator, NULL,
2237 _gtk_marshal_BOOLEAN__BOXED,
2239 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2242 * GtkWidget::property-notify-event:
2243 * @widget: the object which received the signal
2244 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2247 * The ::property-notify-event signal will be emitted when a property on
2248 * the @widget's window has been changed or deleted.
2250 * To receive this signal, the #GdkWindow associated to the widget needs
2251 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2253 * Returns: %TRUE to stop other handlers from being invoked for the event.
2254 * %FALSE to propagate the event further.
2256 widget_signals[PROPERTY_NOTIFY_EVENT] =
2257 g_signal_new (I_("property-notify-event"),
2258 G_TYPE_FROM_CLASS (klass),
2260 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2261 _gtk_boolean_handled_accumulator, NULL,
2262 _gtk_marshal_BOOLEAN__BOXED,
2264 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2267 * GtkWidget::selection-clear-event:
2268 * @widget: the object which received the signal
2269 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2272 * The ::selection-clear-event signal will be emitted when the
2273 * the @widget's window has lost ownership of a selection.
2275 * Returns: %TRUE to stop other handlers from being invoked for the event.
2276 * %FALSE to propagate the event further.
2278 widget_signals[SELECTION_CLEAR_EVENT] =
2279 g_signal_new (I_("selection-clear-event"),
2280 G_TYPE_FROM_CLASS (klass),
2282 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2283 _gtk_boolean_handled_accumulator, NULL,
2284 _gtk_marshal_BOOLEAN__BOXED,
2286 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2289 * GtkWidget::selection-request-event:
2290 * @widget: the object which received the signal
2291 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2294 * The ::selection-request-event signal will be emitted when
2295 * another client requests ownership of the selection owned by
2296 * the @widget's window.
2298 * Returns: %TRUE to stop other handlers from being invoked for the event.
2299 * %FALSE to propagate the event further.
2301 widget_signals[SELECTION_REQUEST_EVENT] =
2302 g_signal_new (I_("selection-request-event"),
2303 G_TYPE_FROM_CLASS (klass),
2305 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2306 _gtk_boolean_handled_accumulator, NULL,
2307 _gtk_marshal_BOOLEAN__BOXED,
2309 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2312 * GtkWidget::selection-notify-event:
2313 * @widget: the object which received the signal.
2314 * @event: (type Gdk.EventSelection):
2316 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2318 widget_signals[SELECTION_NOTIFY_EVENT] =
2319 g_signal_new (I_("selection-notify-event"),
2320 G_TYPE_FROM_CLASS (klass),
2322 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2323 _gtk_boolean_handled_accumulator, NULL,
2324 _gtk_marshal_BOOLEAN__BOXED,
2326 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2329 * GtkWidget::selection-received:
2330 * @widget: the object which received the signal.
2334 widget_signals[SELECTION_RECEIVED] =
2335 g_signal_new (I_("selection-received"),
2336 G_TYPE_FROM_CLASS (klass),
2338 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2340 _gtk_marshal_VOID__BOXED_UINT,
2342 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2346 * GtkWidget::selection-get:
2347 * @widget: the object which received the signal.
2352 widget_signals[SELECTION_GET] =
2353 g_signal_new (I_("selection-get"),
2354 G_TYPE_FROM_CLASS (klass),
2356 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2358 _gtk_marshal_VOID__BOXED_UINT_UINT,
2360 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2365 * GtkWidget::proximity-in-event:
2366 * @widget: the object which received the signal
2367 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2370 * To receive this signal the #GdkWindow associated to the widget needs
2371 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2373 * This signal will be sent to the grab widget if there is one.
2375 * Returns: %TRUE to stop other handlers from being invoked for the event.
2376 * %FALSE to propagate the event further.
2378 widget_signals[PROXIMITY_IN_EVENT] =
2379 g_signal_new (I_("proximity-in-event"),
2380 G_TYPE_FROM_CLASS (klass),
2382 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2383 _gtk_boolean_handled_accumulator, NULL,
2384 _gtk_marshal_BOOLEAN__BOXED,
2386 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2389 * GtkWidget::proximity-out-event:
2390 * @widget: the object which received the signal
2391 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2394 * To receive this signal the #GdkWindow associated to the widget needs
2395 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2397 * This signal will be sent to the grab widget if there is one.
2399 * Returns: %TRUE to stop other handlers from being invoked for the event.
2400 * %FALSE to propagate the event further.
2402 widget_signals[PROXIMITY_OUT_EVENT] =
2403 g_signal_new (I_("proximity-out-event"),
2404 G_TYPE_FROM_CLASS (klass),
2406 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2407 _gtk_boolean_handled_accumulator, NULL,
2408 _gtk_marshal_BOOLEAN__BOXED,
2410 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2413 * GtkWidget::drag-leave:
2414 * @widget: the object which received the signal.
2415 * @drag_context: the drag context
2416 * @time: the timestamp of the motion event
2418 * The ::drag-leave signal is emitted on the drop site when the cursor
2419 * leaves the widget. A typical reason to connect to this signal is to
2420 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2421 * with gtk_drag_unhighlight()
2423 widget_signals[DRAG_LEAVE] =
2424 g_signal_new (I_("drag-leave"),
2425 G_TYPE_FROM_CLASS (klass),
2427 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2429 _gtk_marshal_VOID__OBJECT_UINT,
2431 GDK_TYPE_DRAG_CONTEXT,
2435 * GtkWidget::drag-begin:
2436 * @widget: the object which received the signal
2437 * @drag_context: the drag context
2439 * The ::drag-begin signal is emitted on the drag source when a drag is
2440 * started. A typical reason to connect to this signal is to set up a
2441 * custom drag icon with gtk_drag_source_set_icon().
2443 * Note that some widgets set up a drag icon in the default handler of
2444 * this signal, so you may have to use g_signal_connect_after() to
2445 * override what the default handler did.
2447 widget_signals[DRAG_BEGIN] =
2448 g_signal_new (I_("drag-begin"),
2449 G_TYPE_FROM_CLASS (klass),
2451 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2453 _gtk_marshal_VOID__OBJECT,
2455 GDK_TYPE_DRAG_CONTEXT);
2458 * GtkWidget::drag-end:
2459 * @widget: the object which received the signal
2460 * @drag_context: the drag context
2462 * The ::drag-end signal is emitted on the drag source when a drag is
2463 * finished. A typical reason to connect to this signal is to undo
2464 * things done in #GtkWidget::drag-begin.
2466 widget_signals[DRAG_END] =
2467 g_signal_new (I_("drag-end"),
2468 G_TYPE_FROM_CLASS (klass),
2470 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2472 _gtk_marshal_VOID__OBJECT,
2474 GDK_TYPE_DRAG_CONTEXT);
2477 * GtkWidget::drag-data-delete:
2478 * @widget: the object which received the signal
2479 * @drag_context: the drag context
2481 * The ::drag-data-delete signal is emitted on the drag source when a drag
2482 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2483 * handler is responsible for deleting the data that has been dropped. What
2484 * "delete" means depends on the context of the drag operation.
2486 widget_signals[DRAG_DATA_DELETE] =
2487 g_signal_new (I_("drag-data-delete"),
2488 G_TYPE_FROM_CLASS (klass),
2490 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2492 _gtk_marshal_VOID__OBJECT,
2494 GDK_TYPE_DRAG_CONTEXT);
2497 * GtkWidget::drag-failed:
2498 * @widget: the object which received the signal
2499 * @drag_context: the drag context
2500 * @result: the result of the drag operation
2502 * The ::drag-failed signal is emitted on the drag source when a drag has
2503 * failed. The signal handler may hook custom code to handle a failed DND
2504 * operation based on the type of error, it returns %TRUE is the failure has
2505 * been already handled (not showing the default "drag operation failed"
2506 * animation), otherwise it returns %FALSE.
2508 * Return value: %TRUE if the failed drag operation has been already handled.
2512 widget_signals[DRAG_FAILED] =
2513 g_signal_new (I_("drag-failed"),
2514 G_TYPE_FROM_CLASS (klass),
2516 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2517 _gtk_boolean_handled_accumulator, NULL,
2518 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2520 GDK_TYPE_DRAG_CONTEXT,
2521 GTK_TYPE_DRAG_RESULT);
2524 * GtkWidget::drag-motion:
2525 * @widget: the object which received the signal
2526 * @drag_context: the drag context
2527 * @x: the x coordinate of the current cursor position
2528 * @y: the y coordinate of the current cursor position
2529 * @time: the timestamp of the motion event
2531 * The drag-motion signal is emitted on the drop site when the user
2532 * moves the cursor over the widget during a drag. The signal handler
2533 * must determine whether the cursor position is in a drop zone or not.
2534 * If it is not in a drop zone, it returns %FALSE and no further processing
2535 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2536 * handler is responsible for providing the necessary information for
2537 * displaying feedback to the user, by calling gdk_drag_status().
2539 * If the decision whether the drop will be accepted or rejected can't be
2540 * made based solely on the cursor position and the type of the data, the
2541 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2542 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2543 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2544 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2545 * when using the drag-motion signal that way.
2547 * Also note that there is no drag-enter signal. The drag receiver has to
2548 * keep track of whether he has received any drag-motion signals since the
2549 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2550 * an "enter" signal. Upon an "enter", the handler will typically highlight
2551 * the drop site with gtk_drag_highlight().
2554 * drag_motion (GtkWidget *widget,
2555 * GdkDragContext *context,
2562 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2564 * if (!private_data->drag_highlight)
2566 * private_data->drag_highlight = 1;
2567 * gtk_drag_highlight (widget);
2570 * target = gtk_drag_dest_find_target (widget, context, NULL);
2571 * if (target == GDK_NONE)
2572 * gdk_drag_status (context, 0, time);
2575 * private_data->pending_status = context->suggested_action;
2576 * gtk_drag_get_data (widget, context, target, time);
2583 * drag_data_received (GtkWidget *widget,
2584 * GdkDragContext *context,
2587 * GtkSelectionData *selection_data,
2591 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2593 * if (private_data->suggested_action)
2595 * private_data->suggested_action = 0;
2597 * /* We are getting this data due to a request in drag_motion,
2598 * * rather than due to a request in drag_drop, so we are just
2599 * * supposed to call gdk_drag_status (), not actually paste in
2602 * str = gtk_selection_data_get_text (selection_data);
2603 * if (!data_is_acceptable (str))
2604 * gdk_drag_status (context, 0, time);
2606 * gdk_drag_status (context, private_data->suggested_action, time);
2610 * /* accept the drop */
2615 * Returns: whether the cursor position is in a drop zone
2617 widget_signals[DRAG_MOTION] =
2618 g_signal_new (I_("drag-motion"),
2619 G_TYPE_FROM_CLASS (klass),
2621 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2622 _gtk_boolean_handled_accumulator, NULL,
2623 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2625 GDK_TYPE_DRAG_CONTEXT,
2631 * GtkWidget::drag-drop:
2632 * @widget: the object which received the signal
2633 * @drag_context: the drag context
2634 * @x: the x coordinate of the current cursor position
2635 * @y: the y coordinate of the current cursor position
2636 * @time: the timestamp of the motion event
2638 * The ::drag-drop signal is emitted on the drop site when the user drops
2639 * the data onto the widget. The signal handler must determine whether
2640 * the cursor position is in a drop zone or not. If it is not in a drop
2641 * zone, it returns %FALSE and no further processing is necessary.
2642 * Otherwise, the handler returns %TRUE. In this case, the handler must
2643 * ensure that gtk_drag_finish() is called to let the source know that
2644 * the drop is done. The call to gtk_drag_finish() can be done either
2645 * directly or in a #GtkWidget::drag-data-received handler which gets
2646 * triggered by calling gtk_drag_get_data() to receive the data for one
2647 * or more of the supported targets.
2649 * Returns: whether the cursor position is in a drop zone
2651 widget_signals[DRAG_DROP] =
2652 g_signal_new (I_("drag-drop"),
2653 G_TYPE_FROM_CLASS (klass),
2655 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2656 _gtk_boolean_handled_accumulator, NULL,
2657 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2659 GDK_TYPE_DRAG_CONTEXT,
2665 * GtkWidget::drag-data-get:
2666 * @widget: the object which received the signal
2667 * @drag_context: the drag context
2668 * @data: the #GtkSelectionData to be filled with the dragged data
2669 * @info: the info that has been registered with the target in the
2671 * @time: the timestamp at which the data was requested
2673 * The ::drag-data-get signal is emitted on the drag source when the drop
2674 * site requests the data which is dragged. It is the responsibility of
2675 * the signal handler to fill @data with the data in the format which
2676 * is indicated by @info. See gtk_selection_data_set() and
2677 * gtk_selection_data_set_text().
2679 widget_signals[DRAG_DATA_GET] =
2680 g_signal_new (I_("drag-data-get"),
2681 G_TYPE_FROM_CLASS (klass),
2683 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2685 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2687 GDK_TYPE_DRAG_CONTEXT,
2688 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2693 * GtkWidget::drag-data-received:
2694 * @widget: the object which received the signal
2695 * @drag_context: the drag context
2696 * @x: where the drop happened
2697 * @y: where the drop happened
2698 * @data: the received data
2699 * @info: the info that has been registered with the target in the
2701 * @time: the timestamp at which the data was received
2703 * The ::drag-data-received signal is emitted on the drop site when the
2704 * dragged data has been received. If the data was received in order to
2705 * determine whether the drop will be accepted, the handler is expected
2706 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2707 * If the data was received in response to a #GtkWidget::drag-drop signal
2708 * (and this is the last target to be received), the handler for this
2709 * signal is expected to process the received data and then call
2710 * gtk_drag_finish(), setting the @success parameter depending on whether
2711 * the data was processed successfully.
2713 * The handler may inspect and modify @drag_context->action before calling
2714 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2715 * following example:
2718 * drag_data_received (GtkWidget *widget,
2719 * GdkDragContext *drag_context,
2722 * GtkSelectionData *data,
2726 * if ((data->length >= 0) && (data->format == 8))
2728 * if (drag_context->action == GDK_ACTION_ASK)
2730 * GtkWidget *dialog;
2733 * dialog = gtk_message_dialog_new (NULL,
2734 * GTK_DIALOG_MODAL |
2735 * GTK_DIALOG_DESTROY_WITH_PARENT,
2737 * GTK_BUTTONS_YES_NO,
2738 * "Move the data ?\n");
2739 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2740 * gtk_widget_destroy (dialog);
2742 * if (response == GTK_RESPONSE_YES)
2743 * drag_context->action = GDK_ACTION_MOVE;
2745 * drag_context->action = GDK_ACTION_COPY;
2748 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2752 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2756 widget_signals[DRAG_DATA_RECEIVED] =
2757 g_signal_new (I_("drag-data-received"),
2758 G_TYPE_FROM_CLASS (klass),
2760 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2762 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2764 GDK_TYPE_DRAG_CONTEXT,
2767 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2772 * GtkWidget::visibility-notify-event:
2773 * @widget: the object which received the signal
2774 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2775 * triggered this signal.
2777 * The ::visibility-notify-event will be emitted when the @widget's window
2778 * is obscured or unobscured.
2780 * To receive this signal the #GdkWindow associated to the widget needs
2781 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2783 * Returns: %TRUE to stop other handlers from being invoked for the event.
2784 * %FALSE to propagate the event further.
2786 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2787 g_signal_new (I_("visibility-notify-event"),
2788 G_TYPE_FROM_CLASS (klass),
2790 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2791 _gtk_boolean_handled_accumulator, NULL,
2792 _gtk_marshal_BOOLEAN__BOXED,
2794 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2797 * GtkWidget::window-state-event:
2798 * @widget: the object which received the signal
2799 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2800 * triggered this signal.
2802 * The ::window-state-event will be emitted when the state of the
2803 * toplevel window associated to the @widget changes.
2805 * To receive this signal the #GdkWindow associated to the widget
2806 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2807 * this mask automatically for all new windows.
2809 * Returns: %TRUE to stop other handlers from being invoked for the
2810 * event. %FALSE to propagate the event further.
2812 widget_signals[WINDOW_STATE_EVENT] =
2813 g_signal_new (I_("window-state-event"),
2814 G_TYPE_FROM_CLASS (klass),
2816 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2817 _gtk_boolean_handled_accumulator, NULL,
2818 _gtk_marshal_BOOLEAN__BOXED,
2820 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2823 * GtkWidget::damage-event:
2824 * @widget: the object which received the signal
2825 * @event: (type Gdk.EventExpose): the #GdkEventExpose event
2827 * Emitted when a redirected window belonging to @widget gets drawn into.
2828 * The region/area members of the event shows what area of the redirected
2829 * drawable was drawn into.
2831 * Returns: %TRUE to stop other handlers from being invoked for the event.
2832 * %FALSE to propagate the event further.
2836 widget_signals[DAMAGE_EVENT] =
2837 g_signal_new (I_("damage-event"),
2838 G_TYPE_FROM_CLASS (klass),
2840 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2841 _gtk_boolean_handled_accumulator, NULL,
2842 _gtk_marshal_BOOLEAN__BOXED,
2844 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2847 * GtkWidget::grab-broken-event:
2848 * @widget: the object which received the signal
2849 * @event: (type Gdk.EventGrabBroken): the #GdkEventGrabBroken event
2851 * Emitted when a pointer or keyboard grab on a window belonging
2852 * to @widget gets broken.
2854 * On X11, this happens when the grab window becomes unviewable
2855 * (i.e. it or one of its ancestors is unmapped), or if the same
2856 * application grabs the pointer or keyboard again.
2858 * Returns: %TRUE to stop other handlers from being invoked for
2859 * the event. %FALSE to propagate the event further.
2863 widget_signals[GRAB_BROKEN_EVENT] =
2864 g_signal_new (I_("grab-broken-event"),
2865 G_TYPE_FROM_CLASS (klass),
2867 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2868 _gtk_boolean_handled_accumulator, NULL,
2869 _gtk_marshal_BOOLEAN__BOXED,
2871 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2874 * GtkWidget::query-tooltip:
2875 * @widget: the object which received the signal
2876 * @x: the x coordinate of the cursor position where the request has
2877 * been emitted, relative to @widget's left side
2878 * @y: the y coordinate of the cursor position where the request has
2879 * been emitted, relative to @widget's top
2880 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2881 * @tooltip: a #GtkTooltip
2883 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2884 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2885 * focus in keyboard mode.
2887 * Using the given coordinates, the signal handler should determine
2888 * whether a tooltip should be shown for @widget. If this is the case
2889 * %TRUE should be returned, %FALSE otherwise. Note that if
2890 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2891 * should not be used.
2893 * The signal handler is free to manipulate @tooltip with the therefore
2894 * destined function calls.
2896 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2900 widget_signals[QUERY_TOOLTIP] =
2901 g_signal_new (I_("query-tooltip"),
2902 G_TYPE_FROM_CLASS (klass),
2904 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2905 _gtk_boolean_handled_accumulator, NULL,
2906 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2914 * GtkWidget::popup-menu
2915 * @widget: the object which received the signal
2917 * This signal gets emitted whenever a widget should pop up a context
2918 * menu. This usually happens through the standard key binding mechanism;
2919 * by pressing a certain key while a widget is focused, the user can cause
2920 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2921 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2922 * for an example of how to use this signal.
2924 * Returns: %TRUE if a menu was activated
2926 widget_signals[POPUP_MENU] =
2927 g_signal_new (I_("popup-menu"),
2928 G_TYPE_FROM_CLASS (klass),
2929 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2930 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2931 _gtk_boolean_handled_accumulator, NULL,
2932 _gtk_marshal_BOOLEAN__VOID,
2936 * GtkWidget::show-help:
2937 * @widget: the object which received the signal.
2940 widget_signals[SHOW_HELP] =
2941 g_signal_new (I_("show-help"),
2942 G_TYPE_FROM_CLASS (klass),
2943 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2944 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2945 _gtk_boolean_handled_accumulator, NULL,
2946 _gtk_marshal_BOOLEAN__ENUM,
2948 GTK_TYPE_WIDGET_HELP_TYPE);
2951 * GtkWidget::accel-closures-changed:
2952 * @widget: the object which received the signal.
2954 widget_signals[ACCEL_CLOSURES_CHANGED] =
2955 g_signal_new (I_("accel-closures-changed"),
2956 G_TYPE_FROM_CLASS (klass),
2960 _gtk_marshal_VOID__VOID,
2964 * GtkWidget::screen-changed:
2965 * @widget: the object on which the signal is emitted
2966 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2967 * widget was not associated with a screen before
2969 * The ::screen-changed signal gets emitted when the
2970 * screen of a widget has changed.
2972 widget_signals[SCREEN_CHANGED] =
2973 g_signal_new (I_("screen-changed"),
2974 G_TYPE_FROM_CLASS (klass),
2976 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2978 _gtk_marshal_VOID__OBJECT,
2983 * GtkWidget::can-activate-accel:
2984 * @widget: the object which received the signal
2985 * @signal_id: the ID of a signal installed on @widget
2987 * Determines whether an accelerator that activates the signal
2988 * identified by @signal_id can currently be activated.
2989 * This signal is present to allow applications and derived
2990 * widgets to override the default #GtkWidget handling
2991 * for determining whether an accelerator can be activated.
2993 * Returns: %TRUE if the signal can be activated.
2995 widget_signals[CAN_ACTIVATE_ACCEL] =
2996 g_signal_new (I_("can-activate-accel"),
2997 G_TYPE_FROM_CLASS (klass),
2999 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
3000 _gtk_boolean_handled_accumulator, NULL,
3001 _gtk_marshal_BOOLEAN__UINT,
3002 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
3004 binding_set = gtk_binding_set_by_class (klass);
3005 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
3007 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
3010 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
3012 GTK_TYPE_WIDGET_HELP_TYPE,
3013 GTK_WIDGET_HELP_TOOLTIP);
3014 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
3016 GTK_TYPE_WIDGET_HELP_TYPE,
3017 GTK_WIDGET_HELP_TOOLTIP);
3018 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
3020 GTK_TYPE_WIDGET_HELP_TYPE,
3021 GTK_WIDGET_HELP_WHATS_THIS);
3022 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
3024 GTK_TYPE_WIDGET_HELP_TYPE,
3025 GTK_WIDGET_HELP_WHATS_THIS);
3027 gtk_widget_class_install_style_property (klass,
3028 g_param_spec_boolean ("interior-focus",
3029 P_("Interior Focus"),
3030 P_("Whether to draw the focus indicator inside widgets"),
3032 GTK_PARAM_READABLE));
3034 gtk_widget_class_install_style_property (klass,
3035 g_param_spec_int ("focus-line-width",
3036 P_("Focus linewidth"),
3037 P_("Width, in pixels, of the focus indicator line"),
3039 GTK_PARAM_READABLE));
3041 gtk_widget_class_install_style_property (klass,
3042 g_param_spec_string ("focus-line-pattern",
3043 P_("Focus line dash pattern"),
3044 P_("Dash pattern used to draw the focus indicator"),
3046 GTK_PARAM_READABLE));
3047 gtk_widget_class_install_style_property (klass,
3048 g_param_spec_int ("focus-padding",
3049 P_("Focus padding"),
3050 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3052 GTK_PARAM_READABLE));
3053 gtk_widget_class_install_style_property (klass,
3054 g_param_spec_boxed ("cursor-color",
3056 P_("Color with which to draw insertion cursor"),
3058 GTK_PARAM_READABLE));
3059 gtk_widget_class_install_style_property (klass,
3060 g_param_spec_boxed ("secondary-cursor-color",
3061 P_("Secondary cursor color"),
3062 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3064 GTK_PARAM_READABLE));
3065 gtk_widget_class_install_style_property (klass,
3066 g_param_spec_float ("cursor-aspect-ratio",
3067 P_("Cursor line aspect ratio"),
3068 P_("Aspect ratio with which to draw insertion cursor"),
3070 GTK_PARAM_READABLE));
3072 gtk_widget_class_install_style_property (klass,
3073 g_param_spec_boolean ("window-dragging",
3074 P_("Window dragging"),
3075 P_("Whether windows can be dragged by clicking on empty areas"),
3077 GTK_PARAM_READABLE));
3080 * GtkWidget:link-color:
3082 * The "link-color" style property defines the color of unvisited links.
3086 gtk_widget_class_install_style_property (klass,
3087 g_param_spec_boxed ("link-color",
3088 P_("Unvisited Link Color"),
3089 P_("Color of unvisited links"),
3091 GTK_PARAM_READABLE));
3094 * GtkWidget:visited-link-color:
3096 * The "visited-link-color" style property defines the color of visited links.
3100 gtk_widget_class_install_style_property (klass,
3101 g_param_spec_boxed ("visited-link-color",
3102 P_("Visited Link Color"),
3103 P_("Color of visited links"),
3105 GTK_PARAM_READABLE));
3108 * GtkWidget:wide-separators:
3110 * The "wide-separators" style property defines whether separators have
3111 * configurable width and should be drawn using a box instead of a line.
3115 gtk_widget_class_install_style_property (klass,
3116 g_param_spec_boolean ("wide-separators",
3117 P_("Wide Separators"),
3118 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3120 GTK_PARAM_READABLE));
3123 * GtkWidget:separator-width:
3125 * The "separator-width" style property defines the width of separators.
3126 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3130 gtk_widget_class_install_style_property (klass,
3131 g_param_spec_int ("separator-width",
3132 P_("Separator Width"),
3133 P_("The width of separators if wide-separators is TRUE"),
3135 GTK_PARAM_READABLE));
3138 * GtkWidget:separator-height:
3140 * The "separator-height" style property defines the height of separators.
3141 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3145 gtk_widget_class_install_style_property (klass,
3146 g_param_spec_int ("separator-height",
3147 P_("Separator Height"),
3148 P_("The height of separators if \"wide-separators\" is TRUE"),
3150 GTK_PARAM_READABLE));
3153 * GtkWidget:scroll-arrow-hlength:
3155 * The "scroll-arrow-hlength" style property defines the length of
3156 * horizontal scroll arrows.
3160 gtk_widget_class_install_style_property (klass,
3161 g_param_spec_int ("scroll-arrow-hlength",
3162 P_("Horizontal Scroll Arrow Length"),
3163 P_("The length of horizontal scroll arrows"),
3165 GTK_PARAM_READABLE));
3168 * GtkWidget:scroll-arrow-vlength:
3170 * The "scroll-arrow-vlength" style property defines the length of
3171 * vertical scroll arrows.
3175 gtk_widget_class_install_style_property (klass,
3176 g_param_spec_int ("scroll-arrow-vlength",
3177 P_("Vertical Scroll Arrow Length"),
3178 P_("The length of vertical scroll arrows"),
3180 GTK_PARAM_READABLE));
3182 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3184 gtk_widget_class_set_accessible_type (klass, GTK_TYPE_WIDGET_ACCESSIBLE);
3188 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3192 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3193 for (node = list; node; node = node->next)
3195 GParamSpec *pspec = node->data;
3197 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3198 g_param_spec_unref (pspec);
3204 gtk_widget_set_property (GObject *object,
3206 const GValue *value,
3209 GtkWidget *widget = GTK_WIDGET (object);
3214 gchar *tooltip_markup;
3215 const gchar *tooltip_text;
3216 GtkWindow *tooltip_window;
3219 gtk_widget_set_name (widget, g_value_get_string (value));
3222 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3224 case PROP_WIDTH_REQUEST:
3225 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3227 case PROP_HEIGHT_REQUEST:
3228 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3231 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3233 case PROP_SENSITIVE:
3234 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3236 case PROP_APP_PAINTABLE:
3237 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3239 case PROP_CAN_FOCUS:
3240 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3242 case PROP_HAS_FOCUS:
3243 if (g_value_get_boolean (value))
3244 gtk_widget_grab_focus (widget);
3247 if (g_value_get_boolean (value))
3248 gtk_widget_grab_focus (widget);
3250 case PROP_CAN_DEFAULT:
3251 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3253 case PROP_HAS_DEFAULT:
3254 if (g_value_get_boolean (value))
3255 gtk_widget_grab_default (widget);
3257 case PROP_RECEIVES_DEFAULT:
3258 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3261 gtk_widget_set_style (widget, g_value_get_object (value));
3264 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3265 gtk_widget_set_events (widget, g_value_get_flags (value));
3267 case PROP_NO_SHOW_ALL:
3268 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3270 case PROP_HAS_TOOLTIP:
3271 gtk_widget_real_set_has_tooltip (widget,
3272 g_value_get_boolean (value), FALSE);
3274 case PROP_TOOLTIP_MARKUP:
3275 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3276 tooltip_markup = g_value_dup_string (value);
3278 /* Treat an empty string as a NULL string,
3279 * because an empty string would be useless for a tooltip:
3281 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3283 g_free (tooltip_markup);
3284 tooltip_markup = NULL;
3287 g_object_set_qdata_full (object, quark_tooltip_markup,
3288 tooltip_markup, g_free);
3290 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3291 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3292 if (gtk_widget_get_visible (widget))
3293 gtk_widget_queue_tooltip_query (widget);
3295 case PROP_TOOLTIP_TEXT:
3296 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3298 tooltip_text = g_value_get_string (value);
3300 /* Treat an empty string as a NULL string,
3301 * because an empty string would be useless for a tooltip:
3303 if (tooltip_text && (strlen (tooltip_text) == 0))
3304 tooltip_text = NULL;
3306 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3308 g_object_set_qdata_full (object, quark_tooltip_markup,
3309 tooltip_markup, g_free);
3311 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3312 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3313 if (gtk_widget_get_visible (widget))
3314 gtk_widget_queue_tooltip_query (widget);
3316 case PROP_DOUBLE_BUFFERED:
3317 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3320 gtk_widget_set_halign (widget, g_value_get_enum (value));
3323 gtk_widget_set_valign (widget, g_value_get_enum (value));
3325 case PROP_MARGIN_LEFT:
3326 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3328 case PROP_MARGIN_RIGHT:
3329 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3331 case PROP_MARGIN_TOP:
3332 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3334 case PROP_MARGIN_BOTTOM:
3335 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3338 g_object_freeze_notify (G_OBJECT (widget));
3339 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3340 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3341 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3342 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3343 g_object_thaw_notify (G_OBJECT (widget));
3346 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3348 case PROP_HEXPAND_SET:
3349 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3352 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3354 case PROP_VEXPAND_SET:
3355 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3358 g_object_freeze_notify (G_OBJECT (widget));
3359 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3360 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3361 g_object_thaw_notify (G_OBJECT (widget));
3364 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3370 gtk_widget_get_property (GObject *object,
3375 GtkWidget *widget = GTK_WIDGET (object);
3376 GtkWidgetPrivate *priv = widget->priv;
3384 g_value_set_string (value, priv->name);
3386 g_value_set_static_string (value, "");
3389 g_value_set_object (value, priv->parent);
3391 case PROP_WIDTH_REQUEST:
3394 gtk_widget_get_size_request (widget, &w, NULL);
3395 g_value_set_int (value, w);
3398 case PROP_HEIGHT_REQUEST:
3401 gtk_widget_get_size_request (widget, NULL, &h);
3402 g_value_set_int (value, h);
3406 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3408 case PROP_SENSITIVE:
3409 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3411 case PROP_APP_PAINTABLE:
3412 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3414 case PROP_CAN_FOCUS:
3415 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3417 case PROP_HAS_FOCUS:
3418 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3421 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3423 case PROP_CAN_DEFAULT:
3424 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3426 case PROP_HAS_DEFAULT:
3427 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3429 case PROP_RECEIVES_DEFAULT:
3430 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3432 case PROP_COMPOSITE_CHILD:
3433 g_value_set_boolean (value, widget->priv->composite_child);
3436 g_value_set_object (value, gtk_widget_get_style (widget));
3439 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3440 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3442 case PROP_NO_SHOW_ALL:
3443 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3445 case PROP_HAS_TOOLTIP:
3446 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3448 case PROP_TOOLTIP_TEXT:
3450 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3453 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3454 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3456 g_value_take_string (value, text);
3459 case PROP_TOOLTIP_MARKUP:
3460 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3463 g_value_set_object (value, gtk_widget_get_window (widget));
3465 case PROP_DOUBLE_BUFFERED:
3466 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3469 g_value_set_enum (value, gtk_widget_get_halign (widget));
3472 g_value_set_enum (value, gtk_widget_get_valign (widget));
3474 case PROP_MARGIN_LEFT:
3475 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3477 case PROP_MARGIN_RIGHT:
3478 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3480 case PROP_MARGIN_TOP:
3481 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3483 case PROP_MARGIN_BOTTOM:
3484 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3488 GtkWidgetAuxInfo *aux_info = gtk_widget_get_aux_info (widget, FALSE);
3489 if (aux_info == NULL)
3491 g_value_set_int (value, 0);
3495 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3496 aux_info->margin.right),
3497 MAX (aux_info->margin.top,
3498 aux_info->margin.bottom)));
3503 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3505 case PROP_HEXPAND_SET:
3506 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3509 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3511 case PROP_VEXPAND_SET:
3512 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3515 g_value_set_boolean (value,
3516 gtk_widget_get_hexpand (widget) &&
3517 gtk_widget_get_vexpand (widget));
3520 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3526 gtk_widget_init (GtkWidget *widget)
3528 GtkWidgetPrivate *priv;
3530 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3533 priv = widget->priv;
3535 priv->child_visible = TRUE;
3537 priv->allocation.x = -1;
3538 priv->allocation.y = -1;
3539 priv->allocation.width = 1;
3540 priv->allocation.height = 1;
3541 priv->window = NULL;
3542 priv->parent = NULL;
3544 priv->sensitive = TRUE;
3545 priv->composite_child = composite_child_stack != 0;
3546 priv->double_buffered = TRUE;
3547 priv->redraw_on_alloc = TRUE;
3548 priv->width_request_needed = TRUE;
3549 priv->height_request_needed = TRUE;
3550 priv->alloc_needed = TRUE;
3552 /* this will be set to TRUE if the widget gets a child or if the
3553 * expand flag is set on the widget, but until one of those happen
3554 * we know the expand is already properly FALSE.
3556 * We really want to default FALSE here to avoid computing expand
3557 * all over the place while initially building a widget tree.
3559 priv->need_compute_expand = FALSE;
3561 priv->style = gtk_widget_get_default_style ();
3562 g_object_ref (priv->style);
3567 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3569 GParamSpec **pspecs)
3571 GtkWidgetPrivate *priv = widget->priv;
3572 GtkWidget *container = priv->parent;
3575 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3576 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3580 * gtk_widget_freeze_child_notify:
3581 * @widget: a #GtkWidget
3583 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3584 * signals are queued until gtk_widget_thaw_child_notify() is called
3587 * This is the analogue of g_object_freeze_notify() for child properties.
3590 gtk_widget_freeze_child_notify (GtkWidget *widget)
3592 g_return_if_fail (GTK_IS_WIDGET (widget));
3594 if (!G_OBJECT (widget)->ref_count)
3597 g_object_ref (widget);
3598 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3599 g_object_unref (widget);
3603 * gtk_widget_child_notify:
3604 * @widget: a #GtkWidget
3605 * @child_property: the name of a child property installed on the
3606 * class of @widget<!-- -->'s parent
3608 * Emits a #GtkWidget::child-notify signal for the
3609 * <link linkend="child-properties">child property</link> @child_property
3612 * This is the analogue of g_object_notify() for child properties.
3614 * Also see gtk_container_child_notify().
3617 gtk_widget_child_notify (GtkWidget *widget,
3618 const gchar *child_property)
3620 if (widget->priv->parent == NULL)
3623 gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
3627 * gtk_widget_thaw_child_notify:
3628 * @widget: a #GtkWidget
3630 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3631 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3635 gtk_widget_thaw_child_notify (GtkWidget *widget)
3637 GObjectNotifyQueue *nqueue;
3639 g_return_if_fail (GTK_IS_WIDGET (widget));
3641 if (!G_OBJECT (widget)->ref_count)
3644 g_object_ref (widget);
3645 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3646 if (!nqueue || !nqueue->freeze_count)
3647 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3648 G_OBJECT_TYPE_NAME (widget), widget);
3650 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3651 g_object_unref (widget);
3657 * @type: type ID of the widget to create
3658 * @first_property_name: name of first property to set
3659 * @...: value of first property, followed by more properties,
3662 * This is a convenience function for creating a widget and setting
3663 * its properties in one go. For example you might write:
3664 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3665 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3666 * g_object_new(), but returns a widget so you don't have to
3667 * cast the object yourself.
3669 * Return value: a new #GtkWidget of type @widget_type
3672 gtk_widget_new (GType type,
3673 const gchar *first_property_name,
3679 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3681 va_start (var_args, first_property_name);
3682 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3689 gtk_widget_queue_draw_child (GtkWidget *widget)
3691 GtkWidgetPrivate *priv = widget->priv;
3694 parent = priv->parent;
3695 if (parent && gtk_widget_is_drawable (parent))
3696 gtk_widget_queue_draw_area (parent,
3699 priv->allocation.width,
3700 priv->allocation.height);
3704 * gtk_widget_unparent:
3705 * @widget: a #GtkWidget
3707 * This function is only for use in widget implementations.
3708 * Should be called by implementations of the remove method
3709 * on #GtkContainer, to dissociate a child from the container.
3712 gtk_widget_unparent (GtkWidget *widget)
3714 GtkWidgetPrivate *priv;
3715 GObjectNotifyQueue *nqueue;
3716 GtkWidget *toplevel;
3717 GtkWidget *old_parent;
3719 g_return_if_fail (GTK_IS_WIDGET (widget));
3721 priv = widget->priv;
3723 if (priv->parent == NULL)
3726 /* keep this function in sync with gtk_menu_detach() */
3728 gtk_widget_push_verify_invariants (widget);
3730 g_object_freeze_notify (G_OBJECT (widget));
3731 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3733 toplevel = gtk_widget_get_toplevel (widget);
3734 if (gtk_widget_is_toplevel (toplevel))
3735 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3737 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3738 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3740 gtk_widget_queue_draw_child (widget);
3742 /* Reset the width and height here, to force reallocation if we
3743 * get added back to a new parent. This won't work if our new
3744 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3745 * (would 0x0 be OK here?)
3747 priv->allocation.width = 1;
3748 priv->allocation.height = 1;
3750 if (gtk_widget_get_realized (widget))
3752 if (priv->in_reparent)
3753 gtk_widget_unmap (widget);
3755 gtk_widget_unrealize (widget);
3758 /* If we are unanchoring the child, we save around the toplevel
3759 * to emit hierarchy changed
3761 if (priv->parent->priv->anchored)
3762 g_object_ref (toplevel);
3766 /* Removing a widget from a container restores the child visible
3767 * flag to the default state, so it doesn't affect the child
3768 * in the next parent.
3770 priv->child_visible = TRUE;
3772 old_parent = priv->parent;
3773 priv->parent = NULL;
3775 /* parent may no longer expand if the removed
3776 * child was expand=TRUE and could therefore
3779 if (gtk_widget_get_visible (widget) &&
3780 (priv->need_compute_expand ||
3781 priv->computed_hexpand ||
3782 priv->computed_vexpand))
3784 gtk_widget_queue_compute_expand (old_parent);
3787 /* Unset window-unfocused since we are no longer inside a toplevel window */
3788 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_WINDOW_UNFOCUSED);
3790 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3793 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3794 g_object_unref (toplevel);
3797 /* Now that the parent pointer is nullified and the hierarchy-changed
3798 * already passed, go ahead and unset the parent window, if we are unparenting
3799 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
3800 * will fire again for the new subhierarchy.
3802 gtk_widget_set_parent_window (widget, NULL);
3804 g_object_notify (G_OBJECT (widget), "parent");
3805 g_object_thaw_notify (G_OBJECT (widget));
3807 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3808 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3810 gtk_widget_pop_verify_invariants (widget);
3811 g_object_unref (widget);
3815 * gtk_widget_destroy:
3816 * @widget: a #GtkWidget
3818 * Destroys a widget.
3821 * destroyed, it will break any references it holds to other objects.
3822 * If the widget is inside a container, the widget will be removed
3823 * from the container. If the widget is a toplevel (derived from
3824 * #GtkWindow), it will be removed from the list of toplevels, and the
3825 * reference GTK+ holds to it will be removed. Removing a
3826 * widget from its container or the list of toplevels results in the
3827 * widget being finalized, unless you've added additional references
3828 * to the widget with g_object_ref().
3830 * In most cases, only toplevel widgets (windows) require explicit
3831 * destruction, because when you destroy a toplevel its children will
3832 * be destroyed as well.
3835 gtk_widget_destroy (GtkWidget *widget)
3837 g_return_if_fail (GTK_IS_WIDGET (widget));
3839 if (!widget->priv->in_destruction)
3840 g_object_run_dispose (G_OBJECT (widget));
3844 * gtk_widget_destroyed:
3845 * @widget: a #GtkWidget
3846 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3848 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3849 * %NULL. It's intended to be used as a callback connected to the
3850 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3851 * as a signal handler, and pass the address of your widget variable
3852 * as user data. Then when the widget is destroyed, the variable will
3853 * be set to %NULL. Useful for example to avoid multiple copies
3854 * of the same dialog.
3857 gtk_widget_destroyed (GtkWidget *widget,
3858 GtkWidget **widget_pointer)
3860 /* Don't make any assumptions about the
3862 * Even check widget_pointer.
3865 *widget_pointer = NULL;
3870 * @widget: a #GtkWidget
3872 * Flags a widget to be displayed. Any widget that isn't shown will
3873 * not appear on the screen. If you want to show all the widgets in a
3874 * container, it's easier to call gtk_widget_show_all() on the
3875 * container, instead of individually showing the widgets.
3877 * Remember that you have to show the containers containing a widget,
3878 * in addition to the widget itself, before it will appear onscreen.
3880 * When a toplevel container is shown, it is immediately realized and
3881 * mapped; other shown widgets are realized and mapped when their
3882 * toplevel container is realized and mapped.
3885 gtk_widget_show (GtkWidget *widget)
3887 g_return_if_fail (GTK_IS_WIDGET (widget));
3889 if (!gtk_widget_get_visible (widget))
3891 g_object_ref (widget);
3892 gtk_widget_push_verify_invariants (widget);
3894 if (!gtk_widget_is_toplevel (widget))
3895 gtk_widget_queue_resize (widget);
3897 /* see comment in set_parent() for why this should and can be
3900 if (widget->priv->need_compute_expand ||
3901 widget->priv->computed_hexpand ||
3902 widget->priv->computed_vexpand)
3904 if (widget->priv->parent != NULL)
3905 gtk_widget_queue_compute_expand (widget->priv->parent);
3908 g_signal_emit (widget, widget_signals[SHOW], 0);
3909 g_object_notify (G_OBJECT (widget), "visible");
3911 gtk_widget_pop_verify_invariants (widget);
3912 g_object_unref (widget);
3917 gtk_widget_real_show (GtkWidget *widget)
3919 GtkWidgetPrivate *priv = widget->priv;
3921 if (!gtk_widget_get_visible (widget))
3923 priv->visible = TRUE;
3926 gtk_widget_get_mapped (priv->parent) &&
3927 gtk_widget_get_child_visible (widget) &&
3928 !gtk_widget_get_mapped (widget))
3929 gtk_widget_map (widget);
3934 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3937 g_signal_handlers_disconnect_by_func (widget,
3938 gtk_widget_show_map_callback,
3943 * gtk_widget_show_now:
3944 * @widget: a #GtkWidget
3946 * Shows a widget. If the widget is an unmapped toplevel widget
3947 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3948 * loop and wait for the window to actually be mapped. Be careful;
3949 * because the main loop is running, anything can happen during
3953 gtk_widget_show_now (GtkWidget *widget)
3957 g_return_if_fail (GTK_IS_WIDGET (widget));
3959 /* make sure we will get event */
3960 if (!gtk_widget_get_mapped (widget) &&
3961 gtk_widget_is_toplevel (widget))
3963 gtk_widget_show (widget);
3965 g_signal_connect (widget, "map-event",
3966 G_CALLBACK (gtk_widget_show_map_callback),
3970 gtk_main_iteration ();
3973 gtk_widget_show (widget);
3978 * @widget: a #GtkWidget
3980 * Reverses the effects of gtk_widget_show(), causing the widget to be
3981 * hidden (invisible to the user).
3984 gtk_widget_hide (GtkWidget *widget)
3986 g_return_if_fail (GTK_IS_WIDGET (widget));
3988 if (gtk_widget_get_visible (widget))
3990 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3992 g_object_ref (widget);
3993 gtk_widget_push_verify_invariants (widget);
3995 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3996 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3998 /* a parent may now be expand=FALSE since we're hidden. */
3999 if (widget->priv->need_compute_expand ||
4000 widget->priv->computed_hexpand ||
4001 widget->priv->computed_vexpand)
4003 gtk_widget_queue_compute_expand (widget);
4006 g_signal_emit (widget, widget_signals[HIDE], 0);
4007 if (!gtk_widget_is_toplevel (widget))
4008 gtk_widget_queue_resize (widget);
4009 g_object_notify (G_OBJECT (widget), "visible");
4011 gtk_widget_pop_verify_invariants (widget);
4012 g_object_unref (widget);
4017 gtk_widget_real_hide (GtkWidget *widget)
4019 if (gtk_widget_get_visible (widget))
4021 widget->priv->visible = FALSE;
4023 if (gtk_widget_get_mapped (widget))
4024 gtk_widget_unmap (widget);
4029 * gtk_widget_hide_on_delete:
4030 * @widget: a #GtkWidget
4032 * Utility function; intended to be connected to the #GtkWidget::delete-event
4033 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4034 * argument, then returns %TRUE. If connected to ::delete-event, the
4035 * result is that clicking the close button for a window (on the
4036 * window frame, top right corner usually) will hide but not destroy
4037 * the window. By default, GTK+ destroys windows when ::delete-event
4040 * Return value: %TRUE
4043 gtk_widget_hide_on_delete (GtkWidget *widget)
4045 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4047 gtk_widget_hide (widget);
4053 * gtk_widget_show_all:
4054 * @widget: a #GtkWidget
4056 * Recursively shows a widget, and any child widgets (if the widget is
4060 gtk_widget_show_all (GtkWidget *widget)
4062 GtkWidgetClass *class;
4064 g_return_if_fail (GTK_IS_WIDGET (widget));
4066 if (gtk_widget_get_no_show_all (widget))
4069 class = GTK_WIDGET_GET_CLASS (widget);
4071 if (class->show_all)
4072 class->show_all (widget);
4076 _gtk_widget_notify_state_change (GtkWidget *widget,
4084 case GTK_STATE_FLAG_ACTIVE:
4085 state = GTK_STATE_ACTIVE;
4087 case GTK_STATE_FLAG_PRELIGHT:
4088 state = GTK_STATE_PRELIGHT;
4090 case GTK_STATE_FLAG_SELECTED:
4091 state = GTK_STATE_SELECTED;
4093 case GTK_STATE_FLAG_INSENSITIVE:
4094 state = GTK_STATE_INSENSITIVE;
4096 case GTK_STATE_FLAG_INCONSISTENT:
4097 state = GTK_STATE_INCONSISTENT;
4099 case GTK_STATE_FLAG_FOCUSED:
4100 state = GTK_STATE_FOCUSED;
4106 gtk_style_context_notify_state_change (widget->priv->context,
4107 gtk_widget_get_window (widget),
4108 NULL, state, target);
4111 /* Initializes state transitions for those states that
4112 * were enabled before mapping and have a looping animation.
4115 _gtk_widget_start_state_transitions (GtkWidget *widget)
4117 GtkStateFlags state, flag;
4119 if (!widget->priv->context)
4122 state = gtk_widget_get_state_flags (widget);
4123 flag = GTK_STATE_FLAG_FOCUSED;
4127 GtkAnimationDescription *animation_desc;
4129 if ((state & flag) == 0)
4135 gtk_style_context_get (widget->priv->context, state,
4136 "transition", &animation_desc,
4141 if (_gtk_animation_description_get_loop (animation_desc))
4142 _gtk_widget_notify_state_change (widget, flag, TRUE);
4144 _gtk_animation_description_unref (animation_desc);
4153 * @widget: a #GtkWidget
4155 * This function is only for use in widget implementations. Causes
4156 * a widget to be mapped if it isn't already.
4159 gtk_widget_map (GtkWidget *widget)
4161 GtkWidgetPrivate *priv;
4163 g_return_if_fail (GTK_IS_WIDGET (widget));
4164 g_return_if_fail (gtk_widget_get_visible (widget));
4165 g_return_if_fail (gtk_widget_get_child_visible (widget));
4167 priv = widget->priv;
4169 if (!gtk_widget_get_mapped (widget))
4171 gtk_widget_push_verify_invariants (widget);
4173 if (!gtk_widget_get_realized (widget))
4174 gtk_widget_realize (widget);
4176 g_signal_emit (widget, widget_signals[MAP], 0);
4178 if (!gtk_widget_get_has_window (widget))
4179 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4181 gtk_widget_pop_verify_invariants (widget);
4183 _gtk_widget_start_state_transitions (widget);
4189 * @widget: a #GtkWidget
4191 * This function is only for use in widget implementations. Causes
4192 * a widget to be unmapped if it's currently mapped.
4195 gtk_widget_unmap (GtkWidget *widget)
4197 GtkWidgetPrivate *priv;
4199 g_return_if_fail (GTK_IS_WIDGET (widget));
4201 priv = widget->priv;
4203 if (gtk_widget_get_mapped (widget))
4205 gtk_widget_push_verify_invariants (widget);
4207 if (!gtk_widget_get_has_window (widget))
4208 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4209 _gtk_tooltip_hide (widget);
4210 g_signal_emit (widget, widget_signals[UNMAP], 0);
4212 gtk_widget_pop_verify_invariants (widget);
4215 gtk_style_context_cancel_animations (priv->context, NULL);
4217 /* Unset pointer/window info */
4218 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4223 _gtk_widget_enable_device_events (GtkWidget *widget)
4225 GHashTable *device_events;
4226 GHashTableIter iter;
4227 gpointer key, value;
4229 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4234 g_hash_table_iter_init (&iter, device_events);
4236 while (g_hash_table_iter_next (&iter, &key, &value))
4239 GdkEventMask event_mask;
4242 event_mask = GPOINTER_TO_UINT (value);
4243 gtk_widget_add_events_internal (widget, device, event_mask);
4248 get_widget_windows (GtkWidget *widget)
4250 GList *window_list, *last, *l, *children, *ret;
4252 if (gtk_widget_get_has_window (widget))
4253 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4255 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4257 last = g_list_last (window_list);
4260 for (l = window_list; l; l = l->next)
4262 GtkWidget *window_widget = NULL;
4264 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4266 if (widget != window_widget)
4269 ret = g_list_prepend (ret, l->data);
4270 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4274 last = g_list_concat (last, children);
4275 last = g_list_last (last);
4279 g_list_free (window_list);
4285 device_enable_foreach (GtkWidget *widget,
4288 GdkDevice *device = user_data;
4289 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4293 device_disable_foreach (GtkWidget *widget,
4296 GdkDevice *device = user_data;
4297 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4301 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4306 GList *window_list, *l;
4308 window_list = get_widget_windows (widget);
4310 for (l = window_list; l; l = l->next)
4312 GdkEventMask events = 0;
4318 events = gdk_window_get_events (window);
4320 gdk_window_set_device_events (window, device, events);
4323 if (recurse && GTK_IS_CONTAINER (widget))
4326 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4328 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4331 g_list_free (window_list);
4335 gtk_widget_update_devices_mask (GtkWidget *widget,
4338 GList *enabled_devices, *l;
4340 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4342 for (l = enabled_devices; l; l = l->next)
4343 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4347 * gtk_widget_realize:
4348 * @widget: a #GtkWidget
4350 * Creates the GDK (windowing system) resources associated with a
4351 * widget. For example, @widget->window will be created when a widget
4352 * is realized. Normally realization happens implicitly; if you show
4353 * a widget and all its parent containers, then the widget will be
4354 * realized and mapped automatically.
4356 * Realizing a widget requires all
4357 * the widget's parent widgets to be realized; calling
4358 * gtk_widget_realize() realizes the widget's parents in addition to
4359 * @widget itself. If a widget is not yet inside a toplevel window
4360 * when you realize it, bad things will happen.
4362 * This function is primarily used in widget implementations, and
4363 * isn't very useful otherwise. Many times when you think you might
4364 * need it, a better approach is to connect to a signal that will be
4365 * called after the widget is realized automatically, such as
4366 * #GtkWidget::draw. Or simply g_signal_connect () to the
4367 * #GtkWidget::realize signal.
4370 gtk_widget_realize (GtkWidget *widget)
4372 GtkWidgetPrivate *priv;
4373 cairo_region_t *region;
4375 g_return_if_fail (GTK_IS_WIDGET (widget));
4376 g_return_if_fail (widget->priv->anchored ||
4377 GTK_IS_INVISIBLE (widget));
4379 priv = widget->priv;
4381 if (!gtk_widget_get_realized (widget))
4383 gtk_widget_push_verify_invariants (widget);
4386 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4387 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4390 if (priv->parent == NULL &&
4391 !gtk_widget_is_toplevel (widget))
4392 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4393 "inside a toplevel window is not going to work very well. "
4394 "Widgets must be inside a toplevel container before realizing them.");
4396 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4397 gtk_widget_realize (priv->parent);
4399 gtk_widget_ensure_style (widget);
4401 if (priv->style_update_pending)
4402 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4404 g_signal_emit (widget, widget_signals[REALIZE], 0);
4406 gtk_widget_real_set_has_tooltip (widget,
4407 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4410 if (priv->has_shape_mask)
4412 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4413 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4416 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4418 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4420 if (priv->multidevice)
4421 gdk_window_set_support_multidevice (priv->window, TRUE);
4423 _gtk_widget_enable_device_events (widget);
4424 gtk_widget_update_devices_mask (widget, TRUE);
4426 gtk_widget_pop_verify_invariants (widget);
4431 * gtk_widget_unrealize:
4432 * @widget: a #GtkWidget
4434 * This function is only useful in widget implementations.
4435 * Causes a widget to be unrealized (frees all GDK resources
4436 * associated with the widget, such as @widget->window).
4439 gtk_widget_unrealize (GtkWidget *widget)
4441 g_return_if_fail (GTK_IS_WIDGET (widget));
4443 gtk_widget_push_verify_invariants (widget);
4445 if (widget->priv->has_shape_mask)
4446 gtk_widget_shape_combine_region (widget, NULL);
4448 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4449 gtk_widget_input_shape_combine_region (widget, NULL);
4451 if (gtk_widget_get_realized (widget))
4453 g_object_ref (widget);
4455 if (widget->priv->mapped)
4456 gtk_widget_unmap (widget);
4458 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4459 g_assert (!widget->priv->mapped);
4460 gtk_widget_set_realized (widget, FALSE);
4462 g_object_unref (widget);
4465 gtk_widget_pop_verify_invariants (widget);
4468 /*****************************************
4470 *****************************************/
4473 * gtk_widget_queue_draw_region:
4474 * @widget: a #GtkWidget
4475 * @region: region to draw
4477 * Invalidates the rectangular area of @widget defined by @region by
4478 * calling gdk_window_invalidate_region() on the widget's window and
4479 * all its child windows. Once the main loop becomes idle (after the
4480 * current batch of events has been processed, roughly), the window
4481 * will receive expose events for the union of all regions that have
4484 * Normally you would only use this function in widget
4485 * implementations. You might also use it to schedule a redraw of a
4486 * #GtkDrawingArea or some portion thereof.
4491 gtk_widget_queue_draw_region (GtkWidget *widget,
4492 const cairo_region_t *region)
4494 GtkWidgetPrivate *priv;
4497 g_return_if_fail (GTK_IS_WIDGET (widget));
4499 priv = widget->priv;
4501 if (!gtk_widget_get_realized (widget))
4504 /* Just return if the widget or one of its ancestors isn't mapped */
4505 for (w = widget; w != NULL; w = w->priv->parent)
4506 if (!gtk_widget_get_mapped (w))
4509 gdk_window_invalidate_region (priv->window, region, TRUE);
4513 * gtk_widget_queue_draw_area:
4514 * @widget: a #GtkWidget
4515 * @x: x coordinate of upper-left corner of rectangle to redraw
4516 * @y: y coordinate of upper-left corner of rectangle to redraw
4517 * @width: width of region to draw
4518 * @height: height of region to draw
4520 * Convenience function that calls gtk_widget_queue_draw_region() on
4521 * the region created from the given coordinates.
4523 * The region here is specified in widget coordinates.
4524 * Widget coordinates are a bit odd; for historical reasons, they are
4525 * defined as @widget->window coordinates for widgets that are not
4526 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4527 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4530 gtk_widget_queue_draw_area (GtkWidget *widget,
4537 cairo_region_t *region;
4539 g_return_if_fail (GTK_IS_WIDGET (widget));
4544 rect.height = height;
4546 region = cairo_region_create_rectangle (&rect);
4547 gtk_widget_queue_draw_region (widget, region);
4548 cairo_region_destroy (region);
4552 * gtk_widget_queue_draw:
4553 * @widget: a #GtkWidget
4555 * Equivalent to calling gtk_widget_queue_draw_area() for the
4556 * entire area of a widget.
4559 gtk_widget_queue_draw (GtkWidget *widget)
4563 g_return_if_fail (GTK_IS_WIDGET (widget));
4565 gtk_widget_get_allocation (widget, &rect);
4567 if (!gtk_widget_get_has_window (widget))
4568 gtk_widget_queue_draw_area (widget,
4569 rect.x, rect.y, rect.width, rect.height);
4571 gtk_widget_queue_draw_area (widget,
4572 0, 0, rect.width, rect.height);
4576 * gtk_widget_queue_resize:
4577 * @widget: a #GtkWidget
4579 * This function is only for use in widget implementations.
4580 * Flags a widget to have its size renegotiated; should
4581 * be called when a widget for some reason has a new size request.
4582 * For example, when you change the text in a #GtkLabel, #GtkLabel
4583 * queues a resize to ensure there's enough space for the new text.
4585 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4586 * from inside its implementation of the GtkWidgetClass::size_allocate
4587 * virtual method. Calls to gtk_widget_queue_resize() from inside
4588 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4591 gtk_widget_queue_resize (GtkWidget *widget)
4593 g_return_if_fail (GTK_IS_WIDGET (widget));
4595 if (gtk_widget_get_realized (widget))
4596 gtk_widget_queue_shallow_draw (widget);
4598 _gtk_size_group_queue_resize (widget, 0);
4602 * gtk_widget_queue_resize_no_redraw:
4603 * @widget: a #GtkWidget
4605 * This function works like gtk_widget_queue_resize(),
4606 * except that the widget is not invalidated.
4611 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4613 g_return_if_fail (GTK_IS_WIDGET (widget));
4615 _gtk_size_group_queue_resize (widget, 0);
4619 * gtk_widget_size_request:
4620 * @widget: a #GtkWidget
4621 * @requisition: (out): a #GtkRequisition to be filled in
4623 * This function is typically used when implementing a #GtkContainer
4624 * subclass. Obtains the preferred size of a widget. The container
4625 * uses this information to arrange its child widgets and decide what
4626 * size allocations to give them with gtk_widget_size_allocate().
4628 * You can also call this function from an application, with some
4629 * caveats. Most notably, getting a size request requires the widget
4630 * to be associated with a screen, because font information may be
4631 * needed. Multihead-aware applications should keep this in mind.
4633 * Also remember that the size request is not necessarily the size
4634 * a widget will actually be allocated.
4636 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4639 gtk_widget_size_request (GtkWidget *widget,
4640 GtkRequisition *requisition)
4642 g_return_if_fail (GTK_IS_WIDGET (widget));
4644 gtk_widget_get_preferred_size (widget, requisition, NULL);
4648 * gtk_widget_get_child_requisition:
4649 * @widget: a #GtkWidget
4650 * @requisition: (out): a #GtkRequisition to be filled in
4652 * This function is only for use in widget implementations. Obtains
4653 * @widget->requisition, unless someone has forced a particular
4654 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4655 * in which case it returns that geometry instead of the widget's
4658 * This function differs from gtk_widget_size_request() in that
4659 * it retrieves the last size request value from @widget->requisition,
4660 * while gtk_widget_size_request() actually calls the "size_request" method
4661 * on @widget to compute the size request and fill in @widget->requisition,
4662 * and only then returns @widget->requisition.
4664 * Because this function does not call the "size_request" method, it
4665 * can only be used when you know that @widget->requisition is
4666 * up-to-date, that is, gtk_widget_size_request() has been called
4667 * since the last time a resize was queued. In general, only container
4668 * implementations have this information; applications should use
4669 * gtk_widget_size_request().
4672 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4675 gtk_widget_get_child_requisition (GtkWidget *widget,
4676 GtkRequisition *requisition)
4678 gtk_widget_get_preferred_size (widget, requisition, NULL);
4682 invalidate_predicate (GdkWindow *window,
4687 gdk_window_get_user_data (window, &user_data);
4689 return (user_data == data);
4692 /* Invalidate @region in widget->window and all children
4693 * of widget->window owned by widget. @region is in the
4694 * same coordinates as widget->allocation and will be
4695 * modified by this call.
4698 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4699 cairo_region_t *region)
4701 GtkWidgetPrivate *priv = widget->priv;
4703 if (!gtk_widget_get_realized (widget))
4706 if (gtk_widget_get_has_window (widget) && priv->parent)
4710 gdk_window_get_position (priv->window, &x, &y);
4711 cairo_region_translate (region, -x, -y);
4714 gdk_window_invalidate_maybe_recurse (priv->window, region,
4715 invalidate_predicate, widget);
4719 * gtk_widget_queue_shallow_draw:
4720 * @widget: a #GtkWidget
4722 * Like gtk_widget_queue_draw(), but only windows owned
4723 * by @widget are invalidated.
4726 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4729 cairo_region_t *region;
4731 if (!gtk_widget_get_realized (widget))
4734 gtk_widget_get_allocation (widget, &rect);
4736 region = cairo_region_create_rectangle (&rect);
4737 gtk_widget_invalidate_widget_windows (widget, region);
4738 cairo_region_destroy (region);
4742 * gtk_widget_size_allocate:
4743 * @widget: a #GtkWidget
4744 * @allocation: position and size to be allocated to @widget
4746 * This function is only used by #GtkContainer subclasses, to assign a size
4747 * and position to their child widgets.
4749 * In this function, the allocation may be adjusted. It will be forced
4750 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4751 * method on the child will be used to adjust the allocation. Standard
4752 * adjustments include removing the widget's margins, and applying the
4753 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4756 gtk_widget_size_allocate (GtkWidget *widget,
4757 GtkAllocation *allocation)
4759 GtkWidgetPrivate *priv;
4760 GdkRectangle real_allocation;
4761 GdkRectangle old_allocation;
4762 GdkRectangle adjusted_allocation;
4763 gboolean alloc_needed;
4764 gboolean size_changed;
4765 gboolean position_changed;
4766 gint natural_width, natural_height, dummy;
4767 gint min_width, min_height;
4769 priv = widget->priv;
4771 g_return_if_fail (GTK_IS_WIDGET (widget));
4773 gtk_widget_push_verify_invariants (widget);
4775 #ifdef G_ENABLE_DEBUG
4776 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4787 parent = gtk_widget_get_parent (parent);
4790 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4791 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4792 2 * depth, " ", name,
4793 allocation->width, allocation->height);
4795 #endif /* G_ENABLE_DEBUG */
4797 alloc_needed = priv->alloc_needed;
4798 if (!priv->width_request_needed && !priv->height_request_needed)
4799 /* Preserve request/allocate ordering */
4800 priv->alloc_needed = FALSE;
4802 old_allocation = priv->allocation;
4803 real_allocation = *allocation;
4805 adjusted_allocation = real_allocation;
4806 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4808 /* Go ahead and request the height for allocated width, note that the internals
4809 * of get_height_for_width will internally limit the for_size to natural size
4810 * when aligning implicitly.
4812 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4813 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
4817 /* Go ahead and request the width for allocated height, note that the internals
4818 * of get_width_for_height will internally limit the for_size to natural size
4819 * when aligning implicitly.
4821 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4822 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
4825 #ifdef G_ENABLE_DEBUG
4826 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4828 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
4829 !GTK_IS_SCROLLABLE (widget))
4830 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
4831 "Allocation is %dx%d, but minimum required size is %dx%d.",
4832 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
4833 G_OBJECT_TYPE_NAME (widget), widget,
4834 real_allocation.width, real_allocation.height,
4835 min_width, min_height);
4838 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4839 * allocated sizes and possibly limit them to the natural sizes */
4840 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4841 GTK_ORIENTATION_HORIZONTAL,
4844 &adjusted_allocation.x,
4845 &adjusted_allocation.width);
4846 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4847 GTK_ORIENTATION_VERTICAL,
4850 &adjusted_allocation.y,
4851 &adjusted_allocation.height);
4853 if (adjusted_allocation.x < real_allocation.x ||
4854 adjusted_allocation.y < real_allocation.y ||
4855 (adjusted_allocation.x + adjusted_allocation.width) >
4856 (real_allocation.x + real_allocation.width) ||
4857 (adjusted_allocation.y + adjusted_allocation.height >
4858 real_allocation.y + real_allocation.height))
4860 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",
4861 G_OBJECT_TYPE_NAME (widget), widget,
4862 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4863 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4864 adjusted_allocation = real_allocation; /* veto it */
4868 real_allocation = adjusted_allocation;
4871 if (real_allocation.width < 0 || real_allocation.height < 0)
4873 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4874 real_allocation.width,
4875 real_allocation.height);
4878 real_allocation.width = MAX (real_allocation.width, 1);
4879 real_allocation.height = MAX (real_allocation.height, 1);
4881 size_changed = (old_allocation.width != real_allocation.width ||
4882 old_allocation.height != real_allocation.height);
4883 position_changed = (old_allocation.x != real_allocation.x ||
4884 old_allocation.y != real_allocation.y);
4886 if (!alloc_needed && !size_changed && !position_changed)
4889 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4891 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4892 priv->width_request_needed = FALSE;
4893 priv->height_request_needed = FALSE;
4894 priv->alloc_needed = FALSE;
4896 if (gtk_widget_get_mapped (widget))
4898 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4900 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4902 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4903 cairo_region_union_rectangle (invalidate, &old_allocation);
4905 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4906 cairo_region_destroy (invalidate);
4911 if (priv->redraw_on_alloc)
4913 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4915 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4916 cairo_region_union_rectangle (invalidate, &old_allocation);
4918 gtk_widget_invalidate_widget_windows (widget, invalidate);
4919 cairo_region_destroy (invalidate);
4923 if (size_changed || position_changed)
4925 GtkStyleContext *context;
4927 context = gtk_widget_get_style_context (widget);
4928 _gtk_style_context_invalidate_animation_areas (context);
4932 if ((size_changed || position_changed) && priv->parent &&
4933 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4935 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4936 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4937 cairo_region_destroy (invalidate);
4941 gtk_widget_pop_verify_invariants (widget);
4945 * gtk_widget_common_ancestor:
4946 * @widget_a: a #GtkWidget
4947 * @widget_b: a #GtkWidget
4949 * Find the common ancestor of @widget_a and @widget_b that
4950 * is closest to the two widgets.
4952 * Return value: the closest common ancestor of @widget_a and
4953 * @widget_b or %NULL if @widget_a and @widget_b do not
4954 * share a common ancestor.
4957 gtk_widget_common_ancestor (GtkWidget *widget_a,
4958 GtkWidget *widget_b)
4960 GtkWidget *parent_a;
4961 GtkWidget *parent_b;
4965 parent_a = widget_a;
4966 while (parent_a->priv->parent)
4968 parent_a = parent_a->priv->parent;
4972 parent_b = widget_b;
4973 while (parent_b->priv->parent)
4975 parent_b = parent_b->priv->parent;
4979 if (parent_a != parent_b)
4982 while (depth_a > depth_b)
4984 widget_a = widget_a->priv->parent;
4988 while (depth_b > depth_a)
4990 widget_b = widget_b->priv->parent;
4994 while (widget_a != widget_b)
4996 widget_a = widget_a->priv->parent;
4997 widget_b = widget_b->priv->parent;
5004 * gtk_widget_translate_coordinates:
5005 * @src_widget: a #GtkWidget
5006 * @dest_widget: a #GtkWidget
5007 * @src_x: X position relative to @src_widget
5008 * @src_y: Y position relative to @src_widget
5009 * @dest_x: (out): location to store X position relative to @dest_widget
5010 * @dest_y: (out): location to store Y position relative to @dest_widget
5012 * Translate coordinates relative to @src_widget's allocation to coordinates
5013 * relative to @dest_widget's allocations. In order to perform this
5014 * operation, both widgets must be realized, and must share a common
5017 * Return value: %FALSE if either widget was not realized, or there
5018 * was no common ancestor. In this case, nothing is stored in
5019 * *@dest_x and *@dest_y. Otherwise %TRUE.
5022 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5023 GtkWidget *dest_widget,
5029 GtkWidgetPrivate *src_priv = src_widget->priv;
5030 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5031 GtkWidget *ancestor;
5033 GList *dest_list = NULL;
5035 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5036 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5038 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5039 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5042 /* Translate from allocation relative to window relative */
5043 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5046 gdk_window_get_position (src_priv->window, &wx, &wy);
5048 src_x -= wx - src_priv->allocation.x;
5049 src_y -= wy - src_priv->allocation.y;
5053 src_x += src_priv->allocation.x;
5054 src_y += src_priv->allocation.y;
5057 /* Translate to the common ancestor */
5058 window = src_priv->window;
5059 while (window != ancestor->priv->window)
5063 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5068 window = gdk_window_get_effective_parent (window);
5070 if (!window) /* Handle GtkHandleBox */
5075 window = dest_priv->window;
5076 while (window != ancestor->priv->window)
5078 dest_list = g_list_prepend (dest_list, window);
5080 window = gdk_window_get_effective_parent (window);
5082 if (!window) /* Handle GtkHandleBox */
5084 g_list_free (dest_list);
5093 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5098 dest_list = g_list_remove (dest_list, dest_list->data);
5101 /* Translate from window relative to allocation relative */
5102 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5105 gdk_window_get_position (dest_priv->window, &wx, &wy);
5107 src_x += wx - dest_priv->allocation.x;
5108 src_y += wy - dest_priv->allocation.y;
5112 src_x -= dest_priv->allocation.x;
5113 src_y -= dest_priv->allocation.y;
5125 gtk_widget_real_size_allocate (GtkWidget *widget,
5126 GtkAllocation *allocation)
5128 GtkWidgetPrivate *priv = widget->priv;
5130 priv->allocation = *allocation;
5132 if (gtk_widget_get_realized (widget) &&
5133 gtk_widget_get_has_window (widget))
5135 gdk_window_move_resize (priv->window,
5136 allocation->x, allocation->y,
5137 allocation->width, allocation->height);
5141 /* translate initial/final into start/end */
5143 effective_align (GtkAlign align,
5144 GtkTextDirection direction)
5148 case GTK_ALIGN_START:
5149 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5151 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5158 adjust_for_align (GtkAlign align,
5160 gint *allocated_pos,
5161 gint *allocated_size)
5165 case GTK_ALIGN_FILL:
5166 /* change nothing */
5168 case GTK_ALIGN_START:
5169 /* keep *allocated_pos where it is */
5170 *allocated_size = MIN (*allocated_size, *natural_size);
5173 if (*allocated_size > *natural_size)
5175 *allocated_pos += (*allocated_size - *natural_size);
5176 *allocated_size = *natural_size;
5179 case GTK_ALIGN_CENTER:
5180 if (*allocated_size > *natural_size)
5182 *allocated_pos += (*allocated_size - *natural_size) / 2;
5183 *allocated_size = MIN (*allocated_size, *natural_size);
5190 adjust_for_margin(gint start_margin,
5194 gint *allocated_pos,
5195 gint *allocated_size)
5197 *minimum_size -= (start_margin + end_margin);
5198 *natural_size -= (start_margin + end_margin);
5199 *allocated_pos += start_margin;
5200 *allocated_size -= (start_margin + end_margin);
5204 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5205 GtkOrientation orientation,
5208 gint *allocated_pos,
5209 gint *allocated_size)
5211 const GtkWidgetAuxInfo *aux_info;
5213 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5215 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5217 adjust_for_margin (aux_info->margin.left,
5218 aux_info->margin.right,
5219 minimum_size, natural_size,
5220 allocated_pos, allocated_size);
5221 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5222 natural_size, allocated_pos, allocated_size);
5226 adjust_for_margin (aux_info->margin.top,
5227 aux_info->margin.bottom,
5228 minimum_size, natural_size,
5229 allocated_pos, allocated_size);
5230 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5231 natural_size, allocated_pos, allocated_size);
5236 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5239 GtkWidgetPrivate *priv = widget->priv;
5241 /* widgets must be onscreen for accels to take effect */
5242 return gtk_widget_is_sensitive (widget) &&
5243 gtk_widget_is_drawable (widget) &&
5244 gdk_window_is_viewable (priv->window);
5248 * gtk_widget_can_activate_accel:
5249 * @widget: a #GtkWidget
5250 * @signal_id: the ID of a signal installed on @widget
5252 * Determines whether an accelerator that activates the signal
5253 * identified by @signal_id can currently be activated.
5254 * This is done by emitting the #GtkWidget::can-activate-accel
5255 * signal on @widget; if the signal isn't overridden by a
5256 * handler or in a derived widget, then the default check is
5257 * that the widget must be sensitive, and the widget and all
5258 * its ancestors mapped.
5260 * Return value: %TRUE if the accelerator can be activated.
5265 gtk_widget_can_activate_accel (GtkWidget *widget,
5268 gboolean can_activate = FALSE;
5269 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5270 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5271 return can_activate;
5280 closure_accel_activate (GClosure *closure,
5281 GValue *return_value,
5282 guint n_param_values,
5283 const GValue *param_values,
5284 gpointer invocation_hint,
5285 gpointer marshal_data)
5287 AccelClosure *aclosure = (AccelClosure*) closure;
5288 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5291 g_signal_emit (closure->data, aclosure->signal_id, 0);
5293 /* whether accelerator was handled */
5294 g_value_set_boolean (return_value, can_activate);
5298 closures_destroy (gpointer data)
5300 GSList *slist, *closures = data;
5302 for (slist = closures; slist; slist = slist->next)
5304 g_closure_invalidate (slist->data);
5305 g_closure_unref (slist->data);
5307 g_slist_free (closures);
5311 widget_new_accel_closure (GtkWidget *widget,
5314 AccelClosure *aclosure;
5315 GClosure *closure = NULL;
5316 GSList *slist, *closures;
5318 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5319 for (slist = closures; slist; slist = slist->next)
5320 if (!gtk_accel_group_from_accel_closure (slist->data))
5322 /* reuse this closure */
5323 closure = slist->data;
5328 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5329 closures = g_slist_prepend (closures, g_closure_ref (closure));
5330 g_closure_sink (closure);
5331 g_closure_set_marshal (closure, closure_accel_activate);
5333 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5335 aclosure = (AccelClosure*) closure;
5336 g_assert (closure->data == widget);
5337 g_assert (closure->marshal == closure_accel_activate);
5338 aclosure->signal_id = signal_id;
5344 * gtk_widget_add_accelerator
5345 * @widget: widget to install an accelerator on
5346 * @accel_signal: widget signal to emit on accelerator activation
5347 * @accel_group: accel group for this widget, added to its toplevel
5348 * @accel_key: GDK keyval of the accelerator
5349 * @accel_mods: modifier key combination of the accelerator
5350 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5352 * Installs an accelerator for this @widget in @accel_group that causes
5353 * @accel_signal to be emitted if the accelerator is activated.
5354 * The @accel_group needs to be added to the widget's toplevel via
5355 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5356 * Accelerators added through this function are not user changeable during
5357 * runtime. If you want to support accelerators that can be changed by the
5358 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5359 * gtk_menu_item_set_accel_path() instead.
5362 gtk_widget_add_accelerator (GtkWidget *widget,
5363 const gchar *accel_signal,
5364 GtkAccelGroup *accel_group,
5366 GdkModifierType accel_mods,
5367 GtkAccelFlags accel_flags)
5372 g_return_if_fail (GTK_IS_WIDGET (widget));
5373 g_return_if_fail (accel_signal != NULL);
5374 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5376 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5377 if (!query.signal_id ||
5378 !(query.signal_flags & G_SIGNAL_ACTION) ||
5379 query.return_type != G_TYPE_NONE ||
5382 /* hmm, should be elaborate enough */
5383 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5384 G_OBJECT_TYPE_NAME (widget), accel_signal);
5388 closure = widget_new_accel_closure (widget, query.signal_id);
5390 g_object_ref (widget);
5392 /* install the accelerator. since we don't map this onto an accel_path,
5393 * the accelerator will automatically be locked.
5395 gtk_accel_group_connect (accel_group,
5398 accel_flags | GTK_ACCEL_LOCKED,
5401 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5403 g_object_unref (widget);
5407 * gtk_widget_remove_accelerator:
5408 * @widget: widget to install an accelerator on
5409 * @accel_group: accel group for this widget
5410 * @accel_key: GDK keyval of the accelerator
5411 * @accel_mods: modifier key combination of the accelerator
5413 * Removes an accelerator from @widget, previously installed with
5414 * gtk_widget_add_accelerator().
5416 * Returns: whether an accelerator was installed and could be removed
5419 gtk_widget_remove_accelerator (GtkWidget *widget,
5420 GtkAccelGroup *accel_group,
5422 GdkModifierType accel_mods)
5424 GtkAccelGroupEntry *ag_entry;
5425 GList *slist, *clist;
5428 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5429 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5431 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5432 clist = gtk_widget_list_accel_closures (widget);
5433 for (slist = clist; slist; slist = slist->next)
5437 for (i = 0; i < n; i++)
5438 if (slist->data == (gpointer) ag_entry[i].closure)
5440 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5442 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5444 g_list_free (clist);
5449 g_list_free (clist);
5451 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5452 accel_key, accel_mods, accel_group,
5453 G_OBJECT_TYPE_NAME (widget), widget);
5459 * gtk_widget_list_accel_closures:
5460 * @widget: widget to list accelerator closures for
5462 * Lists the closures used by @widget for accelerator group connections
5463 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5464 * The closures can be used to monitor accelerator changes on @widget,
5465 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5466 * #GtkAccelGroup of a closure which can be found out with
5467 * gtk_accel_group_from_accel_closure().
5469 * Return value: (transfer container) (element-type GClosure):
5470 * a newly allocated #GList of closures
5473 gtk_widget_list_accel_closures (GtkWidget *widget)
5476 GList *clist = NULL;
5478 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5480 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5481 if (gtk_accel_group_from_accel_closure (slist->data))
5482 clist = g_list_prepend (clist, slist->data);
5488 GtkAccelGroup *accel_group;
5493 destroy_accel_path (gpointer data)
5495 AccelPath *apath = data;
5497 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5499 /* closures_destroy takes care of unrefing the closure */
5500 g_object_unref (apath->accel_group);
5502 g_slice_free (AccelPath, apath);
5507 * gtk_widget_set_accel_path:
5508 * @widget: a #GtkWidget
5509 * @accel_path: (allow-none): path used to look up the accelerator
5510 * @accel_group: (allow-none): a #GtkAccelGroup.
5512 * Given an accelerator group, @accel_group, and an accelerator path,
5513 * @accel_path, sets up an accelerator in @accel_group so whenever the
5514 * key binding that is defined for @accel_path is pressed, @widget
5515 * will be activated. This removes any accelerators (for any
5516 * accelerator group) installed by previous calls to
5517 * gtk_widget_set_accel_path(). Associating accelerators with
5518 * paths allows them to be modified by the user and the modifications
5519 * to be saved for future use. (See gtk_accel_map_save().)
5521 * This function is a low level function that would most likely
5522 * be used by a menu creation system like #GtkUIManager. If you
5523 * use #GtkUIManager, setting up accelerator paths will be done
5526 * Even when you you aren't using #GtkUIManager, if you only want to
5527 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5528 * provides a somewhat more convenient interface.
5530 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5531 * pass a static string, you can save some memory by interning it first with
5532 * g_intern_static_string().
5535 gtk_widget_set_accel_path (GtkWidget *widget,
5536 const gchar *accel_path,
5537 GtkAccelGroup *accel_group)
5541 g_return_if_fail (GTK_IS_WIDGET (widget));
5542 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5546 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5547 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5549 gtk_accel_map_add_entry (accel_path, 0, 0);
5550 apath = g_slice_new (AccelPath);
5551 apath->accel_group = g_object_ref (accel_group);
5552 apath->path_quark = g_quark_from_string (accel_path);
5553 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5558 /* also removes possible old settings */
5559 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5562 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5564 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5568 _gtk_widget_get_accel_path (GtkWidget *widget,
5573 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5575 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5577 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5578 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5582 * gtk_widget_mnemonic_activate:
5583 * @widget: a #GtkWidget
5584 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5586 * Emits the #GtkWidget::mnemonic-activate signal.
5588 * The default handler for this signal activates the @widget if
5589 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5592 * Returns: %TRUE if the signal has been handled
5595 gtk_widget_mnemonic_activate (GtkWidget *widget,
5596 gboolean group_cycling)
5600 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5602 group_cycling = group_cycling != FALSE;
5603 if (!gtk_widget_is_sensitive (widget))
5606 g_signal_emit (widget,
5607 widget_signals[MNEMONIC_ACTIVATE],
5615 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5616 gboolean group_cycling)
5618 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5619 gtk_widget_activate (widget);
5620 else if (gtk_widget_get_can_focus (widget))
5621 gtk_widget_grab_focus (widget);
5624 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5625 G_OBJECT_TYPE_NAME (widget));
5626 gtk_widget_error_bell (widget);
5631 static const cairo_user_data_key_t event_key;
5634 _gtk_cairo_get_event (cairo_t *cr)
5636 g_return_val_if_fail (cr != NULL, NULL);
5638 return cairo_get_user_data (cr, &event_key);
5642 gtk_cairo_set_event (cairo_t *cr,
5643 GdkEventExpose *event)
5645 cairo_set_user_data (cr, &event_key, event, NULL);
5649 * gtk_cairo_should_draw_window:
5650 * @cr: a cairo context
5651 * @window: the window to check. @window may not be an input-only
5654 * This function is supposed to be called in #GtkWidget::draw
5655 * implementations for widgets that support multiple windows.
5656 * @cr must be untransformed from invoking of the draw function.
5657 * This function will return %TRUE if the contents of the given
5658 * @window are supposed to be drawn and %FALSE otherwise. Note
5659 * that when the drawing was not initiated by the windowing
5660 * system this function will return %TRUE for all windows, so
5661 * you need to draw the bottommost window first. Also, do not
5662 * use "else if" statements to check which window should be drawn.
5664 * Returns: %TRUE if @window should be drawn
5669 gtk_cairo_should_draw_window (cairo_t *cr,
5672 GdkEventExpose *event;
5674 g_return_val_if_fail (cr != NULL, FALSE);
5675 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5677 event = _gtk_cairo_get_event (cr);
5679 return event == NULL ||
5680 event->window == window;
5684 gtk_widget_get_clip_draw (GtkWidget *widget)
5686 /* labels are not clipped, because clipping them would cause
5687 * mnemonics to not appear on characters that go beyond the
5689 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
5691 if (GTK_IS_LABEL (widget))
5697 /* code shared by gtk_container_propagate_draw() and
5701 _gtk_widget_draw_internal (GtkWidget *widget,
5703 gboolean clip_to_size)
5705 GtkStyleContext *context;
5707 if (!gtk_widget_is_drawable (widget))
5710 clip_to_size &= gtk_widget_get_clip_draw (widget);
5714 cairo_rectangle (cr,
5716 widget->priv->allocation.width,
5717 widget->priv->allocation.height);
5721 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5725 g_signal_emit (widget, widget_signals[DRAW],
5730 context = gtk_widget_get_style_context (widget);
5731 _gtk_style_context_coalesce_animation_areas (context, widget);
5736 * @widget: the widget to draw. It must be drawable (see
5737 * gtk_widget_is_drawable()) and a size must have been allocated.
5738 * @cr: a cairo context to draw to
5740 * Draws @widget to @cr. The top left corner of the widget will be
5741 * drawn to the currently set origin point of @cr.
5743 * You should pass a cairo context as @cr argument that is in an
5744 * original state. Otherwise the resulting drawing is undefined. For
5745 * example changing the operator using cairo_set_operator() or the
5746 * line width using cairo_set_line_width() might have unwanted side
5748 * You may however change the context's transform matrix - like with
5749 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5750 * region with cairo_clip() prior to calling this function. Also, it
5751 * is fine to modify the context with cairo_save() and
5752 * cairo_push_group() prior to calling this function.
5754 * <note><para>Special purpose widgets may contain special code for
5755 * rendering to the screen and might appear differently on screen
5756 * and when rendered using gtk_widget_draw().</para></note>
5761 gtk_widget_draw (GtkWidget *widget,
5764 GdkEventExpose *tmp_event;
5766 g_return_if_fail (GTK_IS_WIDGET (widget));
5767 g_return_if_fail (!widget->priv->alloc_needed);
5768 g_return_if_fail (cr != NULL);
5771 /* We have to reset the event here so that draw functions can call
5772 * gtk_widget_draw() on random other widgets and get the desired
5773 * effect: Drawing all contents, not just the current window.
5775 tmp_event = _gtk_cairo_get_event (cr);
5776 gtk_cairo_set_event (cr, NULL);
5778 _gtk_widget_draw_internal (widget, cr, TRUE);
5780 gtk_cairo_set_event (cr, tmp_event);
5785 gtk_widget_real_key_press_event (GtkWidget *widget,
5788 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5792 gtk_widget_real_key_release_event (GtkWidget *widget,
5795 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5799 gtk_widget_real_focus_in_event (GtkWidget *widget,
5800 GdkEventFocus *event)
5802 gtk_widget_queue_shallow_draw (widget);
5808 gtk_widget_real_focus_out_event (GtkWidget *widget,
5809 GdkEventFocus *event)
5811 gtk_widget_queue_shallow_draw (widget);
5816 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5817 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5821 * @widget: a #GtkWidget
5822 * @event: a #GdkEvent
5824 * Rarely-used function. This function is used to emit
5825 * the event signals on a widget (those signals should never
5826 * be emitted without using this function to do so).
5827 * If you want to synthesize an event though, don't use this function;
5828 * instead, use gtk_main_do_event() so the event will behave as if
5829 * it were in the event queue. Don't synthesize expose events; instead,
5830 * use gdk_window_invalidate_rect() to invalidate a region of the
5833 * Return value: return from the event signal emission (%TRUE if
5834 * the event was handled)
5837 gtk_widget_event (GtkWidget *widget,
5840 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5841 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5843 if (event->type == GDK_EXPOSE)
5845 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5846 "the same effect, call gdk_window_invalidate_rect/region(), "
5847 "followed by gdk_window_process_updates().");
5851 return gtk_widget_event_internal (widget, event);
5854 /* Returns TRUE if a translation should be done */
5856 _gtk_widget_get_translation_to_window (GtkWidget *widget,
5861 GdkWindow *w, *widget_window;
5863 if (!gtk_widget_get_has_window (widget))
5865 *x = -widget->priv->allocation.x;
5866 *y = -widget->priv->allocation.y;
5874 widget_window = gtk_widget_get_window (widget);
5876 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5879 gdk_window_get_position (w, &wx, &wy);
5896 * gtk_cairo_transform_to_window:
5897 * @cr: the cairo context to transform
5898 * @widget: the widget the context is currently centered for
5899 * @window: the window to transform the context to
5901 * Transforms the given cairo context @cr that from @widget-relative
5902 * coordinates to @window-relative coordinates.
5903 * If the @widget's window is not an ancestor of @window, no
5904 * modification will be applied.
5906 * This is the inverse to the transformation GTK applies when
5907 * preparing an expose event to be emitted with the #GtkWidget::draw
5908 * signal. It is intended to help porting multiwindow widgets from
5909 * GTK+ 2 to the rendering architecture of GTK+ 3.
5914 gtk_cairo_transform_to_window (cairo_t *cr,
5920 g_return_if_fail (cr != NULL);
5921 g_return_if_fail (GTK_IS_WIDGET (widget));
5922 g_return_if_fail (GDK_IS_WINDOW (window));
5924 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
5925 cairo_translate (cr, x, y);
5929 * gtk_widget_send_expose:
5930 * @widget: a #GtkWidget
5931 * @event: a expose #GdkEvent
5933 * Very rarely-used function. This function is used to emit
5934 * an expose event on a widget. This function is not normally used
5935 * directly. The only time it is used is when propagating an expose
5936 * event to a child %NO_WINDOW widget, and that is normally done
5937 * using gtk_container_propagate_draw().
5939 * If you want to force an area of a window to be redrawn,
5940 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5941 * To cause the redraw to be done immediately, follow that call
5942 * with a call to gdk_window_process_updates().
5944 * Return value: return from the event signal emission (%TRUE if
5945 * the event was handled)
5948 gtk_widget_send_expose (GtkWidget *widget,
5951 gboolean result = FALSE;
5956 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5957 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5958 g_return_val_if_fail (event != NULL, TRUE);
5959 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5961 cr = gdk_cairo_create (event->expose.window);
5962 gtk_cairo_set_event (cr, &event->expose);
5964 gdk_cairo_region (cr, event->expose.region);
5967 do_clip = _gtk_widget_get_translation_to_window (widget,
5968 event->expose.window,
5970 cairo_translate (cr, -x, -y);
5972 _gtk_widget_draw_internal (widget, cr, do_clip);
5974 /* unset here, so if someone keeps a reference to cr we
5975 * don't leak the window. */
5976 gtk_cairo_set_event (cr, NULL);
5983 event_window_is_still_viewable (GdkEvent *event)
5985 /* Check that we think the event's window is viewable before
5986 * delivering the event, to prevent suprises. We do this here
5987 * at the last moment, since the event may have been queued
5988 * up behind other events, held over a recursive main loop, etc.
5990 switch (event->type)
5993 case GDK_MOTION_NOTIFY:
5994 case GDK_BUTTON_PRESS:
5995 case GDK_2BUTTON_PRESS:
5996 case GDK_3BUTTON_PRESS:
5998 case GDK_ENTER_NOTIFY:
5999 case GDK_PROXIMITY_IN:
6001 return event->any.window && gdk_window_is_viewable (event->any.window);
6004 /* The following events are the second half of paired events;
6005 * we always deliver them to deal with widgets that clean up
6006 * on the second half.
6008 case GDK_BUTTON_RELEASE:
6009 case GDK_KEY_RELEASE:
6010 case GDK_LEAVE_NOTIFY:
6011 case GDK_PROXIMITY_OUT:
6015 /* Remaining events would make sense on an not-viewable window,
6016 * or don't have an associated window.
6023 gtk_widget_event_internal (GtkWidget *widget,
6026 gboolean return_val = FALSE;
6028 /* We check only once for is-still-visible; if someone
6029 * hides the window in on of the signals on the widget,
6030 * they are responsible for returning TRUE to terminate
6033 if (!event_window_is_still_viewable (event))
6036 g_object_ref (widget);
6038 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6039 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6044 switch (event->type)
6050 case GDK_BUTTON_PRESS:
6051 case GDK_2BUTTON_PRESS:
6052 case GDK_3BUTTON_PRESS:
6053 signal_num = BUTTON_PRESS_EVENT;
6056 signal_num = SCROLL_EVENT;
6058 case GDK_BUTTON_RELEASE:
6059 signal_num = BUTTON_RELEASE_EVENT;
6061 case GDK_MOTION_NOTIFY:
6062 signal_num = MOTION_NOTIFY_EVENT;
6065 signal_num = DELETE_EVENT;
6068 signal_num = DESTROY_EVENT;
6069 _gtk_tooltip_hide (widget);
6072 signal_num = KEY_PRESS_EVENT;
6074 case GDK_KEY_RELEASE:
6075 signal_num = KEY_RELEASE_EVENT;
6077 case GDK_ENTER_NOTIFY:
6078 signal_num = ENTER_NOTIFY_EVENT;
6080 case GDK_LEAVE_NOTIFY:
6081 signal_num = LEAVE_NOTIFY_EVENT;
6083 case GDK_FOCUS_CHANGE:
6084 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6085 if (event->focus_change.in)
6086 _gtk_tooltip_focus_in (widget);
6088 _gtk_tooltip_focus_out (widget);
6091 signal_num = CONFIGURE_EVENT;
6094 signal_num = MAP_EVENT;
6097 signal_num = UNMAP_EVENT;
6099 case GDK_WINDOW_STATE:
6100 signal_num = WINDOW_STATE_EVENT;
6102 case GDK_PROPERTY_NOTIFY:
6103 signal_num = PROPERTY_NOTIFY_EVENT;
6105 case GDK_SELECTION_CLEAR:
6106 signal_num = SELECTION_CLEAR_EVENT;
6108 case GDK_SELECTION_REQUEST:
6109 signal_num = SELECTION_REQUEST_EVENT;
6111 case GDK_SELECTION_NOTIFY:
6112 signal_num = SELECTION_NOTIFY_EVENT;
6114 case GDK_PROXIMITY_IN:
6115 signal_num = PROXIMITY_IN_EVENT;
6117 case GDK_PROXIMITY_OUT:
6118 signal_num = PROXIMITY_OUT_EVENT;
6120 case GDK_VISIBILITY_NOTIFY:
6121 signal_num = VISIBILITY_NOTIFY_EVENT;
6123 case GDK_GRAB_BROKEN:
6124 signal_num = GRAB_BROKEN_EVENT;
6127 signal_num = DAMAGE_EVENT;
6130 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6134 if (signal_num != -1)
6135 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6137 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6138 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6142 g_object_unref (widget);
6148 * gtk_widget_activate:
6149 * @widget: a #GtkWidget that's activatable
6151 * For widgets that can be "activated" (buttons, menu items, etc.)
6152 * this function activates them. Activation is what happens when you
6153 * press Enter on a widget during key navigation. If @widget isn't
6154 * activatable, the function returns %FALSE.
6156 * Return value: %TRUE if the widget was activatable
6159 gtk_widget_activate (GtkWidget *widget)
6161 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6163 if (WIDGET_CLASS (widget)->activate_signal)
6165 /* FIXME: we should eventually check the signals signature here */
6166 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6175 gtk_widget_reparent_subwindows (GtkWidget *widget,
6176 GdkWindow *new_window)
6178 GtkWidgetPrivate *priv = widget->priv;
6180 if (!gtk_widget_get_has_window (widget))
6182 GList *children = gdk_window_get_children (priv->window);
6185 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6187 GdkWindow *window = tmp_list->data;
6190 gdk_window_get_user_data (window, &child);
6191 while (child && child != widget)
6192 child = ((GtkWidget*) child)->priv->parent;
6195 gdk_window_reparent (window, new_window, 0, 0);
6198 g_list_free (children);
6203 GList *tmp_list, *children;
6205 parent = gdk_window_get_parent (priv->window);
6208 gdk_window_reparent (priv->window, new_window, 0, 0);
6211 children = gdk_window_get_children (parent);
6213 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6215 GdkWindow *window = tmp_list->data;
6218 gdk_window_get_user_data (window, &child);
6220 if (child == widget)
6221 gdk_window_reparent (window, new_window, 0, 0);
6224 g_list_free (children);
6230 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6231 gpointer client_data)
6233 GtkWidgetPrivate *priv = widget->priv;
6235 g_assert (client_data != NULL);
6237 if (!gtk_widget_get_has_window (widget))
6240 g_object_unref (priv->window);
6241 priv->window = (GdkWindow*) client_data;
6243 g_object_ref (priv->window);
6245 if (GTK_IS_CONTAINER (widget))
6246 gtk_container_forall (GTK_CONTAINER (widget),
6247 gtk_widget_reparent_fixup_child,
6253 * gtk_widget_reparent:
6254 * @widget: a #GtkWidget
6255 * @new_parent: a #GtkContainer to move the widget into
6257 * Moves a widget from one #GtkContainer to another, handling reference
6258 * count issues to avoid destroying the widget.
6261 gtk_widget_reparent (GtkWidget *widget,
6262 GtkWidget *new_parent)
6264 GtkWidgetPrivate *priv;
6266 g_return_if_fail (GTK_IS_WIDGET (widget));
6267 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6268 priv = widget->priv;
6269 g_return_if_fail (priv->parent != NULL);
6271 if (priv->parent != new_parent)
6273 /* First try to see if we can get away without unrealizing
6274 * the widget as we reparent it. if so we set a flag so
6275 * that gtk_widget_unparent doesn't unrealize widget
6277 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6278 priv->in_reparent = TRUE;
6280 g_object_ref (widget);
6281 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6282 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6283 g_object_unref (widget);
6285 if (priv->in_reparent)
6287 priv->in_reparent = FALSE;
6289 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6290 gtk_widget_reparent_fixup_child (widget,
6291 gtk_widget_get_parent_window (widget));
6294 g_object_notify (G_OBJECT (widget), "parent");
6299 * gtk_widget_intersect:
6300 * @widget: a #GtkWidget
6301 * @area: a rectangle
6302 * @intersection: rectangle to store intersection of @widget and @area
6304 * Computes the intersection of a @widget's area and @area, storing
6305 * the intersection in @intersection, and returns %TRUE if there was
6306 * an intersection. @intersection may be %NULL if you're only
6307 * interested in whether there was an intersection.
6309 * Return value: %TRUE if there was an intersection
6312 gtk_widget_intersect (GtkWidget *widget,
6313 const GdkRectangle *area,
6314 GdkRectangle *intersection)
6316 GtkWidgetPrivate *priv;
6321 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6322 g_return_val_if_fail (area != NULL, FALSE);
6324 priv = widget->priv;
6327 dest = intersection;
6331 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6333 if (return_val && intersection && gtk_widget_get_has_window (widget))
6335 intersection->x -= priv->allocation.x;
6336 intersection->y -= priv->allocation.y;
6343 * gtk_widget_region_intersect:
6344 * @widget: a #GtkWidget
6345 * @region: a #cairo_region_t, in the same coordinate system as
6346 * @widget->allocation. That is, relative to @widget->window
6347 * for %NO_WINDOW widgets; relative to the parent window
6348 * of @widget->window for widgets with their own window.
6350 * Computes the intersection of a @widget's area and @region, returning
6351 * the intersection. The result may be empty, use cairo_region_is_empty() to
6354 * Returns: A newly allocated region holding the intersection of @widget
6355 * and @region. The coordinates of the return value are relative to
6356 * @widget->window for %NO_WINDOW widgets, and relative to the parent
6357 * window of @widget->window for widgets with their own window.
6360 gtk_widget_region_intersect (GtkWidget *widget,
6361 const cairo_region_t *region)
6364 cairo_region_t *dest;
6366 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6367 g_return_val_if_fail (region != NULL, NULL);
6369 gtk_widget_get_allocation (widget, &rect);
6371 dest = cairo_region_create_rectangle (&rect);
6373 cairo_region_intersect (dest, region);
6379 * _gtk_widget_grab_notify:
6380 * @widget: a #GtkWidget
6381 * @was_grabbed: whether a grab is now in effect
6383 * Emits the #GtkWidget::grab-notify signal on @widget.
6388 _gtk_widget_grab_notify (GtkWidget *widget,
6389 gboolean was_grabbed)
6391 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6395 * gtk_widget_grab_focus:
6396 * @widget: a #GtkWidget
6398 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6399 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6400 * something like #GtkFrame won't work.
6402 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6403 * gtk_widget_set_can_focus() to modify that flag.
6405 * The widget also needs to be realized and mapped. This is indicated by the
6406 * related signals. Grabbing the focus immediately after creating the widget
6407 * will likely fail and cause critical warnings.
6410 gtk_widget_grab_focus (GtkWidget *widget)
6412 g_return_if_fail (GTK_IS_WIDGET (widget));
6414 if (!gtk_widget_is_sensitive (widget))
6417 g_object_ref (widget);
6418 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6419 g_object_notify (G_OBJECT (widget), "has-focus");
6420 g_object_unref (widget);
6424 reset_focus_recurse (GtkWidget *widget,
6427 if (GTK_IS_CONTAINER (widget))
6429 GtkContainer *container;
6431 container = GTK_CONTAINER (widget);
6432 gtk_container_set_focus_child (container, NULL);
6434 gtk_container_foreach (container,
6435 reset_focus_recurse,
6441 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6443 if (gtk_widget_get_can_focus (focus_widget))
6445 GtkWidget *toplevel;
6448 /* clear the current focus setting, break if the current widget
6449 * is the focus widget's parent, since containers above that will
6450 * be set by the next loop.
6452 toplevel = gtk_widget_get_toplevel (focus_widget);
6453 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6455 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6457 if (widget == focus_widget)
6459 /* We call _gtk_window_internal_set_focus() here so that the
6460 * toplevel window can request the focus if necessary.
6461 * This is needed when the toplevel is a GtkPlug
6463 if (!gtk_widget_has_focus (widget))
6464 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6471 GtkWidget *common_ancestor = gtk_widget_common_ancestor (widget, focus_widget);
6473 if (widget != common_ancestor)
6475 while (widget->priv->parent && widget->priv->parent != common_ancestor)
6477 widget = widget->priv->parent;
6478 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6483 else if (toplevel != focus_widget)
6485 /* gtk_widget_grab_focus() operates on a tree without window...
6486 * actually, this is very questionable behaviour.
6489 gtk_container_foreach (GTK_CONTAINER (toplevel),
6490 reset_focus_recurse,
6494 /* now propagate the new focus up the widget tree and finally
6495 * set it on the window
6497 widget = focus_widget;
6498 while (widget->priv->parent)
6500 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6501 widget = widget->priv->parent;
6503 if (GTK_IS_WINDOW (widget))
6504 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6509 gtk_widget_real_query_tooltip (GtkWidget *widget,
6512 gboolean keyboard_tip,
6513 GtkTooltip *tooltip)
6515 gchar *tooltip_markup;
6516 gboolean has_tooltip;
6518 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6519 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6521 if (has_tooltip && tooltip_markup)
6523 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6531 gtk_widget_real_state_flags_changed (GtkWidget *widget,
6532 GtkStateFlags old_state)
6534 gtk_widget_update_pango_context (widget);
6538 gtk_widget_real_style_updated (GtkWidget *widget)
6540 GtkWidgetPrivate *priv = widget->priv;
6542 gtk_widget_update_pango_context (widget);
6544 if (priv->style != NULL &&
6545 priv->style != gtk_widget_get_default_style ())
6547 /* Trigger ::style-set for old
6548 * widgets not listening to this
6550 g_signal_emit (widget,
6551 widget_signals[STYLE_SET],
6553 widget->priv->style);
6556 if (widget->priv->context)
6558 if (gtk_widget_get_realized (widget) &&
6559 gtk_widget_get_has_window (widget))
6560 gtk_style_context_set_background (widget->priv->context,
6561 widget->priv->window);
6564 if (widget->priv->anchored)
6565 gtk_widget_queue_resize (widget);
6569 gtk_widget_real_show_help (GtkWidget *widget,
6570 GtkWidgetHelpType help_type)
6572 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6574 _gtk_tooltip_toggle_keyboard_mode (widget);
6583 gtk_widget_real_focus (GtkWidget *widget,
6584 GtkDirectionType direction)
6586 if (!gtk_widget_get_can_focus (widget))
6589 if (!gtk_widget_is_focus (widget))
6591 gtk_widget_grab_focus (widget);
6599 gtk_widget_real_move_focus (GtkWidget *widget,
6600 GtkDirectionType direction)
6602 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6604 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6606 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6612 gtk_widget_real_keynav_failed (GtkWidget *widget,
6613 GtkDirectionType direction)
6615 gboolean cursor_only;
6619 case GTK_DIR_TAB_FORWARD:
6620 case GTK_DIR_TAB_BACKWARD:
6627 g_object_get (gtk_widget_get_settings (widget),
6628 "gtk-keynav-cursor-only", &cursor_only,
6635 gtk_widget_error_bell (widget);
6641 * gtk_widget_set_can_focus:
6642 * @widget: a #GtkWidget
6643 * @can_focus: whether or not @widget can own the input focus.
6645 * Specifies whether @widget can own the input focus. See
6646 * gtk_widget_grab_focus() for actually setting the input focus on a
6652 gtk_widget_set_can_focus (GtkWidget *widget,
6655 g_return_if_fail (GTK_IS_WIDGET (widget));
6657 if (widget->priv->can_focus != can_focus)
6659 widget->priv->can_focus = can_focus;
6661 gtk_widget_queue_resize (widget);
6662 g_object_notify (G_OBJECT (widget), "can-focus");
6667 * gtk_widget_get_can_focus:
6668 * @widget: a #GtkWidget
6670 * Determines whether @widget can own the input focus. See
6671 * gtk_widget_set_can_focus().
6673 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6678 gtk_widget_get_can_focus (GtkWidget *widget)
6680 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6682 return widget->priv->can_focus;
6686 * gtk_widget_has_focus:
6687 * @widget: a #GtkWidget
6689 * Determines if the widget has the global input focus. See
6690 * gtk_widget_is_focus() for the difference between having the global
6691 * input focus, and only having the focus within a toplevel.
6693 * Return value: %TRUE if the widget has the global input focus.
6698 gtk_widget_has_focus (GtkWidget *widget)
6700 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6702 return widget->priv->has_focus;
6706 * gtk_widget_has_visible_focus:
6707 * @widget: a #GtkWidget
6709 * Determines if the widget should show a visible indication that
6710 * it has the global input focus. This is a convenience function for
6711 * use in ::draw handlers that takes into account whether focus
6712 * indication should currently be shown in the toplevel window of
6713 * @widget. See gtk_window_get_focus_visible() for more information
6714 * about focus indication.
6716 * To find out if the widget has the global input focus, use
6717 * gtk_widget_has_focus().
6719 * Return value: %TRUE if the widget should display a 'focus rectangle'
6724 gtk_widget_has_visible_focus (GtkWidget *widget)
6726 gboolean draw_focus;
6728 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6730 if (widget->priv->has_focus)
6732 GtkWidget *toplevel;
6734 toplevel = gtk_widget_get_toplevel (widget);
6736 if (GTK_IS_WINDOW (toplevel))
6737 draw_focus = gtk_window_get_focus_visible (GTK_WINDOW (toplevel));
6748 * gtk_widget_is_focus:
6749 * @widget: a #GtkWidget
6751 * Determines if the widget is the focus widget within its
6752 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6753 * necessarily set; %HAS_FOCUS will only be set if the
6754 * toplevel widget additionally has the global input focus.)
6756 * Return value: %TRUE if the widget is the focus widget.
6759 gtk_widget_is_focus (GtkWidget *widget)
6761 GtkWidget *toplevel;
6763 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6765 toplevel = gtk_widget_get_toplevel (widget);
6767 if (GTK_IS_WINDOW (toplevel))
6768 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6774 * gtk_widget_set_can_default:
6775 * @widget: a #GtkWidget
6776 * @can_default: whether or not @widget can be a default widget.
6778 * Specifies whether @widget can be a default widget. See
6779 * gtk_widget_grab_default() for details about the meaning of
6785 gtk_widget_set_can_default (GtkWidget *widget,
6786 gboolean can_default)
6788 g_return_if_fail (GTK_IS_WIDGET (widget));
6790 if (widget->priv->can_default != can_default)
6792 widget->priv->can_default = can_default;
6794 gtk_widget_queue_resize (widget);
6795 g_object_notify (G_OBJECT (widget), "can-default");
6800 * gtk_widget_get_can_default:
6801 * @widget: a #GtkWidget
6803 * Determines whether @widget can be a default widget. See
6804 * gtk_widget_set_can_default().
6806 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6811 gtk_widget_get_can_default (GtkWidget *widget)
6813 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6815 return widget->priv->can_default;
6819 * gtk_widget_has_default:
6820 * @widget: a #GtkWidget
6822 * Determines whether @widget is the current default widget within its
6823 * toplevel. See gtk_widget_set_can_default().
6825 * Return value: %TRUE if @widget is the current default widget within
6826 * its toplevel, %FALSE otherwise
6831 gtk_widget_has_default (GtkWidget *widget)
6833 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6835 return widget->priv->has_default;
6839 _gtk_widget_set_has_default (GtkWidget *widget,
6840 gboolean has_default)
6842 widget->priv->has_default = has_default;
6846 * gtk_widget_grab_default:
6847 * @widget: a #GtkWidget
6849 * Causes @widget to become the default widget. @widget must have the
6850 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6851 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6852 * %TRUE)</literal>. The default widget is activated when
6853 * the user presses Enter in a window. Default widgets must be
6854 * activatable, that is, gtk_widget_activate() should affect them. Note
6855 * that #GtkEntry widgets require the "activates-default" property
6856 * set to %TRUE before they activate the default widget when Enter
6857 * is pressed and the #GtkEntry is focused.
6860 gtk_widget_grab_default (GtkWidget *widget)
6864 g_return_if_fail (GTK_IS_WIDGET (widget));
6865 g_return_if_fail (gtk_widget_get_can_default (widget));
6867 window = gtk_widget_get_toplevel (widget);
6869 if (window && gtk_widget_is_toplevel (window))
6870 gtk_window_set_default (GTK_WINDOW (window), widget);
6872 g_warning (G_STRLOC ": widget not within a GtkWindow");
6876 * gtk_widget_set_receives_default:
6877 * @widget: a #GtkWidget
6878 * @receives_default: whether or not @widget can be a default widget.
6880 * Specifies whether @widget will be treated as the default widget
6881 * within its toplevel when it has the focus, even if another widget
6884 * See gtk_widget_grab_default() for details about the meaning of
6890 gtk_widget_set_receives_default (GtkWidget *widget,
6891 gboolean receives_default)
6893 g_return_if_fail (GTK_IS_WIDGET (widget));
6895 if (widget->priv->receives_default != receives_default)
6897 widget->priv->receives_default = receives_default;
6899 g_object_notify (G_OBJECT (widget), "receives-default");
6904 * gtk_widget_get_receives_default:
6905 * @widget: a #GtkWidget
6907 * Determines whether @widget is alyways treated as default widget
6908 * withing its toplevel when it has the focus, even if another widget
6911 * See gtk_widget_set_receives_default().
6913 * Return value: %TRUE if @widget acts as default widget when focussed,
6919 gtk_widget_get_receives_default (GtkWidget *widget)
6921 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6923 return widget->priv->receives_default;
6927 * gtk_widget_has_grab:
6928 * @widget: a #GtkWidget
6930 * Determines whether the widget is currently grabbing events, so it
6931 * is the only widget receiving input events (keyboard and mouse).
6933 * See also gtk_grab_add().
6935 * Return value: %TRUE if the widget is in the grab_widgets stack
6940 gtk_widget_has_grab (GtkWidget *widget)
6942 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6944 return widget->priv->has_grab;
6948 _gtk_widget_set_has_grab (GtkWidget *widget,
6951 widget->priv->has_grab = has_grab;
6955 * gtk_widget_device_is_shadowed:
6956 * @widget: a #GtkWidget
6957 * @device: a #GdkDevice
6959 * Returns %TRUE if @device has been shadowed by a GTK+
6960 * device grab on another widget, so it would stop sending
6961 * events to @widget. This may be used in the
6962 * #GtkWidget::grab-notify signal to check for specific
6963 * devices. See gtk_device_grab_add().
6965 * Returns: %TRUE if there is an ongoing grab on @device
6966 * by another #GtkWidget than @widget.
6971 gtk_widget_device_is_shadowed (GtkWidget *widget,
6974 GtkWindowGroup *group;
6975 GtkWidget *grab_widget, *toplevel;
6977 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6978 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6980 if (!gtk_widget_get_realized (widget))
6983 toplevel = gtk_widget_get_toplevel (widget);
6985 if (GTK_IS_WINDOW (toplevel))
6986 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6988 group = gtk_window_get_group (NULL);
6990 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6992 /* Widget not inside the hierarchy of grab_widget */
6994 widget != grab_widget &&
6995 !gtk_widget_is_ancestor (widget, grab_widget))
6998 grab_widget = gtk_window_group_get_current_grab (group);
6999 if (grab_widget && widget != grab_widget &&
7000 !gtk_widget_is_ancestor (widget, grab_widget))
7007 * gtk_widget_set_name:
7008 * @widget: a #GtkWidget
7009 * @name: name for the widget
7011 * Widgets can be named, which allows you to refer to them from a
7012 * CSS file. You can apply a style to widgets with a particular name
7013 * in the CSS file. See the documentation for the CSS syntax (on the
7014 * same page as the docs for #GtkStyleContext).
7016 * Note that the CSS syntax has certain special characters to delimit
7017 * and represent elements in a selector (period, #, >, *...),
7018 * so using these will make your widget impossible to match by name.
7019 * Any combination of alphanumeric symbols, dashes and underscores will
7023 gtk_widget_set_name (GtkWidget *widget,
7026 GtkWidgetPrivate *priv;
7029 g_return_if_fail (GTK_IS_WIDGET (widget));
7031 priv = widget->priv;
7033 new_name = g_strdup (name);
7034 g_free (priv->name);
7035 priv->name = new_name;
7037 gtk_widget_reset_style (widget);
7039 g_object_notify (G_OBJECT (widget), "name");
7043 * gtk_widget_get_name:
7044 * @widget: a #GtkWidget
7046 * Retrieves the name of a widget. See gtk_widget_set_name() for the
7047 * significance of widget names.
7049 * Return value: name of the widget. This string is owned by GTK+ and
7050 * should not be modified or freed
7053 gtk_widget_get_name (GtkWidget *widget)
7055 GtkWidgetPrivate *priv;
7057 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7059 priv = widget->priv;
7063 return G_OBJECT_TYPE_NAME (widget);
7067 _gtk_widget_update_state_flags (GtkWidget *widget,
7068 GtkStateFlags flags,
7071 GtkWidgetPrivate *priv;
7073 priv = widget->priv;
7075 /* Handle insensitive first, since it is propagated
7076 * differently throughout the widget hierarchy.
7078 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_UNSET))
7079 gtk_widget_set_sensitive (widget, TRUE);
7080 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation != STATE_CHANGE_UNSET))
7081 gtk_widget_set_sensitive (widget, FALSE);
7082 else if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && !(flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_REPLACE))
7083 gtk_widget_set_sensitive (widget, TRUE);
7085 if (operation != STATE_CHANGE_REPLACE)
7086 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
7089 operation == STATE_CHANGE_REPLACE)
7094 data.operation = operation;
7095 data.use_forall = FALSE;
7097 gtk_widget_propagate_state (widget, &data);
7099 gtk_widget_queue_resize (widget);
7104 * gtk_widget_set_state_flags:
7105 * @widget: a #GtkWidget
7106 * @flags: State flags to turn on
7107 * @clear: Whether to clear state before turning on @flags
7109 * This function is for use in widget implementations. Turns on flag
7110 * values in the current widget state (insensitive, prelighted, etc.).
7112 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7113 * will be propagated down to all non-internal children if @widget is a
7114 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7115 * down to all #GtkContainer children by different means than turning on the
7116 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7117 * gtk_widget_is_sensitive() will make use of these.
7122 gtk_widget_set_state_flags (GtkWidget *widget,
7123 GtkStateFlags flags,
7126 g_return_if_fail (GTK_IS_WIDGET (widget));
7128 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7129 (clear && widget->priv->state_flags == flags))
7133 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7135 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
7139 * gtk_widget_unset_state_flags:
7140 * @widget: a #GtkWidget
7141 * @flags: State flags to turn off
7143 * This function is for use in widget implementations. Turns off flag
7144 * values for the current widget state (insensitive, prelighted, etc.).
7145 * See gtk_widget_set_state_flags().
7150 gtk_widget_unset_state_flags (GtkWidget *widget,
7151 GtkStateFlags flags)
7153 g_return_if_fail (GTK_IS_WIDGET (widget));
7155 if ((widget->priv->state_flags & flags) == 0)
7158 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
7162 * gtk_widget_get_state_flags:
7163 * @widget: a #GtkWidget
7165 * Returns the widget state as a flag set. It is worth mentioning
7166 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7167 * returned, that is, also based on parent insensitivity, even if
7168 * @widget itself is sensitive.
7170 * Returns: The state flags for widget
7175 gtk_widget_get_state_flags (GtkWidget *widget)
7177 GtkStateFlags flags;
7179 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7181 flags = widget->priv->state_flags;
7183 if (gtk_widget_has_focus (widget))
7184 flags |= GTK_STATE_FLAG_FOCUSED;
7190 * gtk_widget_set_state:
7191 * @widget: a #GtkWidget
7192 * @state: new state for @widget
7194 * This function is for use in widget implementations. Sets the state
7195 * of a widget (insensitive, prelighted, etc.) Usually you should set
7196 * the state using wrapper functions such as gtk_widget_set_sensitive().
7198 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7201 gtk_widget_set_state (GtkWidget *widget,
7204 GtkStateFlags flags;
7206 if (state == gtk_widget_get_state (widget))
7211 case GTK_STATE_ACTIVE:
7212 flags = GTK_STATE_FLAG_ACTIVE;
7214 case GTK_STATE_PRELIGHT:
7215 flags = GTK_STATE_FLAG_PRELIGHT;
7217 case GTK_STATE_SELECTED:
7218 flags = GTK_STATE_FLAG_SELECTED;
7220 case GTK_STATE_INSENSITIVE:
7221 flags = GTK_STATE_FLAG_INSENSITIVE;
7223 case GTK_STATE_INCONSISTENT:
7224 flags = GTK_STATE_FLAG_INCONSISTENT;
7226 case GTK_STATE_FOCUSED:
7227 flags = GTK_STATE_FLAG_FOCUSED;
7229 case GTK_STATE_NORMAL:
7235 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7239 * gtk_widget_get_state:
7240 * @widget: a #GtkWidget
7242 * Returns the widget's state. See gtk_widget_set_state().
7244 * Returns: the state of @widget.
7248 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7251 gtk_widget_get_state (GtkWidget *widget)
7253 GtkStateFlags flags;
7255 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7257 flags = gtk_widget_get_state_flags (widget);
7259 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7260 return GTK_STATE_INSENSITIVE;
7261 else if (flags & GTK_STATE_FLAG_ACTIVE)
7262 return GTK_STATE_ACTIVE;
7263 else if (flags & GTK_STATE_FLAG_SELECTED)
7264 return GTK_STATE_SELECTED;
7265 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7266 return GTK_STATE_PRELIGHT;
7268 return GTK_STATE_NORMAL;
7272 * gtk_widget_set_visible:
7273 * @widget: a #GtkWidget
7274 * @visible: whether the widget should be shown or not
7276 * Sets the visibility state of @widget. Note that setting this to
7277 * %TRUE doesn't mean the widget is actually viewable, see
7278 * gtk_widget_get_visible().
7280 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7281 * but is nicer to use when the visibility of the widget depends on
7287 gtk_widget_set_visible (GtkWidget *widget,
7290 g_return_if_fail (GTK_IS_WIDGET (widget));
7292 if (visible != gtk_widget_get_visible (widget))
7295 gtk_widget_show (widget);
7297 gtk_widget_hide (widget);
7302 _gtk_widget_set_visible_flag (GtkWidget *widget,
7305 widget->priv->visible = visible;
7309 * gtk_widget_get_visible:
7310 * @widget: a #GtkWidget
7312 * Determines whether the widget is visible. Note that this doesn't
7313 * take into account whether the widget's parent is also visible
7314 * or the widget is obscured in any way.
7316 * See gtk_widget_set_visible().
7318 * Return value: %TRUE if the widget is visible
7323 gtk_widget_get_visible (GtkWidget *widget)
7325 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7327 return widget->priv->visible;
7331 * gtk_widget_set_has_window:
7332 * @widget: a #GtkWidget
7333 * @has_window: whether or not @widget has a window.
7335 * Specifies whether @widget has a #GdkWindow of its own. Note that
7336 * all realized widgets have a non-%NULL "window" pointer
7337 * (gtk_widget_get_window() never returns a %NULL window when a widget
7338 * is realized), but for many of them it's actually the #GdkWindow of
7339 * one of its parent widgets. Widgets that do not create a %window for
7340 * themselves in #GtkWidget::realize must announce this by
7341 * calling this function with @has_window = %FALSE.
7343 * This function should only be called by widget implementations,
7344 * and they should call it in their init() function.
7349 gtk_widget_set_has_window (GtkWidget *widget,
7350 gboolean has_window)
7352 g_return_if_fail (GTK_IS_WIDGET (widget));
7354 widget->priv->no_window = !has_window;
7358 * gtk_widget_get_has_window:
7359 * @widget: a #GtkWidget
7361 * Determines whether @widget has a #GdkWindow of its own. See
7362 * gtk_widget_set_has_window().
7364 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7369 gtk_widget_get_has_window (GtkWidget *widget)
7371 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7373 return ! widget->priv->no_window;
7377 * gtk_widget_is_toplevel:
7378 * @widget: a #GtkWidget
7380 * Determines whether @widget is a toplevel widget.
7382 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7383 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7386 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7391 gtk_widget_is_toplevel (GtkWidget *widget)
7393 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7395 return widget->priv->toplevel;
7399 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7400 gboolean is_toplevel)
7402 widget->priv->toplevel = is_toplevel;
7406 * gtk_widget_is_drawable:
7407 * @widget: a #GtkWidget
7409 * Determines whether @widget can be drawn to. A widget can be drawn
7410 * to if it is mapped and visible.
7412 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7417 gtk_widget_is_drawable (GtkWidget *widget)
7419 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7421 return (gtk_widget_get_visible (widget) &&
7422 gtk_widget_get_mapped (widget));
7426 * gtk_widget_get_realized:
7427 * @widget: a #GtkWidget
7429 * Determines whether @widget is realized.
7431 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7436 gtk_widget_get_realized (GtkWidget *widget)
7438 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7440 return widget->priv->realized;
7444 * gtk_widget_set_realized:
7445 * @widget: a #GtkWidget
7446 * @realized: %TRUE to mark the widget as realized
7448 * Marks the widget as being realized.
7450 * This function should only ever be called in a derived widget's
7451 * "realize" or "unrealize" implementation.
7456 gtk_widget_set_realized (GtkWidget *widget,
7459 g_return_if_fail (GTK_IS_WIDGET (widget));
7461 widget->priv->realized = realized;
7465 * gtk_widget_get_mapped:
7466 * @widget: a #GtkWidget
7468 * Whether the widget is mapped.
7470 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7475 gtk_widget_get_mapped (GtkWidget *widget)
7477 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7479 return widget->priv->mapped;
7483 * gtk_widget_set_mapped:
7484 * @widget: a #GtkWidget
7485 * @mapped: %TRUE to mark the widget as mapped
7487 * Marks the widget as being realized.
7489 * This function should only ever be called in a derived widget's
7490 * "map" or "unmap" implementation.
7495 gtk_widget_set_mapped (GtkWidget *widget,
7498 g_return_if_fail (GTK_IS_WIDGET (widget));
7500 widget->priv->mapped = mapped;
7504 * gtk_widget_set_app_paintable:
7505 * @widget: a #GtkWidget
7506 * @app_paintable: %TRUE if the application will paint on the widget
7508 * Sets whether the application intends to draw on the widget in
7509 * an #GtkWidget::draw handler.
7511 * This is a hint to the widget and does not affect the behavior of
7512 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7513 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7514 * the effect is to suppress default themed drawing of the widget's
7515 * background. (Children of the widget will still be drawn.) The application
7516 * is then entirely responsible for drawing the widget background.
7518 * Note that the background is still drawn when the widget is mapped.
7521 gtk_widget_set_app_paintable (GtkWidget *widget,
7522 gboolean app_paintable)
7524 g_return_if_fail (GTK_IS_WIDGET (widget));
7526 app_paintable = (app_paintable != FALSE);
7528 if (widget->priv->app_paintable != app_paintable)
7530 widget->priv->app_paintable = app_paintable;
7532 if (gtk_widget_is_drawable (widget))
7533 gtk_widget_queue_draw (widget);
7535 g_object_notify (G_OBJECT (widget), "app-paintable");
7540 * gtk_widget_get_app_paintable:
7541 * @widget: a #GtkWidget
7543 * Determines whether the application intends to draw on the widget in
7544 * an #GtkWidget::draw handler.
7546 * See gtk_widget_set_app_paintable()
7548 * Return value: %TRUE if the widget is app paintable
7553 gtk_widget_get_app_paintable (GtkWidget *widget)
7555 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7557 return widget->priv->app_paintable;
7561 * gtk_widget_set_double_buffered:
7562 * @widget: a #GtkWidget
7563 * @double_buffered: %TRUE to double-buffer a widget
7565 * Widgets are double buffered by default; you can use this function
7566 * to turn off the buffering. "Double buffered" simply means that
7567 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7568 * automatically around expose events sent to the
7569 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7570 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7571 * buffer to the screen. The result is that users see the window
7572 * update in one smooth step, and don't see individual graphics
7573 * primitives being rendered.
7575 * In very simple terms, double buffered widgets don't flicker,
7576 * so you would only use this function to turn off double buffering
7577 * if you had special needs and really knew what you were doing.
7579 * Note: if you turn off double-buffering, you have to handle
7580 * expose events, since even the clearing to the background color or
7581 * pixmap will not happen automatically (as it is done in
7582 * gdk_window_begin_paint()).
7585 gtk_widget_set_double_buffered (GtkWidget *widget,
7586 gboolean double_buffered)
7588 g_return_if_fail (GTK_IS_WIDGET (widget));
7590 double_buffered = (double_buffered != FALSE);
7592 if (widget->priv->double_buffered != double_buffered)
7594 widget->priv->double_buffered = double_buffered;
7596 g_object_notify (G_OBJECT (widget), "double-buffered");
7601 * gtk_widget_get_double_buffered:
7602 * @widget: a #GtkWidget
7604 * Determines whether the widget is double buffered.
7606 * See gtk_widget_set_double_buffered()
7608 * Return value: %TRUE if the widget is double buffered
7613 gtk_widget_get_double_buffered (GtkWidget *widget)
7615 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7617 return widget->priv->double_buffered;
7621 * gtk_widget_set_redraw_on_allocate:
7622 * @widget: a #GtkWidget
7623 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7624 * when it is allocated to a new size. Otherwise, only the
7625 * new portion of the widget will be redrawn.
7627 * Sets whether the entire widget is queued for drawing when its size
7628 * allocation changes. By default, this setting is %TRUE and
7629 * the entire widget is redrawn on every size change. If your widget
7630 * leaves the upper left unchanged when made bigger, turning this
7631 * setting off will improve performance.
7633 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7634 * off all allocation on resizing: the widget will not even redraw if
7635 * its position changes; this is to allow containers that don't draw
7636 * anything to avoid excess invalidations. If you set this flag on a
7637 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7638 * you are responsible for invalidating both the old and new allocation
7639 * of the widget when the widget is moved and responsible for invalidating
7640 * regions newly when the widget increases size.
7643 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7644 gboolean redraw_on_allocate)
7646 g_return_if_fail (GTK_IS_WIDGET (widget));
7648 widget->priv->redraw_on_alloc = redraw_on_allocate;
7652 * gtk_widget_set_sensitive:
7653 * @widget: a #GtkWidget
7654 * @sensitive: %TRUE to make the widget sensitive
7656 * Sets the sensitivity of a widget. A widget is sensitive if the user
7657 * can interact with it. Insensitive widgets are "grayed out" and the
7658 * user can't interact with them. Insensitive widgets are known as
7659 * "inactive", "disabled", or "ghosted" in some other toolkits.
7662 gtk_widget_set_sensitive (GtkWidget *widget,
7665 GtkWidgetPrivate *priv;
7667 g_return_if_fail (GTK_IS_WIDGET (widget));
7669 priv = widget->priv;
7671 sensitive = (sensitive != FALSE);
7673 if (priv->sensitive == sensitive)
7676 priv->sensitive = sensitive;
7678 if (priv->parent == NULL
7679 || gtk_widget_is_sensitive (priv->parent))
7683 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7686 data.operation = STATE_CHANGE_UNSET;
7688 data.operation = STATE_CHANGE_SET;
7690 data.use_forall = TRUE;
7692 gtk_widget_propagate_state (widget, &data);
7694 gtk_widget_queue_resize (widget);
7697 g_object_notify (G_OBJECT (widget), "sensitive");
7701 * gtk_widget_get_sensitive:
7702 * @widget: a #GtkWidget
7704 * Returns the widget's sensitivity (in the sense of returning
7705 * the value that has been set using gtk_widget_set_sensitive()).
7707 * The effective sensitivity of a widget is however determined by both its
7708 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7710 * Returns: %TRUE if the widget is sensitive
7715 gtk_widget_get_sensitive (GtkWidget *widget)
7717 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7719 return widget->priv->sensitive;
7723 * gtk_widget_is_sensitive:
7724 * @widget: a #GtkWidget
7726 * Returns the widget's effective sensitivity, which means
7727 * it is sensitive itself and also its parent widget is sensitive
7729 * Returns: %TRUE if the widget is effectively sensitive
7734 gtk_widget_is_sensitive (GtkWidget *widget)
7736 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7738 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
7742 _gtk_widget_update_path (GtkWidget *widget)
7744 if (widget->priv->path)
7746 gtk_widget_path_free (widget->priv->path);
7747 widget->priv->path = NULL;
7750 gtk_widget_get_path (widget);
7754 * gtk_widget_set_parent:
7755 * @widget: a #GtkWidget
7756 * @parent: parent container
7758 * This function is useful only when implementing subclasses of
7760 * Sets the container as the parent of @widget, and takes care of
7761 * some details such as updating the state and style of the child
7762 * to reflect its new location. The opposite function is
7763 * gtk_widget_unparent().
7766 gtk_widget_set_parent (GtkWidget *widget,
7769 GtkStateFlags parent_flags;
7770 GtkWidgetPrivate *priv;
7773 g_return_if_fail (GTK_IS_WIDGET (widget));
7774 g_return_if_fail (GTK_IS_WIDGET (parent));
7775 g_return_if_fail (widget != parent);
7777 priv = widget->priv;
7779 if (priv->parent != NULL)
7781 g_warning ("Can't set a parent on widget which has a parent\n");
7784 if (gtk_widget_is_toplevel (widget))
7786 g_warning ("Can't set a parent on a toplevel widget\n");
7790 /* keep this function in sync with gtk_menu_attach_to_widget()
7793 g_object_ref_sink (widget);
7795 gtk_widget_push_verify_invariants (widget);
7797 priv->parent = parent;
7799 parent_flags = gtk_widget_get_state_flags (parent);
7801 /* Merge both old state and current parent state,
7802 * making sure to only propagate the right states */
7803 data.flags = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
7804 data.flags |= priv->state_flags;
7806 data.operation = STATE_CHANGE_REPLACE;
7807 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7808 gtk_widget_propagate_state (widget, &data);
7810 gtk_widget_reset_style (widget);
7812 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7813 if (priv->parent->priv->anchored)
7814 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7815 g_object_notify (G_OBJECT (widget), "parent");
7817 /* Enforce realized/mapped invariants
7819 if (gtk_widget_get_realized (priv->parent))
7820 gtk_widget_realize (widget);
7822 if (gtk_widget_get_visible (priv->parent) &&
7823 gtk_widget_get_visible (widget))
7825 if (gtk_widget_get_child_visible (widget) &&
7826 gtk_widget_get_mapped (priv->parent))
7827 gtk_widget_map (widget);
7829 gtk_widget_queue_resize (widget);
7832 /* child may cause parent's expand to change, if the child is
7833 * expanded. If child is not expanded, then it can't modify the
7834 * parent's expand. If the child becomes expanded later then it will
7835 * queue compute_expand then. This optimization plus defaulting
7836 * newly-constructed widgets to need_compute_expand=FALSE should
7837 * mean that initially building a widget tree doesn't have to keep
7838 * walking up setting need_compute_expand on parents over and over.
7840 * We can't change a parent to need to expand unless we're visible.
7842 if (gtk_widget_get_visible (widget) &&
7843 (priv->need_compute_expand ||
7844 priv->computed_hexpand ||
7845 priv->computed_vexpand))
7847 gtk_widget_queue_compute_expand (parent);
7850 gtk_widget_pop_verify_invariants (widget);
7854 * gtk_widget_get_parent:
7855 * @widget: a #GtkWidget
7857 * Returns the parent container of @widget.
7859 * Return value: (transfer none): the parent container of @widget, or %NULL
7862 gtk_widget_get_parent (GtkWidget *widget)
7864 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7866 return widget->priv->parent;
7870 modifier_style_changed (GtkModifierStyle *style,
7873 GtkStyleContext *context;
7875 context = gtk_widget_get_style_context (widget);
7876 gtk_style_context_invalidate (context);
7879 static GtkModifierStyle *
7880 _gtk_widget_get_modifier_properties (GtkWidget *widget)
7882 GtkModifierStyle *style;
7884 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
7886 if (G_UNLIKELY (!style))
7888 GtkStyleContext *context;
7890 style = _gtk_modifier_style_new ();
7891 g_object_set_qdata_full (G_OBJECT (widget),
7892 quark_modifier_style,
7894 (GDestroyNotify) g_object_unref);
7896 g_signal_connect (style, "changed",
7897 G_CALLBACK (modifier_style_changed), widget);
7899 context = gtk_widget_get_style_context (widget);
7901 gtk_style_context_add_provider (context,
7902 GTK_STYLE_PROVIDER (style),
7903 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
7910 * gtk_widget_override_color:
7911 * @widget: a #GtkWidget
7912 * @state: the state for which to set the color
7913 * @color: (allow-none): the color to assign, or %NULL to undo the effect
7914 * of previous calls to gtk_widget_override_color()
7916 * Sets the color to use for a widget.
7918 * All other style values are left untouched.
7921 * This API is mostly meant as a quick way for applications to
7922 * change a widget appearance. If you are developing a widgets
7923 * library and intend this change to be themeable, it is better
7924 * done by setting meaningful CSS classes and regions in your
7925 * widget/container implementation through gtk_style_context_add_class()
7926 * and gtk_style_context_add_region().
7928 * This way, your widget library can install a #GtkCssProvider
7929 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
7930 * to provide a default styling for those widgets that need so, and
7931 * this theming may fully overridden by the user's theme.
7934 * Note that for complex widgets this may bring in undesired
7935 * results (such as uniform background color everywhere), in
7936 * these cases it is better to fully style such widgets through a
7937 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
7944 gtk_widget_override_color (GtkWidget *widget,
7945 GtkStateFlags state,
7946 const GdkRGBA *color)
7948 GtkModifierStyle *style;
7950 g_return_if_fail (GTK_IS_WIDGET (widget));
7952 style = _gtk_widget_get_modifier_properties (widget);
7953 _gtk_modifier_style_set_color (style, state, color);
7957 * gtk_widget_override_background_color:
7958 * @widget: a #GtkWidget
7959 * @state: the state for which to set the background color
7960 * @color: (allow-none): the color to assign, or %NULL to undo the effect
7961 * of previous calls to gtk_widget_override_background_color()
7963 * Sets the background color to use for a widget.
7965 * All other style values are left untouched.
7966 * See gtk_widget_override_color().
7971 gtk_widget_override_background_color (GtkWidget *widget,
7972 GtkStateFlags state,
7973 const GdkRGBA *color)
7975 GtkModifierStyle *style;
7977 g_return_if_fail (GTK_IS_WIDGET (widget));
7979 style = _gtk_widget_get_modifier_properties (widget);
7980 _gtk_modifier_style_set_background_color (style, state, color);
7984 * gtk_widget_override_font:
7985 * @widget: a #GtkWidget
7986 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
7987 * the effect of previous calls to gtk_widget_override_font()
7989 * Sets the font to use for a widget. All other style values are
7990 * left untouched. See gtk_widget_override_color().
7995 gtk_widget_override_font (GtkWidget *widget,
7996 const PangoFontDescription *font_desc)
7998 GtkModifierStyle *style;
8000 g_return_if_fail (GTK_IS_WIDGET (widget));
8002 style = _gtk_widget_get_modifier_properties (widget);
8003 _gtk_modifier_style_set_font (style, font_desc);
8007 * gtk_widget_override_symbolic_color:
8008 * @widget: a #GtkWidget
8009 * @name: the name of the symbolic color to modify
8010 * @color: (allow-none): the color to assign (does not need
8011 * to be allocated), or %NULL to undo the effect of previous
8012 * calls to gtk_widget_override_symbolic_color()
8014 * Sets a symbolic color for a widget.
8016 * All other style values are left untouched.
8017 * See gtk_widget_override_color() for overriding the foreground
8018 * or background color.
8023 gtk_widget_override_symbolic_color (GtkWidget *widget,
8025 const GdkRGBA *color)
8027 GtkModifierStyle *style;
8029 g_return_if_fail (GTK_IS_WIDGET (widget));
8031 style = _gtk_widget_get_modifier_properties (widget);
8032 _gtk_modifier_style_map_color (style, name, color);
8036 * gtk_widget_override_cursor:
8037 * @widget: a #GtkWidget
8038 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8039 * allocated), or %NULL to undo the effect of previous calls to
8040 * of gtk_widget_override_cursor().
8041 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8042 * need to be allocated), or %NULL to undo the effect of previous
8043 * calls to of gtk_widget_override_cursor().
8045 * Sets the cursor color to use in a widget, overriding the
8046 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8047 * style properties. All other style values are left untouched.
8048 * See also gtk_widget_modify_style().
8050 * Note that the underlying properties have the #GdkColor type,
8051 * so the alpha value in @primary and @secondary will be ignored.
8056 gtk_widget_override_cursor (GtkWidget *widget,
8057 const GdkRGBA *cursor,
8058 const GdkRGBA *secondary_cursor)
8060 GtkModifierStyle *style;
8062 g_return_if_fail (GTK_IS_WIDGET (widget));
8064 style = _gtk_widget_get_modifier_properties (widget);
8065 _gtk_modifier_style_set_color_property (style,
8067 "cursor-color", cursor);
8068 _gtk_modifier_style_set_color_property (style,
8070 "secondary-cursor-color",
8075 gtk_widget_real_direction_changed (GtkWidget *widget,
8076 GtkTextDirection previous_direction)
8078 gtk_widget_queue_resize (widget);
8082 gtk_widget_real_style_set (GtkWidget *widget,
8083 GtkStyle *previous_style)
8088 GtkWidget *previous_toplevel;
8089 GdkScreen *previous_screen;
8090 GdkScreen *new_screen;
8091 } HierarchyChangedInfo;
8094 do_screen_change (GtkWidget *widget,
8095 GdkScreen *old_screen,
8096 GdkScreen *new_screen)
8098 if (old_screen != new_screen)
8100 GtkWidgetPrivate *priv = widget->priv;
8104 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8106 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8109 _gtk_tooltip_hide (widget);
8111 if (new_screen && priv->context)
8112 gtk_style_context_set_screen (priv->context, new_screen);
8114 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8119 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8120 gpointer client_data)
8122 GtkWidgetPrivate *priv = widget->priv;
8123 HierarchyChangedInfo *info = client_data;
8124 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8125 (priv->parent && priv->parent->priv->anchored);
8127 if (priv->anchored != new_anchored)
8129 g_object_ref (widget);
8131 priv->anchored = new_anchored;
8133 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8134 do_screen_change (widget, info->previous_screen, info->new_screen);
8136 if (GTK_IS_CONTAINER (widget))
8137 gtk_container_forall (GTK_CONTAINER (widget),
8138 gtk_widget_propagate_hierarchy_changed_recurse,
8141 g_object_unref (widget);
8146 * _gtk_widget_propagate_hierarchy_changed:
8147 * @widget: a #GtkWidget
8148 * @previous_toplevel: Previous toplevel
8150 * Propagates changes in the anchored state to a widget and all
8151 * children, unsetting or setting the %ANCHORED flag, and
8152 * emitting #GtkWidget::hierarchy-changed.
8155 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8156 GtkWidget *previous_toplevel)
8158 GtkWidgetPrivate *priv = widget->priv;
8159 HierarchyChangedInfo info;
8161 info.previous_toplevel = previous_toplevel;
8162 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8164 if (gtk_widget_is_toplevel (widget) ||
8165 (priv->parent && priv->parent->priv->anchored))
8166 info.new_screen = gtk_widget_get_screen (widget);
8168 info.new_screen = NULL;
8170 if (info.previous_screen)
8171 g_object_ref (info.previous_screen);
8172 if (previous_toplevel)
8173 g_object_ref (previous_toplevel);
8175 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8177 if (previous_toplevel)
8178 g_object_unref (previous_toplevel);
8179 if (info.previous_screen)
8180 g_object_unref (info.previous_screen);
8184 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8185 gpointer client_data)
8187 HierarchyChangedInfo *info = client_data;
8189 g_object_ref (widget);
8191 do_screen_change (widget, info->previous_screen, info->new_screen);
8193 if (GTK_IS_CONTAINER (widget))
8194 gtk_container_forall (GTK_CONTAINER (widget),
8195 gtk_widget_propagate_screen_changed_recurse,
8198 g_object_unref (widget);
8202 * gtk_widget_is_composited:
8203 * @widget: a #GtkWidget
8205 * Whether @widget can rely on having its alpha channel
8206 * drawn correctly. On X11 this function returns whether a
8207 * compositing manager is running for @widget's screen.
8209 * Please note that the semantics of this call will change
8210 * in the future if used on a widget that has a composited
8211 * window in its hierarchy (as set by gdk_window_set_composited()).
8213 * Return value: %TRUE if the widget can rely on its alpha
8214 * channel being drawn correctly.
8219 gtk_widget_is_composited (GtkWidget *widget)
8223 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8225 screen = gtk_widget_get_screen (widget);
8227 return gdk_screen_is_composited (screen);
8231 propagate_composited_changed (GtkWidget *widget,
8234 if (GTK_IS_CONTAINER (widget))
8236 gtk_container_forall (GTK_CONTAINER (widget),
8237 propagate_composited_changed,
8241 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8245 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8247 propagate_composited_changed (widget, NULL);
8251 * _gtk_widget_propagate_screen_changed:
8252 * @widget: a #GtkWidget
8253 * @previous_screen: Previous screen
8255 * Propagates changes in the screen for a widget to all
8256 * children, emitting #GtkWidget::screen-changed.
8259 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8260 GdkScreen *previous_screen)
8262 HierarchyChangedInfo info;
8264 info.previous_screen = previous_screen;
8265 info.new_screen = gtk_widget_get_screen (widget);
8267 if (previous_screen)
8268 g_object_ref (previous_screen);
8270 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8272 if (previous_screen)
8273 g_object_unref (previous_screen);
8277 reset_style_recurse (GtkWidget *widget, gpointer data)
8279 _gtk_widget_update_path (widget);
8281 if (GTK_IS_CONTAINER (widget))
8282 gtk_container_forall (GTK_CONTAINER (widget),
8283 reset_style_recurse,
8288 * gtk_widget_reset_style:
8289 * @widget: a #GtkWidget
8291 * Updates the style context of @widget and all descendents
8292 * by updating its widget path. #GtkContainer<!-- -->s may want
8293 * to use this on a child when reordering it in a way that a different
8294 * style might apply to it. See also gtk_container_get_path_for_child().
8299 gtk_widget_reset_style (GtkWidget *widget)
8301 g_return_if_fail (GTK_IS_WIDGET (widget));
8303 reset_style_recurse (widget, NULL);
8306 #ifdef G_ENABLE_DEBUG
8308 /* Verify invariants, see docs/widget_system.txt for notes on much of
8309 * this. Invariants may be temporarily broken while we're in the
8310 * process of updating state, of course, so you can only
8311 * verify_invariants() after a given operation is complete.
8312 * Use push/pop_verify_invariants to help with that.
8315 gtk_widget_verify_invariants (GtkWidget *widget)
8319 if (widget->priv->verifying_invariants_count > 0)
8322 parent = widget->priv->parent;
8324 if (widget->priv->mapped)
8326 /* Mapped implies ... */
8328 if (!widget->priv->realized)
8329 g_warning ("%s %p is mapped but not realized",
8330 G_OBJECT_TYPE_NAME (widget), widget);
8332 if (!widget->priv->visible)
8333 g_warning ("%s %p is mapped but not visible",
8334 G_OBJECT_TYPE_NAME (widget), widget);
8336 if (!widget->priv->toplevel)
8338 if (!widget->priv->child_visible)
8339 g_warning ("%s %p is mapped but not child_visible",
8340 G_OBJECT_TYPE_NAME (widget), widget);
8345 /* Not mapped implies... */
8348 /* This check makes sense for normal toplevels, but for
8349 * something like a toplevel that is embedded within a clutter
8350 * state, mapping may depend on external factors.
8352 if (widget->priv->toplevel)
8354 if (widget->priv->visible)
8355 g_warning ("%s %p toplevel is visible but not mapped",
8356 G_OBJECT_TYPE_NAME (widget), widget);
8361 /* Parent related checks aren't possible if parent has
8362 * verifying_invariants_count > 0 because parent needs to recurse
8363 * children first before the invariants will hold.
8365 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8368 parent->priv->realized)
8370 /* Parent realized implies... */
8373 /* This is in widget_system.txt but appears to fail
8374 * because there's no gtk_container_realize() that
8375 * realizes all children... instead we just lazily
8376 * wait for map to fix things up.
8378 if (!widget->priv->realized)
8379 g_warning ("%s %p is realized but child %s %p is not realized",
8380 G_OBJECT_TYPE_NAME (parent), parent,
8381 G_OBJECT_TYPE_NAME (widget), widget);
8384 else if (!widget->priv->toplevel)
8386 /* No parent or parent not realized on non-toplevel implies... */
8388 if (widget->priv->realized && !widget->priv->in_reparent)
8389 g_warning ("%s %p is not realized but child %s %p is realized",
8390 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8391 G_OBJECT_TYPE_NAME (widget), widget);
8395 parent->priv->mapped &&
8396 widget->priv->visible &&
8397 widget->priv->child_visible)
8399 /* Parent mapped and we are visible implies... */
8401 if (!widget->priv->mapped)
8402 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8403 G_OBJECT_TYPE_NAME (parent), parent,
8404 G_OBJECT_TYPE_NAME (widget), widget);
8406 else if (!widget->priv->toplevel)
8408 /* No parent or parent not mapped on non-toplevel implies... */
8410 if (widget->priv->mapped && !widget->priv->in_reparent)
8411 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8412 G_OBJECT_TYPE_NAME (widget), widget,
8413 widget->priv->visible,
8414 widget->priv->child_visible,
8415 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8416 parent ? parent->priv->mapped : FALSE);
8420 if (!widget->priv->realized)
8422 /* Not realized implies... */
8425 /* widget_system.txt says these hold, but they don't. */
8426 if (widget->priv->resize_pending)
8427 g_warning ("%s %p resize pending but not realized",
8428 G_OBJECT_TYPE_NAME (widget), widget);
8430 if (widget->priv->alloc_needed)
8431 g_warning ("%s %p alloc needed but not realized",
8432 G_OBJECT_TYPE_NAME (widget), widget);
8434 if (widget->priv->width_request_needed)
8435 g_warning ("%s %p width request needed but not realized",
8436 G_OBJECT_TYPE_NAME (widget), widget);
8438 if (widget->priv->height_request_needed)
8439 g_warning ("%s %p height request needed but not realized",
8440 G_OBJECT_TYPE_NAME (widget), widget);
8445 /* The point of this push/pop is that invariants may not hold while
8446 * we're busy making changes. So we only check at the outermost call
8447 * on the call stack, after we finish updating everything.
8450 gtk_widget_push_verify_invariants (GtkWidget *widget)
8452 widget->priv->verifying_invariants_count += 1;
8456 gtk_widget_verify_child_invariants (GtkWidget *widget,
8457 gpointer client_data)
8459 /* We don't recurse further; this is a one-level check. */
8460 gtk_widget_verify_invariants (widget);
8464 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8466 g_assert (widget->priv->verifying_invariants_count > 0);
8468 widget->priv->verifying_invariants_count -= 1;
8470 if (widget->priv->verifying_invariants_count == 0)
8472 gtk_widget_verify_invariants (widget);
8474 if (GTK_IS_CONTAINER (widget))
8476 /* Check one level of children, because our
8477 * push_verify_invariants() will have prevented some of the
8478 * checks. This does not recurse because if recursion is
8479 * needed, it will happen naturally as each child has a
8480 * push/pop on that child. For example if we're recursively
8481 * mapping children, we'll push/pop on each child as we map
8484 gtk_container_forall (GTK_CONTAINER (widget),
8485 gtk_widget_verify_child_invariants,
8490 #endif /* G_ENABLE_DEBUG */
8492 static PangoContext *
8493 gtk_widget_peek_pango_context (GtkWidget *widget)
8495 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8499 * gtk_widget_get_pango_context:
8500 * @widget: a #GtkWidget
8502 * Gets a #PangoContext with the appropriate font map, font description,
8503 * and base direction for this widget. Unlike the context returned
8504 * by gtk_widget_create_pango_context(), this context is owned by
8505 * the widget (it can be used until the screen for the widget changes
8506 * or the widget is removed from its toplevel), and will be updated to
8507 * match any changes to the widget's attributes.
8509 * If you create and keep a #PangoLayout using this context, you must
8510 * deal with changes to the context by calling pango_layout_context_changed()
8511 * on the layout in response to the #GtkWidget::style-updated and
8512 * #GtkWidget::direction-changed signals for the widget.
8514 * Return value: (transfer none): the #PangoContext for the widget.
8517 gtk_widget_get_pango_context (GtkWidget *widget)
8519 PangoContext *context;
8521 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8523 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8526 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8527 g_object_set_qdata_full (G_OBJECT (widget),
8528 quark_pango_context,
8537 update_pango_context (GtkWidget *widget,
8538 PangoContext *context)
8540 const PangoFontDescription *font_desc;
8541 GtkStyleContext *style_context;
8543 style_context = gtk_widget_get_style_context (widget);
8545 font_desc = gtk_style_context_get_font (style_context,
8546 gtk_widget_get_state_flags (widget));
8548 pango_context_set_font_description (context, font_desc);
8549 pango_context_set_base_dir (context,
8550 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8551 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8555 gtk_widget_update_pango_context (GtkWidget *widget)
8557 PangoContext *context = gtk_widget_peek_pango_context (widget);
8563 update_pango_context (widget, context);
8565 screen = gtk_widget_get_screen_unchecked (widget);
8568 pango_cairo_context_set_resolution (context,
8569 gdk_screen_get_resolution (screen));
8570 pango_cairo_context_set_font_options (context,
8571 gdk_screen_get_font_options (screen));
8577 * gtk_widget_create_pango_context:
8578 * @widget: a #GtkWidget
8580 * Creates a new #PangoContext with the appropriate font map,
8581 * font description, and base direction for drawing text for
8582 * this widget. See also gtk_widget_get_pango_context().
8584 * Return value: (transfer full): the new #PangoContext
8587 gtk_widget_create_pango_context (GtkWidget *widget)
8590 PangoContext *context;
8592 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8594 screen = gtk_widget_get_screen_unchecked (widget);
8597 GTK_NOTE (MULTIHEAD,
8598 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8600 screen = gdk_screen_get_default ();
8603 context = gdk_pango_context_get_for_screen (screen);
8605 update_pango_context (widget, context);
8606 pango_context_set_language (context, gtk_get_default_language ());
8612 * gtk_widget_create_pango_layout:
8613 * @widget: a #GtkWidget
8614 * @text: text to set on the layout (can be %NULL)
8616 * Creates a new #PangoLayout with the appropriate font map,
8617 * font description, and base direction for drawing text for
8620 * If you keep a #PangoLayout created in this way around, in order to
8621 * notify the layout of changes to the base direction or font of this
8622 * widget, you must call pango_layout_context_changed() in response to
8623 * the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
8626 * Return value: (transfer full): the new #PangoLayout
8629 gtk_widget_create_pango_layout (GtkWidget *widget,
8632 PangoLayout *layout;
8633 PangoContext *context;
8635 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8637 context = gtk_widget_get_pango_context (widget);
8638 layout = pango_layout_new (context);
8641 pango_layout_set_text (layout, text, -1);
8647 * gtk_widget_render_icon_pixbuf:
8648 * @widget: a #GtkWidget
8649 * @stock_id: a stock ID
8650 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8651 * render at the size of the source and don't scale (if there are
8652 * multiple source sizes, GTK+ picks one of the available sizes).
8654 * A convenience function that uses the theme engine and style
8655 * settings for @widget to look up @stock_id and render it to
8656 * a pixbuf. @stock_id should be a stock icon ID such as
8657 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8658 * such as #GTK_ICON_SIZE_MENU.
8660 * The pixels in the returned #GdkPixbuf are shared with the rest of
8661 * the application and should not be modified. The pixbuf should be freed
8662 * after use with g_object_unref().
8664 * Return value: (transfer full): a new pixbuf, or %NULL if the
8665 * stock ID wasn't known
8670 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
8671 const gchar *stock_id,
8674 GtkStyleContext *context;
8675 GtkIconSet *icon_set;
8677 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8678 g_return_val_if_fail (stock_id != NULL, NULL);
8679 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8681 context = gtk_widget_get_style_context (widget);
8682 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
8684 if (icon_set == NULL)
8687 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
8691 * gtk_widget_set_parent_window:
8692 * @widget: a #GtkWidget.
8693 * @parent_window: the new parent window.
8695 * Sets a non default parent window for @widget.
8697 * For GtkWindow classes, setting a @parent_window effects whether
8698 * the window is a toplevel window or can be embedded into other
8702 * For GtkWindow classes, this needs to be called before the
8703 * window is realized.
8708 gtk_widget_set_parent_window (GtkWidget *widget,
8709 GdkWindow *parent_window)
8711 GdkWindow *old_parent_window;
8713 g_return_if_fail (GTK_IS_WIDGET (widget));
8715 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8716 quark_parent_window);
8718 if (parent_window != old_parent_window)
8722 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8724 if (old_parent_window)
8725 g_object_unref (old_parent_window);
8727 g_object_ref (parent_window);
8729 /* Unset toplevel flag when adding a parent window to a widget,
8730 * this is the primary entry point to allow toplevels to be
8733 #ifdef GDK_WINDOWING_X11
8734 is_plug = GTK_IS_PLUG (widget);
8738 if (GTK_IS_WINDOW (widget) && !is_plug)
8739 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
8744 * gtk_widget_get_parent_window:
8745 * @widget: a #GtkWidget.
8747 * Gets @widget's parent window.
8749 * Returns: (transfer none): the parent window of @widget.
8752 gtk_widget_get_parent_window (GtkWidget *widget)
8754 GtkWidgetPrivate *priv;
8755 GdkWindow *parent_window;
8757 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8759 priv = widget->priv;
8761 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8763 return (parent_window != NULL) ? parent_window :
8764 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8769 * gtk_widget_set_child_visible:
8770 * @widget: a #GtkWidget
8771 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8773 * Sets whether @widget should be mapped along with its when its parent
8774 * is mapped and @widget has been shown with gtk_widget_show().
8776 * The child visibility can be set for widget before it is added to
8777 * a container with gtk_widget_set_parent(), to avoid mapping
8778 * children unnecessary before immediately unmapping them. However
8779 * it will be reset to its default state of %TRUE when the widget
8780 * is removed from a container.
8782 * Note that changing the child visibility of a widget does not
8783 * queue a resize on the widget. Most of the time, the size of
8784 * a widget is computed from all visible children, whether or
8785 * not they are mapped. If this is not the case, the container
8786 * can queue a resize itself.
8788 * This function is only useful for container implementations and
8789 * never should be called by an application.
8792 gtk_widget_set_child_visible (GtkWidget *widget,
8793 gboolean is_visible)
8795 GtkWidgetPrivate *priv;
8797 g_return_if_fail (GTK_IS_WIDGET (widget));
8798 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8800 priv = widget->priv;
8802 g_object_ref (widget);
8803 gtk_widget_verify_invariants (widget);
8806 priv->child_visible = TRUE;
8809 GtkWidget *toplevel;
8811 priv->child_visible = FALSE;
8813 toplevel = gtk_widget_get_toplevel (widget);
8814 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8815 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8818 if (priv->parent && gtk_widget_get_realized (priv->parent))
8820 if (gtk_widget_get_mapped (priv->parent) &&
8821 priv->child_visible &&
8822 gtk_widget_get_visible (widget))
8823 gtk_widget_map (widget);
8825 gtk_widget_unmap (widget);
8828 gtk_widget_verify_invariants (widget);
8829 g_object_unref (widget);
8833 * gtk_widget_get_child_visible:
8834 * @widget: a #GtkWidget
8836 * Gets the value set with gtk_widget_set_child_visible().
8837 * If you feel a need to use this function, your code probably
8838 * needs reorganization.
8840 * This function is only useful for container implementations and
8841 * never should be called by an application.
8843 * Return value: %TRUE if the widget is mapped with the parent.
8846 gtk_widget_get_child_visible (GtkWidget *widget)
8848 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8850 return widget->priv->child_visible;
8854 gtk_widget_get_screen_unchecked (GtkWidget *widget)
8856 GtkWidget *toplevel;
8858 toplevel = gtk_widget_get_toplevel (widget);
8860 if (gtk_widget_is_toplevel (toplevel))
8862 if (GTK_IS_WINDOW (toplevel))
8863 return gtk_window_get_screen (GTK_WINDOW (toplevel));
8864 else if (GTK_IS_INVISIBLE (toplevel))
8865 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
8872 * gtk_widget_get_screen:
8873 * @widget: a #GtkWidget
8875 * Get the #GdkScreen from the toplevel window associated with
8876 * this widget. This function can only be called after the widget
8877 * has been added to a widget hierarchy with a #GtkWindow
8880 * In general, you should only create screen specific
8881 * resources when a widget has been realized, and you should
8882 * free those resources when the widget is unrealized.
8884 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
8889 gtk_widget_get_screen (GtkWidget *widget)
8893 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8895 screen = gtk_widget_get_screen_unchecked (widget);
8902 g_warning (G_STRLOC ": Can't get associated screen"
8903 " for a widget unless it is inside a toplevel GtkWindow\n"
8904 " widget type is %s associated top level type is %s",
8905 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
8906 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
8908 return gdk_screen_get_default ();
8913 * gtk_widget_has_screen:
8914 * @widget: a #GtkWidget
8916 * Checks whether there is a #GdkScreen is associated with
8917 * this widget. All toplevel widgets have an associated
8918 * screen, and all widgets added into a hierarchy with a toplevel
8919 * window at the top.
8921 * Return value: %TRUE if there is a #GdkScreen associcated
8927 gtk_widget_has_screen (GtkWidget *widget)
8929 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8931 return (gtk_widget_get_screen_unchecked (widget) != NULL);
8935 * gtk_widget_get_display:
8936 * @widget: a #GtkWidget
8938 * Get the #GdkDisplay for the toplevel window associated with
8939 * this widget. This function can only be called after the widget
8940 * has been added to a widget hierarchy with a #GtkWindow at the top.
8942 * In general, you should only create display specific
8943 * resources when a widget has been realized, and you should
8944 * free those resources when the widget is unrealized.
8946 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
8951 gtk_widget_get_display (GtkWidget *widget)
8953 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8955 return gdk_screen_get_display (gtk_widget_get_screen (widget));
8959 * gtk_widget_get_root_window:
8960 * @widget: a #GtkWidget
8962 * Get the root window where this widget is located. This function can
8963 * only be called after the widget has been added to a widget
8964 * hierarchy with #GtkWindow at the top.
8966 * The root window is useful for such purposes as creating a popup
8967 * #GdkWindow associated with the window. In general, you should only
8968 * create display specific resources when a widget has been realized,
8969 * and you should free those resources when the widget is unrealized.
8971 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
8976 gtk_widget_get_root_window (GtkWidget *widget)
8978 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8980 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
8984 * gtk_widget_child_focus:
8985 * @widget: a #GtkWidget
8986 * @direction: direction of focus movement
8988 * This function is used by custom widget implementations; if you're
8989 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
8990 * to a particular widget, and gtk_container_set_focus_chain() to
8991 * change the focus tab order. So you may want to investigate those
8992 * functions instead.
8994 * gtk_widget_child_focus() is called by containers as the user moves
8995 * around the window using keyboard shortcuts. @direction indicates
8996 * what kind of motion is taking place (up, down, left, right, tab
8997 * forward, tab backward). gtk_widget_child_focus() emits the
8998 * #GtkWidget::focus signal; widgets override the default handler
8999 * for this signal in order to implement appropriate focus behavior.
9001 * The default ::focus handler for a widget should return %TRUE if
9002 * moving in @direction left the focus on a focusable location inside
9003 * that widget, and %FALSE if moving in @direction moved the focus
9004 * outside the widget. If returning %TRUE, widgets normally
9005 * call gtk_widget_grab_focus() to place the focus accordingly;
9006 * if returning %FALSE, they don't modify the current focus location.
9008 * Return value: %TRUE if focus ended up inside @widget
9011 gtk_widget_child_focus (GtkWidget *widget,
9012 GtkDirectionType direction)
9014 gboolean return_val;
9016 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9018 if (!gtk_widget_get_visible (widget) ||
9019 !gtk_widget_is_sensitive (widget))
9022 /* child widgets must set CAN_FOCUS, containers
9023 * don't have to though.
9025 if (!GTK_IS_CONTAINER (widget) &&
9026 !gtk_widget_get_can_focus (widget))
9029 g_signal_emit (widget,
9030 widget_signals[FOCUS],
9032 direction, &return_val);
9038 * gtk_widget_keynav_failed:
9039 * @widget: a #GtkWidget
9040 * @direction: direction of focus movement
9042 * This function should be called whenever keyboard navigation within
9043 * a single widget hits a boundary. The function emits the
9044 * #GtkWidget::keynav-failed signal on the widget and its return
9045 * value should be interpreted in a way similar to the return value of
9046 * gtk_widget_child_focus():
9048 * When %TRUE is returned, stay in the widget, the failed keyboard
9049 * navigation is Ok and/or there is nowhere we can/should move the
9052 * When %FALSE is returned, the caller should continue with keyboard
9053 * navigation outside the widget, e.g. by calling
9054 * gtk_widget_child_focus() on the widget's toplevel.
9056 * The default ::keynav-failed handler returns %TRUE for
9057 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9058 * values of #GtkDirectionType, it looks at the
9059 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9060 * if the setting is %TRUE. This way the entire user interface
9061 * becomes cursor-navigatable on input devices such as mobile phones
9062 * which only have cursor keys but no tab key.
9064 * Whenever the default handler returns %TRUE, it also calls
9065 * gtk_widget_error_bell() to notify the user of the failed keyboard
9068 * A use case for providing an own implementation of ::keynav-failed
9069 * (either by connecting to it or by overriding it) would be a row of
9070 * #GtkEntry widgets where the user should be able to navigate the
9071 * entire row with the cursor keys, as e.g. known from user interfaces
9072 * that require entering license keys.
9074 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9075 * if the emitting widget should try to handle the keyboard
9076 * navigation attempt in its parent container(s).
9081 gtk_widget_keynav_failed (GtkWidget *widget,
9082 GtkDirectionType direction)
9084 gboolean return_val;
9086 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9088 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9089 direction, &return_val);
9095 * gtk_widget_error_bell:
9096 * @widget: a #GtkWidget
9098 * Notifies the user about an input-related error on this widget.
9099 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9100 * gdk_window_beep(), otherwise it does nothing.
9102 * Note that the effect of gdk_window_beep() can be configured in many
9103 * ways, depending on the windowing backend and the desktop environment
9104 * or window manager that is used.
9109 gtk_widget_error_bell (GtkWidget *widget)
9111 GtkWidgetPrivate *priv;
9112 GtkSettings* settings;
9115 g_return_if_fail (GTK_IS_WIDGET (widget));
9117 priv = widget->priv;
9119 settings = gtk_widget_get_settings (widget);
9123 g_object_get (settings,
9124 "gtk-error-bell", &beep,
9127 if (beep && priv->window)
9128 gdk_window_beep (priv->window);
9132 gtk_widget_set_usize_internal (GtkWidget *widget,
9135 GtkQueueResizeFlags flags)
9137 GtkWidgetAuxInfo *aux_info;
9138 gboolean changed = FALSE;
9140 g_object_freeze_notify (G_OBJECT (widget));
9142 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9144 if (width > -2 && aux_info->width != width)
9146 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9147 g_object_notify (G_OBJECT (widget), "width-request");
9148 aux_info->width = width;
9151 if (height > -2 && aux_info->height != height)
9153 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9154 g_object_notify (G_OBJECT (widget), "height-request");
9155 aux_info->height = height;
9159 if (gtk_widget_get_visible (widget) && changed)
9161 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9162 gtk_widget_queue_resize (widget);
9164 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9167 g_object_thaw_notify (G_OBJECT (widget));
9171 * gtk_widget_set_size_request:
9172 * @widget: a #GtkWidget
9173 * @width: width @widget should request, or -1 to unset
9174 * @height: height @widget should request, or -1 to unset
9176 * Sets the minimum size of a widget; that is, the widget's size
9177 * request will be @width by @height. You can use this function to
9178 * force a widget to be either larger or smaller than it normally
9181 * In most cases, gtk_window_set_default_size() is a better choice for
9182 * toplevel windows than this function; setting the default size will
9183 * still allow users to shrink the window. Setting the size request
9184 * will force them to leave the window at least as large as the size
9185 * request. When dealing with window sizes,
9186 * gtk_window_set_geometry_hints() can be a useful function as well.
9188 * Note the inherent danger of setting any fixed size - themes,
9189 * translations into other languages, different fonts, and user action
9190 * can all change the appropriate size for a given widget. So, it's
9191 * basically impossible to hardcode a size that will always be
9194 * The size request of a widget is the smallest size a widget can
9195 * accept while still functioning well and drawing itself correctly.
9196 * However in some strange cases a widget may be allocated less than
9197 * its requested size, and in many cases a widget may be allocated more
9198 * space than it requested.
9200 * If the size request in a given direction is -1 (unset), then
9201 * the "natural" size request of the widget will be used instead.
9203 * Widgets can't actually be allocated a size less than 1 by 1, but
9204 * you can pass 0,0 to this function to mean "as small as possible."
9206 * The size request set here does not include any margin from the
9207 * #GtkWidget properties margin-left, margin-right, margin-top, and
9208 * margin-bottom, but it does include pretty much all other padding
9209 * or border properties set by any subclass of #GtkWidget.
9212 gtk_widget_set_size_request (GtkWidget *widget,
9216 g_return_if_fail (GTK_IS_WIDGET (widget));
9217 g_return_if_fail (width >= -1);
9218 g_return_if_fail (height >= -1);
9225 gtk_widget_set_usize_internal (widget, width, height, 0);
9230 * gtk_widget_get_size_request:
9231 * @widget: a #GtkWidget
9232 * @width: (out) (allow-none): return location for width, or %NULL
9233 * @height: (out) (allow-none): return location for height, or %NULL
9235 * Gets the size request that was explicitly set for the widget using
9236 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9237 * @height indicates that that dimension has not been set explicitly
9238 * and the natural requisition of the widget will be used intead. See
9239 * gtk_widget_set_size_request(). To get the size a widget will
9240 * actually request, call gtk_widget_get_preferred_size() instead of
9244 gtk_widget_get_size_request (GtkWidget *widget,
9248 const GtkWidgetAuxInfo *aux_info;
9250 g_return_if_fail (GTK_IS_WIDGET (widget));
9252 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9255 *width = aux_info->width;
9258 *height = aux_info->height;
9262 * _gtk_widget_override_size_request:
9263 * @widget: a #GtkWidget
9264 * @width: new forced minimum width
9265 * @height: new forced minimum height
9266 * @old_width: location to store previous forced minimum width
9267 * @old_width: location to store previous forced minumum height
9269 * Temporarily establishes a forced minimum size for a widget; this
9270 * is used by GtkWindow when calculating the size to add to the
9271 * window's geometry widget. Cached sizes for the widget and its
9272 * parents are invalidated, so that subsequent calls to the size
9273 * negotiation machinery produce the overriden result, but the
9274 * widget is not queued for relayout or redraw. The old size must
9275 * be restored with _gtk_widget_restore_size_request() or things
9279 _gtk_widget_override_size_request (GtkWidget *widget,
9285 gtk_widget_get_size_request (widget, old_width, old_height);
9286 gtk_widget_set_usize_internal (widget, width, height,
9287 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9291 * _gtk_widget_restore_size_request:
9292 * @widget: a #GtkWidget
9293 * @old_width: saved forced minimum size
9294 * @old_height: saved forced minimum size
9296 * Undoes the operation of_gtk_widget_override_size_request().
9299 _gtk_widget_restore_size_request (GtkWidget *widget,
9303 gtk_widget_set_usize_internal (widget, old_width, old_height,
9304 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9308 * gtk_widget_set_events:
9309 * @widget: a #GtkWidget
9310 * @events: event mask
9312 * Sets the event mask (see #GdkEventMask) for a widget. The event
9313 * mask determines which events a widget will receive. Keep in mind
9314 * that different widgets have different default event masks, and by
9315 * changing the event mask you may disrupt a widget's functionality,
9316 * so be careful. This function must be called while a widget is
9317 * unrealized. Consider gtk_widget_add_events() for widgets that are
9318 * already realized, or if you want to preserve the existing event
9319 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9320 * to get events on those widgets, place them inside a #GtkEventBox
9321 * and receive events on the event box.
9324 gtk_widget_set_events (GtkWidget *widget,
9327 g_return_if_fail (GTK_IS_WIDGET (widget));
9328 g_return_if_fail (!gtk_widget_get_realized (widget));
9330 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9331 GINT_TO_POINTER (events));
9332 g_object_notify (G_OBJECT (widget), "events");
9336 * gtk_widget_set_device_events:
9337 * @widget: a #GtkWidget
9338 * @device: a #GdkDevice
9339 * @events: event mask
9341 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9342 * mask determines which events a widget will receive from @device. Keep
9343 * in mind that different widgets have different default event masks, and by
9344 * changing the event mask you may disrupt a widget's functionality,
9345 * so be careful. This function must be called while a widget is
9346 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9347 * already realized, or if you want to preserve the existing event
9348 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9349 * to get events on those widgets, place them inside a #GtkEventBox
9350 * and receive events on the event box.
9355 gtk_widget_set_device_events (GtkWidget *widget,
9357 GdkEventMask events)
9359 GHashTable *device_events;
9361 g_return_if_fail (GTK_IS_WIDGET (widget));
9362 g_return_if_fail (GDK_IS_DEVICE (device));
9363 g_return_if_fail (!gtk_widget_get_realized (widget));
9365 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9367 if (G_UNLIKELY (!device_events))
9369 device_events = g_hash_table_new (NULL, NULL);
9370 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9371 (GDestroyNotify) g_hash_table_unref);
9374 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9378 * gtk_widget_set_device_enabled:
9379 * @widget: a #GtkWidget
9380 * @device: a #GdkDevice
9381 * @enabled: whether to enable the device
9383 * Enables or disables a #GdkDevice to interact with @widget
9384 * and all its children.
9386 * It does so by descending through the #GdkWindow hierarchy
9387 * and enabling the same mask that is has for core events
9388 * (i.e. the one that gdk_window_get_events() returns).
9393 gtk_widget_set_device_enabled (GtkWidget *widget,
9397 GList *enabled_devices;
9399 g_return_if_fail (GTK_IS_WIDGET (widget));
9400 g_return_if_fail (GDK_IS_DEVICE (device));
9402 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9403 enabled_devices = g_list_append (enabled_devices, device);
9405 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9406 enabled_devices, (GDestroyNotify) g_list_free);;
9408 if (gtk_widget_get_realized (widget))
9409 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9413 * gtk_widget_get_device_enabled:
9414 * @widget: a #GtkWidget
9415 * @device: a #GdkDevice
9417 * Returns whether @device can interact with @widget and its
9418 * children. See gtk_widget_set_device_enabled().
9420 * Return value: %TRUE is @device is enabled for @widget
9425 gtk_widget_get_device_enabled (GtkWidget *widget,
9428 GList *enabled_devices;
9430 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9431 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9433 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9435 return g_list_find (enabled_devices, device) != NULL;
9439 gtk_widget_add_events_internal_list (GtkWidget *widget,
9446 for (l = window_list; l != NULL; l = l->next)
9448 GdkWindow *window = l->data;
9451 gdk_window_get_user_data (window, &user_data);
9452 if (user_data == widget)
9457 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9459 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9461 children = gdk_window_get_children (window);
9462 gtk_widget_add_events_internal_list (widget, device, events, children);
9463 g_list_free (children);
9469 gtk_widget_add_events_internal (GtkWidget *widget,
9473 GtkWidgetPrivate *priv = widget->priv;
9476 if (!gtk_widget_get_has_window (widget))
9477 window_list = gdk_window_get_children (priv->window);
9479 window_list = g_list_prepend (NULL, priv->window);
9481 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9483 g_list_free (window_list);
9487 * gtk_widget_add_events:
9488 * @widget: a #GtkWidget
9489 * @events: an event mask, see #GdkEventMask
9491 * Adds the events in the bitfield @events to the event mask for
9492 * @widget. See gtk_widget_set_events() for details.
9495 gtk_widget_add_events (GtkWidget *widget,
9500 g_return_if_fail (GTK_IS_WIDGET (widget));
9502 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9503 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9504 GINT_TO_POINTER (old_events | events));
9506 if (gtk_widget_get_realized (widget))
9508 gtk_widget_add_events_internal (widget, NULL, events);
9509 gtk_widget_update_devices_mask (widget, FALSE);
9512 g_object_notify (G_OBJECT (widget), "events");
9516 * gtk_widget_add_device_events:
9517 * @widget: a #GtkWidget
9518 * @device: a #GdkDevice
9519 * @events: an event mask, see #GdkEventMask
9521 * Adds the device events in the bitfield @events to the event mask for
9522 * @widget. See gtk_widget_set_device_events() for details.
9527 gtk_widget_add_device_events (GtkWidget *widget,
9529 GdkEventMask events)
9531 GdkEventMask old_events;
9532 GHashTable *device_events;
9534 g_return_if_fail (GTK_IS_WIDGET (widget));
9535 g_return_if_fail (GDK_IS_DEVICE (device));
9537 old_events = gtk_widget_get_device_events (widget, device);
9539 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9541 if (G_UNLIKELY (!device_events))
9543 device_events = g_hash_table_new (NULL, NULL);
9544 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9545 (GDestroyNotify) g_hash_table_unref);
9548 g_hash_table_insert (device_events, device,
9549 GUINT_TO_POINTER (old_events | events));
9551 if (gtk_widget_get_realized (widget))
9552 gtk_widget_add_events_internal (widget, device, events);
9554 g_object_notify (G_OBJECT (widget), "events");
9558 * gtk_widget_get_toplevel:
9559 * @widget: a #GtkWidget
9561 * This function returns the topmost widget in the container hierarchy
9562 * @widget is a part of. If @widget has no parent widgets, it will be
9563 * returned as the topmost widget. No reference will be added to the
9564 * returned widget; it should not be unreferenced.
9566 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9567 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9569 * %NULL if @widget wasn't inside a toplevel window, and if the
9570 * window was inside a #GtkWindow-derived widget which was in turn
9571 * inside the toplevel #GtkWindow. While the second case may
9572 * seem unlikely, it actually happens when a #GtkPlug is embedded
9573 * inside a #GtkSocket within the same application.
9575 * To reliably find the toplevel #GtkWindow, use
9576 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9577 * is set on the result.
9579 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9580 * if (gtk_widget_is_toplevel (toplevel))
9582 * /* Perform action on toplevel. */
9586 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9587 * if there's no ancestor.
9590 gtk_widget_get_toplevel (GtkWidget *widget)
9592 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9594 while (widget->priv->parent)
9595 widget = widget->priv->parent;
9601 * gtk_widget_get_ancestor:
9602 * @widget: a #GtkWidget
9603 * @widget_type: ancestor type
9605 * Gets the first ancestor of @widget with type @widget_type. For example,
9606 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9607 * the first #GtkBox that's an ancestor of @widget. No reference will be
9608 * added to the returned widget; it should not be unreferenced. See note
9609 * about checking for a toplevel #GtkWindow in the docs for
9610 * gtk_widget_get_toplevel().
9612 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9613 * considers @widget to be an ancestor of itself.
9615 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9618 gtk_widget_get_ancestor (GtkWidget *widget,
9621 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9623 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9624 widget = widget->priv->parent;
9626 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9633 * gtk_widget_set_visual:
9634 * @widget: a #GtkWidget
9635 * @visual: visual to be used or %NULL to unset a previous one
9637 * Sets the visual that should be used for by widget and its children for
9638 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9639 * returned by gdk_widget_get_screen(), so handling the
9640 * #GtkWidget::screen-changed signal is necessary.
9642 * Setting a new @visual will not cause @widget to recreate its windows,
9643 * so you should call this function before @widget is realized.
9646 gtk_widget_set_visual (GtkWidget *widget,
9649 g_return_if_fail (GTK_IS_WIDGET (widget));
9650 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9653 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9656 g_object_set_qdata_full (G_OBJECT (widget),
9658 g_object_ref (visual),
9663 * gtk_widget_get_visual:
9664 * @widget: a #GtkWidget
9666 * Gets the visual that will be used to render @widget.
9668 * Return value: (transfer none): the visual for @widget
9671 gtk_widget_get_visual (GtkWidget *widget)
9677 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9679 if (gtk_widget_get_has_window (widget) &&
9680 widget->priv->window)
9681 return gdk_window_get_visual (widget->priv->window);
9683 screen = gtk_widget_get_screen (widget);
9685 for (w = widget; w != NULL; w = w->priv->parent)
9687 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9690 if (gdk_visual_get_screen (visual) == screen)
9693 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9694 gtk_widget_get_name (widget));
9698 return gdk_screen_get_system_visual (screen);
9702 * gtk_widget_get_settings:
9703 * @widget: a #GtkWidget
9705 * Gets the settings object holding the settings used for this widget.
9707 * Note that this function can only be called when the #GtkWidget
9708 * is attached to a toplevel, since the settings object is specific
9709 * to a particular #GdkScreen.
9711 * Return value: (transfer none): the relevant #GtkSettings object
9714 gtk_widget_get_settings (GtkWidget *widget)
9716 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9718 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9722 * gtk_widget_get_events:
9723 * @widget: a #GtkWidget
9725 * Returns the event mask for the widget (a bitfield containing flags
9726 * from the #GdkEventMask enumeration). These are the events that the widget
9729 * Return value: event mask for @widget
9732 gtk_widget_get_events (GtkWidget *widget)
9734 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9736 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9740 * gtk_widget_get_device_events:
9741 * @widget: a #GtkWidget
9742 * @device: a #GdkDevice
9744 * Returns the events mask for the widget corresponding to an specific device. These
9745 * are the events that the widget will receive when @device operates on it.
9747 * Returns: device event mask for @widget
9752 gtk_widget_get_device_events (GtkWidget *widget,
9755 GHashTable *device_events;
9757 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9758 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9760 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9765 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9769 * gtk_widget_get_pointer:
9770 * @widget: a #GtkWidget
9771 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9772 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9774 * Obtains the location of the mouse pointer in widget coordinates.
9775 * Widget coordinates are a bit odd; for historical reasons, they are
9776 * defined as @widget->window coordinates for widgets that are not
9777 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9778 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9780 * Deprecated: 3.4: Use gdk_window_get_device_position() instead.
9783 gtk_widget_get_pointer (GtkWidget *widget,
9787 GtkWidgetPrivate *priv;
9789 g_return_if_fail (GTK_IS_WIDGET (widget));
9791 priv = widget->priv;
9798 if (gtk_widget_get_realized (widget))
9800 gdk_window_get_device_position (priv->window,
9801 gdk_device_manager_get_client_pointer (
9802 gdk_display_get_device_manager (
9803 gtk_widget_get_display (widget))),
9806 if (!gtk_widget_get_has_window (widget))
9809 *x -= priv->allocation.x;
9811 *y -= priv->allocation.y;
9817 * gtk_widget_is_ancestor:
9818 * @widget: a #GtkWidget
9819 * @ancestor: another #GtkWidget
9821 * Determines whether @widget is somewhere inside @ancestor, possibly with
9822 * intermediate containers.
9824 * Return value: %TRUE if @ancestor contains @widget as a child,
9825 * grandchild, great grandchild, etc.
9828 gtk_widget_is_ancestor (GtkWidget *widget,
9829 GtkWidget *ancestor)
9831 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9832 g_return_val_if_fail (ancestor != NULL, FALSE);
9836 if (widget->priv->parent == ancestor)
9838 widget = widget->priv->parent;
9844 static GQuark quark_composite_name = 0;
9847 * gtk_widget_set_composite_name:
9848 * @widget: a #GtkWidget.
9849 * @name: the name to set
9851 * Sets a widgets composite name. The widget must be
9852 * a composite child of its parent; see gtk_widget_push_composite_child().
9855 gtk_widget_set_composite_name (GtkWidget *widget,
9858 g_return_if_fail (GTK_IS_WIDGET (widget));
9859 g_return_if_fail (widget->priv->composite_child);
9860 g_return_if_fail (name != NULL);
9862 if (!quark_composite_name)
9863 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
9865 g_object_set_qdata_full (G_OBJECT (widget),
9866 quark_composite_name,
9872 * gtk_widget_get_composite_name:
9873 * @widget: a #GtkWidget
9875 * Obtains the composite name of a widget.
9877 * Returns: the composite name of @widget, or %NULL if @widget is not
9878 * a composite child. The string should be freed when it is no
9882 gtk_widget_get_composite_name (GtkWidget *widget)
9884 GtkWidgetPrivate *priv;
9886 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9888 priv = widget->priv;
9890 if (widget->priv->composite_child && priv->parent)
9891 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
9898 * gtk_widget_push_composite_child:
9900 * Makes all newly-created widgets as composite children until
9901 * the corresponding gtk_widget_pop_composite_child() call.
9903 * A composite child is a child that's an implementation detail of the
9904 * container it's inside and should not be visible to people using the
9905 * container. Composite children aren't treated differently by GTK (but
9906 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
9907 * builders might want to treat them in a different way.
9909 * Here is a simple example:
9911 * gtk_widget_push_composite_child ();
9912 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
9913 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
9914 * gtk_widget_pop_composite_child ();
9915 * gtk_widget_set_parent (scrolled_window->hscrollbar,
9916 * GTK_WIDGET (scrolled_window));
9917 * g_object_ref (scrolled_window->hscrollbar);
9921 gtk_widget_push_composite_child (void)
9923 composite_child_stack++;
9927 * gtk_widget_pop_composite_child:
9929 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
9932 gtk_widget_pop_composite_child (void)
9934 if (composite_child_stack)
9935 composite_child_stack--;
9939 gtk_widget_emit_direction_changed (GtkWidget *widget,
9940 GtkTextDirection old_dir)
9942 gtk_widget_update_pango_context (widget);
9944 if (widget->priv->context)
9945 gtk_style_context_set_direction (widget->priv->context,
9946 gtk_widget_get_direction (widget));
9948 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
9952 * gtk_widget_set_direction:
9953 * @widget: a #GtkWidget
9954 * @dir: the new direction
9956 * Sets the reading direction on a particular widget. This direction
9957 * controls the primary direction for widgets containing text,
9958 * and also the direction in which the children of a container are
9959 * packed. The ability to set the direction is present in order
9960 * so that correct localization into languages with right-to-left
9961 * reading directions can be done. Generally, applications will
9962 * let the default reading direction present, except for containers
9963 * where the containers are arranged in an order that is explicitely
9964 * visual rather than logical (such as buttons for text justification).
9966 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
9967 * set by gtk_widget_set_default_direction() will be used.
9970 gtk_widget_set_direction (GtkWidget *widget,
9971 GtkTextDirection dir)
9973 GtkTextDirection old_dir;
9975 g_return_if_fail (GTK_IS_WIDGET (widget));
9976 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
9978 old_dir = gtk_widget_get_direction (widget);
9980 widget->priv->direction = dir;
9982 if (old_dir != gtk_widget_get_direction (widget))
9983 gtk_widget_emit_direction_changed (widget, old_dir);
9987 * gtk_widget_get_direction:
9988 * @widget: a #GtkWidget
9990 * Gets the reading direction for a particular widget. See
9991 * gtk_widget_set_direction().
9993 * Return value: the reading direction for the widget.
9996 gtk_widget_get_direction (GtkWidget *widget)
9998 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10000 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10001 return gtk_default_direction;
10003 return widget->priv->direction;
10007 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10009 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10011 g_object_ref (widget);
10013 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10014 gtk_widget_emit_direction_changed (widget, old_dir);
10016 if (GTK_IS_CONTAINER (widget))
10017 gtk_container_forall (GTK_CONTAINER (widget),
10018 gtk_widget_set_default_direction_recurse,
10021 g_object_unref (widget);
10025 * gtk_widget_set_default_direction:
10026 * @dir: the new default direction. This cannot be
10027 * %GTK_TEXT_DIR_NONE.
10029 * Sets the default reading direction for widgets where the
10030 * direction has not been explicitly set by gtk_widget_set_direction().
10033 gtk_widget_set_default_direction (GtkTextDirection dir)
10035 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10037 if (dir != gtk_default_direction)
10039 GList *toplevels, *tmp_list;
10040 GtkTextDirection old_dir = gtk_default_direction;
10042 gtk_default_direction = dir;
10044 tmp_list = toplevels = gtk_window_list_toplevels ();
10045 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10049 gtk_widget_set_default_direction_recurse (tmp_list->data,
10050 GUINT_TO_POINTER (old_dir));
10051 g_object_unref (tmp_list->data);
10052 tmp_list = tmp_list->next;
10055 g_list_free (toplevels);
10060 * gtk_widget_get_default_direction:
10062 * Obtains the current default reading direction. See
10063 * gtk_widget_set_default_direction().
10065 * Return value: the current default direction.
10068 gtk_widget_get_default_direction (void)
10070 return gtk_default_direction;
10074 gtk_widget_dispose (GObject *object)
10076 GtkWidget *widget = GTK_WIDGET (object);
10077 GtkWidgetPrivate *priv = widget->priv;
10080 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10081 else if (gtk_widget_get_visible (widget))
10082 gtk_widget_hide (widget);
10084 priv->visible = FALSE;
10085 if (gtk_widget_get_realized (widget))
10086 gtk_widget_unrealize (widget);
10088 if (!priv->in_destruction)
10090 priv->in_destruction = TRUE;
10091 g_signal_emit (object, widget_signals[DESTROY], 0);
10092 priv->in_destruction = FALSE;
10095 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10099 gtk_widget_real_destroy (GtkWidget *object)
10101 /* gtk_object_destroy() will already hold a refcount on object */
10102 GtkWidget *widget = GTK_WIDGET (object);
10103 GtkWidgetPrivate *priv = widget->priv;
10105 if (GTK_WIDGET_GET_CLASS (widget)->priv->accessible_type != GTK_TYPE_ACCESSIBLE)
10107 GtkAccessible *accessible = g_object_steal_qdata (G_OBJECT (widget), quark_accessible_object);
10111 gtk_accessible_set_widget (accessible, NULL);
10112 g_object_unref (accessible);
10116 /* wipe accelerator closures (keep order) */
10117 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10118 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10120 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10121 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10123 gtk_grab_remove (widget);
10126 g_object_unref (priv->style);
10127 priv->style = gtk_widget_get_default_style ();
10128 g_object_ref (priv->style);
10132 gtk_widget_finalize (GObject *object)
10134 GtkWidget *widget = GTK_WIDGET (object);
10135 GtkWidgetPrivate *priv = widget->priv;
10136 GtkWidgetAuxInfo *aux_info;
10137 GtkAccessible *accessible;
10139 gtk_grab_remove (widget);
10141 g_object_unref (priv->style);
10142 priv->style = NULL;
10144 g_free (priv->name);
10146 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10148 gtk_widget_aux_info_destroy (aux_info);
10150 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10152 g_object_unref (accessible);
10155 gtk_widget_path_free (priv->path);
10158 g_object_unref (priv->context);
10160 _gtk_widget_free_cached_sizes (widget);
10162 if (g_object_is_floating (object))
10163 g_warning ("A floating object was finalized. This means that someone\n"
10164 "called g_object_unref() on an object that had only a floating\n"
10165 "reference; the initial floating reference is not owned by anyone\n"
10166 "and must be removed with g_object_ref_sink().");
10168 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10171 /*****************************************
10172 * gtk_widget_real_map:
10177 *****************************************/
10180 gtk_widget_real_map (GtkWidget *widget)
10182 GtkWidgetPrivate *priv = widget->priv;
10184 g_assert (gtk_widget_get_realized (widget));
10186 if (!gtk_widget_get_mapped (widget))
10188 gtk_widget_set_mapped (widget, TRUE);
10190 if (gtk_widget_get_has_window (widget))
10191 gdk_window_show (priv->window);
10195 /*****************************************
10196 * gtk_widget_real_unmap:
10201 *****************************************/
10204 gtk_widget_real_unmap (GtkWidget *widget)
10206 GtkWidgetPrivate *priv = widget->priv;
10208 if (gtk_widget_get_mapped (widget))
10210 gtk_widget_set_mapped (widget, FALSE);
10212 if (gtk_widget_get_has_window (widget))
10213 gdk_window_hide (priv->window);
10217 /*****************************************
10218 * gtk_widget_real_realize:
10223 *****************************************/
10226 gtk_widget_real_realize (GtkWidget *widget)
10228 GtkWidgetPrivate *priv = widget->priv;
10230 g_assert (!gtk_widget_get_has_window (widget));
10232 gtk_widget_set_realized (widget, TRUE);
10235 priv->window = gtk_widget_get_parent_window (widget);
10236 g_object_ref (priv->window);
10240 /*****************************************
10241 * gtk_widget_real_unrealize:
10246 *****************************************/
10249 gtk_widget_real_unrealize (GtkWidget *widget)
10251 GtkWidgetPrivate *priv = widget->priv;
10253 g_assert (!widget->priv->mapped);
10255 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10258 /* We must do unrealize child widget BEFORE container widget.
10259 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10260 * So, unrealizing container widget bofore its children causes the problem
10261 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10264 if (GTK_IS_CONTAINER (widget))
10265 gtk_container_forall (GTK_CONTAINER (widget),
10266 (GtkCallback) gtk_widget_unrealize,
10269 if (gtk_widget_get_has_window (widget))
10271 gdk_window_set_user_data (priv->window, NULL);
10272 gdk_window_destroy (priv->window);
10273 priv->window = NULL;
10277 g_object_unref (priv->window);
10278 priv->window = NULL;
10281 gtk_selection_remove_all (widget);
10283 gtk_widget_set_realized (widget, FALSE);
10287 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10288 GtkOrientation orientation,
10289 gint *minimum_size,
10290 gint *natural_size)
10292 const GtkWidgetAuxInfo *aux_info;
10294 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10296 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10297 aux_info->width > 0)
10299 *minimum_size = MAX (*minimum_size, aux_info->width);
10301 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10302 aux_info->height > 0)
10304 *minimum_size = MAX (*minimum_size, aux_info->height);
10307 /* Fix it if set_size_request made natural size smaller than min size.
10308 * This would also silently fix broken widgets, but we warn about them
10309 * in gtksizerequest.c when calling their size request vfuncs.
10311 *natural_size = MAX (*natural_size, *minimum_size);
10313 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10315 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10316 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10320 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10321 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10326 * _gtk_widget_peek_request_cache:
10328 * Returns the address of the widget's request cache (strictly for
10329 * internal use in gtksizerequest.c)
10331 * Return value: the address of @widget's size request cache.
10334 _gtk_widget_peek_request_cache (GtkWidget *widget)
10336 /* Don't bother slowing things down with the return_if_fail guards here */
10337 return &widget->priv->requests;
10341 * _gtk_widget_set_device_window:
10342 * @widget: a #GtkWidget
10343 * @device: a #GdkDevice
10344 * @window: the new device window
10346 * Sets pointer window for @widget and @device.
10347 * Does not ref @window.
10350 _gtk_widget_set_device_window (GtkWidget *widget,
10354 GHashTable *device_window;
10356 g_return_if_fail (GTK_IS_WIDGET (widget));
10357 g_return_if_fail (GDK_IS_DEVICE (device));
10358 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10360 if (!gtk_widget_get_mapped (widget))
10363 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10365 if (!device_window && window)
10367 device_window = g_hash_table_new (NULL, NULL);
10368 g_object_set_qdata_full (G_OBJECT (widget),
10369 quark_pointer_window,
10371 (GDestroyNotify) g_hash_table_destroy);
10375 g_hash_table_insert (device_window, device, window);
10376 else if (device_window)
10378 g_hash_table_remove (device_window, device);
10380 if (g_hash_table_size (device_window) == 0)
10381 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10386 * _gtk_widget_get_device_window:
10387 * @widget: a #GtkWidget
10388 * @device: a #GdkDevice
10390 * Return value: the device window set on @widget, or %NULL
10393 _gtk_widget_get_device_window (GtkWidget *widget,
10396 GHashTable *device_window;
10398 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10399 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10401 if (!gtk_widget_get_mapped (widget))
10404 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10406 if (!device_window)
10409 return g_hash_table_lookup (device_window, device);
10413 * _gtk_widget_list_devices:
10414 * @widget: a #GtkWidget
10416 * Returns the list of #GdkDevices that is currently on top
10417 * of any window belonging to @widget.
10418 * Free the list with g_list_free(), the elements are owned
10419 * by GTK+ and must not be freed.
10422 _gtk_widget_list_devices (GtkWidget *widget)
10424 GHashTableIter iter;
10425 GHashTable *device_window;
10426 GList *devices = NULL;
10427 gpointer key, value;
10429 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10431 if (!gtk_widget_get_mapped (widget))
10434 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10436 if (G_UNLIKELY (!device_window))
10439 g_hash_table_iter_init (&iter, device_window);
10441 while (g_hash_table_iter_next (&iter, &key, &value))
10442 devices = g_list_prepend (devices, key);
10448 synth_crossing (GtkWidget *widget,
10452 GdkCrossingMode mode,
10453 GdkNotifyType detail)
10457 event = gdk_event_new (type);
10459 event->crossing.window = g_object_ref (window);
10460 event->crossing.send_event = TRUE;
10461 event->crossing.subwindow = g_object_ref (window);
10462 event->crossing.time = GDK_CURRENT_TIME;
10463 event->crossing.x = event->crossing.y = 0;
10464 event->crossing.x_root = event->crossing.y_root = 0;
10465 event->crossing.mode = mode;
10466 event->crossing.detail = detail;
10467 event->crossing.focus = FALSE;
10468 event->crossing.state = 0;
10469 gdk_event_set_device (event, device);
10472 widget = gtk_get_event_widget (event);
10475 gtk_widget_event_internal (widget, event);
10477 gdk_event_free (event);
10481 * _gtk_widget_synthesize_crossing:
10482 * @from: the #GtkWidget the virtual pointer is leaving.
10483 * @to: the #GtkWidget the virtual pointer is moving to.
10484 * @mode: the #GdkCrossingMode to place on the synthesized events.
10486 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10488 * The real pointer window is the window that most recently received an enter notify
10489 * event. Windows that don't select for crossing events can't become the real
10490 * poiner window. The real pointer widget that owns the real pointer window. The
10491 * effective pointer window is the same as the real pointer window unless the real
10492 * pointer widget is either insensitive or there is a grab on a widget that is not
10493 * an ancestor of the real pointer widget (in which case the effective pointer
10494 * window should be the root window).
10496 * When the effective pointer window is the same as the real poiner window, we
10497 * receive crossing events from the windowing system. When the effective pointer
10498 * window changes to become different from the real pointer window we synthesize
10499 * crossing events, attempting to follow X protocol rules:
10501 * When the root window becomes the effective pointer window:
10502 * - leave notify on real pointer window, detail Ancestor
10503 * - leave notify on all of its ancestors, detail Virtual
10504 * - enter notify on root window, detail Inferior
10506 * When the root window ceases to be the effective pointer window:
10507 * - leave notify on root window, detail Inferior
10508 * - enter notify on all ancestors of real pointer window, detail Virtual
10509 * - enter notify on real pointer window, detail Ancestor
10512 _gtk_widget_synthesize_crossing (GtkWidget *from,
10515 GdkCrossingMode mode)
10517 GdkWindow *from_window = NULL, *to_window = NULL;
10519 g_return_if_fail (from != NULL || to != NULL);
10523 from_window = _gtk_widget_get_device_window (from, device);
10526 from_window = from->priv->window;
10531 to_window = _gtk_widget_get_device_window (to, device);
10534 to_window = to->priv->window;
10537 if (from_window == NULL && to_window == NULL)
10539 else if (from_window != NULL && to_window == NULL)
10541 GList *from_ancestors = NULL, *list;
10542 GdkWindow *from_ancestor = from_window;
10544 while (from_ancestor != NULL)
10546 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10547 if (from_ancestor == NULL)
10549 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10552 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10553 device, mode, GDK_NOTIFY_ANCESTOR);
10554 for (list = g_list_last (from_ancestors); list; list = list->prev)
10556 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10557 device, mode, GDK_NOTIFY_VIRTUAL);
10560 /* XXX: enter/inferior on root window? */
10562 g_list_free (from_ancestors);
10564 else if (from_window == NULL && to_window != NULL)
10566 GList *to_ancestors = NULL, *list;
10567 GdkWindow *to_ancestor = to_window;
10569 while (to_ancestor != NULL)
10571 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10572 if (to_ancestor == NULL)
10574 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10577 /* XXX: leave/inferior on root window? */
10579 for (list = to_ancestors; list; list = list->next)
10581 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10582 device, mode, GDK_NOTIFY_VIRTUAL);
10584 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10585 device, mode, GDK_NOTIFY_ANCESTOR);
10587 g_list_free (to_ancestors);
10589 else if (from_window == to_window)
10593 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10594 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10596 while (from_ancestor != NULL || to_ancestor != NULL)
10598 if (from_ancestor != NULL)
10600 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10601 if (from_ancestor == to_window)
10604 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10606 if (to_ancestor != NULL)
10608 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10609 if (to_ancestor == from_window)
10612 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10615 if (to_ancestor == from_window)
10617 if (mode != GDK_CROSSING_GTK_UNGRAB)
10618 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10619 device, mode, GDK_NOTIFY_INFERIOR);
10620 for (list = to_ancestors; list; list = list->next)
10621 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10622 device, mode, GDK_NOTIFY_VIRTUAL);
10623 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10624 device, mode, GDK_NOTIFY_ANCESTOR);
10626 else if (from_ancestor == to_window)
10628 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10629 device, mode, GDK_NOTIFY_ANCESTOR);
10630 for (list = g_list_last (from_ancestors); list; list = list->prev)
10632 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10633 device, mode, GDK_NOTIFY_VIRTUAL);
10635 if (mode != GDK_CROSSING_GTK_GRAB)
10636 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10637 device, mode, GDK_NOTIFY_INFERIOR);
10641 while (from_ancestors != NULL && to_ancestors != NULL
10642 && from_ancestors->data == to_ancestors->data)
10644 from_ancestors = g_list_delete_link (from_ancestors,
10646 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10649 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10650 device, mode, GDK_NOTIFY_NONLINEAR);
10652 for (list = g_list_last (from_ancestors); list; list = list->prev)
10654 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10655 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10657 for (list = to_ancestors; list; list = list->next)
10659 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10660 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10662 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10663 device, mode, GDK_NOTIFY_NONLINEAR);
10665 g_list_free (from_ancestors);
10666 g_list_free (to_ancestors);
10671 gtk_widget_propagate_state (GtkWidget *widget,
10672 GtkStateData *data)
10674 GtkWidgetPrivate *priv = widget->priv;
10675 GtkStateFlags new_flags, old_flags = priv->state_flags;
10676 GtkStateType old_state;
10678 old_state = gtk_widget_get_state (widget);
10680 switch (data->operation)
10682 case STATE_CHANGE_REPLACE:
10683 priv->state_flags = data->flags;
10685 case STATE_CHANGE_SET:
10686 priv->state_flags |= data->flags;
10688 case STATE_CHANGE_UNSET:
10689 priv->state_flags &= ~(data->flags);
10693 /* make insensitivity unoverridable */
10694 if (!priv->sensitive)
10695 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
10697 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10701 window = gtk_widget_get_toplevel (widget);
10703 if (window && gtk_widget_is_toplevel (window))
10704 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10707 new_flags = priv->state_flags;
10709 if (old_flags != new_flags)
10711 g_object_ref (widget);
10713 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10714 gtk_grab_remove (widget);
10716 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10717 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
10719 if (!priv->shadowed &&
10720 (new_flags & GTK_STATE_FLAG_INSENSITIVE) != (old_flags & GTK_STATE_FLAG_INSENSITIVE))
10722 GList *event_windows = NULL;
10723 GList *devices, *d;
10725 devices = _gtk_widget_list_devices (widget);
10727 for (d = devices; d; d = d->next)
10733 window = _gtk_widget_get_device_window (widget, device);
10735 /* Do not propagate more than once to the
10736 * same window if non-multidevice aware.
10738 if (!gdk_window_get_support_multidevice (window) &&
10739 g_list_find (event_windows, window))
10742 if (!gtk_widget_is_sensitive (widget))
10743 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10744 GDK_CROSSING_STATE_CHANGED);
10746 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10747 GDK_CROSSING_STATE_CHANGED);
10749 event_windows = g_list_prepend (event_windows, window);
10752 g_list_free (event_windows);
10753 g_list_free (devices);
10756 if (GTK_IS_CONTAINER (widget))
10758 GtkStateData child_data = *data;
10760 /* Make sure to only propate the right states further */
10761 child_data.flags &= GTK_STATE_FLAGS_DO_PROPAGATE;
10763 if (child_data.use_forall)
10764 gtk_container_forall (GTK_CONTAINER (widget),
10765 (GtkCallback) gtk_widget_propagate_state,
10768 gtk_container_foreach (GTK_CONTAINER (widget),
10769 (GtkCallback) gtk_widget_propagate_state,
10773 /* Trigger state change transitions for the widget */
10774 if (priv->context &&
10775 gtk_widget_get_mapped (widget))
10777 gint diff, flag = 1;
10779 diff = old_flags ^ new_flags;
10783 if ((diff & flag) != 0)
10787 target = ((new_flags & flag) != 0);
10788 _gtk_widget_notify_state_change (widget, flag, target);
10797 g_object_unref (widget);
10801 static const GtkWidgetAuxInfo default_aux_info = {
10809 * gtk_widget_get_aux_info:
10810 * @widget: a #GtkWidget
10811 * @create: if %TRUE, create the structure if it doesn't exist
10813 * Get the #GtkWidgetAuxInfo structure for the widget.
10815 * Return value: the #GtkAuxInfo structure for the widget, or
10816 * %NULL if @create is %FALSE and one doesn't already exist.
10818 static GtkWidgetAuxInfo *
10819 gtk_widget_get_aux_info (GtkWidget *widget,
10822 GtkWidgetAuxInfo *aux_info;
10824 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
10825 if (!aux_info && create)
10827 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
10829 *aux_info = default_aux_info;
10831 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
10837 static const GtkWidgetAuxInfo*
10838 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
10840 GtkWidgetAuxInfo *aux_info;
10842 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10843 if (aux_info == NULL)
10845 return &default_aux_info;
10853 /*****************************************
10854 * gtk_widget_aux_info_destroy:
10859 *****************************************/
10862 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
10864 g_slice_free (GtkWidgetAuxInfo, aux_info);
10868 * gtk_widget_shape_combine_region:
10869 * @widget: a #GtkWidget
10870 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10872 * Sets a shape for this widget's GDK window. This allows for
10873 * transparent windows etc., see gdk_window_shape_combine_region()
10874 * for more information.
10879 gtk_widget_shape_combine_region (GtkWidget *widget,
10880 cairo_region_t *region)
10882 GtkWidgetPrivate *priv;
10884 g_return_if_fail (GTK_IS_WIDGET (widget));
10885 /* set_shape doesn't work on widgets without gdk window */
10886 g_return_if_fail (gtk_widget_get_has_window (widget));
10888 priv = widget->priv;
10890 if (region == NULL)
10892 priv->has_shape_mask = FALSE;
10895 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
10897 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
10901 priv->has_shape_mask = TRUE;
10903 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
10904 cairo_region_copy (region),
10905 (GDestroyNotify) cairo_region_destroy);
10907 /* set shape if widget has a gdk window already.
10908 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10911 gdk_window_shape_combine_region (priv->window, region, 0, 0);
10916 * gtk_widget_input_shape_combine_region:
10917 * @widget: a #GtkWidget
10918 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10920 * Sets an input shape for this widget's GDK window. This allows for
10921 * windows which react to mouse click in a nonrectangular region, see
10922 * gdk_window_input_shape_combine_region() for more information.
10927 gtk_widget_input_shape_combine_region (GtkWidget *widget,
10928 cairo_region_t *region)
10930 GtkWidgetPrivate *priv;
10932 g_return_if_fail (GTK_IS_WIDGET (widget));
10933 /* set_shape doesn't work on widgets without gdk window */
10934 g_return_if_fail (gtk_widget_get_has_window (widget));
10936 priv = widget->priv;
10938 if (region == NULL)
10941 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
10943 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
10947 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
10948 cairo_region_copy (region),
10949 (GDestroyNotify) cairo_region_destroy);
10951 /* set shape if widget has a gdk window already.
10952 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10955 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
10960 /* style properties
10964 * gtk_widget_class_install_style_property_parser: (skip)
10965 * @klass: a #GtkWidgetClass
10966 * @pspec: the #GParamSpec for the style property
10967 * @parser: the parser for the style property
10969 * Installs a style property on a widget class.
10972 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
10974 GtkRcPropertyParser parser)
10976 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10977 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10978 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
10979 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
10981 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
10983 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
10984 G_OBJECT_CLASS_NAME (klass),
10989 g_param_spec_ref_sink (pspec);
10990 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
10991 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
10995 * gtk_widget_class_install_style_property:
10996 * @klass: a #GtkWidgetClass
10997 * @pspec: the #GParamSpec for the property
10999 * Installs a style property on a widget class. The parser for the
11000 * style property is determined by the value type of @pspec.
11003 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11006 GtkRcPropertyParser parser;
11008 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11009 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11011 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11013 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11017 * gtk_widget_class_find_style_property:
11018 * @klass: a #GtkWidgetClass
11019 * @property_name: the name of the style property to find
11021 * Finds a style property of a widget class by name.
11023 * Returns: (transfer none): the #GParamSpec of the style property or
11024 * %NULL if @class has no style property with that name.
11029 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11030 const gchar *property_name)
11032 g_return_val_if_fail (property_name != NULL, NULL);
11034 return g_param_spec_pool_lookup (style_property_spec_pool,
11036 G_OBJECT_CLASS_TYPE (klass),
11041 * gtk_widget_class_list_style_properties:
11042 * @klass: a #GtkWidgetClass
11043 * @n_properties: location to return the number of style properties found
11045 * Returns all style properties of a widget class.
11047 * Returns: (array length=n_properties) (transfer container): a
11048 * newly allocated array of #GParamSpec*. The array must be
11049 * freed with g_free().
11054 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11055 guint *n_properties)
11057 GParamSpec **pspecs;
11060 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11061 G_OBJECT_CLASS_TYPE (klass),
11070 * gtk_widget_style_get_property:
11071 * @widget: a #GtkWidget
11072 * @property_name: the name of a style property
11073 * @value: location to return the property value
11075 * Gets the value of a style property of @widget.
11078 gtk_widget_style_get_property (GtkWidget *widget,
11079 const gchar *property_name,
11084 g_return_if_fail (GTK_IS_WIDGET (widget));
11085 g_return_if_fail (property_name != NULL);
11086 g_return_if_fail (G_IS_VALUE (value));
11088 g_object_ref (widget);
11089 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11091 G_OBJECT_TYPE (widget),
11094 g_warning ("%s: widget class `%s' has no property named `%s'",
11096 G_OBJECT_TYPE_NAME (widget),
11100 GtkStyleContext *context;
11101 const GValue *peek_value;
11102 GtkStateFlags state;
11104 context = gtk_widget_get_style_context (widget);
11105 state = gtk_widget_get_state_flags (widget);
11107 peek_value = _gtk_style_context_peek_style_property (context,
11108 G_OBJECT_TYPE (widget),
11111 /* auto-conversion of the caller's value type
11113 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11114 g_value_copy (peek_value, value);
11115 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11116 g_value_transform (peek_value, value);
11118 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11120 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11121 G_VALUE_TYPE_NAME (value));
11123 g_object_unref (widget);
11127 * gtk_widget_style_get_valist:
11128 * @widget: a #GtkWidget
11129 * @first_property_name: the name of the first property to get
11130 * @var_args: a <type>va_list</type> of pairs of property names and
11131 * locations to return the property values, starting with the location
11132 * for @first_property_name.
11134 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11138 gtk_widget_style_get_valist (GtkWidget *widget,
11139 const gchar *first_property_name,
11142 GtkStyleContext *context;
11143 GtkStateFlags state;
11146 g_return_if_fail (GTK_IS_WIDGET (widget));
11148 g_object_ref (widget);
11149 context = gtk_widget_get_style_context (widget);
11150 state = gtk_widget_get_state_flags (widget);
11152 name = first_property_name;
11155 const GValue *peek_value;
11159 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11161 G_OBJECT_TYPE (widget),
11165 g_warning ("%s: widget class `%s' has no property named `%s'",
11167 G_OBJECT_TYPE_NAME (widget),
11171 /* style pspecs are always readable so we can spare that check here */
11173 peek_value = _gtk_style_context_peek_style_property (context,
11174 G_OBJECT_TYPE (widget),
11177 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11180 g_warning ("%s: %s", G_STRLOC, error);
11185 name = va_arg (var_args, gchar*);
11188 g_object_unref (widget);
11192 * gtk_widget_style_get:
11193 * @widget: a #GtkWidget
11194 * @first_property_name: the name of the first property to get
11195 * @...: pairs of property names and locations to return the
11196 * property values, starting with the location for
11197 * @first_property_name, terminated by %NULL.
11199 * Gets the values of a multiple style properties of @widget.
11202 gtk_widget_style_get (GtkWidget *widget,
11203 const gchar *first_property_name,
11208 g_return_if_fail (GTK_IS_WIDGET (widget));
11210 va_start (var_args, first_property_name);
11211 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11216 * gtk_requisition_new:
11218 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11220 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11221 * be freed with gtk_requisition_free().
11226 gtk_requisition_new (void)
11228 return g_slice_new0 (GtkRequisition);
11232 * gtk_requisition_copy:
11233 * @requisition: a #GtkRequisition
11235 * Copies a #GtkRequisition.
11237 * Returns: a copy of @requisition
11240 gtk_requisition_copy (const GtkRequisition *requisition)
11242 return g_slice_dup (GtkRequisition, requisition);
11246 * gtk_requisition_free:
11247 * @requisition: a #GtkRequisition
11249 * Frees a #GtkRequisition.
11252 gtk_requisition_free (GtkRequisition *requisition)
11254 g_slice_free (GtkRequisition, requisition);
11257 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11258 gtk_requisition_copy,
11259 gtk_requisition_free)
11262 * gtk_widget_class_set_accessible_type:
11263 * @widget_class: class to set the accessible type for
11264 * @type: The object type that implements the accessible for @widget_class
11266 * Sets the type to be used for creating accessibles for widgets of
11267 * @widget_class. The given @type must be a subtype of the type used for
11268 * accessibles of the parent class.
11270 * This function should only be called from class init functions of widgets.
11275 gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class,
11278 GtkWidgetClassPrivate *priv;
11280 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11281 g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type));
11283 priv = widget_class->priv;
11285 priv->accessible_type = type;
11286 /* reset this - honoring the type's role is better. */
11287 priv->accessible_role = ATK_ROLE_INVALID;
11291 * gtk_widget_class_set_accessible_role:
11292 * @widget_class: class to set the accessible role for
11293 * @role: The role to use for accessibles created for @widget_class
11295 * Sets the default #AtkRole to be set on accessibles created for
11296 * widgets of @widget_class. Accessibles may decide to not honor this
11297 * setting if their role reporting is more refined. Calls to
11298 * gtk_widget_class_set_accessible_type() will reset this value.
11300 * In cases where you want more fine-grained control over the role of
11301 * accessibles created for @widget_class, you should provide your own
11302 * accessible type and use gtk_widget_class_set_accessible_type()
11305 * If @role is #ATK_ROLE_INVALID, the default role will not be changed
11306 * and the accessible's default role will be used instead.
11308 * This function should only be called from class init functions of widgets.
11313 gtk_widget_class_set_accessible_role (GtkWidgetClass *widget_class,
11316 GtkWidgetClassPrivate *priv;
11318 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11320 priv = widget_class->priv;
11322 priv->accessible_role = role;
11326 * _gtk_widget_peek_accessible:
11327 * @widget: a #GtkWidget
11329 * Gets the accessible for @widget, if it has been created yet.
11330 * Otherwise, this function returns %NULL. If the @widget's implementation
11331 * does not use the default way to create accessibles, %NULL will always be
11334 * Returns: the accessible for @widget or %NULL if none has been
11338 _gtk_widget_peek_accessible (GtkWidget *widget)
11340 return g_object_get_qdata (G_OBJECT (widget),
11341 quark_accessible_object);
11345 * gtk_widget_get_accessible:
11346 * @widget: a #GtkWidget
11348 * Returns the accessible object that describes the widget to an
11349 * assistive technology.
11351 * If accessibility support is not available, this #AtkObject
11352 * instance may be a no-op. Likewise, if no class-specific #AtkObject
11353 * implementation is available for the widget instance in question,
11354 * it will inherit an #AtkObject implementation from the first ancestor
11355 * class for which such an implementation is defined.
11357 * The documentation of the
11358 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
11359 * library contains more information about accessible objects and their uses.
11361 * Returns: (transfer none): the #AtkObject associated with @widget
11364 gtk_widget_get_accessible (GtkWidget *widget)
11366 GtkWidgetClass *klass;
11368 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11370 klass = GTK_WIDGET_GET_CLASS (widget);
11372 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11374 return klass->get_accessible (widget);
11378 gtk_widget_real_get_accessible (GtkWidget *widget)
11380 AtkObject* accessible;
11382 accessible = g_object_get_qdata (G_OBJECT (widget),
11383 quark_accessible_object);
11386 GtkWidgetClass *widget_class;
11387 GtkWidgetClassPrivate *priv;
11388 AtkObjectFactory *factory;
11389 AtkRegistry *default_registry;
11391 widget_class = GTK_WIDGET_GET_CLASS (widget);
11392 priv = widget_class->priv;
11394 if (priv->accessible_type == GTK_TYPE_ACCESSIBLE)
11396 default_registry = atk_get_default_registry ();
11397 factory = atk_registry_get_factory (default_registry,
11398 G_TYPE_FROM_INSTANCE (widget));
11400 atk_object_factory_create_accessible (factory,
11401 G_OBJECT (widget));
11403 if (priv->accessible_role != ATK_ROLE_INVALID)
11404 atk_object_set_role (accessible, priv->accessible_role);
11406 g_object_set_qdata (G_OBJECT (widget),
11407 quark_accessible_object,
11412 accessible = g_object_new (priv->accessible_type, NULL);
11413 if (priv->accessible_role != ATK_ROLE_INVALID)
11414 atk_object_set_role (accessible, priv->accessible_role);
11416 g_object_set_qdata (G_OBJECT (widget),
11417 quark_accessible_object,
11420 atk_object_initialize (accessible, widget);
11422 /* Set the role again, since we don't want a role set
11423 * in some parent initialize() function to override
11426 if (priv->accessible_role != ATK_ROLE_INVALID)
11427 atk_object_set_role (accessible, priv->accessible_role);
11434 * Initialize a AtkImplementorIface instance's virtual pointers as
11435 * appropriate to this implementor's class (GtkWidget).
11438 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11440 iface->ref_accessible = gtk_widget_ref_accessible;
11444 gtk_widget_ref_accessible (AtkImplementor *implementor)
11446 AtkObject *accessible;
11448 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11450 g_object_ref (accessible);
11455 * Expand flag management
11459 gtk_widget_update_computed_expand (GtkWidget *widget)
11461 GtkWidgetPrivate *priv;
11463 priv = widget->priv;
11465 if (priv->need_compute_expand)
11469 if (priv->hexpand_set)
11474 if (priv->vexpand_set)
11479 /* we don't need to use compute_expand if both expands are
11480 * forced by the app
11482 if (!(priv->hexpand_set && priv->vexpand_set))
11484 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11488 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11489 priv->hexpand_set ? &ignored : &h,
11490 priv->vexpand_set ? &ignored : &v);
11494 priv->need_compute_expand = FALSE;
11495 priv->computed_hexpand = h != FALSE;
11496 priv->computed_vexpand = v != FALSE;
11501 * gtk_widget_queue_compute_expand:
11502 * @widget: a #GtkWidget
11504 * Mark @widget as needing to recompute its expand flags. Call
11505 * this function when setting legacy expand child properties
11506 * on the child of a container.
11508 * See gtk_widget_compute_expand().
11511 gtk_widget_queue_compute_expand (GtkWidget *widget)
11514 gboolean changed_anything;
11516 if (widget->priv->need_compute_expand)
11519 changed_anything = FALSE;
11521 while (parent != NULL)
11523 if (!parent->priv->need_compute_expand)
11525 parent->priv->need_compute_expand = TRUE;
11526 changed_anything = TRUE;
11529 /* Note: if we had an invariant that "if a child needs to
11530 * compute expand, its parents also do" then we could stop going
11531 * up when we got to a parent that already needed to
11532 * compute. However, in general we compute expand lazily (as
11533 * soon as we see something in a subtree that is expand, we know
11534 * we're expanding) and so this invariant does not hold and we
11535 * have to always walk all the way up in case some ancestor
11536 * is not currently need_compute_expand.
11539 parent = parent->priv->parent;
11542 /* recomputing expand always requires
11543 * a relayout as well
11545 if (changed_anything)
11546 gtk_widget_queue_resize (widget);
11550 * gtk_widget_compute_expand:
11551 * @widget: the widget
11552 * @orientation: expand direction
11554 * Computes whether a container should give this widget extra space
11555 * when possible. Containers should check this, rather than
11556 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11558 * This function already checks whether the widget is visible, so
11559 * visibility does not need to be checked separately. Non-visible
11560 * widgets are not expanded.
11562 * The computed expand value uses either the expand setting explicitly
11563 * set on the widget itself, or, if none has been explicitly set,
11564 * the widget may expand if some of its children do.
11566 * Return value: whether widget tree rooted here should be expanded
11569 gtk_widget_compute_expand (GtkWidget *widget,
11570 GtkOrientation orientation)
11572 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11574 /* We never make a widget expand if not even showing. */
11575 if (!gtk_widget_get_visible (widget))
11578 gtk_widget_update_computed_expand (widget);
11580 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11582 return widget->priv->computed_hexpand;
11586 return widget->priv->computed_vexpand;
11591 gtk_widget_set_expand (GtkWidget *widget,
11592 GtkOrientation orientation,
11595 const char *expand_prop;
11596 const char *expand_set_prop;
11598 GtkWidgetPrivate *priv;
11600 g_return_if_fail (GTK_IS_WIDGET (widget));
11602 priv = widget->priv;
11604 expand = expand != FALSE;
11606 was_both = priv->hexpand && priv->vexpand;
11608 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11610 if (priv->hexpand_set &&
11611 priv->hexpand == expand)
11614 priv->hexpand_set = TRUE;
11615 priv->hexpand = expand;
11617 expand_prop = "hexpand";
11618 expand_set_prop = "hexpand-set";
11622 if (priv->vexpand_set &&
11623 priv->vexpand == expand)
11626 priv->vexpand_set = TRUE;
11627 priv->vexpand = expand;
11629 expand_prop = "vexpand";
11630 expand_set_prop = "vexpand-set";
11633 gtk_widget_queue_compute_expand (widget);
11635 g_object_freeze_notify (G_OBJECT (widget));
11636 g_object_notify (G_OBJECT (widget), expand_prop);
11637 g_object_notify (G_OBJECT (widget), expand_set_prop);
11638 if (was_both != (priv->hexpand && priv->vexpand))
11639 g_object_notify (G_OBJECT (widget), "expand");
11640 g_object_thaw_notify (G_OBJECT (widget));
11644 gtk_widget_set_expand_set (GtkWidget *widget,
11645 GtkOrientation orientation,
11648 GtkWidgetPrivate *priv;
11651 priv = widget->priv;
11653 set = set != FALSE;
11655 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11657 if (set == priv->hexpand_set)
11660 priv->hexpand_set = set;
11661 prop = "hexpand-set";
11665 if (set == priv->vexpand_set)
11668 priv->vexpand_set = set;
11669 prop = "vexpand-set";
11672 gtk_widget_queue_compute_expand (widget);
11674 g_object_notify (G_OBJECT (widget), prop);
11678 * gtk_widget_get_hexpand:
11679 * @widget: the widget
11681 * Gets whether the widget would like any available extra horizontal
11682 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11683 * generally receive the extra space. For example, a list or
11684 * scrollable area or document in your window would often be set to
11687 * Containers should use gtk_widget_compute_expand() rather than
11688 * this function, to see whether a widget, or any of its children,
11689 * has the expand flag set. If any child of a widget wants to
11690 * expand, the parent may ask to expand also.
11692 * This function only looks at the widget's own hexpand flag, rather
11693 * than computing whether the entire widget tree rooted at this widget
11696 * Return value: whether hexpand flag is set
11699 gtk_widget_get_hexpand (GtkWidget *widget)
11701 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11703 return widget->priv->hexpand;
11707 * gtk_widget_set_hexpand:
11708 * @widget: the widget
11709 * @expand: whether to expand
11711 * Sets whether the widget would like any available extra horizontal
11712 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11713 * generally receive the extra space. For example, a list or
11714 * scrollable area or document in your window would often be set to
11717 * Call this function to set the expand flag if you would like your
11718 * widget to become larger horizontally when the window has extra
11721 * By default, widgets automatically expand if any of their children
11722 * want to expand. (To see if a widget will automatically expand given
11723 * its current children and state, call gtk_widget_compute_expand(). A
11724 * container can decide how the expandability of children affects the
11725 * expansion of the container by overriding the compute_expand virtual
11726 * method on #GtkWidget.).
11728 * Setting hexpand explicitly with this function will override the
11729 * automatic expand behavior.
11731 * This function forces the widget to expand or not to expand,
11732 * regardless of children. The override occurs because
11733 * gtk_widget_set_hexpand() sets the hexpand-set property (see
11734 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
11735 * value to be used, rather than looking at children and widget state.
11738 gtk_widget_set_hexpand (GtkWidget *widget,
11741 g_return_if_fail (GTK_IS_WIDGET (widget));
11743 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
11747 * gtk_widget_get_hexpand_set:
11748 * @widget: the widget
11750 * Gets whether gtk_widget_set_hexpand() has been used to
11751 * explicitly set the expand flag on this widget.
11753 * If hexpand is set, then it overrides any computed
11754 * expand value based on child widgets. If hexpand is not
11755 * set, then the expand value depends on whether any
11756 * children of the widget would like to expand.
11758 * There are few reasons to use this function, but it's here
11759 * for completeness and consistency.
11761 * Return value: whether hexpand has been explicitly set
11764 gtk_widget_get_hexpand_set (GtkWidget *widget)
11766 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11768 return widget->priv->hexpand_set;
11772 * gtk_widget_set_hexpand_set:
11773 * @widget: the widget
11774 * @set: value for hexpand-set property
11776 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
11779 * The hexpand-set property will be set automatically when you call
11780 * gtk_widget_set_hexpand() to set hexpand, so the most likely
11781 * reason to use this function would be to unset an explicit expand
11784 * If hexpand is set, then it overrides any computed
11785 * expand value based on child widgets. If hexpand is not
11786 * set, then the expand value depends on whether any
11787 * children of the widget would like to expand.
11789 * There are few reasons to use this function, but it's here
11790 * for completeness and consistency.
11793 gtk_widget_set_hexpand_set (GtkWidget *widget,
11796 g_return_if_fail (GTK_IS_WIDGET (widget));
11798 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
11803 * gtk_widget_get_vexpand:
11804 * @widget: the widget
11806 * Gets whether the widget would like any available extra vertical
11809 * See gtk_widget_get_hexpand() for more detail.
11811 * Return value: whether vexpand flag is set
11814 gtk_widget_get_vexpand (GtkWidget *widget)
11816 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11818 return widget->priv->vexpand;
11822 * gtk_widget_set_vexpand:
11823 * @widget: the widget
11824 * @expand: whether to expand
11826 * Sets whether the widget would like any available extra vertical
11829 * See gtk_widget_set_hexpand() for more detail.
11832 gtk_widget_set_vexpand (GtkWidget *widget,
11835 g_return_if_fail (GTK_IS_WIDGET (widget));
11837 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
11841 * gtk_widget_get_vexpand_set:
11842 * @widget: the widget
11844 * Gets whether gtk_widget_set_vexpand() has been used to
11845 * explicitly set the expand flag on this widget.
11847 * See gtk_widget_get_hexpand_set() for more detail.
11849 * Return value: whether vexpand has been explicitly set
11852 gtk_widget_get_vexpand_set (GtkWidget *widget)
11854 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11856 return widget->priv->vexpand_set;
11860 * gtk_widget_set_vexpand_set:
11861 * @widget: the widget
11862 * @set: value for vexpand-set property
11864 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
11867 * See gtk_widget_set_hexpand_set() for more detail.
11870 gtk_widget_set_vexpand_set (GtkWidget *widget,
11873 g_return_if_fail (GTK_IS_WIDGET (widget));
11875 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
11879 * GtkBuildable implementation
11881 static GQuark quark_builder_has_default = 0;
11882 static GQuark quark_builder_has_focus = 0;
11883 static GQuark quark_builder_atk_relations = 0;
11884 static GQuark quark_builder_set_name = 0;
11887 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
11889 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
11890 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
11891 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
11892 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
11894 iface->set_name = gtk_widget_buildable_set_name;
11895 iface->get_name = gtk_widget_buildable_get_name;
11896 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
11897 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
11898 iface->parser_finished = gtk_widget_buildable_parser_finished;
11899 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
11900 iface->custom_finished = gtk_widget_buildable_custom_finished;
11904 gtk_widget_buildable_set_name (GtkBuildable *buildable,
11907 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
11908 g_strdup (name), g_free);
11911 static const gchar *
11912 gtk_widget_buildable_get_name (GtkBuildable *buildable)
11914 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
11918 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
11919 GtkBuilder *builder,
11920 const gchar *childname)
11922 if (strcmp (childname, "accessible") == 0)
11923 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
11929 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
11930 GtkBuilder *builder,
11932 const GValue *value)
11934 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
11935 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
11936 GINT_TO_POINTER (TRUE));
11937 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
11938 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
11939 GINT_TO_POINTER (TRUE));
11941 g_object_set_property (G_OBJECT (buildable), name, value);
11946 gchar *action_name;
11947 GString *description;
11949 gboolean translatable;
11959 free_action (AtkActionData *data, gpointer user_data)
11961 g_free (data->action_name);
11962 g_string_free (data->description, TRUE);
11963 g_free (data->context);
11964 g_slice_free (AtkActionData, data);
11968 free_relation (AtkRelationData *data, gpointer user_data)
11970 g_free (data->target);
11971 g_free (data->type);
11972 g_slice_free (AtkRelationData, data);
11976 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
11977 GtkBuilder *builder)
11979 GSList *atk_relations;
11981 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
11982 gtk_widget_grab_default (GTK_WIDGET (buildable));
11983 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
11984 gtk_widget_grab_focus (GTK_WIDGET (buildable));
11986 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
11987 quark_builder_atk_relations);
11990 AtkObject *accessible;
11991 AtkRelationSet *relation_set;
11994 AtkRelationType relation_type;
11995 AtkObject *target_accessible;
11997 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11998 relation_set = atk_object_ref_relation_set (accessible);
12000 for (l = atk_relations; l; l = l->next)
12002 AtkRelationData *relation = (AtkRelationData*)l->data;
12004 target = gtk_builder_get_object (builder, relation->target);
12007 g_warning ("Target object %s in <relation> does not exist",
12011 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12012 g_assert (target_accessible != NULL);
12014 relation_type = atk_relation_type_for_name (relation->type);
12015 if (relation_type == ATK_RELATION_NULL)
12017 g_warning ("<relation> type %s not found",
12021 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12022 target_accessible);
12024 g_object_unref (relation_set);
12026 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
12027 g_slist_free (atk_relations);
12028 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12037 } AccessibilitySubParserData;
12040 accessibility_start_element (GMarkupParseContext *context,
12041 const gchar *element_name,
12042 const gchar **names,
12043 const gchar **values,
12044 gpointer user_data,
12047 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12049 gint line_number, char_number;
12051 if (strcmp (element_name, "relation") == 0)
12053 gchar *target = NULL;
12054 gchar *type = NULL;
12055 AtkRelationData *relation;
12057 for (i = 0; names[i]; i++)
12059 if (strcmp (names[i], "target") == 0)
12060 target = g_strdup (values[i]);
12061 else if (strcmp (names[i], "type") == 0)
12062 type = g_strdup (values[i]);
12065 g_markup_parse_context_get_position (context,
12068 g_set_error (error,
12070 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12071 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12073 line_number, char_number, names[i], "relation");
12080 if (!target || !type)
12082 g_markup_parse_context_get_position (context,
12085 g_set_error (error,
12087 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12088 "%s:%d:%d <%s> requires attribute \"%s\"",
12090 line_number, char_number, "relation",
12091 type ? "target" : "type");
12097 relation = g_slice_new (AtkRelationData);
12098 relation->target = target;
12099 relation->type = type;
12101 data->relations = g_slist_prepend (data->relations, relation);
12103 else if (strcmp (element_name, "action") == 0)
12105 const gchar *action_name = NULL;
12106 const gchar *description = NULL;
12107 const gchar *msg_context = NULL;
12108 gboolean translatable = FALSE;
12109 AtkActionData *action;
12111 for (i = 0; names[i]; i++)
12113 if (strcmp (names[i], "action_name") == 0)
12114 action_name = values[i];
12115 else if (strcmp (names[i], "description") == 0)
12116 description = values[i];
12117 else if (strcmp (names[i], "translatable") == 0)
12119 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12122 else if (strcmp (names[i], "comments") == 0)
12124 /* do nothing, comments are for translators */
12126 else if (strcmp (names[i], "context") == 0)
12127 msg_context = values[i];
12130 g_markup_parse_context_get_position (context,
12133 g_set_error (error,
12135 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12136 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12138 line_number, char_number, names[i], "action");
12145 g_markup_parse_context_get_position (context,
12148 g_set_error (error,
12150 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12151 "%s:%d:%d <%s> requires attribute \"%s\"",
12153 line_number, char_number, "action",
12158 action = g_slice_new (AtkActionData);
12159 action->action_name = g_strdup (action_name);
12160 action->description = g_string_new (description);
12161 action->context = g_strdup (msg_context);
12162 action->translatable = translatable;
12164 data->actions = g_slist_prepend (data->actions, action);
12166 else if (strcmp (element_name, "accessibility") == 0)
12169 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12173 accessibility_text (GMarkupParseContext *context,
12176 gpointer user_data,
12179 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12181 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12183 AtkActionData *action = data->actions->data;
12185 g_string_append_len (action->description, text, text_len);
12189 static const GMarkupParser accessibility_parser =
12191 accessibility_start_element,
12193 accessibility_text,
12202 } AccelGroupParserData;
12205 accel_group_start_element (GMarkupParseContext *context,
12206 const gchar *element_name,
12207 const gchar **names,
12208 const gchar **values,
12209 gpointer user_data,
12214 guint modifiers = 0;
12215 gchar *signal = NULL;
12216 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12218 for (i = 0; names[i]; i++)
12220 if (strcmp (names[i], "key") == 0)
12221 key = gdk_keyval_from_name (values[i]);
12222 else if (strcmp (names[i], "modifiers") == 0)
12224 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12230 else if (strcmp (names[i], "signal") == 0)
12231 signal = g_strdup (values[i]);
12234 if (key == 0 || signal == NULL)
12236 g_warning ("<accelerator> requires key and signal attributes");
12239 parser_data->key = key;
12240 parser_data->modifiers = modifiers;
12241 parser_data->signal = signal;
12244 static const GMarkupParser accel_group_parser =
12246 accel_group_start_element,
12255 style_start_element (GMarkupParseContext *context,
12256 const gchar *element_name,
12257 const gchar **names,
12258 const gchar **values,
12259 gpointer user_data,
12262 StyleParserData *style_data = (StyleParserData *)user_data;
12265 if (strcmp (element_name, "class") == 0)
12267 if (g_markup_collect_attributes (element_name,
12271 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12272 G_MARKUP_COLLECT_INVALID))
12274 style_data->classes = g_slist_append (style_data->classes, class_name);
12277 else if (strcmp (element_name, "style") == 0)
12280 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12283 static const GMarkupParser style_parser =
12285 style_start_element,
12289 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12290 GtkBuilder *builder,
12292 const gchar *tagname,
12293 GMarkupParser *parser,
12296 g_assert (buildable);
12298 if (strcmp (tagname, "accelerator") == 0)
12300 AccelGroupParserData *parser_data;
12302 parser_data = g_slice_new0 (AccelGroupParserData);
12303 parser_data->object = g_object_ref (buildable);
12304 *parser = accel_group_parser;
12305 *data = parser_data;
12308 if (strcmp (tagname, "accessibility") == 0)
12310 AccessibilitySubParserData *parser_data;
12312 parser_data = g_slice_new0 (AccessibilitySubParserData);
12313 *parser = accessibility_parser;
12314 *data = parser_data;
12317 if (strcmp (tagname, "style") == 0)
12319 StyleParserData *parser_data;
12321 parser_data = g_slice_new0 (StyleParserData);
12322 *parser = style_parser;
12323 *data = parser_data;
12331 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12332 GtkWidget *toplevel,
12333 gpointer user_data)
12335 AccelGroupParserData *accel_data;
12336 GSList *accel_groups;
12337 GtkAccelGroup *accel_group;
12339 g_return_if_fail (GTK_IS_WIDGET (widget));
12340 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12341 g_return_if_fail (user_data != NULL);
12343 accel_data = (AccelGroupParserData*)user_data;
12344 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12345 if (g_slist_length (accel_groups) == 0)
12347 accel_group = gtk_accel_group_new ();
12348 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12352 g_assert (g_slist_length (accel_groups) == 1);
12353 accel_group = g_slist_nth_data (accel_groups, 0);
12356 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12357 accel_data->signal,
12360 accel_data->modifiers,
12361 GTK_ACCEL_VISIBLE);
12363 g_object_unref (accel_data->object);
12364 g_free (accel_data->signal);
12365 g_slice_free (AccelGroupParserData, accel_data);
12369 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12370 GtkBuilder *builder,
12372 const gchar *tagname,
12373 gpointer user_data)
12375 if (strcmp (tagname, "accelerator") == 0)
12377 AccelGroupParserData *accel_data;
12378 GtkWidget *toplevel;
12380 accel_data = (AccelGroupParserData*)user_data;
12381 g_assert (accel_data->object);
12383 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12385 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12387 else if (strcmp (tagname, "accessibility") == 0)
12389 AccessibilitySubParserData *a11y_data;
12391 a11y_data = (AccessibilitySubParserData*)user_data;
12393 if (a11y_data->actions)
12395 AtkObject *accessible;
12400 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12402 if (ATK_IS_ACTION (accessible))
12404 action = ATK_ACTION (accessible);
12405 n_actions = atk_action_get_n_actions (action);
12407 for (l = a11y_data->actions; l; l = l->next)
12409 AtkActionData *action_data = (AtkActionData*)l->data;
12411 for (i = 0; i < n_actions; i++)
12412 if (strcmp (atk_action_get_name (action, i),
12413 action_data->action_name) == 0)
12418 gchar *description;
12420 if (action_data->translatable && action_data->description->len)
12421 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12422 action_data->context,
12423 action_data->description->str);
12425 description = action_data->description->str;
12427 atk_action_set_description (action, i, description);
12432 g_warning ("accessibility action on a widget that does not implement AtkAction");
12434 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
12435 g_slist_free (a11y_data->actions);
12438 if (a11y_data->relations)
12439 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12440 a11y_data->relations);
12442 g_slice_free (AccessibilitySubParserData, a11y_data);
12444 else if (strcmp (tagname, "style") == 0)
12446 StyleParserData *style_data = (StyleParserData *)user_data;
12447 GtkStyleContext *context;
12450 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
12452 for (l = style_data->classes; l; l = l->next)
12453 gtk_style_context_add_class (context, (const gchar *)l->data);
12455 gtk_widget_reset_style (GTK_WIDGET (buildable));
12457 g_slist_free_full (style_data->classes, g_free);
12458 g_slice_free (StyleParserData, style_data);
12462 static GtkSizeRequestMode
12463 gtk_widget_real_get_request_mode (GtkWidget *widget)
12465 /* By default widgets dont trade size at all. */
12466 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
12470 gtk_widget_real_get_width (GtkWidget *widget,
12471 gint *minimum_size,
12472 gint *natural_size)
12482 gtk_widget_real_get_height (GtkWidget *widget,
12483 gint *minimum_size,
12484 gint *natural_size)
12494 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12496 gint *minimum_height,
12497 gint *natural_height)
12499 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12503 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12505 gint *minimum_width,
12506 gint *natural_width)
12508 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12512 * gtk_widget_get_halign:
12513 * @widget: a #GtkWidget
12515 * Gets the value of the #GtkWidget:halign property.
12517 * Returns: the horizontal alignment of @widget
12520 gtk_widget_get_halign (GtkWidget *widget)
12522 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12523 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12527 * gtk_widget_set_halign:
12528 * @widget: a #GtkWidget
12529 * @align: the horizontal alignment
12531 * Sets the horizontal alignment of @widget.
12532 * See the #GtkWidget:halign property.
12535 gtk_widget_set_halign (GtkWidget *widget,
12538 GtkWidgetAuxInfo *aux_info;
12540 g_return_if_fail (GTK_IS_WIDGET (widget));
12542 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12544 if (aux_info->halign == align)
12547 aux_info->halign = align;
12548 gtk_widget_queue_resize (widget);
12549 g_object_notify (G_OBJECT (widget), "halign");
12553 * gtk_widget_get_valign:
12554 * @widget: a #GtkWidget
12556 * Gets the value of the #GtkWidget:valign property.
12558 * Returns: the vertical alignment of @widget
12561 gtk_widget_get_valign (GtkWidget *widget)
12563 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12564 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12568 * gtk_widget_set_valign:
12569 * @widget: a #GtkWidget
12570 * @align: the vertical alignment
12572 * Sets the vertical alignment of @widget.
12573 * See the #GtkWidget:valign property.
12576 gtk_widget_set_valign (GtkWidget *widget,
12579 GtkWidgetAuxInfo *aux_info;
12581 g_return_if_fail (GTK_IS_WIDGET (widget));
12583 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12585 if (aux_info->valign == align)
12588 aux_info->valign = align;
12589 gtk_widget_queue_resize (widget);
12590 g_object_notify (G_OBJECT (widget), "valign");
12594 * gtk_widget_get_margin_left:
12595 * @widget: a #GtkWidget
12597 * Gets the value of the #GtkWidget:margin-left property.
12599 * Returns: The left margin of @widget
12604 gtk_widget_get_margin_left (GtkWidget *widget)
12606 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12608 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12612 * gtk_widget_set_margin_left:
12613 * @widget: a #GtkWidget
12614 * @margin: the left margin
12616 * Sets the left margin of @widget.
12617 * See the #GtkWidget:margin-left property.
12622 gtk_widget_set_margin_left (GtkWidget *widget,
12625 GtkWidgetAuxInfo *aux_info;
12627 g_return_if_fail (GTK_IS_WIDGET (widget));
12628 g_return_if_fail (margin <= G_MAXINT16);
12630 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12632 if (aux_info->margin.left == margin)
12635 aux_info->margin.left = margin;
12636 gtk_widget_queue_resize (widget);
12637 g_object_notify (G_OBJECT (widget), "margin-left");
12641 * gtk_widget_get_margin_right:
12642 * @widget: a #GtkWidget
12644 * Gets the value of the #GtkWidget:margin-right property.
12646 * Returns: The right margin of @widget
12651 gtk_widget_get_margin_right (GtkWidget *widget)
12653 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12655 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12659 * gtk_widget_set_margin_right:
12660 * @widget: a #GtkWidget
12661 * @margin: the right margin
12663 * Sets the right margin of @widget.
12664 * See the #GtkWidget:margin-right property.
12669 gtk_widget_set_margin_right (GtkWidget *widget,
12672 GtkWidgetAuxInfo *aux_info;
12674 g_return_if_fail (GTK_IS_WIDGET (widget));
12675 g_return_if_fail (margin <= G_MAXINT16);
12677 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12679 if (aux_info->margin.right == margin)
12682 aux_info->margin.right = margin;
12683 gtk_widget_queue_resize (widget);
12684 g_object_notify (G_OBJECT (widget), "margin-right");
12688 * gtk_widget_get_margin_top:
12689 * @widget: a #GtkWidget
12691 * Gets the value of the #GtkWidget:margin-top property.
12693 * Returns: The top margin of @widget
12698 gtk_widget_get_margin_top (GtkWidget *widget)
12700 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12702 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12706 * gtk_widget_set_margin_top:
12707 * @widget: a #GtkWidget
12708 * @margin: the top margin
12710 * Sets the top margin of @widget.
12711 * See the #GtkWidget:margin-top property.
12716 gtk_widget_set_margin_top (GtkWidget *widget,
12719 GtkWidgetAuxInfo *aux_info;
12721 g_return_if_fail (GTK_IS_WIDGET (widget));
12722 g_return_if_fail (margin <= G_MAXINT16);
12724 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12726 if (aux_info->margin.top == margin)
12729 aux_info->margin.top = margin;
12730 gtk_widget_queue_resize (widget);
12731 g_object_notify (G_OBJECT (widget), "margin-top");
12735 * gtk_widget_get_margin_bottom:
12736 * @widget: a #GtkWidget
12738 * Gets the value of the #GtkWidget:margin-bottom property.
12740 * Returns: The bottom margin of @widget
12745 gtk_widget_get_margin_bottom (GtkWidget *widget)
12747 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12749 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
12753 * gtk_widget_set_margin_bottom:
12754 * @widget: a #GtkWidget
12755 * @margin: the bottom margin
12757 * Sets the bottom margin of @widget.
12758 * See the #GtkWidget:margin-bottom property.
12763 gtk_widget_set_margin_bottom (GtkWidget *widget,
12766 GtkWidgetAuxInfo *aux_info;
12768 g_return_if_fail (GTK_IS_WIDGET (widget));
12769 g_return_if_fail (margin <= G_MAXINT16);
12771 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12773 if (aux_info->margin.bottom == margin)
12776 aux_info->margin.bottom = margin;
12777 gtk_widget_queue_resize (widget);
12778 g_object_notify (G_OBJECT (widget), "margin-bottom");
12782 * gtk_widget_get_clipboard:
12783 * @widget: a #GtkWidget
12784 * @selection: a #GdkAtom which identifies the clipboard
12785 * to use. %GDK_SELECTION_CLIPBOARD gives the
12786 * default clipboard. Another common value
12787 * is %GDK_SELECTION_PRIMARY, which gives
12788 * the primary X selection.
12790 * Returns the clipboard object for the given selection to
12791 * be used with @widget. @widget must have a #GdkDisplay
12792 * associated with it, so must be attached to a toplevel
12795 * Return value: (transfer none): the appropriate clipboard object. If no
12796 * clipboard already exists, a new one will
12797 * be created. Once a clipboard object has
12798 * been created, it is persistent for all time.
12803 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
12805 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12806 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
12808 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
12813 * gtk_widget_list_mnemonic_labels:
12814 * @widget: a #GtkWidget
12816 * Returns a newly allocated list of the widgets, normally labels, for
12817 * which this widget is the target of a mnemonic (see for example,
12818 * gtk_label_set_mnemonic_widget()).
12820 * The widgets in the list are not individually referenced. If you
12821 * want to iterate through the list and perform actions involving
12822 * callbacks that might destroy the widgets, you
12823 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
12824 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
12825 * widgets afterwards.
12827 * Return value: (element-type GtkWidget) (transfer container): the list of
12828 * mnemonic labels; free this list
12829 * with g_list_free() when you are done with it.
12834 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
12836 GList *list = NULL;
12839 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12841 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
12842 list = g_list_prepend (list, l->data);
12848 * gtk_widget_add_mnemonic_label:
12849 * @widget: a #GtkWidget
12850 * @label: a #GtkWidget that acts as a mnemonic label for @widget
12852 * Adds a widget to the list of mnemonic labels for
12853 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
12854 * list of mnemonic labels for the widget is cleared when the
12855 * widget is destroyed, so the caller must make sure to update
12856 * its internal state at this point as well, by using a connection
12857 * to the #GtkWidget::destroy signal or a weak notifier.
12862 gtk_widget_add_mnemonic_label (GtkWidget *widget,
12865 GSList *old_list, *new_list;
12867 g_return_if_fail (GTK_IS_WIDGET (widget));
12868 g_return_if_fail (GTK_IS_WIDGET (label));
12870 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12871 new_list = g_slist_prepend (old_list, label);
12873 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12874 new_list, (GDestroyNotify) g_slist_free);
12878 * gtk_widget_remove_mnemonic_label:
12879 * @widget: a #GtkWidget
12880 * @label: a #GtkWidget that was previously set as a mnemnic label for
12881 * @widget with gtk_widget_add_mnemonic_label().
12883 * Removes a widget from the list of mnemonic labels for
12884 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
12885 * must have previously been added to the list with
12886 * gtk_widget_add_mnemonic_label().
12891 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
12894 GSList *old_list, *new_list;
12896 g_return_if_fail (GTK_IS_WIDGET (widget));
12897 g_return_if_fail (GTK_IS_WIDGET (label));
12899 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12900 new_list = g_slist_remove (old_list, label);
12903 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12904 new_list, (GDestroyNotify) g_slist_free);
12908 * gtk_widget_get_no_show_all:
12909 * @widget: a #GtkWidget
12911 * Returns the current value of the #GtkWidget:no-show-all property,
12912 * which determines whether calls to gtk_widget_show_all()
12913 * will affect this widget.
12915 * Return value: the current value of the "no-show-all" property.
12920 gtk_widget_get_no_show_all (GtkWidget *widget)
12922 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12924 return widget->priv->no_show_all;
12928 * gtk_widget_set_no_show_all:
12929 * @widget: a #GtkWidget
12930 * @no_show_all: the new value for the "no-show-all" property
12932 * Sets the #GtkWidget:no-show-all property, which determines whether
12933 * calls to gtk_widget_show_all() will affect this widget.
12935 * This is mostly for use in constructing widget hierarchies with externally
12936 * controlled visibility, see #GtkUIManager.
12941 gtk_widget_set_no_show_all (GtkWidget *widget,
12942 gboolean no_show_all)
12944 g_return_if_fail (GTK_IS_WIDGET (widget));
12946 no_show_all = (no_show_all != FALSE);
12948 if (widget->priv->no_show_all != no_show_all)
12950 widget->priv->no_show_all = no_show_all;
12952 g_object_notify (G_OBJECT (widget), "no-show-all");
12958 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
12959 gboolean has_tooltip,
12962 GtkWidgetPrivate *priv = widget->priv;
12963 gboolean priv_has_tooltip;
12965 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
12966 quark_has_tooltip));
12968 if (priv_has_tooltip != has_tooltip || force)
12970 priv_has_tooltip = has_tooltip;
12972 if (priv_has_tooltip)
12974 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
12975 gdk_window_set_events (priv->window,
12976 gdk_window_get_events (priv->window) |
12977 GDK_LEAVE_NOTIFY_MASK |
12978 GDK_POINTER_MOTION_MASK |
12979 GDK_POINTER_MOTION_HINT_MASK);
12981 if (gtk_widget_get_has_window (widget))
12982 gtk_widget_add_events (widget,
12983 GDK_LEAVE_NOTIFY_MASK |
12984 GDK_POINTER_MOTION_MASK |
12985 GDK_POINTER_MOTION_HINT_MASK);
12988 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
12989 GUINT_TO_POINTER (priv_has_tooltip));
12994 * gtk_widget_set_tooltip_window:
12995 * @widget: a #GtkWidget
12996 * @custom_window: (allow-none): a #GtkWindow, or %NULL
12998 * Replaces the default, usually yellow, window used for displaying
12999 * tooltips with @custom_window. GTK+ will take care of showing and
13000 * hiding @custom_window at the right moment, to behave likewise as
13001 * the default tooltip window. If @custom_window is %NULL, the default
13002 * tooltip window will be used.
13004 * If the custom window should have the default theming it needs to
13005 * have the name "gtk-tooltip", see gtk_widget_set_name().
13010 gtk_widget_set_tooltip_window (GtkWidget *widget,
13011 GtkWindow *custom_window)
13013 gboolean has_tooltip;
13014 gchar *tooltip_markup;
13016 g_return_if_fail (GTK_IS_WIDGET (widget));
13017 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13019 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13022 g_object_ref (custom_window);
13024 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13025 custom_window, g_object_unref);
13027 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13028 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13030 if (has_tooltip && gtk_widget_get_visible (widget))
13031 gtk_widget_queue_tooltip_query (widget);
13035 * gtk_widget_get_tooltip_window:
13036 * @widget: a #GtkWidget
13038 * Returns the #GtkWindow of the current tooltip. This can be the
13039 * GtkWindow created by default, or the custom tooltip window set
13040 * using gtk_widget_set_tooltip_window().
13042 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13047 gtk_widget_get_tooltip_window (GtkWidget *widget)
13049 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13051 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13055 * gtk_widget_trigger_tooltip_query:
13056 * @widget: a #GtkWidget
13058 * Triggers a tooltip query on the display where the toplevel of @widget
13059 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13065 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13067 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13070 static guint tooltip_query_id;
13071 static GSList *tooltip_query_displays;
13074 tooltip_query_idle (gpointer data)
13076 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13077 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13078 g_slist_free (tooltip_query_displays);
13080 tooltip_query_displays = NULL;
13081 tooltip_query_id = 0;
13087 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13089 GdkDisplay *display;
13091 display = gtk_widget_get_display (widget);
13093 if (!g_slist_find (tooltip_query_displays, display))
13094 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13096 if (tooltip_query_id == 0)
13097 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13101 * gtk_widget_set_tooltip_text:
13102 * @widget: a #GtkWidget
13103 * @text: the contents of the tooltip for @widget
13105 * Sets @text as the contents of the tooltip. This function will take
13106 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13107 * handler for the #GtkWidget::query-tooltip signal.
13109 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13114 gtk_widget_set_tooltip_text (GtkWidget *widget,
13117 g_return_if_fail (GTK_IS_WIDGET (widget));
13119 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13123 * gtk_widget_get_tooltip_text:
13124 * @widget: a #GtkWidget
13126 * Gets the contents of the tooltip for @widget.
13128 * Return value: the tooltip text, or %NULL. You should free the
13129 * returned string with g_free() when done.
13134 gtk_widget_get_tooltip_text (GtkWidget *widget)
13136 gchar *text = NULL;
13138 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13140 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13146 * gtk_widget_set_tooltip_markup:
13147 * @widget: a #GtkWidget
13148 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13150 * Sets @markup as the contents of the tooltip, which is marked up with
13151 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13153 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13154 * and of the default handler for the #GtkWidget::query-tooltip signal.
13156 * See also the #GtkWidget:tooltip-markup property and
13157 * gtk_tooltip_set_markup().
13162 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13163 const gchar *markup)
13165 g_return_if_fail (GTK_IS_WIDGET (widget));
13167 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13171 * gtk_widget_get_tooltip_markup:
13172 * @widget: a #GtkWidget
13174 * Gets the contents of the tooltip for @widget.
13176 * Return value: the tooltip text, or %NULL. You should free the
13177 * returned string with g_free() when done.
13182 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13184 gchar *text = NULL;
13186 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13188 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13194 * gtk_widget_set_has_tooltip:
13195 * @widget: a #GtkWidget
13196 * @has_tooltip: whether or not @widget has a tooltip.
13198 * Sets the has-tooltip property on @widget to @has_tooltip. See
13199 * #GtkWidget:has-tooltip for more information.
13204 gtk_widget_set_has_tooltip (GtkWidget *widget,
13205 gboolean has_tooltip)
13207 g_return_if_fail (GTK_IS_WIDGET (widget));
13209 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13213 * gtk_widget_get_has_tooltip:
13214 * @widget: a #GtkWidget
13216 * Returns the current value of the has-tooltip property. See
13217 * #GtkWidget:has-tooltip for more information.
13219 * Return value: current value of has-tooltip on @widget.
13224 gtk_widget_get_has_tooltip (GtkWidget *widget)
13226 gboolean has_tooltip = FALSE;
13228 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13230 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13232 return has_tooltip;
13236 * gtk_widget_get_allocation:
13237 * @widget: a #GtkWidget
13238 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13240 * Retrieves the widget's allocation.
13242 * Note, when implementing a #GtkContainer: a widget's allocation will
13243 * be its "adjusted" allocation, that is, the widget's parent
13244 * container typically calls gtk_widget_size_allocate() with an
13245 * allocation, and that allocation is then adjusted (to handle margin
13246 * and alignment for example) before assignment to the widget.
13247 * gtk_widget_get_allocation() returns the adjusted allocation that
13248 * was actually assigned to the widget. The adjusted allocation is
13249 * guaranteed to be completely contained within the
13250 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13251 * is guaranteed that its children stay inside the assigned bounds,
13252 * but not that they have exactly the bounds the container assigned.
13253 * There is no way to get the original allocation assigned by
13254 * gtk_widget_size_allocate(), since it isn't stored; if a container
13255 * implementation needs that information it will have to track it itself.
13260 gtk_widget_get_allocation (GtkWidget *widget,
13261 GtkAllocation *allocation)
13263 GtkWidgetPrivate *priv;
13265 g_return_if_fail (GTK_IS_WIDGET (widget));
13266 g_return_if_fail (allocation != NULL);
13268 priv = widget->priv;
13270 *allocation = priv->allocation;
13274 * gtk_widget_set_allocation:
13275 * @widget: a #GtkWidget
13276 * @allocation: a pointer to a #GtkAllocation to copy from
13278 * Sets the widget's allocation. This should not be used
13279 * directly, but from within a widget's size_allocate method.
13281 * The allocation set should be the "adjusted" or actual
13282 * allocation. If you're implementing a #GtkContainer, you want to use
13283 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13284 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13285 * allocation inside gtk_widget_size_allocate() to create an adjusted
13291 gtk_widget_set_allocation (GtkWidget *widget,
13292 const GtkAllocation *allocation)
13294 GtkWidgetPrivate *priv;
13296 g_return_if_fail (GTK_IS_WIDGET (widget));
13297 g_return_if_fail (allocation != NULL);
13299 priv = widget->priv;
13301 priv->allocation = *allocation;
13305 * gtk_widget_get_allocated_width:
13306 * @widget: the widget to query
13308 * Returns the width that has currently been allocated to @widget.
13309 * This function is intended to be used when implementing handlers
13310 * for the #GtkWidget::draw function.
13312 * Returns: the width of the @widget
13315 gtk_widget_get_allocated_width (GtkWidget *widget)
13317 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13319 return widget->priv->allocation.width;
13323 * gtk_widget_get_allocated_height:
13324 * @widget: the widget to query
13326 * Returns the height that has currently been allocated to @widget.
13327 * This function is intended to be used when implementing handlers
13328 * for the #GtkWidget::draw function.
13330 * Returns: the height of the @widget
13333 gtk_widget_get_allocated_height (GtkWidget *widget)
13335 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13337 return widget->priv->allocation.height;
13341 * gtk_widget_get_requisition:
13342 * @widget: a #GtkWidget
13343 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13345 * Retrieves the widget's requisition.
13347 * This function should only be used by widget implementations in
13348 * order to figure whether the widget's requisition has actually
13349 * changed after some internal state change (so that they can call
13350 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13352 * Normally, gtk_widget_size_request() should be used.
13356 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13357 * removed, If you need to cache sizes across requests and allocations,
13358 * add an explicit cache to the widget in question instead.
13361 gtk_widget_get_requisition (GtkWidget *widget,
13362 GtkRequisition *requisition)
13364 g_return_if_fail (GTK_IS_WIDGET (widget));
13365 g_return_if_fail (requisition != NULL);
13367 gtk_widget_get_preferred_size (widget, requisition, NULL);
13371 * gtk_widget_set_window:
13372 * @widget: a #GtkWidget
13373 * @window: (transfer full): a #GdkWindow
13375 * Sets a widget's window. This function should only be used in a
13376 * widget's #GtkWidget::realize implementation. The %window passed is
13377 * usually either new window created with gdk_window_new(), or the
13378 * window of its parent widget as returned by
13379 * gtk_widget_get_parent_window().
13381 * Widgets must indicate whether they will create their own #GdkWindow
13382 * by calling gtk_widget_set_has_window(). This is usually done in the
13383 * widget's init() function.
13385 * <note><para>This function does not add any reference to @window.</para></note>
13390 gtk_widget_set_window (GtkWidget *widget,
13393 GtkWidgetPrivate *priv;
13395 g_return_if_fail (GTK_IS_WIDGET (widget));
13396 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13398 priv = widget->priv;
13400 if (priv->window != window)
13402 priv->window = window;
13403 g_object_notify (G_OBJECT (widget), "window");
13408 * gtk_widget_get_window:
13409 * @widget: a #GtkWidget
13411 * Returns the widget's window if it is realized, %NULL otherwise
13413 * Return value: (transfer none): @widget's window.
13418 gtk_widget_get_window (GtkWidget *widget)
13420 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13422 return widget->priv->window;
13426 * gtk_widget_get_support_multidevice:
13427 * @widget: a #GtkWidget
13429 * Returns %TRUE if @widget is multiple pointer aware. See
13430 * gtk_widget_set_support_multidevice() for more information.
13432 * Returns: %TRUE if @widget is multidevice aware.
13435 gtk_widget_get_support_multidevice (GtkWidget *widget)
13437 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13439 return widget->priv->multidevice;
13443 * gtk_widget_set_support_multidevice:
13444 * @widget: a #GtkWidget
13445 * @support_multidevice: %TRUE to support input from multiple devices.
13447 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13448 * @widget will start receiving multiple, per device enter/leave events. Note
13449 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13450 * gdk_window_set_support_multidevice() will have to be called manually on them.
13455 gtk_widget_set_support_multidevice (GtkWidget *widget,
13456 gboolean support_multidevice)
13458 GtkWidgetPrivate *priv;
13460 g_return_if_fail (GTK_IS_WIDGET (widget));
13462 priv = widget->priv;
13463 priv->multidevice = (support_multidevice == TRUE);
13465 if (gtk_widget_get_realized (widget))
13466 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13470 _gtk_widget_set_has_focus (GtkWidget *widget,
13471 gboolean has_focus)
13473 widget->priv->has_focus = has_focus;
13476 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
13478 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
13482 * gtk_widget_send_focus_change:
13483 * @widget: a #GtkWidget
13484 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13486 * Sends the focus change @event to @widget
13488 * This function is not meant to be used by applications. The only time it
13489 * should be used is when it is necessary for a #GtkWidget to assign focus
13490 * to a widget that is semantically owned by the first widget even though
13491 * it's not a direct child - for instance, a search entry in a floating
13492 * window similar to the quick search in #GtkTreeView.
13494 * An example of its usage is:
13497 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13499 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13500 * fevent->focus_change.in = TRUE;
13501 * fevent->focus_change.window = gtk_widget_get_window (widget);
13502 * if (fevent->focus_change.window != NULL)
13503 * g_object_ref (fevent->focus_change.window);
13505 * gtk_widget_send_focus_change (widget, fevent);
13507 * gdk_event_free (event);
13510 * Return value: the return value from the event signal emission: %TRUE
13511 * if the event was handled, and %FALSE otherwise
13516 gtk_widget_send_focus_change (GtkWidget *widget,
13521 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13522 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13524 g_object_ref (widget);
13526 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13528 res = gtk_widget_event (widget, event);
13530 g_object_notify (G_OBJECT (widget), "has-focus");
13532 g_object_unref (widget);
13538 * gtk_widget_in_destruction:
13539 * @widget: a #GtkWidget
13541 * Returns whether the widget is currently being destroyed.
13542 * This information can sometimes be used to avoid doing
13543 * unnecessary work.
13545 * Returns: %TRUE if @widget is being destroyed
13548 gtk_widget_in_destruction (GtkWidget *widget)
13550 return widget->priv->in_destruction;
13554 _gtk_widget_get_resize_pending (GtkWidget *widget)
13556 return widget->priv->resize_pending;
13560 _gtk_widget_set_resize_pending (GtkWidget *widget,
13561 gboolean resize_pending)
13563 widget->priv->resize_pending = resize_pending;
13567 _gtk_widget_get_in_reparent (GtkWidget *widget)
13569 return widget->priv->in_reparent;
13573 _gtk_widget_set_in_reparent (GtkWidget *widget,
13574 gboolean in_reparent)
13576 widget->priv->in_reparent = in_reparent;
13580 _gtk_widget_get_anchored (GtkWidget *widget)
13582 return widget->priv->anchored;
13586 _gtk_widget_set_anchored (GtkWidget *widget,
13589 widget->priv->anchored = anchored;
13593 _gtk_widget_get_shadowed (GtkWidget *widget)
13595 return widget->priv->shadowed;
13599 _gtk_widget_set_shadowed (GtkWidget *widget,
13602 widget->priv->shadowed = shadowed;
13606 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13608 return widget->priv->alloc_needed;
13612 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13613 gboolean alloc_needed)
13615 widget->priv->alloc_needed = alloc_needed;
13619 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13621 return widget->priv->width_request_needed;
13625 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13626 gboolean width_request_needed)
13628 widget->priv->width_request_needed = width_request_needed;
13632 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13634 return widget->priv->height_request_needed;
13638 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13639 gboolean height_request_needed)
13641 widget->priv->height_request_needed = height_request_needed;
13645 _gtk_widget_get_sizegroup_visited (GtkWidget *widget)
13647 return widget->priv->sizegroup_visited;
13651 _gtk_widget_set_sizegroup_visited (GtkWidget *widget,
13654 widget->priv->sizegroup_visited = visited;
13658 _gtk_widget_get_sizegroup_bumping (GtkWidget *widget)
13660 return widget->priv->sizegroup_bumping;
13664 _gtk_widget_set_sizegroup_bumping (GtkWidget *widget,
13667 widget->priv->sizegroup_bumping = bumping;
13671 _gtk_widget_add_sizegroup (GtkWidget *widget,
13676 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13677 groups = g_slist_prepend (groups, group);
13678 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13680 widget->priv->have_size_groups = TRUE;
13684 _gtk_widget_remove_sizegroup (GtkWidget *widget,
13689 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13690 groups = g_slist_remove (groups, group);
13691 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13693 widget->priv->have_size_groups = groups != NULL;
13697 _gtk_widget_get_sizegroups (GtkWidget *widget)
13699 if (widget->priv->have_size_groups)
13700 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13706 * gtk_widget_path_append_for_widget:
13707 * @path: a widget path
13708 * @widget: the widget to append to the widget path
13710 * Appends the data from @widget to the widget hierarchy represented
13711 * by @path. This function is a shortcut for adding information from
13712 * @widget to the given @path. This includes setting the name or
13713 * adding the style classes from @widget.
13715 * Returns: the position where the data was inserted
13720 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
13725 g_return_val_if_fail (path != NULL, 0);
13726 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13728 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
13730 if (widget->priv->name)
13731 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
13733 if (widget->priv->context)
13735 GList *classes, *l;
13737 /* Also add any persistent classes in
13738 * the style context the widget path
13740 classes = gtk_style_context_list_classes (widget->priv->context);
13742 for (l = classes; l; l = l->next)
13743 gtk_widget_path_iter_add_class (path, pos, l->data);
13745 g_list_free (classes);
13752 * gtk_widget_get_path:
13753 * @widget: a #GtkWidget
13755 * Returns the #GtkWidgetPath representing @widget, if the widget
13756 * is not connected to a toplevel widget, a partial path will be
13759 * Returns: (transfer none): The #GtkWidgetPath representing @widget
13762 gtk_widget_get_path (GtkWidget *widget)
13764 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13766 /* As strange as it may seem, this may happen on object construction.
13767 * init() implementations of parent types may eventually call this function,
13768 * each with its corresponding GType, which could leave a child
13769 * implementation with a wrong widget type in the widget path
13771 if (widget->priv->path &&
13772 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (widget->priv->path))
13774 gtk_widget_path_free (widget->priv->path);
13775 widget->priv->path = NULL;
13778 if (!widget->priv->path)
13782 parent = widget->priv->parent;
13785 widget->priv->path = gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
13788 /* Widget is either toplevel or unparented, treat both
13789 * as toplevels style wise, since there are situations
13790 * where style properties might be retrieved on that
13793 widget->priv->path = gtk_widget_path_new ();
13795 gtk_widget_path_append_for_widget (widget->priv->path, widget);
13798 if (widget->priv->context)
13799 gtk_style_context_set_path (widget->priv->context,
13800 widget->priv->path);
13803 return widget->priv->path;
13807 style_context_changed (GtkStyleContext *context,
13808 gpointer user_data)
13810 GtkWidget *widget = user_data;
13812 if (gtk_widget_get_realized (widget))
13813 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
13816 /* Compress all style updates so it
13817 * is only emitted once pre-realize.
13819 widget->priv->style_update_pending = TRUE;
13822 if (widget->priv->anchored)
13823 gtk_widget_queue_resize (widget);
13827 * gtk_widget_get_style_context:
13828 * @widget: a #GtkWidget
13830 * Returns the style context associated to @widget.
13832 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
13833 * must not be freed.
13836 gtk_widget_get_style_context (GtkWidget *widget)
13838 GtkWidgetPrivate *priv;
13839 GtkWidgetPath *path;
13841 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13843 priv = widget->priv;
13845 /* updates style context if it exists already */
13846 path = gtk_widget_get_path (widget);
13848 if (G_UNLIKELY (priv->context == NULL))
13852 priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
13853 "direction", gtk_widget_get_direction (widget),
13856 g_signal_connect (widget->priv->context, "changed",
13857 G_CALLBACK (style_context_changed), widget);
13859 screen = gtk_widget_get_screen (widget);
13862 gtk_style_context_set_screen (priv->context, screen);
13864 gtk_style_context_set_path (priv->context, path);
13867 return widget->priv->context;
13871 * gtk_widget_get_modifier_mask:
13872 * @widget: a #GtkWidget
13873 * @intent: the use case for the modifier mask
13875 * Returns the modifier mask the @widget's windowing system backend
13876 * uses for a particular purpose.
13878 * See gdk_keymap_get_modifier_mask().
13880 * Returns: the modifier mask used for @intent.
13885 gtk_widget_get_modifier_mask (GtkWidget *widget,
13886 GdkModifierIntent intent)
13888 GdkDisplay *display;
13890 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13892 display = gtk_widget_get_display (widget);
13894 return gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
13899 _gtk_widget_get_style (GtkWidget *widget)
13901 return widget->priv->style;
13905 _gtk_widget_set_style (GtkWidget *widget,
13908 widget->priv->style = style;