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 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3790 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3791 g_object_unref (toplevel);
3794 /* Now that the parent pointer is nullified and the hierarchy-changed
3795 * already passed, go ahead and unset the parent window, if we are unparenting
3796 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
3797 * will fire again for the new subhierarchy.
3799 gtk_widget_set_parent_window (widget, NULL);
3801 g_object_notify (G_OBJECT (widget), "parent");
3802 g_object_thaw_notify (G_OBJECT (widget));
3804 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3805 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3807 gtk_widget_pop_verify_invariants (widget);
3808 g_object_unref (widget);
3812 * gtk_widget_destroy:
3813 * @widget: a #GtkWidget
3815 * Destroys a widget.
3818 * destroyed, it will break any references it holds to other objects.
3819 * If the widget is inside a container, the widget will be removed
3820 * from the container. If the widget is a toplevel (derived from
3821 * #GtkWindow), it will be removed from the list of toplevels, and the
3822 * reference GTK+ holds to it will be removed. Removing a
3823 * widget from its container or the list of toplevels results in the
3824 * widget being finalized, unless you've added additional references
3825 * to the widget with g_object_ref().
3827 * In most cases, only toplevel widgets (windows) require explicit
3828 * destruction, because when you destroy a toplevel its children will
3829 * be destroyed as well.
3832 gtk_widget_destroy (GtkWidget *widget)
3834 g_return_if_fail (GTK_IS_WIDGET (widget));
3836 if (!widget->priv->in_destruction)
3837 g_object_run_dispose (G_OBJECT (widget));
3841 * gtk_widget_destroyed:
3842 * @widget: a #GtkWidget
3843 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3845 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3846 * %NULL. It's intended to be used as a callback connected to the
3847 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3848 * as a signal handler, and pass the address of your widget variable
3849 * as user data. Then when the widget is destroyed, the variable will
3850 * be set to %NULL. Useful for example to avoid multiple copies
3851 * of the same dialog.
3854 gtk_widget_destroyed (GtkWidget *widget,
3855 GtkWidget **widget_pointer)
3857 /* Don't make any assumptions about the
3859 * Even check widget_pointer.
3862 *widget_pointer = NULL;
3867 * @widget: a #GtkWidget
3869 * Flags a widget to be displayed. Any widget that isn't shown will
3870 * not appear on the screen. If you want to show all the widgets in a
3871 * container, it's easier to call gtk_widget_show_all() on the
3872 * container, instead of individually showing the widgets.
3874 * Remember that you have to show the containers containing a widget,
3875 * in addition to the widget itself, before it will appear onscreen.
3877 * When a toplevel container is shown, it is immediately realized and
3878 * mapped; other shown widgets are realized and mapped when their
3879 * toplevel container is realized and mapped.
3882 gtk_widget_show (GtkWidget *widget)
3884 g_return_if_fail (GTK_IS_WIDGET (widget));
3886 if (!gtk_widget_get_visible (widget))
3888 g_object_ref (widget);
3889 gtk_widget_push_verify_invariants (widget);
3891 if (!gtk_widget_is_toplevel (widget))
3892 gtk_widget_queue_resize (widget);
3894 /* see comment in set_parent() for why this should and can be
3897 if (widget->priv->need_compute_expand ||
3898 widget->priv->computed_hexpand ||
3899 widget->priv->computed_vexpand)
3901 if (widget->priv->parent != NULL)
3902 gtk_widget_queue_compute_expand (widget->priv->parent);
3905 g_signal_emit (widget, widget_signals[SHOW], 0);
3906 g_object_notify (G_OBJECT (widget), "visible");
3908 gtk_widget_pop_verify_invariants (widget);
3909 g_object_unref (widget);
3914 gtk_widget_real_show (GtkWidget *widget)
3916 GtkWidgetPrivate *priv = widget->priv;
3918 if (!gtk_widget_get_visible (widget))
3920 priv->visible = TRUE;
3923 gtk_widget_get_mapped (priv->parent) &&
3924 gtk_widget_get_child_visible (widget) &&
3925 !gtk_widget_get_mapped (widget))
3926 gtk_widget_map (widget);
3931 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3934 g_signal_handlers_disconnect_by_func (widget,
3935 gtk_widget_show_map_callback,
3940 * gtk_widget_show_now:
3941 * @widget: a #GtkWidget
3943 * Shows a widget. If the widget is an unmapped toplevel widget
3944 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3945 * loop and wait for the window to actually be mapped. Be careful;
3946 * because the main loop is running, anything can happen during
3950 gtk_widget_show_now (GtkWidget *widget)
3954 g_return_if_fail (GTK_IS_WIDGET (widget));
3956 /* make sure we will get event */
3957 if (!gtk_widget_get_mapped (widget) &&
3958 gtk_widget_is_toplevel (widget))
3960 gtk_widget_show (widget);
3962 g_signal_connect (widget, "map-event",
3963 G_CALLBACK (gtk_widget_show_map_callback),
3967 gtk_main_iteration ();
3970 gtk_widget_show (widget);
3975 * @widget: a #GtkWidget
3977 * Reverses the effects of gtk_widget_show(), causing the widget to be
3978 * hidden (invisible to the user).
3981 gtk_widget_hide (GtkWidget *widget)
3983 g_return_if_fail (GTK_IS_WIDGET (widget));
3985 if (gtk_widget_get_visible (widget))
3987 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3989 g_object_ref (widget);
3990 gtk_widget_push_verify_invariants (widget);
3992 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3993 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3995 /* a parent may now be expand=FALSE since we're hidden. */
3996 if (widget->priv->need_compute_expand ||
3997 widget->priv->computed_hexpand ||
3998 widget->priv->computed_vexpand)
4000 gtk_widget_queue_compute_expand (widget);
4003 g_signal_emit (widget, widget_signals[HIDE], 0);
4004 if (!gtk_widget_is_toplevel (widget))
4005 gtk_widget_queue_resize (widget);
4006 g_object_notify (G_OBJECT (widget), "visible");
4008 gtk_widget_pop_verify_invariants (widget);
4009 g_object_unref (widget);
4014 gtk_widget_real_hide (GtkWidget *widget)
4016 if (gtk_widget_get_visible (widget))
4018 widget->priv->visible = FALSE;
4020 if (gtk_widget_get_mapped (widget))
4021 gtk_widget_unmap (widget);
4026 * gtk_widget_hide_on_delete:
4027 * @widget: a #GtkWidget
4029 * Utility function; intended to be connected to the #GtkWidget::delete-event
4030 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4031 * argument, then returns %TRUE. If connected to ::delete-event, the
4032 * result is that clicking the close button for a window (on the
4033 * window frame, top right corner usually) will hide but not destroy
4034 * the window. By default, GTK+ destroys windows when ::delete-event
4037 * Return value: %TRUE
4040 gtk_widget_hide_on_delete (GtkWidget *widget)
4042 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4044 gtk_widget_hide (widget);
4050 * gtk_widget_show_all:
4051 * @widget: a #GtkWidget
4053 * Recursively shows a widget, and any child widgets (if the widget is
4057 gtk_widget_show_all (GtkWidget *widget)
4059 GtkWidgetClass *class;
4061 g_return_if_fail (GTK_IS_WIDGET (widget));
4063 if (gtk_widget_get_no_show_all (widget))
4066 class = GTK_WIDGET_GET_CLASS (widget);
4068 if (class->show_all)
4069 class->show_all (widget);
4073 _gtk_widget_notify_state_change (GtkWidget *widget,
4081 case GTK_STATE_FLAG_ACTIVE:
4082 state = GTK_STATE_ACTIVE;
4084 case GTK_STATE_FLAG_PRELIGHT:
4085 state = GTK_STATE_PRELIGHT;
4087 case GTK_STATE_FLAG_SELECTED:
4088 state = GTK_STATE_SELECTED;
4090 case GTK_STATE_FLAG_INSENSITIVE:
4091 state = GTK_STATE_INSENSITIVE;
4093 case GTK_STATE_FLAG_INCONSISTENT:
4094 state = GTK_STATE_INCONSISTENT;
4096 case GTK_STATE_FLAG_FOCUSED:
4097 state = GTK_STATE_FOCUSED;
4103 gtk_style_context_notify_state_change (widget->priv->context,
4104 gtk_widget_get_window (widget),
4105 NULL, state, target);
4108 /* Initializes state transitions for those states that
4109 * were enabled before mapping and have a looping animation.
4112 _gtk_widget_start_state_transitions (GtkWidget *widget)
4114 GtkStateFlags state, flag;
4116 if (!widget->priv->context)
4119 state = gtk_widget_get_state_flags (widget);
4120 flag = GTK_STATE_FLAG_FOCUSED;
4124 GtkAnimationDescription *animation_desc;
4126 if ((state & flag) == 0)
4132 gtk_style_context_get (widget->priv->context, state,
4133 "transition", &animation_desc,
4138 if (_gtk_animation_description_get_loop (animation_desc))
4139 _gtk_widget_notify_state_change (widget, flag, TRUE);
4141 _gtk_animation_description_unref (animation_desc);
4150 * @widget: a #GtkWidget
4152 * This function is only for use in widget implementations. Causes
4153 * a widget to be mapped if it isn't already.
4156 gtk_widget_map (GtkWidget *widget)
4158 GtkWidgetPrivate *priv;
4160 g_return_if_fail (GTK_IS_WIDGET (widget));
4161 g_return_if_fail (gtk_widget_get_visible (widget));
4162 g_return_if_fail (gtk_widget_get_child_visible (widget));
4164 priv = widget->priv;
4166 if (!gtk_widget_get_mapped (widget))
4168 gtk_widget_push_verify_invariants (widget);
4170 if (!gtk_widget_get_realized (widget))
4171 gtk_widget_realize (widget);
4173 g_signal_emit (widget, widget_signals[MAP], 0);
4175 if (!gtk_widget_get_has_window (widget))
4176 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4178 gtk_widget_pop_verify_invariants (widget);
4180 _gtk_widget_start_state_transitions (widget);
4186 * @widget: a #GtkWidget
4188 * This function is only for use in widget implementations. Causes
4189 * a widget to be unmapped if it's currently mapped.
4192 gtk_widget_unmap (GtkWidget *widget)
4194 GtkWidgetPrivate *priv;
4196 g_return_if_fail (GTK_IS_WIDGET (widget));
4198 priv = widget->priv;
4200 if (gtk_widget_get_mapped (widget))
4202 gtk_widget_push_verify_invariants (widget);
4204 if (!gtk_widget_get_has_window (widget))
4205 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4206 _gtk_tooltip_hide (widget);
4207 g_signal_emit (widget, widget_signals[UNMAP], 0);
4209 gtk_widget_pop_verify_invariants (widget);
4212 gtk_style_context_cancel_animations (priv->context, NULL);
4214 /* Unset pointer/window info */
4215 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4220 _gtk_widget_enable_device_events (GtkWidget *widget)
4222 GHashTable *device_events;
4223 GHashTableIter iter;
4224 gpointer key, value;
4226 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4231 g_hash_table_iter_init (&iter, device_events);
4233 while (g_hash_table_iter_next (&iter, &key, &value))
4236 GdkEventMask event_mask;
4239 event_mask = GPOINTER_TO_UINT (value);
4240 gtk_widget_add_events_internal (widget, device, event_mask);
4245 get_widget_windows (GtkWidget *widget)
4247 GList *window_list, *last, *l, *children, *ret;
4249 if (gtk_widget_get_has_window (widget))
4250 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4252 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4254 last = g_list_last (window_list);
4257 for (l = window_list; l; l = l->next)
4259 GtkWidget *window_widget = NULL;
4261 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4263 if (widget != window_widget)
4266 ret = g_list_prepend (ret, l->data);
4267 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4271 last = g_list_concat (last, children);
4272 last = g_list_last (last);
4276 g_list_free (window_list);
4282 device_enable_foreach (GtkWidget *widget,
4285 GdkDevice *device = user_data;
4286 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4290 device_disable_foreach (GtkWidget *widget,
4293 GdkDevice *device = user_data;
4294 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4298 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4303 GList *window_list, *l;
4305 window_list = get_widget_windows (widget);
4307 for (l = window_list; l; l = l->next)
4309 GdkEventMask events = 0;
4315 events = gdk_window_get_events (window);
4317 gdk_window_set_device_events (window, device, events);
4320 if (recurse && GTK_IS_CONTAINER (widget))
4323 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4325 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4328 g_list_free (window_list);
4332 gtk_widget_update_devices_mask (GtkWidget *widget,
4335 GList *enabled_devices, *l;
4337 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4339 for (l = enabled_devices; l; l = l->next)
4340 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4344 * gtk_widget_realize:
4345 * @widget: a #GtkWidget
4347 * Creates the GDK (windowing system) resources associated with a
4348 * widget. For example, @widget->window will be created when a widget
4349 * is realized. Normally realization happens implicitly; if you show
4350 * a widget and all its parent containers, then the widget will be
4351 * realized and mapped automatically.
4353 * Realizing a widget requires all
4354 * the widget's parent widgets to be realized; calling
4355 * gtk_widget_realize() realizes the widget's parents in addition to
4356 * @widget itself. If a widget is not yet inside a toplevel window
4357 * when you realize it, bad things will happen.
4359 * This function is primarily used in widget implementations, and
4360 * isn't very useful otherwise. Many times when you think you might
4361 * need it, a better approach is to connect to a signal that will be
4362 * called after the widget is realized automatically, such as
4363 * #GtkWidget::draw. Or simply g_signal_connect () to the
4364 * #GtkWidget::realize signal.
4367 gtk_widget_realize (GtkWidget *widget)
4369 GtkWidgetPrivate *priv;
4370 cairo_region_t *region;
4372 g_return_if_fail (GTK_IS_WIDGET (widget));
4373 g_return_if_fail (widget->priv->anchored ||
4374 GTK_IS_INVISIBLE (widget));
4376 priv = widget->priv;
4378 if (!gtk_widget_get_realized (widget))
4380 gtk_widget_push_verify_invariants (widget);
4383 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4384 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4387 if (priv->parent == NULL &&
4388 !gtk_widget_is_toplevel (widget))
4389 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4390 "inside a toplevel window is not going to work very well. "
4391 "Widgets must be inside a toplevel container before realizing them.");
4393 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4394 gtk_widget_realize (priv->parent);
4396 gtk_widget_ensure_style (widget);
4398 if (priv->style_update_pending)
4399 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4401 g_signal_emit (widget, widget_signals[REALIZE], 0);
4403 gtk_widget_real_set_has_tooltip (widget,
4404 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4407 if (priv->has_shape_mask)
4409 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4410 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4413 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4415 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4417 if (priv->multidevice)
4418 gdk_window_set_support_multidevice (priv->window, TRUE);
4420 _gtk_widget_enable_device_events (widget);
4421 gtk_widget_update_devices_mask (widget, TRUE);
4423 gtk_widget_pop_verify_invariants (widget);
4428 * gtk_widget_unrealize:
4429 * @widget: a #GtkWidget
4431 * This function is only useful in widget implementations.
4432 * Causes a widget to be unrealized (frees all GDK resources
4433 * associated with the widget, such as @widget->window).
4436 gtk_widget_unrealize (GtkWidget *widget)
4438 g_return_if_fail (GTK_IS_WIDGET (widget));
4440 gtk_widget_push_verify_invariants (widget);
4442 if (widget->priv->has_shape_mask)
4443 gtk_widget_shape_combine_region (widget, NULL);
4445 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4446 gtk_widget_input_shape_combine_region (widget, NULL);
4448 if (gtk_widget_get_realized (widget))
4450 g_object_ref (widget);
4452 if (widget->priv->mapped)
4453 gtk_widget_unmap (widget);
4455 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4456 g_assert (!widget->priv->mapped);
4457 gtk_widget_set_realized (widget, FALSE);
4459 g_object_unref (widget);
4462 gtk_widget_pop_verify_invariants (widget);
4465 /*****************************************
4467 *****************************************/
4470 * gtk_widget_queue_draw_region:
4471 * @widget: a #GtkWidget
4472 * @region: region to draw
4474 * Invalidates the rectangular area of @widget defined by @region by
4475 * calling gdk_window_invalidate_region() on the widget's window and
4476 * all its child windows. Once the main loop becomes idle (after the
4477 * current batch of events has been processed, roughly), the window
4478 * will receive expose events for the union of all regions that have
4481 * Normally you would only use this function in widget
4482 * implementations. You might also use it to schedule a redraw of a
4483 * #GtkDrawingArea or some portion thereof.
4488 gtk_widget_queue_draw_region (GtkWidget *widget,
4489 const cairo_region_t *region)
4491 GtkWidgetPrivate *priv;
4494 g_return_if_fail (GTK_IS_WIDGET (widget));
4496 priv = widget->priv;
4498 if (!gtk_widget_get_realized (widget))
4501 /* Just return if the widget or one of its ancestors isn't mapped */
4502 for (w = widget; w != NULL; w = w->priv->parent)
4503 if (!gtk_widget_get_mapped (w))
4506 gdk_window_invalidate_region (priv->window, region, TRUE);
4510 * gtk_widget_queue_draw_area:
4511 * @widget: a #GtkWidget
4512 * @x: x coordinate of upper-left corner of rectangle to redraw
4513 * @y: y coordinate of upper-left corner of rectangle to redraw
4514 * @width: width of region to draw
4515 * @height: height of region to draw
4517 * Convenience function that calls gtk_widget_queue_draw_region() on
4518 * the region created from the given coordinates.
4520 * The region here is specified in widget coordinates.
4521 * Widget coordinates are a bit odd; for historical reasons, they are
4522 * defined as @widget->window coordinates for widgets that are not
4523 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4524 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4527 gtk_widget_queue_draw_area (GtkWidget *widget,
4534 cairo_region_t *region;
4536 g_return_if_fail (GTK_IS_WIDGET (widget));
4541 rect.height = height;
4543 region = cairo_region_create_rectangle (&rect);
4544 gtk_widget_queue_draw_region (widget, region);
4545 cairo_region_destroy (region);
4549 * gtk_widget_queue_draw:
4550 * @widget: a #GtkWidget
4552 * Equivalent to calling gtk_widget_queue_draw_area() for the
4553 * entire area of a widget.
4556 gtk_widget_queue_draw (GtkWidget *widget)
4560 g_return_if_fail (GTK_IS_WIDGET (widget));
4562 gtk_widget_get_allocation (widget, &rect);
4564 if (!gtk_widget_get_has_window (widget))
4565 gtk_widget_queue_draw_area (widget,
4566 rect.x, rect.y, rect.width, rect.height);
4568 gtk_widget_queue_draw_area (widget,
4569 0, 0, rect.width, rect.height);
4573 * gtk_widget_queue_resize:
4574 * @widget: a #GtkWidget
4576 * This function is only for use in widget implementations.
4577 * Flags a widget to have its size renegotiated; should
4578 * be called when a widget for some reason has a new size request.
4579 * For example, when you change the text in a #GtkLabel, #GtkLabel
4580 * queues a resize to ensure there's enough space for the new text.
4582 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4583 * from inside its implementation of the GtkWidgetClass::size_allocate
4584 * virtual method. Calls to gtk_widget_queue_resize() from inside
4585 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4588 gtk_widget_queue_resize (GtkWidget *widget)
4590 g_return_if_fail (GTK_IS_WIDGET (widget));
4592 if (gtk_widget_get_realized (widget))
4593 gtk_widget_queue_shallow_draw (widget);
4595 _gtk_size_group_queue_resize (widget, 0);
4599 * gtk_widget_queue_resize_no_redraw:
4600 * @widget: a #GtkWidget
4602 * This function works like gtk_widget_queue_resize(),
4603 * except that the widget is not invalidated.
4608 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4610 g_return_if_fail (GTK_IS_WIDGET (widget));
4612 _gtk_size_group_queue_resize (widget, 0);
4616 * gtk_widget_size_request:
4617 * @widget: a #GtkWidget
4618 * @requisition: (out): a #GtkRequisition to be filled in
4620 * This function is typically used when implementing a #GtkContainer
4621 * subclass. Obtains the preferred size of a widget. The container
4622 * uses this information to arrange its child widgets and decide what
4623 * size allocations to give them with gtk_widget_size_allocate().
4625 * You can also call this function from an application, with some
4626 * caveats. Most notably, getting a size request requires the widget
4627 * to be associated with a screen, because font information may be
4628 * needed. Multihead-aware applications should keep this in mind.
4630 * Also remember that the size request is not necessarily the size
4631 * a widget will actually be allocated.
4633 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4636 gtk_widget_size_request (GtkWidget *widget,
4637 GtkRequisition *requisition)
4639 g_return_if_fail (GTK_IS_WIDGET (widget));
4641 gtk_widget_get_preferred_size (widget, requisition, NULL);
4645 * gtk_widget_get_child_requisition:
4646 * @widget: a #GtkWidget
4647 * @requisition: (out): a #GtkRequisition to be filled in
4649 * This function is only for use in widget implementations. Obtains
4650 * @widget->requisition, unless someone has forced a particular
4651 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4652 * in which case it returns that geometry instead of the widget's
4655 * This function differs from gtk_widget_size_request() in that
4656 * it retrieves the last size request value from @widget->requisition,
4657 * while gtk_widget_size_request() actually calls the "size_request" method
4658 * on @widget to compute the size request and fill in @widget->requisition,
4659 * and only then returns @widget->requisition.
4661 * Because this function does not call the "size_request" method, it
4662 * can only be used when you know that @widget->requisition is
4663 * up-to-date, that is, gtk_widget_size_request() has been called
4664 * since the last time a resize was queued. In general, only container
4665 * implementations have this information; applications should use
4666 * gtk_widget_size_request().
4669 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4672 gtk_widget_get_child_requisition (GtkWidget *widget,
4673 GtkRequisition *requisition)
4675 gtk_widget_get_preferred_size (widget, requisition, NULL);
4679 invalidate_predicate (GdkWindow *window,
4684 gdk_window_get_user_data (window, &user_data);
4686 return (user_data == data);
4689 /* Invalidate @region in widget->window and all children
4690 * of widget->window owned by widget. @region is in the
4691 * same coordinates as widget->allocation and will be
4692 * modified by this call.
4695 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4696 cairo_region_t *region)
4698 GtkWidgetPrivate *priv = widget->priv;
4700 if (!gtk_widget_get_realized (widget))
4703 if (gtk_widget_get_has_window (widget) && priv->parent)
4707 gdk_window_get_position (priv->window, &x, &y);
4708 cairo_region_translate (region, -x, -y);
4711 gdk_window_invalidate_maybe_recurse (priv->window, region,
4712 invalidate_predicate, widget);
4716 * gtk_widget_queue_shallow_draw:
4717 * @widget: a #GtkWidget
4719 * Like gtk_widget_queue_draw(), but only windows owned
4720 * by @widget are invalidated.
4723 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4726 cairo_region_t *region;
4728 if (!gtk_widget_get_realized (widget))
4731 gtk_widget_get_allocation (widget, &rect);
4733 region = cairo_region_create_rectangle (&rect);
4734 gtk_widget_invalidate_widget_windows (widget, region);
4735 cairo_region_destroy (region);
4739 * gtk_widget_size_allocate:
4740 * @widget: a #GtkWidget
4741 * @allocation: position and size to be allocated to @widget
4743 * This function is only used by #GtkContainer subclasses, to assign a size
4744 * and position to their child widgets.
4746 * In this function, the allocation may be adjusted. It will be forced
4747 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4748 * method on the child will be used to adjust the allocation. Standard
4749 * adjustments include removing the widget's margins, and applying the
4750 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4753 gtk_widget_size_allocate (GtkWidget *widget,
4754 GtkAllocation *allocation)
4756 GtkWidgetPrivate *priv;
4757 GdkRectangle real_allocation;
4758 GdkRectangle old_allocation;
4759 GdkRectangle adjusted_allocation;
4760 gboolean alloc_needed;
4761 gboolean size_changed;
4762 gboolean position_changed;
4763 gint natural_width, natural_height, dummy;
4764 gint min_width, min_height;
4766 priv = widget->priv;
4768 g_return_if_fail (GTK_IS_WIDGET (widget));
4770 gtk_widget_push_verify_invariants (widget);
4772 #ifdef G_ENABLE_DEBUG
4773 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4784 parent = gtk_widget_get_parent (parent);
4787 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4788 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4789 2 * depth, " ", name,
4790 allocation->width, allocation->height);
4792 #endif /* G_ENABLE_DEBUG */
4794 alloc_needed = priv->alloc_needed;
4795 if (!priv->width_request_needed && !priv->height_request_needed)
4796 /* Preserve request/allocate ordering */
4797 priv->alloc_needed = FALSE;
4799 old_allocation = priv->allocation;
4800 real_allocation = *allocation;
4802 adjusted_allocation = real_allocation;
4803 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4805 /* Go ahead and request the height for allocated width, note that the internals
4806 * of get_height_for_width will internally limit the for_size to natural size
4807 * when aligning implicitly.
4809 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4810 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
4814 /* Go ahead and request the width for allocated height, note that the internals
4815 * of get_width_for_height will internally limit the for_size to natural size
4816 * when aligning implicitly.
4818 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4819 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
4822 #ifdef G_ENABLE_DEBUG
4823 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4825 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
4826 !GTK_IS_SCROLLABLE (widget))
4827 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
4828 "Allocation is %dx%d, but minimum required size is %dx%d.",
4829 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
4830 G_OBJECT_TYPE_NAME (widget), widget,
4831 real_allocation.width, real_allocation.height,
4832 min_width, min_height);
4835 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4836 * allocated sizes and possibly limit them to the natural sizes */
4837 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4838 GTK_ORIENTATION_HORIZONTAL,
4841 &adjusted_allocation.x,
4842 &adjusted_allocation.width);
4843 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4844 GTK_ORIENTATION_VERTICAL,
4847 &adjusted_allocation.y,
4848 &adjusted_allocation.height);
4850 if (adjusted_allocation.x < real_allocation.x ||
4851 adjusted_allocation.y < real_allocation.y ||
4852 (adjusted_allocation.x + adjusted_allocation.width) >
4853 (real_allocation.x + real_allocation.width) ||
4854 (adjusted_allocation.y + adjusted_allocation.height >
4855 real_allocation.y + real_allocation.height))
4857 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",
4858 G_OBJECT_TYPE_NAME (widget), widget,
4859 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4860 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4861 adjusted_allocation = real_allocation; /* veto it */
4865 real_allocation = adjusted_allocation;
4868 if (real_allocation.width < 0 || real_allocation.height < 0)
4870 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4871 real_allocation.width,
4872 real_allocation.height);
4875 real_allocation.width = MAX (real_allocation.width, 1);
4876 real_allocation.height = MAX (real_allocation.height, 1);
4878 size_changed = (old_allocation.width != real_allocation.width ||
4879 old_allocation.height != real_allocation.height);
4880 position_changed = (old_allocation.x != real_allocation.x ||
4881 old_allocation.y != real_allocation.y);
4883 if (!alloc_needed && !size_changed && !position_changed)
4886 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4888 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4889 priv->width_request_needed = FALSE;
4890 priv->height_request_needed = FALSE;
4891 priv->alloc_needed = FALSE;
4893 if (gtk_widget_get_mapped (widget))
4895 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4897 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4899 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4900 cairo_region_union_rectangle (invalidate, &old_allocation);
4902 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4903 cairo_region_destroy (invalidate);
4908 if (priv->redraw_on_alloc)
4910 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4912 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4913 cairo_region_union_rectangle (invalidate, &old_allocation);
4915 gtk_widget_invalidate_widget_windows (widget, invalidate);
4916 cairo_region_destroy (invalidate);
4920 if (size_changed || position_changed)
4922 GtkStyleContext *context;
4924 context = gtk_widget_get_style_context (widget);
4925 _gtk_style_context_invalidate_animation_areas (context);
4929 if ((size_changed || position_changed) && priv->parent &&
4930 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4932 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4933 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4934 cairo_region_destroy (invalidate);
4938 gtk_widget_pop_verify_invariants (widget);
4942 * gtk_widget_common_ancestor:
4943 * @widget_a: a #GtkWidget
4944 * @widget_b: a #GtkWidget
4946 * Find the common ancestor of @widget_a and @widget_b that
4947 * is closest to the two widgets.
4949 * Return value: the closest common ancestor of @widget_a and
4950 * @widget_b or %NULL if @widget_a and @widget_b do not
4951 * share a common ancestor.
4954 gtk_widget_common_ancestor (GtkWidget *widget_a,
4955 GtkWidget *widget_b)
4957 GtkWidget *parent_a;
4958 GtkWidget *parent_b;
4962 parent_a = widget_a;
4963 while (parent_a->priv->parent)
4965 parent_a = parent_a->priv->parent;
4969 parent_b = widget_b;
4970 while (parent_b->priv->parent)
4972 parent_b = parent_b->priv->parent;
4976 if (parent_a != parent_b)
4979 while (depth_a > depth_b)
4981 widget_a = widget_a->priv->parent;
4985 while (depth_b > depth_a)
4987 widget_b = widget_b->priv->parent;
4991 while (widget_a != widget_b)
4993 widget_a = widget_a->priv->parent;
4994 widget_b = widget_b->priv->parent;
5001 * gtk_widget_translate_coordinates:
5002 * @src_widget: a #GtkWidget
5003 * @dest_widget: a #GtkWidget
5004 * @src_x: X position relative to @src_widget
5005 * @src_y: Y position relative to @src_widget
5006 * @dest_x: (out): location to store X position relative to @dest_widget
5007 * @dest_y: (out): location to store Y position relative to @dest_widget
5009 * Translate coordinates relative to @src_widget's allocation to coordinates
5010 * relative to @dest_widget's allocations. In order to perform this
5011 * operation, both widgets must be realized, and must share a common
5014 * Return value: %FALSE if either widget was not realized, or there
5015 * was no common ancestor. In this case, nothing is stored in
5016 * *@dest_x and *@dest_y. Otherwise %TRUE.
5019 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5020 GtkWidget *dest_widget,
5026 GtkWidgetPrivate *src_priv = src_widget->priv;
5027 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5028 GtkWidget *ancestor;
5030 GList *dest_list = NULL;
5032 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5033 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5035 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5036 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5039 /* Translate from allocation relative to window relative */
5040 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5043 gdk_window_get_position (src_priv->window, &wx, &wy);
5045 src_x -= wx - src_priv->allocation.x;
5046 src_y -= wy - src_priv->allocation.y;
5050 src_x += src_priv->allocation.x;
5051 src_y += src_priv->allocation.y;
5054 /* Translate to the common ancestor */
5055 window = src_priv->window;
5056 while (window != ancestor->priv->window)
5060 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5065 window = gdk_window_get_effective_parent (window);
5067 if (!window) /* Handle GtkHandleBox */
5072 window = dest_priv->window;
5073 while (window != ancestor->priv->window)
5075 dest_list = g_list_prepend (dest_list, window);
5077 window = gdk_window_get_effective_parent (window);
5079 if (!window) /* Handle GtkHandleBox */
5081 g_list_free (dest_list);
5090 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5095 dest_list = g_list_remove (dest_list, dest_list->data);
5098 /* Translate from window relative to allocation relative */
5099 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5102 gdk_window_get_position (dest_priv->window, &wx, &wy);
5104 src_x += wx - dest_priv->allocation.x;
5105 src_y += wy - dest_priv->allocation.y;
5109 src_x -= dest_priv->allocation.x;
5110 src_y -= dest_priv->allocation.y;
5122 gtk_widget_real_size_allocate (GtkWidget *widget,
5123 GtkAllocation *allocation)
5125 GtkWidgetPrivate *priv = widget->priv;
5127 priv->allocation = *allocation;
5129 if (gtk_widget_get_realized (widget) &&
5130 gtk_widget_get_has_window (widget))
5132 gdk_window_move_resize (priv->window,
5133 allocation->x, allocation->y,
5134 allocation->width, allocation->height);
5138 /* translate initial/final into start/end */
5140 effective_align (GtkAlign align,
5141 GtkTextDirection direction)
5145 case GTK_ALIGN_START:
5146 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5148 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5155 adjust_for_align (GtkAlign align,
5157 gint *allocated_pos,
5158 gint *allocated_size)
5162 case GTK_ALIGN_FILL:
5163 /* change nothing */
5165 case GTK_ALIGN_START:
5166 /* keep *allocated_pos where it is */
5167 *allocated_size = MIN (*allocated_size, *natural_size);
5170 if (*allocated_size > *natural_size)
5172 *allocated_pos += (*allocated_size - *natural_size);
5173 *allocated_size = *natural_size;
5176 case GTK_ALIGN_CENTER:
5177 if (*allocated_size > *natural_size)
5179 *allocated_pos += (*allocated_size - *natural_size) / 2;
5180 *allocated_size = MIN (*allocated_size, *natural_size);
5187 adjust_for_margin(gint start_margin,
5191 gint *allocated_pos,
5192 gint *allocated_size)
5194 *minimum_size -= (start_margin + end_margin);
5195 *natural_size -= (start_margin + end_margin);
5196 *allocated_pos += start_margin;
5197 *allocated_size -= (start_margin + end_margin);
5201 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5202 GtkOrientation orientation,
5205 gint *allocated_pos,
5206 gint *allocated_size)
5208 const GtkWidgetAuxInfo *aux_info;
5210 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5212 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5214 adjust_for_margin (aux_info->margin.left,
5215 aux_info->margin.right,
5216 minimum_size, natural_size,
5217 allocated_pos, allocated_size);
5218 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5219 natural_size, allocated_pos, allocated_size);
5223 adjust_for_margin (aux_info->margin.top,
5224 aux_info->margin.bottom,
5225 minimum_size, natural_size,
5226 allocated_pos, allocated_size);
5227 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5228 natural_size, allocated_pos, allocated_size);
5233 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5236 GtkWidgetPrivate *priv = widget->priv;
5238 /* widgets must be onscreen for accels to take effect */
5239 return gtk_widget_is_sensitive (widget) &&
5240 gtk_widget_is_drawable (widget) &&
5241 gdk_window_is_viewable (priv->window);
5245 * gtk_widget_can_activate_accel:
5246 * @widget: a #GtkWidget
5247 * @signal_id: the ID of a signal installed on @widget
5249 * Determines whether an accelerator that activates the signal
5250 * identified by @signal_id can currently be activated.
5251 * This is done by emitting the #GtkWidget::can-activate-accel
5252 * signal on @widget; if the signal isn't overridden by a
5253 * handler or in a derived widget, then the default check is
5254 * that the widget must be sensitive, and the widget and all
5255 * its ancestors mapped.
5257 * Return value: %TRUE if the accelerator can be activated.
5262 gtk_widget_can_activate_accel (GtkWidget *widget,
5265 gboolean can_activate = FALSE;
5266 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5267 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5268 return can_activate;
5277 closure_accel_activate (GClosure *closure,
5278 GValue *return_value,
5279 guint n_param_values,
5280 const GValue *param_values,
5281 gpointer invocation_hint,
5282 gpointer marshal_data)
5284 AccelClosure *aclosure = (AccelClosure*) closure;
5285 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5288 g_signal_emit (closure->data, aclosure->signal_id, 0);
5290 /* whether accelerator was handled */
5291 g_value_set_boolean (return_value, can_activate);
5295 closures_destroy (gpointer data)
5297 GSList *slist, *closures = data;
5299 for (slist = closures; slist; slist = slist->next)
5301 g_closure_invalidate (slist->data);
5302 g_closure_unref (slist->data);
5304 g_slist_free (closures);
5308 widget_new_accel_closure (GtkWidget *widget,
5311 AccelClosure *aclosure;
5312 GClosure *closure = NULL;
5313 GSList *slist, *closures;
5315 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5316 for (slist = closures; slist; slist = slist->next)
5317 if (!gtk_accel_group_from_accel_closure (slist->data))
5319 /* reuse this closure */
5320 closure = slist->data;
5325 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5326 closures = g_slist_prepend (closures, g_closure_ref (closure));
5327 g_closure_sink (closure);
5328 g_closure_set_marshal (closure, closure_accel_activate);
5330 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5332 aclosure = (AccelClosure*) closure;
5333 g_assert (closure->data == widget);
5334 g_assert (closure->marshal == closure_accel_activate);
5335 aclosure->signal_id = signal_id;
5341 * gtk_widget_add_accelerator
5342 * @widget: widget to install an accelerator on
5343 * @accel_signal: widget signal to emit on accelerator activation
5344 * @accel_group: accel group for this widget, added to its toplevel
5345 * @accel_key: GDK keyval of the accelerator
5346 * @accel_mods: modifier key combination of the accelerator
5347 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5349 * Installs an accelerator for this @widget in @accel_group that causes
5350 * @accel_signal to be emitted if the accelerator is activated.
5351 * The @accel_group needs to be added to the widget's toplevel via
5352 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5353 * Accelerators added through this function are not user changeable during
5354 * runtime. If you want to support accelerators that can be changed by the
5355 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5356 * gtk_menu_item_set_accel_path() instead.
5359 gtk_widget_add_accelerator (GtkWidget *widget,
5360 const gchar *accel_signal,
5361 GtkAccelGroup *accel_group,
5363 GdkModifierType accel_mods,
5364 GtkAccelFlags accel_flags)
5369 g_return_if_fail (GTK_IS_WIDGET (widget));
5370 g_return_if_fail (accel_signal != NULL);
5371 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5373 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5374 if (!query.signal_id ||
5375 !(query.signal_flags & G_SIGNAL_ACTION) ||
5376 query.return_type != G_TYPE_NONE ||
5379 /* hmm, should be elaborate enough */
5380 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5381 G_OBJECT_TYPE_NAME (widget), accel_signal);
5385 closure = widget_new_accel_closure (widget, query.signal_id);
5387 g_object_ref (widget);
5389 /* install the accelerator. since we don't map this onto an accel_path,
5390 * the accelerator will automatically be locked.
5392 gtk_accel_group_connect (accel_group,
5395 accel_flags | GTK_ACCEL_LOCKED,
5398 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5400 g_object_unref (widget);
5404 * gtk_widget_remove_accelerator:
5405 * @widget: widget to install an accelerator on
5406 * @accel_group: accel group for this widget
5407 * @accel_key: GDK keyval of the accelerator
5408 * @accel_mods: modifier key combination of the accelerator
5410 * Removes an accelerator from @widget, previously installed with
5411 * gtk_widget_add_accelerator().
5413 * Returns: whether an accelerator was installed and could be removed
5416 gtk_widget_remove_accelerator (GtkWidget *widget,
5417 GtkAccelGroup *accel_group,
5419 GdkModifierType accel_mods)
5421 GtkAccelGroupEntry *ag_entry;
5422 GList *slist, *clist;
5425 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5426 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5428 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5429 clist = gtk_widget_list_accel_closures (widget);
5430 for (slist = clist; slist; slist = slist->next)
5434 for (i = 0; i < n; i++)
5435 if (slist->data == (gpointer) ag_entry[i].closure)
5437 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5439 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5441 g_list_free (clist);
5446 g_list_free (clist);
5448 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5449 accel_key, accel_mods, accel_group,
5450 G_OBJECT_TYPE_NAME (widget), widget);
5456 * gtk_widget_list_accel_closures:
5457 * @widget: widget to list accelerator closures for
5459 * Lists the closures used by @widget for accelerator group connections
5460 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5461 * The closures can be used to monitor accelerator changes on @widget,
5462 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5463 * #GtkAccelGroup of a closure which can be found out with
5464 * gtk_accel_group_from_accel_closure().
5466 * Return value: (transfer container) (element-type GClosure):
5467 * a newly allocated #GList of closures
5470 gtk_widget_list_accel_closures (GtkWidget *widget)
5473 GList *clist = NULL;
5475 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5477 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5478 if (gtk_accel_group_from_accel_closure (slist->data))
5479 clist = g_list_prepend (clist, slist->data);
5485 GtkAccelGroup *accel_group;
5490 destroy_accel_path (gpointer data)
5492 AccelPath *apath = data;
5494 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5496 /* closures_destroy takes care of unrefing the closure */
5497 g_object_unref (apath->accel_group);
5499 g_slice_free (AccelPath, apath);
5504 * gtk_widget_set_accel_path:
5505 * @widget: a #GtkWidget
5506 * @accel_path: (allow-none): path used to look up the accelerator
5507 * @accel_group: (allow-none): a #GtkAccelGroup.
5509 * Given an accelerator group, @accel_group, and an accelerator path,
5510 * @accel_path, sets up an accelerator in @accel_group so whenever the
5511 * key binding that is defined for @accel_path is pressed, @widget
5512 * will be activated. This removes any accelerators (for any
5513 * accelerator group) installed by previous calls to
5514 * gtk_widget_set_accel_path(). Associating accelerators with
5515 * paths allows them to be modified by the user and the modifications
5516 * to be saved for future use. (See gtk_accel_map_save().)
5518 * This function is a low level function that would most likely
5519 * be used by a menu creation system like #GtkUIManager. If you
5520 * use #GtkUIManager, setting up accelerator paths will be done
5523 * Even when you you aren't using #GtkUIManager, if you only want to
5524 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5525 * provides a somewhat more convenient interface.
5527 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5528 * pass a static string, you can save some memory by interning it first with
5529 * g_intern_static_string().
5532 gtk_widget_set_accel_path (GtkWidget *widget,
5533 const gchar *accel_path,
5534 GtkAccelGroup *accel_group)
5538 g_return_if_fail (GTK_IS_WIDGET (widget));
5539 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5543 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5544 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5546 gtk_accel_map_add_entry (accel_path, 0, 0);
5547 apath = g_slice_new (AccelPath);
5548 apath->accel_group = g_object_ref (accel_group);
5549 apath->path_quark = g_quark_from_string (accel_path);
5550 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5555 /* also removes possible old settings */
5556 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5559 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5561 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5565 _gtk_widget_get_accel_path (GtkWidget *widget,
5570 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5572 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5574 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5575 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5579 * gtk_widget_mnemonic_activate:
5580 * @widget: a #GtkWidget
5581 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5583 * Emits the #GtkWidget::mnemonic-activate signal.
5585 * The default handler for this signal activates the @widget if
5586 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5589 * Returns: %TRUE if the signal has been handled
5592 gtk_widget_mnemonic_activate (GtkWidget *widget,
5593 gboolean group_cycling)
5597 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5599 group_cycling = group_cycling != FALSE;
5600 if (!gtk_widget_is_sensitive (widget))
5603 g_signal_emit (widget,
5604 widget_signals[MNEMONIC_ACTIVATE],
5612 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5613 gboolean group_cycling)
5615 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5616 gtk_widget_activate (widget);
5617 else if (gtk_widget_get_can_focus (widget))
5618 gtk_widget_grab_focus (widget);
5621 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5622 G_OBJECT_TYPE_NAME (widget));
5623 gtk_widget_error_bell (widget);
5628 static const cairo_user_data_key_t event_key;
5631 _gtk_cairo_get_event (cairo_t *cr)
5633 g_return_val_if_fail (cr != NULL, NULL);
5635 return cairo_get_user_data (cr, &event_key);
5639 gtk_cairo_set_event (cairo_t *cr,
5640 GdkEventExpose *event)
5642 cairo_set_user_data (cr, &event_key, event, NULL);
5646 * gtk_cairo_should_draw_window:
5647 * @cr: a cairo context
5648 * @window: the window to check. @window may not be an input-only
5651 * This function is supposed to be called in #GtkWidget::draw
5652 * implementations for widgets that support multiple windows.
5653 * @cr must be untransformed from invoking of the draw function.
5654 * This function will return %TRUE if the contents of the given
5655 * @window are supposed to be drawn and %FALSE otherwise. Note
5656 * that when the drawing was not initiated by the windowing
5657 * system this function will return %TRUE for all windows, so
5658 * you need to draw the bottommost window first. Also, do not
5659 * use "else if" statements to check which window should be drawn.
5661 * Returns: %TRUE if @window should be drawn
5666 gtk_cairo_should_draw_window (cairo_t *cr,
5669 GdkEventExpose *event;
5671 g_return_val_if_fail (cr != NULL, FALSE);
5672 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5674 event = _gtk_cairo_get_event (cr);
5676 return event == NULL ||
5677 event->window == window;
5681 gtk_widget_get_clip_draw (GtkWidget *widget)
5683 /* labels are not clipped, because clipping them would cause
5684 * mnemonics to not appear on characters that go beyond the
5686 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
5688 if (GTK_IS_LABEL (widget))
5694 /* code shared by gtk_container_propagate_draw() and
5698 _gtk_widget_draw_internal (GtkWidget *widget,
5700 gboolean clip_to_size)
5702 GtkStyleContext *context;
5704 if (!gtk_widget_is_drawable (widget))
5707 clip_to_size &= gtk_widget_get_clip_draw (widget);
5711 cairo_rectangle (cr,
5713 widget->priv->allocation.width,
5714 widget->priv->allocation.height);
5718 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5722 g_signal_emit (widget, widget_signals[DRAW],
5727 context = gtk_widget_get_style_context (widget);
5728 _gtk_style_context_coalesce_animation_areas (context, widget);
5733 * @widget: the widget to draw. It must be drawable (see
5734 * gtk_widget_is_drawable()) and a size must have been allocated.
5735 * @cr: a cairo context to draw to
5737 * Draws @widget to @cr. The top left corner of the widget will be
5738 * drawn to the currently set origin point of @cr.
5740 * You should pass a cairo context as @cr argument that is in an
5741 * original state. Otherwise the resulting drawing is undefined. For
5742 * example changing the operator using cairo_set_operator() or the
5743 * line width using cairo_set_line_width() might have unwanted side
5745 * You may however change the context's transform matrix - like with
5746 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5747 * region with cairo_clip() prior to calling this function. Also, it
5748 * is fine to modify the context with cairo_save() and
5749 * cairo_push_group() prior to calling this function.
5751 * <note><para>Special purpose widgets may contain special code for
5752 * rendering to the screen and might appear differently on screen
5753 * and when rendered using gtk_widget_draw().</para></note>
5758 gtk_widget_draw (GtkWidget *widget,
5761 GdkEventExpose *tmp_event;
5763 g_return_if_fail (GTK_IS_WIDGET (widget));
5764 g_return_if_fail (!widget->priv->alloc_needed);
5765 g_return_if_fail (cr != NULL);
5768 /* We have to reset the event here so that draw functions can call
5769 * gtk_widget_draw() on random other widgets and get the desired
5770 * effect: Drawing all contents, not just the current window.
5772 tmp_event = _gtk_cairo_get_event (cr);
5773 gtk_cairo_set_event (cr, NULL);
5775 _gtk_widget_draw_internal (widget, cr, TRUE);
5777 gtk_cairo_set_event (cr, tmp_event);
5782 gtk_widget_real_key_press_event (GtkWidget *widget,
5785 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5789 gtk_widget_real_key_release_event (GtkWidget *widget,
5792 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5796 gtk_widget_real_focus_in_event (GtkWidget *widget,
5797 GdkEventFocus *event)
5799 gtk_widget_queue_shallow_draw (widget);
5805 gtk_widget_real_focus_out_event (GtkWidget *widget,
5806 GdkEventFocus *event)
5808 gtk_widget_queue_shallow_draw (widget);
5813 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5814 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5818 * @widget: a #GtkWidget
5819 * @event: a #GdkEvent
5821 * Rarely-used function. This function is used to emit
5822 * the event signals on a widget (those signals should never
5823 * be emitted without using this function to do so).
5824 * If you want to synthesize an event though, don't use this function;
5825 * instead, use gtk_main_do_event() so the event will behave as if
5826 * it were in the event queue. Don't synthesize expose events; instead,
5827 * use gdk_window_invalidate_rect() to invalidate a region of the
5830 * Return value: return from the event signal emission (%TRUE if
5831 * the event was handled)
5834 gtk_widget_event (GtkWidget *widget,
5837 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5838 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5840 if (event->type == GDK_EXPOSE)
5842 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5843 "the same effect, call gdk_window_invalidate_rect/region(), "
5844 "followed by gdk_window_process_updates().");
5848 return gtk_widget_event_internal (widget, event);
5851 /* Returns TRUE if a translation should be done */
5853 _gtk_widget_get_translation_to_window (GtkWidget *widget,
5858 GdkWindow *w, *widget_window;
5860 if (!gtk_widget_get_has_window (widget))
5862 *x = -widget->priv->allocation.x;
5863 *y = -widget->priv->allocation.y;
5871 widget_window = gtk_widget_get_window (widget);
5873 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5876 gdk_window_get_position (w, &wx, &wy);
5893 * gtk_cairo_transform_to_window:
5894 * @cr: the cairo context to transform
5895 * @widget: the widget the context is currently centered for
5896 * @window: the window to transform the context to
5898 * Transforms the given cairo context @cr that from @widget-relative
5899 * coordinates to @window-relative coordinates.
5900 * If the @widget's window is not an ancestor of @window, no
5901 * modification will be applied.
5903 * This is the inverse to the transformation GTK applies when
5904 * preparing an expose event to be emitted with the #GtkWidget::draw
5905 * signal. It is intended to help porting multiwindow widgets from
5906 * GTK+ 2 to the rendering architecture of GTK+ 3.
5911 gtk_cairo_transform_to_window (cairo_t *cr,
5917 g_return_if_fail (cr != NULL);
5918 g_return_if_fail (GTK_IS_WIDGET (widget));
5919 g_return_if_fail (GDK_IS_WINDOW (window));
5921 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
5922 cairo_translate (cr, x, y);
5926 * gtk_widget_send_expose:
5927 * @widget: a #GtkWidget
5928 * @event: a expose #GdkEvent
5930 * Very rarely-used function. This function is used to emit
5931 * an expose event on a widget. This function is not normally used
5932 * directly. The only time it is used is when propagating an expose
5933 * event to a child %NO_WINDOW widget, and that is normally done
5934 * using gtk_container_propagate_draw().
5936 * If you want to force an area of a window to be redrawn,
5937 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5938 * To cause the redraw to be done immediately, follow that call
5939 * with a call to gdk_window_process_updates().
5941 * Return value: return from the event signal emission (%TRUE if
5942 * the event was handled)
5945 gtk_widget_send_expose (GtkWidget *widget,
5948 gboolean result = FALSE;
5953 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5954 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5955 g_return_val_if_fail (event != NULL, TRUE);
5956 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5958 cr = gdk_cairo_create (event->expose.window);
5959 gtk_cairo_set_event (cr, &event->expose);
5961 gdk_cairo_region (cr, event->expose.region);
5964 do_clip = _gtk_widget_get_translation_to_window (widget,
5965 event->expose.window,
5967 cairo_translate (cr, -x, -y);
5969 _gtk_widget_draw_internal (widget, cr, do_clip);
5971 /* unset here, so if someone keeps a reference to cr we
5972 * don't leak the window. */
5973 gtk_cairo_set_event (cr, NULL);
5980 event_window_is_still_viewable (GdkEvent *event)
5982 /* Check that we think the event's window is viewable before
5983 * delivering the event, to prevent suprises. We do this here
5984 * at the last moment, since the event may have been queued
5985 * up behind other events, held over a recursive main loop, etc.
5987 switch (event->type)
5990 case GDK_MOTION_NOTIFY:
5991 case GDK_BUTTON_PRESS:
5992 case GDK_2BUTTON_PRESS:
5993 case GDK_3BUTTON_PRESS:
5995 case GDK_ENTER_NOTIFY:
5996 case GDK_PROXIMITY_IN:
5998 return event->any.window && gdk_window_is_viewable (event->any.window);
6001 /* The following events are the second half of paired events;
6002 * we always deliver them to deal with widgets that clean up
6003 * on the second half.
6005 case GDK_BUTTON_RELEASE:
6006 case GDK_KEY_RELEASE:
6007 case GDK_LEAVE_NOTIFY:
6008 case GDK_PROXIMITY_OUT:
6012 /* Remaining events would make sense on an not-viewable window,
6013 * or don't have an associated window.
6020 gtk_widget_event_internal (GtkWidget *widget,
6023 gboolean return_val = FALSE;
6025 /* We check only once for is-still-visible; if someone
6026 * hides the window in on of the signals on the widget,
6027 * they are responsible for returning TRUE to terminate
6030 if (!event_window_is_still_viewable (event))
6033 g_object_ref (widget);
6035 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6036 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6041 switch (event->type)
6047 case GDK_BUTTON_PRESS:
6048 case GDK_2BUTTON_PRESS:
6049 case GDK_3BUTTON_PRESS:
6050 signal_num = BUTTON_PRESS_EVENT;
6053 signal_num = SCROLL_EVENT;
6055 case GDK_BUTTON_RELEASE:
6056 signal_num = BUTTON_RELEASE_EVENT;
6058 case GDK_MOTION_NOTIFY:
6059 signal_num = MOTION_NOTIFY_EVENT;
6062 signal_num = DELETE_EVENT;
6065 signal_num = DESTROY_EVENT;
6066 _gtk_tooltip_hide (widget);
6069 signal_num = KEY_PRESS_EVENT;
6071 case GDK_KEY_RELEASE:
6072 signal_num = KEY_RELEASE_EVENT;
6074 case GDK_ENTER_NOTIFY:
6075 signal_num = ENTER_NOTIFY_EVENT;
6077 case GDK_LEAVE_NOTIFY:
6078 signal_num = LEAVE_NOTIFY_EVENT;
6080 case GDK_FOCUS_CHANGE:
6081 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6082 if (event->focus_change.in)
6083 _gtk_tooltip_focus_in (widget);
6085 _gtk_tooltip_focus_out (widget);
6088 signal_num = CONFIGURE_EVENT;
6091 signal_num = MAP_EVENT;
6094 signal_num = UNMAP_EVENT;
6096 case GDK_WINDOW_STATE:
6097 signal_num = WINDOW_STATE_EVENT;
6099 case GDK_PROPERTY_NOTIFY:
6100 signal_num = PROPERTY_NOTIFY_EVENT;
6102 case GDK_SELECTION_CLEAR:
6103 signal_num = SELECTION_CLEAR_EVENT;
6105 case GDK_SELECTION_REQUEST:
6106 signal_num = SELECTION_REQUEST_EVENT;
6108 case GDK_SELECTION_NOTIFY:
6109 signal_num = SELECTION_NOTIFY_EVENT;
6111 case GDK_PROXIMITY_IN:
6112 signal_num = PROXIMITY_IN_EVENT;
6114 case GDK_PROXIMITY_OUT:
6115 signal_num = PROXIMITY_OUT_EVENT;
6117 case GDK_VISIBILITY_NOTIFY:
6118 signal_num = VISIBILITY_NOTIFY_EVENT;
6120 case GDK_GRAB_BROKEN:
6121 signal_num = GRAB_BROKEN_EVENT;
6124 signal_num = DAMAGE_EVENT;
6127 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6131 if (signal_num != -1)
6132 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6134 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6135 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6139 g_object_unref (widget);
6145 * gtk_widget_activate:
6146 * @widget: a #GtkWidget that's activatable
6148 * For widgets that can be "activated" (buttons, menu items, etc.)
6149 * this function activates them. Activation is what happens when you
6150 * press Enter on a widget during key navigation. If @widget isn't
6151 * activatable, the function returns %FALSE.
6153 * Return value: %TRUE if the widget was activatable
6156 gtk_widget_activate (GtkWidget *widget)
6158 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6160 if (WIDGET_CLASS (widget)->activate_signal)
6162 /* FIXME: we should eventually check the signals signature here */
6163 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6172 gtk_widget_reparent_subwindows (GtkWidget *widget,
6173 GdkWindow *new_window)
6175 GtkWidgetPrivate *priv = widget->priv;
6177 if (!gtk_widget_get_has_window (widget))
6179 GList *children = gdk_window_get_children (priv->window);
6182 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6184 GdkWindow *window = tmp_list->data;
6187 gdk_window_get_user_data (window, &child);
6188 while (child && child != widget)
6189 child = ((GtkWidget*) child)->priv->parent;
6192 gdk_window_reparent (window, new_window, 0, 0);
6195 g_list_free (children);
6200 GList *tmp_list, *children;
6202 parent = gdk_window_get_parent (priv->window);
6205 gdk_window_reparent (priv->window, new_window, 0, 0);
6208 children = gdk_window_get_children (parent);
6210 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6212 GdkWindow *window = tmp_list->data;
6215 gdk_window_get_user_data (window, &child);
6217 if (child == widget)
6218 gdk_window_reparent (window, new_window, 0, 0);
6221 g_list_free (children);
6227 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6228 gpointer client_data)
6230 GtkWidgetPrivate *priv = widget->priv;
6232 g_assert (client_data != NULL);
6234 if (!gtk_widget_get_has_window (widget))
6237 g_object_unref (priv->window);
6238 priv->window = (GdkWindow*) client_data;
6240 g_object_ref (priv->window);
6242 if (GTK_IS_CONTAINER (widget))
6243 gtk_container_forall (GTK_CONTAINER (widget),
6244 gtk_widget_reparent_fixup_child,
6250 * gtk_widget_reparent:
6251 * @widget: a #GtkWidget
6252 * @new_parent: a #GtkContainer to move the widget into
6254 * Moves a widget from one #GtkContainer to another, handling reference
6255 * count issues to avoid destroying the widget.
6258 gtk_widget_reparent (GtkWidget *widget,
6259 GtkWidget *new_parent)
6261 GtkWidgetPrivate *priv;
6263 g_return_if_fail (GTK_IS_WIDGET (widget));
6264 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6265 priv = widget->priv;
6266 g_return_if_fail (priv->parent != NULL);
6268 if (priv->parent != new_parent)
6270 /* First try to see if we can get away without unrealizing
6271 * the widget as we reparent it. if so we set a flag so
6272 * that gtk_widget_unparent doesn't unrealize widget
6274 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6275 priv->in_reparent = TRUE;
6277 g_object_ref (widget);
6278 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6279 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6280 g_object_unref (widget);
6282 if (priv->in_reparent)
6284 priv->in_reparent = FALSE;
6286 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6287 gtk_widget_reparent_fixup_child (widget,
6288 gtk_widget_get_parent_window (widget));
6291 g_object_notify (G_OBJECT (widget), "parent");
6296 * gtk_widget_intersect:
6297 * @widget: a #GtkWidget
6298 * @area: a rectangle
6299 * @intersection: rectangle to store intersection of @widget and @area
6301 * Computes the intersection of a @widget's area and @area, storing
6302 * the intersection in @intersection, and returns %TRUE if there was
6303 * an intersection. @intersection may be %NULL if you're only
6304 * interested in whether there was an intersection.
6306 * Return value: %TRUE if there was an intersection
6309 gtk_widget_intersect (GtkWidget *widget,
6310 const GdkRectangle *area,
6311 GdkRectangle *intersection)
6313 GtkWidgetPrivate *priv;
6318 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6319 g_return_val_if_fail (area != NULL, FALSE);
6321 priv = widget->priv;
6324 dest = intersection;
6328 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6330 if (return_val && intersection && gtk_widget_get_has_window (widget))
6332 intersection->x -= priv->allocation.x;
6333 intersection->y -= priv->allocation.y;
6340 * gtk_widget_region_intersect:
6341 * @widget: a #GtkWidget
6342 * @region: a #cairo_region_t, in the same coordinate system as
6343 * @widget->allocation. That is, relative to @widget->window
6344 * for %NO_WINDOW widgets; relative to the parent window
6345 * of @widget->window for widgets with their own window.
6347 * Computes the intersection of a @widget's area and @region, returning
6348 * the intersection. The result may be empty, use cairo_region_is_empty() to
6351 * Returns: A newly allocated region holding the intersection of @widget
6352 * and @region. The coordinates of the return value are relative to
6353 * @widget->window for %NO_WINDOW widgets, and relative to the parent
6354 * window of @widget->window for widgets with their own window.
6357 gtk_widget_region_intersect (GtkWidget *widget,
6358 const cairo_region_t *region)
6361 cairo_region_t *dest;
6363 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6364 g_return_val_if_fail (region != NULL, NULL);
6366 gtk_widget_get_allocation (widget, &rect);
6368 dest = cairo_region_create_rectangle (&rect);
6370 cairo_region_intersect (dest, region);
6376 * _gtk_widget_grab_notify:
6377 * @widget: a #GtkWidget
6378 * @was_grabbed: whether a grab is now in effect
6380 * Emits the #GtkWidget::grab-notify signal on @widget.
6385 _gtk_widget_grab_notify (GtkWidget *widget,
6386 gboolean was_grabbed)
6388 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6392 * gtk_widget_grab_focus:
6393 * @widget: a #GtkWidget
6395 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6396 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6397 * something like #GtkFrame won't work.
6399 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6400 * gtk_widget_set_can_focus() to modify that flag.
6402 * The widget also needs to be realized and mapped. This is indicated by the
6403 * related signals. Grabbing the focus immediately after creating the widget
6404 * will likely fail and cause critical warnings.
6407 gtk_widget_grab_focus (GtkWidget *widget)
6409 g_return_if_fail (GTK_IS_WIDGET (widget));
6411 if (!gtk_widget_is_sensitive (widget))
6414 g_object_ref (widget);
6415 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6416 g_object_notify (G_OBJECT (widget), "has-focus");
6417 g_object_unref (widget);
6421 reset_focus_recurse (GtkWidget *widget,
6424 if (GTK_IS_CONTAINER (widget))
6426 GtkContainer *container;
6428 container = GTK_CONTAINER (widget);
6429 gtk_container_set_focus_child (container, NULL);
6431 gtk_container_foreach (container,
6432 reset_focus_recurse,
6438 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6440 if (gtk_widget_get_can_focus (focus_widget))
6442 GtkWidget *toplevel;
6445 /* clear the current focus setting, break if the current widget
6446 * is the focus widget's parent, since containers above that will
6447 * be set by the next loop.
6449 toplevel = gtk_widget_get_toplevel (focus_widget);
6450 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6452 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6454 if (widget == focus_widget)
6456 /* We call _gtk_window_internal_set_focus() here so that the
6457 * toplevel window can request the focus if necessary.
6458 * This is needed when the toplevel is a GtkPlug
6460 if (!gtk_widget_has_focus (widget))
6461 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6468 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
6470 widget = widget->priv->parent;
6471 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6475 else if (toplevel != focus_widget)
6477 /* gtk_widget_grab_focus() operates on a tree without window...
6478 * actually, this is very questionable behaviour.
6481 gtk_container_foreach (GTK_CONTAINER (toplevel),
6482 reset_focus_recurse,
6486 /* now propagate the new focus up the widget tree and finally
6487 * set it on the window
6489 widget = focus_widget;
6490 while (widget->priv->parent)
6492 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6493 widget = widget->priv->parent;
6495 if (GTK_IS_WINDOW (widget))
6496 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6501 gtk_widget_real_query_tooltip (GtkWidget *widget,
6504 gboolean keyboard_tip,
6505 GtkTooltip *tooltip)
6507 gchar *tooltip_markup;
6508 gboolean has_tooltip;
6510 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6511 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6513 if (has_tooltip && tooltip_markup)
6515 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6523 gtk_widget_real_state_flags_changed (GtkWidget *widget,
6524 GtkStateFlags old_state)
6526 gtk_widget_update_pango_context (widget);
6530 gtk_widget_real_style_updated (GtkWidget *widget)
6532 GtkWidgetPrivate *priv = widget->priv;
6534 gtk_widget_update_pango_context (widget);
6536 if (priv->style != NULL &&
6537 priv->style != gtk_widget_get_default_style ())
6539 /* Trigger ::style-set for old
6540 * widgets not listening to this
6542 g_signal_emit (widget,
6543 widget_signals[STYLE_SET],
6545 widget->priv->style);
6548 if (widget->priv->context)
6550 if (gtk_widget_get_realized (widget) &&
6551 gtk_widget_get_has_window (widget))
6552 gtk_style_context_set_background (widget->priv->context,
6553 widget->priv->window);
6556 if (widget->priv->anchored)
6557 gtk_widget_queue_resize (widget);
6561 gtk_widget_real_show_help (GtkWidget *widget,
6562 GtkWidgetHelpType help_type)
6564 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6566 _gtk_tooltip_toggle_keyboard_mode (widget);
6575 gtk_widget_real_focus (GtkWidget *widget,
6576 GtkDirectionType direction)
6578 if (!gtk_widget_get_can_focus (widget))
6581 if (!gtk_widget_is_focus (widget))
6583 gtk_widget_grab_focus (widget);
6591 gtk_widget_real_move_focus (GtkWidget *widget,
6592 GtkDirectionType direction)
6594 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6596 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6598 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6604 gtk_widget_real_keynav_failed (GtkWidget *widget,
6605 GtkDirectionType direction)
6607 gboolean cursor_only;
6611 case GTK_DIR_TAB_FORWARD:
6612 case GTK_DIR_TAB_BACKWARD:
6619 g_object_get (gtk_widget_get_settings (widget),
6620 "gtk-keynav-cursor-only", &cursor_only,
6627 gtk_widget_error_bell (widget);
6633 * gtk_widget_set_can_focus:
6634 * @widget: a #GtkWidget
6635 * @can_focus: whether or not @widget can own the input focus.
6637 * Specifies whether @widget can own the input focus. See
6638 * gtk_widget_grab_focus() for actually setting the input focus on a
6644 gtk_widget_set_can_focus (GtkWidget *widget,
6647 g_return_if_fail (GTK_IS_WIDGET (widget));
6649 if (widget->priv->can_focus != can_focus)
6651 widget->priv->can_focus = can_focus;
6653 gtk_widget_queue_resize (widget);
6654 g_object_notify (G_OBJECT (widget), "can-focus");
6659 * gtk_widget_get_can_focus:
6660 * @widget: a #GtkWidget
6662 * Determines whether @widget can own the input focus. See
6663 * gtk_widget_set_can_focus().
6665 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6670 gtk_widget_get_can_focus (GtkWidget *widget)
6672 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6674 return widget->priv->can_focus;
6678 * gtk_widget_has_focus:
6679 * @widget: a #GtkWidget
6681 * Determines if the widget has the global input focus. See
6682 * gtk_widget_is_focus() for the difference between having the global
6683 * input focus, and only having the focus within a toplevel.
6685 * Return value: %TRUE if the widget has the global input focus.
6690 gtk_widget_has_focus (GtkWidget *widget)
6692 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6694 return widget->priv->has_focus;
6698 * gtk_widget_has_visible_focus:
6699 * @widget: a #GtkWidget
6701 * Determines if the widget should show a visible indication that
6702 * it has the global input focus. This is a convenience function for
6703 * use in ::draw handlers that takes into account whether focus
6704 * indication should currently be shown in the toplevel window of
6705 * @widget. See gtk_window_get_focus_visible() for more information
6706 * about focus indication.
6708 * To find out if the widget has the global input focus, use
6709 * gtk_widget_has_focus().
6711 * Return value: %TRUE if the widget should display a 'focus rectangle'
6716 gtk_widget_has_visible_focus (GtkWidget *widget)
6718 gboolean draw_focus;
6720 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6722 if (widget->priv->has_focus)
6724 GtkWidget *toplevel;
6726 toplevel = gtk_widget_get_toplevel (widget);
6728 if (GTK_IS_WINDOW (toplevel))
6729 draw_focus = gtk_window_get_focus_visible (GTK_WINDOW (toplevel));
6740 * gtk_widget_is_focus:
6741 * @widget: a #GtkWidget
6743 * Determines if the widget is the focus widget within its
6744 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6745 * necessarily set; %HAS_FOCUS will only be set if the
6746 * toplevel widget additionally has the global input focus.)
6748 * Return value: %TRUE if the widget is the focus widget.
6751 gtk_widget_is_focus (GtkWidget *widget)
6753 GtkWidget *toplevel;
6755 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6757 toplevel = gtk_widget_get_toplevel (widget);
6759 if (GTK_IS_WINDOW (toplevel))
6760 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6766 * gtk_widget_set_can_default:
6767 * @widget: a #GtkWidget
6768 * @can_default: whether or not @widget can be a default widget.
6770 * Specifies whether @widget can be a default widget. See
6771 * gtk_widget_grab_default() for details about the meaning of
6777 gtk_widget_set_can_default (GtkWidget *widget,
6778 gboolean can_default)
6780 g_return_if_fail (GTK_IS_WIDGET (widget));
6782 if (widget->priv->can_default != can_default)
6784 widget->priv->can_default = can_default;
6786 gtk_widget_queue_resize (widget);
6787 g_object_notify (G_OBJECT (widget), "can-default");
6792 * gtk_widget_get_can_default:
6793 * @widget: a #GtkWidget
6795 * Determines whether @widget can be a default widget. See
6796 * gtk_widget_set_can_default().
6798 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6803 gtk_widget_get_can_default (GtkWidget *widget)
6805 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6807 return widget->priv->can_default;
6811 * gtk_widget_has_default:
6812 * @widget: a #GtkWidget
6814 * Determines whether @widget is the current default widget within its
6815 * toplevel. See gtk_widget_set_can_default().
6817 * Return value: %TRUE if @widget is the current default widget within
6818 * its toplevel, %FALSE otherwise
6823 gtk_widget_has_default (GtkWidget *widget)
6825 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6827 return widget->priv->has_default;
6831 _gtk_widget_set_has_default (GtkWidget *widget,
6832 gboolean has_default)
6834 widget->priv->has_default = has_default;
6838 * gtk_widget_grab_default:
6839 * @widget: a #GtkWidget
6841 * Causes @widget to become the default widget. @widget must have the
6842 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6843 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6844 * %TRUE)</literal>. The default widget is activated when
6845 * the user presses Enter in a window. Default widgets must be
6846 * activatable, that is, gtk_widget_activate() should affect them. Note
6847 * that #GtkEntry widgets require the "activates-default" property
6848 * set to %TRUE before they activate the default widget when Enter
6849 * is pressed and the #GtkEntry is focused.
6852 gtk_widget_grab_default (GtkWidget *widget)
6856 g_return_if_fail (GTK_IS_WIDGET (widget));
6857 g_return_if_fail (gtk_widget_get_can_default (widget));
6859 window = gtk_widget_get_toplevel (widget);
6861 if (window && gtk_widget_is_toplevel (window))
6862 gtk_window_set_default (GTK_WINDOW (window), widget);
6864 g_warning (G_STRLOC ": widget not within a GtkWindow");
6868 * gtk_widget_set_receives_default:
6869 * @widget: a #GtkWidget
6870 * @receives_default: whether or not @widget can be a default widget.
6872 * Specifies whether @widget will be treated as the default widget
6873 * within its toplevel when it has the focus, even if another widget
6876 * See gtk_widget_grab_default() for details about the meaning of
6882 gtk_widget_set_receives_default (GtkWidget *widget,
6883 gboolean receives_default)
6885 g_return_if_fail (GTK_IS_WIDGET (widget));
6887 if (widget->priv->receives_default != receives_default)
6889 widget->priv->receives_default = receives_default;
6891 g_object_notify (G_OBJECT (widget), "receives-default");
6896 * gtk_widget_get_receives_default:
6897 * @widget: a #GtkWidget
6899 * Determines whether @widget is alyways treated as default widget
6900 * withing its toplevel when it has the focus, even if another widget
6903 * See gtk_widget_set_receives_default().
6905 * Return value: %TRUE if @widget acts as default widget when focussed,
6911 gtk_widget_get_receives_default (GtkWidget *widget)
6913 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6915 return widget->priv->receives_default;
6919 * gtk_widget_has_grab:
6920 * @widget: a #GtkWidget
6922 * Determines whether the widget is currently grabbing events, so it
6923 * is the only widget receiving input events (keyboard and mouse).
6925 * See also gtk_grab_add().
6927 * Return value: %TRUE if the widget is in the grab_widgets stack
6932 gtk_widget_has_grab (GtkWidget *widget)
6934 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6936 return widget->priv->has_grab;
6940 _gtk_widget_set_has_grab (GtkWidget *widget,
6943 widget->priv->has_grab = has_grab;
6947 * gtk_widget_device_is_shadowed:
6948 * @widget: a #GtkWidget
6949 * @device: a #GdkDevice
6951 * Returns %TRUE if @device has been shadowed by a GTK+
6952 * device grab on another widget, so it would stop sending
6953 * events to @widget. This may be used in the
6954 * #GtkWidget::grab-notify signal to check for specific
6955 * devices. See gtk_device_grab_add().
6957 * Returns: %TRUE if there is an ongoing grab on @device
6958 * by another #GtkWidget than @widget.
6963 gtk_widget_device_is_shadowed (GtkWidget *widget,
6966 GtkWindowGroup *group;
6967 GtkWidget *grab_widget, *toplevel;
6969 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6970 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6972 if (!gtk_widget_get_realized (widget))
6975 toplevel = gtk_widget_get_toplevel (widget);
6977 if (GTK_IS_WINDOW (toplevel))
6978 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6980 group = gtk_window_get_group (NULL);
6982 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6984 /* Widget not inside the hierarchy of grab_widget */
6986 widget != grab_widget &&
6987 !gtk_widget_is_ancestor (widget, grab_widget))
6990 grab_widget = gtk_window_group_get_current_grab (group);
6991 if (grab_widget && widget != grab_widget &&
6992 !gtk_widget_is_ancestor (widget, grab_widget))
6999 * gtk_widget_set_name:
7000 * @widget: a #GtkWidget
7001 * @name: name for the widget
7003 * Widgets can be named, which allows you to refer to them from a
7004 * CSS file. You can apply a style to widgets with a particular name
7005 * in the CSS file. See the documentation for the CSS syntax (on the
7006 * same page as the docs for #GtkStyleContext).
7008 * Note that the CSS syntax has certain special characters to delimit
7009 * and represent elements in a selector (period, #, >, *...),
7010 * so using these will make your widget impossible to match by name.
7011 * Any combination of alphanumeric symbols, dashes and underscores will
7015 gtk_widget_set_name (GtkWidget *widget,
7018 GtkWidgetPrivate *priv;
7021 g_return_if_fail (GTK_IS_WIDGET (widget));
7023 priv = widget->priv;
7025 new_name = g_strdup (name);
7026 g_free (priv->name);
7027 priv->name = new_name;
7029 gtk_widget_reset_style (widget);
7031 g_object_notify (G_OBJECT (widget), "name");
7035 * gtk_widget_get_name:
7036 * @widget: a #GtkWidget
7038 * Retrieves the name of a widget. See gtk_widget_set_name() for the
7039 * significance of widget names.
7041 * Return value: name of the widget. This string is owned by GTK+ and
7042 * should not be modified or freed
7045 gtk_widget_get_name (GtkWidget *widget)
7047 GtkWidgetPrivate *priv;
7049 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7051 priv = widget->priv;
7055 return G_OBJECT_TYPE_NAME (widget);
7059 _gtk_widget_update_state_flags (GtkWidget *widget,
7060 GtkStateFlags flags,
7063 GtkWidgetPrivate *priv;
7065 priv = widget->priv;
7067 /* Handle insensitive first, since it is propagated
7068 * differently throughout the widget hierarchy.
7070 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_UNSET))
7071 gtk_widget_set_sensitive (widget, TRUE);
7072 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation != STATE_CHANGE_UNSET))
7073 gtk_widget_set_sensitive (widget, FALSE);
7074 else if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && !(flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_REPLACE))
7075 gtk_widget_set_sensitive (widget, TRUE);
7077 if (operation != STATE_CHANGE_REPLACE)
7078 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
7081 operation == STATE_CHANGE_REPLACE)
7086 data.operation = operation;
7087 data.use_forall = FALSE;
7089 gtk_widget_propagate_state (widget, &data);
7091 gtk_widget_queue_resize (widget);
7096 * gtk_widget_set_state_flags:
7097 * @widget: a #GtkWidget
7098 * @flags: State flags to turn on
7099 * @clear: Whether to clear state before turning on @flags
7101 * This function is for use in widget implementations. Turns on flag
7102 * values in the current widget state (insensitive, prelighted, etc.).
7104 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7105 * will be propagated down to all non-internal children if @widget is a
7106 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7107 * down to all #GtkContainer children by different means than turning on the
7108 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7109 * gtk_widget_is_sensitive() will make use of these.
7114 gtk_widget_set_state_flags (GtkWidget *widget,
7115 GtkStateFlags flags,
7118 g_return_if_fail (GTK_IS_WIDGET (widget));
7120 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7121 (clear && widget->priv->state_flags == flags))
7125 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7127 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
7131 * gtk_widget_unset_state_flags:
7132 * @widget: a #GtkWidget
7133 * @flags: State flags to turn off
7135 * This function is for use in widget implementations. Turns off flag
7136 * values for the current widget state (insensitive, prelighted, etc.).
7137 * See gtk_widget_set_state_flags().
7142 gtk_widget_unset_state_flags (GtkWidget *widget,
7143 GtkStateFlags flags)
7145 g_return_if_fail (GTK_IS_WIDGET (widget));
7147 if ((widget->priv->state_flags & flags) == 0)
7150 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
7154 * gtk_widget_get_state_flags:
7155 * @widget: a #GtkWidget
7157 * Returns the widget state as a flag set. It is worth mentioning
7158 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7159 * returned, that is, also based on parent insensitivity, even if
7160 * @widget itself is sensitive.
7162 * Returns: The state flags for widget
7167 gtk_widget_get_state_flags (GtkWidget *widget)
7169 GtkStateFlags flags;
7171 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7173 flags = widget->priv->state_flags;
7175 if (gtk_widget_has_focus (widget))
7176 flags |= GTK_STATE_FLAG_FOCUSED;
7182 * gtk_widget_set_state:
7183 * @widget: a #GtkWidget
7184 * @state: new state for @widget
7186 * This function is for use in widget implementations. Sets the state
7187 * of a widget (insensitive, prelighted, etc.) Usually you should set
7188 * the state using wrapper functions such as gtk_widget_set_sensitive().
7190 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7193 gtk_widget_set_state (GtkWidget *widget,
7196 GtkStateFlags flags;
7198 if (state == gtk_widget_get_state (widget))
7203 case GTK_STATE_ACTIVE:
7204 flags = GTK_STATE_FLAG_ACTIVE;
7206 case GTK_STATE_PRELIGHT:
7207 flags = GTK_STATE_FLAG_PRELIGHT;
7209 case GTK_STATE_SELECTED:
7210 flags = GTK_STATE_FLAG_SELECTED;
7212 case GTK_STATE_INSENSITIVE:
7213 flags = GTK_STATE_FLAG_INSENSITIVE;
7215 case GTK_STATE_INCONSISTENT:
7216 flags = GTK_STATE_FLAG_INCONSISTENT;
7218 case GTK_STATE_FOCUSED:
7219 flags = GTK_STATE_FLAG_FOCUSED;
7221 case GTK_STATE_NORMAL:
7227 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7231 * gtk_widget_get_state:
7232 * @widget: a #GtkWidget
7234 * Returns the widget's state. See gtk_widget_set_state().
7236 * Returns: the state of @widget.
7240 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7243 gtk_widget_get_state (GtkWidget *widget)
7245 GtkStateFlags flags;
7247 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7249 flags = gtk_widget_get_state_flags (widget);
7251 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7252 return GTK_STATE_INSENSITIVE;
7253 else if (flags & GTK_STATE_FLAG_ACTIVE)
7254 return GTK_STATE_ACTIVE;
7255 else if (flags & GTK_STATE_FLAG_SELECTED)
7256 return GTK_STATE_SELECTED;
7257 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7258 return GTK_STATE_PRELIGHT;
7260 return GTK_STATE_NORMAL;
7264 * gtk_widget_set_visible:
7265 * @widget: a #GtkWidget
7266 * @visible: whether the widget should be shown or not
7268 * Sets the visibility state of @widget. Note that setting this to
7269 * %TRUE doesn't mean the widget is actually viewable, see
7270 * gtk_widget_get_visible().
7272 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7273 * but is nicer to use when the visibility of the widget depends on
7279 gtk_widget_set_visible (GtkWidget *widget,
7282 g_return_if_fail (GTK_IS_WIDGET (widget));
7284 if (visible != gtk_widget_get_visible (widget))
7287 gtk_widget_show (widget);
7289 gtk_widget_hide (widget);
7294 _gtk_widget_set_visible_flag (GtkWidget *widget,
7297 widget->priv->visible = visible;
7301 * gtk_widget_get_visible:
7302 * @widget: a #GtkWidget
7304 * Determines whether the widget is visible. Note that this doesn't
7305 * take into account whether the widget's parent is also visible
7306 * or the widget is obscured in any way.
7308 * See gtk_widget_set_visible().
7310 * Return value: %TRUE if the widget is visible
7315 gtk_widget_get_visible (GtkWidget *widget)
7317 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7319 return widget->priv->visible;
7323 * gtk_widget_set_has_window:
7324 * @widget: a #GtkWidget
7325 * @has_window: whether or not @widget has a window.
7327 * Specifies whether @widget has a #GdkWindow of its own. Note that
7328 * all realized widgets have a non-%NULL "window" pointer
7329 * (gtk_widget_get_window() never returns a %NULL window when a widget
7330 * is realized), but for many of them it's actually the #GdkWindow of
7331 * one of its parent widgets. Widgets that do not create a %window for
7332 * themselves in #GtkWidget::realize must announce this by
7333 * calling this function with @has_window = %FALSE.
7335 * This function should only be called by widget implementations,
7336 * and they should call it in their init() function.
7341 gtk_widget_set_has_window (GtkWidget *widget,
7342 gboolean has_window)
7344 g_return_if_fail (GTK_IS_WIDGET (widget));
7346 widget->priv->no_window = !has_window;
7350 * gtk_widget_get_has_window:
7351 * @widget: a #GtkWidget
7353 * Determines whether @widget has a #GdkWindow of its own. See
7354 * gtk_widget_set_has_window().
7356 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7361 gtk_widget_get_has_window (GtkWidget *widget)
7363 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7365 return ! widget->priv->no_window;
7369 * gtk_widget_is_toplevel:
7370 * @widget: a #GtkWidget
7372 * Determines whether @widget is a toplevel widget.
7374 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7375 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7378 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7383 gtk_widget_is_toplevel (GtkWidget *widget)
7385 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7387 return widget->priv->toplevel;
7391 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7392 gboolean is_toplevel)
7394 widget->priv->toplevel = is_toplevel;
7398 * gtk_widget_is_drawable:
7399 * @widget: a #GtkWidget
7401 * Determines whether @widget can be drawn to. A widget can be drawn
7402 * to if it is mapped and visible.
7404 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7409 gtk_widget_is_drawable (GtkWidget *widget)
7411 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7413 return (gtk_widget_get_visible (widget) &&
7414 gtk_widget_get_mapped (widget));
7418 * gtk_widget_get_realized:
7419 * @widget: a #GtkWidget
7421 * Determines whether @widget is realized.
7423 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7428 gtk_widget_get_realized (GtkWidget *widget)
7430 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7432 return widget->priv->realized;
7436 * gtk_widget_set_realized:
7437 * @widget: a #GtkWidget
7438 * @realized: %TRUE to mark the widget as realized
7440 * Marks the widget as being realized.
7442 * This function should only ever be called in a derived widget's
7443 * "realize" or "unrealize" implementation.
7448 gtk_widget_set_realized (GtkWidget *widget,
7451 g_return_if_fail (GTK_IS_WIDGET (widget));
7453 widget->priv->realized = realized;
7457 * gtk_widget_get_mapped:
7458 * @widget: a #GtkWidget
7460 * Whether the widget is mapped.
7462 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7467 gtk_widget_get_mapped (GtkWidget *widget)
7469 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7471 return widget->priv->mapped;
7475 * gtk_widget_set_mapped:
7476 * @widget: a #GtkWidget
7477 * @mapped: %TRUE to mark the widget as mapped
7479 * Marks the widget as being realized.
7481 * This function should only ever be called in a derived widget's
7482 * "map" or "unmap" implementation.
7487 gtk_widget_set_mapped (GtkWidget *widget,
7490 g_return_if_fail (GTK_IS_WIDGET (widget));
7492 widget->priv->mapped = mapped;
7496 * gtk_widget_set_app_paintable:
7497 * @widget: a #GtkWidget
7498 * @app_paintable: %TRUE if the application will paint on the widget
7500 * Sets whether the application intends to draw on the widget in
7501 * an #GtkWidget::draw handler.
7503 * This is a hint to the widget and does not affect the behavior of
7504 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7505 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7506 * the effect is to suppress default themed drawing of the widget's
7507 * background. (Children of the widget will still be drawn.) The application
7508 * is then entirely responsible for drawing the widget background.
7510 * Note that the background is still drawn when the widget is mapped.
7513 gtk_widget_set_app_paintable (GtkWidget *widget,
7514 gboolean app_paintable)
7516 g_return_if_fail (GTK_IS_WIDGET (widget));
7518 app_paintable = (app_paintable != FALSE);
7520 if (widget->priv->app_paintable != app_paintable)
7522 widget->priv->app_paintable = app_paintable;
7524 if (gtk_widget_is_drawable (widget))
7525 gtk_widget_queue_draw (widget);
7527 g_object_notify (G_OBJECT (widget), "app-paintable");
7532 * gtk_widget_get_app_paintable:
7533 * @widget: a #GtkWidget
7535 * Determines whether the application intends to draw on the widget in
7536 * an #GtkWidget::draw handler.
7538 * See gtk_widget_set_app_paintable()
7540 * Return value: %TRUE if the widget is app paintable
7545 gtk_widget_get_app_paintable (GtkWidget *widget)
7547 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7549 return widget->priv->app_paintable;
7553 * gtk_widget_set_double_buffered:
7554 * @widget: a #GtkWidget
7555 * @double_buffered: %TRUE to double-buffer a widget
7557 * Widgets are double buffered by default; you can use this function
7558 * to turn off the buffering. "Double buffered" simply means that
7559 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7560 * automatically around expose events sent to the
7561 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7562 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7563 * buffer to the screen. The result is that users see the window
7564 * update in one smooth step, and don't see individual graphics
7565 * primitives being rendered.
7567 * In very simple terms, double buffered widgets don't flicker,
7568 * so you would only use this function to turn off double buffering
7569 * if you had special needs and really knew what you were doing.
7571 * Note: if you turn off double-buffering, you have to handle
7572 * expose events, since even the clearing to the background color or
7573 * pixmap will not happen automatically (as it is done in
7574 * gdk_window_begin_paint()).
7577 gtk_widget_set_double_buffered (GtkWidget *widget,
7578 gboolean double_buffered)
7580 g_return_if_fail (GTK_IS_WIDGET (widget));
7582 double_buffered = (double_buffered != FALSE);
7584 if (widget->priv->double_buffered != double_buffered)
7586 widget->priv->double_buffered = double_buffered;
7588 g_object_notify (G_OBJECT (widget), "double-buffered");
7593 * gtk_widget_get_double_buffered:
7594 * @widget: a #GtkWidget
7596 * Determines whether the widget is double buffered.
7598 * See gtk_widget_set_double_buffered()
7600 * Return value: %TRUE if the widget is double buffered
7605 gtk_widget_get_double_buffered (GtkWidget *widget)
7607 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7609 return widget->priv->double_buffered;
7613 * gtk_widget_set_redraw_on_allocate:
7614 * @widget: a #GtkWidget
7615 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7616 * when it is allocated to a new size. Otherwise, only the
7617 * new portion of the widget will be redrawn.
7619 * Sets whether the entire widget is queued for drawing when its size
7620 * allocation changes. By default, this setting is %TRUE and
7621 * the entire widget is redrawn on every size change. If your widget
7622 * leaves the upper left unchanged when made bigger, turning this
7623 * setting off will improve performance.
7625 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7626 * off all allocation on resizing: the widget will not even redraw if
7627 * its position changes; this is to allow containers that don't draw
7628 * anything to avoid excess invalidations. If you set this flag on a
7629 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7630 * you are responsible for invalidating both the old and new allocation
7631 * of the widget when the widget is moved and responsible for invalidating
7632 * regions newly when the widget increases size.
7635 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7636 gboolean redraw_on_allocate)
7638 g_return_if_fail (GTK_IS_WIDGET (widget));
7640 widget->priv->redraw_on_alloc = redraw_on_allocate;
7644 * gtk_widget_set_sensitive:
7645 * @widget: a #GtkWidget
7646 * @sensitive: %TRUE to make the widget sensitive
7648 * Sets the sensitivity of a widget. A widget is sensitive if the user
7649 * can interact with it. Insensitive widgets are "grayed out" and the
7650 * user can't interact with them. Insensitive widgets are known as
7651 * "inactive", "disabled", or "ghosted" in some other toolkits.
7654 gtk_widget_set_sensitive (GtkWidget *widget,
7657 GtkWidgetPrivate *priv;
7660 g_return_if_fail (GTK_IS_WIDGET (widget));
7662 priv = widget->priv;
7664 sensitive = (sensitive != FALSE);
7666 if (priv->sensitive == sensitive)
7669 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7673 priv->sensitive = TRUE;
7674 data.operation = STATE_CHANGE_UNSET;
7678 priv->sensitive = FALSE;
7679 data.operation = STATE_CHANGE_SET;
7682 data.use_forall = TRUE;
7684 gtk_widget_propagate_state (widget, &data);
7686 gtk_widget_queue_resize (widget);
7688 g_object_notify (G_OBJECT (widget), "sensitive");
7692 * gtk_widget_get_sensitive:
7693 * @widget: a #GtkWidget
7695 * Returns the widget's sensitivity (in the sense of returning
7696 * the value that has been set using gtk_widget_set_sensitive()).
7698 * The effective sensitivity of a widget is however determined by both its
7699 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7701 * Returns: %TRUE if the widget is sensitive
7706 gtk_widget_get_sensitive (GtkWidget *widget)
7708 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7710 return widget->priv->sensitive;
7714 * gtk_widget_is_sensitive:
7715 * @widget: a #GtkWidget
7717 * Returns the widget's effective sensitivity, which means
7718 * it is sensitive itself and also its parent widget is sensitive
7720 * Returns: %TRUE if the widget is effectively sensitive
7725 gtk_widget_is_sensitive (GtkWidget *widget)
7727 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7729 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
7733 _gtk_widget_update_path (GtkWidget *widget)
7735 if (widget->priv->path)
7737 gtk_widget_path_free (widget->priv->path);
7738 widget->priv->path = NULL;
7741 gtk_widget_get_path (widget);
7745 * gtk_widget_set_parent:
7746 * @widget: a #GtkWidget
7747 * @parent: parent container
7749 * This function is useful only when implementing subclasses of
7751 * Sets the container as the parent of @widget, and takes care of
7752 * some details such as updating the state and style of the child
7753 * to reflect its new location. The opposite function is
7754 * gtk_widget_unparent().
7757 gtk_widget_set_parent (GtkWidget *widget,
7760 GtkStateFlags parent_flags;
7761 GtkWidgetPrivate *priv;
7764 g_return_if_fail (GTK_IS_WIDGET (widget));
7765 g_return_if_fail (GTK_IS_WIDGET (parent));
7766 g_return_if_fail (widget != parent);
7768 priv = widget->priv;
7770 if (priv->parent != NULL)
7772 g_warning ("Can't set a parent on widget which has a parent\n");
7775 if (gtk_widget_is_toplevel (widget))
7777 g_warning ("Can't set a parent on a toplevel widget\n");
7781 /* keep this function in sync with gtk_menu_attach_to_widget()
7784 g_object_ref_sink (widget);
7786 gtk_widget_push_verify_invariants (widget);
7788 priv->parent = parent;
7790 parent_flags = gtk_widget_get_state_flags (parent);
7792 /* Merge both old state and current parent state,
7793 * making sure to only propagate the right states */
7794 data.flags = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
7795 data.flags |= priv->state_flags;
7797 data.operation = STATE_CHANGE_REPLACE;
7798 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7799 gtk_widget_propagate_state (widget, &data);
7801 gtk_widget_reset_style (widget);
7803 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7804 if (priv->parent->priv->anchored)
7805 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7806 g_object_notify (G_OBJECT (widget), "parent");
7808 /* Enforce realized/mapped invariants
7810 if (gtk_widget_get_realized (priv->parent))
7811 gtk_widget_realize (widget);
7813 if (gtk_widget_get_visible (priv->parent) &&
7814 gtk_widget_get_visible (widget))
7816 if (gtk_widget_get_child_visible (widget) &&
7817 gtk_widget_get_mapped (priv->parent))
7818 gtk_widget_map (widget);
7820 gtk_widget_queue_resize (widget);
7823 /* child may cause parent's expand to change, if the child is
7824 * expanded. If child is not expanded, then it can't modify the
7825 * parent's expand. If the child becomes expanded later then it will
7826 * queue compute_expand then. This optimization plus defaulting
7827 * newly-constructed widgets to need_compute_expand=FALSE should
7828 * mean that initially building a widget tree doesn't have to keep
7829 * walking up setting need_compute_expand on parents over and over.
7831 * We can't change a parent to need to expand unless we're visible.
7833 if (gtk_widget_get_visible (widget) &&
7834 (priv->need_compute_expand ||
7835 priv->computed_hexpand ||
7836 priv->computed_vexpand))
7838 gtk_widget_queue_compute_expand (parent);
7841 gtk_widget_pop_verify_invariants (widget);
7845 * gtk_widget_get_parent:
7846 * @widget: a #GtkWidget
7848 * Returns the parent container of @widget.
7850 * Return value: (transfer none): the parent container of @widget, or %NULL
7853 gtk_widget_get_parent (GtkWidget *widget)
7855 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7857 return widget->priv->parent;
7861 modifier_style_changed (GtkModifierStyle *style,
7864 GtkStyleContext *context;
7866 context = gtk_widget_get_style_context (widget);
7867 gtk_style_context_invalidate (context);
7870 static GtkModifierStyle *
7871 _gtk_widget_get_modifier_properties (GtkWidget *widget)
7873 GtkModifierStyle *style;
7875 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
7877 if (G_UNLIKELY (!style))
7879 GtkStyleContext *context;
7881 style = _gtk_modifier_style_new ();
7882 g_object_set_qdata_full (G_OBJECT (widget),
7883 quark_modifier_style,
7885 (GDestroyNotify) g_object_unref);
7887 g_signal_connect (style, "changed",
7888 G_CALLBACK (modifier_style_changed), widget);
7890 context = gtk_widget_get_style_context (widget);
7892 gtk_style_context_add_provider (context,
7893 GTK_STYLE_PROVIDER (style),
7894 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
7901 * gtk_widget_override_color:
7902 * @widget: a #GtkWidget
7903 * @state: the state for which to set the color
7904 * @color: (allow-none): the color to assign, or %NULL to undo the effect
7905 * of previous calls to gtk_widget_override_color()
7907 * Sets the color to use for a widget.
7909 * All other style values are left untouched.
7912 * This API is mostly meant as a quick way for applications to
7913 * change a widget appearance. If you are developing a widgets
7914 * library and intend this change to be themeable, it is better
7915 * done by setting meaningful CSS classes and regions in your
7916 * widget/container implementation through gtk_style_context_add_class()
7917 * and gtk_style_context_add_region().
7919 * This way, your widget library can install a #GtkCssProvider
7920 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
7921 * to provide a default styling for those widgets that need so, and
7922 * this theming may fully overridden by the user's theme.
7925 * Note that for complex widgets this may bring in undesired
7926 * results (such as uniform background color everywhere), in
7927 * these cases it is better to fully style such widgets through a
7928 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
7935 gtk_widget_override_color (GtkWidget *widget,
7936 GtkStateFlags state,
7937 const GdkRGBA *color)
7939 GtkModifierStyle *style;
7941 g_return_if_fail (GTK_IS_WIDGET (widget));
7943 style = _gtk_widget_get_modifier_properties (widget);
7944 _gtk_modifier_style_set_color (style, state, color);
7948 * gtk_widget_override_background_color:
7949 * @widget: a #GtkWidget
7950 * @state: the state for which to set the background color
7951 * @color: (allow-none): the color to assign, or %NULL to undo the effect
7952 * of previous calls to gtk_widget_override_background_color()
7954 * Sets the background color to use for a widget.
7956 * All other style values are left untouched.
7957 * See gtk_widget_override_color().
7962 gtk_widget_override_background_color (GtkWidget *widget,
7963 GtkStateFlags state,
7964 const GdkRGBA *color)
7966 GtkModifierStyle *style;
7968 g_return_if_fail (GTK_IS_WIDGET (widget));
7970 style = _gtk_widget_get_modifier_properties (widget);
7971 _gtk_modifier_style_set_background_color (style, state, color);
7975 * gtk_widget_override_font:
7976 * @widget: a #GtkWidget
7977 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
7978 * the effect of previous calls to gtk_widget_override_font()
7980 * Sets the font to use for a widget. All other style values are
7981 * left untouched. See gtk_widget_override_color().
7986 gtk_widget_override_font (GtkWidget *widget,
7987 const PangoFontDescription *font_desc)
7989 GtkModifierStyle *style;
7991 g_return_if_fail (GTK_IS_WIDGET (widget));
7993 style = _gtk_widget_get_modifier_properties (widget);
7994 _gtk_modifier_style_set_font (style, font_desc);
7998 * gtk_widget_override_symbolic_color:
7999 * @widget: a #GtkWidget
8000 * @name: the name of the symbolic color to modify
8001 * @color: (allow-none): the color to assign (does not need
8002 * to be allocated), or %NULL to undo the effect of previous
8003 * calls to gtk_widget_override_symbolic_color()
8005 * Sets a symbolic color for a widget.
8007 * All other style values are left untouched.
8008 * See gtk_widget_override_color() for overriding the foreground
8009 * or background color.
8014 gtk_widget_override_symbolic_color (GtkWidget *widget,
8016 const GdkRGBA *color)
8018 GtkModifierStyle *style;
8020 g_return_if_fail (GTK_IS_WIDGET (widget));
8022 style = _gtk_widget_get_modifier_properties (widget);
8023 _gtk_modifier_style_map_color (style, name, color);
8027 * gtk_widget_override_cursor:
8028 * @widget: a #GtkWidget
8029 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8030 * allocated), or %NULL to undo the effect of previous calls to
8031 * of gtk_widget_override_cursor().
8032 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8033 * need to be allocated), or %NULL to undo the effect of previous
8034 * calls to of gtk_widget_override_cursor().
8036 * Sets the cursor color to use in a widget, overriding the
8037 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8038 * style properties. All other style values are left untouched.
8039 * See also gtk_widget_modify_style().
8041 * Note that the underlying properties have the #GdkColor type,
8042 * so the alpha value in @primary and @secondary will be ignored.
8047 gtk_widget_override_cursor (GtkWidget *widget,
8048 const GdkRGBA *cursor,
8049 const GdkRGBA *secondary_cursor)
8051 GtkModifierStyle *style;
8053 g_return_if_fail (GTK_IS_WIDGET (widget));
8055 style = _gtk_widget_get_modifier_properties (widget);
8056 _gtk_modifier_style_set_color_property (style,
8058 "cursor-color", cursor);
8059 _gtk_modifier_style_set_color_property (style,
8061 "secondary-cursor-color",
8066 gtk_widget_real_direction_changed (GtkWidget *widget,
8067 GtkTextDirection previous_direction)
8069 gtk_widget_queue_resize (widget);
8073 gtk_widget_real_style_set (GtkWidget *widget,
8074 GtkStyle *previous_style)
8079 GtkWidget *previous_toplevel;
8080 GdkScreen *previous_screen;
8081 GdkScreen *new_screen;
8082 } HierarchyChangedInfo;
8085 do_screen_change (GtkWidget *widget,
8086 GdkScreen *old_screen,
8087 GdkScreen *new_screen)
8089 if (old_screen != new_screen)
8091 GtkWidgetPrivate *priv = widget->priv;
8095 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8097 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8100 _gtk_tooltip_hide (widget);
8102 if (new_screen && priv->context)
8103 gtk_style_context_set_screen (priv->context, new_screen);
8105 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8110 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8111 gpointer client_data)
8113 GtkWidgetPrivate *priv = widget->priv;
8114 HierarchyChangedInfo *info = client_data;
8115 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8116 (priv->parent && priv->parent->priv->anchored);
8118 if (priv->anchored != new_anchored)
8120 g_object_ref (widget);
8122 priv->anchored = new_anchored;
8124 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8125 do_screen_change (widget, info->previous_screen, info->new_screen);
8127 if (GTK_IS_CONTAINER (widget))
8128 gtk_container_forall (GTK_CONTAINER (widget),
8129 gtk_widget_propagate_hierarchy_changed_recurse,
8132 g_object_unref (widget);
8137 * _gtk_widget_propagate_hierarchy_changed:
8138 * @widget: a #GtkWidget
8139 * @previous_toplevel: Previous toplevel
8141 * Propagates changes in the anchored state to a widget and all
8142 * children, unsetting or setting the %ANCHORED flag, and
8143 * emitting #GtkWidget::hierarchy-changed.
8146 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8147 GtkWidget *previous_toplevel)
8149 GtkWidgetPrivate *priv = widget->priv;
8150 HierarchyChangedInfo info;
8152 info.previous_toplevel = previous_toplevel;
8153 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8155 if (gtk_widget_is_toplevel (widget) ||
8156 (priv->parent && priv->parent->priv->anchored))
8157 info.new_screen = gtk_widget_get_screen (widget);
8159 info.new_screen = NULL;
8161 if (info.previous_screen)
8162 g_object_ref (info.previous_screen);
8163 if (previous_toplevel)
8164 g_object_ref (previous_toplevel);
8166 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8168 if (previous_toplevel)
8169 g_object_unref (previous_toplevel);
8170 if (info.previous_screen)
8171 g_object_unref (info.previous_screen);
8175 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8176 gpointer client_data)
8178 HierarchyChangedInfo *info = client_data;
8180 g_object_ref (widget);
8182 do_screen_change (widget, info->previous_screen, info->new_screen);
8184 if (GTK_IS_CONTAINER (widget))
8185 gtk_container_forall (GTK_CONTAINER (widget),
8186 gtk_widget_propagate_screen_changed_recurse,
8189 g_object_unref (widget);
8193 * gtk_widget_is_composited:
8194 * @widget: a #GtkWidget
8196 * Whether @widget can rely on having its alpha channel
8197 * drawn correctly. On X11 this function returns whether a
8198 * compositing manager is running for @widget's screen.
8200 * Please note that the semantics of this call will change
8201 * in the future if used on a widget that has a composited
8202 * window in its hierarchy (as set by gdk_window_set_composited()).
8204 * Return value: %TRUE if the widget can rely on its alpha
8205 * channel being drawn correctly.
8210 gtk_widget_is_composited (GtkWidget *widget)
8214 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8216 screen = gtk_widget_get_screen (widget);
8218 return gdk_screen_is_composited (screen);
8222 propagate_composited_changed (GtkWidget *widget,
8225 if (GTK_IS_CONTAINER (widget))
8227 gtk_container_forall (GTK_CONTAINER (widget),
8228 propagate_composited_changed,
8232 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8236 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8238 propagate_composited_changed (widget, NULL);
8242 * _gtk_widget_propagate_screen_changed:
8243 * @widget: a #GtkWidget
8244 * @previous_screen: Previous screen
8246 * Propagates changes in the screen for a widget to all
8247 * children, emitting #GtkWidget::screen-changed.
8250 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8251 GdkScreen *previous_screen)
8253 HierarchyChangedInfo info;
8255 info.previous_screen = previous_screen;
8256 info.new_screen = gtk_widget_get_screen (widget);
8258 if (previous_screen)
8259 g_object_ref (previous_screen);
8261 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8263 if (previous_screen)
8264 g_object_unref (previous_screen);
8268 reset_style_recurse (GtkWidget *widget, gpointer data)
8270 _gtk_widget_update_path (widget);
8272 if (GTK_IS_CONTAINER (widget))
8273 gtk_container_forall (GTK_CONTAINER (widget),
8274 reset_style_recurse,
8279 * gtk_widget_reset_style:
8280 * @widget: a #GtkWidget
8282 * Updates the style context of @widget and all descendents
8283 * by updating its widget path. #GtkContainer<!-- -->s may want
8284 * to use this on a child when reordering it in a way that a different
8285 * style might apply to it. See also gtk_container_get_path_for_child().
8290 gtk_widget_reset_style (GtkWidget *widget)
8292 g_return_if_fail (GTK_IS_WIDGET (widget));
8294 reset_style_recurse (widget, NULL);
8297 #ifdef G_ENABLE_DEBUG
8299 /* Verify invariants, see docs/widget_system.txt for notes on much of
8300 * this. Invariants may be temporarily broken while we're in the
8301 * process of updating state, of course, so you can only
8302 * verify_invariants() after a given operation is complete.
8303 * Use push/pop_verify_invariants to help with that.
8306 gtk_widget_verify_invariants (GtkWidget *widget)
8310 if (widget->priv->verifying_invariants_count > 0)
8313 parent = widget->priv->parent;
8315 if (widget->priv->mapped)
8317 /* Mapped implies ... */
8319 if (!widget->priv->realized)
8320 g_warning ("%s %p is mapped but not realized",
8321 G_OBJECT_TYPE_NAME (widget), widget);
8323 if (!widget->priv->visible)
8324 g_warning ("%s %p is mapped but not visible",
8325 G_OBJECT_TYPE_NAME (widget), widget);
8327 if (!widget->priv->toplevel)
8329 if (!widget->priv->child_visible)
8330 g_warning ("%s %p is mapped but not child_visible",
8331 G_OBJECT_TYPE_NAME (widget), widget);
8336 /* Not mapped implies... */
8339 /* This check makes sense for normal toplevels, but for
8340 * something like a toplevel that is embedded within a clutter
8341 * state, mapping may depend on external factors.
8343 if (widget->priv->toplevel)
8345 if (widget->priv->visible)
8346 g_warning ("%s %p toplevel is visible but not mapped",
8347 G_OBJECT_TYPE_NAME (widget), widget);
8352 /* Parent related checks aren't possible if parent has
8353 * verifying_invariants_count > 0 because parent needs to recurse
8354 * children first before the invariants will hold.
8356 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8359 parent->priv->realized)
8361 /* Parent realized implies... */
8364 /* This is in widget_system.txt but appears to fail
8365 * because there's no gtk_container_realize() that
8366 * realizes all children... instead we just lazily
8367 * wait for map to fix things up.
8369 if (!widget->priv->realized)
8370 g_warning ("%s %p is realized but child %s %p is not realized",
8371 G_OBJECT_TYPE_NAME (parent), parent,
8372 G_OBJECT_TYPE_NAME (widget), widget);
8375 else if (!widget->priv->toplevel)
8377 /* No parent or parent not realized on non-toplevel implies... */
8379 if (widget->priv->realized && !widget->priv->in_reparent)
8380 g_warning ("%s %p is not realized but child %s %p is realized",
8381 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8382 G_OBJECT_TYPE_NAME (widget), widget);
8386 parent->priv->mapped &&
8387 widget->priv->visible &&
8388 widget->priv->child_visible)
8390 /* Parent mapped and we are visible implies... */
8392 if (!widget->priv->mapped)
8393 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8394 G_OBJECT_TYPE_NAME (parent), parent,
8395 G_OBJECT_TYPE_NAME (widget), widget);
8397 else if (!widget->priv->toplevel)
8399 /* No parent or parent not mapped on non-toplevel implies... */
8401 if (widget->priv->mapped && !widget->priv->in_reparent)
8402 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8403 G_OBJECT_TYPE_NAME (widget), widget,
8404 widget->priv->visible,
8405 widget->priv->child_visible,
8406 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8407 parent ? parent->priv->mapped : FALSE);
8411 if (!widget->priv->realized)
8413 /* Not realized implies... */
8416 /* widget_system.txt says these hold, but they don't. */
8417 if (widget->priv->resize_pending)
8418 g_warning ("%s %p resize pending but not realized",
8419 G_OBJECT_TYPE_NAME (widget), widget);
8421 if (widget->priv->alloc_needed)
8422 g_warning ("%s %p alloc needed but not realized",
8423 G_OBJECT_TYPE_NAME (widget), widget);
8425 if (widget->priv->width_request_needed)
8426 g_warning ("%s %p width request needed but not realized",
8427 G_OBJECT_TYPE_NAME (widget), widget);
8429 if (widget->priv->height_request_needed)
8430 g_warning ("%s %p height request needed but not realized",
8431 G_OBJECT_TYPE_NAME (widget), widget);
8436 /* The point of this push/pop is that invariants may not hold while
8437 * we're busy making changes. So we only check at the outermost call
8438 * on the call stack, after we finish updating everything.
8441 gtk_widget_push_verify_invariants (GtkWidget *widget)
8443 widget->priv->verifying_invariants_count += 1;
8447 gtk_widget_verify_child_invariants (GtkWidget *widget,
8448 gpointer client_data)
8450 /* We don't recurse further; this is a one-level check. */
8451 gtk_widget_verify_invariants (widget);
8455 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8457 g_assert (widget->priv->verifying_invariants_count > 0);
8459 widget->priv->verifying_invariants_count -= 1;
8461 if (widget->priv->verifying_invariants_count == 0)
8463 gtk_widget_verify_invariants (widget);
8465 if (GTK_IS_CONTAINER (widget))
8467 /* Check one level of children, because our
8468 * push_verify_invariants() will have prevented some of the
8469 * checks. This does not recurse because if recursion is
8470 * needed, it will happen naturally as each child has a
8471 * push/pop on that child. For example if we're recursively
8472 * mapping children, we'll push/pop on each child as we map
8475 gtk_container_forall (GTK_CONTAINER (widget),
8476 gtk_widget_verify_child_invariants,
8481 #endif /* G_ENABLE_DEBUG */
8483 static PangoContext *
8484 gtk_widget_peek_pango_context (GtkWidget *widget)
8486 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8490 * gtk_widget_get_pango_context:
8491 * @widget: a #GtkWidget
8493 * Gets a #PangoContext with the appropriate font map, font description,
8494 * and base direction for this widget. Unlike the context returned
8495 * by gtk_widget_create_pango_context(), this context is owned by
8496 * the widget (it can be used until the screen for the widget changes
8497 * or the widget is removed from its toplevel), and will be updated to
8498 * match any changes to the widget's attributes.
8500 * If you create and keep a #PangoLayout using this context, you must
8501 * deal with changes to the context by calling pango_layout_context_changed()
8502 * on the layout in response to the #GtkWidget::style-updated and
8503 * #GtkWidget::direction-changed signals for the widget.
8505 * Return value: (transfer none): the #PangoContext for the widget.
8508 gtk_widget_get_pango_context (GtkWidget *widget)
8510 PangoContext *context;
8512 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8514 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8517 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8518 g_object_set_qdata_full (G_OBJECT (widget),
8519 quark_pango_context,
8528 update_pango_context (GtkWidget *widget,
8529 PangoContext *context)
8531 const PangoFontDescription *font_desc;
8532 GtkStyleContext *style_context;
8534 style_context = gtk_widget_get_style_context (widget);
8536 font_desc = gtk_style_context_get_font (style_context,
8537 gtk_widget_get_state_flags (widget));
8539 pango_context_set_font_description (context, font_desc);
8540 pango_context_set_base_dir (context,
8541 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8542 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8546 gtk_widget_update_pango_context (GtkWidget *widget)
8548 PangoContext *context = gtk_widget_peek_pango_context (widget);
8554 update_pango_context (widget, context);
8556 screen = gtk_widget_get_screen_unchecked (widget);
8559 pango_cairo_context_set_resolution (context,
8560 gdk_screen_get_resolution (screen));
8561 pango_cairo_context_set_font_options (context,
8562 gdk_screen_get_font_options (screen));
8568 * gtk_widget_create_pango_context:
8569 * @widget: a #GtkWidget
8571 * Creates a new #PangoContext with the appropriate font map,
8572 * font description, and base direction for drawing text for
8573 * this widget. See also gtk_widget_get_pango_context().
8575 * Return value: (transfer full): the new #PangoContext
8578 gtk_widget_create_pango_context (GtkWidget *widget)
8581 PangoContext *context;
8583 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8585 screen = gtk_widget_get_screen_unchecked (widget);
8588 GTK_NOTE (MULTIHEAD,
8589 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8591 screen = gdk_screen_get_default ();
8594 context = gdk_pango_context_get_for_screen (screen);
8596 update_pango_context (widget, context);
8597 pango_context_set_language (context, gtk_get_default_language ());
8603 * gtk_widget_create_pango_layout:
8604 * @widget: a #GtkWidget
8605 * @text: text to set on the layout (can be %NULL)
8607 * Creates a new #PangoLayout with the appropriate font map,
8608 * font description, and base direction for drawing text for
8611 * If you keep a #PangoLayout created in this way around, in order to
8612 * notify the layout of changes to the base direction or font of this
8613 * widget, you must call pango_layout_context_changed() in response to
8614 * the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
8617 * Return value: (transfer full): the new #PangoLayout
8620 gtk_widget_create_pango_layout (GtkWidget *widget,
8623 PangoLayout *layout;
8624 PangoContext *context;
8626 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8628 context = gtk_widget_get_pango_context (widget);
8629 layout = pango_layout_new (context);
8632 pango_layout_set_text (layout, text, -1);
8638 * gtk_widget_render_icon_pixbuf:
8639 * @widget: a #GtkWidget
8640 * @stock_id: a stock ID
8641 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8642 * render at the size of the source and don't scale (if there are
8643 * multiple source sizes, GTK+ picks one of the available sizes).
8645 * A convenience function that uses the theme engine and style
8646 * settings for @widget to look up @stock_id and render it to
8647 * a pixbuf. @stock_id should be a stock icon ID such as
8648 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8649 * such as #GTK_ICON_SIZE_MENU.
8651 * The pixels in the returned #GdkPixbuf are shared with the rest of
8652 * the application and should not be modified. The pixbuf should be freed
8653 * after use with g_object_unref().
8655 * Return value: (transfer full): a new pixbuf, or %NULL if the
8656 * stock ID wasn't known
8661 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
8662 const gchar *stock_id,
8665 GtkStyleContext *context;
8666 GtkIconSet *icon_set;
8668 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8669 g_return_val_if_fail (stock_id != NULL, NULL);
8670 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8672 context = gtk_widget_get_style_context (widget);
8673 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
8675 if (icon_set == NULL)
8678 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
8682 * gtk_widget_set_parent_window:
8683 * @widget: a #GtkWidget.
8684 * @parent_window: the new parent window.
8686 * Sets a non default parent window for @widget.
8688 * For GtkWindow classes, setting a @parent_window effects whether
8689 * the window is a toplevel window or can be embedded into other
8693 * For GtkWindow classes, this needs to be called before the
8694 * window is realized.
8699 gtk_widget_set_parent_window (GtkWidget *widget,
8700 GdkWindow *parent_window)
8702 GdkWindow *old_parent_window;
8704 g_return_if_fail (GTK_IS_WIDGET (widget));
8706 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8707 quark_parent_window);
8709 if (parent_window != old_parent_window)
8713 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8715 if (old_parent_window)
8716 g_object_unref (old_parent_window);
8718 g_object_ref (parent_window);
8720 /* Unset toplevel flag when adding a parent window to a widget,
8721 * this is the primary entry point to allow toplevels to be
8724 #ifdef GDK_WINDOWING_X11
8725 is_plug = GTK_IS_PLUG (widget);
8729 if (GTK_IS_WINDOW (widget) && !is_plug)
8730 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
8735 * gtk_widget_get_parent_window:
8736 * @widget: a #GtkWidget.
8738 * Gets @widget's parent window.
8740 * Returns: (transfer none): the parent window of @widget.
8743 gtk_widget_get_parent_window (GtkWidget *widget)
8745 GtkWidgetPrivate *priv;
8746 GdkWindow *parent_window;
8748 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8750 priv = widget->priv;
8752 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8754 return (parent_window != NULL) ? parent_window :
8755 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8760 * gtk_widget_set_child_visible:
8761 * @widget: a #GtkWidget
8762 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8764 * Sets whether @widget should be mapped along with its when its parent
8765 * is mapped and @widget has been shown with gtk_widget_show().
8767 * The child visibility can be set for widget before it is added to
8768 * a container with gtk_widget_set_parent(), to avoid mapping
8769 * children unnecessary before immediately unmapping them. However
8770 * it will be reset to its default state of %TRUE when the widget
8771 * is removed from a container.
8773 * Note that changing the child visibility of a widget does not
8774 * queue a resize on the widget. Most of the time, the size of
8775 * a widget is computed from all visible children, whether or
8776 * not they are mapped. If this is not the case, the container
8777 * can queue a resize itself.
8779 * This function is only useful for container implementations and
8780 * never should be called by an application.
8783 gtk_widget_set_child_visible (GtkWidget *widget,
8784 gboolean is_visible)
8786 GtkWidgetPrivate *priv;
8788 g_return_if_fail (GTK_IS_WIDGET (widget));
8789 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8791 priv = widget->priv;
8793 g_object_ref (widget);
8794 gtk_widget_verify_invariants (widget);
8797 priv->child_visible = TRUE;
8800 GtkWidget *toplevel;
8802 priv->child_visible = FALSE;
8804 toplevel = gtk_widget_get_toplevel (widget);
8805 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8806 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8809 if (priv->parent && gtk_widget_get_realized (priv->parent))
8811 if (gtk_widget_get_mapped (priv->parent) &&
8812 priv->child_visible &&
8813 gtk_widget_get_visible (widget))
8814 gtk_widget_map (widget);
8816 gtk_widget_unmap (widget);
8819 gtk_widget_verify_invariants (widget);
8820 g_object_unref (widget);
8824 * gtk_widget_get_child_visible:
8825 * @widget: a #GtkWidget
8827 * Gets the value set with gtk_widget_set_child_visible().
8828 * If you feel a need to use this function, your code probably
8829 * needs reorganization.
8831 * This function is only useful for container implementations and
8832 * never should be called by an application.
8834 * Return value: %TRUE if the widget is mapped with the parent.
8837 gtk_widget_get_child_visible (GtkWidget *widget)
8839 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8841 return widget->priv->child_visible;
8845 gtk_widget_get_screen_unchecked (GtkWidget *widget)
8847 GtkWidget *toplevel;
8849 toplevel = gtk_widget_get_toplevel (widget);
8851 if (gtk_widget_is_toplevel (toplevel))
8853 if (GTK_IS_WINDOW (toplevel))
8854 return gtk_window_get_screen (GTK_WINDOW (toplevel));
8855 else if (GTK_IS_INVISIBLE (toplevel))
8856 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
8863 * gtk_widget_get_screen:
8864 * @widget: a #GtkWidget
8866 * Get the #GdkScreen from the toplevel window associated with
8867 * this widget. This function can only be called after the widget
8868 * has been added to a widget hierarchy with a #GtkWindow
8871 * In general, you should only create screen specific
8872 * resources when a widget has been realized, and you should
8873 * free those resources when the widget is unrealized.
8875 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
8880 gtk_widget_get_screen (GtkWidget *widget)
8884 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8886 screen = gtk_widget_get_screen_unchecked (widget);
8893 g_warning (G_STRLOC ": Can't get associated screen"
8894 " for a widget unless it is inside a toplevel GtkWindow\n"
8895 " widget type is %s associated top level type is %s",
8896 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
8897 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
8899 return gdk_screen_get_default ();
8904 * gtk_widget_has_screen:
8905 * @widget: a #GtkWidget
8907 * Checks whether there is a #GdkScreen is associated with
8908 * this widget. All toplevel widgets have an associated
8909 * screen, and all widgets added into a hierarchy with a toplevel
8910 * window at the top.
8912 * Return value: %TRUE if there is a #GdkScreen associcated
8918 gtk_widget_has_screen (GtkWidget *widget)
8920 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8922 return (gtk_widget_get_screen_unchecked (widget) != NULL);
8926 * gtk_widget_get_display:
8927 * @widget: a #GtkWidget
8929 * Get the #GdkDisplay for the toplevel window associated with
8930 * this widget. This function can only be called after the widget
8931 * has been added to a widget hierarchy with a #GtkWindow at the top.
8933 * In general, you should only create display specific
8934 * resources when a widget has been realized, and you should
8935 * free those resources when the widget is unrealized.
8937 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
8942 gtk_widget_get_display (GtkWidget *widget)
8944 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8946 return gdk_screen_get_display (gtk_widget_get_screen (widget));
8950 * gtk_widget_get_root_window:
8951 * @widget: a #GtkWidget
8953 * Get the root window where this widget is located. This function can
8954 * only be called after the widget has been added to a widget
8955 * hierarchy with #GtkWindow at the top.
8957 * The root window is useful for such purposes as creating a popup
8958 * #GdkWindow associated with the window. In general, you should only
8959 * create display specific resources when a widget has been realized,
8960 * and you should free those resources when the widget is unrealized.
8962 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
8967 gtk_widget_get_root_window (GtkWidget *widget)
8969 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8971 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
8975 * gtk_widget_child_focus:
8976 * @widget: a #GtkWidget
8977 * @direction: direction of focus movement
8979 * This function is used by custom widget implementations; if you're
8980 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
8981 * to a particular widget, and gtk_container_set_focus_chain() to
8982 * change the focus tab order. So you may want to investigate those
8983 * functions instead.
8985 * gtk_widget_child_focus() is called by containers as the user moves
8986 * around the window using keyboard shortcuts. @direction indicates
8987 * what kind of motion is taking place (up, down, left, right, tab
8988 * forward, tab backward). gtk_widget_child_focus() emits the
8989 * #GtkWidget::focus signal; widgets override the default handler
8990 * for this signal in order to implement appropriate focus behavior.
8992 * The default ::focus handler for a widget should return %TRUE if
8993 * moving in @direction left the focus on a focusable location inside
8994 * that widget, and %FALSE if moving in @direction moved the focus
8995 * outside the widget. If returning %TRUE, widgets normally
8996 * call gtk_widget_grab_focus() to place the focus accordingly;
8997 * if returning %FALSE, they don't modify the current focus location.
8999 * Return value: %TRUE if focus ended up inside @widget
9002 gtk_widget_child_focus (GtkWidget *widget,
9003 GtkDirectionType direction)
9005 gboolean return_val;
9007 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9009 if (!gtk_widget_get_visible (widget) ||
9010 !gtk_widget_is_sensitive (widget))
9013 /* child widgets must set CAN_FOCUS, containers
9014 * don't have to though.
9016 if (!GTK_IS_CONTAINER (widget) &&
9017 !gtk_widget_get_can_focus (widget))
9020 g_signal_emit (widget,
9021 widget_signals[FOCUS],
9023 direction, &return_val);
9029 * gtk_widget_keynav_failed:
9030 * @widget: a #GtkWidget
9031 * @direction: direction of focus movement
9033 * This function should be called whenever keyboard navigation within
9034 * a single widget hits a boundary. The function emits the
9035 * #GtkWidget::keynav-failed signal on the widget and its return
9036 * value should be interpreted in a way similar to the return value of
9037 * gtk_widget_child_focus():
9039 * When %TRUE is returned, stay in the widget, the failed keyboard
9040 * navigation is Ok and/or there is nowhere we can/should move the
9043 * When %FALSE is returned, the caller should continue with keyboard
9044 * navigation outside the widget, e.g. by calling
9045 * gtk_widget_child_focus() on the widget's toplevel.
9047 * The default ::keynav-failed handler returns %TRUE for
9048 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9049 * values of #GtkDirectionType, it looks at the
9050 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9051 * if the setting is %TRUE. This way the entire user interface
9052 * becomes cursor-navigatable on input devices such as mobile phones
9053 * which only have cursor keys but no tab key.
9055 * Whenever the default handler returns %TRUE, it also calls
9056 * gtk_widget_error_bell() to notify the user of the failed keyboard
9059 * A use case for providing an own implementation of ::keynav-failed
9060 * (either by connecting to it or by overriding it) would be a row of
9061 * #GtkEntry widgets where the user should be able to navigate the
9062 * entire row with the cursor keys, as e.g. known from user interfaces
9063 * that require entering license keys.
9065 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9066 * if the emitting widget should try to handle the keyboard
9067 * navigation attempt in its parent container(s).
9072 gtk_widget_keynav_failed (GtkWidget *widget,
9073 GtkDirectionType direction)
9075 gboolean return_val;
9077 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9079 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9080 direction, &return_val);
9086 * gtk_widget_error_bell:
9087 * @widget: a #GtkWidget
9089 * Notifies the user about an input-related error on this widget.
9090 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9091 * gdk_window_beep(), otherwise it does nothing.
9093 * Note that the effect of gdk_window_beep() can be configured in many
9094 * ways, depending on the windowing backend and the desktop environment
9095 * or window manager that is used.
9100 gtk_widget_error_bell (GtkWidget *widget)
9102 GtkWidgetPrivate *priv;
9103 GtkSettings* settings;
9106 g_return_if_fail (GTK_IS_WIDGET (widget));
9108 priv = widget->priv;
9110 settings = gtk_widget_get_settings (widget);
9114 g_object_get (settings,
9115 "gtk-error-bell", &beep,
9118 if (beep && priv->window)
9119 gdk_window_beep (priv->window);
9123 gtk_widget_set_usize_internal (GtkWidget *widget,
9126 GtkQueueResizeFlags flags)
9128 GtkWidgetAuxInfo *aux_info;
9129 gboolean changed = FALSE;
9131 g_object_freeze_notify (G_OBJECT (widget));
9133 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9135 if (width > -2 && aux_info->width != width)
9137 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9138 g_object_notify (G_OBJECT (widget), "width-request");
9139 aux_info->width = width;
9142 if (height > -2 && aux_info->height != height)
9144 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9145 g_object_notify (G_OBJECT (widget), "height-request");
9146 aux_info->height = height;
9150 if (gtk_widget_get_visible (widget) && changed)
9152 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9153 gtk_widget_queue_resize (widget);
9155 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9158 g_object_thaw_notify (G_OBJECT (widget));
9162 * gtk_widget_set_size_request:
9163 * @widget: a #GtkWidget
9164 * @width: width @widget should request, or -1 to unset
9165 * @height: height @widget should request, or -1 to unset
9167 * Sets the minimum size of a widget; that is, the widget's size
9168 * request will be @width by @height. You can use this function to
9169 * force a widget to be either larger or smaller than it normally
9172 * In most cases, gtk_window_set_default_size() is a better choice for
9173 * toplevel windows than this function; setting the default size will
9174 * still allow users to shrink the window. Setting the size request
9175 * will force them to leave the window at least as large as the size
9176 * request. When dealing with window sizes,
9177 * gtk_window_set_geometry_hints() can be a useful function as well.
9179 * Note the inherent danger of setting any fixed size - themes,
9180 * translations into other languages, different fonts, and user action
9181 * can all change the appropriate size for a given widget. So, it's
9182 * basically impossible to hardcode a size that will always be
9185 * The size request of a widget is the smallest size a widget can
9186 * accept while still functioning well and drawing itself correctly.
9187 * However in some strange cases a widget may be allocated less than
9188 * its requested size, and in many cases a widget may be allocated more
9189 * space than it requested.
9191 * If the size request in a given direction is -1 (unset), then
9192 * the "natural" size request of the widget will be used instead.
9194 * Widgets can't actually be allocated a size less than 1 by 1, but
9195 * you can pass 0,0 to this function to mean "as small as possible."
9197 * The size request set here does not include any margin from the
9198 * #GtkWidget properties margin-left, margin-right, margin-top, and
9199 * margin-bottom, but it does include pretty much all other padding
9200 * or border properties set by any subclass of #GtkWidget.
9203 gtk_widget_set_size_request (GtkWidget *widget,
9207 g_return_if_fail (GTK_IS_WIDGET (widget));
9208 g_return_if_fail (width >= -1);
9209 g_return_if_fail (height >= -1);
9216 gtk_widget_set_usize_internal (widget, width, height, 0);
9221 * gtk_widget_get_size_request:
9222 * @widget: a #GtkWidget
9223 * @width: (out) (allow-none): return location for width, or %NULL
9224 * @height: (out) (allow-none): return location for height, or %NULL
9226 * Gets the size request that was explicitly set for the widget using
9227 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9228 * @height indicates that that dimension has not been set explicitly
9229 * and the natural requisition of the widget will be used intead. See
9230 * gtk_widget_set_size_request(). To get the size a widget will
9231 * actually request, call gtk_widget_get_preferred_size() instead of
9235 gtk_widget_get_size_request (GtkWidget *widget,
9239 const GtkWidgetAuxInfo *aux_info;
9241 g_return_if_fail (GTK_IS_WIDGET (widget));
9243 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9246 *width = aux_info->width;
9249 *height = aux_info->height;
9253 * _gtk_widget_override_size_request:
9254 * @widget: a #GtkWidget
9255 * @width: new forced minimum width
9256 * @height: new forced minimum height
9257 * @old_width: location to store previous forced minimum width
9258 * @old_width: location to store previous forced minumum height
9260 * Temporarily establishes a forced minimum size for a widget; this
9261 * is used by GtkWindow when calculating the size to add to the
9262 * window's geometry widget. Cached sizes for the widget and its
9263 * parents are invalidated, so that subsequent calls to the size
9264 * negotiation machinery produce the overriden result, but the
9265 * widget is not queued for relayout or redraw. The old size must
9266 * be restored with _gtk_widget_restore_size_request() or things
9270 _gtk_widget_override_size_request (GtkWidget *widget,
9276 gtk_widget_get_size_request (widget, old_width, old_height);
9277 gtk_widget_set_usize_internal (widget, width, height,
9278 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9282 * _gtk_widget_restore_size_request:
9283 * @widget: a #GtkWidget
9284 * @old_width: saved forced minimum size
9285 * @old_height: saved forced minimum size
9287 * Undoes the operation of_gtk_widget_override_size_request().
9290 _gtk_widget_restore_size_request (GtkWidget *widget,
9294 gtk_widget_set_usize_internal (widget, old_width, old_height,
9295 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9299 * gtk_widget_set_events:
9300 * @widget: a #GtkWidget
9301 * @events: event mask
9303 * Sets the event mask (see #GdkEventMask) for a widget. The event
9304 * mask determines which events a widget will receive. Keep in mind
9305 * that different widgets have different default event masks, and by
9306 * changing the event mask you may disrupt a widget's functionality,
9307 * so be careful. This function must be called while a widget is
9308 * unrealized. Consider gtk_widget_add_events() for widgets that are
9309 * already realized, or if you want to preserve the existing event
9310 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9311 * to get events on those widgets, place them inside a #GtkEventBox
9312 * and receive events on the event box.
9315 gtk_widget_set_events (GtkWidget *widget,
9318 g_return_if_fail (GTK_IS_WIDGET (widget));
9319 g_return_if_fail (!gtk_widget_get_realized (widget));
9321 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9322 GINT_TO_POINTER (events));
9323 g_object_notify (G_OBJECT (widget), "events");
9327 * gtk_widget_set_device_events:
9328 * @widget: a #GtkWidget
9329 * @device: a #GdkDevice
9330 * @events: event mask
9332 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9333 * mask determines which events a widget will receive from @device. Keep
9334 * in mind that different widgets have different default event masks, and by
9335 * changing the event mask you may disrupt a widget's functionality,
9336 * so be careful. This function must be called while a widget is
9337 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9338 * already realized, or if you want to preserve the existing event
9339 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9340 * to get events on those widgets, place them inside a #GtkEventBox
9341 * and receive events on the event box.
9346 gtk_widget_set_device_events (GtkWidget *widget,
9348 GdkEventMask events)
9350 GHashTable *device_events;
9352 g_return_if_fail (GTK_IS_WIDGET (widget));
9353 g_return_if_fail (GDK_IS_DEVICE (device));
9354 g_return_if_fail (!gtk_widget_get_realized (widget));
9356 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9358 if (G_UNLIKELY (!device_events))
9360 device_events = g_hash_table_new (NULL, NULL);
9361 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9362 (GDestroyNotify) g_hash_table_unref);
9365 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9369 * gtk_widget_set_device_enabled:
9370 * @widget: a #GtkWidget
9371 * @device: a #GdkDevice
9372 * @enabled: whether to enable the device
9374 * Enables or disables a #GdkDevice to interact with @widget
9375 * and all its children.
9377 * It does so by descending through the #GdkWindow hierarchy
9378 * and enabling the same mask that is has for core events
9379 * (i.e. the one that gdk_window_get_events() returns).
9384 gtk_widget_set_device_enabled (GtkWidget *widget,
9388 GList *enabled_devices;
9390 g_return_if_fail (GTK_IS_WIDGET (widget));
9391 g_return_if_fail (GDK_IS_DEVICE (device));
9393 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9394 enabled_devices = g_list_append (enabled_devices, device);
9396 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9397 enabled_devices, (GDestroyNotify) g_list_free);;
9399 if (gtk_widget_get_realized (widget))
9400 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9404 * gtk_widget_get_device_enabled:
9405 * @widget: a #GtkWidget
9406 * @device: a #GdkDevice
9408 * Returns whether @device can interact with @widget and its
9409 * children. See gtk_widget_set_device_enabled().
9411 * Return value: %TRUE is @device is enabled for @widget
9416 gtk_widget_get_device_enabled (GtkWidget *widget,
9419 GList *enabled_devices;
9421 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9422 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9424 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9426 return g_list_find (enabled_devices, device) != NULL;
9430 gtk_widget_add_events_internal_list (GtkWidget *widget,
9437 for (l = window_list; l != NULL; l = l->next)
9439 GdkWindow *window = l->data;
9442 gdk_window_get_user_data (window, &user_data);
9443 if (user_data == widget)
9448 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9450 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9452 children = gdk_window_get_children (window);
9453 gtk_widget_add_events_internal_list (widget, device, events, children);
9454 g_list_free (children);
9460 gtk_widget_add_events_internal (GtkWidget *widget,
9464 GtkWidgetPrivate *priv = widget->priv;
9467 if (!gtk_widget_get_has_window (widget))
9468 window_list = gdk_window_get_children (priv->window);
9470 window_list = g_list_prepend (NULL, priv->window);
9472 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9474 g_list_free (window_list);
9478 * gtk_widget_add_events:
9479 * @widget: a #GtkWidget
9480 * @events: an event mask, see #GdkEventMask
9482 * Adds the events in the bitfield @events to the event mask for
9483 * @widget. See gtk_widget_set_events() for details.
9486 gtk_widget_add_events (GtkWidget *widget,
9491 g_return_if_fail (GTK_IS_WIDGET (widget));
9493 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9494 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9495 GINT_TO_POINTER (old_events | events));
9497 if (gtk_widget_get_realized (widget))
9499 gtk_widget_add_events_internal (widget, NULL, events);
9500 gtk_widget_update_devices_mask (widget, FALSE);
9503 g_object_notify (G_OBJECT (widget), "events");
9507 * gtk_widget_add_device_events:
9508 * @widget: a #GtkWidget
9509 * @device: a #GdkDevice
9510 * @events: an event mask, see #GdkEventMask
9512 * Adds the device events in the bitfield @events to the event mask for
9513 * @widget. See gtk_widget_set_device_events() for details.
9518 gtk_widget_add_device_events (GtkWidget *widget,
9520 GdkEventMask events)
9522 GdkEventMask old_events;
9523 GHashTable *device_events;
9525 g_return_if_fail (GTK_IS_WIDGET (widget));
9526 g_return_if_fail (GDK_IS_DEVICE (device));
9528 old_events = gtk_widget_get_device_events (widget, device);
9530 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9532 if (G_UNLIKELY (!device_events))
9534 device_events = g_hash_table_new (NULL, NULL);
9535 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9536 (GDestroyNotify) g_hash_table_unref);
9539 g_hash_table_insert (device_events, device,
9540 GUINT_TO_POINTER (old_events | events));
9542 if (gtk_widget_get_realized (widget))
9543 gtk_widget_add_events_internal (widget, device, events);
9545 g_object_notify (G_OBJECT (widget), "events");
9549 * gtk_widget_get_toplevel:
9550 * @widget: a #GtkWidget
9552 * This function returns the topmost widget in the container hierarchy
9553 * @widget is a part of. If @widget has no parent widgets, it will be
9554 * returned as the topmost widget. No reference will be added to the
9555 * returned widget; it should not be unreferenced.
9557 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9558 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9560 * %NULL if @widget wasn't inside a toplevel window, and if the
9561 * window was inside a #GtkWindow-derived widget which was in turn
9562 * inside the toplevel #GtkWindow. While the second case may
9563 * seem unlikely, it actually happens when a #GtkPlug is embedded
9564 * inside a #GtkSocket within the same application.
9566 * To reliably find the toplevel #GtkWindow, use
9567 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9568 * is set on the result.
9570 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9571 * if (gtk_widget_is_toplevel (toplevel))
9573 * /* Perform action on toplevel. */
9577 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9578 * if there's no ancestor.
9581 gtk_widget_get_toplevel (GtkWidget *widget)
9583 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9585 while (widget->priv->parent)
9586 widget = widget->priv->parent;
9592 * gtk_widget_get_ancestor:
9593 * @widget: a #GtkWidget
9594 * @widget_type: ancestor type
9596 * Gets the first ancestor of @widget with type @widget_type. For example,
9597 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9598 * the first #GtkBox that's an ancestor of @widget. No reference will be
9599 * added to the returned widget; it should not be unreferenced. See note
9600 * about checking for a toplevel #GtkWindow in the docs for
9601 * gtk_widget_get_toplevel().
9603 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9604 * considers @widget to be an ancestor of itself.
9606 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9609 gtk_widget_get_ancestor (GtkWidget *widget,
9612 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9614 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9615 widget = widget->priv->parent;
9617 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9624 * gtk_widget_set_visual:
9625 * @widget: a #GtkWidget
9626 * @visual: visual to be used or %NULL to unset a previous one
9628 * Sets the visual that should be used for by widget and its children for
9629 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9630 * returned by gdk_widget_get_screen(), so handling the
9631 * #GtkWidget::screen-changed signal is necessary.
9633 * Setting a new @visual will not cause @widget to recreate its windows,
9634 * so you should call this function before @widget is realized.
9637 gtk_widget_set_visual (GtkWidget *widget,
9640 g_return_if_fail (GTK_IS_WIDGET (widget));
9641 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9644 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9647 g_object_set_qdata_full (G_OBJECT (widget),
9649 g_object_ref (visual),
9654 * gtk_widget_get_visual:
9655 * @widget: a #GtkWidget
9657 * Gets the visual that will be used to render @widget.
9659 * Return value: (transfer none): the visual for @widget
9662 gtk_widget_get_visual (GtkWidget *widget)
9668 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9670 if (gtk_widget_get_has_window (widget) &&
9671 widget->priv->window)
9672 return gdk_window_get_visual (widget->priv->window);
9674 screen = gtk_widget_get_screen (widget);
9676 for (w = widget; w != NULL; w = w->priv->parent)
9678 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9681 if (gdk_visual_get_screen (visual) == screen)
9684 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9685 gtk_widget_get_name (widget));
9689 return gdk_screen_get_system_visual (screen);
9693 * gtk_widget_get_settings:
9694 * @widget: a #GtkWidget
9696 * Gets the settings object holding the settings used for this widget.
9698 * Note that this function can only be called when the #GtkWidget
9699 * is attached to a toplevel, since the settings object is specific
9700 * to a particular #GdkScreen.
9702 * Return value: (transfer none): the relevant #GtkSettings object
9705 gtk_widget_get_settings (GtkWidget *widget)
9707 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9709 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9713 * gtk_widget_get_events:
9714 * @widget: a #GtkWidget
9716 * Returns the event mask for the widget (a bitfield containing flags
9717 * from the #GdkEventMask enumeration). These are the events that the widget
9720 * Return value: event mask for @widget
9723 gtk_widget_get_events (GtkWidget *widget)
9725 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9727 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9731 * gtk_widget_get_device_events:
9732 * @widget: a #GtkWidget
9733 * @device: a #GdkDevice
9735 * Returns the events mask for the widget corresponding to an specific device. These
9736 * are the events that the widget will receive when @device operates on it.
9738 * Returns: device event mask for @widget
9743 gtk_widget_get_device_events (GtkWidget *widget,
9746 GHashTable *device_events;
9748 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9749 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9751 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9756 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9760 * gtk_widget_get_pointer:
9761 * @widget: a #GtkWidget
9762 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9763 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9765 * Obtains the location of the mouse pointer in widget coordinates.
9766 * Widget coordinates are a bit odd; for historical reasons, they are
9767 * defined as @widget->window coordinates for widgets that are not
9768 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9769 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9771 * Deprecated: 3.4: Use gdk_window_get_device_position() instead.
9774 gtk_widget_get_pointer (GtkWidget *widget,
9778 GtkWidgetPrivate *priv;
9780 g_return_if_fail (GTK_IS_WIDGET (widget));
9782 priv = widget->priv;
9789 if (gtk_widget_get_realized (widget))
9791 gdk_window_get_device_position (priv->window,
9792 gdk_device_manager_get_client_pointer (
9793 gdk_display_get_device_manager (
9794 gtk_widget_get_display (widget))),
9797 if (!gtk_widget_get_has_window (widget))
9800 *x -= priv->allocation.x;
9802 *y -= priv->allocation.y;
9808 * gtk_widget_is_ancestor:
9809 * @widget: a #GtkWidget
9810 * @ancestor: another #GtkWidget
9812 * Determines whether @widget is somewhere inside @ancestor, possibly with
9813 * intermediate containers.
9815 * Return value: %TRUE if @ancestor contains @widget as a child,
9816 * grandchild, great grandchild, etc.
9819 gtk_widget_is_ancestor (GtkWidget *widget,
9820 GtkWidget *ancestor)
9822 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9823 g_return_val_if_fail (ancestor != NULL, FALSE);
9827 if (widget->priv->parent == ancestor)
9829 widget = widget->priv->parent;
9835 static GQuark quark_composite_name = 0;
9838 * gtk_widget_set_composite_name:
9839 * @widget: a #GtkWidget.
9840 * @name: the name to set
9842 * Sets a widgets composite name. The widget must be
9843 * a composite child of its parent; see gtk_widget_push_composite_child().
9846 gtk_widget_set_composite_name (GtkWidget *widget,
9849 g_return_if_fail (GTK_IS_WIDGET (widget));
9850 g_return_if_fail (widget->priv->composite_child);
9851 g_return_if_fail (name != NULL);
9853 if (!quark_composite_name)
9854 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
9856 g_object_set_qdata_full (G_OBJECT (widget),
9857 quark_composite_name,
9863 * gtk_widget_get_composite_name:
9864 * @widget: a #GtkWidget
9866 * Obtains the composite name of a widget.
9868 * Returns: the composite name of @widget, or %NULL if @widget is not
9869 * a composite child. The string should be freed when it is no
9873 gtk_widget_get_composite_name (GtkWidget *widget)
9875 GtkWidgetPrivate *priv;
9877 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9879 priv = widget->priv;
9881 if (widget->priv->composite_child && priv->parent)
9882 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
9889 * gtk_widget_push_composite_child:
9891 * Makes all newly-created widgets as composite children until
9892 * the corresponding gtk_widget_pop_composite_child() call.
9894 * A composite child is a child that's an implementation detail of the
9895 * container it's inside and should not be visible to people using the
9896 * container. Composite children aren't treated differently by GTK (but
9897 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
9898 * builders might want to treat them in a different way.
9900 * Here is a simple example:
9902 * gtk_widget_push_composite_child ();
9903 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
9904 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
9905 * gtk_widget_pop_composite_child ();
9906 * gtk_widget_set_parent (scrolled_window->hscrollbar,
9907 * GTK_WIDGET (scrolled_window));
9908 * g_object_ref (scrolled_window->hscrollbar);
9912 gtk_widget_push_composite_child (void)
9914 composite_child_stack++;
9918 * gtk_widget_pop_composite_child:
9920 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
9923 gtk_widget_pop_composite_child (void)
9925 if (composite_child_stack)
9926 composite_child_stack--;
9930 gtk_widget_emit_direction_changed (GtkWidget *widget,
9931 GtkTextDirection old_dir)
9933 gtk_widget_update_pango_context (widget);
9935 if (widget->priv->context)
9936 gtk_style_context_set_direction (widget->priv->context,
9937 gtk_widget_get_direction (widget));
9939 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
9943 * gtk_widget_set_direction:
9944 * @widget: a #GtkWidget
9945 * @dir: the new direction
9947 * Sets the reading direction on a particular widget. This direction
9948 * controls the primary direction for widgets containing text,
9949 * and also the direction in which the children of a container are
9950 * packed. The ability to set the direction is present in order
9951 * so that correct localization into languages with right-to-left
9952 * reading directions can be done. Generally, applications will
9953 * let the default reading direction present, except for containers
9954 * where the containers are arranged in an order that is explicitely
9955 * visual rather than logical (such as buttons for text justification).
9957 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
9958 * set by gtk_widget_set_default_direction() will be used.
9961 gtk_widget_set_direction (GtkWidget *widget,
9962 GtkTextDirection dir)
9964 GtkTextDirection old_dir;
9966 g_return_if_fail (GTK_IS_WIDGET (widget));
9967 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
9969 old_dir = gtk_widget_get_direction (widget);
9971 widget->priv->direction = dir;
9973 if (old_dir != gtk_widget_get_direction (widget))
9974 gtk_widget_emit_direction_changed (widget, old_dir);
9978 * gtk_widget_get_direction:
9979 * @widget: a #GtkWidget
9981 * Gets the reading direction for a particular widget. See
9982 * gtk_widget_set_direction().
9984 * Return value: the reading direction for the widget.
9987 gtk_widget_get_direction (GtkWidget *widget)
9989 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
9991 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
9992 return gtk_default_direction;
9994 return widget->priv->direction;
9998 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10000 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10002 g_object_ref (widget);
10004 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10005 gtk_widget_emit_direction_changed (widget, old_dir);
10007 if (GTK_IS_CONTAINER (widget))
10008 gtk_container_forall (GTK_CONTAINER (widget),
10009 gtk_widget_set_default_direction_recurse,
10012 g_object_unref (widget);
10016 * gtk_widget_set_default_direction:
10017 * @dir: the new default direction. This cannot be
10018 * %GTK_TEXT_DIR_NONE.
10020 * Sets the default reading direction for widgets where the
10021 * direction has not been explicitly set by gtk_widget_set_direction().
10024 gtk_widget_set_default_direction (GtkTextDirection dir)
10026 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10028 if (dir != gtk_default_direction)
10030 GList *toplevels, *tmp_list;
10031 GtkTextDirection old_dir = gtk_default_direction;
10033 gtk_default_direction = dir;
10035 tmp_list = toplevels = gtk_window_list_toplevels ();
10036 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10040 gtk_widget_set_default_direction_recurse (tmp_list->data,
10041 GUINT_TO_POINTER (old_dir));
10042 g_object_unref (tmp_list->data);
10043 tmp_list = tmp_list->next;
10046 g_list_free (toplevels);
10051 * gtk_widget_get_default_direction:
10053 * Obtains the current default reading direction. See
10054 * gtk_widget_set_default_direction().
10056 * Return value: the current default direction.
10059 gtk_widget_get_default_direction (void)
10061 return gtk_default_direction;
10065 gtk_widget_dispose (GObject *object)
10067 GtkWidget *widget = GTK_WIDGET (object);
10068 GtkWidgetPrivate *priv = widget->priv;
10071 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10072 else if (gtk_widget_get_visible (widget))
10073 gtk_widget_hide (widget);
10075 priv->visible = FALSE;
10076 if (gtk_widget_get_realized (widget))
10077 gtk_widget_unrealize (widget);
10079 if (!priv->in_destruction)
10081 priv->in_destruction = TRUE;
10082 g_signal_emit (object, widget_signals[DESTROY], 0);
10083 priv->in_destruction = FALSE;
10086 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10090 gtk_widget_real_destroy (GtkWidget *object)
10092 /* gtk_object_destroy() will already hold a refcount on object */
10093 GtkWidget *widget = GTK_WIDGET (object);
10094 GtkWidgetPrivate *priv = widget->priv;
10096 /* wipe accelerator closures (keep order) */
10097 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10098 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10100 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10101 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10103 gtk_grab_remove (widget);
10106 g_object_unref (priv->style);
10107 priv->style = gtk_widget_get_default_style ();
10108 g_object_ref (priv->style);
10112 gtk_widget_finalize (GObject *object)
10114 GtkWidget *widget = GTK_WIDGET (object);
10115 GtkWidgetPrivate *priv = widget->priv;
10116 GtkWidgetAuxInfo *aux_info;
10117 GtkAccessible *accessible;
10119 gtk_grab_remove (widget);
10121 g_object_unref (priv->style);
10122 priv->style = NULL;
10124 g_free (priv->name);
10126 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10128 gtk_widget_aux_info_destroy (aux_info);
10130 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10132 g_object_unref (accessible);
10135 gtk_widget_path_free (priv->path);
10138 g_object_unref (priv->context);
10140 _gtk_widget_free_cached_sizes (widget);
10142 if (g_object_is_floating (object))
10143 g_warning ("A floating object was finalized. This means that someone\n"
10144 "called g_object_unref() on an object that had only a floating\n"
10145 "reference; the initial floating reference is not owned by anyone\n"
10146 "and must be removed with g_object_ref_sink().");
10148 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10151 /*****************************************
10152 * gtk_widget_real_map:
10157 *****************************************/
10160 gtk_widget_real_map (GtkWidget *widget)
10162 GtkWidgetPrivate *priv = widget->priv;
10164 g_assert (gtk_widget_get_realized (widget));
10166 if (!gtk_widget_get_mapped (widget))
10168 gtk_widget_set_mapped (widget, TRUE);
10170 if (gtk_widget_get_has_window (widget))
10171 gdk_window_show (priv->window);
10175 /*****************************************
10176 * gtk_widget_real_unmap:
10181 *****************************************/
10184 gtk_widget_real_unmap (GtkWidget *widget)
10186 GtkWidgetPrivate *priv = widget->priv;
10188 if (gtk_widget_get_mapped (widget))
10190 gtk_widget_set_mapped (widget, FALSE);
10192 if (gtk_widget_get_has_window (widget))
10193 gdk_window_hide (priv->window);
10197 /*****************************************
10198 * gtk_widget_real_realize:
10203 *****************************************/
10206 gtk_widget_real_realize (GtkWidget *widget)
10208 GtkWidgetPrivate *priv = widget->priv;
10210 g_assert (!gtk_widget_get_has_window (widget));
10212 gtk_widget_set_realized (widget, TRUE);
10215 priv->window = gtk_widget_get_parent_window (widget);
10216 g_object_ref (priv->window);
10220 /*****************************************
10221 * gtk_widget_real_unrealize:
10226 *****************************************/
10229 gtk_widget_real_unrealize (GtkWidget *widget)
10231 GtkWidgetPrivate *priv = widget->priv;
10233 g_assert (!widget->priv->mapped);
10235 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10238 /* We must do unrealize child widget BEFORE container widget.
10239 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10240 * So, unrealizing container widget bofore its children causes the problem
10241 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10244 if (GTK_IS_CONTAINER (widget))
10245 gtk_container_forall (GTK_CONTAINER (widget),
10246 (GtkCallback) gtk_widget_unrealize,
10249 if (gtk_widget_get_has_window (widget))
10251 gdk_window_set_user_data (priv->window, NULL);
10252 gdk_window_destroy (priv->window);
10253 priv->window = NULL;
10257 g_object_unref (priv->window);
10258 priv->window = NULL;
10261 gtk_selection_remove_all (widget);
10263 gtk_widget_set_realized (widget, FALSE);
10267 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10268 GtkOrientation orientation,
10269 gint *minimum_size,
10270 gint *natural_size)
10272 const GtkWidgetAuxInfo *aux_info;
10274 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10276 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10277 aux_info->width > 0)
10279 *minimum_size = MAX (*minimum_size, aux_info->width);
10281 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10282 aux_info->height > 0)
10284 *minimum_size = MAX (*minimum_size, aux_info->height);
10287 /* Fix it if set_size_request made natural size smaller than min size.
10288 * This would also silently fix broken widgets, but we warn about them
10289 * in gtksizerequest.c when calling their size request vfuncs.
10291 *natural_size = MAX (*natural_size, *minimum_size);
10293 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10295 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10296 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10300 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10301 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10306 * _gtk_widget_peek_request_cache:
10308 * Returns the address of the widget's request cache (strictly for
10309 * internal use in gtksizerequest.c)
10311 * Return value: the address of @widget's size request cache.
10314 _gtk_widget_peek_request_cache (GtkWidget *widget)
10316 /* Don't bother slowing things down with the return_if_fail guards here */
10317 return &widget->priv->requests;
10321 * _gtk_widget_set_device_window:
10322 * @widget: a #GtkWidget
10323 * @device: a #GdkDevice
10324 * @window: the new device window
10326 * Sets pointer window for @widget and @device.
10327 * Does not ref @window.
10330 _gtk_widget_set_device_window (GtkWidget *widget,
10334 GHashTable *device_window;
10336 g_return_if_fail (GTK_IS_WIDGET (widget));
10337 g_return_if_fail (GDK_IS_DEVICE (device));
10338 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10340 if (!gtk_widget_get_mapped (widget))
10343 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10345 if (!device_window && window)
10347 device_window = g_hash_table_new (NULL, NULL);
10348 g_object_set_qdata_full (G_OBJECT (widget),
10349 quark_pointer_window,
10351 (GDestroyNotify) g_hash_table_destroy);
10355 g_hash_table_insert (device_window, device, window);
10356 else if (device_window)
10358 g_hash_table_remove (device_window, device);
10360 if (g_hash_table_size (device_window) == 0)
10361 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10366 * _gtk_widget_get_device_window:
10367 * @widget: a #GtkWidget
10368 * @device: a #GdkDevice
10370 * Return value: the device window set on @widget, or %NULL
10373 _gtk_widget_get_device_window (GtkWidget *widget,
10376 GHashTable *device_window;
10378 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10379 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10381 if (!gtk_widget_get_mapped (widget))
10384 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10386 if (!device_window)
10389 return g_hash_table_lookup (device_window, device);
10393 * _gtk_widget_list_devices:
10394 * @widget: a #GtkWidget
10396 * Returns the list of #GdkDevices that is currently on top
10397 * of any window belonging to @widget.
10398 * Free the list with g_list_free(), the elements are owned
10399 * by GTK+ and must not be freed.
10402 _gtk_widget_list_devices (GtkWidget *widget)
10404 GHashTableIter iter;
10405 GHashTable *device_window;
10406 GList *devices = NULL;
10407 gpointer key, value;
10409 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10411 if (!gtk_widget_get_mapped (widget))
10414 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10416 if (G_UNLIKELY (!device_window))
10419 g_hash_table_iter_init (&iter, device_window);
10421 while (g_hash_table_iter_next (&iter, &key, &value))
10422 devices = g_list_prepend (devices, key);
10428 synth_crossing (GtkWidget *widget,
10432 GdkCrossingMode mode,
10433 GdkNotifyType detail)
10437 event = gdk_event_new (type);
10439 event->crossing.window = g_object_ref (window);
10440 event->crossing.send_event = TRUE;
10441 event->crossing.subwindow = g_object_ref (window);
10442 event->crossing.time = GDK_CURRENT_TIME;
10443 event->crossing.x = event->crossing.y = 0;
10444 event->crossing.x_root = event->crossing.y_root = 0;
10445 event->crossing.mode = mode;
10446 event->crossing.detail = detail;
10447 event->crossing.focus = FALSE;
10448 event->crossing.state = 0;
10449 gdk_event_set_device (event, device);
10452 widget = gtk_get_event_widget (event);
10455 gtk_widget_event_internal (widget, event);
10457 gdk_event_free (event);
10461 * _gtk_widget_synthesize_crossing:
10462 * @from: the #GtkWidget the virtual pointer is leaving.
10463 * @to: the #GtkWidget the virtual pointer is moving to.
10464 * @mode: the #GdkCrossingMode to place on the synthesized events.
10466 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10468 * The real pointer window is the window that most recently received an enter notify
10469 * event. Windows that don't select for crossing events can't become the real
10470 * poiner window. The real pointer widget that owns the real pointer window. The
10471 * effective pointer window is the same as the real pointer window unless the real
10472 * pointer widget is either insensitive or there is a grab on a widget that is not
10473 * an ancestor of the real pointer widget (in which case the effective pointer
10474 * window should be the root window).
10476 * When the effective pointer window is the same as the real poiner window, we
10477 * receive crossing events from the windowing system. When the effective pointer
10478 * window changes to become different from the real pointer window we synthesize
10479 * crossing events, attempting to follow X protocol rules:
10481 * When the root window becomes the effective pointer window:
10482 * - leave notify on real pointer window, detail Ancestor
10483 * - leave notify on all of its ancestors, detail Virtual
10484 * - enter notify on root window, detail Inferior
10486 * When the root window ceases to be the effective pointer window:
10487 * - leave notify on root window, detail Inferior
10488 * - enter notify on all ancestors of real pointer window, detail Virtual
10489 * - enter notify on real pointer window, detail Ancestor
10492 _gtk_widget_synthesize_crossing (GtkWidget *from,
10495 GdkCrossingMode mode)
10497 GdkWindow *from_window = NULL, *to_window = NULL;
10499 g_return_if_fail (from != NULL || to != NULL);
10503 from_window = _gtk_widget_get_device_window (from, device);
10506 from_window = from->priv->window;
10511 to_window = _gtk_widget_get_device_window (to, device);
10514 to_window = to->priv->window;
10517 if (from_window == NULL && to_window == NULL)
10519 else if (from_window != NULL && to_window == NULL)
10521 GList *from_ancestors = NULL, *list;
10522 GdkWindow *from_ancestor = from_window;
10524 while (from_ancestor != NULL)
10526 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10527 if (from_ancestor == NULL)
10529 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10532 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10533 device, mode, GDK_NOTIFY_ANCESTOR);
10534 for (list = g_list_last (from_ancestors); list; list = list->prev)
10536 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10537 device, mode, GDK_NOTIFY_VIRTUAL);
10540 /* XXX: enter/inferior on root window? */
10542 g_list_free (from_ancestors);
10544 else if (from_window == NULL && to_window != NULL)
10546 GList *to_ancestors = NULL, *list;
10547 GdkWindow *to_ancestor = to_window;
10549 while (to_ancestor != NULL)
10551 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10552 if (to_ancestor == NULL)
10554 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10557 /* XXX: leave/inferior on root window? */
10559 for (list = to_ancestors; list; list = list->next)
10561 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10562 device, mode, GDK_NOTIFY_VIRTUAL);
10564 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10565 device, mode, GDK_NOTIFY_ANCESTOR);
10567 g_list_free (to_ancestors);
10569 else if (from_window == to_window)
10573 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10574 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10576 while (from_ancestor != NULL || to_ancestor != NULL)
10578 if (from_ancestor != NULL)
10580 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10581 if (from_ancestor == to_window)
10584 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10586 if (to_ancestor != NULL)
10588 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10589 if (to_ancestor == from_window)
10592 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10595 if (to_ancestor == from_window)
10597 if (mode != GDK_CROSSING_GTK_UNGRAB)
10598 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10599 device, mode, GDK_NOTIFY_INFERIOR);
10600 for (list = to_ancestors; list; list = list->next)
10601 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10602 device, mode, GDK_NOTIFY_VIRTUAL);
10603 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10604 device, mode, GDK_NOTIFY_ANCESTOR);
10606 else if (from_ancestor == to_window)
10608 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10609 device, mode, GDK_NOTIFY_ANCESTOR);
10610 for (list = g_list_last (from_ancestors); list; list = list->prev)
10612 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10613 device, mode, GDK_NOTIFY_VIRTUAL);
10615 if (mode != GDK_CROSSING_GTK_GRAB)
10616 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10617 device, mode, GDK_NOTIFY_INFERIOR);
10621 while (from_ancestors != NULL && to_ancestors != NULL
10622 && from_ancestors->data == to_ancestors->data)
10624 from_ancestors = g_list_delete_link (from_ancestors,
10626 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10629 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10630 device, mode, GDK_NOTIFY_NONLINEAR);
10632 for (list = g_list_last (from_ancestors); list; list = list->prev)
10634 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10635 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10637 for (list = to_ancestors; list; list = list->next)
10639 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10640 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10642 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10643 device, mode, GDK_NOTIFY_NONLINEAR);
10645 g_list_free (from_ancestors);
10646 g_list_free (to_ancestors);
10651 gtk_widget_propagate_state (GtkWidget *widget,
10652 GtkStateData *data)
10654 GtkWidgetPrivate *priv = widget->priv;
10655 GtkStateFlags new_flags, old_flags = priv->state_flags;
10656 GtkStateType old_state;
10658 old_state = gtk_widget_get_state (widget);
10660 switch (data->operation)
10662 case STATE_CHANGE_REPLACE:
10663 priv->state_flags = data->flags;
10665 case STATE_CHANGE_SET:
10666 priv->state_flags |= data->flags;
10668 case STATE_CHANGE_UNSET:
10669 priv->state_flags &= ~(data->flags);
10673 /* make insensitivity unoverridable */
10674 if (!priv->sensitive)
10675 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
10677 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10681 window = gtk_widget_get_toplevel (widget);
10683 if (window && gtk_widget_is_toplevel (window))
10684 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10687 new_flags = priv->state_flags;
10689 if (old_flags != new_flags)
10691 g_object_ref (widget);
10693 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10694 gtk_grab_remove (widget);
10696 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10697 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
10699 if (!priv->shadowed)
10701 GList *event_windows = NULL;
10702 GList *devices, *d;
10704 devices = _gtk_widget_list_devices (widget);
10706 for (d = devices; d; d = d->next)
10712 window = _gtk_widget_get_device_window (widget, device);
10714 /* Do not propagate more than once to the
10715 * same window if non-multidevice aware.
10717 if (!gdk_window_get_support_multidevice (window) &&
10718 g_list_find (event_windows, window))
10721 if (!gtk_widget_is_sensitive (widget))
10722 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10723 GDK_CROSSING_STATE_CHANGED);
10724 else if (old_flags & GTK_STATE_FLAG_INSENSITIVE)
10725 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10726 GDK_CROSSING_STATE_CHANGED);
10728 event_windows = g_list_prepend (event_windows, window);
10731 g_list_free (event_windows);
10732 g_list_free (devices);
10735 if (GTK_IS_CONTAINER (widget))
10737 GtkStateData child_data = *data;
10739 /* Make sure to only propate the right states further */
10740 child_data.flags &= GTK_STATE_FLAGS_DO_PROPAGATE;
10742 if (child_data.use_forall)
10743 gtk_container_forall (GTK_CONTAINER (widget),
10744 (GtkCallback) gtk_widget_propagate_state,
10747 gtk_container_foreach (GTK_CONTAINER (widget),
10748 (GtkCallback) gtk_widget_propagate_state,
10752 /* Trigger state change transitions for the widget */
10753 if (priv->context &&
10754 gtk_widget_get_mapped (widget))
10756 gint diff, flag = 1;
10758 diff = old_flags ^ new_flags;
10762 if ((diff & flag) != 0)
10766 target = ((new_flags & flag) != 0);
10767 _gtk_widget_notify_state_change (widget, flag, target);
10776 g_object_unref (widget);
10780 static const GtkWidgetAuxInfo default_aux_info = {
10788 * gtk_widget_get_aux_info:
10789 * @widget: a #GtkWidget
10790 * @create: if %TRUE, create the structure if it doesn't exist
10792 * Get the #GtkWidgetAuxInfo structure for the widget.
10794 * Return value: the #GtkAuxInfo structure for the widget, or
10795 * %NULL if @create is %FALSE and one doesn't already exist.
10797 static GtkWidgetAuxInfo *
10798 gtk_widget_get_aux_info (GtkWidget *widget,
10801 GtkWidgetAuxInfo *aux_info;
10803 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
10804 if (!aux_info && create)
10806 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
10808 *aux_info = default_aux_info;
10810 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
10816 static const GtkWidgetAuxInfo*
10817 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
10819 GtkWidgetAuxInfo *aux_info;
10821 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10822 if (aux_info == NULL)
10824 return &default_aux_info;
10832 /*****************************************
10833 * gtk_widget_aux_info_destroy:
10838 *****************************************/
10841 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
10843 g_slice_free (GtkWidgetAuxInfo, aux_info);
10847 * gtk_widget_shape_combine_region:
10848 * @widget: a #GtkWidget
10849 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10851 * Sets a shape for this widget's GDK window. This allows for
10852 * transparent windows etc., see gdk_window_shape_combine_region()
10853 * for more information.
10858 gtk_widget_shape_combine_region (GtkWidget *widget,
10859 cairo_region_t *region)
10861 GtkWidgetPrivate *priv;
10863 g_return_if_fail (GTK_IS_WIDGET (widget));
10864 /* set_shape doesn't work on widgets without gdk window */
10865 g_return_if_fail (gtk_widget_get_has_window (widget));
10867 priv = widget->priv;
10869 if (region == NULL)
10871 priv->has_shape_mask = FALSE;
10874 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
10876 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
10880 priv->has_shape_mask = TRUE;
10882 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
10883 cairo_region_copy (region),
10884 (GDestroyNotify) cairo_region_destroy);
10886 /* set shape if widget has a gdk window already.
10887 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10890 gdk_window_shape_combine_region (priv->window, region, 0, 0);
10895 * gtk_widget_input_shape_combine_region:
10896 * @widget: a #GtkWidget
10897 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10899 * Sets an input shape for this widget's GDK window. This allows for
10900 * windows which react to mouse click in a nonrectangular region, see
10901 * gdk_window_input_shape_combine_region() for more information.
10906 gtk_widget_input_shape_combine_region (GtkWidget *widget,
10907 cairo_region_t *region)
10909 GtkWidgetPrivate *priv;
10911 g_return_if_fail (GTK_IS_WIDGET (widget));
10912 /* set_shape doesn't work on widgets without gdk window */
10913 g_return_if_fail (gtk_widget_get_has_window (widget));
10915 priv = widget->priv;
10917 if (region == NULL)
10920 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
10922 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
10926 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
10927 cairo_region_copy (region),
10928 (GDestroyNotify) cairo_region_destroy);
10930 /* set shape if widget has a gdk window already.
10931 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10934 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
10939 /* style properties
10943 * gtk_widget_class_install_style_property_parser: (skip)
10944 * @klass: a #GtkWidgetClass
10945 * @pspec: the #GParamSpec for the style property
10946 * @parser: the parser for the style property
10948 * Installs a style property on a widget class.
10951 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
10953 GtkRcPropertyParser parser)
10955 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10956 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10957 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
10958 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
10960 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
10962 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
10963 G_OBJECT_CLASS_NAME (klass),
10968 g_param_spec_ref_sink (pspec);
10969 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
10970 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
10974 * gtk_widget_class_install_style_property:
10975 * @klass: a #GtkWidgetClass
10976 * @pspec: the #GParamSpec for the property
10978 * Installs a style property on a widget class. The parser for the
10979 * style property is determined by the value type of @pspec.
10982 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
10985 GtkRcPropertyParser parser;
10987 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10988 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10990 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
10992 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
10996 * gtk_widget_class_find_style_property:
10997 * @klass: a #GtkWidgetClass
10998 * @property_name: the name of the style property to find
11000 * Finds a style property of a widget class by name.
11002 * Returns: (transfer none): the #GParamSpec of the style property or
11003 * %NULL if @class has no style property with that name.
11008 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11009 const gchar *property_name)
11011 g_return_val_if_fail (property_name != NULL, NULL);
11013 return g_param_spec_pool_lookup (style_property_spec_pool,
11015 G_OBJECT_CLASS_TYPE (klass),
11020 * gtk_widget_class_list_style_properties:
11021 * @klass: a #GtkWidgetClass
11022 * @n_properties: location to return the number of style properties found
11024 * Returns all style properties of a widget class.
11026 * Returns: (array length=n_properties) (transfer container): a
11027 * newly allocated array of #GParamSpec*. The array must be
11028 * freed with g_free().
11033 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11034 guint *n_properties)
11036 GParamSpec **pspecs;
11039 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11040 G_OBJECT_CLASS_TYPE (klass),
11049 * gtk_widget_style_get_property:
11050 * @widget: a #GtkWidget
11051 * @property_name: the name of a style property
11052 * @value: location to return the property value
11054 * Gets the value of a style property of @widget.
11057 gtk_widget_style_get_property (GtkWidget *widget,
11058 const gchar *property_name,
11063 g_return_if_fail (GTK_IS_WIDGET (widget));
11064 g_return_if_fail (property_name != NULL);
11065 g_return_if_fail (G_IS_VALUE (value));
11067 g_object_ref (widget);
11068 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11070 G_OBJECT_TYPE (widget),
11073 g_warning ("%s: widget class `%s' has no property named `%s'",
11075 G_OBJECT_TYPE_NAME (widget),
11079 GtkStyleContext *context;
11080 const GValue *peek_value;
11081 GtkStateFlags state;
11083 context = gtk_widget_get_style_context (widget);
11084 state = gtk_widget_get_state_flags (widget);
11086 peek_value = _gtk_style_context_peek_style_property (context,
11087 G_OBJECT_TYPE (widget),
11090 /* auto-conversion of the caller's value type
11092 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11093 g_value_copy (peek_value, value);
11094 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11095 g_value_transform (peek_value, value);
11097 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11099 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11100 G_VALUE_TYPE_NAME (value));
11102 g_object_unref (widget);
11106 * gtk_widget_style_get_valist:
11107 * @widget: a #GtkWidget
11108 * @first_property_name: the name of the first property to get
11109 * @var_args: a <type>va_list</type> of pairs of property names and
11110 * locations to return the property values, starting with the location
11111 * for @first_property_name.
11113 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11117 gtk_widget_style_get_valist (GtkWidget *widget,
11118 const gchar *first_property_name,
11121 GtkStyleContext *context;
11122 GtkStateFlags state;
11125 g_return_if_fail (GTK_IS_WIDGET (widget));
11127 g_object_ref (widget);
11128 context = gtk_widget_get_style_context (widget);
11129 state = gtk_widget_get_state_flags (widget);
11131 name = first_property_name;
11134 const GValue *peek_value;
11138 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11140 G_OBJECT_TYPE (widget),
11144 g_warning ("%s: widget class `%s' has no property named `%s'",
11146 G_OBJECT_TYPE_NAME (widget),
11150 /* style pspecs are always readable so we can spare that check here */
11152 peek_value = _gtk_style_context_peek_style_property (context,
11153 G_OBJECT_TYPE (widget),
11156 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11159 g_warning ("%s: %s", G_STRLOC, error);
11164 name = va_arg (var_args, gchar*);
11167 g_object_unref (widget);
11171 * gtk_widget_style_get:
11172 * @widget: a #GtkWidget
11173 * @first_property_name: the name of the first property to get
11174 * @...: pairs of property names and locations to return the
11175 * property values, starting with the location for
11176 * @first_property_name, terminated by %NULL.
11178 * Gets the values of a multiple style properties of @widget.
11181 gtk_widget_style_get (GtkWidget *widget,
11182 const gchar *first_property_name,
11187 g_return_if_fail (GTK_IS_WIDGET (widget));
11189 va_start (var_args, first_property_name);
11190 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11195 * gtk_requisition_new:
11197 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11199 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11200 * be freed with gtk_requisition_free().
11205 gtk_requisition_new (void)
11207 return g_slice_new0 (GtkRequisition);
11211 * gtk_requisition_copy:
11212 * @requisition: a #GtkRequisition
11214 * Copies a #GtkRequisition.
11216 * Returns: a copy of @requisition
11219 gtk_requisition_copy (const GtkRequisition *requisition)
11221 return g_slice_dup (GtkRequisition, requisition);
11225 * gtk_requisition_free:
11226 * @requisition: a #GtkRequisition
11228 * Frees a #GtkRequisition.
11231 gtk_requisition_free (GtkRequisition *requisition)
11233 g_slice_free (GtkRequisition, requisition);
11236 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11237 gtk_requisition_copy,
11238 gtk_requisition_free)
11241 * gtk_widget_class_set_accessible_type:
11242 * @widget_class: class to set the accessible type for
11243 * @type: The object type that implements the accessible for @widget_class
11245 * Sets the type to be used for creating accessibles for widgets of
11246 * @widget_class. The given @type must be a subtype of the type used for
11247 * accessibles of the parent class.
11249 * This function should only be called from class init functions of widgets.
11254 gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class,
11257 GtkWidgetClassPrivate *priv;
11259 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11260 g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type));
11262 priv = widget_class->priv;
11264 priv->accessible_type = type;
11265 /* reset this - honoring the type's role is better. */
11266 priv->accessible_role = ATK_ROLE_INVALID;
11270 * gtk_widget_class_set_accessible_role:
11271 * @widget_class: class to set the accessible role for
11272 * @role: The role to use for accessibles created for @widget_class
11274 * Sets the default #AtkRole to be set on accessibles created for
11275 * widgets of @widget_class. Accessibles may decide to not honor this
11276 * setting if their role reporting is more refined. Calls to
11277 * gtk_widget_class_set_accessible_type() will reset this value.
11279 * In cases where you want more fine-grained control over the role of
11280 * accessibles created for @widget_class, you should provide your own
11281 * accessible type and use gtk_widget_class_set_accessible_type()
11284 * If @role is #ATK_ROLE_INVALID, the default role will not be changed
11285 * and the accessible's default role will be used instead.
11287 * This function should only be called from class init functions of widgets.
11292 gtk_widget_class_set_accessible_role (GtkWidgetClass *widget_class,
11295 GtkWidgetClassPrivate *priv;
11297 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11299 priv = widget_class->priv;
11301 priv->accessible_role = role;
11305 * _gtk_widget_peek_accessible:
11306 * @widget: a #GtkWidget
11308 * Gets the accessible for @widget, if it has been created yet.
11309 * Otherwise, this function returns %NULL. If the @widget's implementation
11310 * does not use the default way to create accessibles, %NULL will always be
11313 * Returns: the accessible for @widget or %NULL if none has been
11317 _gtk_widget_peek_accessible (GtkWidget *widget)
11319 return g_object_get_qdata (G_OBJECT (widget),
11320 quark_accessible_object);
11324 * gtk_widget_get_accessible:
11325 * @widget: a #GtkWidget
11327 * Returns the accessible object that describes the widget to an
11328 * assistive technology.
11330 * If accessibility support is not available, this #AtkObject
11331 * instance may be a no-op. Likewise, if no class-specific #AtkObject
11332 * implementation is available for the widget instance in question,
11333 * it will inherit an #AtkObject implementation from the first ancestor
11334 * class for which such an implementation is defined.
11336 * The documentation of the
11337 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
11338 * library contains more information about accessible objects and their uses.
11340 * Returns: (transfer none): the #AtkObject associated with @widget
11343 gtk_widget_get_accessible (GtkWidget *widget)
11345 GtkWidgetClass *klass;
11347 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11349 klass = GTK_WIDGET_GET_CLASS (widget);
11351 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11353 return klass->get_accessible (widget);
11357 gtk_widget_real_get_accessible (GtkWidget *widget)
11359 AtkObject* accessible;
11361 accessible = g_object_get_qdata (G_OBJECT (widget),
11362 quark_accessible_object);
11365 GtkWidgetClass *widget_class;
11366 GtkWidgetClassPrivate *priv;
11367 AtkObjectFactory *factory;
11368 AtkRegistry *default_registry;
11370 widget_class = GTK_WIDGET_GET_CLASS (widget);
11371 priv = widget_class->priv;
11373 if (priv->accessible_type == GTK_TYPE_ACCESSIBLE)
11375 default_registry = atk_get_default_registry ();
11376 factory = atk_registry_get_factory (default_registry,
11377 G_TYPE_FROM_INSTANCE (widget));
11379 atk_object_factory_create_accessible (factory,
11380 G_OBJECT (widget));
11382 if (priv->accessible_role != ATK_ROLE_INVALID)
11383 atk_object_set_role (accessible, priv->accessible_role);
11385 g_object_set_qdata (G_OBJECT (widget),
11386 quark_accessible_object,
11391 accessible = g_object_new (priv->accessible_type, NULL);
11392 if (priv->accessible_role != ATK_ROLE_INVALID)
11393 atk_object_set_role (accessible, priv->accessible_role);
11395 g_object_set_qdata (G_OBJECT (widget),
11396 quark_accessible_object,
11399 atk_object_initialize (accessible, widget);
11401 /* Set the role again, since we don't want a role set
11402 * in some parent initialize() function to override
11405 if (priv->accessible_role != ATK_ROLE_INVALID)
11406 atk_object_set_role (accessible, priv->accessible_role);
11413 * Initialize a AtkImplementorIface instance's virtual pointers as
11414 * appropriate to this implementor's class (GtkWidget).
11417 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11419 iface->ref_accessible = gtk_widget_ref_accessible;
11423 gtk_widget_ref_accessible (AtkImplementor *implementor)
11425 AtkObject *accessible;
11427 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11429 g_object_ref (accessible);
11434 * Expand flag management
11438 gtk_widget_update_computed_expand (GtkWidget *widget)
11440 GtkWidgetPrivate *priv;
11442 priv = widget->priv;
11444 if (priv->need_compute_expand)
11448 if (priv->hexpand_set)
11453 if (priv->vexpand_set)
11458 /* we don't need to use compute_expand if both expands are
11459 * forced by the app
11461 if (!(priv->hexpand_set && priv->vexpand_set))
11463 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11467 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11468 priv->hexpand_set ? &ignored : &h,
11469 priv->vexpand_set ? &ignored : &v);
11473 priv->need_compute_expand = FALSE;
11474 priv->computed_hexpand = h != FALSE;
11475 priv->computed_vexpand = v != FALSE;
11480 * gtk_widget_queue_compute_expand:
11481 * @widget: a #GtkWidget
11483 * Mark @widget as needing to recompute its expand flags. Call
11484 * this function when setting legacy expand child properties
11485 * on the child of a container.
11487 * See gtk_widget_compute_expand().
11490 gtk_widget_queue_compute_expand (GtkWidget *widget)
11493 gboolean changed_anything;
11495 if (widget->priv->need_compute_expand)
11498 changed_anything = FALSE;
11500 while (parent != NULL)
11502 if (!parent->priv->need_compute_expand)
11504 parent->priv->need_compute_expand = TRUE;
11505 changed_anything = TRUE;
11508 /* Note: if we had an invariant that "if a child needs to
11509 * compute expand, its parents also do" then we could stop going
11510 * up when we got to a parent that already needed to
11511 * compute. However, in general we compute expand lazily (as
11512 * soon as we see something in a subtree that is expand, we know
11513 * we're expanding) and so this invariant does not hold and we
11514 * have to always walk all the way up in case some ancestor
11515 * is not currently need_compute_expand.
11518 parent = parent->priv->parent;
11521 /* recomputing expand always requires
11522 * a relayout as well
11524 if (changed_anything)
11525 gtk_widget_queue_resize (widget);
11529 * gtk_widget_compute_expand:
11530 * @widget: the widget
11531 * @orientation: expand direction
11533 * Computes whether a container should give this widget extra space
11534 * when possible. Containers should check this, rather than
11535 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11537 * This function already checks whether the widget is visible, so
11538 * visibility does not need to be checked separately. Non-visible
11539 * widgets are not expanded.
11541 * The computed expand value uses either the expand setting explicitly
11542 * set on the widget itself, or, if none has been explicitly set,
11543 * the widget may expand if some of its children do.
11545 * Return value: whether widget tree rooted here should be expanded
11548 gtk_widget_compute_expand (GtkWidget *widget,
11549 GtkOrientation orientation)
11551 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11553 /* We never make a widget expand if not even showing. */
11554 if (!gtk_widget_get_visible (widget))
11557 gtk_widget_update_computed_expand (widget);
11559 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11561 return widget->priv->computed_hexpand;
11565 return widget->priv->computed_vexpand;
11570 gtk_widget_set_expand (GtkWidget *widget,
11571 GtkOrientation orientation,
11574 const char *expand_prop;
11575 const char *expand_set_prop;
11577 GtkWidgetPrivate *priv;
11579 g_return_if_fail (GTK_IS_WIDGET (widget));
11581 priv = widget->priv;
11583 expand = expand != FALSE;
11585 was_both = priv->hexpand && priv->vexpand;
11587 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11589 if (priv->hexpand_set &&
11590 priv->hexpand == expand)
11593 priv->hexpand_set = TRUE;
11594 priv->hexpand = expand;
11596 expand_prop = "hexpand";
11597 expand_set_prop = "hexpand-set";
11601 if (priv->vexpand_set &&
11602 priv->vexpand == expand)
11605 priv->vexpand_set = TRUE;
11606 priv->vexpand = expand;
11608 expand_prop = "vexpand";
11609 expand_set_prop = "vexpand-set";
11612 gtk_widget_queue_compute_expand (widget);
11614 g_object_freeze_notify (G_OBJECT (widget));
11615 g_object_notify (G_OBJECT (widget), expand_prop);
11616 g_object_notify (G_OBJECT (widget), expand_set_prop);
11617 if (was_both != (priv->hexpand && priv->vexpand))
11618 g_object_notify (G_OBJECT (widget), "expand");
11619 g_object_thaw_notify (G_OBJECT (widget));
11623 gtk_widget_set_expand_set (GtkWidget *widget,
11624 GtkOrientation orientation,
11627 GtkWidgetPrivate *priv;
11630 priv = widget->priv;
11632 set = set != FALSE;
11634 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11636 if (set == priv->hexpand_set)
11639 priv->hexpand_set = set;
11640 prop = "hexpand-set";
11644 if (set == priv->vexpand_set)
11647 priv->vexpand_set = set;
11648 prop = "vexpand-set";
11651 gtk_widget_queue_compute_expand (widget);
11653 g_object_notify (G_OBJECT (widget), prop);
11657 * gtk_widget_get_hexpand:
11658 * @widget: the widget
11660 * Gets whether the widget would like any available extra horizontal
11661 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11662 * generally receive the extra space. For example, a list or
11663 * scrollable area or document in your window would often be set to
11666 * Containers should use gtk_widget_compute_expand() rather than
11667 * this function, to see whether a widget, or any of its children,
11668 * has the expand flag set. If any child of a widget wants to
11669 * expand, the parent may ask to expand also.
11671 * This function only looks at the widget's own hexpand flag, rather
11672 * than computing whether the entire widget tree rooted at this widget
11675 * Return value: whether hexpand flag is set
11678 gtk_widget_get_hexpand (GtkWidget *widget)
11680 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11682 return widget->priv->hexpand;
11686 * gtk_widget_set_hexpand:
11687 * @widget: the widget
11688 * @expand: whether to expand
11690 * Sets whether the widget would like any available extra horizontal
11691 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11692 * generally receive the extra space. For example, a list or
11693 * scrollable area or document in your window would often be set to
11696 * Call this function to set the expand flag if you would like your
11697 * widget to become larger horizontally when the window has extra
11700 * By default, widgets automatically expand if any of their children
11701 * want to expand. (To see if a widget will automatically expand given
11702 * its current children and state, call gtk_widget_compute_expand(). A
11703 * container can decide how the expandability of children affects the
11704 * expansion of the container by overriding the compute_expand virtual
11705 * method on #GtkWidget.).
11707 * Setting hexpand explicitly with this function will override the
11708 * automatic expand behavior.
11710 * This function forces the widget to expand or not to expand,
11711 * regardless of children. The override occurs because
11712 * gtk_widget_set_hexpand() sets the hexpand-set property (see
11713 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
11714 * value to be used, rather than looking at children and widget state.
11717 gtk_widget_set_hexpand (GtkWidget *widget,
11720 g_return_if_fail (GTK_IS_WIDGET (widget));
11722 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
11726 * gtk_widget_get_hexpand_set:
11727 * @widget: the widget
11729 * Gets whether gtk_widget_set_hexpand() has been used to
11730 * explicitly set the expand flag on this widget.
11732 * If hexpand is set, then it overrides any computed
11733 * expand value based on child widgets. If hexpand is not
11734 * set, then the expand value depends on whether any
11735 * children of the widget would like to expand.
11737 * There are few reasons to use this function, but it's here
11738 * for completeness and consistency.
11740 * Return value: whether hexpand has been explicitly set
11743 gtk_widget_get_hexpand_set (GtkWidget *widget)
11745 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11747 return widget->priv->hexpand_set;
11751 * gtk_widget_set_hexpand_set:
11752 * @widget: the widget
11753 * @set: value for hexpand-set property
11755 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
11758 * The hexpand-set property will be set automatically when you call
11759 * gtk_widget_set_hexpand() to set hexpand, so the most likely
11760 * reason to use this function would be to unset an explicit expand
11763 * If hexpand is set, then it overrides any computed
11764 * expand value based on child widgets. If hexpand is not
11765 * set, then the expand value depends on whether any
11766 * children of the widget would like to expand.
11768 * There are few reasons to use this function, but it's here
11769 * for completeness and consistency.
11772 gtk_widget_set_hexpand_set (GtkWidget *widget,
11775 g_return_if_fail (GTK_IS_WIDGET (widget));
11777 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
11782 * gtk_widget_get_vexpand:
11783 * @widget: the widget
11785 * Gets whether the widget would like any available extra vertical
11788 * See gtk_widget_get_hexpand() for more detail.
11790 * Return value: whether vexpand flag is set
11793 gtk_widget_get_vexpand (GtkWidget *widget)
11795 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11797 return widget->priv->vexpand;
11801 * gtk_widget_set_vexpand:
11802 * @widget: the widget
11803 * @expand: whether to expand
11805 * Sets whether the widget would like any available extra vertical
11808 * See gtk_widget_set_hexpand() for more detail.
11811 gtk_widget_set_vexpand (GtkWidget *widget,
11814 g_return_if_fail (GTK_IS_WIDGET (widget));
11816 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
11820 * gtk_widget_get_vexpand_set:
11821 * @widget: the widget
11823 * Gets whether gtk_widget_set_vexpand() has been used to
11824 * explicitly set the expand flag on this widget.
11826 * See gtk_widget_get_hexpand_set() for more detail.
11828 * Return value: whether vexpand has been explicitly set
11831 gtk_widget_get_vexpand_set (GtkWidget *widget)
11833 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11835 return widget->priv->vexpand_set;
11839 * gtk_widget_set_vexpand_set:
11840 * @widget: the widget
11841 * @set: value for vexpand-set property
11843 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
11846 * See gtk_widget_set_hexpand_set() for more detail.
11849 gtk_widget_set_vexpand_set (GtkWidget *widget,
11852 g_return_if_fail (GTK_IS_WIDGET (widget));
11854 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
11858 * GtkBuildable implementation
11860 static GQuark quark_builder_has_default = 0;
11861 static GQuark quark_builder_has_focus = 0;
11862 static GQuark quark_builder_atk_relations = 0;
11863 static GQuark quark_builder_set_name = 0;
11866 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
11868 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
11869 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
11870 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
11871 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
11873 iface->set_name = gtk_widget_buildable_set_name;
11874 iface->get_name = gtk_widget_buildable_get_name;
11875 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
11876 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
11877 iface->parser_finished = gtk_widget_buildable_parser_finished;
11878 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
11879 iface->custom_finished = gtk_widget_buildable_custom_finished;
11883 gtk_widget_buildable_set_name (GtkBuildable *buildable,
11886 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
11887 g_strdup (name), g_free);
11890 static const gchar *
11891 gtk_widget_buildable_get_name (GtkBuildable *buildable)
11893 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
11897 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
11898 GtkBuilder *builder,
11899 const gchar *childname)
11901 if (strcmp (childname, "accessible") == 0)
11902 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
11908 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
11909 GtkBuilder *builder,
11911 const GValue *value)
11913 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
11914 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
11915 GINT_TO_POINTER (TRUE));
11916 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
11917 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
11918 GINT_TO_POINTER (TRUE));
11920 g_object_set_property (G_OBJECT (buildable), name, value);
11925 gchar *action_name;
11926 GString *description;
11928 gboolean translatable;
11938 free_action (AtkActionData *data, gpointer user_data)
11940 g_free (data->action_name);
11941 g_string_free (data->description, TRUE);
11942 g_free (data->context);
11943 g_slice_free (AtkActionData, data);
11947 free_relation (AtkRelationData *data, gpointer user_data)
11949 g_free (data->target);
11950 g_free (data->type);
11951 g_slice_free (AtkRelationData, data);
11955 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
11956 GtkBuilder *builder)
11958 GSList *atk_relations;
11960 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
11961 gtk_widget_grab_default (GTK_WIDGET (buildable));
11962 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
11963 gtk_widget_grab_focus (GTK_WIDGET (buildable));
11965 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
11966 quark_builder_atk_relations);
11969 AtkObject *accessible;
11970 AtkRelationSet *relation_set;
11973 AtkRelationType relation_type;
11974 AtkObject *target_accessible;
11976 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11977 relation_set = atk_object_ref_relation_set (accessible);
11979 for (l = atk_relations; l; l = l->next)
11981 AtkRelationData *relation = (AtkRelationData*)l->data;
11983 target = gtk_builder_get_object (builder, relation->target);
11986 g_warning ("Target object %s in <relation> does not exist",
11990 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
11991 g_assert (target_accessible != NULL);
11993 relation_type = atk_relation_type_for_name (relation->type);
11994 if (relation_type == ATK_RELATION_NULL)
11996 g_warning ("<relation> type %s not found",
12000 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12001 target_accessible);
12003 g_object_unref (relation_set);
12005 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
12006 g_slist_free (atk_relations);
12007 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12016 } AccessibilitySubParserData;
12019 accessibility_start_element (GMarkupParseContext *context,
12020 const gchar *element_name,
12021 const gchar **names,
12022 const gchar **values,
12023 gpointer user_data,
12026 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12028 gint line_number, char_number;
12030 if (strcmp (element_name, "relation") == 0)
12032 gchar *target = NULL;
12033 gchar *type = NULL;
12034 AtkRelationData *relation;
12036 for (i = 0; names[i]; i++)
12038 if (strcmp (names[i], "target") == 0)
12039 target = g_strdup (values[i]);
12040 else if (strcmp (names[i], "type") == 0)
12041 type = g_strdup (values[i]);
12044 g_markup_parse_context_get_position (context,
12047 g_set_error (error,
12049 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12050 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12052 line_number, char_number, names[i], "relation");
12059 if (!target || !type)
12061 g_markup_parse_context_get_position (context,
12064 g_set_error (error,
12066 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12067 "%s:%d:%d <%s> requires attribute \"%s\"",
12069 line_number, char_number, "relation",
12070 type ? "target" : "type");
12076 relation = g_slice_new (AtkRelationData);
12077 relation->target = target;
12078 relation->type = type;
12080 data->relations = g_slist_prepend (data->relations, relation);
12082 else if (strcmp (element_name, "action") == 0)
12084 const gchar *action_name = NULL;
12085 const gchar *description = NULL;
12086 const gchar *msg_context = NULL;
12087 gboolean translatable = FALSE;
12088 AtkActionData *action;
12090 for (i = 0; names[i]; i++)
12092 if (strcmp (names[i], "action_name") == 0)
12093 action_name = values[i];
12094 else if (strcmp (names[i], "description") == 0)
12095 description = values[i];
12096 else if (strcmp (names[i], "translatable") == 0)
12098 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12101 else if (strcmp (names[i], "comments") == 0)
12103 /* do nothing, comments are for translators */
12105 else if (strcmp (names[i], "context") == 0)
12106 msg_context = values[i];
12109 g_markup_parse_context_get_position (context,
12112 g_set_error (error,
12114 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12115 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12117 line_number, char_number, names[i], "action");
12124 g_markup_parse_context_get_position (context,
12127 g_set_error (error,
12129 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12130 "%s:%d:%d <%s> requires attribute \"%s\"",
12132 line_number, char_number, "action",
12137 action = g_slice_new (AtkActionData);
12138 action->action_name = g_strdup (action_name);
12139 action->description = g_string_new (description);
12140 action->context = g_strdup (msg_context);
12141 action->translatable = translatable;
12143 data->actions = g_slist_prepend (data->actions, action);
12145 else if (strcmp (element_name, "accessibility") == 0)
12148 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12152 accessibility_text (GMarkupParseContext *context,
12155 gpointer user_data,
12158 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12160 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12162 AtkActionData *action = data->actions->data;
12164 g_string_append_len (action->description, text, text_len);
12168 static const GMarkupParser accessibility_parser =
12170 accessibility_start_element,
12172 accessibility_text,
12181 } AccelGroupParserData;
12184 accel_group_start_element (GMarkupParseContext *context,
12185 const gchar *element_name,
12186 const gchar **names,
12187 const gchar **values,
12188 gpointer user_data,
12193 guint modifiers = 0;
12194 gchar *signal = NULL;
12195 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12197 for (i = 0; names[i]; i++)
12199 if (strcmp (names[i], "key") == 0)
12200 key = gdk_keyval_from_name (values[i]);
12201 else if (strcmp (names[i], "modifiers") == 0)
12203 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12209 else if (strcmp (names[i], "signal") == 0)
12210 signal = g_strdup (values[i]);
12213 if (key == 0 || signal == NULL)
12215 g_warning ("<accelerator> requires key and signal attributes");
12218 parser_data->key = key;
12219 parser_data->modifiers = modifiers;
12220 parser_data->signal = signal;
12223 static const GMarkupParser accel_group_parser =
12225 accel_group_start_element,
12234 style_start_element (GMarkupParseContext *context,
12235 const gchar *element_name,
12236 const gchar **names,
12237 const gchar **values,
12238 gpointer user_data,
12241 StyleParserData *style_data = (StyleParserData *)user_data;
12244 if (strcmp (element_name, "class") == 0)
12246 if (g_markup_collect_attributes (element_name,
12250 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12251 G_MARKUP_COLLECT_INVALID))
12253 style_data->classes = g_slist_append (style_data->classes, class_name);
12256 else if (strcmp (element_name, "style") == 0)
12259 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12262 static const GMarkupParser style_parser =
12264 style_start_element,
12268 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12269 GtkBuilder *builder,
12271 const gchar *tagname,
12272 GMarkupParser *parser,
12275 g_assert (buildable);
12277 if (strcmp (tagname, "accelerator") == 0)
12279 AccelGroupParserData *parser_data;
12281 parser_data = g_slice_new0 (AccelGroupParserData);
12282 parser_data->object = g_object_ref (buildable);
12283 *parser = accel_group_parser;
12284 *data = parser_data;
12287 if (strcmp (tagname, "accessibility") == 0)
12289 AccessibilitySubParserData *parser_data;
12291 parser_data = g_slice_new0 (AccessibilitySubParserData);
12292 *parser = accessibility_parser;
12293 *data = parser_data;
12296 if (strcmp (tagname, "style") == 0)
12298 StyleParserData *parser_data;
12300 parser_data = g_slice_new0 (StyleParserData);
12301 *parser = style_parser;
12302 *data = parser_data;
12310 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12311 GtkWidget *toplevel,
12312 gpointer user_data)
12314 AccelGroupParserData *accel_data;
12315 GSList *accel_groups;
12316 GtkAccelGroup *accel_group;
12318 g_return_if_fail (GTK_IS_WIDGET (widget));
12319 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12320 g_return_if_fail (user_data != NULL);
12322 accel_data = (AccelGroupParserData*)user_data;
12323 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12324 if (g_slist_length (accel_groups) == 0)
12326 accel_group = gtk_accel_group_new ();
12327 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12331 g_assert (g_slist_length (accel_groups) == 1);
12332 accel_group = g_slist_nth_data (accel_groups, 0);
12335 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12336 accel_data->signal,
12339 accel_data->modifiers,
12340 GTK_ACCEL_VISIBLE);
12342 g_object_unref (accel_data->object);
12343 g_free (accel_data->signal);
12344 g_slice_free (AccelGroupParserData, accel_data);
12348 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12349 GtkBuilder *builder,
12351 const gchar *tagname,
12352 gpointer user_data)
12354 if (strcmp (tagname, "accelerator") == 0)
12356 AccelGroupParserData *accel_data;
12357 GtkWidget *toplevel;
12359 accel_data = (AccelGroupParserData*)user_data;
12360 g_assert (accel_data->object);
12362 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12364 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12366 else if (strcmp (tagname, "accessibility") == 0)
12368 AccessibilitySubParserData *a11y_data;
12370 a11y_data = (AccessibilitySubParserData*)user_data;
12372 if (a11y_data->actions)
12374 AtkObject *accessible;
12379 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12381 if (ATK_IS_ACTION (accessible))
12383 action = ATK_ACTION (accessible);
12384 n_actions = atk_action_get_n_actions (action);
12386 for (l = a11y_data->actions; l; l = l->next)
12388 AtkActionData *action_data = (AtkActionData*)l->data;
12390 for (i = 0; i < n_actions; i++)
12391 if (strcmp (atk_action_get_name (action, i),
12392 action_data->action_name) == 0)
12397 gchar *description;
12399 if (action_data->translatable && action_data->description->len)
12400 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12401 action_data->context,
12402 action_data->description->str);
12404 description = action_data->description->str;
12406 atk_action_set_description (action, i, description);
12411 g_warning ("accessibility action on a widget that does not implement AtkAction");
12413 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
12414 g_slist_free (a11y_data->actions);
12417 if (a11y_data->relations)
12418 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12419 a11y_data->relations);
12421 g_slice_free (AccessibilitySubParserData, a11y_data);
12423 else if (strcmp (tagname, "style") == 0)
12425 StyleParserData *style_data = (StyleParserData *)user_data;
12426 GtkStyleContext *context;
12429 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
12431 for (l = style_data->classes; l; l = l->next)
12432 gtk_style_context_add_class (context, (const gchar *)l->data);
12434 gtk_widget_reset_style (GTK_WIDGET (buildable));
12436 g_slist_free_full (style_data->classes, g_free);
12437 g_slice_free (StyleParserData, style_data);
12441 static GtkSizeRequestMode
12442 gtk_widget_real_get_request_mode (GtkWidget *widget)
12444 /* By default widgets dont trade size at all. */
12445 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
12449 gtk_widget_real_get_width (GtkWidget *widget,
12450 gint *minimum_size,
12451 gint *natural_size)
12461 gtk_widget_real_get_height (GtkWidget *widget,
12462 gint *minimum_size,
12463 gint *natural_size)
12473 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12475 gint *minimum_height,
12476 gint *natural_height)
12478 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12482 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12484 gint *minimum_width,
12485 gint *natural_width)
12487 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12491 * gtk_widget_get_halign:
12492 * @widget: a #GtkWidget
12494 * Gets the value of the #GtkWidget:halign property.
12496 * Returns: the horizontal alignment of @widget
12499 gtk_widget_get_halign (GtkWidget *widget)
12501 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12502 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12506 * gtk_widget_set_halign:
12507 * @widget: a #GtkWidget
12508 * @align: the horizontal alignment
12510 * Sets the horizontal alignment of @widget.
12511 * See the #GtkWidget:halign property.
12514 gtk_widget_set_halign (GtkWidget *widget,
12517 GtkWidgetAuxInfo *aux_info;
12519 g_return_if_fail (GTK_IS_WIDGET (widget));
12521 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12523 if (aux_info->halign == align)
12526 aux_info->halign = align;
12527 gtk_widget_queue_resize (widget);
12528 g_object_notify (G_OBJECT (widget), "halign");
12532 * gtk_widget_get_valign:
12533 * @widget: a #GtkWidget
12535 * Gets the value of the #GtkWidget:valign property.
12537 * Returns: the vertical alignment of @widget
12540 gtk_widget_get_valign (GtkWidget *widget)
12542 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12543 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12547 * gtk_widget_set_valign:
12548 * @widget: a #GtkWidget
12549 * @align: the vertical alignment
12551 * Sets the vertical alignment of @widget.
12552 * See the #GtkWidget:valign property.
12555 gtk_widget_set_valign (GtkWidget *widget,
12558 GtkWidgetAuxInfo *aux_info;
12560 g_return_if_fail (GTK_IS_WIDGET (widget));
12562 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12564 if (aux_info->valign == align)
12567 aux_info->valign = align;
12568 gtk_widget_queue_resize (widget);
12569 g_object_notify (G_OBJECT (widget), "valign");
12573 * gtk_widget_get_margin_left:
12574 * @widget: a #GtkWidget
12576 * Gets the value of the #GtkWidget:margin-left property.
12578 * Returns: The left margin of @widget
12583 gtk_widget_get_margin_left (GtkWidget *widget)
12585 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12587 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12591 * gtk_widget_set_margin_left:
12592 * @widget: a #GtkWidget
12593 * @margin: the left margin
12595 * Sets the left margin of @widget.
12596 * See the #GtkWidget:margin-left property.
12601 gtk_widget_set_margin_left (GtkWidget *widget,
12604 GtkWidgetAuxInfo *aux_info;
12606 g_return_if_fail (GTK_IS_WIDGET (widget));
12607 g_return_if_fail (margin <= G_MAXINT16);
12609 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12611 if (aux_info->margin.left == margin)
12614 aux_info->margin.left = margin;
12615 gtk_widget_queue_resize (widget);
12616 g_object_notify (G_OBJECT (widget), "margin-left");
12620 * gtk_widget_get_margin_right:
12621 * @widget: a #GtkWidget
12623 * Gets the value of the #GtkWidget:margin-right property.
12625 * Returns: The right margin of @widget
12630 gtk_widget_get_margin_right (GtkWidget *widget)
12632 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12634 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12638 * gtk_widget_set_margin_right:
12639 * @widget: a #GtkWidget
12640 * @margin: the right margin
12642 * Sets the right margin of @widget.
12643 * See the #GtkWidget:margin-right property.
12648 gtk_widget_set_margin_right (GtkWidget *widget,
12651 GtkWidgetAuxInfo *aux_info;
12653 g_return_if_fail (GTK_IS_WIDGET (widget));
12654 g_return_if_fail (margin <= G_MAXINT16);
12656 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12658 if (aux_info->margin.right == margin)
12661 aux_info->margin.right = margin;
12662 gtk_widget_queue_resize (widget);
12663 g_object_notify (G_OBJECT (widget), "margin-right");
12667 * gtk_widget_get_margin_top:
12668 * @widget: a #GtkWidget
12670 * Gets the value of the #GtkWidget:margin-top property.
12672 * Returns: The top margin of @widget
12677 gtk_widget_get_margin_top (GtkWidget *widget)
12679 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12681 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12685 * gtk_widget_set_margin_top:
12686 * @widget: a #GtkWidget
12687 * @margin: the top margin
12689 * Sets the top margin of @widget.
12690 * See the #GtkWidget:margin-top property.
12695 gtk_widget_set_margin_top (GtkWidget *widget,
12698 GtkWidgetAuxInfo *aux_info;
12700 g_return_if_fail (GTK_IS_WIDGET (widget));
12701 g_return_if_fail (margin <= G_MAXINT16);
12703 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12705 if (aux_info->margin.top == margin)
12708 aux_info->margin.top = margin;
12709 gtk_widget_queue_resize (widget);
12710 g_object_notify (G_OBJECT (widget), "margin-top");
12714 * gtk_widget_get_margin_bottom:
12715 * @widget: a #GtkWidget
12717 * Gets the value of the #GtkWidget:margin-bottom property.
12719 * Returns: The bottom margin of @widget
12724 gtk_widget_get_margin_bottom (GtkWidget *widget)
12726 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12728 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
12732 * gtk_widget_set_margin_bottom:
12733 * @widget: a #GtkWidget
12734 * @margin: the bottom margin
12736 * Sets the bottom margin of @widget.
12737 * See the #GtkWidget:margin-bottom property.
12742 gtk_widget_set_margin_bottom (GtkWidget *widget,
12745 GtkWidgetAuxInfo *aux_info;
12747 g_return_if_fail (GTK_IS_WIDGET (widget));
12748 g_return_if_fail (margin <= G_MAXINT16);
12750 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12752 if (aux_info->margin.bottom == margin)
12755 aux_info->margin.bottom = margin;
12756 gtk_widget_queue_resize (widget);
12757 g_object_notify (G_OBJECT (widget), "margin-bottom");
12761 * gtk_widget_get_clipboard:
12762 * @widget: a #GtkWidget
12763 * @selection: a #GdkAtom which identifies the clipboard
12764 * to use. %GDK_SELECTION_CLIPBOARD gives the
12765 * default clipboard. Another common value
12766 * is %GDK_SELECTION_PRIMARY, which gives
12767 * the primary X selection.
12769 * Returns the clipboard object for the given selection to
12770 * be used with @widget. @widget must have a #GdkDisplay
12771 * associated with it, so must be attached to a toplevel
12774 * Return value: (transfer none): the appropriate clipboard object. If no
12775 * clipboard already exists, a new one will
12776 * be created. Once a clipboard object has
12777 * been created, it is persistent for all time.
12782 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
12784 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12785 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
12787 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
12792 * gtk_widget_list_mnemonic_labels:
12793 * @widget: a #GtkWidget
12795 * Returns a newly allocated list of the widgets, normally labels, for
12796 * which this widget is the target of a mnemonic (see for example,
12797 * gtk_label_set_mnemonic_widget()).
12799 * The widgets in the list are not individually referenced. If you
12800 * want to iterate through the list and perform actions involving
12801 * callbacks that might destroy the widgets, you
12802 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
12803 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
12804 * widgets afterwards.
12806 * Return value: (element-type GtkWidget) (transfer container): the list of
12807 * mnemonic labels; free this list
12808 * with g_list_free() when you are done with it.
12813 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
12815 GList *list = NULL;
12818 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12820 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
12821 list = g_list_prepend (list, l->data);
12827 * gtk_widget_add_mnemonic_label:
12828 * @widget: a #GtkWidget
12829 * @label: a #GtkWidget that acts as a mnemonic label for @widget
12831 * Adds a widget to the list of mnemonic labels for
12832 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
12833 * list of mnemonic labels for the widget is cleared when the
12834 * widget is destroyed, so the caller must make sure to update
12835 * its internal state at this point as well, by using a connection
12836 * to the #GtkWidget::destroy signal or a weak notifier.
12841 gtk_widget_add_mnemonic_label (GtkWidget *widget,
12844 GSList *old_list, *new_list;
12846 g_return_if_fail (GTK_IS_WIDGET (widget));
12847 g_return_if_fail (GTK_IS_WIDGET (label));
12849 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12850 new_list = g_slist_prepend (old_list, label);
12852 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12853 new_list, (GDestroyNotify) g_slist_free);
12857 * gtk_widget_remove_mnemonic_label:
12858 * @widget: a #GtkWidget
12859 * @label: a #GtkWidget that was previously set as a mnemnic label for
12860 * @widget with gtk_widget_add_mnemonic_label().
12862 * Removes a widget from the list of mnemonic labels for
12863 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
12864 * must have previously been added to the list with
12865 * gtk_widget_add_mnemonic_label().
12870 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
12873 GSList *old_list, *new_list;
12875 g_return_if_fail (GTK_IS_WIDGET (widget));
12876 g_return_if_fail (GTK_IS_WIDGET (label));
12878 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12879 new_list = g_slist_remove (old_list, label);
12882 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12883 new_list, (GDestroyNotify) g_slist_free);
12887 * gtk_widget_get_no_show_all:
12888 * @widget: a #GtkWidget
12890 * Returns the current value of the #GtkWidget:no-show-all property,
12891 * which determines whether calls to gtk_widget_show_all()
12892 * will affect this widget.
12894 * Return value: the current value of the "no-show-all" property.
12899 gtk_widget_get_no_show_all (GtkWidget *widget)
12901 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12903 return widget->priv->no_show_all;
12907 * gtk_widget_set_no_show_all:
12908 * @widget: a #GtkWidget
12909 * @no_show_all: the new value for the "no-show-all" property
12911 * Sets the #GtkWidget:no-show-all property, which determines whether
12912 * calls to gtk_widget_show_all() will affect this widget.
12914 * This is mostly for use in constructing widget hierarchies with externally
12915 * controlled visibility, see #GtkUIManager.
12920 gtk_widget_set_no_show_all (GtkWidget *widget,
12921 gboolean no_show_all)
12923 g_return_if_fail (GTK_IS_WIDGET (widget));
12925 no_show_all = (no_show_all != FALSE);
12927 if (widget->priv->no_show_all != no_show_all)
12929 widget->priv->no_show_all = no_show_all;
12931 g_object_notify (G_OBJECT (widget), "no-show-all");
12937 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
12938 gboolean has_tooltip,
12941 GtkWidgetPrivate *priv = widget->priv;
12942 gboolean priv_has_tooltip;
12944 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
12945 quark_has_tooltip));
12947 if (priv_has_tooltip != has_tooltip || force)
12949 priv_has_tooltip = has_tooltip;
12951 if (priv_has_tooltip)
12953 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
12954 gdk_window_set_events (priv->window,
12955 gdk_window_get_events (priv->window) |
12956 GDK_LEAVE_NOTIFY_MASK |
12957 GDK_POINTER_MOTION_MASK |
12958 GDK_POINTER_MOTION_HINT_MASK);
12960 if (gtk_widget_get_has_window (widget))
12961 gtk_widget_add_events (widget,
12962 GDK_LEAVE_NOTIFY_MASK |
12963 GDK_POINTER_MOTION_MASK |
12964 GDK_POINTER_MOTION_HINT_MASK);
12967 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
12968 GUINT_TO_POINTER (priv_has_tooltip));
12973 * gtk_widget_set_tooltip_window:
12974 * @widget: a #GtkWidget
12975 * @custom_window: (allow-none): a #GtkWindow, or %NULL
12977 * Replaces the default, usually yellow, window used for displaying
12978 * tooltips with @custom_window. GTK+ will take care of showing and
12979 * hiding @custom_window at the right moment, to behave likewise as
12980 * the default tooltip window. If @custom_window is %NULL, the default
12981 * tooltip window will be used.
12983 * If the custom window should have the default theming it needs to
12984 * have the name "gtk-tooltip", see gtk_widget_set_name().
12989 gtk_widget_set_tooltip_window (GtkWidget *widget,
12990 GtkWindow *custom_window)
12992 gboolean has_tooltip;
12993 gchar *tooltip_markup;
12995 g_return_if_fail (GTK_IS_WIDGET (widget));
12996 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
12998 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13001 g_object_ref (custom_window);
13003 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13004 custom_window, g_object_unref);
13006 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13007 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13009 if (has_tooltip && gtk_widget_get_visible (widget))
13010 gtk_widget_queue_tooltip_query (widget);
13014 * gtk_widget_get_tooltip_window:
13015 * @widget: a #GtkWidget
13017 * Returns the #GtkWindow of the current tooltip. This can be the
13018 * GtkWindow created by default, or the custom tooltip window set
13019 * using gtk_widget_set_tooltip_window().
13021 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13026 gtk_widget_get_tooltip_window (GtkWidget *widget)
13028 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13030 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13034 * gtk_widget_trigger_tooltip_query:
13035 * @widget: a #GtkWidget
13037 * Triggers a tooltip query on the display where the toplevel of @widget
13038 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13044 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13046 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13049 static guint tooltip_query_id;
13050 static GSList *tooltip_query_displays;
13053 tooltip_query_idle (gpointer data)
13055 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13056 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13057 g_slist_free (tooltip_query_displays);
13059 tooltip_query_displays = NULL;
13060 tooltip_query_id = 0;
13066 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13068 GdkDisplay *display;
13070 display = gtk_widget_get_display (widget);
13072 if (!g_slist_find (tooltip_query_displays, display))
13073 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13075 if (tooltip_query_id == 0)
13076 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13080 * gtk_widget_set_tooltip_text:
13081 * @widget: a #GtkWidget
13082 * @text: the contents of the tooltip for @widget
13084 * Sets @text as the contents of the tooltip. This function will take
13085 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13086 * handler for the #GtkWidget::query-tooltip signal.
13088 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13093 gtk_widget_set_tooltip_text (GtkWidget *widget,
13096 g_return_if_fail (GTK_IS_WIDGET (widget));
13098 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13102 * gtk_widget_get_tooltip_text:
13103 * @widget: a #GtkWidget
13105 * Gets the contents of the tooltip for @widget.
13107 * Return value: the tooltip text, or %NULL. You should free the
13108 * returned string with g_free() when done.
13113 gtk_widget_get_tooltip_text (GtkWidget *widget)
13115 gchar *text = NULL;
13117 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13119 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13125 * gtk_widget_set_tooltip_markup:
13126 * @widget: a #GtkWidget
13127 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13129 * Sets @markup as the contents of the tooltip, which is marked up with
13130 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13132 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13133 * and of the default handler for the #GtkWidget::query-tooltip signal.
13135 * See also the #GtkWidget:tooltip-markup property and
13136 * gtk_tooltip_set_markup().
13141 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13142 const gchar *markup)
13144 g_return_if_fail (GTK_IS_WIDGET (widget));
13146 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13150 * gtk_widget_get_tooltip_markup:
13151 * @widget: a #GtkWidget
13153 * Gets the contents of the tooltip for @widget.
13155 * Return value: the tooltip text, or %NULL. You should free the
13156 * returned string with g_free() when done.
13161 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13163 gchar *text = NULL;
13165 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13167 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13173 * gtk_widget_set_has_tooltip:
13174 * @widget: a #GtkWidget
13175 * @has_tooltip: whether or not @widget has a tooltip.
13177 * Sets the has-tooltip property on @widget to @has_tooltip. See
13178 * #GtkWidget:has-tooltip for more information.
13183 gtk_widget_set_has_tooltip (GtkWidget *widget,
13184 gboolean has_tooltip)
13186 g_return_if_fail (GTK_IS_WIDGET (widget));
13188 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13192 * gtk_widget_get_has_tooltip:
13193 * @widget: a #GtkWidget
13195 * Returns the current value of the has-tooltip property. See
13196 * #GtkWidget:has-tooltip for more information.
13198 * Return value: current value of has-tooltip on @widget.
13203 gtk_widget_get_has_tooltip (GtkWidget *widget)
13205 gboolean has_tooltip = FALSE;
13207 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13209 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13211 return has_tooltip;
13215 * gtk_widget_get_allocation:
13216 * @widget: a #GtkWidget
13217 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13219 * Retrieves the widget's allocation.
13221 * Note, when implementing a #GtkContainer: a widget's allocation will
13222 * be its "adjusted" allocation, that is, the widget's parent
13223 * container typically calls gtk_widget_size_allocate() with an
13224 * allocation, and that allocation is then adjusted (to handle margin
13225 * and alignment for example) before assignment to the widget.
13226 * gtk_widget_get_allocation() returns the adjusted allocation that
13227 * was actually assigned to the widget. The adjusted allocation is
13228 * guaranteed to be completely contained within the
13229 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13230 * is guaranteed that its children stay inside the assigned bounds,
13231 * but not that they have exactly the bounds the container assigned.
13232 * There is no way to get the original allocation assigned by
13233 * gtk_widget_size_allocate(), since it isn't stored; if a container
13234 * implementation needs that information it will have to track it itself.
13239 gtk_widget_get_allocation (GtkWidget *widget,
13240 GtkAllocation *allocation)
13242 GtkWidgetPrivate *priv;
13244 g_return_if_fail (GTK_IS_WIDGET (widget));
13245 g_return_if_fail (allocation != NULL);
13247 priv = widget->priv;
13249 *allocation = priv->allocation;
13253 * gtk_widget_set_allocation:
13254 * @widget: a #GtkWidget
13255 * @allocation: a pointer to a #GtkAllocation to copy from
13257 * Sets the widget's allocation. This should not be used
13258 * directly, but from within a widget's size_allocate method.
13260 * The allocation set should be the "adjusted" or actual
13261 * allocation. If you're implementing a #GtkContainer, you want to use
13262 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13263 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13264 * allocation inside gtk_widget_size_allocate() to create an adjusted
13270 gtk_widget_set_allocation (GtkWidget *widget,
13271 const GtkAllocation *allocation)
13273 GtkWidgetPrivate *priv;
13275 g_return_if_fail (GTK_IS_WIDGET (widget));
13276 g_return_if_fail (allocation != NULL);
13278 priv = widget->priv;
13280 priv->allocation = *allocation;
13284 * gtk_widget_get_allocated_width:
13285 * @widget: the widget to query
13287 * Returns the width that has currently been allocated to @widget.
13288 * This function is intended to be used when implementing handlers
13289 * for the #GtkWidget::draw function.
13291 * Returns: the width of the @widget
13294 gtk_widget_get_allocated_width (GtkWidget *widget)
13296 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13298 return widget->priv->allocation.width;
13302 * gtk_widget_get_allocated_height:
13303 * @widget: the widget to query
13305 * Returns the height that has currently been allocated to @widget.
13306 * This function is intended to be used when implementing handlers
13307 * for the #GtkWidget::draw function.
13309 * Returns: the height of the @widget
13312 gtk_widget_get_allocated_height (GtkWidget *widget)
13314 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13316 return widget->priv->allocation.height;
13320 * gtk_widget_get_requisition:
13321 * @widget: a #GtkWidget
13322 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13324 * Retrieves the widget's requisition.
13326 * This function should only be used by widget implementations in
13327 * order to figure whether the widget's requisition has actually
13328 * changed after some internal state change (so that they can call
13329 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13331 * Normally, gtk_widget_size_request() should be used.
13335 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13336 * removed, If you need to cache sizes across requests and allocations,
13337 * add an explicit cache to the widget in question instead.
13340 gtk_widget_get_requisition (GtkWidget *widget,
13341 GtkRequisition *requisition)
13343 g_return_if_fail (GTK_IS_WIDGET (widget));
13344 g_return_if_fail (requisition != NULL);
13346 gtk_widget_get_preferred_size (widget, requisition, NULL);
13350 * gtk_widget_set_window:
13351 * @widget: a #GtkWidget
13352 * @window: (transfer full): a #GdkWindow
13354 * Sets a widget's window. This function should only be used in a
13355 * widget's #GtkWidget::realize implementation. The %window passed is
13356 * usually either new window created with gdk_window_new(), or the
13357 * window of its parent widget as returned by
13358 * gtk_widget_get_parent_window().
13360 * Widgets must indicate whether they will create their own #GdkWindow
13361 * by calling gtk_widget_set_has_window(). This is usually done in the
13362 * widget's init() function.
13364 * <note><para>This function does not add any reference to @window.</para></note>
13369 gtk_widget_set_window (GtkWidget *widget,
13372 GtkWidgetPrivate *priv;
13374 g_return_if_fail (GTK_IS_WIDGET (widget));
13375 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13377 priv = widget->priv;
13379 if (priv->window != window)
13381 priv->window = window;
13382 g_object_notify (G_OBJECT (widget), "window");
13387 * gtk_widget_get_window:
13388 * @widget: a #GtkWidget
13390 * Returns the widget's window if it is realized, %NULL otherwise
13392 * Return value: (transfer none): @widget's window.
13397 gtk_widget_get_window (GtkWidget *widget)
13399 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13401 return widget->priv->window;
13405 * gtk_widget_get_support_multidevice:
13406 * @widget: a #GtkWidget
13408 * Returns %TRUE if @widget is multiple pointer aware. See
13409 * gtk_widget_set_support_multidevice() for more information.
13411 * Returns: %TRUE if @widget is multidevice aware.
13414 gtk_widget_get_support_multidevice (GtkWidget *widget)
13416 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13418 return widget->priv->multidevice;
13422 * gtk_widget_set_support_multidevice:
13423 * @widget: a #GtkWidget
13424 * @support_multidevice: %TRUE to support input from multiple devices.
13426 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13427 * @widget will start receiving multiple, per device enter/leave events. Note
13428 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13429 * gdk_window_set_support_multidevice() will have to be called manually on them.
13434 gtk_widget_set_support_multidevice (GtkWidget *widget,
13435 gboolean support_multidevice)
13437 GtkWidgetPrivate *priv;
13439 g_return_if_fail (GTK_IS_WIDGET (widget));
13441 priv = widget->priv;
13442 priv->multidevice = (support_multidevice == TRUE);
13444 if (gtk_widget_get_realized (widget))
13445 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13449 _gtk_widget_set_has_focus (GtkWidget *widget,
13450 gboolean has_focus)
13452 widget->priv->has_focus = has_focus;
13455 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
13457 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
13461 * gtk_widget_send_focus_change:
13462 * @widget: a #GtkWidget
13463 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13465 * Sends the focus change @event to @widget
13467 * This function is not meant to be used by applications. The only time it
13468 * should be used is when it is necessary for a #GtkWidget to assign focus
13469 * to a widget that is semantically owned by the first widget even though
13470 * it's not a direct child - for instance, a search entry in a floating
13471 * window similar to the quick search in #GtkTreeView.
13473 * An example of its usage is:
13476 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13478 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13479 * fevent->focus_change.in = TRUE;
13480 * fevent->focus_change.window = gtk_widget_get_window (widget);
13481 * if (fevent->focus_change.window != NULL)
13482 * g_object_ref (fevent->focus_change.window);
13484 * gtk_widget_send_focus_change (widget, fevent);
13486 * gdk_event_free (event);
13489 * Return value: the return value from the event signal emission: %TRUE
13490 * if the event was handled, and %FALSE otherwise
13495 gtk_widget_send_focus_change (GtkWidget *widget,
13500 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13501 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13503 g_object_ref (widget);
13505 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13507 res = gtk_widget_event (widget, event);
13509 g_object_notify (G_OBJECT (widget), "has-focus");
13511 g_object_unref (widget);
13517 * gtk_widget_in_destruction:
13518 * @widget: a #GtkWidget
13520 * Returns whether the widget is currently being destroyed.
13521 * This information can sometimes be used to avoid doing
13522 * unnecessary work.
13524 * Returns: %TRUE if @widget is being destroyed
13527 gtk_widget_in_destruction (GtkWidget *widget)
13529 return widget->priv->in_destruction;
13533 _gtk_widget_get_resize_pending (GtkWidget *widget)
13535 return widget->priv->resize_pending;
13539 _gtk_widget_set_resize_pending (GtkWidget *widget,
13540 gboolean resize_pending)
13542 widget->priv->resize_pending = resize_pending;
13546 _gtk_widget_get_in_reparent (GtkWidget *widget)
13548 return widget->priv->in_reparent;
13552 _gtk_widget_set_in_reparent (GtkWidget *widget,
13553 gboolean in_reparent)
13555 widget->priv->in_reparent = in_reparent;
13559 _gtk_widget_get_anchored (GtkWidget *widget)
13561 return widget->priv->anchored;
13565 _gtk_widget_set_anchored (GtkWidget *widget,
13568 widget->priv->anchored = anchored;
13572 _gtk_widget_get_shadowed (GtkWidget *widget)
13574 return widget->priv->shadowed;
13578 _gtk_widget_set_shadowed (GtkWidget *widget,
13581 widget->priv->shadowed = shadowed;
13585 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13587 return widget->priv->alloc_needed;
13591 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13592 gboolean alloc_needed)
13594 widget->priv->alloc_needed = alloc_needed;
13598 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13600 return widget->priv->width_request_needed;
13604 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13605 gboolean width_request_needed)
13607 widget->priv->width_request_needed = width_request_needed;
13611 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13613 return widget->priv->height_request_needed;
13617 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13618 gboolean height_request_needed)
13620 widget->priv->height_request_needed = height_request_needed;
13624 _gtk_widget_get_sizegroup_visited (GtkWidget *widget)
13626 return widget->priv->sizegroup_visited;
13630 _gtk_widget_set_sizegroup_visited (GtkWidget *widget,
13633 widget->priv->sizegroup_visited = visited;
13637 _gtk_widget_get_sizegroup_bumping (GtkWidget *widget)
13639 return widget->priv->sizegroup_bumping;
13643 _gtk_widget_set_sizegroup_bumping (GtkWidget *widget,
13646 widget->priv->sizegroup_bumping = bumping;
13650 _gtk_widget_add_sizegroup (GtkWidget *widget,
13655 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13656 groups = g_slist_prepend (groups, group);
13657 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13659 widget->priv->have_size_groups = TRUE;
13663 _gtk_widget_remove_sizegroup (GtkWidget *widget,
13668 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13669 groups = g_slist_remove (groups, group);
13670 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13672 widget->priv->have_size_groups = groups != NULL;
13676 _gtk_widget_get_sizegroups (GtkWidget *widget)
13678 if (widget->priv->have_size_groups)
13679 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13685 * gtk_widget_path_append_for_widget:
13686 * @path: a widget path
13687 * @widget: the widget to append to the widget path
13689 * Appends the data from @widget to the widget hierarchy represented
13690 * by @path. This function is a shortcut for adding information from
13691 * @widget to the given @path. This includes setting the name or
13692 * adding the style classes from @widget.
13694 * Returns: the position where the data was inserted
13699 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
13704 g_return_val_if_fail (path != NULL, 0);
13705 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13707 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
13709 if (widget->priv->name)
13710 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
13712 if (widget->priv->context)
13714 GList *classes, *l;
13716 /* Also add any persistent classes in
13717 * the style context the widget path
13719 classes = gtk_style_context_list_classes (widget->priv->context);
13721 for (l = classes; l; l = l->next)
13722 gtk_widget_path_iter_add_class (path, pos, l->data);
13724 g_list_free (classes);
13731 * gtk_widget_get_path:
13732 * @widget: a #GtkWidget
13734 * Returns the #GtkWidgetPath representing @widget, if the widget
13735 * is not connected to a toplevel widget, a partial path will be
13738 * Returns: (transfer none): The #GtkWidgetPath representing @widget
13741 gtk_widget_get_path (GtkWidget *widget)
13743 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13745 /* As strange as it may seem, this may happen on object construction.
13746 * init() implementations of parent types may eventually call this function,
13747 * each with its corresponding GType, which could leave a child
13748 * implementation with a wrong widget type in the widget path
13750 if (widget->priv->path &&
13751 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (widget->priv->path))
13753 gtk_widget_path_free (widget->priv->path);
13754 widget->priv->path = NULL;
13757 if (!widget->priv->path)
13761 parent = widget->priv->parent;
13764 widget->priv->path = gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
13767 /* Widget is either toplevel or unparented, treat both
13768 * as toplevels style wise, since there are situations
13769 * where style properties might be retrieved on that
13772 widget->priv->path = gtk_widget_path_new ();
13774 gtk_widget_path_append_for_widget (widget->priv->path, widget);
13777 if (widget->priv->context)
13778 gtk_style_context_set_path (widget->priv->context,
13779 widget->priv->path);
13782 return widget->priv->path;
13786 style_context_changed (GtkStyleContext *context,
13787 gpointer user_data)
13789 GtkWidget *widget = user_data;
13791 if (gtk_widget_get_realized (widget))
13792 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
13795 /* Compress all style updates so it
13796 * is only emitted once pre-realize.
13798 widget->priv->style_update_pending = TRUE;
13801 if (widget->priv->anchored)
13802 gtk_widget_queue_resize (widget);
13806 * gtk_widget_get_style_context:
13807 * @widget: a #GtkWidget
13809 * Returns the style context associated to @widget.
13811 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
13812 * must not be freed.
13815 gtk_widget_get_style_context (GtkWidget *widget)
13817 GtkWidgetPrivate *priv;
13818 GtkWidgetPath *path;
13820 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13822 priv = widget->priv;
13824 /* updates style context if it exists already */
13825 path = gtk_widget_get_path (widget);
13827 if (G_UNLIKELY (priv->context == NULL))
13831 priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
13832 "direction", gtk_widget_get_direction (widget),
13835 g_signal_connect (widget->priv->context, "changed",
13836 G_CALLBACK (style_context_changed), widget);
13838 screen = gtk_widget_get_screen (widget);
13841 gtk_style_context_set_screen (priv->context, screen);
13843 gtk_style_context_set_path (priv->context, path);
13846 return widget->priv->context;
13850 * gtk_widget_get_modifier_mask:
13851 * @widget: a #GtkWidget
13852 * @intent: the use case for the modifier mask
13854 * Returns the modifier mask the @widget's windowing system backend
13855 * uses for a particular purpose.
13857 * See gdk_keymap_get_modifier_mask().
13859 * Returns: the modifier mask used for @intent.
13864 gtk_widget_get_modifier_mask (GtkWidget *widget,
13865 GdkModifierIntent intent)
13867 GdkDisplay *display;
13869 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13871 display = gtk_widget_get_display (widget);
13873 return gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
13878 _gtk_widget_get_style (GtkWidget *widget)
13880 return widget->priv->style;
13884 _gtk_widget_set_style (GtkWidget *widget,
13887 widget->priv->style = style;