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 "gtkmainprivate.h"
43 #include "gtkmarshalers.h"
44 #include "gtkselectionprivate.h"
45 #include "gtksettingsprivate.h"
46 #include "gtksizegroup-private.h"
47 #include "gtkwidget.h"
48 #include "gtkwidgetprivate.h"
49 #include "gtkwindowprivate.h"
50 #include "gtkcontainerprivate.h"
51 #include "gtkbindings.h"
52 #include "gtkprivate.h"
53 #include "gtkaccessible.h"
54 #include "gtktooltip.h"
55 #include "gtkinvisible.h"
56 #include "gtkbuildable.h"
57 #include "gtkbuilderprivate.h"
58 #include "gtksizerequest.h"
59 #include "gtkstylecontextprivate.h"
60 #include "gtksymboliccolor.h"
61 #include "gtkcssprovider.h"
62 #include "gtkanimationdescription.h"
63 #include "gtkmodifierstyle.h"
64 #include "gtkversion.h"
67 #include "gtktypebuiltins.h"
68 #include "a11y/gtkwidgetaccessible.h"
72 * @Short_description: Base class for all widgets
75 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
76 * widget lifecycle, states and style.
78 * <refsect2 id="geometry-management">
79 * <title>Height-for-width Geometry Management</title>
81 * GTK+ uses a height-for-width (and width-for-height) geometry management
82 * system. Height-for-width means that a widget can change how much
83 * vertical space it needs, depending on the amount of horizontal space
84 * that it is given (and similar for width-for-height). The most common
85 * example is a label that reflows to fill up the available width, wraps
86 * to fewer lines, and therefore needs less height.
88 * Height-for-width geometry management is implemented in GTK+ by way
89 * of five virtual methods:
91 * <listitem>#GtkWidgetClass.get_request_mode()</listitem>
92 * <listitem>#GtkWidgetClass.get_preferred_width()</listitem>
93 * <listitem>#GtkWidgetClass.get_preferred_height()</listitem>
94 * <listitem>#GtkWidgetClass.get_preferred_height_for_width()</listitem>
95 * <listitem>#GtkWidgetClass.get_preferred_width_for_height()</listitem>
98 * There are some important things to keep in mind when implementing
99 * height-for-width and when using it in container implementations.
101 * The geometry management system will query a widget hierarchy in
102 * only one orientation at a time. When widgets are initially queried
103 * for their minimum sizes it is generally done in two initial passes
104 * in the #GtkSizeRequestMode chosen by the toplevel.
106 * For example, when queried in the normal
107 * %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode:
108 * First, the default minimum and natural width for each widget
109 * in the interface will be computed using gtk_widget_get_preferred_width().
110 * Because the preferred widths for each container depend on the preferred
111 * widths of their children, this information propagates up the hierarchy,
112 * and finally a minimum and natural width is determined for the entire
113 * toplevel. Next, the toplevel will use the minimum width to query for the
114 * minimum height contextual to that width using
115 * gtk_widget_get_preferred_height_for_width(), which will also be a highly
116 * recursive operation. The minimum height for the minimum width is normally
117 * used to set the minimum size constraint on the toplevel
118 * (unless gtk_window_set_geometry_hints() is explicitly used instead).
120 * After the toplevel window has initially requested its size in both
121 * dimensions it can go on to allocate itself a reasonable size (or a size
122 * previously specified with gtk_window_set_default_size()). During the
123 * recursive allocation process it's important to note that request cycles
124 * will be recursively executed while container widgets allocate their children.
125 * Each container widget, once allocated a size, will go on to first share the
126 * space in one orientation among its children and then request each child's
127 * height for its target allocated width or its width for allocated height,
128 * depending. In this way a #GtkWidget will typically be requested its size
129 * a number of times before actually being allocated a size. The size a
130 * widget is finally allocated can of course differ from the size it has
131 * requested. For this reason, #GtkWidget caches a small number of results
132 * to avoid re-querying for the same sizes in one allocation cycle.
134 * See <link linkend="container-geometry-management">GtkContainer's
135 * geometry management section</link>
136 * to learn more about how height-for-width allocations are performed
137 * by container widgets.
139 * If a widget does move content around to intelligently use up the
140 * allocated size then it must support the request in both
141 * #GtkSizeRequestModes even if the widget in question only
142 * trades sizes in a single orientation.
144 * For instance, a #GtkLabel that does height-for-width word wrapping
145 * will not expect to have #GtkWidgetClass.get_preferred_height() called
146 * because that call is specific to a width-for-height request. In this
147 * case the label must return the height required for its own minimum
148 * possible width. By following this rule any widget that handles
149 * height-for-width or width-for-height requests will always be allocated
150 * at least enough space to fit its own content.
152 * Here are some examples of how a %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH widget
153 * generally deals with width-for-height requests, for #GtkWidgetClass.get_preferred_height()
155 * <programlisting><![CDATA[
157 * foo_widget_get_preferred_height (GtkWidget *widget, gint *min_height, gint *nat_height)
159 * if (i_am_in_height_for_width_mode)
163 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
164 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width,
165 * min_height, nat_height);
169 * ... some widgets do both. For instance, if a GtkLabel is rotated to 90 degrees
170 * it will return the minimum and natural height for the rotated label here.
173 * ]]></programlisting>
175 * And in #GtkWidgetClass.get_preferred_width_for_height() it will simply return
176 * the minimum and natural width:
178 * <programlisting><![CDATA[
180 * foo_widget_get_preferred_width_for_height (GtkWidget *widget, gint for_height,
181 * gint *min_width, gint *nat_width)
183 * if (i_am_in_height_for_width_mode)
185 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, min_width, nat_width);
189 * ... again if a widget is sometimes operating in width-for-height mode
190 * (like a rotated GtkLabel) it can go ahead and do its real width for
191 * height calculation here.
194 * ]]></programlisting>
196 * Often a widget needs to get its own request during size request or
197 * allocation. For example, when computing height it may need to also
198 * compute width. Or when deciding how to use an allocation, the widget
199 * may need to know its natural size. In these cases, the widget should
200 * be careful to call its virtual methods directly, like this:
202 * <title>Widget calling its own size request method.</title>
204 * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget),
209 * It will not work to use the wrapper functions, such as
210 * gtk_widget_get_preferred_width() inside your own size request
211 * implementation. These return a request adjusted by #GtkSizeGroup
212 * and by the #GtkWidgetClass.adjust_size_request() virtual method. If a
213 * widget used the wrappers inside its virtual method implementations,
214 * then the adjustments (such as widget margins) would be applied
215 * twice. GTK+ therefore does not allow this and will warn if you try
218 * Of course if you are getting the size request for
219 * <emphasis>another</emphasis> widget, such as a child of a
220 * container, you <emphasis>must</emphasis> use the wrapper APIs.
221 * Otherwise, you would not properly consider widget margins,
222 * #GtkSizeGroup, and so forth.
225 * <refsect2 id="style-properties">
226 * <title>Style Properties</title>
228 * <structname>GtkWidget</structname> introduces <firstterm>style
229 * properties</firstterm> - these are basically object properties that are stored
230 * not on the object, but in the style object associated to the widget. Style
231 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
232 * This mechanism is used for configuring such things as the location of the
233 * scrollbar arrows through the theme, giving theme authors more control over the
234 * look of applications without the need to write a theme engine in C.
237 * Use gtk_widget_class_install_style_property() to install style properties for
238 * a widget class, gtk_widget_class_find_style_property() or
239 * gtk_widget_class_list_style_properties() to get information about existing
240 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
241 * gtk_widget_style_get_valist() to obtain the value of a style property.
244 * <refsect2 id="GtkWidget-BUILDER-UI">
245 * <title>GtkWidget as GtkBuildable</title>
247 * The GtkWidget implementation of the GtkBuildable interface supports a
248 * custom <accelerator> element, which has attributes named key,
249 * modifiers and signal and allows to specify accelerators.
252 * <title>A UI definition fragment specifying an accelerator</title>
253 * <programlisting><![CDATA[
254 * <object class="GtkButton">
255 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
257 * ]]></programlisting>
260 * In addition to accelerators, <structname>GtkWidget</structname> also support a
261 * custom <accessible> element, which supports actions and relations.
262 * Properties on the accessible implementation of an object can be set by accessing the
263 * internal child "accessible" of a <structname>GtkWidget</structname>.
266 * <title>A UI definition fragment specifying an accessible</title>
267 * <programlisting><![CDATA[
268 * <object class="GtkButton" id="label1"/>
269 * <property name="label">I am a Label for a Button</property>
271 * <object class="GtkButton" id="button1">
273 * <action action_name="click" translatable="yes">Click the button.</action>
274 * <relation target="label1" type="labelled-by"/>
276 * <child internal-child="accessible">
277 * <object class="AtkObject" id="a11y-button1">
278 * <property name="AtkObject::name">Clickable Button</property>
282 * ]]></programlisting>
285 * Finally, GtkWidget allows style information such as style classes to
286 * be associated with widgets, using the custom <style> element:
288 * <title>A UI definition fragment specifying an style class</title>
289 * <programlisting><![CDATA[
290 * <object class="GtkButton" id="button1">
292 * <class name="my-special-button-class"/>
293 * <class name="dark-button"/>
296 * ]]></programlisting>
302 /* Add flags here that should not be propagated to children. By default,
303 * all flags will be set on children (think prelight or active), but we
304 * might want to not do this for some.
306 #define GTK_STATE_FLAGS_DONT_PROPAGATE (GTK_STATE_FLAG_FOCUSED)
307 #define GTK_STATE_FLAGS_DO_PROPAGATE (~GTK_STATE_FLAGS_DONT_PROPAGATE)
309 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
310 #define INIT_PATH_SIZE (512)
312 struct _GtkWidgetPrivate
314 /* The state of the widget. There are actually only
315 * 5 widget states (defined in "gtkenums.h")
318 guint state_flags : 6;
322 guint in_destruction : 1;
325 guint composite_child : 1;
333 guint can_default : 1;
334 guint has_default : 1;
335 guint receives_default : 1;
339 guint style_update_pending : 1;
340 guint app_paintable : 1;
341 guint double_buffered : 1;
342 guint redraw_on_alloc : 1;
343 guint no_show_all : 1;
344 guint child_visible : 1;
345 guint multidevice : 1;
346 guint has_shape_mask : 1;
347 guint in_reparent : 1;
349 /* Queue-resize related flags */
350 guint resize_pending : 1;
351 guint alloc_needed : 1;
352 guint width_request_needed : 1;
353 guint height_request_needed : 1;
355 /* Expand-related flags */
356 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
357 guint computed_hexpand : 1; /* computed results (composite of child flags) */
358 guint computed_vexpand : 1;
359 guint hexpand : 1; /* application-forced expand */
361 guint hexpand_set : 1; /* whether to use application-forced */
362 guint vexpand_set : 1; /* instead of computing from children */
364 /* SizeGroup related flags */
365 guint sizegroup_visited : 1;
366 guint sizegroup_bumping : 1;
367 guint have_size_groups : 1;
369 /* The widget's name. If the widget does not have a name
370 * (the name is NULL), then its name (as returned by
371 * "gtk_widget_get_name") is its class's name.
372 * Among other things, the widget name is used to determine
373 * the style to use for a widget.
377 /* The style for the widget. The style contains the
378 * colors the widget should be drawn in for each state
379 * along with graphics contexts used to draw with and
380 * the font to use for text.
383 GtkStyleContext *context;
385 /* Widget's path for styling */
388 /* The widget's allocated size */
389 GtkAllocation allocation;
391 /* The widget's requested sizes */
392 SizeRequestCache requests;
394 /* The widget's window or its parent window if it does
395 * not have a window. (Which will be indicated by the
396 * GTK_NO_WINDOW flag being set).
400 /* The widget's parent */
403 #ifdef G_ENABLE_DEBUG
404 /* Number of gtk_widget_push_verify_invariants () */
405 guint verifying_invariants_count;
406 #endif /* G_ENABLE_DEBUG */
409 struct _GtkWidgetClassPrivate
411 GType accessible_type;
412 AtkRole accessible_role;
441 BUTTON_RELEASE_EVENT,
455 PROPERTY_NOTIFY_EVENT,
456 SELECTION_CLEAR_EVENT,
457 SELECTION_REQUEST_EVENT,
458 SELECTION_NOTIFY_EVENT,
463 VISIBILITY_NOTIFY_EVENT,
477 ACCEL_CLOSURES_CHANGED,
501 PROP_RECEIVES_DEFAULT,
502 PROP_COMPOSITE_CHILD,
510 PROP_DOUBLE_BUFFERED,
525 typedef struct _GtkStateData GtkStateData;
528 STATE_CHANGE_REPLACE,
537 guint use_forall : 1;
540 /* --- prototypes --- */
541 static void gtk_widget_base_class_init (gpointer g_class);
542 static void gtk_widget_class_init (GtkWidgetClass *klass);
543 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
544 static void gtk_widget_init (GtkWidget *widget);
545 static void gtk_widget_set_property (GObject *object,
549 static void gtk_widget_get_property (GObject *object,
553 static void gtk_widget_dispose (GObject *object);
554 static void gtk_widget_real_destroy (GtkWidget *object);
555 static void gtk_widget_finalize (GObject *object);
556 static void gtk_widget_real_show (GtkWidget *widget);
557 static void gtk_widget_real_hide (GtkWidget *widget);
558 static void gtk_widget_real_map (GtkWidget *widget);
559 static void gtk_widget_real_unmap (GtkWidget *widget);
560 static void gtk_widget_real_realize (GtkWidget *widget);
561 static void gtk_widget_real_unrealize (GtkWidget *widget);
562 static void gtk_widget_real_size_allocate (GtkWidget *widget,
563 GtkAllocation *allocation);
564 static void gtk_widget_real_style_set (GtkWidget *widget,
565 GtkStyle *previous_style);
566 static void gtk_widget_real_direction_changed(GtkWidget *widget,
567 GtkTextDirection previous_direction);
569 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
570 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
573 gboolean keyboard_tip,
574 GtkTooltip *tooltip);
575 static void gtk_widget_real_style_updated (GtkWidget *widget);
576 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
577 GtkWidgetHelpType help_type);
579 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
581 GParamSpec **pspecs);
582 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
584 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
586 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
587 GdkEventFocus *event);
588 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
589 GdkEventFocus *event);
590 static gboolean gtk_widget_real_focus (GtkWidget *widget,
591 GtkDirectionType direction);
592 static void gtk_widget_real_move_focus (GtkWidget *widget,
593 GtkDirectionType direction);
594 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
595 GtkDirectionType direction);
596 #ifdef G_ENABLE_DEBUG
597 static void gtk_widget_verify_invariants (GtkWidget *widget);
598 static void gtk_widget_push_verify_invariants (GtkWidget *widget);
599 static void gtk_widget_pop_verify_invariants (GtkWidget *widget);
601 #define gtk_widget_verify_invariants(widget)
602 #define gtk_widget_push_verify_invariants(widget)
603 #define gtk_widget_pop_verify_invariants(widget)
605 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
606 static void gtk_widget_update_pango_context (GtkWidget *widget);
607 static void gtk_widget_propagate_state (GtkWidget *widget,
610 static gint gtk_widget_event_internal (GtkWidget *widget,
612 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
613 gboolean group_cycling);
614 static void gtk_widget_real_get_width (GtkWidget *widget,
617 static void gtk_widget_real_get_height (GtkWidget *widget,
620 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
622 gint *minimum_height,
623 gint *natural_height);
624 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
627 gint *natural_width);
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 GtkStyle *gtk_default_style = NULL;
709 static guint composite_child_stack = 0;
710 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
711 static GParamSpecPool *style_property_spec_pool = NULL;
713 static GQuark quark_property_parser = 0;
714 static GQuark quark_aux_info = 0;
715 static GQuark quark_accel_path = 0;
716 static GQuark quark_accel_closures = 0;
717 static GQuark quark_event_mask = 0;
718 static GQuark quark_device_event_mask = 0;
719 static GQuark quark_parent_window = 0;
720 static GQuark quark_pointer_window = 0;
721 static GQuark quark_shape_info = 0;
722 static GQuark quark_input_shape_info = 0;
723 static GQuark quark_pango_context = 0;
724 static GQuark quark_rc_style = 0;
725 static GQuark quark_accessible_object = 0;
726 static GQuark quark_mnemonic_labels = 0;
727 static GQuark quark_tooltip_markup = 0;
728 static GQuark quark_has_tooltip = 0;
729 static GQuark quark_tooltip_window = 0;
730 static GQuark quark_visual = 0;
731 static GQuark quark_modifier_style = 0;
732 static GQuark quark_enabled_devices = 0;
733 static GQuark quark_size_groups = 0;
734 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
735 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
737 /* --- functions --- */
739 gtk_widget_get_type (void)
741 static GType widget_type = 0;
743 if (G_UNLIKELY (widget_type == 0))
745 const GTypeInfo widget_info =
747 sizeof (GtkWidgetClass),
748 gtk_widget_base_class_init,
749 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
750 (GClassInitFunc) gtk_widget_class_init,
751 NULL, /* class_finalize */
752 NULL, /* class_init */
755 (GInstanceInitFunc) gtk_widget_init,
756 NULL, /* value_table */
759 const GInterfaceInfo accessibility_info =
761 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
762 (GInterfaceFinalizeFunc) NULL,
763 NULL /* interface data */
766 const GInterfaceInfo buildable_info =
768 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
769 (GInterfaceFinalizeFunc) NULL,
770 NULL /* interface data */
773 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
774 &widget_info, G_TYPE_FLAG_ABSTRACT);
776 g_type_add_class_private (widget_type, sizeof (GtkWidgetClassPrivate));
778 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
779 &accessibility_info) ;
780 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
788 gtk_widget_base_class_init (gpointer g_class)
790 GtkWidgetClass *klass = g_class;
792 klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
796 child_property_notify_dispatcher (GObject *object,
800 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
803 /* We guard against the draw signal callbacks modifying the state of the
804 * cairo context by surounding it with save/restore.
805 * Maybe we should also cairo_new_path() just to be sure?
808 gtk_widget_draw_marshaller (GClosure *closure,
809 GValue *return_value,
810 guint n_param_values,
811 const GValue *param_values,
812 gpointer invocation_hint,
813 gpointer marshal_data)
815 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
819 _gtk_marshal_BOOLEAN__BOXED (closure,
830 gtk_widget_class_init (GtkWidgetClass *klass)
832 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
833 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
834 GtkBindingSet *binding_set;
836 gtk_widget_parent_class = g_type_class_peek_parent (klass);
838 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
839 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
840 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
841 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
842 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
843 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
844 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
845 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
846 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
847 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
848 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
849 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
850 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
851 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
852 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
853 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
854 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
855 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
856 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
857 quark_enabled_devices = g_quark_from_static_string ("gtk-widget-enabled-devices");
858 quark_size_groups = g_quark_from_static_string ("gtk-widget-size-groups");
860 style_property_spec_pool = g_param_spec_pool_new (FALSE);
861 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
862 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
863 cpn_context.dispatcher = child_property_notify_dispatcher;
864 _gtk_widget_child_property_notify_context = &cpn_context;
866 gobject_class->dispose = gtk_widget_dispose;
867 gobject_class->finalize = gtk_widget_finalize;
868 gobject_class->set_property = gtk_widget_set_property;
869 gobject_class->get_property = gtk_widget_get_property;
871 klass->destroy = gtk_widget_real_destroy;
873 klass->activate_signal = 0;
874 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
875 klass->show = gtk_widget_real_show;
876 klass->show_all = gtk_widget_show;
877 klass->hide = gtk_widget_real_hide;
878 klass->map = gtk_widget_real_map;
879 klass->unmap = gtk_widget_real_unmap;
880 klass->realize = gtk_widget_real_realize;
881 klass->unrealize = gtk_widget_real_unrealize;
882 klass->size_allocate = gtk_widget_real_size_allocate;
883 klass->get_request_mode = gtk_widget_real_get_request_mode;
884 klass->get_preferred_width = gtk_widget_real_get_width;
885 klass->get_preferred_height = gtk_widget_real_get_height;
886 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
887 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
888 klass->state_changed = NULL;
889 klass->parent_set = NULL;
890 klass->hierarchy_changed = NULL;
891 klass->style_set = gtk_widget_real_style_set;
892 klass->direction_changed = gtk_widget_real_direction_changed;
893 klass->grab_notify = NULL;
894 klass->child_notify = NULL;
896 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
897 klass->grab_focus = gtk_widget_real_grab_focus;
898 klass->focus = gtk_widget_real_focus;
899 klass->move_focus = gtk_widget_real_move_focus;
900 klass->keynav_failed = gtk_widget_real_keynav_failed;
902 klass->button_press_event = NULL;
903 klass->button_release_event = NULL;
904 klass->motion_notify_event = NULL;
905 klass->delete_event = NULL;
906 klass->destroy_event = NULL;
907 klass->key_press_event = gtk_widget_real_key_press_event;
908 klass->key_release_event = gtk_widget_real_key_release_event;
909 klass->enter_notify_event = NULL;
910 klass->leave_notify_event = NULL;
911 klass->configure_event = NULL;
912 klass->focus_in_event = gtk_widget_real_focus_in_event;
913 klass->focus_out_event = gtk_widget_real_focus_out_event;
914 klass->map_event = NULL;
915 klass->unmap_event = NULL;
916 klass->window_state_event = NULL;
917 klass->property_notify_event = _gtk_selection_property_notify;
918 klass->selection_clear_event = _gtk_selection_clear;
919 klass->selection_request_event = _gtk_selection_request;
920 klass->selection_notify_event = _gtk_selection_notify;
921 klass->selection_received = NULL;
922 klass->proximity_in_event = NULL;
923 klass->proximity_out_event = NULL;
924 klass->drag_begin = NULL;
925 klass->drag_end = NULL;
926 klass->drag_data_delete = NULL;
927 klass->drag_leave = NULL;
928 klass->drag_motion = NULL;
929 klass->drag_drop = NULL;
930 klass->drag_data_received = NULL;
931 klass->screen_changed = NULL;
932 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
933 klass->grab_broken_event = NULL;
934 klass->query_tooltip = gtk_widget_real_query_tooltip;
935 klass->style_updated = gtk_widget_real_style_updated;
937 klass->show_help = gtk_widget_real_show_help;
939 /* Accessibility support */
940 klass->priv->accessible_type = GTK_TYPE_ACCESSIBLE;
941 klass->priv->accessible_role = ATK_ROLE_INVALID;
942 klass->get_accessible = gtk_widget_real_get_accessible;
944 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
945 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
947 g_object_class_install_property (gobject_class,
949 g_param_spec_string ("name",
951 P_("The name of the widget"),
953 GTK_PARAM_READWRITE));
954 g_object_class_install_property (gobject_class,
956 g_param_spec_object ("parent",
958 P_("The parent widget of this widget. Must be a Container widget"),
960 GTK_PARAM_READWRITE));
962 g_object_class_install_property (gobject_class,
964 g_param_spec_int ("width-request",
966 P_("Override for width request of the widget, or -1 if natural request should be used"),
970 GTK_PARAM_READWRITE));
971 g_object_class_install_property (gobject_class,
973 g_param_spec_int ("height-request",
974 P_("Height request"),
975 P_("Override for height request of the widget, or -1 if natural request should be used"),
979 GTK_PARAM_READWRITE));
980 g_object_class_install_property (gobject_class,
982 g_param_spec_boolean ("visible",
984 P_("Whether the widget is visible"),
986 GTK_PARAM_READWRITE));
987 g_object_class_install_property (gobject_class,
989 g_param_spec_boolean ("sensitive",
991 P_("Whether the widget responds to input"),
993 GTK_PARAM_READWRITE));
994 g_object_class_install_property (gobject_class,
996 g_param_spec_boolean ("app-paintable",
997 P_("Application paintable"),
998 P_("Whether the application will paint directly on the widget"),
1000 GTK_PARAM_READWRITE));
1001 g_object_class_install_property (gobject_class,
1003 g_param_spec_boolean ("can-focus",
1005 P_("Whether the widget can accept the input focus"),
1007 GTK_PARAM_READWRITE));
1008 g_object_class_install_property (gobject_class,
1010 g_param_spec_boolean ("has-focus",
1012 P_("Whether the widget has the input focus"),
1014 GTK_PARAM_READWRITE));
1015 g_object_class_install_property (gobject_class,
1017 g_param_spec_boolean ("is-focus",
1019 P_("Whether the widget is the focus widget within the toplevel"),
1021 GTK_PARAM_READWRITE));
1022 g_object_class_install_property (gobject_class,
1024 g_param_spec_boolean ("can-default",
1026 P_("Whether the widget can be the default widget"),
1028 GTK_PARAM_READWRITE));
1029 g_object_class_install_property (gobject_class,
1031 g_param_spec_boolean ("has-default",
1033 P_("Whether the widget is the default widget"),
1035 GTK_PARAM_READWRITE));
1036 g_object_class_install_property (gobject_class,
1037 PROP_RECEIVES_DEFAULT,
1038 g_param_spec_boolean ("receives-default",
1039 P_("Receives default"),
1040 P_("If TRUE, the widget will receive the default action when it is focused"),
1042 GTK_PARAM_READWRITE));
1043 g_object_class_install_property (gobject_class,
1044 PROP_COMPOSITE_CHILD,
1045 g_param_spec_boolean ("composite-child",
1046 P_("Composite child"),
1047 P_("Whether the widget is part of a composite widget"),
1049 GTK_PARAM_READABLE));
1050 g_object_class_install_property (gobject_class,
1052 g_param_spec_object ("style",
1054 P_("The style of the widget, which contains information about how it will look (colors etc)"),
1056 GTK_PARAM_READWRITE));
1057 g_object_class_install_property (gobject_class,
1059 g_param_spec_flags ("events",
1061 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1062 GDK_TYPE_EVENT_MASK,
1064 GTK_PARAM_READWRITE));
1065 g_object_class_install_property (gobject_class,
1067 g_param_spec_boolean ("no-show-all",
1069 P_("Whether gtk_widget_show_all() should not affect this widget"),
1071 GTK_PARAM_READWRITE));
1074 * GtkWidget:has-tooltip:
1076 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1077 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1078 * the widget will be queried using #GtkWidget::query-tooltip to determine
1079 * whether it will provide a tooltip or not.
1081 * Note that setting this property to %TRUE for the first time will change
1082 * the event masks of the GdkWindows of this widget to include leave-notify
1083 * and motion-notify events. This cannot and will not be undone when the
1084 * property is set to %FALSE again.
1088 g_object_class_install_property (gobject_class,
1090 g_param_spec_boolean ("has-tooltip",
1092 P_("Whether this widget has a tooltip"),
1094 GTK_PARAM_READWRITE));
1096 * GtkWidget:tooltip-text:
1098 * Sets the text of tooltip to be the given string.
1100 * Also see gtk_tooltip_set_text().
1102 * This is a convenience property which will take care of getting the
1103 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1104 * will automatically be set to %TRUE and there will be taken care of
1105 * #GtkWidget::query-tooltip in the default signal handler.
1109 g_object_class_install_property (gobject_class,
1111 g_param_spec_string ("tooltip-text",
1113 P_("The contents of the tooltip for this widget"),
1115 GTK_PARAM_READWRITE));
1117 * GtkWidget:tooltip-markup:
1119 * Sets the text of tooltip to be the given string, which is marked up
1120 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1121 * Also see gtk_tooltip_set_markup().
1123 * This is a convenience property which will take care of getting the
1124 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1125 * will automatically be set to %TRUE and there will be taken care of
1126 * #GtkWidget::query-tooltip in the default signal handler.
1130 g_object_class_install_property (gobject_class,
1131 PROP_TOOLTIP_MARKUP,
1132 g_param_spec_string ("tooltip-markup",
1133 P_("Tooltip markup"),
1134 P_("The contents of the tooltip for this widget"),
1136 GTK_PARAM_READWRITE));
1141 * The widget's window if it is realized, %NULL otherwise.
1145 g_object_class_install_property (gobject_class,
1147 g_param_spec_object ("window",
1149 P_("The widget's window if it is realized"),
1151 GTK_PARAM_READABLE));
1154 * GtkWidget:double-buffered
1156 * Whether the widget is double buffered.
1160 g_object_class_install_property (gobject_class,
1161 PROP_DOUBLE_BUFFERED,
1162 g_param_spec_boolean ("double-buffered",
1163 P_("Double Buffered"),
1164 P_("Whether the widget is double buffered"),
1166 GTK_PARAM_READWRITE));
1171 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1175 g_object_class_install_property (gobject_class,
1177 g_param_spec_enum ("halign",
1178 P_("Horizontal Alignment"),
1179 P_("How to position in extra horizontal space"),
1182 GTK_PARAM_READWRITE));
1187 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1191 g_object_class_install_property (gobject_class,
1193 g_param_spec_enum ("valign",
1194 P_("Vertical Alignment"),
1195 P_("How to position in extra vertical space"),
1198 GTK_PARAM_READWRITE));
1201 * GtkWidget:margin-left
1203 * Margin on left side of widget.
1205 * This property adds margin outside of the widget's normal size
1206 * request, the margin will be added in addition to the size from
1207 * gtk_widget_set_size_request() for example.
1211 g_object_class_install_property (gobject_class,
1213 g_param_spec_int ("margin-left",
1214 P_("Margin on Left"),
1215 P_("Pixels of extra space on the left side"),
1219 GTK_PARAM_READWRITE));
1222 * GtkWidget:margin-right
1224 * Margin on right side of widget.
1226 * This property adds margin outside of the widget's normal size
1227 * request, the margin will be added in addition to the size from
1228 * gtk_widget_set_size_request() for example.
1232 g_object_class_install_property (gobject_class,
1234 g_param_spec_int ("margin-right",
1235 P_("Margin on Right"),
1236 P_("Pixels of extra space on the right side"),
1240 GTK_PARAM_READWRITE));
1243 * GtkWidget:margin-top
1245 * Margin on top side of widget.
1247 * This property adds margin outside of the widget's normal size
1248 * request, the margin will be added in addition to the size from
1249 * gtk_widget_set_size_request() for example.
1253 g_object_class_install_property (gobject_class,
1255 g_param_spec_int ("margin-top",
1256 P_("Margin on Top"),
1257 P_("Pixels of extra space on the top side"),
1261 GTK_PARAM_READWRITE));
1264 * GtkWidget:margin-bottom
1266 * Margin on bottom side of widget.
1268 * This property adds margin outside of the widget's normal size
1269 * request, the margin will be added in addition to the size from
1270 * gtk_widget_set_size_request() for example.
1274 g_object_class_install_property (gobject_class,
1276 g_param_spec_int ("margin-bottom",
1277 P_("Margin on Bottom"),
1278 P_("Pixels of extra space on the bottom side"),
1282 GTK_PARAM_READWRITE));
1287 * Sets all four sides' margin at once. If read, returns max
1288 * margin on any side.
1292 g_object_class_install_property (gobject_class,
1294 g_param_spec_int ("margin",
1296 P_("Pixels of extra space on all four sides"),
1300 GTK_PARAM_READWRITE));
1303 * GtkWidget::destroy:
1304 * @object: the object which received the signal
1306 * Signals that all holders of a reference to the widget should release
1307 * the reference that they hold. May result in finalization of the widget
1308 * if all references are released.
1310 widget_signals[DESTROY] =
1311 g_signal_new (I_("destroy"),
1312 G_TYPE_FROM_CLASS (gobject_class),
1313 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1314 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1316 _gtk_marshal_VOID__VOID,
1322 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1326 g_object_class_install_property (gobject_class,
1328 g_param_spec_boolean ("hexpand",
1329 P_("Horizontal Expand"),
1330 P_("Whether widget wants more horizontal space"),
1332 GTK_PARAM_READWRITE));
1335 * GtkWidget:hexpand-set
1337 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1341 g_object_class_install_property (gobject_class,
1343 g_param_spec_boolean ("hexpand-set",
1344 P_("Horizontal Expand Set"),
1345 P_("Whether to use the hexpand property"),
1347 GTK_PARAM_READWRITE));
1352 * Whether to expand vertically. See gtk_widget_set_vexpand().
1356 g_object_class_install_property (gobject_class,
1358 g_param_spec_boolean ("vexpand",
1359 P_("Vertical Expand"),
1360 P_("Whether widget wants more vertical space"),
1362 GTK_PARAM_READWRITE));
1365 * GtkWidget:vexpand-set
1367 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1371 g_object_class_install_property (gobject_class,
1373 g_param_spec_boolean ("vexpand-set",
1374 P_("Vertical Expand Set"),
1375 P_("Whether to use the vexpand property"),
1377 GTK_PARAM_READWRITE));
1382 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1386 g_object_class_install_property (gobject_class,
1388 g_param_spec_boolean ("expand",
1390 P_("Whether widget wants to expand in both directions"),
1392 GTK_PARAM_READWRITE));
1396 * @widget: the object which received the signal.
1398 widget_signals[SHOW] =
1399 g_signal_new (I_("show"),
1400 G_TYPE_FROM_CLASS (gobject_class),
1402 G_STRUCT_OFFSET (GtkWidgetClass, show),
1404 _gtk_marshal_VOID__VOID,
1409 * @widget: the object which received the signal.
1411 widget_signals[HIDE] =
1412 g_signal_new (I_("hide"),
1413 G_TYPE_FROM_CLASS (gobject_class),
1415 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1417 _gtk_marshal_VOID__VOID,
1422 * @widget: the object which received the signal.
1424 widget_signals[MAP] =
1425 g_signal_new (I_("map"),
1426 G_TYPE_FROM_CLASS (gobject_class),
1428 G_STRUCT_OFFSET (GtkWidgetClass, map),
1430 _gtk_marshal_VOID__VOID,
1435 * @widget: the object which received the signal.
1437 widget_signals[UNMAP] =
1438 g_signal_new (I_("unmap"),
1439 G_TYPE_FROM_CLASS (gobject_class),
1441 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1443 _gtk_marshal_VOID__VOID,
1447 * GtkWidget::realize:
1448 * @widget: the object which received the signal.
1450 widget_signals[REALIZE] =
1451 g_signal_new (I_("realize"),
1452 G_TYPE_FROM_CLASS (gobject_class),
1454 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1456 _gtk_marshal_VOID__VOID,
1460 * GtkWidget::unrealize:
1461 * @widget: the object which received the signal.
1463 widget_signals[UNREALIZE] =
1464 g_signal_new (I_("unrealize"),
1465 G_TYPE_FROM_CLASS (gobject_class),
1467 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1469 _gtk_marshal_VOID__VOID,
1473 * GtkWidget::size-allocate:
1474 * @widget: the object which received the signal.
1477 widget_signals[SIZE_ALLOCATE] =
1478 g_signal_new (I_("size-allocate"),
1479 G_TYPE_FROM_CLASS (gobject_class),
1481 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1483 _gtk_marshal_VOID__BOXED,
1485 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1488 * GtkWidget::state-changed:
1489 * @widget: the object which received the signal.
1490 * @state: the previous state
1492 * The ::state-changed signal is emitted when the widget state changes.
1493 * See gtk_widget_get_state().
1495 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1497 widget_signals[STATE_CHANGED] =
1498 g_signal_new (I_("state-changed"),
1499 G_TYPE_FROM_CLASS (gobject_class),
1501 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1503 _gtk_marshal_VOID__ENUM,
1505 GTK_TYPE_STATE_TYPE);
1508 * GtkWidget::state-flags-changed:
1509 * @widget: the object which received the signal.
1510 * @flags: The previous state flags.
1512 * The ::state-flags-changed signal is emitted when the widget state
1513 * changes, see gtk_widget_get_state_flags().
1517 widget_signals[STATE_FLAGS_CHANGED] =
1518 g_signal_new (I_("state-flags-changed"),
1519 G_TYPE_FROM_CLASS (gobject_class),
1521 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1523 _gtk_marshal_VOID__FLAGS,
1525 GTK_TYPE_STATE_FLAGS);
1528 * GtkWidget::parent-set:
1529 * @widget: the object on which the signal is emitted
1530 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1531 * just got its initial parent.
1533 * The ::parent-set signal is emitted when a new parent
1534 * has been set on a widget.
1536 widget_signals[PARENT_SET] =
1537 g_signal_new (I_("parent-set"),
1538 G_TYPE_FROM_CLASS (gobject_class),
1540 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1542 _gtk_marshal_VOID__OBJECT,
1547 * GtkWidget::hierarchy-changed:
1548 * @widget: the object on which the signal is emitted
1549 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1550 * if the widget was previously unanchored
1552 * The ::hierarchy-changed signal is emitted when the
1553 * anchored state of a widget changes. A widget is
1554 * <firstterm>anchored</firstterm> when its toplevel
1555 * ancestor is a #GtkWindow. This signal is emitted when
1556 * a widget changes from un-anchored to anchored or vice-versa.
1558 widget_signals[HIERARCHY_CHANGED] =
1559 g_signal_new (I_("hierarchy-changed"),
1560 G_TYPE_FROM_CLASS (gobject_class),
1562 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1564 _gtk_marshal_VOID__OBJECT,
1569 * GtkWidget::style-set:
1570 * @widget: the object on which the signal is emitted
1571 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1572 * just got its initial style
1574 * The ::style-set signal is emitted when a new style has been set
1575 * on a widget. Note that style-modifying functions like
1576 * gtk_widget_modify_base() also cause this signal to be emitted.
1578 * Note that this signal is emitted for changes to the deprecated
1579 * #GtkStyle. To track changes to the #GtkStyleContext associated
1580 * with a widget, use the #GtkWidget::style-updated signal.
1582 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1584 widget_signals[STYLE_SET] =
1585 g_signal_new (I_("style-set"),
1586 G_TYPE_FROM_CLASS (gobject_class),
1588 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1590 _gtk_marshal_VOID__OBJECT,
1595 * GtkWidget::style-updated:
1596 * @widget: the object on which the signal is emitted
1598 * The ::style-updated signal is emitted when the #GtkStyleContext
1599 * of a widget is changed. Note that style-modifying functions like
1600 * gtk_widget_override_color() also cause this signal to be emitted.
1604 widget_signals[STYLE_UPDATED] =
1605 g_signal_new (I_("style-updated"),
1606 G_TYPE_FROM_CLASS (gobject_class),
1608 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1610 g_cclosure_marshal_VOID__VOID,
1614 * GtkWidget::direction-changed:
1615 * @widget: the object on which the signal is emitted
1616 * @previous_direction: the previous text direction of @widget
1618 * The ::direction-changed signal is emitted when the text direction
1619 * of a widget changes.
1621 widget_signals[DIRECTION_CHANGED] =
1622 g_signal_new (I_("direction-changed"),
1623 G_TYPE_FROM_CLASS (gobject_class),
1625 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1627 _gtk_marshal_VOID__ENUM,
1629 GTK_TYPE_TEXT_DIRECTION);
1632 * GtkWidget::grab-notify:
1633 * @widget: the object which received the signal
1634 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1635 * if it becomes unshadowed
1637 * The ::grab-notify signal is emitted when a widget becomes
1638 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1639 * another widget, or when it becomes unshadowed due to a grab
1642 * A widget is shadowed by a gtk_grab_add() when the topmost
1643 * grab widget in the grab stack of its window group is not
1646 widget_signals[GRAB_NOTIFY] =
1647 g_signal_new (I_("grab-notify"),
1648 G_TYPE_FROM_CLASS (gobject_class),
1650 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1652 _gtk_marshal_VOID__BOOLEAN,
1657 * GtkWidget::child-notify:
1658 * @widget: the object which received the signal
1659 * @pspec: the #GParamSpec of the changed child property
1661 * The ::child-notify signal is emitted for each
1662 * <link linkend="child-properties">child property</link> that has
1663 * changed on an object. The signal's detail holds the property name.
1665 widget_signals[CHILD_NOTIFY] =
1666 g_signal_new (I_("child-notify"),
1667 G_TYPE_FROM_CLASS (gobject_class),
1668 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1669 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1671 g_cclosure_marshal_VOID__PARAM,
1677 * @widget: the object which received the signal
1678 * @cr: the cairo context to draw to
1680 * This signal is emitted when a widget is supposed to render itself.
1681 * The @widget's top left corner must be painted at the origin of
1682 * the passed in context and be sized to the values returned by
1683 * gtk_widget_get_allocated_width() and
1684 * gtk_widget_get_allocated_height().
1686 * Signal handlers connected to this signal can modify the cairo
1687 * context passed as @cr in any way they like and don't need to
1688 * restore it. The signal emission takes care of calling cairo_save()
1689 * before and cairo_restore() after invoking the handler.
1693 widget_signals[DRAW] =
1694 g_signal_new (I_("draw"),
1695 G_TYPE_FROM_CLASS (gobject_class),
1697 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1698 _gtk_boolean_handled_accumulator, NULL,
1699 gtk_widget_draw_marshaller,
1701 CAIRO_GOBJECT_TYPE_CONTEXT);
1704 * GtkWidget::mnemonic-activate:
1705 * @widget: the object which received the signal.
1708 widget_signals[MNEMONIC_ACTIVATE] =
1709 g_signal_new (I_("mnemonic-activate"),
1710 G_TYPE_FROM_CLASS (gobject_class),
1712 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1713 _gtk_boolean_handled_accumulator, NULL,
1714 _gtk_marshal_BOOLEAN__BOOLEAN,
1719 * GtkWidget::grab-focus:
1720 * @widget: the object which received the signal.
1722 widget_signals[GRAB_FOCUS] =
1723 g_signal_new (I_("grab-focus"),
1724 G_TYPE_FROM_CLASS (gobject_class),
1725 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1726 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1728 _gtk_marshal_VOID__VOID,
1733 * @widget: the object which received the signal.
1736 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1738 widget_signals[FOCUS] =
1739 g_signal_new (I_("focus"),
1740 G_TYPE_FROM_CLASS (klass),
1742 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1743 _gtk_boolean_handled_accumulator, NULL,
1744 _gtk_marshal_BOOLEAN__ENUM,
1746 GTK_TYPE_DIRECTION_TYPE);
1749 * GtkWidget::move-focus:
1750 * @widget: the object which received the signal.
1753 widget_signals[MOVE_FOCUS] =
1754 g_signal_new (I_("move-focus"),
1755 G_TYPE_FROM_CLASS (klass),
1756 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1757 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1759 _gtk_marshal_VOID__ENUM,
1762 GTK_TYPE_DIRECTION_TYPE);
1765 * GtkWidget::keynav-failed:
1766 * @widget: the object which received the signal
1767 * @direction: the direction of movement
1769 * Gets emitted if keyboard navigation fails.
1770 * See gtk_widget_keynav_failed() for details.
1772 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1773 * if the emitting widget should try to handle the keyboard
1774 * navigation attempt in its parent container(s).
1778 widget_signals[KEYNAV_FAILED] =
1779 g_signal_new (I_("keynav-failed"),
1780 G_TYPE_FROM_CLASS (klass),
1782 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1783 _gtk_boolean_handled_accumulator, NULL,
1784 _gtk_marshal_BOOLEAN__ENUM,
1786 GTK_TYPE_DIRECTION_TYPE);
1790 * @widget: the object which received the signal.
1791 * @event: the #GdkEvent which triggered this signal
1793 * The GTK+ main loop will emit three signals for each GDK event delivered
1794 * to a widget: one generic ::event signal, another, more specific,
1795 * signal that matches the type of event delivered (e.g.
1796 * #GtkWidget::key-press-event) and finally a generic
1797 * #GtkWidget::event-after signal.
1799 * Returns: %TRUE to stop other handlers from being invoked for the event
1800 * and to cancel the emission of the second specific ::event signal.
1801 * %FALSE to propagate the event further and to allow the emission of
1802 * the second signal. The ::event-after signal is emitted regardless of
1805 widget_signals[EVENT] =
1806 g_signal_new (I_("event"),
1807 G_TYPE_FROM_CLASS (klass),
1809 G_STRUCT_OFFSET (GtkWidgetClass, event),
1810 _gtk_boolean_handled_accumulator, NULL,
1811 _gtk_marshal_BOOLEAN__BOXED,
1813 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1816 * GtkWidget::event-after:
1817 * @widget: the object which received the signal.
1818 * @event: the #GdkEvent which triggered this signal
1820 * After the emission of the #GtkWidget::event signal and (optionally)
1821 * the second more specific signal, ::event-after will be emitted
1822 * regardless of the previous two signals handlers return values.
1825 widget_signals[EVENT_AFTER] =
1826 g_signal_new (I_("event-after"),
1827 G_TYPE_FROM_CLASS (klass),
1831 _gtk_marshal_VOID__BOXED,
1833 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1836 * GtkWidget::button-press-event:
1837 * @widget: the object which received the signal.
1838 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1841 * The ::button-press-event signal will be emitted when a button
1842 * (typically from a mouse) is pressed.
1844 * To receive this signal, the #GdkWindow associated to the
1845 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1847 * This signal will be sent to the grab widget if there is one.
1849 * Returns: %TRUE to stop other handlers from being invoked for the event.
1850 * %FALSE to propagate the event further.
1852 widget_signals[BUTTON_PRESS_EVENT] =
1853 g_signal_new (I_("button-press-event"),
1854 G_TYPE_FROM_CLASS (klass),
1856 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1857 _gtk_boolean_handled_accumulator, NULL,
1858 _gtk_marshal_BOOLEAN__BOXED,
1860 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1863 * GtkWidget::button-release-event:
1864 * @widget: the object which received the signal.
1865 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1868 * The ::button-release-event signal will be emitted when a button
1869 * (typically from a mouse) is released.
1871 * To receive this signal, the #GdkWindow associated to the
1872 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1874 * This signal will be sent to the grab widget if there is one.
1876 * Returns: %TRUE to stop other handlers from being invoked for the event.
1877 * %FALSE to propagate the event further.
1879 widget_signals[BUTTON_RELEASE_EVENT] =
1880 g_signal_new (I_("button-release-event"),
1881 G_TYPE_FROM_CLASS (klass),
1883 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1884 _gtk_boolean_handled_accumulator, NULL,
1885 _gtk_marshal_BOOLEAN__BOXED,
1887 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1890 * GtkWidget::scroll-event:
1891 * @widget: the object which received the signal.
1892 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1895 * The ::scroll-event signal is emitted when a button in the 4 to 7
1896 * range is pressed. Wheel mice are usually configured to generate
1897 * button press events for buttons 4 and 5 when the wheel is turned.
1899 * To receive this signal, the #GdkWindow associated to the widget needs
1900 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1902 * This signal will be sent to the grab widget if there is one.
1904 * Returns: %TRUE to stop other handlers from being invoked for the event.
1905 * %FALSE to propagate the event further.
1907 widget_signals[SCROLL_EVENT] =
1908 g_signal_new (I_("scroll-event"),
1909 G_TYPE_FROM_CLASS (klass),
1911 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1912 _gtk_boolean_handled_accumulator, NULL,
1913 _gtk_marshal_BOOLEAN__BOXED,
1915 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1918 * GtkWidget::motion-notify-event:
1919 * @widget: the object which received the signal.
1920 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1923 * The ::motion-notify-event signal is emitted when the pointer moves
1924 * over the widget's #GdkWindow.
1926 * To receive this signal, the #GdkWindow associated to the widget
1927 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1929 * This signal will be sent to the grab widget if there is one.
1931 * Returns: %TRUE to stop other handlers from being invoked for the event.
1932 * %FALSE to propagate the event further.
1934 widget_signals[MOTION_NOTIFY_EVENT] =
1935 g_signal_new (I_("motion-notify-event"),
1936 G_TYPE_FROM_CLASS (klass),
1938 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1939 _gtk_boolean_handled_accumulator, NULL,
1940 _gtk_marshal_BOOLEAN__BOXED,
1942 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1945 * GtkWidget::composited-changed:
1946 * @widget: the object on which the signal is emitted
1948 * The ::composited-changed signal is emitted when the composited
1949 * status of @widget<!-- -->s screen changes.
1950 * See gdk_screen_is_composited().
1952 widget_signals[COMPOSITED_CHANGED] =
1953 g_signal_new (I_("composited-changed"),
1954 G_TYPE_FROM_CLASS (klass),
1955 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1956 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1958 _gtk_marshal_VOID__VOID,
1962 * GtkWidget::delete-event:
1963 * @widget: the object which received the signal
1964 * @event: the event which triggered this signal
1966 * The ::delete-event signal is emitted if a user requests that
1967 * a toplevel window is closed. The default handler for this signal
1968 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1969 * this signal will cause the window to be hidden instead, so that
1970 * it can later be shown again without reconstructing it.
1972 * Returns: %TRUE to stop other handlers from being invoked for the event.
1973 * %FALSE to propagate the event further.
1975 widget_signals[DELETE_EVENT] =
1976 g_signal_new (I_("delete-event"),
1977 G_TYPE_FROM_CLASS (klass),
1979 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1980 _gtk_boolean_handled_accumulator, NULL,
1981 _gtk_marshal_BOOLEAN__BOXED,
1983 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1986 * GtkWidget::destroy-event:
1987 * @widget: the object which received the signal.
1988 * @event: the event which triggered this signal
1990 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1991 * You rarely get this signal, because most widgets disconnect themselves
1992 * from their window before they destroy it, so no widget owns the
1993 * window at destroy time.
1995 * To receive this signal, the #GdkWindow associated to the widget needs
1996 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1997 * automatically for all new windows.
1999 * Returns: %TRUE to stop other handlers from being invoked for the event.
2000 * %FALSE to propagate the event further.
2002 widget_signals[DESTROY_EVENT] =
2003 g_signal_new (I_("destroy-event"),
2004 G_TYPE_FROM_CLASS (klass),
2006 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
2007 _gtk_boolean_handled_accumulator, NULL,
2008 _gtk_marshal_BOOLEAN__BOXED,
2010 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2013 * GtkWidget::key-press-event:
2014 * @widget: the object which received the signal
2015 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2017 * The ::key-press-event signal is emitted when a key is pressed. The signal
2018 * emission will reoccur at the key-repeat rate when the key is kept pressed.
2020 * To receive this signal, the #GdkWindow associated to the widget needs
2021 * to enable the #GDK_KEY_PRESS_MASK mask.
2023 * This signal will be sent to the grab widget if there is one.
2025 * Returns: %TRUE to stop other handlers from being invoked for the event.
2026 * %FALSE to propagate the event further.
2028 widget_signals[KEY_PRESS_EVENT] =
2029 g_signal_new (I_("key-press-event"),
2030 G_TYPE_FROM_CLASS (klass),
2032 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
2033 _gtk_boolean_handled_accumulator, NULL,
2034 _gtk_marshal_BOOLEAN__BOXED,
2036 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2039 * GtkWidget::key-release-event:
2040 * @widget: the object which received the signal
2041 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2043 * The ::key-release-event signal is emitted when a key is released.
2045 * To receive this signal, the #GdkWindow associated to the widget needs
2046 * to enable the #GDK_KEY_RELEASE_MASK mask.
2048 * This signal will be sent to the grab widget if there is one.
2050 * Returns: %TRUE to stop other handlers from being invoked for the event.
2051 * %FALSE to propagate the event further.
2053 widget_signals[KEY_RELEASE_EVENT] =
2054 g_signal_new (I_("key-release-event"),
2055 G_TYPE_FROM_CLASS (klass),
2057 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2058 _gtk_boolean_handled_accumulator, NULL,
2059 _gtk_marshal_BOOLEAN__BOXED,
2061 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2064 * GtkWidget::enter-notify-event:
2065 * @widget: the object which received the signal
2066 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2069 * The ::enter-notify-event will be emitted when the pointer enters
2070 * the @widget's window.
2072 * To receive this signal, the #GdkWindow associated to the widget needs
2073 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2075 * This signal will be sent to the grab widget if there is one.
2077 * Returns: %TRUE to stop other handlers from being invoked for the event.
2078 * %FALSE to propagate the event further.
2080 widget_signals[ENTER_NOTIFY_EVENT] =
2081 g_signal_new (I_("enter-notify-event"),
2082 G_TYPE_FROM_CLASS (klass),
2084 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2085 _gtk_boolean_handled_accumulator, NULL,
2086 _gtk_marshal_BOOLEAN__BOXED,
2088 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2091 * GtkWidget::leave-notify-event:
2092 * @widget: the object which received the signal
2093 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2096 * The ::leave-notify-event will be emitted when the pointer leaves
2097 * the @widget's window.
2099 * To receive this signal, the #GdkWindow associated to the widget needs
2100 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2102 * This signal will be sent to the grab widget if there is one.
2104 * Returns: %TRUE to stop other handlers from being invoked for the event.
2105 * %FALSE to propagate the event further.
2107 widget_signals[LEAVE_NOTIFY_EVENT] =
2108 g_signal_new (I_("leave-notify-event"),
2109 G_TYPE_FROM_CLASS (klass),
2111 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2112 _gtk_boolean_handled_accumulator, NULL,
2113 _gtk_marshal_BOOLEAN__BOXED,
2115 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2118 * GtkWidget::configure-event:
2119 * @widget: the object which received the signal
2120 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2123 * The ::configure-event signal will be emitted when the size, position or
2124 * stacking of the @widget's window has changed.
2126 * To receive this signal, the #GdkWindow associated to the widget needs
2127 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2128 * automatically for all new windows.
2130 * Returns: %TRUE to stop other handlers from being invoked for the event.
2131 * %FALSE to propagate the event further.
2133 widget_signals[CONFIGURE_EVENT] =
2134 g_signal_new (I_("configure-event"),
2135 G_TYPE_FROM_CLASS (klass),
2137 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2138 _gtk_boolean_handled_accumulator, NULL,
2139 _gtk_marshal_BOOLEAN__BOXED,
2141 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2144 * GtkWidget::focus-in-event:
2145 * @widget: the object which received the signal
2146 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2149 * The ::focus-in-event signal will be emitted when the keyboard focus
2150 * enters the @widget's window.
2152 * To receive this signal, the #GdkWindow associated to the widget needs
2153 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2155 * Returns: %TRUE to stop other handlers from being invoked for the event.
2156 * %FALSE to propagate the event further.
2158 widget_signals[FOCUS_IN_EVENT] =
2159 g_signal_new (I_("focus-in-event"),
2160 G_TYPE_FROM_CLASS (klass),
2162 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2163 _gtk_boolean_handled_accumulator, NULL,
2164 _gtk_marshal_BOOLEAN__BOXED,
2166 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2169 * GtkWidget::focus-out-event:
2170 * @widget: the object which received the signal
2171 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2174 * The ::focus-out-event signal will be emitted when the keyboard focus
2175 * leaves the @widget's window.
2177 * To receive this signal, the #GdkWindow associated to the widget needs
2178 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2180 * Returns: %TRUE to stop other handlers from being invoked for the event.
2181 * %FALSE to propagate the event further.
2183 widget_signals[FOCUS_OUT_EVENT] =
2184 g_signal_new (I_("focus-out-event"),
2185 G_TYPE_FROM_CLASS (klass),
2187 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2188 _gtk_boolean_handled_accumulator, NULL,
2189 _gtk_marshal_BOOLEAN__BOXED,
2191 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2194 * GtkWidget::map-event:
2195 * @widget: the object which received the signal
2196 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2198 * The ::map-event signal will be emitted when the @widget's window is
2199 * mapped. A window is mapped when it becomes visible on the screen.
2201 * To receive this signal, the #GdkWindow associated to the widget needs
2202 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2203 * automatically for all new windows.
2205 * Returns: %TRUE to stop other handlers from being invoked for the event.
2206 * %FALSE to propagate the event further.
2208 widget_signals[MAP_EVENT] =
2209 g_signal_new (I_("map-event"),
2210 G_TYPE_FROM_CLASS (klass),
2212 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2213 _gtk_boolean_handled_accumulator, NULL,
2214 _gtk_marshal_BOOLEAN__BOXED,
2216 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2219 * GtkWidget::unmap-event:
2220 * @widget: the object which received the signal
2221 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2223 * The ::unmap-event signal will be emitted when the @widget's window is
2224 * unmapped. A window is unmapped when it becomes invisible on the screen.
2226 * To receive this signal, the #GdkWindow associated to the widget needs
2227 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2228 * automatically for all new windows.
2230 * Returns: %TRUE to stop other handlers from being invoked for the event.
2231 * %FALSE to propagate the event further.
2233 widget_signals[UNMAP_EVENT] =
2234 g_signal_new (I_("unmap-event"),
2235 G_TYPE_FROM_CLASS (klass),
2237 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2238 _gtk_boolean_handled_accumulator, NULL,
2239 _gtk_marshal_BOOLEAN__BOXED,
2241 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2244 * GtkWidget::property-notify-event:
2245 * @widget: the object which received the signal
2246 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2249 * The ::property-notify-event signal will be emitted when a property on
2250 * the @widget's window has been changed or deleted.
2252 * To receive this signal, the #GdkWindow associated to the widget needs
2253 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2255 * Returns: %TRUE to stop other handlers from being invoked for the event.
2256 * %FALSE to propagate the event further.
2258 widget_signals[PROPERTY_NOTIFY_EVENT] =
2259 g_signal_new (I_("property-notify-event"),
2260 G_TYPE_FROM_CLASS (klass),
2262 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2263 _gtk_boolean_handled_accumulator, NULL,
2264 _gtk_marshal_BOOLEAN__BOXED,
2266 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2269 * GtkWidget::selection-clear-event:
2270 * @widget: the object which received the signal
2271 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2274 * The ::selection-clear-event signal will be emitted when the
2275 * the @widget's window has lost ownership of a selection.
2277 * Returns: %TRUE to stop other handlers from being invoked for the event.
2278 * %FALSE to propagate the event further.
2280 widget_signals[SELECTION_CLEAR_EVENT] =
2281 g_signal_new (I_("selection-clear-event"),
2282 G_TYPE_FROM_CLASS (klass),
2284 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2285 _gtk_boolean_handled_accumulator, NULL,
2286 _gtk_marshal_BOOLEAN__BOXED,
2288 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2291 * GtkWidget::selection-request-event:
2292 * @widget: the object which received the signal
2293 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2296 * The ::selection-request-event signal will be emitted when
2297 * another client requests ownership of the selection owned by
2298 * the @widget's window.
2300 * Returns: %TRUE to stop other handlers from being invoked for the event.
2301 * %FALSE to propagate the event further.
2303 widget_signals[SELECTION_REQUEST_EVENT] =
2304 g_signal_new (I_("selection-request-event"),
2305 G_TYPE_FROM_CLASS (klass),
2307 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2308 _gtk_boolean_handled_accumulator, NULL,
2309 _gtk_marshal_BOOLEAN__BOXED,
2311 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2314 * GtkWidget::selection-notify-event:
2315 * @widget: the object which received the signal.
2316 * @event: (type Gdk.EventSelection):
2318 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2320 widget_signals[SELECTION_NOTIFY_EVENT] =
2321 g_signal_new (I_("selection-notify-event"),
2322 G_TYPE_FROM_CLASS (klass),
2324 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2325 _gtk_boolean_handled_accumulator, NULL,
2326 _gtk_marshal_BOOLEAN__BOXED,
2328 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2331 * GtkWidget::selection-received:
2332 * @widget: the object which received the signal.
2336 widget_signals[SELECTION_RECEIVED] =
2337 g_signal_new (I_("selection-received"),
2338 G_TYPE_FROM_CLASS (klass),
2340 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2342 _gtk_marshal_VOID__BOXED_UINT,
2344 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2348 * GtkWidget::selection-get:
2349 * @widget: the object which received the signal.
2354 widget_signals[SELECTION_GET] =
2355 g_signal_new (I_("selection-get"),
2356 G_TYPE_FROM_CLASS (klass),
2358 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2360 _gtk_marshal_VOID__BOXED_UINT_UINT,
2362 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2367 * GtkWidget::proximity-in-event:
2368 * @widget: the object which received the signal
2369 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2372 * To receive this signal the #GdkWindow associated to the widget needs
2373 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2375 * This signal will be sent to the grab widget if there is one.
2377 * Returns: %TRUE to stop other handlers from being invoked for the event.
2378 * %FALSE to propagate the event further.
2380 widget_signals[PROXIMITY_IN_EVENT] =
2381 g_signal_new (I_("proximity-in-event"),
2382 G_TYPE_FROM_CLASS (klass),
2384 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2385 _gtk_boolean_handled_accumulator, NULL,
2386 _gtk_marshal_BOOLEAN__BOXED,
2388 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2391 * GtkWidget::proximity-out-event:
2392 * @widget: the object which received the signal
2393 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2396 * To receive this signal the #GdkWindow associated to the widget needs
2397 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2399 * This signal will be sent to the grab widget if there is one.
2401 * Returns: %TRUE to stop other handlers from being invoked for the event.
2402 * %FALSE to propagate the event further.
2404 widget_signals[PROXIMITY_OUT_EVENT] =
2405 g_signal_new (I_("proximity-out-event"),
2406 G_TYPE_FROM_CLASS (klass),
2408 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2409 _gtk_boolean_handled_accumulator, NULL,
2410 _gtk_marshal_BOOLEAN__BOXED,
2412 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2415 * GtkWidget::drag-leave:
2416 * @widget: the object which received the signal.
2417 * @drag_context: the drag context
2418 * @time: the timestamp of the motion event
2420 * The ::drag-leave signal is emitted on the drop site when the cursor
2421 * leaves the widget. A typical reason to connect to this signal is to
2422 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2423 * with gtk_drag_unhighlight()
2425 widget_signals[DRAG_LEAVE] =
2426 g_signal_new (I_("drag-leave"),
2427 G_TYPE_FROM_CLASS (klass),
2429 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2431 _gtk_marshal_VOID__OBJECT_UINT,
2433 GDK_TYPE_DRAG_CONTEXT,
2437 * GtkWidget::drag-begin:
2438 * @widget: the object which received the signal
2439 * @drag_context: the drag context
2441 * The ::drag-begin signal is emitted on the drag source when a drag is
2442 * started. A typical reason to connect to this signal is to set up a
2443 * custom drag icon with gtk_drag_source_set_icon().
2445 * Note that some widgets set up a drag icon in the default handler of
2446 * this signal, so you may have to use g_signal_connect_after() to
2447 * override what the default handler did.
2449 widget_signals[DRAG_BEGIN] =
2450 g_signal_new (I_("drag-begin"),
2451 G_TYPE_FROM_CLASS (klass),
2453 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2455 _gtk_marshal_VOID__OBJECT,
2457 GDK_TYPE_DRAG_CONTEXT);
2460 * GtkWidget::drag-end:
2461 * @widget: the object which received the signal
2462 * @drag_context: the drag context
2464 * The ::drag-end signal is emitted on the drag source when a drag is
2465 * finished. A typical reason to connect to this signal is to undo
2466 * things done in #GtkWidget::drag-begin.
2468 widget_signals[DRAG_END] =
2469 g_signal_new (I_("drag-end"),
2470 G_TYPE_FROM_CLASS (klass),
2472 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2474 _gtk_marshal_VOID__OBJECT,
2476 GDK_TYPE_DRAG_CONTEXT);
2479 * GtkWidget::drag-data-delete:
2480 * @widget: the object which received the signal
2481 * @drag_context: the drag context
2483 * The ::drag-data-delete signal is emitted on the drag source when a drag
2484 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2485 * handler is responsible for deleting the data that has been dropped. What
2486 * "delete" means depends on the context of the drag operation.
2488 widget_signals[DRAG_DATA_DELETE] =
2489 g_signal_new (I_("drag-data-delete"),
2490 G_TYPE_FROM_CLASS (klass),
2492 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2494 _gtk_marshal_VOID__OBJECT,
2496 GDK_TYPE_DRAG_CONTEXT);
2499 * GtkWidget::drag-failed:
2500 * @widget: the object which received the signal
2501 * @drag_context: the drag context
2502 * @result: the result of the drag operation
2504 * The ::drag-failed signal is emitted on the drag source when a drag has
2505 * failed. The signal handler may hook custom code to handle a failed DND
2506 * operation based on the type of error, it returns %TRUE is the failure has
2507 * been already handled (not showing the default "drag operation failed"
2508 * animation), otherwise it returns %FALSE.
2510 * Return value: %TRUE if the failed drag operation has been already handled.
2514 widget_signals[DRAG_FAILED] =
2515 g_signal_new (I_("drag-failed"),
2516 G_TYPE_FROM_CLASS (klass),
2518 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2519 _gtk_boolean_handled_accumulator, NULL,
2520 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2522 GDK_TYPE_DRAG_CONTEXT,
2523 GTK_TYPE_DRAG_RESULT);
2526 * GtkWidget::drag-motion:
2527 * @widget: the object which received the signal
2528 * @drag_context: the drag context
2529 * @x: the x coordinate of the current cursor position
2530 * @y: the y coordinate of the current cursor position
2531 * @time: the timestamp of the motion event
2532 * @returns: whether the cursor position is in a drop zone
2534 * The drag-motion signal is emitted on the drop site when the user
2535 * moves the cursor over the widget during a drag. The signal handler
2536 * must determine whether the cursor position is in a drop zone or not.
2537 * If it is not in a drop zone, it returns %FALSE and no further processing
2538 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2539 * handler is responsible for providing the necessary information for
2540 * displaying feedback to the user, by calling gdk_drag_status().
2542 * If the decision whether the drop will be accepted or rejected can't be
2543 * made based solely on the cursor position and the type of the data, the
2544 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2545 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2546 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2547 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2548 * when using the drag-motion signal that way.
2550 * Also note that there is no drag-enter signal. The drag receiver has to
2551 * keep track of whether he has received any drag-motion signals since the
2552 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2553 * an "enter" signal. Upon an "enter", the handler will typically highlight
2554 * the drop site with gtk_drag_highlight().
2557 * drag_motion (GtkWidget *widget,
2558 * GdkDragContext *context,
2565 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2567 * if (!private_data->drag_highlight)
2569 * private_data->drag_highlight = 1;
2570 * gtk_drag_highlight (widget);
2573 * target = gtk_drag_dest_find_target (widget, context, NULL);
2574 * if (target == GDK_NONE)
2575 * gdk_drag_status (context, 0, time);
2578 * private_data->pending_status = context->suggested_action;
2579 * gtk_drag_get_data (widget, context, target, time);
2586 * drag_data_received (GtkWidget *widget,
2587 * GdkDragContext *context,
2590 * GtkSelectionData *selection_data,
2594 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2596 * if (private_data->suggested_action)
2598 * private_data->suggested_action = 0;
2600 * /* We are getting this data due to a request in drag_motion,
2601 * * rather than due to a request in drag_drop, so we are just
2602 * * supposed to call gdk_drag_status (), not actually paste in
2605 * str = gtk_selection_data_get_text (selection_data);
2606 * if (!data_is_acceptable (str))
2607 * gdk_drag_status (context, 0, time);
2609 * gdk_drag_status (context, private_data->suggested_action, time);
2613 * /* accept the drop */
2618 widget_signals[DRAG_MOTION] =
2619 g_signal_new (I_("drag-motion"),
2620 G_TYPE_FROM_CLASS (klass),
2622 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2623 _gtk_boolean_handled_accumulator, NULL,
2624 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2626 GDK_TYPE_DRAG_CONTEXT,
2632 * GtkWidget::drag-drop:
2633 * @widget: the object which received the signal
2634 * @drag_context: the drag context
2635 * @x: the x coordinate of the current cursor position
2636 * @y: the y coordinate of the current cursor position
2637 * @time: the timestamp of the motion event
2638 * @returns: whether the cursor position is in a drop zone
2640 * The ::drag-drop signal is emitted on the drop site when the user drops
2641 * the data onto the widget. The signal handler must determine whether
2642 * the cursor position is in a drop zone or not. If it is not in a drop
2643 * zone, it returns %FALSE and no further processing is necessary.
2644 * Otherwise, the handler returns %TRUE. In this case, the handler must
2645 * ensure that gtk_drag_finish() is called to let the source know that
2646 * the drop is done. The call to gtk_drag_finish() can be done either
2647 * directly or in a #GtkWidget::drag-data-received handler which gets
2648 * triggered by calling gtk_drag_get_data() to receive the data for one
2649 * or more of the supported targets.
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 * @Varargs: 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 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
4823 !GTK_IS_SCROLLABLE (widget))
4824 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
4825 "Allocation is %dx%d, but minimum required size is %dx%d.",
4826 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
4827 G_OBJECT_TYPE_NAME (widget), widget,
4828 real_allocation.width, real_allocation.height,
4829 min_width, min_height);
4830 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4831 * allocated sizes and possibly limit them to the natural sizes */
4832 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4833 GTK_ORIENTATION_HORIZONTAL,
4836 &adjusted_allocation.x,
4837 &adjusted_allocation.width);
4838 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4839 GTK_ORIENTATION_VERTICAL,
4842 &adjusted_allocation.y,
4843 &adjusted_allocation.height);
4845 if (adjusted_allocation.x < real_allocation.x ||
4846 adjusted_allocation.y < real_allocation.y ||
4847 (adjusted_allocation.x + adjusted_allocation.width) >
4848 (real_allocation.x + real_allocation.width) ||
4849 (adjusted_allocation.y + adjusted_allocation.height >
4850 real_allocation.y + real_allocation.height))
4852 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",
4853 G_OBJECT_TYPE_NAME (widget), widget,
4854 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4855 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4856 adjusted_allocation = real_allocation; /* veto it */
4860 real_allocation = adjusted_allocation;
4863 if (real_allocation.width < 0 || real_allocation.height < 0)
4865 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4866 real_allocation.width,
4867 real_allocation.height);
4870 real_allocation.width = MAX (real_allocation.width, 1);
4871 real_allocation.height = MAX (real_allocation.height, 1);
4873 size_changed = (old_allocation.width != real_allocation.width ||
4874 old_allocation.height != real_allocation.height);
4875 position_changed = (old_allocation.x != real_allocation.x ||
4876 old_allocation.y != real_allocation.y);
4878 if (!alloc_needed && !size_changed && !position_changed)
4881 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4883 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4884 priv->width_request_needed = FALSE;
4885 priv->height_request_needed = FALSE;
4886 priv->alloc_needed = FALSE;
4888 if (gtk_widget_get_mapped (widget))
4890 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4892 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4894 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4895 cairo_region_union_rectangle (invalidate, &old_allocation);
4897 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4898 cairo_region_destroy (invalidate);
4903 if (priv->redraw_on_alloc)
4905 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4907 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4908 cairo_region_union_rectangle (invalidate, &old_allocation);
4910 gtk_widget_invalidate_widget_windows (widget, invalidate);
4911 cairo_region_destroy (invalidate);
4915 if (size_changed || position_changed)
4917 GtkStyleContext *context;
4919 context = gtk_widget_get_style_context (widget);
4920 _gtk_style_context_invalidate_animation_areas (context);
4924 if ((size_changed || position_changed) && priv->parent &&
4925 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4927 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4928 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4929 cairo_region_destroy (invalidate);
4933 gtk_widget_pop_verify_invariants (widget);
4937 * gtk_widget_common_ancestor:
4938 * @widget_a: a #GtkWidget
4939 * @widget_b: a #GtkWidget
4941 * Find the common ancestor of @widget_a and @widget_b that
4942 * is closest to the two widgets.
4944 * Return value: the closest common ancestor of @widget_a and
4945 * @widget_b or %NULL if @widget_a and @widget_b do not
4946 * share a common ancestor.
4949 gtk_widget_common_ancestor (GtkWidget *widget_a,
4950 GtkWidget *widget_b)
4952 GtkWidget *parent_a;
4953 GtkWidget *parent_b;
4957 parent_a = widget_a;
4958 while (parent_a->priv->parent)
4960 parent_a = parent_a->priv->parent;
4964 parent_b = widget_b;
4965 while (parent_b->priv->parent)
4967 parent_b = parent_b->priv->parent;
4971 if (parent_a != parent_b)
4974 while (depth_a > depth_b)
4976 widget_a = widget_a->priv->parent;
4980 while (depth_b > depth_a)
4982 widget_b = widget_b->priv->parent;
4986 while (widget_a != widget_b)
4988 widget_a = widget_a->priv->parent;
4989 widget_b = widget_b->priv->parent;
4996 * gtk_widget_translate_coordinates:
4997 * @src_widget: a #GtkWidget
4998 * @dest_widget: a #GtkWidget
4999 * @src_x: X position relative to @src_widget
5000 * @src_y: Y position relative to @src_widget
5001 * @dest_x: (out): location to store X position relative to @dest_widget
5002 * @dest_y: (out): location to store Y position relative to @dest_widget
5004 * Translate coordinates relative to @src_widget's allocation to coordinates
5005 * relative to @dest_widget's allocations. In order to perform this
5006 * operation, both widgets must be realized, and must share a common
5009 * Return value: %FALSE if either widget was not realized, or there
5010 * was no common ancestor. In this case, nothing is stored in
5011 * *@dest_x and *@dest_y. Otherwise %TRUE.
5014 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5015 GtkWidget *dest_widget,
5021 GtkWidgetPrivate *src_priv = src_widget->priv;
5022 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5023 GtkWidget *ancestor;
5025 GList *dest_list = NULL;
5027 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5028 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5030 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5031 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5034 /* Translate from allocation relative to window relative */
5035 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5038 gdk_window_get_position (src_priv->window, &wx, &wy);
5040 src_x -= wx - src_priv->allocation.x;
5041 src_y -= wy - src_priv->allocation.y;
5045 src_x += src_priv->allocation.x;
5046 src_y += src_priv->allocation.y;
5049 /* Translate to the common ancestor */
5050 window = src_priv->window;
5051 while (window != ancestor->priv->window)
5055 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5060 window = gdk_window_get_effective_parent (window);
5062 if (!window) /* Handle GtkHandleBox */
5067 window = dest_priv->window;
5068 while (window != ancestor->priv->window)
5070 dest_list = g_list_prepend (dest_list, window);
5072 window = gdk_window_get_effective_parent (window);
5074 if (!window) /* Handle GtkHandleBox */
5076 g_list_free (dest_list);
5085 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5090 dest_list = g_list_remove (dest_list, dest_list->data);
5093 /* Translate from window relative to allocation relative */
5094 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5097 gdk_window_get_position (dest_priv->window, &wx, &wy);
5099 src_x += wx - dest_priv->allocation.x;
5100 src_y += wy - dest_priv->allocation.y;
5104 src_x -= dest_priv->allocation.x;
5105 src_y -= dest_priv->allocation.y;
5117 gtk_widget_real_size_allocate (GtkWidget *widget,
5118 GtkAllocation *allocation)
5120 GtkWidgetPrivate *priv = widget->priv;
5122 priv->allocation = *allocation;
5124 if (gtk_widget_get_realized (widget) &&
5125 gtk_widget_get_has_window (widget))
5127 gdk_window_move_resize (priv->window,
5128 allocation->x, allocation->y,
5129 allocation->width, allocation->height);
5133 /* translate initial/final into start/end */
5135 effective_align (GtkAlign align,
5136 GtkTextDirection direction)
5140 case GTK_ALIGN_START:
5141 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5143 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5150 adjust_for_align (GtkAlign align,
5152 gint *allocated_pos,
5153 gint *allocated_size)
5157 case GTK_ALIGN_FILL:
5158 /* change nothing */
5160 case GTK_ALIGN_START:
5161 /* keep *allocated_pos where it is */
5162 *allocated_size = MIN (*allocated_size, *natural_size);
5165 if (*allocated_size > *natural_size)
5167 *allocated_pos += (*allocated_size - *natural_size);
5168 *allocated_size = *natural_size;
5171 case GTK_ALIGN_CENTER:
5172 if (*allocated_size > *natural_size)
5174 *allocated_pos += (*allocated_size - *natural_size) / 2;
5175 *allocated_size = MIN (*allocated_size, *natural_size);
5182 adjust_for_margin(gint start_margin,
5186 gint *allocated_pos,
5187 gint *allocated_size)
5189 *minimum_size -= (start_margin + end_margin);
5190 *natural_size -= (start_margin + end_margin);
5191 *allocated_pos += start_margin;
5192 *allocated_size -= (start_margin + end_margin);
5196 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5197 GtkOrientation orientation,
5200 gint *allocated_pos,
5201 gint *allocated_size)
5203 const GtkWidgetAuxInfo *aux_info;
5205 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5207 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5209 adjust_for_margin (aux_info->margin.left,
5210 aux_info->margin.right,
5211 minimum_size, natural_size,
5212 allocated_pos, allocated_size);
5213 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5214 natural_size, allocated_pos, allocated_size);
5218 adjust_for_margin (aux_info->margin.top,
5219 aux_info->margin.bottom,
5220 minimum_size, natural_size,
5221 allocated_pos, allocated_size);
5222 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5223 natural_size, allocated_pos, allocated_size);
5228 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5231 GtkWidgetPrivate *priv = widget->priv;
5233 /* widgets must be onscreen for accels to take effect */
5234 return gtk_widget_is_sensitive (widget) &&
5235 gtk_widget_is_drawable (widget) &&
5236 gdk_window_is_viewable (priv->window);
5240 * gtk_widget_can_activate_accel:
5241 * @widget: a #GtkWidget
5242 * @signal_id: the ID of a signal installed on @widget
5244 * Determines whether an accelerator that activates the signal
5245 * identified by @signal_id can currently be activated.
5246 * This is done by emitting the #GtkWidget::can-activate-accel
5247 * signal on @widget; if the signal isn't overridden by a
5248 * handler or in a derived widget, then the default check is
5249 * that the widget must be sensitive, and the widget and all
5250 * its ancestors mapped.
5252 * Return value: %TRUE if the accelerator can be activated.
5257 gtk_widget_can_activate_accel (GtkWidget *widget,
5260 gboolean can_activate = FALSE;
5261 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5262 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5263 return can_activate;
5272 closure_accel_activate (GClosure *closure,
5273 GValue *return_value,
5274 guint n_param_values,
5275 const GValue *param_values,
5276 gpointer invocation_hint,
5277 gpointer marshal_data)
5279 AccelClosure *aclosure = (AccelClosure*) closure;
5280 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5283 g_signal_emit (closure->data, aclosure->signal_id, 0);
5285 /* whether accelerator was handled */
5286 g_value_set_boolean (return_value, can_activate);
5290 closures_destroy (gpointer data)
5292 GSList *slist, *closures = data;
5294 for (slist = closures; slist; slist = slist->next)
5296 g_closure_invalidate (slist->data);
5297 g_closure_unref (slist->data);
5299 g_slist_free (closures);
5303 widget_new_accel_closure (GtkWidget *widget,
5306 AccelClosure *aclosure;
5307 GClosure *closure = NULL;
5308 GSList *slist, *closures;
5310 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5311 for (slist = closures; slist; slist = slist->next)
5312 if (!gtk_accel_group_from_accel_closure (slist->data))
5314 /* reuse this closure */
5315 closure = slist->data;
5320 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5321 closures = g_slist_prepend (closures, g_closure_ref (closure));
5322 g_closure_sink (closure);
5323 g_closure_set_marshal (closure, closure_accel_activate);
5325 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5327 aclosure = (AccelClosure*) closure;
5328 g_assert (closure->data == widget);
5329 g_assert (closure->marshal == closure_accel_activate);
5330 aclosure->signal_id = signal_id;
5336 * gtk_widget_add_accelerator
5337 * @widget: widget to install an accelerator on
5338 * @accel_signal: widget signal to emit on accelerator activation
5339 * @accel_group: accel group for this widget, added to its toplevel
5340 * @accel_key: GDK keyval of the accelerator
5341 * @accel_mods: modifier key combination of the accelerator
5342 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5344 * Installs an accelerator for this @widget in @accel_group that causes
5345 * @accel_signal to be emitted if the accelerator is activated.
5346 * The @accel_group needs to be added to the widget's toplevel via
5347 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5348 * Accelerators added through this function are not user changeable during
5349 * runtime. If you want to support accelerators that can be changed by the
5350 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5351 * gtk_menu_item_set_accel_path() instead.
5354 gtk_widget_add_accelerator (GtkWidget *widget,
5355 const gchar *accel_signal,
5356 GtkAccelGroup *accel_group,
5358 GdkModifierType accel_mods,
5359 GtkAccelFlags accel_flags)
5364 g_return_if_fail (GTK_IS_WIDGET (widget));
5365 g_return_if_fail (accel_signal != NULL);
5366 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5368 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5369 if (!query.signal_id ||
5370 !(query.signal_flags & G_SIGNAL_ACTION) ||
5371 query.return_type != G_TYPE_NONE ||
5374 /* hmm, should be elaborate enough */
5375 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5376 G_OBJECT_TYPE_NAME (widget), accel_signal);
5380 closure = widget_new_accel_closure (widget, query.signal_id);
5382 g_object_ref (widget);
5384 /* install the accelerator. since we don't map this onto an accel_path,
5385 * the accelerator will automatically be locked.
5387 gtk_accel_group_connect (accel_group,
5390 accel_flags | GTK_ACCEL_LOCKED,
5393 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5395 g_object_unref (widget);
5399 * gtk_widget_remove_accelerator:
5400 * @widget: widget to install an accelerator on
5401 * @accel_group: accel group for this widget
5402 * @accel_key: GDK keyval of the accelerator
5403 * @accel_mods: modifier key combination of the accelerator
5404 * @returns: whether an accelerator was installed and could be removed
5406 * Removes an accelerator from @widget, previously installed with
5407 * gtk_widget_add_accelerator().
5410 gtk_widget_remove_accelerator (GtkWidget *widget,
5411 GtkAccelGroup *accel_group,
5413 GdkModifierType accel_mods)
5415 GtkAccelGroupEntry *ag_entry;
5416 GList *slist, *clist;
5419 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5420 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5422 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5423 clist = gtk_widget_list_accel_closures (widget);
5424 for (slist = clist; slist; slist = slist->next)
5428 for (i = 0; i < n; i++)
5429 if (slist->data == (gpointer) ag_entry[i].closure)
5431 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5433 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5435 g_list_free (clist);
5440 g_list_free (clist);
5442 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5443 accel_key, accel_mods, accel_group,
5444 G_OBJECT_TYPE_NAME (widget), widget);
5450 * gtk_widget_list_accel_closures:
5451 * @widget: widget to list accelerator closures for
5453 * Lists the closures used by @widget for accelerator group connections
5454 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5455 * The closures can be used to monitor accelerator changes on @widget,
5456 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5457 * #GtkAccelGroup of a closure which can be found out with
5458 * gtk_accel_group_from_accel_closure().
5460 * Return value: (transfer container) (element-type GClosure):
5461 * a newly allocated #GList of closures
5464 gtk_widget_list_accel_closures (GtkWidget *widget)
5467 GList *clist = NULL;
5469 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5471 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5472 if (gtk_accel_group_from_accel_closure (slist->data))
5473 clist = g_list_prepend (clist, slist->data);
5479 GtkAccelGroup *accel_group;
5484 destroy_accel_path (gpointer data)
5486 AccelPath *apath = data;
5488 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5490 /* closures_destroy takes care of unrefing the closure */
5491 g_object_unref (apath->accel_group);
5493 g_slice_free (AccelPath, apath);
5498 * gtk_widget_set_accel_path:
5499 * @widget: a #GtkWidget
5500 * @accel_path: (allow-none): path used to look up the accelerator
5501 * @accel_group: (allow-none): a #GtkAccelGroup.
5503 * Given an accelerator group, @accel_group, and an accelerator path,
5504 * @accel_path, sets up an accelerator in @accel_group so whenever the
5505 * key binding that is defined for @accel_path is pressed, @widget
5506 * will be activated. This removes any accelerators (for any
5507 * accelerator group) installed by previous calls to
5508 * gtk_widget_set_accel_path(). Associating accelerators with
5509 * paths allows them to be modified by the user and the modifications
5510 * to be saved for future use. (See gtk_accel_map_save().)
5512 * This function is a low level function that would most likely
5513 * be used by a menu creation system like #GtkUIManager. If you
5514 * use #GtkUIManager, setting up accelerator paths will be done
5517 * Even when you you aren't using #GtkUIManager, if you only want to
5518 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5519 * provides a somewhat more convenient interface.
5521 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5522 * pass a static string, you can save some memory by interning it first with
5523 * g_intern_static_string().
5526 gtk_widget_set_accel_path (GtkWidget *widget,
5527 const gchar *accel_path,
5528 GtkAccelGroup *accel_group)
5532 g_return_if_fail (GTK_IS_WIDGET (widget));
5533 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5537 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5538 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5540 gtk_accel_map_add_entry (accel_path, 0, 0);
5541 apath = g_slice_new (AccelPath);
5542 apath->accel_group = g_object_ref (accel_group);
5543 apath->path_quark = g_quark_from_string (accel_path);
5544 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5549 /* also removes possible old settings */
5550 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5553 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5555 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5559 _gtk_widget_get_accel_path (GtkWidget *widget,
5564 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5566 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5568 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5569 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5573 * gtk_widget_mnemonic_activate:
5574 * @widget: a #GtkWidget
5575 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5577 * Emits the #GtkWidget::mnemonic-activate signal.
5579 * The default handler for this signal activates the @widget if
5580 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5583 * Returns: %TRUE if the signal has been handled
5586 gtk_widget_mnemonic_activate (GtkWidget *widget,
5587 gboolean group_cycling)
5591 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5593 group_cycling = group_cycling != FALSE;
5594 if (!gtk_widget_is_sensitive (widget))
5597 g_signal_emit (widget,
5598 widget_signals[MNEMONIC_ACTIVATE],
5606 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5607 gboolean group_cycling)
5609 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5610 gtk_widget_activate (widget);
5611 else if (gtk_widget_get_can_focus (widget))
5612 gtk_widget_grab_focus (widget);
5615 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5616 G_OBJECT_TYPE_NAME (widget));
5617 gtk_widget_error_bell (widget);
5622 static const cairo_user_data_key_t event_key;
5625 _gtk_cairo_get_event (cairo_t *cr)
5627 g_return_val_if_fail (cr != NULL, NULL);
5629 return cairo_get_user_data (cr, &event_key);
5633 gtk_cairo_set_event (cairo_t *cr,
5634 GdkEventExpose *event)
5636 cairo_set_user_data (cr, &event_key, event, NULL);
5640 * gtk_cairo_should_draw_window:
5641 * @cr: a cairo context
5642 * @window: the window to check. @window may not be an input-only
5645 * This function is supposed to be called in #GtkWidget::draw
5646 * implementations for widgets that support multiple windows.
5647 * @cr must be untransformed from invoking of the draw function.
5648 * This function will return %TRUE if the contents of the given
5649 * @window are supposed to be drawn and %FALSE otherwise. Note
5650 * that when the drawing was not initiated by the windowing
5651 * system this function will return %TRUE for all windows, so
5652 * you need to draw the bottommost window first. Also, do not
5653 * use "else if" statements to check which window should be drawn.
5655 * Returns: %TRUE if @window should be drawn
5660 gtk_cairo_should_draw_window (cairo_t *cr,
5663 GdkEventExpose *event;
5665 g_return_val_if_fail (cr != NULL, FALSE);
5666 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5668 event = _gtk_cairo_get_event (cr);
5670 return event == NULL ||
5671 event->window == window;
5675 gtk_widget_get_clip_draw (GtkWidget *widget)
5677 /* labels are not clipped, because clipping them would cause
5678 * mnemonics to not appear on characters that go beyond the
5680 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
5682 if (GTK_IS_LABEL (widget))
5688 /* code shared by gtk_container_propagate_draw() and
5692 _gtk_widget_draw_internal (GtkWidget *widget,
5694 gboolean clip_to_size)
5696 GtkStyleContext *context;
5698 if (!gtk_widget_is_drawable (widget))
5701 clip_to_size &= gtk_widget_get_clip_draw (widget);
5705 cairo_rectangle (cr,
5707 widget->priv->allocation.width,
5708 widget->priv->allocation.height);
5712 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5716 g_signal_emit (widget, widget_signals[DRAW],
5721 context = gtk_widget_get_style_context (widget);
5722 _gtk_style_context_coalesce_animation_areas (context, widget);
5727 * @widget: the widget to draw. It must be drawable (see
5728 * gtk_widget_is_drawable()) and a size must have been allocated.
5729 * @cr: a cairo context to draw to
5731 * Draws @widget to @cr. The top left corner of the widget will be
5732 * drawn to the currently set origin point of @cr.
5734 * You should pass a cairo context as @cr argument that is in an
5735 * original state. Otherwise the resulting drawing is undefined. For
5736 * example changing the operator using cairo_set_operator() or the
5737 * line width using cairo_set_line_width() might have unwanted side
5739 * You may however change the context's transform matrix - like with
5740 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5741 * region with cairo_clip() prior to calling this function. Also, it
5742 * is fine to modify the context with cairo_save() and
5743 * cairo_push_group() prior to calling this function.
5745 * <note><para>Special purpose widgets may contain special code for
5746 * rendering to the screen and might appear differently on screen
5747 * and when rendered using gtk_widget_draw().</para></note>
5752 gtk_widget_draw (GtkWidget *widget,
5755 GdkEventExpose *tmp_event;
5757 g_return_if_fail (GTK_IS_WIDGET (widget));
5758 g_return_if_fail (!widget->priv->alloc_needed);
5759 g_return_if_fail (cr != NULL);
5762 /* We have to reset the event here so that draw functions can call
5763 * gtk_widget_draw() on random other widgets and get the desired
5764 * effect: Drawing all contents, not just the current window.
5766 tmp_event = _gtk_cairo_get_event (cr);
5767 gtk_cairo_set_event (cr, NULL);
5769 _gtk_widget_draw_internal (widget, cr, TRUE);
5771 gtk_cairo_set_event (cr, tmp_event);
5776 gtk_widget_real_key_press_event (GtkWidget *widget,
5779 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5783 gtk_widget_real_key_release_event (GtkWidget *widget,
5786 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5790 gtk_widget_real_focus_in_event (GtkWidget *widget,
5791 GdkEventFocus *event)
5793 gtk_widget_queue_shallow_draw (widget);
5799 gtk_widget_real_focus_out_event (GtkWidget *widget,
5800 GdkEventFocus *event)
5802 gtk_widget_queue_shallow_draw (widget);
5807 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5808 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5812 * @widget: a #GtkWidget
5813 * @event: a #GdkEvent
5815 * Rarely-used function. This function is used to emit
5816 * the event signals on a widget (those signals should never
5817 * be emitted without using this function to do so).
5818 * If you want to synthesize an event though, don't use this function;
5819 * instead, use gtk_main_do_event() so the event will behave as if
5820 * it were in the event queue. Don't synthesize expose events; instead,
5821 * use gdk_window_invalidate_rect() to invalidate a region of the
5824 * Return value: return from the event signal emission (%TRUE if
5825 * the event was handled)
5828 gtk_widget_event (GtkWidget *widget,
5831 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5832 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5834 if (event->type == GDK_EXPOSE)
5836 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5837 "the same effect, call gdk_window_invalidate_rect/region(), "
5838 "followed by gdk_window_process_updates().");
5842 return gtk_widget_event_internal (widget, event);
5845 /* Returns TRUE if a translation should be done */
5847 _gtk_widget_get_translation_to_window (GtkWidget *widget,
5852 GdkWindow *w, *widget_window;
5854 if (!gtk_widget_get_has_window (widget))
5856 *x = -widget->priv->allocation.x;
5857 *y = -widget->priv->allocation.y;
5865 widget_window = gtk_widget_get_window (widget);
5867 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5870 gdk_window_get_position (w, &wx, &wy);
5887 * gtk_cairo_transform_to_window:
5888 * @cr: the cairo context to transform
5889 * @widget: the widget the context is currently centered for
5890 * @window: the window to transform the context to
5892 * Transforms the given cairo context @cr that from @widget-relative
5893 * coordinates to @window-relative coordinates.
5894 * If the @widget's window is not an ancestor of @window, no
5895 * modification will be applied.
5897 * This is the inverse to the transformation GTK applies when
5898 * preparing an expose event to be emitted with the #GtkWidget::draw
5899 * signal. It is intended to help porting multiwindow widgets from
5900 * GTK+ 2 to the rendering architecture of GTK+ 3.
5905 gtk_cairo_transform_to_window (cairo_t *cr,
5911 g_return_if_fail (cr != NULL);
5912 g_return_if_fail (GTK_IS_WIDGET (widget));
5913 g_return_if_fail (GDK_IS_WINDOW (window));
5915 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
5916 cairo_translate (cr, x, y);
5920 * gtk_widget_send_expose:
5921 * @widget: a #GtkWidget
5922 * @event: a expose #GdkEvent
5924 * Very rarely-used function. This function is used to emit
5925 * an expose event on a widget. This function is not normally used
5926 * directly. The only time it is used is when propagating an expose
5927 * event to a child %NO_WINDOW widget, and that is normally done
5928 * using gtk_container_propagate_draw().
5930 * If you want to force an area of a window to be redrawn,
5931 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5932 * To cause the redraw to be done immediately, follow that call
5933 * with a call to gdk_window_process_updates().
5935 * Return value: return from the event signal emission (%TRUE if
5936 * the event was handled)
5939 gtk_widget_send_expose (GtkWidget *widget,
5942 gboolean result = FALSE;
5947 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5948 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5949 g_return_val_if_fail (event != NULL, TRUE);
5950 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5952 cr = gdk_cairo_create (event->expose.window);
5953 gtk_cairo_set_event (cr, &event->expose);
5955 gdk_cairo_region (cr, event->expose.region);
5958 do_clip = _gtk_widget_get_translation_to_window (widget,
5959 event->expose.window,
5961 cairo_translate (cr, -x, -y);
5963 _gtk_widget_draw_internal (widget, cr, do_clip);
5965 /* unset here, so if someone keeps a reference to cr we
5966 * don't leak the window. */
5967 gtk_cairo_set_event (cr, NULL);
5974 event_window_is_still_viewable (GdkEvent *event)
5976 /* Check that we think the event's window is viewable before
5977 * delivering the event, to prevent suprises. We do this here
5978 * at the last moment, since the event may have been queued
5979 * up behind other events, held over a recursive main loop, etc.
5981 switch (event->type)
5984 case GDK_MOTION_NOTIFY:
5985 case GDK_BUTTON_PRESS:
5986 case GDK_2BUTTON_PRESS:
5987 case GDK_3BUTTON_PRESS:
5989 case GDK_ENTER_NOTIFY:
5990 case GDK_PROXIMITY_IN:
5992 return event->any.window && gdk_window_is_viewable (event->any.window);
5995 /* The following events are the second half of paired events;
5996 * we always deliver them to deal with widgets that clean up
5997 * on the second half.
5999 case GDK_BUTTON_RELEASE:
6000 case GDK_KEY_RELEASE:
6001 case GDK_LEAVE_NOTIFY:
6002 case GDK_PROXIMITY_OUT:
6006 /* Remaining events would make sense on an not-viewable window,
6007 * or don't have an associated window.
6014 gtk_widget_event_internal (GtkWidget *widget,
6017 gboolean return_val = FALSE;
6019 /* We check only once for is-still-visible; if someone
6020 * hides the window in on of the signals on the widget,
6021 * they are responsible for returning TRUE to terminate
6024 if (!event_window_is_still_viewable (event))
6027 g_object_ref (widget);
6029 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6030 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6035 switch (event->type)
6041 case GDK_BUTTON_PRESS:
6042 case GDK_2BUTTON_PRESS:
6043 case GDK_3BUTTON_PRESS:
6044 signal_num = BUTTON_PRESS_EVENT;
6047 signal_num = SCROLL_EVENT;
6049 case GDK_BUTTON_RELEASE:
6050 signal_num = BUTTON_RELEASE_EVENT;
6052 case GDK_MOTION_NOTIFY:
6053 signal_num = MOTION_NOTIFY_EVENT;
6056 signal_num = DELETE_EVENT;
6059 signal_num = DESTROY_EVENT;
6060 _gtk_tooltip_hide (widget);
6063 signal_num = KEY_PRESS_EVENT;
6065 case GDK_KEY_RELEASE:
6066 signal_num = KEY_RELEASE_EVENT;
6068 case GDK_ENTER_NOTIFY:
6069 signal_num = ENTER_NOTIFY_EVENT;
6071 case GDK_LEAVE_NOTIFY:
6072 signal_num = LEAVE_NOTIFY_EVENT;
6074 case GDK_FOCUS_CHANGE:
6075 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6076 if (event->focus_change.in)
6077 _gtk_tooltip_focus_in (widget);
6079 _gtk_tooltip_focus_out (widget);
6082 signal_num = CONFIGURE_EVENT;
6085 signal_num = MAP_EVENT;
6088 signal_num = UNMAP_EVENT;
6090 case GDK_WINDOW_STATE:
6091 signal_num = WINDOW_STATE_EVENT;
6093 case GDK_PROPERTY_NOTIFY:
6094 signal_num = PROPERTY_NOTIFY_EVENT;
6096 case GDK_SELECTION_CLEAR:
6097 signal_num = SELECTION_CLEAR_EVENT;
6099 case GDK_SELECTION_REQUEST:
6100 signal_num = SELECTION_REQUEST_EVENT;
6102 case GDK_SELECTION_NOTIFY:
6103 signal_num = SELECTION_NOTIFY_EVENT;
6105 case GDK_PROXIMITY_IN:
6106 signal_num = PROXIMITY_IN_EVENT;
6108 case GDK_PROXIMITY_OUT:
6109 signal_num = PROXIMITY_OUT_EVENT;
6111 case GDK_VISIBILITY_NOTIFY:
6112 signal_num = VISIBILITY_NOTIFY_EVENT;
6114 case GDK_GRAB_BROKEN:
6115 signal_num = GRAB_BROKEN_EVENT;
6118 signal_num = DAMAGE_EVENT;
6121 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6125 if (signal_num != -1)
6126 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6128 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6129 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6133 g_object_unref (widget);
6139 * gtk_widget_activate:
6140 * @widget: a #GtkWidget that's activatable
6142 * For widgets that can be "activated" (buttons, menu items, etc.)
6143 * this function activates them. Activation is what happens when you
6144 * press Enter on a widget during key navigation. If @widget isn't
6145 * activatable, the function returns %FALSE.
6147 * Return value: %TRUE if the widget was activatable
6150 gtk_widget_activate (GtkWidget *widget)
6152 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6154 if (WIDGET_CLASS (widget)->activate_signal)
6156 /* FIXME: we should eventually check the signals signature here */
6157 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6166 gtk_widget_reparent_subwindows (GtkWidget *widget,
6167 GdkWindow *new_window)
6169 GtkWidgetPrivate *priv = widget->priv;
6171 if (!gtk_widget_get_has_window (widget))
6173 GList *children = gdk_window_get_children (priv->window);
6176 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6178 GdkWindow *window = tmp_list->data;
6181 gdk_window_get_user_data (window, &child);
6182 while (child && child != widget)
6183 child = ((GtkWidget*) child)->priv->parent;
6186 gdk_window_reparent (window, new_window, 0, 0);
6189 g_list_free (children);
6194 GList *tmp_list, *children;
6196 parent = gdk_window_get_parent (priv->window);
6199 gdk_window_reparent (priv->window, new_window, 0, 0);
6202 children = gdk_window_get_children (parent);
6204 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6206 GdkWindow *window = tmp_list->data;
6209 gdk_window_get_user_data (window, &child);
6211 if (child == widget)
6212 gdk_window_reparent (window, new_window, 0, 0);
6215 g_list_free (children);
6221 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6222 gpointer client_data)
6224 GtkWidgetPrivate *priv = widget->priv;
6226 g_assert (client_data != NULL);
6228 if (!gtk_widget_get_has_window (widget))
6231 g_object_unref (priv->window);
6232 priv->window = (GdkWindow*) client_data;
6234 g_object_ref (priv->window);
6236 if (GTK_IS_CONTAINER (widget))
6237 gtk_container_forall (GTK_CONTAINER (widget),
6238 gtk_widget_reparent_fixup_child,
6244 * gtk_widget_reparent:
6245 * @widget: a #GtkWidget
6246 * @new_parent: a #GtkContainer to move the widget into
6248 * Moves a widget from one #GtkContainer to another, handling reference
6249 * count issues to avoid destroying the widget.
6252 gtk_widget_reparent (GtkWidget *widget,
6253 GtkWidget *new_parent)
6255 GtkWidgetPrivate *priv;
6257 g_return_if_fail (GTK_IS_WIDGET (widget));
6258 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6259 priv = widget->priv;
6260 g_return_if_fail (priv->parent != NULL);
6262 if (priv->parent != new_parent)
6264 /* First try to see if we can get away without unrealizing
6265 * the widget as we reparent it. if so we set a flag so
6266 * that gtk_widget_unparent doesn't unrealize widget
6268 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6269 priv->in_reparent = TRUE;
6271 g_object_ref (widget);
6272 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6273 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6274 g_object_unref (widget);
6276 if (priv->in_reparent)
6278 priv->in_reparent = FALSE;
6280 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6281 gtk_widget_reparent_fixup_child (widget,
6282 gtk_widget_get_parent_window (widget));
6285 g_object_notify (G_OBJECT (widget), "parent");
6290 * gtk_widget_intersect:
6291 * @widget: a #GtkWidget
6292 * @area: a rectangle
6293 * @intersection: rectangle to store intersection of @widget and @area
6295 * Computes the intersection of a @widget's area and @area, storing
6296 * the intersection in @intersection, and returns %TRUE if there was
6297 * an intersection. @intersection may be %NULL if you're only
6298 * interested in whether there was an intersection.
6300 * Return value: %TRUE if there was an intersection
6303 gtk_widget_intersect (GtkWidget *widget,
6304 const GdkRectangle *area,
6305 GdkRectangle *intersection)
6307 GtkWidgetPrivate *priv;
6312 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6313 g_return_val_if_fail (area != NULL, FALSE);
6315 priv = widget->priv;
6318 dest = intersection;
6322 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6324 if (return_val && intersection && gtk_widget_get_has_window (widget))
6326 intersection->x -= priv->allocation.x;
6327 intersection->y -= priv->allocation.y;
6334 * gtk_widget_region_intersect:
6335 * @widget: a #GtkWidget
6336 * @region: a #cairo_region_t, in the same coordinate system as
6337 * @widget->allocation. That is, relative to @widget->window
6338 * for %NO_WINDOW widgets; relative to the parent window
6339 * of @widget->window for widgets with their own window.
6340 * @returns: A newly allocated region holding the intersection of @widget
6341 * and @region. The coordinates of the return value are
6342 * relative to @widget->window for %NO_WINDOW widgets, and
6343 * relative to the parent window of @widget->window for
6344 * widgets with their own window.
6346 * Computes the intersection of a @widget's area and @region, returning
6347 * the intersection. The result may be empty, use cairo_region_is_empty() to
6351 gtk_widget_region_intersect (GtkWidget *widget,
6352 const cairo_region_t *region)
6355 cairo_region_t *dest;
6357 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6358 g_return_val_if_fail (region != NULL, NULL);
6360 gtk_widget_get_allocation (widget, &rect);
6362 dest = cairo_region_create_rectangle (&rect);
6364 cairo_region_intersect (dest, region);
6370 * _gtk_widget_grab_notify:
6371 * @widget: a #GtkWidget
6372 * @was_grabbed: whether a grab is now in effect
6374 * Emits the #GtkWidget::grab-notify signal on @widget.
6379 _gtk_widget_grab_notify (GtkWidget *widget,
6380 gboolean was_grabbed)
6382 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6386 * gtk_widget_grab_focus:
6387 * @widget: a #GtkWidget
6389 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6390 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6391 * something like #GtkFrame won't work.
6393 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6394 * gtk_widget_set_can_focus() to modify that flag.
6396 * The widget also needs to be realized and mapped. This is indicated by the
6397 * related signals. Grabbing the focus immediately after creating the widget
6398 * will likely fail and cause critical warnings.
6401 gtk_widget_grab_focus (GtkWidget *widget)
6403 g_return_if_fail (GTK_IS_WIDGET (widget));
6405 if (!gtk_widget_is_sensitive (widget))
6408 g_object_ref (widget);
6409 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6410 g_object_notify (G_OBJECT (widget), "has-focus");
6411 g_object_unref (widget);
6415 reset_focus_recurse (GtkWidget *widget,
6418 if (GTK_IS_CONTAINER (widget))
6420 GtkContainer *container;
6422 container = GTK_CONTAINER (widget);
6423 gtk_container_set_focus_child (container, NULL);
6425 gtk_container_foreach (container,
6426 reset_focus_recurse,
6432 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6434 if (gtk_widget_get_can_focus (focus_widget))
6436 GtkWidget *toplevel;
6439 /* clear the current focus setting, break if the current widget
6440 * is the focus widget's parent, since containers above that will
6441 * be set by the next loop.
6443 toplevel = gtk_widget_get_toplevel (focus_widget);
6444 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6446 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6448 if (widget == focus_widget)
6450 /* We call _gtk_window_internal_set_focus() here so that the
6451 * toplevel window can request the focus if necessary.
6452 * This is needed when the toplevel is a GtkPlug
6454 if (!gtk_widget_has_focus (widget))
6455 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6462 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
6464 widget = widget->priv->parent;
6465 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6469 else if (toplevel != focus_widget)
6471 /* gtk_widget_grab_focus() operates on a tree without window...
6472 * actually, this is very questionable behaviour.
6475 gtk_container_foreach (GTK_CONTAINER (toplevel),
6476 reset_focus_recurse,
6480 /* now propagate the new focus up the widget tree and finally
6481 * set it on the window
6483 widget = focus_widget;
6484 while (widget->priv->parent)
6486 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6487 widget = widget->priv->parent;
6489 if (GTK_IS_WINDOW (widget))
6490 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6495 gtk_widget_real_query_tooltip (GtkWidget *widget,
6498 gboolean keyboard_tip,
6499 GtkTooltip *tooltip)
6501 gchar *tooltip_markup;
6502 gboolean has_tooltip;
6504 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6505 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6507 if (has_tooltip && tooltip_markup)
6509 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6517 gtk_widget_real_style_updated (GtkWidget *widget)
6519 GtkWidgetPrivate *priv = widget->priv;
6521 gtk_widget_update_pango_context (widget);
6523 if (priv->style != NULL &&
6524 priv->style != gtk_widget_get_default_style ())
6526 /* Trigger ::style-set for old
6527 * widgets not listening to this
6529 g_signal_emit (widget,
6530 widget_signals[STYLE_SET],
6532 widget->priv->style);
6535 if (widget->priv->context)
6537 if (gtk_widget_get_realized (widget) &&
6538 gtk_widget_get_has_window (widget))
6539 gtk_style_context_set_background (widget->priv->context,
6540 widget->priv->window);
6543 if (widget->priv->anchored)
6544 gtk_widget_queue_resize (widget);
6548 gtk_widget_real_show_help (GtkWidget *widget,
6549 GtkWidgetHelpType help_type)
6551 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6553 _gtk_tooltip_toggle_keyboard_mode (widget);
6562 gtk_widget_real_focus (GtkWidget *widget,
6563 GtkDirectionType direction)
6565 if (!gtk_widget_get_can_focus (widget))
6568 if (!gtk_widget_is_focus (widget))
6570 gtk_widget_grab_focus (widget);
6578 gtk_widget_real_move_focus (GtkWidget *widget,
6579 GtkDirectionType direction)
6581 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6583 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6585 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6591 gtk_widget_real_keynav_failed (GtkWidget *widget,
6592 GtkDirectionType direction)
6594 gboolean cursor_only;
6598 case GTK_DIR_TAB_FORWARD:
6599 case GTK_DIR_TAB_BACKWARD:
6606 g_object_get (gtk_widget_get_settings (widget),
6607 "gtk-keynav-cursor-only", &cursor_only,
6614 gtk_widget_error_bell (widget);
6620 * gtk_widget_set_can_focus:
6621 * @widget: a #GtkWidget
6622 * @can_focus: whether or not @widget can own the input focus.
6624 * Specifies whether @widget can own the input focus. See
6625 * gtk_widget_grab_focus() for actually setting the input focus on a
6631 gtk_widget_set_can_focus (GtkWidget *widget,
6634 g_return_if_fail (GTK_IS_WIDGET (widget));
6636 if (widget->priv->can_focus != can_focus)
6638 widget->priv->can_focus = can_focus;
6640 gtk_widget_queue_resize (widget);
6641 g_object_notify (G_OBJECT (widget), "can-focus");
6646 * gtk_widget_get_can_focus:
6647 * @widget: a #GtkWidget
6649 * Determines whether @widget can own the input focus. See
6650 * gtk_widget_set_can_focus().
6652 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6657 gtk_widget_get_can_focus (GtkWidget *widget)
6659 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6661 return widget->priv->can_focus;
6665 * gtk_widget_has_focus:
6666 * @widget: a #GtkWidget
6668 * Determines if the widget has the global input focus. See
6669 * gtk_widget_is_focus() for the difference between having the global
6670 * input focus, and only having the focus within a toplevel.
6672 * Return value: %TRUE if the widget has the global input focus.
6677 gtk_widget_has_focus (GtkWidget *widget)
6679 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6681 return widget->priv->has_focus;
6685 * gtk_widget_is_focus:
6686 * @widget: a #GtkWidget
6688 * Determines if the widget is the focus widget within its
6689 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6690 * necessarily set; %HAS_FOCUS will only be set if the
6691 * toplevel widget additionally has the global input focus.)
6693 * Return value: %TRUE if the widget is the focus widget.
6696 gtk_widget_is_focus (GtkWidget *widget)
6698 GtkWidget *toplevel;
6700 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6702 toplevel = gtk_widget_get_toplevel (widget);
6704 if (GTK_IS_WINDOW (toplevel))
6705 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6711 * gtk_widget_set_can_default:
6712 * @widget: a #GtkWidget
6713 * @can_default: whether or not @widget can be a default widget.
6715 * Specifies whether @widget can be a default widget. See
6716 * gtk_widget_grab_default() for details about the meaning of
6722 gtk_widget_set_can_default (GtkWidget *widget,
6723 gboolean can_default)
6725 g_return_if_fail (GTK_IS_WIDGET (widget));
6727 if (widget->priv->can_default != can_default)
6729 widget->priv->can_default = can_default;
6731 gtk_widget_queue_resize (widget);
6732 g_object_notify (G_OBJECT (widget), "can-default");
6737 * gtk_widget_get_can_default:
6738 * @widget: a #GtkWidget
6740 * Determines whether @widget can be a default widget. See
6741 * gtk_widget_set_can_default().
6743 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6748 gtk_widget_get_can_default (GtkWidget *widget)
6750 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6752 return widget->priv->can_default;
6756 * gtk_widget_has_default:
6757 * @widget: a #GtkWidget
6759 * Determines whether @widget is the current default widget within its
6760 * toplevel. See gtk_widget_set_can_default().
6762 * Return value: %TRUE if @widget is the current default widget within
6763 * its toplevel, %FALSE otherwise
6768 gtk_widget_has_default (GtkWidget *widget)
6770 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6772 return widget->priv->has_default;
6776 _gtk_widget_set_has_default (GtkWidget *widget,
6777 gboolean has_default)
6779 widget->priv->has_default = has_default;
6783 * gtk_widget_grab_default:
6784 * @widget: a #GtkWidget
6786 * Causes @widget to become the default widget. @widget must have the
6787 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6788 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6789 * %TRUE)</literal>. The default widget is activated when
6790 * the user presses Enter in a window. Default widgets must be
6791 * activatable, that is, gtk_widget_activate() should affect them. Note
6792 * that #GtkEntry widgets require the "activates-default" property
6793 * set to %TRUE before they activate the default widget when Enter
6794 * is pressed and the #GtkEntry is focused.
6797 gtk_widget_grab_default (GtkWidget *widget)
6801 g_return_if_fail (GTK_IS_WIDGET (widget));
6802 g_return_if_fail (gtk_widget_get_can_default (widget));
6804 window = gtk_widget_get_toplevel (widget);
6806 if (window && gtk_widget_is_toplevel (window))
6807 gtk_window_set_default (GTK_WINDOW (window), widget);
6809 g_warning (G_STRLOC ": widget not within a GtkWindow");
6813 * gtk_widget_set_receives_default:
6814 * @widget: a #GtkWidget
6815 * @receives_default: whether or not @widget can be a default widget.
6817 * Specifies whether @widget will be treated as the default widget
6818 * within its toplevel when it has the focus, even if another widget
6821 * See gtk_widget_grab_default() for details about the meaning of
6827 gtk_widget_set_receives_default (GtkWidget *widget,
6828 gboolean receives_default)
6830 g_return_if_fail (GTK_IS_WIDGET (widget));
6832 if (widget->priv->receives_default != receives_default)
6834 widget->priv->receives_default = receives_default;
6836 g_object_notify (G_OBJECT (widget), "receives-default");
6841 * gtk_widget_get_receives_default:
6842 * @widget: a #GtkWidget
6844 * Determines whether @widget is alyways treated as default widget
6845 * withing its toplevel when it has the focus, even if another widget
6848 * See gtk_widget_set_receives_default().
6850 * Return value: %TRUE if @widget acts as default widget when focussed,
6856 gtk_widget_get_receives_default (GtkWidget *widget)
6858 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6860 return widget->priv->receives_default;
6864 * gtk_widget_has_grab:
6865 * @widget: a #GtkWidget
6867 * Determines whether the widget is currently grabbing events, so it
6868 * is the only widget receiving input events (keyboard and mouse).
6870 * See also gtk_grab_add().
6872 * Return value: %TRUE if the widget is in the grab_widgets stack
6877 gtk_widget_has_grab (GtkWidget *widget)
6879 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6881 return widget->priv->has_grab;
6885 _gtk_widget_set_has_grab (GtkWidget *widget,
6888 widget->priv->has_grab = has_grab;
6892 * gtk_widget_device_is_shadowed:
6893 * @widget: a #GtkWidget
6894 * @device: a #GdkDevice
6896 * Returns %TRUE if @device has been shadowed by a GTK+
6897 * device grab on another widget, so it would stop sending
6898 * events to @widget. This may be used in the
6899 * #GtkWidget::grab-notify signal to check for specific
6900 * devices. See gtk_device_grab_add().
6902 * Returns: %TRUE if there is an ongoing grab on @device
6903 * by another #GtkWidget than @widget.
6908 gtk_widget_device_is_shadowed (GtkWidget *widget,
6911 GtkWindowGroup *group;
6912 GtkWidget *grab_widget, *toplevel;
6914 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6915 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6917 if (!gtk_widget_get_realized (widget))
6920 toplevel = gtk_widget_get_toplevel (widget);
6922 if (GTK_IS_WINDOW (toplevel))
6923 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6925 group = gtk_window_get_group (NULL);
6927 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6929 /* Widget not inside the hierarchy of grab_widget */
6931 widget != grab_widget &&
6932 !gtk_widget_is_ancestor (widget, grab_widget))
6935 grab_widget = gtk_window_group_get_current_grab (group);
6936 if (grab_widget && widget != grab_widget &&
6937 !gtk_widget_is_ancestor (widget, grab_widget))
6944 * gtk_widget_set_name:
6945 * @widget: a #GtkWidget
6946 * @name: name for the widget
6948 * Widgets can be named, which allows you to refer to them from a
6949 * CSS file. You can apply a style to widgets with a particular name
6950 * in the CSS file. See the documentation for the CSS syntax (on the
6951 * same page as the docs for #GtkStyleContext).
6953 * Note that the CSS syntax has certain special characters to delimit
6954 * and represent elements in a selector (period, #, >, *...),
6955 * so using these will make your widget impossible to match by name.
6956 * Any combination of alphanumeric symbols, dashes and underscores will
6960 gtk_widget_set_name (GtkWidget *widget,
6963 GtkWidgetPrivate *priv;
6966 g_return_if_fail (GTK_IS_WIDGET (widget));
6968 priv = widget->priv;
6970 new_name = g_strdup (name);
6971 g_free (priv->name);
6972 priv->name = new_name;
6974 gtk_widget_reset_style (widget);
6976 g_object_notify (G_OBJECT (widget), "name");
6980 * gtk_widget_get_name:
6981 * @widget: a #GtkWidget
6983 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6984 * significance of widget names.
6986 * Return value: name of the widget. This string is owned by GTK+ and
6987 * should not be modified or freed
6990 gtk_widget_get_name (GtkWidget *widget)
6992 GtkWidgetPrivate *priv;
6994 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6996 priv = widget->priv;
7000 return G_OBJECT_TYPE_NAME (widget);
7004 _gtk_widget_update_state_flags (GtkWidget *widget,
7005 GtkStateFlags flags,
7008 GtkWidgetPrivate *priv;
7010 priv = widget->priv;
7012 /* Handle insensitive first, since it is propagated
7013 * differently throughout the widget hierarchy.
7015 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_UNSET))
7016 gtk_widget_set_sensitive (widget, TRUE);
7017 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation != STATE_CHANGE_UNSET))
7018 gtk_widget_set_sensitive (widget, FALSE);
7019 else if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && !(flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_REPLACE))
7020 gtk_widget_set_sensitive (widget, TRUE);
7022 if (operation != STATE_CHANGE_REPLACE)
7023 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
7026 operation == STATE_CHANGE_REPLACE)
7031 data.operation = operation;
7032 data.use_forall = FALSE;
7034 gtk_widget_propagate_state (widget, &data);
7036 gtk_widget_queue_resize (widget);
7041 * gtk_widget_set_state_flags:
7042 * @widget: a #GtkWidget
7043 * @flags: State flags to turn on
7044 * @clear: Whether to clear state before turning on @flags
7046 * This function is for use in widget implementations. Turns on flag
7047 * values in the current widget state (insensitive, prelighted, etc.).
7049 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7050 * will be propagated down to all non-internal children if @widget is a
7051 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7052 * down to all #GtkContainer children by different means than turning on the
7053 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7054 * gtk_widget_is_sensitive() will make use of these.
7059 gtk_widget_set_state_flags (GtkWidget *widget,
7060 GtkStateFlags flags,
7063 g_return_if_fail (GTK_IS_WIDGET (widget));
7065 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7066 (clear && widget->priv->state_flags == flags))
7070 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7072 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
7076 * gtk_widget_unset_state_flags:
7077 * @widget: a #GtkWidget
7078 * @flags: State flags to turn off
7080 * This function is for use in widget implementations. Turns off flag
7081 * values for the current widget state (insensitive, prelighted, etc.).
7082 * See gtk_widget_set_state_flags().
7087 gtk_widget_unset_state_flags (GtkWidget *widget,
7088 GtkStateFlags flags)
7090 g_return_if_fail (GTK_IS_WIDGET (widget));
7092 if ((widget->priv->state_flags & flags) == 0)
7095 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
7099 * gtk_widget_get_state_flags:
7100 * @widget: a #GtkWidget
7102 * Returns the widget state as a flag set. It is worth mentioning
7103 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7104 * returned, that is, also based on parent insensitivity, even if
7105 * @widget itself is sensitive.
7107 * Returns: The state flags for widget
7112 gtk_widget_get_state_flags (GtkWidget *widget)
7114 GtkStateFlags flags;
7116 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7118 flags = widget->priv->state_flags;
7120 if (gtk_widget_has_focus (widget))
7121 flags |= GTK_STATE_FLAG_FOCUSED;
7127 * gtk_widget_set_state:
7128 * @widget: a #GtkWidget
7129 * @state: new state for @widget
7131 * This function is for use in widget implementations. Sets the state
7132 * of a widget (insensitive, prelighted, etc.) Usually you should set
7133 * the state using wrapper functions such as gtk_widget_set_sensitive().
7135 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7138 gtk_widget_set_state (GtkWidget *widget,
7141 GtkStateFlags flags;
7143 if (state == gtk_widget_get_state (widget))
7148 case GTK_STATE_ACTIVE:
7149 flags = GTK_STATE_FLAG_ACTIVE;
7151 case GTK_STATE_PRELIGHT:
7152 flags = GTK_STATE_FLAG_PRELIGHT;
7154 case GTK_STATE_SELECTED:
7155 flags = GTK_STATE_FLAG_SELECTED;
7157 case GTK_STATE_INSENSITIVE:
7158 flags = GTK_STATE_FLAG_INSENSITIVE;
7160 case GTK_STATE_INCONSISTENT:
7161 flags = GTK_STATE_FLAG_INCONSISTENT;
7163 case GTK_STATE_FOCUSED:
7164 flags = GTK_STATE_FLAG_FOCUSED;
7166 case GTK_STATE_NORMAL:
7172 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7176 * gtk_widget_get_state:
7177 * @widget: a #GtkWidget
7179 * Returns the widget's state. See gtk_widget_set_state().
7181 * Returns: the state of @widget.
7185 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7188 gtk_widget_get_state (GtkWidget *widget)
7190 GtkStateFlags flags;
7192 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7194 flags = gtk_widget_get_state_flags (widget);
7196 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7197 return GTK_STATE_INSENSITIVE;
7198 else if (flags & GTK_STATE_FLAG_ACTIVE)
7199 return GTK_STATE_ACTIVE;
7200 else if (flags & GTK_STATE_FLAG_SELECTED)
7201 return GTK_STATE_SELECTED;
7202 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7203 return GTK_STATE_PRELIGHT;
7205 return GTK_STATE_NORMAL;
7209 * gtk_widget_set_visible:
7210 * @widget: a #GtkWidget
7211 * @visible: whether the widget should be shown or not
7213 * Sets the visibility state of @widget. Note that setting this to
7214 * %TRUE doesn't mean the widget is actually viewable, see
7215 * gtk_widget_get_visible().
7217 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7218 * but is nicer to use when the visibility of the widget depends on
7224 gtk_widget_set_visible (GtkWidget *widget,
7227 g_return_if_fail (GTK_IS_WIDGET (widget));
7229 if (visible != gtk_widget_get_visible (widget))
7232 gtk_widget_show (widget);
7234 gtk_widget_hide (widget);
7239 _gtk_widget_set_visible_flag (GtkWidget *widget,
7242 widget->priv->visible = visible;
7246 * gtk_widget_get_visible:
7247 * @widget: a #GtkWidget
7249 * Determines whether the widget is visible. Note that this doesn't
7250 * take into account whether the widget's parent is also visible
7251 * or the widget is obscured in any way.
7253 * See gtk_widget_set_visible().
7255 * Return value: %TRUE if the widget is visible
7260 gtk_widget_get_visible (GtkWidget *widget)
7262 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7264 return widget->priv->visible;
7268 * gtk_widget_set_has_window:
7269 * @widget: a #GtkWidget
7270 * @has_window: whether or not @widget has a window.
7272 * Specifies whether @widget has a #GdkWindow of its own. Note that
7273 * all realized widgets have a non-%NULL "window" pointer
7274 * (gtk_widget_get_window() never returns a %NULL window when a widget
7275 * is realized), but for many of them it's actually the #GdkWindow of
7276 * one of its parent widgets. Widgets that do not create a %window for
7277 * themselves in #GtkWidget::realize must announce this by
7278 * calling this function with @has_window = %FALSE.
7280 * This function should only be called by widget implementations,
7281 * and they should call it in their init() function.
7286 gtk_widget_set_has_window (GtkWidget *widget,
7287 gboolean has_window)
7289 g_return_if_fail (GTK_IS_WIDGET (widget));
7291 widget->priv->no_window = !has_window;
7295 * gtk_widget_get_has_window:
7296 * @widget: a #GtkWidget
7298 * Determines whether @widget has a #GdkWindow of its own. See
7299 * gtk_widget_set_has_window().
7301 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7306 gtk_widget_get_has_window (GtkWidget *widget)
7308 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7310 return ! widget->priv->no_window;
7314 * gtk_widget_is_toplevel:
7315 * @widget: a #GtkWidget
7317 * Determines whether @widget is a toplevel widget.
7319 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7320 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7323 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7328 gtk_widget_is_toplevel (GtkWidget *widget)
7330 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7332 return widget->priv->toplevel;
7336 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7337 gboolean is_toplevel)
7339 widget->priv->toplevel = is_toplevel;
7343 * gtk_widget_is_drawable:
7344 * @widget: a #GtkWidget
7346 * Determines whether @widget can be drawn to. A widget can be drawn
7347 * to if it is mapped and visible.
7349 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7354 gtk_widget_is_drawable (GtkWidget *widget)
7356 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7358 return (gtk_widget_get_visible (widget) &&
7359 gtk_widget_get_mapped (widget));
7363 * gtk_widget_get_realized:
7364 * @widget: a #GtkWidget
7366 * Determines whether @widget is realized.
7368 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7373 gtk_widget_get_realized (GtkWidget *widget)
7375 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7377 return widget->priv->realized;
7381 * gtk_widget_set_realized:
7382 * @widget: a #GtkWidget
7383 * @realized: %TRUE to mark the widget as realized
7385 * Marks the widget as being realized.
7387 * This function should only ever be called in a derived widget's
7388 * "realize" or "unrealize" implementation.
7393 gtk_widget_set_realized (GtkWidget *widget,
7396 g_return_if_fail (GTK_IS_WIDGET (widget));
7398 widget->priv->realized = realized;
7402 * gtk_widget_get_mapped:
7403 * @widget: a #GtkWidget
7405 * Whether the widget is mapped.
7407 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7412 gtk_widget_get_mapped (GtkWidget *widget)
7414 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7416 return widget->priv->mapped;
7420 * gtk_widget_set_mapped:
7421 * @widget: a #GtkWidget
7422 * @mapped: %TRUE to mark the widget as mapped
7424 * Marks the widget as being realized.
7426 * This function should only ever be called in a derived widget's
7427 * "map" or "unmap" implementation.
7432 gtk_widget_set_mapped (GtkWidget *widget,
7435 g_return_if_fail (GTK_IS_WIDGET (widget));
7437 widget->priv->mapped = mapped;
7441 * gtk_widget_set_app_paintable:
7442 * @widget: a #GtkWidget
7443 * @app_paintable: %TRUE if the application will paint on the widget
7445 * Sets whether the application intends to draw on the widget in
7446 * an #GtkWidget::draw handler.
7448 * This is a hint to the widget and does not affect the behavior of
7449 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7450 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7451 * the effect is to suppress default themed drawing of the widget's
7452 * background. (Children of the widget will still be drawn.) The application
7453 * is then entirely responsible for drawing the widget background.
7455 * Note that the background is still drawn when the widget is mapped.
7458 gtk_widget_set_app_paintable (GtkWidget *widget,
7459 gboolean app_paintable)
7461 g_return_if_fail (GTK_IS_WIDGET (widget));
7463 app_paintable = (app_paintable != FALSE);
7465 if (widget->priv->app_paintable != app_paintable)
7467 widget->priv->app_paintable = app_paintable;
7469 if (gtk_widget_is_drawable (widget))
7470 gtk_widget_queue_draw (widget);
7472 g_object_notify (G_OBJECT (widget), "app-paintable");
7477 * gtk_widget_get_app_paintable:
7478 * @widget: a #GtkWidget
7480 * Determines whether the application intends to draw on the widget in
7481 * an #GtkWidget::draw handler.
7483 * See gtk_widget_set_app_paintable()
7485 * Return value: %TRUE if the widget is app paintable
7490 gtk_widget_get_app_paintable (GtkWidget *widget)
7492 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7494 return widget->priv->app_paintable;
7498 * gtk_widget_set_double_buffered:
7499 * @widget: a #GtkWidget
7500 * @double_buffered: %TRUE to double-buffer a widget
7502 * Widgets are double buffered by default; you can use this function
7503 * to turn off the buffering. "Double buffered" simply means that
7504 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7505 * automatically around expose events sent to the
7506 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7507 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7508 * buffer to the screen. The result is that users see the window
7509 * update in one smooth step, and don't see individual graphics
7510 * primitives being rendered.
7512 * In very simple terms, double buffered widgets don't flicker,
7513 * so you would only use this function to turn off double buffering
7514 * if you had special needs and really knew what you were doing.
7516 * Note: if you turn off double-buffering, you have to handle
7517 * expose events, since even the clearing to the background color or
7518 * pixmap will not happen automatically (as it is done in
7519 * gdk_window_begin_paint()).
7522 gtk_widget_set_double_buffered (GtkWidget *widget,
7523 gboolean double_buffered)
7525 g_return_if_fail (GTK_IS_WIDGET (widget));
7527 double_buffered = (double_buffered != FALSE);
7529 if (widget->priv->double_buffered != double_buffered)
7531 widget->priv->double_buffered = double_buffered;
7533 g_object_notify (G_OBJECT (widget), "double-buffered");
7538 * gtk_widget_get_double_buffered:
7539 * @widget: a #GtkWidget
7541 * Determines whether the widget is double buffered.
7543 * See gtk_widget_set_double_buffered()
7545 * Return value: %TRUE if the widget is double buffered
7550 gtk_widget_get_double_buffered (GtkWidget *widget)
7552 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7554 return widget->priv->double_buffered;
7558 * gtk_widget_set_redraw_on_allocate:
7559 * @widget: a #GtkWidget
7560 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7561 * when it is allocated to a new size. Otherwise, only the
7562 * new portion of the widget will be redrawn.
7564 * Sets whether the entire widget is queued for drawing when its size
7565 * allocation changes. By default, this setting is %TRUE and
7566 * the entire widget is redrawn on every size change. If your widget
7567 * leaves the upper left unchanged when made bigger, turning this
7568 * setting off will improve performance.
7570 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7571 * off all allocation on resizing: the widget will not even redraw if
7572 * its position changes; this is to allow containers that don't draw
7573 * anything to avoid excess invalidations. If you set this flag on a
7574 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7575 * you are responsible for invalidating both the old and new allocation
7576 * of the widget when the widget is moved and responsible for invalidating
7577 * regions newly when the widget increases size.
7580 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7581 gboolean redraw_on_allocate)
7583 g_return_if_fail (GTK_IS_WIDGET (widget));
7585 widget->priv->redraw_on_alloc = redraw_on_allocate;
7589 * gtk_widget_set_sensitive:
7590 * @widget: a #GtkWidget
7591 * @sensitive: %TRUE to make the widget sensitive
7593 * Sets the sensitivity of a widget. A widget is sensitive if the user
7594 * can interact with it. Insensitive widgets are "grayed out" and the
7595 * user can't interact with them. Insensitive widgets are known as
7596 * "inactive", "disabled", or "ghosted" in some other toolkits.
7599 gtk_widget_set_sensitive (GtkWidget *widget,
7602 GtkWidgetPrivate *priv;
7605 g_return_if_fail (GTK_IS_WIDGET (widget));
7607 priv = widget->priv;
7609 sensitive = (sensitive != FALSE);
7611 if (priv->sensitive == sensitive)
7614 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7618 priv->sensitive = TRUE;
7619 data.operation = STATE_CHANGE_UNSET;
7623 priv->sensitive = FALSE;
7624 data.operation = STATE_CHANGE_SET;
7627 data.use_forall = TRUE;
7629 gtk_widget_propagate_state (widget, &data);
7631 gtk_widget_queue_resize (widget);
7633 g_object_notify (G_OBJECT (widget), "sensitive");
7637 * gtk_widget_get_sensitive:
7638 * @widget: a #GtkWidget
7640 * Returns the widget's sensitivity (in the sense of returning
7641 * the value that has been set using gtk_widget_set_sensitive()).
7643 * The effective sensitivity of a widget is however determined by both its
7644 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7646 * Returns: %TRUE if the widget is sensitive
7651 gtk_widget_get_sensitive (GtkWidget *widget)
7653 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7655 return widget->priv->sensitive;
7659 * gtk_widget_is_sensitive:
7660 * @widget: a #GtkWidget
7662 * Returns the widget's effective sensitivity, which means
7663 * it is sensitive itself and also its parent widget is sensitive
7665 * Returns: %TRUE if the widget is effectively sensitive
7670 gtk_widget_is_sensitive (GtkWidget *widget)
7672 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7674 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
7678 _gtk_widget_update_path (GtkWidget *widget)
7680 if (widget->priv->path)
7682 gtk_widget_path_free (widget->priv->path);
7683 widget->priv->path = NULL;
7686 gtk_widget_get_path (widget);
7690 * gtk_widget_set_parent:
7691 * @widget: a #GtkWidget
7692 * @parent: parent container
7694 * This function is useful only when implementing subclasses of
7696 * Sets the container as the parent of @widget, and takes care of
7697 * some details such as updating the state and style of the child
7698 * to reflect its new location. The opposite function is
7699 * gtk_widget_unparent().
7702 gtk_widget_set_parent (GtkWidget *widget,
7705 GtkStateFlags parent_flags;
7706 GtkWidgetPrivate *priv;
7709 g_return_if_fail (GTK_IS_WIDGET (widget));
7710 g_return_if_fail (GTK_IS_WIDGET (parent));
7711 g_return_if_fail (widget != parent);
7713 priv = widget->priv;
7715 if (priv->parent != NULL)
7717 g_warning ("Can't set a parent on widget which has a parent\n");
7720 if (gtk_widget_is_toplevel (widget))
7722 g_warning ("Can't set a parent on a toplevel widget\n");
7726 /* keep this function in sync with gtk_menu_attach_to_widget()
7729 g_object_ref_sink (widget);
7731 gtk_widget_push_verify_invariants (widget);
7733 priv->parent = parent;
7735 parent_flags = gtk_widget_get_state_flags (parent);
7737 /* Merge both old state and current parent state,
7738 * making sure to only propagate the right states */
7739 data.flags = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
7740 data.flags |= priv->state_flags;
7742 data.operation = STATE_CHANGE_REPLACE;
7743 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7744 gtk_widget_propagate_state (widget, &data);
7746 gtk_widget_reset_style (widget);
7748 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7749 if (priv->parent->priv->anchored)
7750 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7751 g_object_notify (G_OBJECT (widget), "parent");
7753 /* Enforce realized/mapped invariants
7755 if (gtk_widget_get_realized (priv->parent))
7756 gtk_widget_realize (widget);
7758 if (gtk_widget_get_visible (priv->parent) &&
7759 gtk_widget_get_visible (widget))
7761 if (gtk_widget_get_child_visible (widget) &&
7762 gtk_widget_get_mapped (priv->parent))
7763 gtk_widget_map (widget);
7765 gtk_widget_queue_resize (widget);
7768 /* child may cause parent's expand to change, if the child is
7769 * expanded. If child is not expanded, then it can't modify the
7770 * parent's expand. If the child becomes expanded later then it will
7771 * queue compute_expand then. This optimization plus defaulting
7772 * newly-constructed widgets to need_compute_expand=FALSE should
7773 * mean that initially building a widget tree doesn't have to keep
7774 * walking up setting need_compute_expand on parents over and over.
7776 * We can't change a parent to need to expand unless we're visible.
7778 if (gtk_widget_get_visible (widget) &&
7779 (priv->need_compute_expand ||
7780 priv->computed_hexpand ||
7781 priv->computed_vexpand))
7783 gtk_widget_queue_compute_expand (parent);
7786 gtk_widget_pop_verify_invariants (widget);
7790 * gtk_widget_get_parent:
7791 * @widget: a #GtkWidget
7793 * Returns the parent container of @widget.
7795 * Return value: (transfer none): the parent container of @widget, or %NULL
7798 gtk_widget_get_parent (GtkWidget *widget)
7800 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7802 return widget->priv->parent;
7805 /*****************************************
7807 * see docs/styles.txt
7808 *****************************************/
7811 * gtk_widget_style_attach:
7812 * @widget: a #GtkWidget
7814 * This function attaches the widget's #GtkStyle to the widget's
7815 * #GdkWindow. It is a replacement for
7818 * widget->style = gtk_style_attach (widget->style, widget->window);
7821 * and should only ever be called in a derived widget's "realize"
7822 * implementation which does not chain up to its parent class'
7823 * "realize" implementation, because one of the parent classes
7824 * (finally #GtkWidget) would attach the style itself.
7828 * Deprecated: 3.0. This step is unnecessary with #GtkStyleContext.
7831 gtk_widget_style_attach (GtkWidget *widget)
7833 g_return_if_fail (GTK_IS_WIDGET (widget));
7834 g_return_if_fail (gtk_widget_get_realized (widget));
7838 * gtk_widget_has_rc_style:
7839 * @widget: a #GtkWidget
7841 * Determines if the widget style has been looked up through the rc mechanism.
7843 * Returns: %TRUE if the widget has been looked up through the rc
7844 * mechanism, %FALSE otherwise.
7848 * Deprecated:3.0: Use #GtkStyleContext instead
7851 gtk_widget_has_rc_style (GtkWidget *widget)
7853 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7855 return widget->priv->rc_style;
7859 * gtk_widget_set_style:
7860 * @widget: a #GtkWidget
7861 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect
7862 * of a previous call to gtk_widget_set_style() and go back to
7865 * Used to set the #GtkStyle for a widget (@widget->style). Since
7866 * GTK 3, this function does nothing, the passed in style is ignored.
7868 * Deprecated:3.0: Use #GtkStyleContext instead
7871 gtk_widget_set_style (GtkWidget *widget,
7874 g_return_if_fail (GTK_IS_WIDGET (widget));
7878 * gtk_widget_ensure_style:
7879 * @widget: a #GtkWidget
7881 * Ensures that @widget has a style (@widget->style).
7883 * Not a very useful function; most of the time, if you
7884 * want the style, the widget is realized, and realized
7885 * widgets are guaranteed to have a style already.
7887 * Deprecated:3.0: Use #GtkStyleContext instead
7890 gtk_widget_ensure_style (GtkWidget *widget)
7892 GtkWidgetPrivate *priv;
7894 g_return_if_fail (GTK_IS_WIDGET (widget));
7896 priv = widget->priv;
7898 if (priv->style == gtk_widget_get_default_style ())
7900 g_object_unref (priv->style);
7904 g_signal_emit (widget,
7905 widget_signals[STYLE_SET],
7911 * gtk_widget_get_style:
7912 * @widget: a #GtkWidget
7914 * Simply an accessor function that returns @widget->style.
7916 * Return value: (transfer none): the widget's #GtkStyle
7918 * Deprecated:3.0: Use #GtkStyleContext instead
7921 gtk_widget_get_style (GtkWidget *widget)
7923 GtkWidgetPrivate *priv;
7925 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7927 priv = widget->priv;
7929 if (priv->style == NULL)
7931 priv->style = g_object_new (GTK_TYPE_STYLE,
7932 "context", gtk_widget_get_style_context (widget),
7941 * gtk_widget_modify_style:
7942 * @widget: a #GtkWidget
7943 * @style: the #GtkRcStyle holding the style modifications
7945 * Modifies style values on the widget.
7947 * Modifications made using this technique take precedence over
7948 * style values set via an RC file, however, they will be overridden
7949 * if a style is explicitely set on the widget using gtk_widget_set_style().
7950 * The #GtkRcStyle structure is designed so each field can either be
7951 * set or unset, so it is possible, using this function, to modify some
7952 * style values and leave the others unchanged.
7954 * Note that modifications made with this function are not cumulative
7955 * with previous calls to gtk_widget_modify_style() or with such
7956 * functions as gtk_widget_modify_fg(). If you wish to retain
7957 * previous values, you must first call gtk_widget_get_modifier_style(),
7958 * make your modifications to the returned style, then call
7959 * gtk_widget_modify_style() with that style. On the other hand,
7960 * if you first call gtk_widget_modify_style(), subsequent calls
7961 * to such functions gtk_widget_modify_fg() will have a cumulative
7962 * effect with the initial modifications.
7964 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7967 gtk_widget_modify_style (GtkWidget *widget,
7970 g_return_if_fail (GTK_IS_WIDGET (widget));
7971 g_return_if_fail (GTK_IS_RC_STYLE (style));
7973 g_object_set_qdata_full (G_OBJECT (widget),
7975 gtk_rc_style_copy (style),
7976 (GDestroyNotify) g_object_unref);
7980 * gtk_widget_get_modifier_style:
7981 * @widget: a #GtkWidget
7983 * Returns the current modifier style for the widget. (As set by
7984 * gtk_widget_modify_style().) If no style has previously set, a new
7985 * #GtkRcStyle will be created with all values unset, and set as the
7986 * modifier style for the widget. If you make changes to this rc
7987 * style, you must call gtk_widget_modify_style(), passing in the
7988 * returned rc style, to make sure that your changes take effect.
7990 * Caution: passing the style back to gtk_widget_modify_style() will
7991 * normally end up destroying it, because gtk_widget_modify_style() copies
7992 * the passed-in style and sets the copy as the new modifier style,
7993 * thus dropping any reference to the old modifier style. Add a reference
7994 * to the modifier style if you want to keep it alive.
7996 * Return value: (transfer none): the modifier style for the widget.
7997 * This rc style is owned by the widget. If you want to keep a
7998 * pointer to value this around, you must add a refcount using
8001 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
8004 gtk_widget_get_modifier_style (GtkWidget *widget)
8006 GtkRcStyle *rc_style;
8008 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8010 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
8014 rc_style = gtk_rc_style_new ();
8015 g_object_set_qdata_full (G_OBJECT (widget),
8018 (GDestroyNotify) g_object_unref);
8025 gtk_widget_modify_color_component (GtkWidget *widget,
8026 GtkRcFlags component,
8028 const GdkColor *color)
8030 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
8037 rc_style->fg[state] = *color;
8040 rc_style->bg[state] = *color;
8043 rc_style->text[state] = *color;
8046 rc_style->base[state] = *color;
8049 g_assert_not_reached();
8052 rc_style->color_flags[state] |= component;
8055 rc_style->color_flags[state] &= ~component;
8057 gtk_widget_modify_style (widget, rc_style);
8061 modifier_style_changed (GtkModifierStyle *style,
8064 GtkStyleContext *context;
8066 context = gtk_widget_get_style_context (widget);
8067 gtk_style_context_invalidate (context);
8070 static GtkModifierStyle *
8071 _gtk_widget_get_modifier_properties (GtkWidget *widget)
8073 GtkModifierStyle *style;
8075 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
8077 if (G_UNLIKELY (!style))
8079 GtkStyleContext *context;
8081 style = _gtk_modifier_style_new ();
8082 g_object_set_qdata_full (G_OBJECT (widget),
8083 quark_modifier_style,
8085 (GDestroyNotify) g_object_unref);
8087 g_signal_connect (style, "changed",
8088 G_CALLBACK (modifier_style_changed), widget);
8090 context = gtk_widget_get_style_context (widget);
8092 gtk_style_context_add_provider (context,
8093 GTK_STYLE_PROVIDER (style),
8094 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
8101 * gtk_widget_override_color:
8102 * @widget: a #GtkWidget
8103 * @state: the state for which to set the color
8104 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8105 * of previous calls to gtk_widget_override_color()
8107 * Sets the color to use for a widget.
8109 * All other style values are left untouched.
8112 * This API is mostly meant as a quick way for applications to
8113 * change a widget appearance. If you are developing a widgets
8114 * library and intend this change to be themeable, it is better
8115 * done by setting meaningful CSS classes and regions in your
8116 * widget/container implementation through gtk_style_context_add_class()
8117 * and gtk_style_context_add_region().
8119 * This way, your widget library can install a #GtkCssProvider
8120 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
8121 * to provide a default styling for those widgets that need so, and
8122 * this theming may fully overridden by the user's theme.
8125 * Note that for complex widgets this may bring in undesired
8126 * results (such as uniform background color everywhere), in
8127 * these cases it is better to fully style such widgets through a
8128 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8135 gtk_widget_override_color (GtkWidget *widget,
8136 GtkStateFlags state,
8137 const GdkRGBA *color)
8139 GtkModifierStyle *style;
8141 g_return_if_fail (GTK_IS_WIDGET (widget));
8143 style = _gtk_widget_get_modifier_properties (widget);
8144 _gtk_modifier_style_set_color (style, state, color);
8148 * gtk_widget_override_background_color:
8149 * @widget: a #GtkWidget
8150 * @state: the state for which to set the background color
8151 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8152 * of previous calls to gtk_widget_override_background_color()
8154 * Sets the background color to use for a widget.
8156 * All other style values are left untouched.
8157 * See gtk_widget_override_color().
8162 gtk_widget_override_background_color (GtkWidget *widget,
8163 GtkStateFlags state,
8164 const GdkRGBA *color)
8166 GtkModifierStyle *style;
8168 g_return_if_fail (GTK_IS_WIDGET (widget));
8170 style = _gtk_widget_get_modifier_properties (widget);
8171 _gtk_modifier_style_set_background_color (style, state, color);
8175 * gtk_widget_override_font:
8176 * @widget: a #GtkWidget
8177 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
8178 * the effect of previous calls to gtk_widget_override_font()
8180 * Sets the font to use for a widget. All other style values are
8181 * left untouched. See gtk_widget_override_color().
8186 gtk_widget_override_font (GtkWidget *widget,
8187 const PangoFontDescription *font_desc)
8189 GtkModifierStyle *style;
8191 g_return_if_fail (GTK_IS_WIDGET (widget));
8193 style = _gtk_widget_get_modifier_properties (widget);
8194 _gtk_modifier_style_set_font (style, font_desc);
8198 * gtk_widget_override_symbolic_color:
8199 * @widget: a #GtkWidget
8200 * @name: the name of the symbolic color to modify
8201 * @color: (allow-none): the color to assign (does not need
8202 * to be allocated), or %NULL to undo the effect of previous
8203 * calls to gtk_widget_override_symbolic_color()
8205 * Sets a symbolic color for a widget.
8207 * All other style values are left untouched.
8208 * See gtk_widget_override_color() for overriding the foreground
8209 * or background color.
8214 gtk_widget_override_symbolic_color (GtkWidget *widget,
8216 const GdkRGBA *color)
8218 GtkModifierStyle *style;
8220 g_return_if_fail (GTK_IS_WIDGET (widget));
8222 style = _gtk_widget_get_modifier_properties (widget);
8223 _gtk_modifier_style_map_color (style, name, color);
8227 * gtk_widget_override_cursor:
8228 * @widget: a #GtkWidget
8229 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8230 * allocated), or %NULL to undo the effect of previous calls to
8231 * of gtk_widget_override_cursor().
8232 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8233 * need to be allocated), or %NULL to undo the effect of previous
8234 * calls to of gtk_widget_override_cursor().
8236 * Sets the cursor color to use in a widget, overriding the
8237 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8238 * style properties. All other style values are left untouched.
8239 * See also gtk_widget_modify_style().
8241 * Note that the underlying properties have the #GdkColor type,
8242 * so the alpha value in @primary and @secondary will be ignored.
8247 gtk_widget_override_cursor (GtkWidget *widget,
8248 const GdkRGBA *cursor,
8249 const GdkRGBA *secondary_cursor)
8251 GtkModifierStyle *style;
8253 g_return_if_fail (GTK_IS_WIDGET (widget));
8255 style = _gtk_widget_get_modifier_properties (widget);
8256 _gtk_modifier_style_set_color_property (style,
8258 "cursor-color", cursor);
8259 _gtk_modifier_style_set_color_property (style,
8261 "secondary-cursor-color",
8266 * gtk_widget_modify_fg:
8267 * @widget: a #GtkWidget
8268 * @state: the state for which to set the foreground color
8269 * @color: (allow-none): the color to assign (does not need to be allocated),
8270 * or %NULL to undo the effect of previous calls to
8271 * of gtk_widget_modify_fg().
8273 * Sets the foreground color for a widget in a particular state.
8275 * All other style values are left untouched.
8276 * See also gtk_widget_modify_style().
8278 * Deprecated:3.0: Use gtk_widget_override_color() instead
8281 gtk_widget_modify_fg (GtkWidget *widget,
8283 const GdkColor *color)
8285 GtkStateFlags flags;
8288 g_return_if_fail (GTK_IS_WIDGET (widget));
8289 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8293 case GTK_STATE_ACTIVE:
8294 flags = GTK_STATE_FLAG_ACTIVE;
8296 case GTK_STATE_PRELIGHT:
8297 flags = GTK_STATE_FLAG_PRELIGHT;
8299 case GTK_STATE_SELECTED:
8300 flags = GTK_STATE_FLAG_SELECTED;
8302 case GTK_STATE_INSENSITIVE:
8303 flags = GTK_STATE_FLAG_INSENSITIVE;
8305 case GTK_STATE_NORMAL:
8312 rgba.red = color->red / 65535.;
8313 rgba.green = color->green / 65535.;
8314 rgba.blue = color->blue / 65535.;
8317 gtk_widget_override_color (widget, flags, &rgba);
8320 gtk_widget_override_color (widget, flags, NULL);
8324 * gtk_widget_modify_bg:
8325 * @widget: a #GtkWidget
8326 * @state: the state for which to set the background color
8327 * @color: (allow-none): the color to assign (does not need
8328 * to be allocated), or %NULL to undo the effect of previous
8329 * calls to of gtk_widget_modify_bg().
8331 * Sets the background color for a widget in a particular state.
8333 * All other style values are left untouched.
8334 * See also gtk_widget_modify_style().
8337 * Note that "no window" widgets (which have the %GTK_NO_WINDOW
8338 * flag set) draw on their parent container's window and thus may
8339 * not draw any background themselves. This is the case for e.g.
8342 * To modify the background of such widgets, you have to set the
8343 * background color on their parent; if you want to set the background
8344 * of a rectangular area around a label, try placing the label in
8345 * a #GtkEventBox widget and setting the background color on that.
8348 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8351 gtk_widget_modify_bg (GtkWidget *widget,
8353 const GdkColor *color)
8355 GtkStateFlags flags;
8358 g_return_if_fail (GTK_IS_WIDGET (widget));
8359 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8363 case GTK_STATE_ACTIVE:
8364 flags = GTK_STATE_FLAG_ACTIVE;
8366 case GTK_STATE_PRELIGHT:
8367 flags = GTK_STATE_FLAG_PRELIGHT;
8369 case GTK_STATE_SELECTED:
8370 flags = GTK_STATE_FLAG_SELECTED;
8372 case GTK_STATE_INSENSITIVE:
8373 flags = GTK_STATE_FLAG_INSENSITIVE;
8375 case GTK_STATE_NORMAL:
8382 rgba.red = color->red / 65535.;
8383 rgba.green = color->green / 65535.;
8384 rgba.blue = color->blue / 65535.;
8387 gtk_widget_override_background_color (widget, flags, &rgba);
8390 gtk_widget_override_background_color (widget, flags, NULL);
8394 * gtk_widget_modify_text:
8395 * @widget: a #GtkWidget
8396 * @state: the state for which to set the text color
8397 * @color: (allow-none): the color to assign (does not need to
8398 * be allocated), or %NULL to undo the effect of previous
8399 * calls to of gtk_widget_modify_text().
8401 * Sets the text color for a widget in a particular state.
8403 * All other style values are left untouched.
8404 * The text color is the foreground color used along with the
8405 * base color (see gtk_widget_modify_base()) for widgets such
8406 * as #GtkEntry and #GtkTextView.
8407 * See also gtk_widget_modify_style().
8409 * Deprecated:3.0: Use gtk_widget_override_color() instead
8412 gtk_widget_modify_text (GtkWidget *widget,
8414 const GdkColor *color)
8416 g_return_if_fail (GTK_IS_WIDGET (widget));
8417 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8419 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
8423 * gtk_widget_modify_base:
8424 * @widget: a #GtkWidget
8425 * @state: the state for which to set the base color
8426 * @color: (allow-none): the color to assign (does not need to
8427 * be allocated), or %NULL to undo the effect of previous
8428 * calls to of gtk_widget_modify_base().
8430 * Sets the base color for a widget in a particular state.
8431 * All other style values are left untouched. The base color
8432 * is the background color used along with the text color
8433 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
8434 * and #GtkTextView. See also gtk_widget_modify_style().
8437 * Note that "no window" widgets (which have the %GTK_NO_WINDOW
8438 * flag set) draw on their parent container's window and thus may
8439 * not draw any background themselves. This is the case for e.g.
8442 * To modify the background of such widgets, you have to set the
8443 * base color on their parent; if you want to set the background
8444 * of a rectangular area around a label, try placing the label in
8445 * a #GtkEventBox widget and setting the base color on that.
8448 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8451 gtk_widget_modify_base (GtkWidget *widget,
8453 const GdkColor *color)
8455 g_return_if_fail (GTK_IS_WIDGET (widget));
8456 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8458 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
8462 * gtk_widget_modify_cursor:
8463 * @widget: a #GtkWidget
8464 * @primary: the color to use for primary cursor (does not need to be
8465 * allocated), or %NULL to undo the effect of previous calls to
8466 * of gtk_widget_modify_cursor().
8467 * @secondary: the color to use for secondary cursor (does not need to be
8468 * allocated), or %NULL to undo the effect of previous calls to
8469 * of gtk_widget_modify_cursor().
8471 * Sets the cursor color to use in a widget, overriding the
8472 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8475 * All other style values are left untouched.
8476 * See also gtk_widget_modify_style().
8480 * Deprecated: 3.0. Use gtk_widget_override_cursor() instead.
8483 gtk_widget_modify_cursor (GtkWidget *widget,
8484 const GdkColor *primary,
8485 const GdkColor *secondary)
8487 GdkRGBA primary_rgba, secondary_rgba;
8489 g_return_if_fail (GTK_IS_WIDGET (widget));
8491 primary_rgba.red = primary->red / 65535.;
8492 primary_rgba.green = primary->green / 65535.;
8493 primary_rgba.blue = primary->blue / 65535.;
8494 primary_rgba.alpha = 1;
8496 secondary_rgba.red = secondary->red / 65535.;
8497 secondary_rgba.green = secondary->green / 65535.;
8498 secondary_rgba.blue = secondary->blue / 65535.;
8499 secondary_rgba.alpha = 1;
8501 gtk_widget_override_cursor (widget, &primary_rgba, &secondary_rgba);
8505 * gtk_widget_modify_font:
8506 * @widget: a #GtkWidget
8507 * @font_desc: (allow-none): the font description to use, or %NULL
8508 * to undo the effect of previous calls to gtk_widget_modify_font()
8510 * Sets the font to use for a widget.
8512 * All other style values are left untouched.
8513 * See also gtk_widget_modify_style().
8515 * Deprecated:3.0: Use gtk_widget_override_font() instead
8518 gtk_widget_modify_font (GtkWidget *widget,
8519 PangoFontDescription *font_desc)
8521 g_return_if_fail (GTK_IS_WIDGET (widget));
8523 gtk_widget_override_font (widget, font_desc);
8527 gtk_widget_real_direction_changed (GtkWidget *widget,
8528 GtkTextDirection previous_direction)
8530 gtk_widget_queue_resize (widget);
8534 gtk_widget_real_style_set (GtkWidget *widget,
8535 GtkStyle *previous_style)
8540 GtkWidget *previous_toplevel;
8541 GdkScreen *previous_screen;
8542 GdkScreen *new_screen;
8543 } HierarchyChangedInfo;
8546 do_screen_change (GtkWidget *widget,
8547 GdkScreen *old_screen,
8548 GdkScreen *new_screen)
8550 if (old_screen != new_screen)
8552 GtkWidgetPrivate *priv = widget->priv;
8556 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8558 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8561 _gtk_tooltip_hide (widget);
8563 if (new_screen && priv->context)
8564 gtk_style_context_set_screen (priv->context, new_screen);
8566 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8571 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8572 gpointer client_data)
8574 GtkWidgetPrivate *priv = widget->priv;
8575 HierarchyChangedInfo *info = client_data;
8576 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8577 (priv->parent && priv->parent->priv->anchored);
8579 if (priv->anchored != new_anchored)
8581 g_object_ref (widget);
8583 priv->anchored = new_anchored;
8585 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8586 do_screen_change (widget, info->previous_screen, info->new_screen);
8588 if (GTK_IS_CONTAINER (widget))
8589 gtk_container_forall (GTK_CONTAINER (widget),
8590 gtk_widget_propagate_hierarchy_changed_recurse,
8593 g_object_unref (widget);
8598 * _gtk_widget_propagate_hierarchy_changed:
8599 * @widget: a #GtkWidget
8600 * @previous_toplevel: Previous toplevel
8602 * Propagates changes in the anchored state to a widget and all
8603 * children, unsetting or setting the %ANCHORED flag, and
8604 * emitting #GtkWidget::hierarchy-changed.
8607 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8608 GtkWidget *previous_toplevel)
8610 GtkWidgetPrivate *priv = widget->priv;
8611 HierarchyChangedInfo info;
8613 info.previous_toplevel = previous_toplevel;
8614 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8616 if (gtk_widget_is_toplevel (widget) ||
8617 (priv->parent && priv->parent->priv->anchored))
8618 info.new_screen = gtk_widget_get_screen (widget);
8620 info.new_screen = NULL;
8622 if (info.previous_screen)
8623 g_object_ref (info.previous_screen);
8624 if (previous_toplevel)
8625 g_object_ref (previous_toplevel);
8627 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8629 if (previous_toplevel)
8630 g_object_unref (previous_toplevel);
8631 if (info.previous_screen)
8632 g_object_unref (info.previous_screen);
8636 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8637 gpointer client_data)
8639 HierarchyChangedInfo *info = client_data;
8641 g_object_ref (widget);
8643 do_screen_change (widget, info->previous_screen, info->new_screen);
8645 if (GTK_IS_CONTAINER (widget))
8646 gtk_container_forall (GTK_CONTAINER (widget),
8647 gtk_widget_propagate_screen_changed_recurse,
8650 g_object_unref (widget);
8654 * gtk_widget_is_composited:
8655 * @widget: a #GtkWidget
8657 * Whether @widget can rely on having its alpha channel
8658 * drawn correctly. On X11 this function returns whether a
8659 * compositing manager is running for @widget's screen.
8661 * Please note that the semantics of this call will change
8662 * in the future if used on a widget that has a composited
8663 * window in its hierarchy (as set by gdk_window_set_composited()).
8665 * Return value: %TRUE if the widget can rely on its alpha
8666 * channel being drawn correctly.
8671 gtk_widget_is_composited (GtkWidget *widget)
8675 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8677 screen = gtk_widget_get_screen (widget);
8679 return gdk_screen_is_composited (screen);
8683 propagate_composited_changed (GtkWidget *widget,
8686 if (GTK_IS_CONTAINER (widget))
8688 gtk_container_forall (GTK_CONTAINER (widget),
8689 propagate_composited_changed,
8693 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8697 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8699 propagate_composited_changed (widget, NULL);
8703 * _gtk_widget_propagate_screen_changed:
8704 * @widget: a #GtkWidget
8705 * @previous_screen: Previous screen
8707 * Propagates changes in the screen for a widget to all
8708 * children, emitting #GtkWidget::screen-changed.
8711 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8712 GdkScreen *previous_screen)
8714 HierarchyChangedInfo info;
8716 info.previous_screen = previous_screen;
8717 info.new_screen = gtk_widget_get_screen (widget);
8719 if (previous_screen)
8720 g_object_ref (previous_screen);
8722 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8724 if (previous_screen)
8725 g_object_unref (previous_screen);
8729 reset_style_recurse (GtkWidget *widget, gpointer data)
8731 _gtk_widget_update_path (widget);
8733 if (GTK_IS_CONTAINER (widget))
8734 gtk_container_forall (GTK_CONTAINER (widget),
8735 reset_style_recurse,
8740 * gtk_widget_reset_style:
8741 * @widget: a #GtkWidget
8743 * Updates the style context of @widget and all descendents
8744 * by updating its widget path. #GtkContainer<!-- -->s may want
8745 * to use this on a child when reordering it in a way that a different
8746 * style might apply to it. See also gtk_container_get_path_for_child().
8751 gtk_widget_reset_style (GtkWidget *widget)
8753 g_return_if_fail (GTK_IS_WIDGET (widget));
8755 reset_style_recurse (widget, NULL);
8759 * gtk_widget_reset_rc_styles:
8760 * @widget: a #GtkWidget.
8762 * Reset the styles of @widget and all descendents, so when
8763 * they are looked up again, they get the correct values
8764 * for the currently loaded RC file settings.
8766 * This function is not useful for applications.
8768 * Deprecated:3.0: Use #GtkStyleContext instead, and gtk_widget_reset_style()
8771 gtk_widget_reset_rc_styles (GtkWidget *widget)
8773 g_return_if_fail (GTK_IS_WIDGET (widget));
8775 reset_style_recurse (widget, NULL);
8779 * gtk_widget_get_default_style:
8781 * Returns the default style used by all widgets initially.
8783 * Returns: (transfer none): the default style. This #GtkStyle
8784 * object is owned by GTK+ and should not be modified or freed.
8786 * Deprecated:3.0: Use #GtkStyleContext instead, and
8787 * gtk_css_provider_get_default() to obtain a #GtkStyleProvider
8788 * with the default widget style information.
8791 gtk_widget_get_default_style (void)
8793 if (!gtk_default_style)
8795 gtk_default_style = gtk_style_new ();
8796 g_object_ref (gtk_default_style);
8799 return gtk_default_style;
8802 #ifdef G_ENABLE_DEBUG
8804 /* Verify invariants, see docs/widget_system.txt for notes on much of
8805 * this. Invariants may be temporarily broken while we're in the
8806 * process of updating state, of course, so you can only
8807 * verify_invariants() after a given operation is complete.
8808 * Use push/pop_verify_invariants to help with that.
8811 gtk_widget_verify_invariants (GtkWidget *widget)
8815 if (widget->priv->verifying_invariants_count > 0)
8818 parent = widget->priv->parent;
8820 if (widget->priv->mapped)
8822 /* Mapped implies ... */
8824 if (!widget->priv->realized)
8825 g_warning ("%s %p is mapped but not realized",
8826 G_OBJECT_TYPE_NAME (widget), widget);
8828 if (!widget->priv->visible)
8829 g_warning ("%s %p is mapped but not visible",
8830 G_OBJECT_TYPE_NAME (widget), widget);
8832 if (!widget->priv->toplevel)
8834 if (!widget->priv->child_visible)
8835 g_warning ("%s %p is mapped but not child_visible",
8836 G_OBJECT_TYPE_NAME (widget), widget);
8841 /* Not mapped implies... */
8844 /* This check makes sense for normal toplevels, but for
8845 * something like a toplevel that is embedded within a clutter
8846 * state, mapping may depend on external factors.
8848 if (widget->priv->toplevel)
8850 if (widget->priv->visible)
8851 g_warning ("%s %p toplevel is visible but not mapped",
8852 G_OBJECT_TYPE_NAME (widget), widget);
8857 /* Parent related checks aren't possible if parent has
8858 * verifying_invariants_count > 0 because parent needs to recurse
8859 * children first before the invariants will hold.
8861 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8864 parent->priv->realized)
8866 /* Parent realized implies... */
8869 /* This is in widget_system.txt but appears to fail
8870 * because there's no gtk_container_realize() that
8871 * realizes all children... instead we just lazily
8872 * wait for map to fix things up.
8874 if (!widget->priv->realized)
8875 g_warning ("%s %p is realized but child %s %p is not realized",
8876 G_OBJECT_TYPE_NAME (parent), parent,
8877 G_OBJECT_TYPE_NAME (widget), widget);
8880 else if (!widget->priv->toplevel)
8882 /* No parent or parent not realized on non-toplevel implies... */
8884 if (widget->priv->realized && !widget->priv->in_reparent)
8885 g_warning ("%s %p is not realized but child %s %p is realized",
8886 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8887 G_OBJECT_TYPE_NAME (widget), widget);
8891 parent->priv->mapped &&
8892 widget->priv->visible &&
8893 widget->priv->child_visible)
8895 /* Parent mapped and we are visible implies... */
8897 if (!widget->priv->mapped)
8898 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8899 G_OBJECT_TYPE_NAME (parent), parent,
8900 G_OBJECT_TYPE_NAME (widget), widget);
8902 else if (!widget->priv->toplevel)
8904 /* No parent or parent not mapped on non-toplevel implies... */
8906 if (widget->priv->mapped && !widget->priv->in_reparent)
8907 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8908 G_OBJECT_TYPE_NAME (widget), widget,
8909 widget->priv->visible,
8910 widget->priv->child_visible,
8911 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8912 parent ? parent->priv->mapped : FALSE);
8916 if (!widget->priv->realized)
8918 /* Not realized implies... */
8921 /* widget_system.txt says these hold, but they don't. */
8922 if (widget->priv->resize_pending)
8923 g_warning ("%s %p resize pending but not realized",
8924 G_OBJECT_TYPE_NAME (widget), widget);
8926 if (widget->priv->alloc_needed)
8927 g_warning ("%s %p alloc needed but not realized",
8928 G_OBJECT_TYPE_NAME (widget), widget);
8930 if (widget->priv->width_request_needed)
8931 g_warning ("%s %p width request needed but not realized",
8932 G_OBJECT_TYPE_NAME (widget), widget);
8934 if (widget->priv->height_request_needed)
8935 g_warning ("%s %p height request needed but not realized",
8936 G_OBJECT_TYPE_NAME (widget), widget);
8941 /* The point of this push/pop is that invariants may not hold while
8942 * we're busy making changes. So we only check at the outermost call
8943 * on the call stack, after we finish updating everything.
8946 gtk_widget_push_verify_invariants (GtkWidget *widget)
8948 widget->priv->verifying_invariants_count += 1;
8952 gtk_widget_verify_child_invariants (GtkWidget *widget,
8953 gpointer client_data)
8955 /* We don't recurse further; this is a one-level check. */
8956 gtk_widget_verify_invariants (widget);
8960 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8962 g_assert (widget->priv->verifying_invariants_count > 0);
8964 widget->priv->verifying_invariants_count -= 1;
8966 if (widget->priv->verifying_invariants_count == 0)
8968 gtk_widget_verify_invariants (widget);
8970 if (GTK_IS_CONTAINER (widget))
8972 /* Check one level of children, because our
8973 * push_verify_invariants() will have prevented some of the
8974 * checks. This does not recurse because if recursion is
8975 * needed, it will happen naturally as each child has a
8976 * push/pop on that child. For example if we're recursively
8977 * mapping children, we'll push/pop on each child as we map
8980 gtk_container_forall (GTK_CONTAINER (widget),
8981 gtk_widget_verify_child_invariants,
8986 #endif /* G_ENABLE_DEBUG */
8988 static PangoContext *
8989 gtk_widget_peek_pango_context (GtkWidget *widget)
8991 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8995 * gtk_widget_get_pango_context:
8996 * @widget: a #GtkWidget
8998 * Gets a #PangoContext with the appropriate font map, font description,
8999 * and base direction for this widget. Unlike the context returned
9000 * by gtk_widget_create_pango_context(), this context is owned by
9001 * the widget (it can be used until the screen for the widget changes
9002 * or the widget is removed from its toplevel), and will be updated to
9003 * match any changes to the widget's attributes.
9005 * If you create and keep a #PangoLayout using this context, you must
9006 * deal with changes to the context by calling pango_layout_context_changed()
9007 * on the layout in response to the #GtkWidget::style-updated and
9008 * #GtkWidget::direction-changed signals for the widget.
9010 * Return value: (transfer none): the #PangoContext for the widget.
9013 gtk_widget_get_pango_context (GtkWidget *widget)
9015 PangoContext *context;
9017 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9019 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
9022 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
9023 g_object_set_qdata_full (G_OBJECT (widget),
9024 quark_pango_context,
9033 update_pango_context (GtkWidget *widget,
9034 PangoContext *context)
9036 const PangoFontDescription *font_desc;
9037 GtkStyleContext *style_context;
9039 style_context = gtk_widget_get_style_context (widget);
9041 font_desc = gtk_style_context_get_font (style_context,
9042 gtk_widget_get_state_flags (widget));
9044 pango_context_set_font_description (context, font_desc);
9045 pango_context_set_base_dir (context,
9046 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
9047 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
9051 gtk_widget_update_pango_context (GtkWidget *widget)
9053 PangoContext *context = gtk_widget_peek_pango_context (widget);
9059 update_pango_context (widget, context);
9061 screen = gtk_widget_get_screen_unchecked (widget);
9064 pango_cairo_context_set_resolution (context,
9065 gdk_screen_get_resolution (screen));
9066 pango_cairo_context_set_font_options (context,
9067 gdk_screen_get_font_options (screen));
9073 * gtk_widget_create_pango_context:
9074 * @widget: a #GtkWidget
9076 * Creates a new #PangoContext with the appropriate font map,
9077 * font description, and base direction for drawing text for
9078 * this widget. See also gtk_widget_get_pango_context().
9080 * Return value: (transfer full): the new #PangoContext
9083 gtk_widget_create_pango_context (GtkWidget *widget)
9086 PangoContext *context;
9088 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9090 screen = gtk_widget_get_screen_unchecked (widget);
9093 GTK_NOTE (MULTIHEAD,
9094 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
9096 screen = gdk_screen_get_default ();
9099 context = gdk_pango_context_get_for_screen (screen);
9101 update_pango_context (widget, context);
9102 pango_context_set_language (context, gtk_get_default_language ());
9108 * gtk_widget_create_pango_layout:
9109 * @widget: a #GtkWidget
9110 * @text: text to set on the layout (can be %NULL)
9112 * Creates a new #PangoLayout with the appropriate font map,
9113 * font description, and base direction for drawing text for
9116 * If you keep a #PangoLayout created in this way around, in order to
9117 * notify the layout of changes to the base direction or font of this
9118 * widget, you must call pango_layout_context_changed() in response to
9119 * the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
9122 * Return value: (transfer full): the new #PangoLayout
9125 gtk_widget_create_pango_layout (GtkWidget *widget,
9128 PangoLayout *layout;
9129 PangoContext *context;
9131 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9133 context = gtk_widget_get_pango_context (widget);
9134 layout = pango_layout_new (context);
9137 pango_layout_set_text (layout, text, -1);
9143 * gtk_widget_render_icon_pixbuf:
9144 * @widget: a #GtkWidget
9145 * @stock_id: a stock ID
9146 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
9147 * render at the size of the source and don't scale (if there are
9148 * multiple source sizes, GTK+ picks one of the available sizes).
9150 * A convenience function that uses the theme engine and style
9151 * settings for @widget to look up @stock_id and render it to
9152 * a pixbuf. @stock_id should be a stock icon ID such as
9153 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
9154 * such as #GTK_ICON_SIZE_MENU.
9156 * The pixels in the returned #GdkPixbuf are shared with the rest of
9157 * the application and should not be modified. The pixbuf should be freed
9158 * after use with g_object_unref().
9160 * Return value: (transfer full): a new pixbuf, or %NULL if the
9161 * stock ID wasn't known
9166 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
9167 const gchar *stock_id,
9170 GtkStyleContext *context;
9171 GtkIconSet *icon_set;
9173 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9174 g_return_val_if_fail (stock_id != NULL, NULL);
9175 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
9177 context = gtk_widget_get_style_context (widget);
9178 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
9180 if (icon_set == NULL)
9183 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
9187 * gtk_widget_render_icon:
9188 * @widget: a #GtkWidget
9189 * @stock_id: a stock ID
9190 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
9191 * render at the size of the source and don't scale (if there are
9192 * multiple source sizes, GTK+ picks one of the available sizes).
9193 * @detail: (allow-none): render detail to pass to theme engine
9195 * A convenience function that uses the theme settings for @widget
9196 * to look up @stock_id and render it to a pixbuf. @stock_id should
9197 * be a stock icon ID such as #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size
9198 * should be a size such as #GTK_ICON_SIZE_MENU. @detail should be a
9199 * string that identifies the widget or code doing the rendering, so
9200 * that theme engines can special-case rendering for that widget or
9203 * The pixels in the returned #GdkPixbuf are shared with the rest of
9204 * the application and should not be modified. The pixbuf should be
9205 * freed after use with g_object_unref().
9207 * Return value: (transfer full): a new pixbuf, or %NULL if the
9208 * stock ID wasn't known
9210 * Deprecated: 3.0: Use gtk_widget_render_icon_pixbuf() instead.
9213 gtk_widget_render_icon (GtkWidget *widget,
9214 const gchar *stock_id,
9216 const gchar *detail)
9218 gtk_widget_ensure_style (widget);
9220 return gtk_widget_render_icon_pixbuf (widget, stock_id, size);
9224 * gtk_widget_set_parent_window:
9225 * @widget: a #GtkWidget.
9226 * @parent_window: the new parent window.
9228 * Sets a non default parent window for @widget.
9230 * For GtkWindow classes, setting a @parent_window effects whether
9231 * the window is a toplevel window or can be embedded into other
9235 * For GtkWindow classes, this needs to be called before the
9236 * window is realized.
9241 gtk_widget_set_parent_window (GtkWidget *widget,
9242 GdkWindow *parent_window)
9244 GdkWindow *old_parent_window;
9246 g_return_if_fail (GTK_IS_WIDGET (widget));
9248 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
9249 quark_parent_window);
9251 if (parent_window != old_parent_window)
9255 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
9257 if (old_parent_window)
9258 g_object_unref (old_parent_window);
9260 g_object_ref (parent_window);
9262 /* Unset toplevel flag when adding a parent window to a widget,
9263 * this is the primary entry point to allow toplevels to be
9266 #ifdef GDK_WINDOWING_X11
9267 is_plug = GTK_IS_PLUG (widget);
9271 if (GTK_IS_WINDOW (widget) && !is_plug)
9272 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
9277 * gtk_widget_get_parent_window:
9278 * @widget: a #GtkWidget.
9280 * Gets @widget's parent window.
9282 * Returns: (transfer none): the parent window of @widget.
9285 gtk_widget_get_parent_window (GtkWidget *widget)
9287 GtkWidgetPrivate *priv;
9288 GdkWindow *parent_window;
9290 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9292 priv = widget->priv;
9294 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
9296 return (parent_window != NULL) ? parent_window :
9297 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
9302 * gtk_widget_set_child_visible:
9303 * @widget: a #GtkWidget
9304 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
9306 * Sets whether @widget should be mapped along with its when its parent
9307 * is mapped and @widget has been shown with gtk_widget_show().
9309 * The child visibility can be set for widget before it is added to
9310 * a container with gtk_widget_set_parent(), to avoid mapping
9311 * children unnecessary before immediately unmapping them. However
9312 * it will be reset to its default state of %TRUE when the widget
9313 * is removed from a container.
9315 * Note that changing the child visibility of a widget does not
9316 * queue a resize on the widget. Most of the time, the size of
9317 * a widget is computed from all visible children, whether or
9318 * not they are mapped. If this is not the case, the container
9319 * can queue a resize itself.
9321 * This function is only useful for container implementations and
9322 * never should be called by an application.
9325 gtk_widget_set_child_visible (GtkWidget *widget,
9326 gboolean is_visible)
9328 GtkWidgetPrivate *priv;
9330 g_return_if_fail (GTK_IS_WIDGET (widget));
9331 g_return_if_fail (!gtk_widget_is_toplevel (widget));
9333 priv = widget->priv;
9335 g_object_ref (widget);
9336 gtk_widget_verify_invariants (widget);
9339 priv->child_visible = TRUE;
9342 GtkWidget *toplevel;
9344 priv->child_visible = FALSE;
9346 toplevel = gtk_widget_get_toplevel (widget);
9347 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
9348 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
9351 if (priv->parent && gtk_widget_get_realized (priv->parent))
9353 if (gtk_widget_get_mapped (priv->parent) &&
9354 priv->child_visible &&
9355 gtk_widget_get_visible (widget))
9356 gtk_widget_map (widget);
9358 gtk_widget_unmap (widget);
9361 gtk_widget_verify_invariants (widget);
9362 g_object_unref (widget);
9366 * gtk_widget_get_child_visible:
9367 * @widget: a #GtkWidget
9369 * Gets the value set with gtk_widget_set_child_visible().
9370 * If you feel a need to use this function, your code probably
9371 * needs reorganization.
9373 * This function is only useful for container implementations and
9374 * never should be called by an application.
9376 * Return value: %TRUE if the widget is mapped with the parent.
9379 gtk_widget_get_child_visible (GtkWidget *widget)
9381 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9383 return widget->priv->child_visible;
9387 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9389 GtkWidget *toplevel;
9391 toplevel = gtk_widget_get_toplevel (widget);
9393 if (gtk_widget_is_toplevel (toplevel))
9395 if (GTK_IS_WINDOW (toplevel))
9396 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9397 else if (GTK_IS_INVISIBLE (toplevel))
9398 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9405 * gtk_widget_get_screen:
9406 * @widget: a #GtkWidget
9408 * Get the #GdkScreen from the toplevel window associated with
9409 * this widget. This function can only be called after the widget
9410 * has been added to a widget hierarchy with a #GtkWindow
9413 * In general, you should only create screen specific
9414 * resources when a widget has been realized, and you should
9415 * free those resources when the widget is unrealized.
9417 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9422 gtk_widget_get_screen (GtkWidget *widget)
9426 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9428 screen = gtk_widget_get_screen_unchecked (widget);
9435 g_warning (G_STRLOC ": Can't get associated screen"
9436 " for a widget unless it is inside a toplevel GtkWindow\n"
9437 " widget type is %s associated top level type is %s",
9438 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9439 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9441 return gdk_screen_get_default ();
9446 * gtk_widget_has_screen:
9447 * @widget: a #GtkWidget
9449 * Checks whether there is a #GdkScreen is associated with
9450 * this widget. All toplevel widgets have an associated
9451 * screen, and all widgets added into a hierarchy with a toplevel
9452 * window at the top.
9454 * Return value: %TRUE if there is a #GdkScreen associcated
9460 gtk_widget_has_screen (GtkWidget *widget)
9462 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9464 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9468 * gtk_widget_get_display:
9469 * @widget: a #GtkWidget
9471 * Get the #GdkDisplay for the toplevel window associated with
9472 * this widget. This function can only be called after the widget
9473 * has been added to a widget hierarchy with a #GtkWindow at the top.
9475 * In general, you should only create display specific
9476 * resources when a widget has been realized, and you should
9477 * free those resources when the widget is unrealized.
9479 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9484 gtk_widget_get_display (GtkWidget *widget)
9486 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9488 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9492 * gtk_widget_get_root_window:
9493 * @widget: a #GtkWidget
9495 * Get the root window where this widget is located. This function can
9496 * only be called after the widget has been added to a widget
9497 * hierarchy with #GtkWindow at the top.
9499 * The root window is useful for such purposes as creating a popup
9500 * #GdkWindow associated with the window. In general, you should only
9501 * create display specific resources when a widget has been realized,
9502 * and you should free those resources when the widget is unrealized.
9504 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9509 gtk_widget_get_root_window (GtkWidget *widget)
9511 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9513 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9517 * gtk_widget_child_focus:
9518 * @widget: a #GtkWidget
9519 * @direction: direction of focus movement
9521 * This function is used by custom widget implementations; if you're
9522 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9523 * to a particular widget, and gtk_container_set_focus_chain() to
9524 * change the focus tab order. So you may want to investigate those
9525 * functions instead.
9527 * gtk_widget_child_focus() is called by containers as the user moves
9528 * around the window using keyboard shortcuts. @direction indicates
9529 * what kind of motion is taking place (up, down, left, right, tab
9530 * forward, tab backward). gtk_widget_child_focus() emits the
9531 * #GtkWidget::focus signal; widgets override the default handler
9532 * for this signal in order to implement appropriate focus behavior.
9534 * The default ::focus handler for a widget should return %TRUE if
9535 * moving in @direction left the focus on a focusable location inside
9536 * that widget, and %FALSE if moving in @direction moved the focus
9537 * outside the widget. If returning %TRUE, widgets normally
9538 * call gtk_widget_grab_focus() to place the focus accordingly;
9539 * if returning %FALSE, they don't modify the current focus location.
9541 * Return value: %TRUE if focus ended up inside @widget
9544 gtk_widget_child_focus (GtkWidget *widget,
9545 GtkDirectionType direction)
9547 gboolean return_val;
9549 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9551 if (!gtk_widget_get_visible (widget) ||
9552 !gtk_widget_is_sensitive (widget))
9555 /* child widgets must set CAN_FOCUS, containers
9556 * don't have to though.
9558 if (!GTK_IS_CONTAINER (widget) &&
9559 !gtk_widget_get_can_focus (widget))
9562 g_signal_emit (widget,
9563 widget_signals[FOCUS],
9565 direction, &return_val);
9571 * gtk_widget_keynav_failed:
9572 * @widget: a #GtkWidget
9573 * @direction: direction of focus movement
9575 * This function should be called whenever keyboard navigation within
9576 * a single widget hits a boundary. The function emits the
9577 * #GtkWidget::keynav-failed signal on the widget and its return
9578 * value should be interpreted in a way similar to the return value of
9579 * gtk_widget_child_focus():
9581 * When %TRUE is returned, stay in the widget, the failed keyboard
9582 * navigation is Ok and/or there is nowhere we can/should move the
9585 * When %FALSE is returned, the caller should continue with keyboard
9586 * navigation outside the widget, e.g. by calling
9587 * gtk_widget_child_focus() on the widget's toplevel.
9589 * The default ::keynav-failed handler returns %TRUE for
9590 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9591 * values of #GtkDirectionType, it looks at the
9592 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9593 * if the setting is %TRUE. This way the entire user interface
9594 * becomes cursor-navigatable on input devices such as mobile phones
9595 * which only have cursor keys but no tab key.
9597 * Whenever the default handler returns %TRUE, it also calls
9598 * gtk_widget_error_bell() to notify the user of the failed keyboard
9601 * A use case for providing an own implementation of ::keynav-failed
9602 * (either by connecting to it or by overriding it) would be a row of
9603 * #GtkEntry widgets where the user should be able to navigate the
9604 * entire row with the cursor keys, as e.g. known from user interfaces
9605 * that require entering license keys.
9607 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9608 * if the emitting widget should try to handle the keyboard
9609 * navigation attempt in its parent container(s).
9614 gtk_widget_keynav_failed (GtkWidget *widget,
9615 GtkDirectionType direction)
9617 gboolean return_val;
9619 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9621 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9622 direction, &return_val);
9628 * gtk_widget_error_bell:
9629 * @widget: a #GtkWidget
9631 * Notifies the user about an input-related error on this widget.
9632 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9633 * gdk_window_beep(), otherwise it does nothing.
9635 * Note that the effect of gdk_window_beep() can be configured in many
9636 * ways, depending on the windowing backend and the desktop environment
9637 * or window manager that is used.
9642 gtk_widget_error_bell (GtkWidget *widget)
9644 GtkWidgetPrivate *priv;
9645 GtkSettings* settings;
9648 g_return_if_fail (GTK_IS_WIDGET (widget));
9650 priv = widget->priv;
9652 settings = gtk_widget_get_settings (widget);
9656 g_object_get (settings,
9657 "gtk-error-bell", &beep,
9660 if (beep && priv->window)
9661 gdk_window_beep (priv->window);
9665 gtk_widget_set_usize_internal (GtkWidget *widget,
9668 GtkQueueResizeFlags flags)
9670 GtkWidgetAuxInfo *aux_info;
9671 gboolean changed = FALSE;
9673 g_object_freeze_notify (G_OBJECT (widget));
9675 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9677 if (width > -2 && aux_info->width != width)
9679 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9680 g_object_notify (G_OBJECT (widget), "width-request");
9681 aux_info->width = width;
9684 if (height > -2 && aux_info->height != height)
9686 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9687 g_object_notify (G_OBJECT (widget), "height-request");
9688 aux_info->height = height;
9692 if (gtk_widget_get_visible (widget) && changed)
9694 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9695 gtk_widget_queue_resize (widget);
9697 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9700 g_object_thaw_notify (G_OBJECT (widget));
9704 * gtk_widget_set_size_request:
9705 * @widget: a #GtkWidget
9706 * @width: width @widget should request, or -1 to unset
9707 * @height: height @widget should request, or -1 to unset
9709 * Sets the minimum size of a widget; that is, the widget's size
9710 * request will be @width by @height. You can use this function to
9711 * force a widget to be either larger or smaller than it normally
9714 * In most cases, gtk_window_set_default_size() is a better choice for
9715 * toplevel windows than this function; setting the default size will
9716 * still allow users to shrink the window. Setting the size request
9717 * will force them to leave the window at least as large as the size
9718 * request. When dealing with window sizes,
9719 * gtk_window_set_geometry_hints() can be a useful function as well.
9721 * Note the inherent danger of setting any fixed size - themes,
9722 * translations into other languages, different fonts, and user action
9723 * can all change the appropriate size for a given widget. So, it's
9724 * basically impossible to hardcode a size that will always be
9727 * The size request of a widget is the smallest size a widget can
9728 * accept while still functioning well and drawing itself correctly.
9729 * However in some strange cases a widget may be allocated less than
9730 * its requested size, and in many cases a widget may be allocated more
9731 * space than it requested.
9733 * If the size request in a given direction is -1 (unset), then
9734 * the "natural" size request of the widget will be used instead.
9736 * Widgets can't actually be allocated a size less than 1 by 1, but
9737 * you can pass 0,0 to this function to mean "as small as possible."
9739 * The size request set here does not include any margin from the
9740 * #GtkWidget properties margin-left, margin-right, margin-top, and
9741 * margin-bottom, but it does include pretty much all other padding
9742 * or border properties set by any subclass of #GtkWidget.
9745 gtk_widget_set_size_request (GtkWidget *widget,
9749 g_return_if_fail (GTK_IS_WIDGET (widget));
9750 g_return_if_fail (width >= -1);
9751 g_return_if_fail (height >= -1);
9758 gtk_widget_set_usize_internal (widget, width, height, 0);
9763 * gtk_widget_get_size_request:
9764 * @widget: a #GtkWidget
9765 * @width: (out) (allow-none): return location for width, or %NULL
9766 * @height: (out) (allow-none): return location for height, or %NULL
9768 * Gets the size request that was explicitly set for the widget using
9769 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9770 * @height indicates that that dimension has not been set explicitly
9771 * and the natural requisition of the widget will be used intead. See
9772 * gtk_widget_set_size_request(). To get the size a widget will
9773 * actually request, call gtk_widget_get_preferred_size() instead of
9777 gtk_widget_get_size_request (GtkWidget *widget,
9781 const GtkWidgetAuxInfo *aux_info;
9783 g_return_if_fail (GTK_IS_WIDGET (widget));
9785 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9788 *width = aux_info->width;
9791 *height = aux_info->height;
9795 * _gtk_widget_override_size_request:
9796 * @widget: a #GtkWidget
9797 * @width: new forced minimum width
9798 * @height: new forced minimum height
9799 * @old_width: location to store previous forced minimum width
9800 * @old_width: location to store previous forced minumum height
9802 * Temporarily establishes a forced minimum size for a widget; this
9803 * is used by GtkWindow when calculating the size to add to the
9804 * window's geometry widget. Cached sizes for the widget and its
9805 * parents are invalidated, so that subsequent calls to the size
9806 * negotiation machinery produce the overriden result, but the
9807 * widget is not queued for relayout or redraw. The old size must
9808 * be restored with _gtk_widget_restore_size_request() or things
9812 _gtk_widget_override_size_request (GtkWidget *widget,
9818 gtk_widget_get_size_request (widget, old_width, old_height);
9819 gtk_widget_set_usize_internal (widget, width, height,
9820 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9824 * _gtk_widget_restore_size_request:
9825 * @widget: a #GtkWidget
9826 * @old_width: saved forced minimum size
9827 * @old_height: saved forced minimum size
9829 * Undoes the operation of_gtk_widget_override_size_request().
9832 _gtk_widget_restore_size_request (GtkWidget *widget,
9836 gtk_widget_set_usize_internal (widget, old_width, old_height,
9837 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9841 * gtk_widget_set_events:
9842 * @widget: a #GtkWidget
9843 * @events: event mask
9845 * Sets the event mask (see #GdkEventMask) for a widget. The event
9846 * mask determines which events a widget will receive. Keep in mind
9847 * that different widgets have different default event masks, and by
9848 * changing the event mask you may disrupt a widget's functionality,
9849 * so be careful. This function must be called while a widget is
9850 * unrealized. Consider gtk_widget_add_events() for widgets that are
9851 * already realized, or if you want to preserve the existing event
9852 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9853 * to get events on those widgets, place them inside a #GtkEventBox
9854 * and receive events on the event box.
9857 gtk_widget_set_events (GtkWidget *widget,
9860 g_return_if_fail (GTK_IS_WIDGET (widget));
9861 g_return_if_fail (!gtk_widget_get_realized (widget));
9863 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9864 GINT_TO_POINTER (events));
9865 g_object_notify (G_OBJECT (widget), "events");
9869 * gtk_widget_set_device_events:
9870 * @widget: a #GtkWidget
9871 * @device: a #GdkDevice
9872 * @events: event mask
9874 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9875 * mask determines which events a widget will receive from @device. Keep
9876 * in mind that different widgets have different default event masks, and by
9877 * changing the event mask you may disrupt a widget's functionality,
9878 * so be careful. This function must be called while a widget is
9879 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9880 * already realized, or if you want to preserve the existing event
9881 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9882 * to get events on those widgets, place them inside a #GtkEventBox
9883 * and receive events on the event box.
9888 gtk_widget_set_device_events (GtkWidget *widget,
9890 GdkEventMask events)
9892 GHashTable *device_events;
9894 g_return_if_fail (GTK_IS_WIDGET (widget));
9895 g_return_if_fail (GDK_IS_DEVICE (device));
9896 g_return_if_fail (!gtk_widget_get_realized (widget));
9898 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9900 if (G_UNLIKELY (!device_events))
9902 device_events = g_hash_table_new (NULL, NULL);
9903 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9904 (GDestroyNotify) g_hash_table_unref);
9907 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9911 * gtk_widget_set_device_enabled:
9912 * @widget: a #GtkWidget
9913 * @device: a #GdkDevice
9914 * @enabled: whether to enable the device
9916 * Enables or disables a #GdkDevice to interact with @widget
9917 * and all its children.
9919 * It does so by descending through the #GdkWindow hierarchy
9920 * and enabling the same mask that is has for core events
9921 * (i.e. the one that gdk_window_get_events() returns).
9926 gtk_widget_set_device_enabled (GtkWidget *widget,
9930 GList *enabled_devices;
9932 g_return_if_fail (GTK_IS_WIDGET (widget));
9933 g_return_if_fail (GDK_IS_DEVICE (device));
9935 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9936 enabled_devices = g_list_append (enabled_devices, device);
9938 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9939 enabled_devices, (GDestroyNotify) g_list_free);;
9941 if (gtk_widget_get_realized (widget))
9942 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9946 * gtk_widget_get_device_enabled:
9947 * @widget: a #GtkWidget
9948 * @device: a #GdkDevice
9950 * Returns whether @device can interact with @widget and its
9951 * children. See gtk_widget_set_device_enabled().
9953 * Return value: %TRUE is @device is enabled for @widget
9958 gtk_widget_get_device_enabled (GtkWidget *widget,
9961 GList *enabled_devices;
9963 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9964 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9966 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9968 return g_list_find (enabled_devices, device) != NULL;
9972 gtk_widget_add_events_internal_list (GtkWidget *widget,
9979 for (l = window_list; l != NULL; l = l->next)
9981 GdkWindow *window = l->data;
9984 gdk_window_get_user_data (window, &user_data);
9985 if (user_data == widget)
9990 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9992 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9994 children = gdk_window_get_children (window);
9995 gtk_widget_add_events_internal_list (widget, device, events, children);
9996 g_list_free (children);
10002 gtk_widget_add_events_internal (GtkWidget *widget,
10006 GtkWidgetPrivate *priv = widget->priv;
10007 GList *window_list;
10009 if (!gtk_widget_get_has_window (widget))
10010 window_list = gdk_window_get_children (priv->window);
10012 window_list = g_list_prepend (NULL, priv->window);
10014 gtk_widget_add_events_internal_list (widget, device, events, window_list);
10016 g_list_free (window_list);
10020 * gtk_widget_add_events:
10021 * @widget: a #GtkWidget
10022 * @events: an event mask, see #GdkEventMask
10024 * Adds the events in the bitfield @events to the event mask for
10025 * @widget. See gtk_widget_set_events() for details.
10028 gtk_widget_add_events (GtkWidget *widget,
10033 g_return_if_fail (GTK_IS_WIDGET (widget));
10035 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10036 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
10037 GINT_TO_POINTER (old_events | events));
10039 if (gtk_widget_get_realized (widget))
10041 gtk_widget_add_events_internal (widget, NULL, events);
10042 gtk_widget_update_devices_mask (widget, FALSE);
10045 g_object_notify (G_OBJECT (widget), "events");
10049 * gtk_widget_add_device_events:
10050 * @widget: a #GtkWidget
10051 * @device: a #GdkDevice
10052 * @events: an event mask, see #GdkEventMask
10054 * Adds the device events in the bitfield @events to the event mask for
10055 * @widget. See gtk_widget_set_device_events() for details.
10060 gtk_widget_add_device_events (GtkWidget *widget,
10062 GdkEventMask events)
10064 GdkEventMask old_events;
10065 GHashTable *device_events;
10067 g_return_if_fail (GTK_IS_WIDGET (widget));
10068 g_return_if_fail (GDK_IS_DEVICE (device));
10070 old_events = gtk_widget_get_device_events (widget, device);
10072 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10074 if (G_UNLIKELY (!device_events))
10076 device_events = g_hash_table_new (NULL, NULL);
10077 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
10078 (GDestroyNotify) g_hash_table_unref);
10081 g_hash_table_insert (device_events, device,
10082 GUINT_TO_POINTER (old_events | events));
10084 if (gtk_widget_get_realized (widget))
10085 gtk_widget_add_events_internal (widget, device, events);
10087 g_object_notify (G_OBJECT (widget), "events");
10091 * gtk_widget_get_toplevel:
10092 * @widget: a #GtkWidget
10094 * This function returns the topmost widget in the container hierarchy
10095 * @widget is a part of. If @widget has no parent widgets, it will be
10096 * returned as the topmost widget. No reference will be added to the
10097 * returned widget; it should not be unreferenced.
10099 * Note the difference in behavior vs. gtk_widget_get_ancestor();
10100 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
10102 * %NULL if @widget wasn't inside a toplevel window, and if the
10103 * window was inside a #GtkWindow-derived widget which was in turn
10104 * inside the toplevel #GtkWindow. While the second case may
10105 * seem unlikely, it actually happens when a #GtkPlug is embedded
10106 * inside a #GtkSocket within the same application.
10108 * To reliably find the toplevel #GtkWindow, use
10109 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
10110 * is set on the result.
10112 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
10113 * if (gtk_widget_is_toplevel (toplevel))
10115 * /* Perform action on toplevel. */
10119 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
10120 * if there's no ancestor.
10123 gtk_widget_get_toplevel (GtkWidget *widget)
10125 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10127 while (widget->priv->parent)
10128 widget = widget->priv->parent;
10134 * gtk_widget_get_ancestor:
10135 * @widget: a #GtkWidget
10136 * @widget_type: ancestor type
10138 * Gets the first ancestor of @widget with type @widget_type. For example,
10139 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
10140 * the first #GtkBox that's an ancestor of @widget. No reference will be
10141 * added to the returned widget; it should not be unreferenced. See note
10142 * about checking for a toplevel #GtkWindow in the docs for
10143 * gtk_widget_get_toplevel().
10145 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
10146 * considers @widget to be an ancestor of itself.
10148 * Return value: (transfer none): the ancestor widget, or %NULL if not found
10151 gtk_widget_get_ancestor (GtkWidget *widget,
10154 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10156 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
10157 widget = widget->priv->parent;
10159 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
10166 * gtk_widget_set_visual:
10167 * @widget: a #GtkWidget
10168 * @visual: visual to be used or %NULL to unset a previous one
10170 * Sets the visual that should be used for by widget and its children for
10171 * creating #GdkWindows. The visual must be on the same #GdkScreen as
10172 * returned by gdk_widget_get_screen(), so handling the
10173 * #GtkWidget::screen-changed signal is necessary.
10175 * Setting a new @visual will not cause @widget to recreate its windows,
10176 * so you should call this function before @widget is realized.
10179 gtk_widget_set_visual (GtkWidget *widget,
10182 g_return_if_fail (GTK_IS_WIDGET (widget));
10183 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
10186 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
10189 g_object_set_qdata_full (G_OBJECT (widget),
10191 g_object_ref (visual),
10196 * gtk_widget_get_visual:
10197 * @widget: a #GtkWidget
10199 * Gets the visual that will be used to render @widget.
10201 * Return value: (transfer none): the visual for @widget
10204 gtk_widget_get_visual (GtkWidget *widget)
10210 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10212 if (gtk_widget_get_has_window (widget) &&
10213 widget->priv->window)
10214 return gdk_window_get_visual (widget->priv->window);
10216 screen = gtk_widget_get_screen (widget);
10218 for (w = widget; w != NULL; w = w->priv->parent)
10220 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
10223 if (gdk_visual_get_screen (visual) == screen)
10226 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
10227 gtk_widget_get_name (widget));
10231 return gdk_screen_get_system_visual (screen);
10235 * gtk_widget_get_settings:
10236 * @widget: a #GtkWidget
10238 * Gets the settings object holding the settings used for this widget.
10240 * Note that this function can only be called when the #GtkWidget
10241 * is attached to a toplevel, since the settings object is specific
10242 * to a particular #GdkScreen.
10244 * Return value: (transfer none): the relevant #GtkSettings object
10247 gtk_widget_get_settings (GtkWidget *widget)
10249 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10251 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
10255 * gtk_widget_get_events:
10256 * @widget: a #GtkWidget
10258 * Returns the event mask for the widget (a bitfield containing flags
10259 * from the #GdkEventMask enumeration). These are the events that the widget
10262 * Return value: event mask for @widget
10265 gtk_widget_get_events (GtkWidget *widget)
10267 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10269 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10273 * gtk_widget_get_device_events:
10274 * @widget: a #GtkWidget
10275 * @device: a #GdkDevice
10277 * Returns the events mask for the widget corresponding to an specific device. These
10278 * are the events that the widget will receive when @device operates on it.
10280 * Returns: device event mask for @widget
10285 gtk_widget_get_device_events (GtkWidget *widget,
10288 GHashTable *device_events;
10290 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10291 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
10293 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10295 if (!device_events)
10298 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
10302 * gtk_widget_get_pointer:
10303 * @widget: a #GtkWidget
10304 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
10305 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
10307 * Obtains the location of the mouse pointer in widget coordinates.
10308 * Widget coordinates are a bit odd; for historical reasons, they are
10309 * defined as @widget->window coordinates for widgets that are not
10310 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
10311 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
10314 gtk_widget_get_pointer (GtkWidget *widget,
10318 GtkWidgetPrivate *priv;
10320 g_return_if_fail (GTK_IS_WIDGET (widget));
10322 priv = widget->priv;
10329 if (gtk_widget_get_realized (widget))
10331 gdk_window_get_pointer (priv->window, x, y, NULL);
10333 if (!gtk_widget_get_has_window (widget))
10336 *x -= priv->allocation.x;
10338 *y -= priv->allocation.y;
10344 * gtk_widget_is_ancestor:
10345 * @widget: a #GtkWidget
10346 * @ancestor: another #GtkWidget
10348 * Determines whether @widget is somewhere inside @ancestor, possibly with
10349 * intermediate containers.
10351 * Return value: %TRUE if @ancestor contains @widget as a child,
10352 * grandchild, great grandchild, etc.
10355 gtk_widget_is_ancestor (GtkWidget *widget,
10356 GtkWidget *ancestor)
10358 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10359 g_return_val_if_fail (ancestor != NULL, FALSE);
10363 if (widget->priv->parent == ancestor)
10365 widget = widget->priv->parent;
10371 static GQuark quark_composite_name = 0;
10374 * gtk_widget_set_composite_name:
10375 * @widget: a #GtkWidget.
10376 * @name: the name to set
10378 * Sets a widgets composite name. The widget must be
10379 * a composite child of its parent; see gtk_widget_push_composite_child().
10382 gtk_widget_set_composite_name (GtkWidget *widget,
10385 g_return_if_fail (GTK_IS_WIDGET (widget));
10386 g_return_if_fail (widget->priv->composite_child);
10387 g_return_if_fail (name != NULL);
10389 if (!quark_composite_name)
10390 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10392 g_object_set_qdata_full (G_OBJECT (widget),
10393 quark_composite_name,
10399 * gtk_widget_get_composite_name:
10400 * @widget: a #GtkWidget
10402 * Obtains the composite name of a widget.
10404 * Returns: the composite name of @widget, or %NULL if @widget is not
10405 * a composite child. The string should be freed when it is no
10409 gtk_widget_get_composite_name (GtkWidget *widget)
10411 GtkWidgetPrivate *priv;
10413 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10415 priv = widget->priv;
10417 if (widget->priv->composite_child && priv->parent)
10418 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10425 * gtk_widget_push_composite_child:
10427 * Makes all newly-created widgets as composite children until
10428 * the corresponding gtk_widget_pop_composite_child() call.
10430 * A composite child is a child that's an implementation detail of the
10431 * container it's inside and should not be visible to people using the
10432 * container. Composite children aren't treated differently by GTK (but
10433 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10434 * builders might want to treat them in a different way.
10436 * Here is a simple example:
10438 * gtk_widget_push_composite_child ();
10439 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10440 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10441 * gtk_widget_pop_composite_child ();
10442 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10443 * GTK_WIDGET (scrolled_window));
10444 * g_object_ref (scrolled_window->hscrollbar);
10448 gtk_widget_push_composite_child (void)
10450 composite_child_stack++;
10454 * gtk_widget_pop_composite_child:
10456 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10459 gtk_widget_pop_composite_child (void)
10461 if (composite_child_stack)
10462 composite_child_stack--;
10466 gtk_widget_emit_direction_changed (GtkWidget *widget,
10467 GtkTextDirection old_dir)
10469 gtk_widget_update_pango_context (widget);
10471 if (widget->priv->context)
10472 gtk_style_context_set_direction (widget->priv->context,
10473 gtk_widget_get_direction (widget));
10475 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10479 * gtk_widget_set_direction:
10480 * @widget: a #GtkWidget
10481 * @dir: the new direction
10483 * Sets the reading direction on a particular widget. This direction
10484 * controls the primary direction for widgets containing text,
10485 * and also the direction in which the children of a container are
10486 * packed. The ability to set the direction is present in order
10487 * so that correct localization into languages with right-to-left
10488 * reading directions can be done. Generally, applications will
10489 * let the default reading direction present, except for containers
10490 * where the containers are arranged in an order that is explicitely
10491 * visual rather than logical (such as buttons for text justification).
10493 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10494 * set by gtk_widget_set_default_direction() will be used.
10497 gtk_widget_set_direction (GtkWidget *widget,
10498 GtkTextDirection dir)
10500 GtkTextDirection old_dir;
10502 g_return_if_fail (GTK_IS_WIDGET (widget));
10503 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10505 old_dir = gtk_widget_get_direction (widget);
10507 widget->priv->direction = dir;
10509 if (old_dir != gtk_widget_get_direction (widget))
10510 gtk_widget_emit_direction_changed (widget, old_dir);
10514 * gtk_widget_get_direction:
10515 * @widget: a #GtkWidget
10517 * Gets the reading direction for a particular widget. See
10518 * gtk_widget_set_direction().
10520 * Return value: the reading direction for the widget.
10523 gtk_widget_get_direction (GtkWidget *widget)
10525 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10527 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10528 return gtk_default_direction;
10530 return widget->priv->direction;
10534 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10536 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10538 g_object_ref (widget);
10540 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10541 gtk_widget_emit_direction_changed (widget, old_dir);
10543 if (GTK_IS_CONTAINER (widget))
10544 gtk_container_forall (GTK_CONTAINER (widget),
10545 gtk_widget_set_default_direction_recurse,
10548 g_object_unref (widget);
10552 * gtk_widget_set_default_direction:
10553 * @dir: the new default direction. This cannot be
10554 * %GTK_TEXT_DIR_NONE.
10556 * Sets the default reading direction for widgets where the
10557 * direction has not been explicitly set by gtk_widget_set_direction().
10560 gtk_widget_set_default_direction (GtkTextDirection dir)
10562 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10564 if (dir != gtk_default_direction)
10566 GList *toplevels, *tmp_list;
10567 GtkTextDirection old_dir = gtk_default_direction;
10569 gtk_default_direction = dir;
10571 tmp_list = toplevels = gtk_window_list_toplevels ();
10572 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10576 gtk_widget_set_default_direction_recurse (tmp_list->data,
10577 GUINT_TO_POINTER (old_dir));
10578 g_object_unref (tmp_list->data);
10579 tmp_list = tmp_list->next;
10582 g_list_free (toplevels);
10587 * gtk_widget_get_default_direction:
10589 * Obtains the current default reading direction. See
10590 * gtk_widget_set_default_direction().
10592 * Return value: the current default direction.
10595 gtk_widget_get_default_direction (void)
10597 return gtk_default_direction;
10601 gtk_widget_dispose (GObject *object)
10603 GtkWidget *widget = GTK_WIDGET (object);
10604 GtkWidgetPrivate *priv = widget->priv;
10607 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10608 else if (gtk_widget_get_visible (widget))
10609 gtk_widget_hide (widget);
10611 priv->visible = FALSE;
10612 if (gtk_widget_get_realized (widget))
10613 gtk_widget_unrealize (widget);
10615 if (!priv->in_destruction)
10617 priv->in_destruction = TRUE;
10618 g_signal_emit (object, widget_signals[DESTROY], 0);
10619 priv->in_destruction = FALSE;
10622 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10626 gtk_widget_real_destroy (GtkWidget *object)
10628 /* gtk_object_destroy() will already hold a refcount on object */
10629 GtkWidget *widget = GTK_WIDGET (object);
10630 GtkWidgetPrivate *priv = widget->priv;
10632 /* wipe accelerator closures (keep order) */
10633 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10634 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10636 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10637 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10639 gtk_grab_remove (widget);
10642 g_object_unref (priv->style);
10643 priv->style = gtk_widget_get_default_style ();
10644 g_object_ref (priv->style);
10648 gtk_widget_finalize (GObject *object)
10650 GtkWidget *widget = GTK_WIDGET (object);
10651 GtkWidgetPrivate *priv = widget->priv;
10652 GtkWidgetAuxInfo *aux_info;
10653 GtkAccessible *accessible;
10655 gtk_grab_remove (widget);
10657 g_object_unref (priv->style);
10658 priv->style = NULL;
10660 g_free (priv->name);
10662 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10664 gtk_widget_aux_info_destroy (aux_info);
10666 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10668 g_object_unref (accessible);
10671 gtk_widget_path_free (priv->path);
10674 g_object_unref (priv->context);
10676 _gtk_widget_free_cached_sizes (widget);
10678 if (g_object_is_floating (object))
10679 g_warning ("A floating object was finalized. This means that someone\n"
10680 "called g_object_unref() on an object that had only a floating\n"
10681 "reference; the initial floating reference is not owned by anyone\n"
10682 "and must be removed with g_object_ref_sink().");
10684 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10687 /*****************************************
10688 * gtk_widget_real_map:
10693 *****************************************/
10696 gtk_widget_real_map (GtkWidget *widget)
10698 GtkWidgetPrivate *priv = widget->priv;
10700 g_assert (gtk_widget_get_realized (widget));
10702 if (!gtk_widget_get_mapped (widget))
10704 gtk_widget_set_mapped (widget, TRUE);
10706 if (gtk_widget_get_has_window (widget))
10707 gdk_window_show (priv->window);
10711 /*****************************************
10712 * gtk_widget_real_unmap:
10717 *****************************************/
10720 gtk_widget_real_unmap (GtkWidget *widget)
10722 GtkWidgetPrivate *priv = widget->priv;
10724 if (gtk_widget_get_mapped (widget))
10726 gtk_widget_set_mapped (widget, FALSE);
10728 if (gtk_widget_get_has_window (widget))
10729 gdk_window_hide (priv->window);
10733 /*****************************************
10734 * gtk_widget_real_realize:
10739 *****************************************/
10742 gtk_widget_real_realize (GtkWidget *widget)
10744 GtkWidgetPrivate *priv = widget->priv;
10746 g_assert (!gtk_widget_get_has_window (widget));
10748 gtk_widget_set_realized (widget, TRUE);
10751 priv->window = gtk_widget_get_parent_window (widget);
10752 g_object_ref (priv->window);
10756 /*****************************************
10757 * gtk_widget_real_unrealize:
10762 *****************************************/
10765 gtk_widget_real_unrealize (GtkWidget *widget)
10767 GtkWidgetPrivate *priv = widget->priv;
10769 g_assert (!widget->priv->mapped);
10771 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10774 /* We must do unrealize child widget BEFORE container widget.
10775 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10776 * So, unrealizing container widget bofore its children causes the problem
10777 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10780 if (GTK_IS_CONTAINER (widget))
10781 gtk_container_forall (GTK_CONTAINER (widget),
10782 (GtkCallback) gtk_widget_unrealize,
10785 if (gtk_widget_get_has_window (widget))
10787 gdk_window_set_user_data (priv->window, NULL);
10788 gdk_window_destroy (priv->window);
10789 priv->window = NULL;
10793 g_object_unref (priv->window);
10794 priv->window = NULL;
10797 gtk_selection_remove_all (widget);
10799 gtk_widget_set_realized (widget, FALSE);
10803 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10804 GtkOrientation orientation,
10805 gint *minimum_size,
10806 gint *natural_size)
10808 const GtkWidgetAuxInfo *aux_info;
10810 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10812 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10813 aux_info->width > 0)
10815 *minimum_size = MAX (*minimum_size, aux_info->width);
10817 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10818 aux_info->height > 0)
10820 *minimum_size = MAX (*minimum_size, aux_info->height);
10823 /* Fix it if set_size_request made natural size smaller than min size.
10824 * This would also silently fix broken widgets, but we warn about them
10825 * in gtksizerequest.c when calling their size request vfuncs.
10827 *natural_size = MAX (*natural_size, *minimum_size);
10829 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10831 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10832 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10836 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10837 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10842 * _gtk_widget_peek_request_cache:
10844 * Returns the address of the widget's request cache (strictly for
10845 * internal use in gtksizerequest.c)
10847 * Return value: the address of @widget's size request cache.
10850 _gtk_widget_peek_request_cache (GtkWidget *widget)
10852 /* Don't bother slowing things down with the return_if_fail guards here */
10853 return &widget->priv->requests;
10857 * _gtk_widget_set_device_window:
10858 * @widget: a #GtkWidget
10859 * @device: a #GdkDevice
10860 * @window: the new device window
10862 * Sets pointer window for @widget and @device.
10863 * Does not ref @window.
10866 _gtk_widget_set_device_window (GtkWidget *widget,
10870 GHashTable *device_window;
10872 g_return_if_fail (GTK_IS_WIDGET (widget));
10873 g_return_if_fail (GDK_IS_DEVICE (device));
10874 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10876 if (!gtk_widget_get_mapped (widget))
10879 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10881 if (!device_window && window)
10883 device_window = g_hash_table_new (NULL, NULL);
10884 g_object_set_qdata_full (G_OBJECT (widget),
10885 quark_pointer_window,
10887 (GDestroyNotify) g_hash_table_destroy);
10891 g_hash_table_insert (device_window, device, window);
10892 else if (device_window)
10894 g_hash_table_remove (device_window, device);
10896 if (g_hash_table_size (device_window) == 0)
10897 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10902 * _gtk_widget_get_device_window:
10903 * @widget: a #GtkWidget
10904 * @device: a #GdkDevice
10906 * Return value: the device window set on @widget, or %NULL
10909 _gtk_widget_get_device_window (GtkWidget *widget,
10912 GHashTable *device_window;
10914 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10915 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10917 if (!gtk_widget_get_mapped (widget))
10920 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10922 if (!device_window)
10925 return g_hash_table_lookup (device_window, device);
10929 * _gtk_widget_list_devices:
10930 * @widget: a #GtkWidget
10932 * Returns the list of #GdkDevices that is currently on top
10933 * of any window belonging to @widget.
10934 * Free the list with g_list_free(), the elements are owned
10935 * by GTK+ and must not be freed.
10938 _gtk_widget_list_devices (GtkWidget *widget)
10940 GHashTableIter iter;
10941 GHashTable *device_window;
10942 GList *devices = NULL;
10943 gpointer key, value;
10945 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10947 if (!gtk_widget_get_mapped (widget))
10950 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10952 if (G_UNLIKELY (!device_window))
10955 g_hash_table_iter_init (&iter, device_window);
10957 while (g_hash_table_iter_next (&iter, &key, &value))
10958 devices = g_list_prepend (devices, key);
10964 synth_crossing (GtkWidget *widget,
10968 GdkCrossingMode mode,
10969 GdkNotifyType detail)
10973 event = gdk_event_new (type);
10975 event->crossing.window = g_object_ref (window);
10976 event->crossing.send_event = TRUE;
10977 event->crossing.subwindow = g_object_ref (window);
10978 event->crossing.time = GDK_CURRENT_TIME;
10979 event->crossing.x = event->crossing.y = 0;
10980 event->crossing.x_root = event->crossing.y_root = 0;
10981 event->crossing.mode = mode;
10982 event->crossing.detail = detail;
10983 event->crossing.focus = FALSE;
10984 event->crossing.state = 0;
10985 gdk_event_set_device (event, device);
10988 widget = gtk_get_event_widget (event);
10991 gtk_widget_event_internal (widget, event);
10993 gdk_event_free (event);
10997 * _gtk_widget_synthesize_crossing:
10998 * @from: the #GtkWidget the virtual pointer is leaving.
10999 * @to: the #GtkWidget the virtual pointer is moving to.
11000 * @mode: the #GdkCrossingMode to place on the synthesized events.
11002 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
11004 * The real pointer window is the window that most recently received an enter notify
11005 * event. Windows that don't select for crossing events can't become the real
11006 * poiner window. The real pointer widget that owns the real pointer window. The
11007 * effective pointer window is the same as the real pointer window unless the real
11008 * pointer widget is either insensitive or there is a grab on a widget that is not
11009 * an ancestor of the real pointer widget (in which case the effective pointer
11010 * window should be the root window).
11012 * When the effective pointer window is the same as the real poiner window, we
11013 * receive crossing events from the windowing system. When the effective pointer
11014 * window changes to become different from the real pointer window we synthesize
11015 * crossing events, attempting to follow X protocol rules:
11017 * When the root window becomes the effective pointer window:
11018 * - leave notify on real pointer window, detail Ancestor
11019 * - leave notify on all of its ancestors, detail Virtual
11020 * - enter notify on root window, detail Inferior
11022 * When the root window ceases to be the effective pointer window:
11023 * - leave notify on root window, detail Inferior
11024 * - enter notify on all ancestors of real pointer window, detail Virtual
11025 * - enter notify on real pointer window, detail Ancestor
11028 _gtk_widget_synthesize_crossing (GtkWidget *from,
11031 GdkCrossingMode mode)
11033 GdkWindow *from_window = NULL, *to_window = NULL;
11035 g_return_if_fail (from != NULL || to != NULL);
11039 from_window = _gtk_widget_get_device_window (from, device);
11042 from_window = from->priv->window;
11047 to_window = _gtk_widget_get_device_window (to, device);
11050 to_window = to->priv->window;
11053 if (from_window == NULL && to_window == NULL)
11055 else if (from_window != NULL && to_window == NULL)
11057 GList *from_ancestors = NULL, *list;
11058 GdkWindow *from_ancestor = from_window;
11060 while (from_ancestor != NULL)
11062 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
11063 if (from_ancestor == NULL)
11065 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
11068 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11069 device, mode, GDK_NOTIFY_ANCESTOR);
11070 for (list = g_list_last (from_ancestors); list; list = list->prev)
11072 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11073 device, mode, GDK_NOTIFY_VIRTUAL);
11076 /* XXX: enter/inferior on root window? */
11078 g_list_free (from_ancestors);
11080 else if (from_window == NULL && to_window != NULL)
11082 GList *to_ancestors = NULL, *list;
11083 GdkWindow *to_ancestor = to_window;
11085 while (to_ancestor != NULL)
11087 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
11088 if (to_ancestor == NULL)
11090 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
11093 /* XXX: leave/inferior on root window? */
11095 for (list = to_ancestors; list; list = list->next)
11097 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11098 device, mode, GDK_NOTIFY_VIRTUAL);
11100 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11101 device, mode, GDK_NOTIFY_ANCESTOR);
11103 g_list_free (to_ancestors);
11105 else if (from_window == to_window)
11109 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
11110 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
11112 while (from_ancestor != NULL || to_ancestor != NULL)
11114 if (from_ancestor != NULL)
11116 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
11117 if (from_ancestor == to_window)
11120 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
11122 if (to_ancestor != NULL)
11124 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
11125 if (to_ancestor == from_window)
11128 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
11131 if (to_ancestor == from_window)
11133 if (mode != GDK_CROSSING_GTK_UNGRAB)
11134 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11135 device, mode, GDK_NOTIFY_INFERIOR);
11136 for (list = to_ancestors; list; list = list->next)
11137 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11138 device, mode, GDK_NOTIFY_VIRTUAL);
11139 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11140 device, mode, GDK_NOTIFY_ANCESTOR);
11142 else if (from_ancestor == to_window)
11144 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11145 device, mode, GDK_NOTIFY_ANCESTOR);
11146 for (list = g_list_last (from_ancestors); list; list = list->prev)
11148 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11149 device, mode, GDK_NOTIFY_VIRTUAL);
11151 if (mode != GDK_CROSSING_GTK_GRAB)
11152 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11153 device, mode, GDK_NOTIFY_INFERIOR);
11157 while (from_ancestors != NULL && to_ancestors != NULL
11158 && from_ancestors->data == to_ancestors->data)
11160 from_ancestors = g_list_delete_link (from_ancestors,
11162 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
11165 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11166 device, mode, GDK_NOTIFY_NONLINEAR);
11168 for (list = g_list_last (from_ancestors); list; list = list->prev)
11170 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11171 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11173 for (list = to_ancestors; list; list = list->next)
11175 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11176 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11178 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11179 device, mode, GDK_NOTIFY_NONLINEAR);
11181 g_list_free (from_ancestors);
11182 g_list_free (to_ancestors);
11187 gtk_widget_propagate_state (GtkWidget *widget,
11188 GtkStateData *data)
11190 GtkWidgetPrivate *priv = widget->priv;
11191 GtkStateFlags new_flags, old_flags = priv->state_flags;
11192 GtkStateType old_state;
11194 old_state = gtk_widget_get_state (widget);
11196 switch (data->operation)
11198 case STATE_CHANGE_REPLACE:
11199 priv->state_flags = data->flags;
11201 case STATE_CHANGE_SET:
11202 priv->state_flags |= data->flags;
11204 case STATE_CHANGE_UNSET:
11205 priv->state_flags &= ~(data->flags);
11209 /* make insensitivity unoverridable */
11210 if (!priv->sensitive)
11211 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
11213 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
11217 window = gtk_widget_get_toplevel (widget);
11219 if (window && gtk_widget_is_toplevel (window))
11220 gtk_window_set_focus (GTK_WINDOW (window), NULL);
11223 new_flags = priv->state_flags;
11225 if (old_flags != new_flags)
11227 g_object_ref (widget);
11229 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
11230 gtk_grab_remove (widget);
11232 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
11233 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
11235 if (!priv->shadowed)
11237 GList *event_windows = NULL;
11238 GList *devices, *d;
11240 devices = _gtk_widget_list_devices (widget);
11242 for (d = devices; d; d = d->next)
11248 window = _gtk_widget_get_device_window (widget, device);
11250 /* Do not propagate more than once to the
11251 * same window if non-multidevice aware.
11253 if (!gdk_window_get_support_multidevice (window) &&
11254 g_list_find (event_windows, window))
11257 if (!gtk_widget_is_sensitive (widget))
11258 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
11259 GDK_CROSSING_STATE_CHANGED);
11260 else if (old_flags & GTK_STATE_FLAG_INSENSITIVE)
11261 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
11262 GDK_CROSSING_STATE_CHANGED);
11264 event_windows = g_list_prepend (event_windows, window);
11267 g_list_free (event_windows);
11268 g_list_free (devices);
11271 if (GTK_IS_CONTAINER (widget))
11273 GtkStateData child_data = *data;
11275 /* Make sure to only propate the right states further */
11276 child_data.flags &= GTK_STATE_FLAGS_DO_PROPAGATE;
11278 if (child_data.use_forall)
11279 gtk_container_forall (GTK_CONTAINER (widget),
11280 (GtkCallback) gtk_widget_propagate_state,
11283 gtk_container_foreach (GTK_CONTAINER (widget),
11284 (GtkCallback) gtk_widget_propagate_state,
11288 /* Trigger state change transitions for the widget */
11289 if (priv->context &&
11290 gtk_widget_get_mapped (widget))
11292 gint diff, flag = 1;
11294 diff = old_flags ^ new_flags;
11298 if ((diff & flag) != 0)
11302 target = ((new_flags & flag) != 0);
11303 _gtk_widget_notify_state_change (widget, flag, target);
11312 g_object_unref (widget);
11316 static const GtkWidgetAuxInfo default_aux_info = {
11324 * gtk_widget_get_aux_info:
11325 * @widget: a #GtkWidget
11326 * @create: if %TRUE, create the structure if it doesn't exist
11328 * Get the #GtkWidgetAuxInfo structure for the widget.
11330 * Return value: the #GtkAuxInfo structure for the widget, or
11331 * %NULL if @create is %FALSE and one doesn't already exist.
11333 static GtkWidgetAuxInfo *
11334 gtk_widget_get_aux_info (GtkWidget *widget,
11337 GtkWidgetAuxInfo *aux_info;
11339 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
11340 if (!aux_info && create)
11342 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
11344 *aux_info = default_aux_info;
11346 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
11352 static const GtkWidgetAuxInfo*
11353 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11355 GtkWidgetAuxInfo *aux_info;
11357 aux_info = gtk_widget_get_aux_info (widget, FALSE);
11358 if (aux_info == NULL)
11360 return &default_aux_info;
11368 /*****************************************
11369 * gtk_widget_aux_info_destroy:
11374 *****************************************/
11377 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11379 g_slice_free (GtkWidgetAuxInfo, aux_info);
11383 * gtk_widget_shape_combine_region:
11384 * @widget: a #GtkWidget
11385 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11387 * Sets a shape for this widget's GDK window. This allows for
11388 * transparent windows etc., see gdk_window_shape_combine_region()
11389 * for more information.
11394 gtk_widget_shape_combine_region (GtkWidget *widget,
11395 cairo_region_t *region)
11397 GtkWidgetPrivate *priv;
11399 g_return_if_fail (GTK_IS_WIDGET (widget));
11400 /* set_shape doesn't work on widgets without gdk window */
11401 g_return_if_fail (gtk_widget_get_has_window (widget));
11403 priv = widget->priv;
11405 if (region == NULL)
11407 priv->has_shape_mask = FALSE;
11410 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11412 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11416 priv->has_shape_mask = TRUE;
11418 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11419 cairo_region_copy (region),
11420 (GDestroyNotify) cairo_region_destroy);
11422 /* set shape if widget has a gdk window already.
11423 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11426 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11431 * gtk_widget_input_shape_combine_region:
11432 * @widget: a #GtkWidget
11433 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11435 * Sets an input shape for this widget's GDK window. This allows for
11436 * windows which react to mouse click in a nonrectangular region, see
11437 * gdk_window_input_shape_combine_region() for more information.
11442 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11443 cairo_region_t *region)
11445 GtkWidgetPrivate *priv;
11447 g_return_if_fail (GTK_IS_WIDGET (widget));
11448 /* set_shape doesn't work on widgets without gdk window */
11449 g_return_if_fail (gtk_widget_get_has_window (widget));
11451 priv = widget->priv;
11453 if (region == NULL)
11456 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11458 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11462 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11463 cairo_region_copy (region),
11464 (GDestroyNotify) cairo_region_destroy);
11466 /* set shape if widget has a gdk window already.
11467 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11470 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11475 /* style properties
11479 * gtk_widget_class_install_style_property_parser: (skip)
11480 * @klass: a #GtkWidgetClass
11481 * @pspec: the #GParamSpec for the style property
11482 * @parser: the parser for the style property
11484 * Installs a style property on a widget class.
11487 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11489 GtkRcPropertyParser parser)
11491 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11492 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11493 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11494 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11496 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11498 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11499 G_OBJECT_CLASS_NAME (klass),
11504 g_param_spec_ref_sink (pspec);
11505 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11506 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11510 * gtk_widget_class_install_style_property:
11511 * @klass: a #GtkWidgetClass
11512 * @pspec: the #GParamSpec for the property
11514 * Installs a style property on a widget class. The parser for the
11515 * style property is determined by the value type of @pspec.
11518 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11521 GtkRcPropertyParser parser;
11523 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11524 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11526 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11528 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11532 * gtk_widget_class_find_style_property:
11533 * @klass: a #GtkWidgetClass
11534 * @property_name: the name of the style property to find
11535 * @returns: (transfer none): the #GParamSpec of the style property or
11536 * %NULL if @class has no style property with that name.
11538 * Finds a style property of a widget class by name.
11543 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11544 const gchar *property_name)
11546 g_return_val_if_fail (property_name != NULL, NULL);
11548 return g_param_spec_pool_lookup (style_property_spec_pool,
11550 G_OBJECT_CLASS_TYPE (klass),
11555 * gtk_widget_class_list_style_properties:
11556 * @klass: a #GtkWidgetClass
11557 * @n_properties: location to return the number of style properties found
11558 * @returns: (array length=n_properties) (transfer container): an
11559 * newly allocated array of #GParamSpec*. The array must be
11560 * freed with g_free().
11562 * Returns all style properties of a widget class.
11567 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11568 guint *n_properties)
11570 GParamSpec **pspecs;
11573 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11574 G_OBJECT_CLASS_TYPE (klass),
11583 * gtk_widget_style_get_property:
11584 * @widget: a #GtkWidget
11585 * @property_name: the name of a style property
11586 * @value: location to return the property value
11588 * Gets the value of a style property of @widget.
11591 gtk_widget_style_get_property (GtkWidget *widget,
11592 const gchar *property_name,
11597 g_return_if_fail (GTK_IS_WIDGET (widget));
11598 g_return_if_fail (property_name != NULL);
11599 g_return_if_fail (G_IS_VALUE (value));
11601 g_object_ref (widget);
11602 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11604 G_OBJECT_TYPE (widget),
11607 g_warning ("%s: widget class `%s' has no property named `%s'",
11609 G_OBJECT_TYPE_NAME (widget),
11613 GtkStyleContext *context;
11614 const GValue *peek_value;
11615 GtkStateFlags state;
11617 context = gtk_widget_get_style_context (widget);
11618 state = gtk_widget_get_state_flags (widget);
11620 peek_value = _gtk_style_context_peek_style_property (context,
11621 G_OBJECT_TYPE (widget),
11624 /* auto-conversion of the caller's value type
11626 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11627 g_value_copy (peek_value, value);
11628 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11629 g_value_transform (peek_value, value);
11631 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11633 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11634 G_VALUE_TYPE_NAME (value));
11636 g_object_unref (widget);
11640 * gtk_widget_style_get_valist:
11641 * @widget: a #GtkWidget
11642 * @first_property_name: the name of the first property to get
11643 * @var_args: a <type>va_list</type> of pairs of property names and
11644 * locations to return the property values, starting with the location
11645 * for @first_property_name.
11647 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11651 gtk_widget_style_get_valist (GtkWidget *widget,
11652 const gchar *first_property_name,
11655 GtkStyleContext *context;
11656 GtkStateFlags state;
11659 g_return_if_fail (GTK_IS_WIDGET (widget));
11661 g_object_ref (widget);
11662 context = gtk_widget_get_style_context (widget);
11663 state = gtk_widget_get_state_flags (widget);
11665 name = first_property_name;
11668 const GValue *peek_value;
11672 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11674 G_OBJECT_TYPE (widget),
11678 g_warning ("%s: widget class `%s' has no property named `%s'",
11680 G_OBJECT_TYPE_NAME (widget),
11684 /* style pspecs are always readable so we can spare that check here */
11686 peek_value = _gtk_style_context_peek_style_property (context,
11687 G_OBJECT_TYPE (widget),
11690 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11693 g_warning ("%s: %s", G_STRLOC, error);
11698 name = va_arg (var_args, gchar*);
11701 g_object_unref (widget);
11705 * gtk_widget_style_get:
11706 * @widget: a #GtkWidget
11707 * @first_property_name: the name of the first property to get
11708 * @Varargs: pairs of property names and locations to
11709 * return the property values, starting with the location for
11710 * @first_property_name, terminated by %NULL.
11712 * Gets the values of a multiple style properties of @widget.
11715 gtk_widget_style_get (GtkWidget *widget,
11716 const gchar *first_property_name,
11721 g_return_if_fail (GTK_IS_WIDGET (widget));
11723 va_start (var_args, first_property_name);
11724 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11730 * @widget: a #GtkWidget
11731 * @path_length: (out) (allow-none): location to store length of the path,
11733 * @path: (out) (allow-none): location to store allocated path string,
11735 * @path_reversed: (out) (allow-none): location to store allocated reverse
11736 * path string, or %NULL
11738 * Obtains the full path to @widget. The path is simply the name of a
11739 * widget and all its parents in the container hierarchy, separated by
11740 * periods. The name of a widget comes from
11741 * gtk_widget_get_name(). Paths are used to apply styles to a widget
11742 * in gtkrc configuration files. Widget names are the type of the
11743 * widget by default (e.g. "GtkButton") or can be set to an
11744 * application-specific value with gtk_widget_set_name(). By setting
11745 * the name of a widget, you allow users or theme authors to apply
11746 * styles to that specific widget in their gtkrc
11747 * file. @path_reversed_p fills in the path in reverse order,
11748 * i.e. starting with @widget's name instead of starting with the name
11749 * of @widget's outermost ancestor.
11751 * Deprecated:3.0: Use gtk_widget_get_path() instead
11754 gtk_widget_path (GtkWidget *widget,
11755 guint *path_length,
11757 gchar **path_reversed)
11759 static gchar *rev_path = NULL;
11760 static guint tmp_path_len = 0;
11763 g_return_if_fail (GTK_IS_WIDGET (widget));
11768 const gchar *string;
11773 string = gtk_widget_get_name (widget);
11774 l = strlen (string);
11775 while (tmp_path_len <= len + l + 1)
11777 tmp_path_len += INIT_PATH_SIZE;
11778 rev_path = g_realloc (rev_path, tmp_path_len);
11780 s = string + l - 1;
11781 d = rev_path + len;
11782 while (s >= string)
11786 widget = widget->priv->parent;
11789 rev_path[len++] = '.';
11791 rev_path[len++] = 0;
11796 *path_length = len - 1;
11798 *path_reversed = g_strdup (rev_path);
11801 *path = g_strdup (rev_path);
11802 g_strreverse (*path);
11807 * gtk_widget_class_path:
11808 * @widget: a #GtkWidget
11809 * @path_length: (out) (allow-none): location to store the length of the
11810 * class path, or %NULL
11811 * @path: (out) (allow-none): location to store the class path as an
11812 * allocated string, or %NULL
11813 * @path_reversed: (out) (allow-none): location to store the reverse
11814 * class path as an allocated string, or %NULL
11816 * Same as gtk_widget_path(), but always uses the name of a widget's type,
11817 * never uses a custom name set with gtk_widget_set_name().
11819 * Deprecated:3.0: Use gtk_widget_get_path() instead
11822 gtk_widget_class_path (GtkWidget *widget,
11823 guint *path_length,
11825 gchar **path_reversed)
11827 static gchar *rev_path = NULL;
11828 static guint tmp_path_len = 0;
11831 g_return_if_fail (GTK_IS_WIDGET (widget));
11836 const gchar *string;
11841 string = g_type_name (G_OBJECT_TYPE (widget));
11842 l = strlen (string);
11843 while (tmp_path_len <= len + l + 1)
11845 tmp_path_len += INIT_PATH_SIZE;
11846 rev_path = g_realloc (rev_path, tmp_path_len);
11848 s = string + l - 1;
11849 d = rev_path + len;
11850 while (s >= string)
11854 widget = widget->priv->parent;
11857 rev_path[len++] = '.';
11859 rev_path[len++] = 0;
11864 *path_length = len - 1;
11866 *path_reversed = g_strdup (rev_path);
11869 *path = g_strdup (rev_path);
11870 g_strreverse (*path);
11875 * gtk_requisition_new:
11877 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11879 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11880 * be freed with gtk_requisition_free().
11885 gtk_requisition_new (void)
11887 return g_slice_new0 (GtkRequisition);
11891 * gtk_requisition_copy:
11892 * @requisition: a #GtkRequisition
11894 * Copies a #GtkRequisition.
11896 * Returns: a copy of @requisition
11899 gtk_requisition_copy (const GtkRequisition *requisition)
11901 return g_slice_dup (GtkRequisition, requisition);
11905 * gtk_requisition_free:
11906 * @requisition: a #GtkRequisition
11908 * Frees a #GtkRequisition.
11911 gtk_requisition_free (GtkRequisition *requisition)
11913 g_slice_free (GtkRequisition, requisition);
11916 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11917 gtk_requisition_copy,
11918 gtk_requisition_free)
11921 * gtk_widget_class_set_accessible_type:
11922 * @widget_class: class to set the accessible type for
11923 * @type: The object type that implements the accessible for @widget_class
11925 * Sets the type to be used for creating accessibles for widgets of
11926 * @widget_class. The given @type must be a subtype of the type used for
11927 * accessibles of the parent class.
11929 * This function should only be called from class init functions of widgets.
11934 gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class,
11937 GtkWidgetClassPrivate *priv;
11939 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11940 g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type));
11942 priv = widget_class->priv;
11944 priv->accessible_type = type;
11945 /* reset this - honoring the type's role is better. */
11946 priv->accessible_role = ATK_ROLE_INVALID;
11950 * gtk_widget_class_set_accessible_role:
11951 * @widget_class: class to set the accessible role for
11952 * @role: The role to use for accessibles created for @widget_class
11954 * Sets the default #AtkRole to be set on accessibles created for
11955 * widgets of @widget_class. Accessibles may decide to not honor this
11956 * setting if their role reporting is more refined. Calls to
11957 * gtk_widget_class_set_accessible_type() will reset this value.
11959 * In cases where you want more fine-grained control over the role of
11960 * accessibles created for @widget_class, you should provide your own
11961 * accessible type and use gtk_widget_class_set_accessible_type()
11964 * If @role is #ATK_ROLE_INVALID, the default role will not be changed
11965 * and the accessible's default role will be used instead.
11967 * This function should only be called from class init functions of widgets.
11972 gtk_widget_class_set_accessible_role (GtkWidgetClass *widget_class,
11975 GtkWidgetClassPrivate *priv;
11977 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11979 priv = widget_class->priv;
11981 priv->accessible_role = role;
11985 * gtk_widget_get_accessible:
11986 * @widget: a #GtkWidget
11988 * Returns the accessible object that describes the widget to an
11989 * assistive technology.
11991 * If no accessibility library is loaded (i.e. no ATK implementation library is
11992 * loaded via <envar>GTK_MODULES</envar> or via another application library,
11993 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
11994 * if no class-specific #AtkObject implementation is available for the widget
11995 * instance in question, it will inherit an #AtkObject implementation from the
11996 * first ancestor class for which such an implementation is defined.
11998 * The documentation of the
11999 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
12000 * library contains more information about accessible objects and their uses.
12002 * Returns: (transfer none): the #AtkObject associated with @widget
12005 gtk_widget_get_accessible (GtkWidget *widget)
12007 GtkWidgetClass *klass;
12009 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12011 klass = GTK_WIDGET_GET_CLASS (widget);
12013 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
12015 return klass->get_accessible (widget);
12019 gtk_widget_real_get_accessible (GtkWidget *widget)
12021 AtkObject* accessible;
12023 accessible = g_object_get_qdata (G_OBJECT (widget),
12024 quark_accessible_object);
12027 GtkWidgetClass *widget_class;
12028 GtkWidgetClassPrivate *priv;
12029 AtkObjectFactory *factory;
12030 AtkRegistry *default_registry;
12032 widget_class = GTK_WIDGET_GET_CLASS (widget);
12033 priv = widget_class->priv;
12035 if (priv->accessible_type == GTK_TYPE_ACCESSIBLE)
12037 default_registry = atk_get_default_registry ();
12038 factory = atk_registry_get_factory (default_registry,
12039 G_TYPE_FROM_INSTANCE (widget));
12041 atk_object_factory_create_accessible (factory,
12042 G_OBJECT (widget));
12046 accessible = g_object_new (priv->accessible_type, NULL);
12047 atk_object_initialize (accessible, widget);
12050 if (priv->accessible_role != ATK_ROLE_INVALID)
12051 atk_object_set_role (accessible, priv->accessible_role);
12053 g_object_set_qdata (G_OBJECT (widget),
12054 quark_accessible_object,
12061 * Initialize a AtkImplementorIface instance's virtual pointers as
12062 * appropriate to this implementor's class (GtkWidget).
12065 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
12067 iface->ref_accessible = gtk_widget_ref_accessible;
12071 gtk_widget_ref_accessible (AtkImplementor *implementor)
12073 AtkObject *accessible;
12075 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
12077 g_object_ref (accessible);
12082 * Expand flag management
12086 gtk_widget_update_computed_expand (GtkWidget *widget)
12088 GtkWidgetPrivate *priv;
12090 priv = widget->priv;
12092 if (priv->need_compute_expand)
12096 if (priv->hexpand_set)
12101 if (priv->vexpand_set)
12106 /* we don't need to use compute_expand if both expands are
12107 * forced by the app
12109 if (!(priv->hexpand_set && priv->vexpand_set))
12111 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
12115 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
12116 priv->hexpand_set ? &ignored : &h,
12117 priv->vexpand_set ? &ignored : &v);
12121 priv->need_compute_expand = FALSE;
12122 priv->computed_hexpand = h != FALSE;
12123 priv->computed_vexpand = v != FALSE;
12128 * gtk_widget_queue_compute_expand:
12129 * @widget: a #GtkWidget
12131 * Mark @widget as needing to recompute its expand flags. Call
12132 * this function when setting legacy expand child properties
12133 * on the child of a container.
12135 * See gtk_widget_compute_expand().
12138 gtk_widget_queue_compute_expand (GtkWidget *widget)
12141 gboolean changed_anything;
12143 if (widget->priv->need_compute_expand)
12146 changed_anything = FALSE;
12148 while (parent != NULL)
12150 if (!parent->priv->need_compute_expand)
12152 parent->priv->need_compute_expand = TRUE;
12153 changed_anything = TRUE;
12156 /* Note: if we had an invariant that "if a child needs to
12157 * compute expand, its parents also do" then we could stop going
12158 * up when we got to a parent that already needed to
12159 * compute. However, in general we compute expand lazily (as
12160 * soon as we see something in a subtree that is expand, we know
12161 * we're expanding) and so this invariant does not hold and we
12162 * have to always walk all the way up in case some ancestor
12163 * is not currently need_compute_expand.
12166 parent = parent->priv->parent;
12169 /* recomputing expand always requires
12170 * a relayout as well
12172 if (changed_anything)
12173 gtk_widget_queue_resize (widget);
12177 * gtk_widget_compute_expand:
12178 * @widget: the widget
12179 * @orientation: expand direction
12181 * Computes whether a container should give this widget extra space
12182 * when possible. Containers should check this, rather than
12183 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
12185 * This function already checks whether the widget is visible, so
12186 * visibility does not need to be checked separately. Non-visible
12187 * widgets are not expanded.
12189 * The computed expand value uses either the expand setting explicitly
12190 * set on the widget itself, or, if none has been explicitly set,
12191 * the widget may expand if some of its children do.
12193 * Return value: whether widget tree rooted here should be expanded
12196 gtk_widget_compute_expand (GtkWidget *widget,
12197 GtkOrientation orientation)
12199 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12201 /* We never make a widget expand if not even showing. */
12202 if (!gtk_widget_get_visible (widget))
12205 gtk_widget_update_computed_expand (widget);
12207 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12209 return widget->priv->computed_hexpand;
12213 return widget->priv->computed_vexpand;
12218 gtk_widget_set_expand (GtkWidget *widget,
12219 GtkOrientation orientation,
12222 const char *expand_prop;
12223 const char *expand_set_prop;
12225 GtkWidgetPrivate *priv;
12227 g_return_if_fail (GTK_IS_WIDGET (widget));
12229 priv = widget->priv;
12231 expand = expand != FALSE;
12233 was_both = priv->hexpand && priv->vexpand;
12235 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12237 if (priv->hexpand_set &&
12238 priv->hexpand == expand)
12241 priv->hexpand_set = TRUE;
12242 priv->hexpand = expand;
12244 expand_prop = "hexpand";
12245 expand_set_prop = "hexpand-set";
12249 if (priv->vexpand_set &&
12250 priv->vexpand == expand)
12253 priv->vexpand_set = TRUE;
12254 priv->vexpand = expand;
12256 expand_prop = "vexpand";
12257 expand_set_prop = "vexpand-set";
12260 gtk_widget_queue_compute_expand (widget);
12262 g_object_freeze_notify (G_OBJECT (widget));
12263 g_object_notify (G_OBJECT (widget), expand_prop);
12264 g_object_notify (G_OBJECT (widget), expand_set_prop);
12265 if (was_both != (priv->hexpand && priv->vexpand))
12266 g_object_notify (G_OBJECT (widget), "expand");
12267 g_object_thaw_notify (G_OBJECT (widget));
12271 gtk_widget_set_expand_set (GtkWidget *widget,
12272 GtkOrientation orientation,
12275 GtkWidgetPrivate *priv;
12278 priv = widget->priv;
12280 set = set != FALSE;
12282 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12284 if (set == priv->hexpand_set)
12287 priv->hexpand_set = set;
12288 prop = "hexpand-set";
12292 if (set == priv->vexpand_set)
12295 priv->vexpand_set = set;
12296 prop = "vexpand-set";
12299 gtk_widget_queue_compute_expand (widget);
12301 g_object_notify (G_OBJECT (widget), prop);
12305 * gtk_widget_get_hexpand:
12306 * @widget: the widget
12308 * Gets whether the widget would like any available extra horizontal
12309 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12310 * generally receive the extra space. For example, a list or
12311 * scrollable area or document in your window would often be set to
12314 * Containers should use gtk_widget_compute_expand() rather than
12315 * this function, to see whether a widget, or any of its children,
12316 * has the expand flag set. If any child of a widget wants to
12317 * expand, the parent may ask to expand also.
12319 * This function only looks at the widget's own hexpand flag, rather
12320 * than computing whether the entire widget tree rooted at this widget
12323 * Return value: whether hexpand flag is set
12326 gtk_widget_get_hexpand (GtkWidget *widget)
12328 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12330 return widget->priv->hexpand;
12334 * gtk_widget_set_hexpand:
12335 * @widget: the widget
12336 * @expand: whether to expand
12338 * Sets whether the widget would like any available extra horizontal
12339 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12340 * generally receive the extra space. For example, a list or
12341 * scrollable area or document in your window would often be set to
12344 * Call this function to set the expand flag if you would like your
12345 * widget to become larger horizontally when the window has extra
12348 * By default, widgets automatically expand if any of their children
12349 * want to expand. (To see if a widget will automatically expand given
12350 * its current children and state, call gtk_widget_compute_expand(). A
12351 * container can decide how the expandability of children affects the
12352 * expansion of the container by overriding the compute_expand virtual
12353 * method on #GtkWidget.).
12355 * Setting hexpand explicitly with this function will override the
12356 * automatic expand behavior.
12358 * This function forces the widget to expand or not to expand,
12359 * regardless of children. The override occurs because
12360 * gtk_widget_set_hexpand() sets the hexpand-set property (see
12361 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
12362 * value to be used, rather than looking at children and widget state.
12365 gtk_widget_set_hexpand (GtkWidget *widget,
12368 g_return_if_fail (GTK_IS_WIDGET (widget));
12370 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
12374 * gtk_widget_get_hexpand_set:
12375 * @widget: the widget
12377 * Gets whether gtk_widget_set_hexpand() has been used to
12378 * explicitly set the expand flag on this widget.
12380 * If hexpand is set, then it overrides any computed
12381 * expand value based on child widgets. If hexpand is not
12382 * set, then the expand value depends on whether any
12383 * children of the widget would like to expand.
12385 * There are few reasons to use this function, but it's here
12386 * for completeness and consistency.
12388 * Return value: whether hexpand has been explicitly set
12391 gtk_widget_get_hexpand_set (GtkWidget *widget)
12393 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12395 return widget->priv->hexpand_set;
12399 * gtk_widget_set_hexpand_set:
12400 * @widget: the widget
12401 * @set: value for hexpand-set property
12403 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
12406 * The hexpand-set property will be set automatically when you call
12407 * gtk_widget_set_hexpand() to set hexpand, so the most likely
12408 * reason to use this function would be to unset an explicit expand
12411 * If hexpand is set, then it overrides any computed
12412 * expand value based on child widgets. If hexpand is not
12413 * set, then the expand value depends on whether any
12414 * children of the widget would like to expand.
12416 * There are few reasons to use this function, but it's here
12417 * for completeness and consistency.
12420 gtk_widget_set_hexpand_set (GtkWidget *widget,
12423 g_return_if_fail (GTK_IS_WIDGET (widget));
12425 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
12430 * gtk_widget_get_vexpand:
12431 * @widget: the widget
12433 * Gets whether the widget would like any available extra vertical
12436 * See gtk_widget_get_hexpand() for more detail.
12438 * Return value: whether vexpand flag is set
12441 gtk_widget_get_vexpand (GtkWidget *widget)
12443 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12445 return widget->priv->vexpand;
12449 * gtk_widget_set_vexpand:
12450 * @widget: the widget
12451 * @expand: whether to expand
12453 * Sets whether the widget would like any available extra vertical
12456 * See gtk_widget_set_hexpand() for more detail.
12459 gtk_widget_set_vexpand (GtkWidget *widget,
12462 g_return_if_fail (GTK_IS_WIDGET (widget));
12464 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12468 * gtk_widget_get_vexpand_set:
12469 * @widget: the widget
12471 * Gets whether gtk_widget_set_vexpand() has been used to
12472 * explicitly set the expand flag on this widget.
12474 * See gtk_widget_get_hexpand_set() for more detail.
12476 * Return value: whether vexpand has been explicitly set
12479 gtk_widget_get_vexpand_set (GtkWidget *widget)
12481 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12483 return widget->priv->vexpand_set;
12487 * gtk_widget_set_vexpand_set:
12488 * @widget: the widget
12489 * @set: value for vexpand-set property
12491 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12494 * See gtk_widget_set_hexpand_set() for more detail.
12497 gtk_widget_set_vexpand_set (GtkWidget *widget,
12500 g_return_if_fail (GTK_IS_WIDGET (widget));
12502 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12506 * GtkBuildable implementation
12508 static GQuark quark_builder_has_default = 0;
12509 static GQuark quark_builder_has_focus = 0;
12510 static GQuark quark_builder_atk_relations = 0;
12511 static GQuark quark_builder_set_name = 0;
12514 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12516 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12517 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12518 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12519 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12521 iface->set_name = gtk_widget_buildable_set_name;
12522 iface->get_name = gtk_widget_buildable_get_name;
12523 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12524 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12525 iface->parser_finished = gtk_widget_buildable_parser_finished;
12526 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12527 iface->custom_finished = gtk_widget_buildable_custom_finished;
12531 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12534 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12535 g_strdup (name), g_free);
12538 static const gchar *
12539 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12541 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12545 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12546 GtkBuilder *builder,
12547 const gchar *childname)
12549 if (strcmp (childname, "accessible") == 0)
12550 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12556 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12557 GtkBuilder *builder,
12559 const GValue *value)
12561 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12562 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12563 GINT_TO_POINTER (TRUE));
12564 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12565 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12566 GINT_TO_POINTER (TRUE));
12568 g_object_set_property (G_OBJECT (buildable), name, value);
12573 gchar *action_name;
12574 GString *description;
12576 gboolean translatable;
12586 free_action (AtkActionData *data, gpointer user_data)
12588 g_free (data->action_name);
12589 g_string_free (data->description, TRUE);
12590 g_free (data->context);
12591 g_slice_free (AtkActionData, data);
12595 free_relation (AtkRelationData *data, gpointer user_data)
12597 g_free (data->target);
12598 g_free (data->type);
12599 g_slice_free (AtkRelationData, data);
12603 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12604 GtkBuilder *builder)
12606 GSList *atk_relations;
12608 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12609 gtk_widget_grab_default (GTK_WIDGET (buildable));
12610 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12611 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12613 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12614 quark_builder_atk_relations);
12617 AtkObject *accessible;
12618 AtkRelationSet *relation_set;
12621 AtkRelationType relation_type;
12622 AtkObject *target_accessible;
12624 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12625 relation_set = atk_object_ref_relation_set (accessible);
12627 for (l = atk_relations; l; l = l->next)
12629 AtkRelationData *relation = (AtkRelationData*)l->data;
12631 target = gtk_builder_get_object (builder, relation->target);
12634 g_warning ("Target object %s in <relation> does not exist",
12638 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12639 g_assert (target_accessible != NULL);
12641 relation_type = atk_relation_type_for_name (relation->type);
12642 if (relation_type == ATK_RELATION_NULL)
12644 g_warning ("<relation> type %s not found",
12648 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12649 target_accessible);
12651 g_object_unref (relation_set);
12653 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
12654 g_slist_free (atk_relations);
12655 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12664 } AccessibilitySubParserData;
12667 accessibility_start_element (GMarkupParseContext *context,
12668 const gchar *element_name,
12669 const gchar **names,
12670 const gchar **values,
12671 gpointer user_data,
12674 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12676 gint line_number, char_number;
12678 if (strcmp (element_name, "relation") == 0)
12680 gchar *target = NULL;
12681 gchar *type = NULL;
12682 AtkRelationData *relation;
12684 for (i = 0; names[i]; i++)
12686 if (strcmp (names[i], "target") == 0)
12687 target = g_strdup (values[i]);
12688 else if (strcmp (names[i], "type") == 0)
12689 type = g_strdup (values[i]);
12692 g_markup_parse_context_get_position (context,
12695 g_set_error (error,
12697 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12698 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12700 line_number, char_number, names[i], "relation");
12707 if (!target || !type)
12709 g_markup_parse_context_get_position (context,
12712 g_set_error (error,
12714 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12715 "%s:%d:%d <%s> requires attribute \"%s\"",
12717 line_number, char_number, "relation",
12718 type ? "target" : "type");
12724 relation = g_slice_new (AtkRelationData);
12725 relation->target = target;
12726 relation->type = type;
12728 data->relations = g_slist_prepend (data->relations, relation);
12730 else if (strcmp (element_name, "action") == 0)
12732 const gchar *action_name = NULL;
12733 const gchar *description = NULL;
12734 const gchar *msg_context = NULL;
12735 gboolean translatable = FALSE;
12736 AtkActionData *action;
12738 for (i = 0; names[i]; i++)
12740 if (strcmp (names[i], "action_name") == 0)
12741 action_name = values[i];
12742 else if (strcmp (names[i], "description") == 0)
12743 description = values[i];
12744 else if (strcmp (names[i], "translatable") == 0)
12746 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12749 else if (strcmp (names[i], "comments") == 0)
12751 /* do nothing, comments are for translators */
12753 else if (strcmp (names[i], "context") == 0)
12754 msg_context = values[i];
12757 g_markup_parse_context_get_position (context,
12760 g_set_error (error,
12762 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12763 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12765 line_number, char_number, names[i], "action");
12772 g_markup_parse_context_get_position (context,
12775 g_set_error (error,
12777 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12778 "%s:%d:%d <%s> requires attribute \"%s\"",
12780 line_number, char_number, "action",
12785 action = g_slice_new (AtkActionData);
12786 action->action_name = g_strdup (action_name);
12787 action->description = g_string_new (description);
12788 action->context = g_strdup (msg_context);
12789 action->translatable = translatable;
12791 data->actions = g_slist_prepend (data->actions, action);
12793 else if (strcmp (element_name, "accessibility") == 0)
12796 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12800 accessibility_text (GMarkupParseContext *context,
12803 gpointer user_data,
12806 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12808 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12810 AtkActionData *action = data->actions->data;
12812 g_string_append_len (action->description, text, text_len);
12816 static const GMarkupParser accessibility_parser =
12818 accessibility_start_element,
12820 accessibility_text,
12829 } AccelGroupParserData;
12832 accel_group_start_element (GMarkupParseContext *context,
12833 const gchar *element_name,
12834 const gchar **names,
12835 const gchar **values,
12836 gpointer user_data,
12841 guint modifiers = 0;
12842 gchar *signal = NULL;
12843 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12845 for (i = 0; names[i]; i++)
12847 if (strcmp (names[i], "key") == 0)
12848 key = gdk_keyval_from_name (values[i]);
12849 else if (strcmp (names[i], "modifiers") == 0)
12851 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12857 else if (strcmp (names[i], "signal") == 0)
12858 signal = g_strdup (values[i]);
12861 if (key == 0 || signal == NULL)
12863 g_warning ("<accelerator> requires key and signal attributes");
12866 parser_data->key = key;
12867 parser_data->modifiers = modifiers;
12868 parser_data->signal = signal;
12871 static const GMarkupParser accel_group_parser =
12873 accel_group_start_element,
12882 style_start_element (GMarkupParseContext *context,
12883 const gchar *element_name,
12884 const gchar **names,
12885 const gchar **values,
12886 gpointer user_data,
12889 StyleParserData *style_data = (StyleParserData *)user_data;
12892 if (strcmp (element_name, "class") == 0)
12894 if (g_markup_collect_attributes (element_name,
12898 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12899 G_MARKUP_COLLECT_INVALID))
12901 style_data->classes = g_slist_append (style_data->classes, class_name);
12904 else if (strcmp (element_name, "style") == 0)
12907 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12910 static const GMarkupParser style_parser =
12912 style_start_element,
12916 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12917 GtkBuilder *builder,
12919 const gchar *tagname,
12920 GMarkupParser *parser,
12923 g_assert (buildable);
12925 if (strcmp (tagname, "accelerator") == 0)
12927 AccelGroupParserData *parser_data;
12929 parser_data = g_slice_new0 (AccelGroupParserData);
12930 parser_data->object = g_object_ref (buildable);
12931 *parser = accel_group_parser;
12932 *data = parser_data;
12935 if (strcmp (tagname, "accessibility") == 0)
12937 AccessibilitySubParserData *parser_data;
12939 parser_data = g_slice_new0 (AccessibilitySubParserData);
12940 *parser = accessibility_parser;
12941 *data = parser_data;
12944 if (strcmp (tagname, "style") == 0)
12946 StyleParserData *parser_data;
12948 parser_data = g_slice_new0 (StyleParserData);
12949 *parser = style_parser;
12950 *data = parser_data;
12958 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12959 GtkWidget *toplevel,
12960 gpointer user_data)
12962 AccelGroupParserData *accel_data;
12963 GSList *accel_groups;
12964 GtkAccelGroup *accel_group;
12966 g_return_if_fail (GTK_IS_WIDGET (widget));
12967 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12968 g_return_if_fail (user_data != NULL);
12970 accel_data = (AccelGroupParserData*)user_data;
12971 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12972 if (g_slist_length (accel_groups) == 0)
12974 accel_group = gtk_accel_group_new ();
12975 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12979 g_assert (g_slist_length (accel_groups) == 1);
12980 accel_group = g_slist_nth_data (accel_groups, 0);
12983 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12984 accel_data->signal,
12987 accel_data->modifiers,
12988 GTK_ACCEL_VISIBLE);
12990 g_object_unref (accel_data->object);
12991 g_free (accel_data->signal);
12992 g_slice_free (AccelGroupParserData, accel_data);
12996 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12997 GtkBuilder *builder,
12999 const gchar *tagname,
13000 gpointer user_data)
13002 if (strcmp (tagname, "accelerator") == 0)
13004 AccelGroupParserData *accel_data;
13005 GtkWidget *toplevel;
13007 accel_data = (AccelGroupParserData*)user_data;
13008 g_assert (accel_data->object);
13010 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
13012 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
13014 else if (strcmp (tagname, "accessibility") == 0)
13016 AccessibilitySubParserData *a11y_data;
13018 a11y_data = (AccessibilitySubParserData*)user_data;
13020 if (a11y_data->actions)
13022 AtkObject *accessible;
13027 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
13029 if (ATK_IS_ACTION (accessible))
13031 action = ATK_ACTION (accessible);
13032 n_actions = atk_action_get_n_actions (action);
13034 for (l = a11y_data->actions; l; l = l->next)
13036 AtkActionData *action_data = (AtkActionData*)l->data;
13038 for (i = 0; i < n_actions; i++)
13039 if (strcmp (atk_action_get_name (action, i),
13040 action_data->action_name) == 0)
13045 gchar *description;
13047 if (action_data->translatable && action_data->description->len)
13048 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
13049 action_data->context,
13050 action_data->description->str);
13052 description = action_data->description->str;
13054 atk_action_set_description (action, i, description);
13059 g_warning ("accessibility action on a widget that does not implement AtkAction");
13061 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
13062 g_slist_free (a11y_data->actions);
13065 if (a11y_data->relations)
13066 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
13067 a11y_data->relations);
13069 g_slice_free (AccessibilitySubParserData, a11y_data);
13071 else if (strcmp (tagname, "style") == 0)
13073 StyleParserData *style_data = (StyleParserData *)user_data;
13074 GtkStyleContext *context;
13077 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
13079 for (l = style_data->classes; l; l = l->next)
13080 gtk_style_context_add_class (context, (const gchar *)l->data);
13082 gtk_widget_reset_style (GTK_WIDGET (buildable));
13084 g_slist_free_full (style_data->classes, g_free);
13085 g_slice_free (StyleParserData, style_data);
13089 static GtkSizeRequestMode
13090 gtk_widget_real_get_request_mode (GtkWidget *widget)
13092 /* By default widgets dont trade size at all. */
13093 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
13097 gtk_widget_real_get_width (GtkWidget *widget,
13098 gint *minimum_size,
13099 gint *natural_size)
13109 gtk_widget_real_get_height (GtkWidget *widget,
13110 gint *minimum_size,
13111 gint *natural_size)
13121 gtk_widget_real_get_height_for_width (GtkWidget *widget,
13123 gint *minimum_height,
13124 gint *natural_height)
13126 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
13130 gtk_widget_real_get_width_for_height (GtkWidget *widget,
13132 gint *minimum_width,
13133 gint *natural_width)
13135 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
13139 * gtk_widget_get_halign:
13140 * @widget: a #GtkWidget
13142 * Gets the value of the #GtkWidget:halign property.
13144 * Returns: the horizontal alignment of @widget
13147 gtk_widget_get_halign (GtkWidget *widget)
13149 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
13150 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
13154 * gtk_widget_set_halign:
13155 * @widget: a #GtkWidget
13156 * @align: the horizontal alignment
13158 * Sets the horizontal alignment of @widget.
13159 * See the #GtkWidget:halign property.
13162 gtk_widget_set_halign (GtkWidget *widget,
13165 GtkWidgetAuxInfo *aux_info;
13167 g_return_if_fail (GTK_IS_WIDGET (widget));
13169 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13171 if (aux_info->halign == align)
13174 aux_info->halign = align;
13175 gtk_widget_queue_resize (widget);
13176 g_object_notify (G_OBJECT (widget), "halign");
13180 * gtk_widget_get_valign:
13181 * @widget: a #GtkWidget
13183 * Gets the value of the #GtkWidget:valign property.
13185 * Returns: the vertical alignment of @widget
13188 gtk_widget_get_valign (GtkWidget *widget)
13190 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
13191 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
13195 * gtk_widget_set_valign:
13196 * @widget: a #GtkWidget
13197 * @align: the vertical alignment
13199 * Sets the vertical alignment of @widget.
13200 * See the #GtkWidget:valign property.
13203 gtk_widget_set_valign (GtkWidget *widget,
13206 GtkWidgetAuxInfo *aux_info;
13208 g_return_if_fail (GTK_IS_WIDGET (widget));
13210 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13212 if (aux_info->valign == align)
13215 aux_info->valign = align;
13216 gtk_widget_queue_resize (widget);
13217 g_object_notify (G_OBJECT (widget), "valign");
13221 * gtk_widget_get_margin_left:
13222 * @widget: a #GtkWidget
13224 * Gets the value of the #GtkWidget:margin-left property.
13226 * Returns: The left margin of @widget
13231 gtk_widget_get_margin_left (GtkWidget *widget)
13233 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13235 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
13239 * gtk_widget_set_margin_left:
13240 * @widget: a #GtkWidget
13241 * @margin: the left margin
13243 * Sets the left margin of @widget.
13244 * See the #GtkWidget:margin-left property.
13249 gtk_widget_set_margin_left (GtkWidget *widget,
13252 GtkWidgetAuxInfo *aux_info;
13254 g_return_if_fail (GTK_IS_WIDGET (widget));
13255 g_return_if_fail (margin <= G_MAXINT16);
13257 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13259 if (aux_info->margin.left == margin)
13262 aux_info->margin.left = margin;
13263 gtk_widget_queue_resize (widget);
13264 g_object_notify (G_OBJECT (widget), "margin-left");
13268 * gtk_widget_get_margin_right:
13269 * @widget: a #GtkWidget
13271 * Gets the value of the #GtkWidget:margin-right property.
13273 * Returns: The right margin of @widget
13278 gtk_widget_get_margin_right (GtkWidget *widget)
13280 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13282 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
13286 * gtk_widget_set_margin_right:
13287 * @widget: a #GtkWidget
13288 * @margin: the right margin
13290 * Sets the right margin of @widget.
13291 * See the #GtkWidget:margin-right property.
13296 gtk_widget_set_margin_right (GtkWidget *widget,
13299 GtkWidgetAuxInfo *aux_info;
13301 g_return_if_fail (GTK_IS_WIDGET (widget));
13302 g_return_if_fail (margin <= G_MAXINT16);
13304 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13306 if (aux_info->margin.right == margin)
13309 aux_info->margin.right = margin;
13310 gtk_widget_queue_resize (widget);
13311 g_object_notify (G_OBJECT (widget), "margin-right");
13315 * gtk_widget_get_margin_top:
13316 * @widget: a #GtkWidget
13318 * Gets the value of the #GtkWidget:margin-top property.
13320 * Returns: The top margin of @widget
13325 gtk_widget_get_margin_top (GtkWidget *widget)
13327 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13329 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
13333 * gtk_widget_set_margin_top:
13334 * @widget: a #GtkWidget
13335 * @margin: the top margin
13337 * Sets the top margin of @widget.
13338 * See the #GtkWidget:margin-top property.
13343 gtk_widget_set_margin_top (GtkWidget *widget,
13346 GtkWidgetAuxInfo *aux_info;
13348 g_return_if_fail (GTK_IS_WIDGET (widget));
13349 g_return_if_fail (margin <= G_MAXINT16);
13351 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13353 if (aux_info->margin.top == margin)
13356 aux_info->margin.top = margin;
13357 gtk_widget_queue_resize (widget);
13358 g_object_notify (G_OBJECT (widget), "margin-top");
13362 * gtk_widget_get_margin_bottom:
13363 * @widget: a #GtkWidget
13365 * Gets the value of the #GtkWidget:margin-bottom property.
13367 * Returns: The bottom margin of @widget
13372 gtk_widget_get_margin_bottom (GtkWidget *widget)
13374 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13376 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
13380 * gtk_widget_set_margin_bottom:
13381 * @widget: a #GtkWidget
13382 * @margin: the bottom margin
13384 * Sets the bottom margin of @widget.
13385 * See the #GtkWidget:margin-bottom property.
13390 gtk_widget_set_margin_bottom (GtkWidget *widget,
13393 GtkWidgetAuxInfo *aux_info;
13395 g_return_if_fail (GTK_IS_WIDGET (widget));
13396 g_return_if_fail (margin <= G_MAXINT16);
13398 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13400 if (aux_info->margin.bottom == margin)
13403 aux_info->margin.bottom = margin;
13404 gtk_widget_queue_resize (widget);
13405 g_object_notify (G_OBJECT (widget), "margin-bottom");
13409 * gtk_widget_get_clipboard:
13410 * @widget: a #GtkWidget
13411 * @selection: a #GdkAtom which identifies the clipboard
13412 * to use. %GDK_SELECTION_CLIPBOARD gives the
13413 * default clipboard. Another common value
13414 * is %GDK_SELECTION_PRIMARY, which gives
13415 * the primary X selection.
13417 * Returns the clipboard object for the given selection to
13418 * be used with @widget. @widget must have a #GdkDisplay
13419 * associated with it, so must be attached to a toplevel
13422 * Return value: (transfer none): the appropriate clipboard object. If no
13423 * clipboard already exists, a new one will
13424 * be created. Once a clipboard object has
13425 * been created, it is persistent for all time.
13430 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
13432 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13433 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
13435 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
13440 * gtk_widget_list_mnemonic_labels:
13441 * @widget: a #GtkWidget
13443 * Returns a newly allocated list of the widgets, normally labels, for
13444 * which this widget is the target of a mnemonic (see for example,
13445 * gtk_label_set_mnemonic_widget()).
13447 * The widgets in the list are not individually referenced. If you
13448 * want to iterate through the list and perform actions involving
13449 * callbacks that might destroy the widgets, you
13450 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
13451 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
13452 * widgets afterwards.
13454 * Return value: (element-type GtkWidget) (transfer container): the list of
13455 * mnemonic labels; free this list
13456 * with g_list_free() when you are done with it.
13461 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
13463 GList *list = NULL;
13466 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13468 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13469 list = g_list_prepend (list, l->data);
13475 * gtk_widget_add_mnemonic_label:
13476 * @widget: a #GtkWidget
13477 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13479 * Adds a widget to the list of mnemonic labels for
13480 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13481 * list of mnemonic labels for the widget is cleared when the
13482 * widget is destroyed, so the caller must make sure to update
13483 * its internal state at this point as well, by using a connection
13484 * to the #GtkWidget::destroy signal or a weak notifier.
13489 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13492 GSList *old_list, *new_list;
13494 g_return_if_fail (GTK_IS_WIDGET (widget));
13495 g_return_if_fail (GTK_IS_WIDGET (label));
13497 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13498 new_list = g_slist_prepend (old_list, label);
13500 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13501 new_list, (GDestroyNotify) g_slist_free);
13505 * gtk_widget_remove_mnemonic_label:
13506 * @widget: a #GtkWidget
13507 * @label: a #GtkWidget that was previously set as a mnemnic label for
13508 * @widget with gtk_widget_add_mnemonic_label().
13510 * Removes a widget from the list of mnemonic labels for
13511 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13512 * must have previously been added to the list with
13513 * gtk_widget_add_mnemonic_label().
13518 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13521 GSList *old_list, *new_list;
13523 g_return_if_fail (GTK_IS_WIDGET (widget));
13524 g_return_if_fail (GTK_IS_WIDGET (label));
13526 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13527 new_list = g_slist_remove (old_list, label);
13530 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13531 new_list, (GDestroyNotify) g_slist_free);
13535 * gtk_widget_get_no_show_all:
13536 * @widget: a #GtkWidget
13538 * Returns the current value of the #GtkWidget:no-show-all property,
13539 * which determines whether calls to gtk_widget_show_all()
13540 * will affect this widget.
13542 * Return value: the current value of the "no-show-all" property.
13547 gtk_widget_get_no_show_all (GtkWidget *widget)
13549 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13551 return widget->priv->no_show_all;
13555 * gtk_widget_set_no_show_all:
13556 * @widget: a #GtkWidget
13557 * @no_show_all: the new value for the "no-show-all" property
13559 * Sets the #GtkWidget:no-show-all property, which determines whether
13560 * calls to gtk_widget_show_all() will affect this widget.
13562 * This is mostly for use in constructing widget hierarchies with externally
13563 * controlled visibility, see #GtkUIManager.
13568 gtk_widget_set_no_show_all (GtkWidget *widget,
13569 gboolean no_show_all)
13571 g_return_if_fail (GTK_IS_WIDGET (widget));
13573 no_show_all = (no_show_all != FALSE);
13575 if (widget->priv->no_show_all != no_show_all)
13577 widget->priv->no_show_all = no_show_all;
13579 g_object_notify (G_OBJECT (widget), "no-show-all");
13585 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13586 gboolean has_tooltip,
13589 GtkWidgetPrivate *priv = widget->priv;
13590 gboolean priv_has_tooltip;
13592 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13593 quark_has_tooltip));
13595 if (priv_has_tooltip != has_tooltip || force)
13597 priv_has_tooltip = has_tooltip;
13599 if (priv_has_tooltip)
13601 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13602 gdk_window_set_events (priv->window,
13603 gdk_window_get_events (priv->window) |
13604 GDK_LEAVE_NOTIFY_MASK |
13605 GDK_POINTER_MOTION_MASK |
13606 GDK_POINTER_MOTION_HINT_MASK);
13608 if (gtk_widget_get_has_window (widget))
13609 gtk_widget_add_events (widget,
13610 GDK_LEAVE_NOTIFY_MASK |
13611 GDK_POINTER_MOTION_MASK |
13612 GDK_POINTER_MOTION_HINT_MASK);
13615 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13616 GUINT_TO_POINTER (priv_has_tooltip));
13621 * gtk_widget_set_tooltip_window:
13622 * @widget: a #GtkWidget
13623 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13625 * Replaces the default, usually yellow, window used for displaying
13626 * tooltips with @custom_window. GTK+ will take care of showing and
13627 * hiding @custom_window at the right moment, to behave likewise as
13628 * the default tooltip window. If @custom_window is %NULL, the default
13629 * tooltip window will be used.
13631 * If the custom window should have the default theming it needs to
13632 * have the name "gtk-tooltip", see gtk_widget_set_name().
13637 gtk_widget_set_tooltip_window (GtkWidget *widget,
13638 GtkWindow *custom_window)
13640 gboolean has_tooltip;
13641 gchar *tooltip_markup;
13643 g_return_if_fail (GTK_IS_WIDGET (widget));
13644 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13646 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13649 g_object_ref (custom_window);
13651 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13652 custom_window, g_object_unref);
13654 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13655 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13657 if (has_tooltip && gtk_widget_get_visible (widget))
13658 gtk_widget_queue_tooltip_query (widget);
13662 * gtk_widget_get_tooltip_window:
13663 * @widget: a #GtkWidget
13665 * Returns the #GtkWindow of the current tooltip. This can be the
13666 * GtkWindow created by default, or the custom tooltip window set
13667 * using gtk_widget_set_tooltip_window().
13669 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13674 gtk_widget_get_tooltip_window (GtkWidget *widget)
13676 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13678 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13682 * gtk_widget_trigger_tooltip_query:
13683 * @widget: a #GtkWidget
13685 * Triggers a tooltip query on the display where the toplevel of @widget
13686 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13692 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13694 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13697 static guint tooltip_query_id;
13698 static GSList *tooltip_query_displays;
13701 tooltip_query_idle (gpointer data)
13703 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13704 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13705 g_slist_free (tooltip_query_displays);
13707 tooltip_query_displays = NULL;
13708 tooltip_query_id = 0;
13714 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13716 GdkDisplay *display;
13718 display = gtk_widget_get_display (widget);
13720 if (!g_slist_find (tooltip_query_displays, display))
13721 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13723 if (tooltip_query_id == 0)
13724 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13728 * gtk_widget_set_tooltip_text:
13729 * @widget: a #GtkWidget
13730 * @text: the contents of the tooltip for @widget
13732 * Sets @text as the contents of the tooltip. This function will take
13733 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13734 * handler for the #GtkWidget::query-tooltip signal.
13736 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13741 gtk_widget_set_tooltip_text (GtkWidget *widget,
13744 g_return_if_fail (GTK_IS_WIDGET (widget));
13746 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13750 * gtk_widget_get_tooltip_text:
13751 * @widget: a #GtkWidget
13753 * Gets the contents of the tooltip for @widget.
13755 * Return value: the tooltip text, or %NULL. You should free the
13756 * returned string with g_free() when done.
13761 gtk_widget_get_tooltip_text (GtkWidget *widget)
13763 gchar *text = NULL;
13765 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13767 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13773 * gtk_widget_set_tooltip_markup:
13774 * @widget: a #GtkWidget
13775 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13777 * Sets @markup as the contents of the tooltip, which is marked up with
13778 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13780 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13781 * and of the default handler for the #GtkWidget::query-tooltip signal.
13783 * See also the #GtkWidget:tooltip-markup property and
13784 * gtk_tooltip_set_markup().
13789 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13790 const gchar *markup)
13792 g_return_if_fail (GTK_IS_WIDGET (widget));
13794 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13798 * gtk_widget_get_tooltip_markup:
13799 * @widget: a #GtkWidget
13801 * Gets the contents of the tooltip for @widget.
13803 * Return value: the tooltip text, or %NULL. You should free the
13804 * returned string with g_free() when done.
13809 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13811 gchar *text = NULL;
13813 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13815 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13821 * gtk_widget_set_has_tooltip:
13822 * @widget: a #GtkWidget
13823 * @has_tooltip: whether or not @widget has a tooltip.
13825 * Sets the has-tooltip property on @widget to @has_tooltip. See
13826 * #GtkWidget:has-tooltip for more information.
13831 gtk_widget_set_has_tooltip (GtkWidget *widget,
13832 gboolean has_tooltip)
13834 g_return_if_fail (GTK_IS_WIDGET (widget));
13836 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13840 * gtk_widget_get_has_tooltip:
13841 * @widget: a #GtkWidget
13843 * Returns the current value of the has-tooltip property. See
13844 * #GtkWidget:has-tooltip for more information.
13846 * Return value: current value of has-tooltip on @widget.
13851 gtk_widget_get_has_tooltip (GtkWidget *widget)
13853 gboolean has_tooltip = FALSE;
13855 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13857 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13859 return has_tooltip;
13863 * gtk_widget_get_allocation:
13864 * @widget: a #GtkWidget
13865 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13867 * Retrieves the widget's allocation.
13869 * Note, when implementing a #GtkContainer: a widget's allocation will
13870 * be its "adjusted" allocation, that is, the widget's parent
13871 * container typically calls gtk_widget_size_allocate() with an
13872 * allocation, and that allocation is then adjusted (to handle margin
13873 * and alignment for example) before assignment to the widget.
13874 * gtk_widget_get_allocation() returns the adjusted allocation that
13875 * was actually assigned to the widget. The adjusted allocation is
13876 * guaranteed to be completely contained within the
13877 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13878 * is guaranteed that its children stay inside the assigned bounds,
13879 * but not that they have exactly the bounds the container assigned.
13880 * There is no way to get the original allocation assigned by
13881 * gtk_widget_size_allocate(), since it isn't stored; if a container
13882 * implementation needs that information it will have to track it itself.
13887 gtk_widget_get_allocation (GtkWidget *widget,
13888 GtkAllocation *allocation)
13890 GtkWidgetPrivate *priv;
13892 g_return_if_fail (GTK_IS_WIDGET (widget));
13893 g_return_if_fail (allocation != NULL);
13895 priv = widget->priv;
13897 *allocation = priv->allocation;
13901 * gtk_widget_set_allocation:
13902 * @widget: a #GtkWidget
13903 * @allocation: a pointer to a #GtkAllocation to copy from
13905 * Sets the widget's allocation. This should not be used
13906 * directly, but from within a widget's size_allocate method.
13908 * The allocation set should be the "adjusted" or actual
13909 * allocation. If you're implementing a #GtkContainer, you want to use
13910 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13911 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13912 * allocation inside gtk_widget_size_allocate() to create an adjusted
13918 gtk_widget_set_allocation (GtkWidget *widget,
13919 const GtkAllocation *allocation)
13921 GtkWidgetPrivate *priv;
13923 g_return_if_fail (GTK_IS_WIDGET (widget));
13924 g_return_if_fail (allocation != NULL);
13926 priv = widget->priv;
13928 priv->allocation = *allocation;
13932 * gtk_widget_get_allocated_width:
13933 * @widget: the widget to query
13935 * Returns the width that has currently been allocated to @widget.
13936 * This function is intended to be used when implementing handlers
13937 * for the #GtkWidget::draw function.
13939 * Returns: the width of the @widget
13942 gtk_widget_get_allocated_width (GtkWidget *widget)
13944 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13946 return widget->priv->allocation.width;
13950 * gtk_widget_get_allocated_height:
13951 * @widget: the widget to query
13953 * Returns the height that has currently been allocated to @widget.
13954 * This function is intended to be used when implementing handlers
13955 * for the #GtkWidget::draw function.
13957 * Returns: the height of the @widget
13960 gtk_widget_get_allocated_height (GtkWidget *widget)
13962 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13964 return widget->priv->allocation.height;
13968 * gtk_widget_get_requisition:
13969 * @widget: a #GtkWidget
13970 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13972 * Retrieves the widget's requisition.
13974 * This function should only be used by widget implementations in
13975 * order to figure whether the widget's requisition has actually
13976 * changed after some internal state change (so that they can call
13977 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13979 * Normally, gtk_widget_size_request() should be used.
13983 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13984 * removed, If you need to cache sizes across requests and allocations,
13985 * add an explicit cache to the widget in question instead.
13988 gtk_widget_get_requisition (GtkWidget *widget,
13989 GtkRequisition *requisition)
13991 g_return_if_fail (GTK_IS_WIDGET (widget));
13992 g_return_if_fail (requisition != NULL);
13994 gtk_widget_get_preferred_size (widget, requisition, NULL);
13998 * gtk_widget_set_window:
13999 * @widget: a #GtkWidget
14000 * @window: a #GdkWindow
14002 * Sets a widget's window. This function should only be used in a
14003 * widget's #GtkWidget::realize implementation. The %window passed is
14004 * usually either new window created with gdk_window_new(), or the
14005 * window of its parent widget as returned by
14006 * gtk_widget_get_parent_window().
14008 * Widgets must indicate whether they will create their own #GdkWindow
14009 * by calling gtk_widget_set_has_window(). This is usually done in the
14010 * widget's init() function.
14012 * <note><para>This function does not add any reference to @window.</para></note>
14017 gtk_widget_set_window (GtkWidget *widget,
14020 GtkWidgetPrivate *priv;
14022 g_return_if_fail (GTK_IS_WIDGET (widget));
14023 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
14025 priv = widget->priv;
14027 if (priv->window != window)
14029 priv->window = window;
14030 g_object_notify (G_OBJECT (widget), "window");
14035 * gtk_widget_get_window:
14036 * @widget: a #GtkWidget
14038 * Returns the widget's window if it is realized, %NULL otherwise
14040 * Return value: (transfer none): @widget's window.
14045 gtk_widget_get_window (GtkWidget *widget)
14047 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14049 return widget->priv->window;
14053 * gtk_widget_get_support_multidevice:
14054 * @widget: a #GtkWidget
14056 * Returns %TRUE if @widget is multiple pointer aware. See
14057 * gtk_widget_set_support_multidevice() for more information.
14059 * Returns: %TRUE if @widget is multidevice aware.
14062 gtk_widget_get_support_multidevice (GtkWidget *widget)
14064 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
14066 return widget->priv->multidevice;
14070 * gtk_widget_set_support_multidevice:
14071 * @widget: a #GtkWidget
14072 * @support_multidevice: %TRUE to support input from multiple devices.
14074 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
14075 * @widget will start receiving multiple, per device enter/leave events. Note
14076 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
14077 * gdk_window_set_support_multidevice() will have to be called manually on them.
14082 gtk_widget_set_support_multidevice (GtkWidget *widget,
14083 gboolean support_multidevice)
14085 GtkWidgetPrivate *priv;
14087 g_return_if_fail (GTK_IS_WIDGET (widget));
14089 priv = widget->priv;
14090 priv->multidevice = (support_multidevice == TRUE);
14092 if (gtk_widget_get_realized (widget))
14093 gdk_window_set_support_multidevice (priv->window, support_multidevice);
14097 _gtk_widget_set_has_focus (GtkWidget *widget,
14098 gboolean has_focus)
14100 widget->priv->has_focus = has_focus;
14103 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
14105 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
14109 * gtk_widget_send_focus_change:
14110 * @widget: a #GtkWidget
14111 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
14113 * Sends the focus change @event to @widget
14115 * This function is not meant to be used by applications. The only time it
14116 * should be used is when it is necessary for a #GtkWidget to assign focus
14117 * to a widget that is semantically owned by the first widget even though
14118 * it's not a direct child - for instance, a search entry in a floating
14119 * window similar to the quick search in #GtkTreeView.
14121 * An example of its usage is:
14124 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
14126 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
14127 * fevent->focus_change.in = TRUE;
14128 * fevent->focus_change.window = gtk_widget_get_window (widget);
14129 * if (fevent->focus_change.window != NULL)
14130 * g_object_ref (fevent->focus_change.window);
14132 * gtk_widget_send_focus_change (widget, fevent);
14134 * gdk_event_free (event);
14137 * Return value: the return value from the event signal emission: %TRUE
14138 * if the event was handled, and %FALSE otherwise
14143 gtk_widget_send_focus_change (GtkWidget *widget,
14148 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
14149 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
14151 g_object_ref (widget);
14153 _gtk_widget_set_has_focus (widget, event->focus_change.in);
14155 res = gtk_widget_event (widget, event);
14157 g_object_notify (G_OBJECT (widget), "has-focus");
14159 g_object_unref (widget);
14165 * gtk_widget_in_destruction:
14166 * @widget: a #GtkWidget
14168 * Returns whether the widget is currently being destroyed.
14169 * This information can sometimes be used to avoid doing
14170 * unnecessary work.
14172 * Returns: %TRUE if @widget is being destroyed
14175 gtk_widget_in_destruction (GtkWidget *widget)
14177 return widget->priv->in_destruction;
14181 _gtk_widget_get_resize_pending (GtkWidget *widget)
14183 return widget->priv->resize_pending;
14187 _gtk_widget_set_resize_pending (GtkWidget *widget,
14188 gboolean resize_pending)
14190 widget->priv->resize_pending = resize_pending;
14194 _gtk_widget_get_in_reparent (GtkWidget *widget)
14196 return widget->priv->in_reparent;
14200 _gtk_widget_set_in_reparent (GtkWidget *widget,
14201 gboolean in_reparent)
14203 widget->priv->in_reparent = in_reparent;
14207 _gtk_widget_get_anchored (GtkWidget *widget)
14209 return widget->priv->anchored;
14213 _gtk_widget_set_anchored (GtkWidget *widget,
14216 widget->priv->anchored = anchored;
14220 _gtk_widget_get_shadowed (GtkWidget *widget)
14222 return widget->priv->shadowed;
14226 _gtk_widget_set_shadowed (GtkWidget *widget,
14229 widget->priv->shadowed = shadowed;
14233 _gtk_widget_get_alloc_needed (GtkWidget *widget)
14235 return widget->priv->alloc_needed;
14239 _gtk_widget_set_alloc_needed (GtkWidget *widget,
14240 gboolean alloc_needed)
14242 widget->priv->alloc_needed = alloc_needed;
14246 _gtk_widget_get_width_request_needed (GtkWidget *widget)
14248 return widget->priv->width_request_needed;
14252 _gtk_widget_set_width_request_needed (GtkWidget *widget,
14253 gboolean width_request_needed)
14255 widget->priv->width_request_needed = width_request_needed;
14259 _gtk_widget_get_height_request_needed (GtkWidget *widget)
14261 return widget->priv->height_request_needed;
14265 _gtk_widget_set_height_request_needed (GtkWidget *widget,
14266 gboolean height_request_needed)
14268 widget->priv->height_request_needed = height_request_needed;
14272 _gtk_widget_get_sizegroup_visited (GtkWidget *widget)
14274 return widget->priv->sizegroup_visited;
14278 _gtk_widget_set_sizegroup_visited (GtkWidget *widget,
14281 widget->priv->sizegroup_visited = visited;
14285 _gtk_widget_get_sizegroup_bumping (GtkWidget *widget)
14287 return widget->priv->sizegroup_bumping;
14291 _gtk_widget_set_sizegroup_bumping (GtkWidget *widget,
14294 widget->priv->sizegroup_bumping = bumping;
14298 _gtk_widget_add_sizegroup (GtkWidget *widget,
14303 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14304 groups = g_slist_prepend (groups, group);
14305 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14307 widget->priv->have_size_groups = TRUE;
14311 _gtk_widget_remove_sizegroup (GtkWidget *widget,
14316 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14317 groups = g_slist_remove (groups, group);
14318 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14320 widget->priv->have_size_groups = groups != NULL;
14324 _gtk_widget_get_sizegroups (GtkWidget *widget)
14326 if (widget->priv->have_size_groups)
14327 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14333 * gtk_widget_path_append_for_widget:
14334 * @path: a widget path
14335 * @widget: the widget to append to the widget path
14337 * Appends the data from @widget to the widget hierarchy represented
14338 * by @path. This function is a shortcut for adding information from
14339 * @widget to the given @path. This includes setting the name or
14340 * adding the style classes from @widget.
14342 * Returns: the position where the data was inserted
14347 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
14352 g_return_val_if_fail (path != NULL, 0);
14353 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14355 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
14357 if (widget->priv->name)
14358 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
14360 if (widget->priv->context)
14362 GList *classes, *l;
14364 /* Also add any persistent classes in
14365 * the style context the widget path
14367 classes = gtk_style_context_list_classes (widget->priv->context);
14369 for (l = classes; l; l = l->next)
14370 gtk_widget_path_iter_add_class (path, pos, l->data);
14372 g_list_free (classes);
14379 * gtk_widget_get_path:
14380 * @widget: a #GtkWidget
14382 * Returns the #GtkWidgetPath representing @widget, if the widget
14383 * is not connected to a toplevel widget, a partial path will be
14386 * Returns: (transfer none): The #GtkWidgetPath representing @widget
14389 gtk_widget_get_path (GtkWidget *widget)
14391 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14393 /* As strange as it may seem, this may happen on object construction.
14394 * init() implementations of parent types may eventually call this function,
14395 * each with its corresponding GType, which could leave a child
14396 * implementation with a wrong widget type in the widget path
14398 if (widget->priv->path &&
14399 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (widget->priv->path))
14401 gtk_widget_path_free (widget->priv->path);
14402 widget->priv->path = NULL;
14405 if (!widget->priv->path)
14409 parent = widget->priv->parent;
14412 widget->priv->path = gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
14415 /* Widget is either toplevel or unparented, treat both
14416 * as toplevels style wise, since there are situations
14417 * where style properties might be retrieved on that
14420 widget->priv->path = gtk_widget_path_new ();
14422 gtk_widget_path_append_for_widget (widget->priv->path, widget);
14425 if (widget->priv->context)
14426 gtk_style_context_set_path (widget->priv->context,
14427 widget->priv->path);
14430 return widget->priv->path;
14434 style_context_changed (GtkStyleContext *context,
14435 gpointer user_data)
14437 GtkWidget *widget = user_data;
14439 if (gtk_widget_get_realized (widget))
14440 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
14443 /* Compress all style updates so it
14444 * is only emitted once pre-realize.
14446 widget->priv->style_update_pending = TRUE;
14449 if (widget->priv->anchored)
14450 gtk_widget_queue_resize (widget);
14454 * gtk_widget_get_style_context:
14455 * @widget: a #GtkWidget
14457 * Returns the style context associated to @widget.
14459 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
14460 * must not be freed.
14463 gtk_widget_get_style_context (GtkWidget *widget)
14465 GtkWidgetPrivate *priv;
14466 GtkWidgetPath *path;
14468 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14470 priv = widget->priv;
14472 /* updates style context if it exists already */
14473 path = gtk_widget_get_path (widget);
14475 if (G_UNLIKELY (priv->context == NULL))
14479 priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
14480 "direction", gtk_widget_get_direction (widget),
14483 g_signal_connect (widget->priv->context, "changed",
14484 G_CALLBACK (style_context_changed), widget);
14486 screen = gtk_widget_get_screen (widget);
14489 gtk_style_context_set_screen (priv->context, screen);
14491 gtk_style_context_set_path (priv->context, path);
14494 return widget->priv->context;