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;
440 BUTTON_RELEASE_EVENT,
454 PROPERTY_NOTIFY_EVENT,
455 SELECTION_CLEAR_EVENT,
456 SELECTION_REQUEST_EVENT,
457 SELECTION_NOTIFY_EVENT,
462 VISIBILITY_NOTIFY_EVENT,
476 ACCEL_CLOSURES_CHANGED,
500 PROP_RECEIVES_DEFAULT,
501 PROP_COMPOSITE_CHILD,
509 PROP_DOUBLE_BUFFERED,
524 typedef struct _GtkStateData GtkStateData;
527 STATE_CHANGE_REPLACE,
536 guint use_forall : 1;
539 /* --- prototypes --- */
540 static void gtk_widget_base_class_init (gpointer g_class);
541 static void gtk_widget_class_init (GtkWidgetClass *klass);
542 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
543 static void gtk_widget_init (GtkWidget *widget);
544 static void gtk_widget_set_property (GObject *object,
548 static void gtk_widget_get_property (GObject *object,
552 static void gtk_widget_dispose (GObject *object);
553 static void gtk_widget_real_destroy (GtkWidget *object);
554 static void gtk_widget_finalize (GObject *object);
555 static void gtk_widget_real_show (GtkWidget *widget);
556 static void gtk_widget_real_hide (GtkWidget *widget);
557 static void gtk_widget_real_map (GtkWidget *widget);
558 static void gtk_widget_real_unmap (GtkWidget *widget);
559 static void gtk_widget_real_realize (GtkWidget *widget);
560 static void gtk_widget_real_unrealize (GtkWidget *widget);
561 static void gtk_widget_real_size_allocate (GtkWidget *widget,
562 GtkAllocation *allocation);
563 static void gtk_widget_real_style_set (GtkWidget *widget,
564 GtkStyle *previous_style);
565 static void gtk_widget_real_direction_changed(GtkWidget *widget,
566 GtkTextDirection previous_direction);
568 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
569 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
572 gboolean keyboard_tip,
573 GtkTooltip *tooltip);
574 static void gtk_widget_real_style_updated (GtkWidget *widget);
575 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
576 GtkWidgetHelpType help_type);
578 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
580 GParamSpec **pspecs);
581 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
583 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
585 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
586 GdkEventFocus *event);
587 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
588 GdkEventFocus *event);
589 static gboolean gtk_widget_real_focus (GtkWidget *widget,
590 GtkDirectionType direction);
591 static void gtk_widget_real_move_focus (GtkWidget *widget,
592 GtkDirectionType direction);
593 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
594 GtkDirectionType direction);
595 #ifdef G_ENABLE_DEBUG
596 static void gtk_widget_verify_invariants (GtkWidget *widget);
597 static void gtk_widget_push_verify_invariants (GtkWidget *widget);
598 static void gtk_widget_pop_verify_invariants (GtkWidget *widget);
600 #define gtk_widget_verify_invariants(widget)
601 #define gtk_widget_push_verify_invariants(widget)
602 #define gtk_widget_pop_verify_invariants(widget)
604 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
605 static void gtk_widget_update_pango_context (GtkWidget *widget);
606 static void gtk_widget_propagate_state (GtkWidget *widget,
609 static gint gtk_widget_event_internal (GtkWidget *widget,
611 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
612 gboolean group_cycling);
613 static void gtk_widget_real_get_width (GtkWidget *widget,
616 static void gtk_widget_real_get_height (GtkWidget *widget,
619 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
621 gint *minimum_height,
622 gint *natural_height);
623 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
626 gint *natural_width);
627 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
628 static GtkWidgetAuxInfo* gtk_widget_get_aux_info (GtkWidget *widget,
630 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
631 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
632 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
633 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
634 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
635 cairo_region_t *region);
636 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
637 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
638 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
641 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
642 gboolean has_tooltip,
644 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
645 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
647 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
648 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
650 const gchar *childname);
651 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
654 const GValue *value);
655 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
658 const gchar *tagname,
659 GMarkupParser *parser,
661 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
664 const gchar *tagname,
666 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
667 GtkBuilder *builder);
669 static GtkSizeRequestMode gtk_widget_real_get_request_mode (GtkWidget *widget);
670 static void gtk_widget_real_get_width (GtkWidget *widget,
673 static void gtk_widget_real_get_height (GtkWidget *widget,
677 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
680 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
681 GtkOrientation orientation,
684 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
685 GtkOrientation orientation,
689 gint *allocated_size);
691 static void gtk_widget_set_usize_internal (GtkWidget *widget,
694 GtkQueueResizeFlags flags);
696 static void gtk_widget_add_events_internal (GtkWidget *widget,
699 static void gtk_widget_set_device_enabled_internal (GtkWidget *widget,
704 /* --- variables --- */
705 static gpointer gtk_widget_parent_class = NULL;
706 static guint widget_signals[LAST_SIGNAL] = { 0 };
707 static GtkStyle *gtk_default_style = NULL;
708 static guint composite_child_stack = 0;
709 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
710 static GParamSpecPool *style_property_spec_pool = NULL;
712 static GQuark quark_property_parser = 0;
713 static GQuark quark_aux_info = 0;
714 static GQuark quark_accel_path = 0;
715 static GQuark quark_accel_closures = 0;
716 static GQuark quark_event_mask = 0;
717 static GQuark quark_device_event_mask = 0;
718 static GQuark quark_parent_window = 0;
719 static GQuark quark_pointer_window = 0;
720 static GQuark quark_shape_info = 0;
721 static GQuark quark_input_shape_info = 0;
722 static GQuark quark_pango_context = 0;
723 static GQuark quark_rc_style = 0;
724 static GQuark quark_accessible_object = 0;
725 static GQuark quark_mnemonic_labels = 0;
726 static GQuark quark_tooltip_markup = 0;
727 static GQuark quark_has_tooltip = 0;
728 static GQuark quark_tooltip_window = 0;
729 static GQuark quark_visual = 0;
730 static GQuark quark_modifier_style = 0;
731 static GQuark quark_enabled_devices = 0;
732 static GQuark quark_size_groups = 0;
733 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
734 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
736 /* --- functions --- */
738 gtk_widget_get_type (void)
740 static GType widget_type = 0;
742 if (G_UNLIKELY (widget_type == 0))
744 const GTypeInfo widget_info =
746 sizeof (GtkWidgetClass),
747 gtk_widget_base_class_init,
748 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
749 (GClassInitFunc) gtk_widget_class_init,
750 NULL, /* class_finalize */
751 NULL, /* class_init */
754 (GInstanceInitFunc) gtk_widget_init,
755 NULL, /* value_table */
758 const GInterfaceInfo accessibility_info =
760 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
761 (GInterfaceFinalizeFunc) NULL,
762 NULL /* interface data */
765 const GInterfaceInfo buildable_info =
767 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
768 (GInterfaceFinalizeFunc) NULL,
769 NULL /* interface data */
772 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
773 &widget_info, G_TYPE_FLAG_ABSTRACT);
775 g_type_add_class_private (widget_type, sizeof (GtkWidgetClassPrivate));
777 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
778 &accessibility_info) ;
779 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
787 gtk_widget_base_class_init (gpointer g_class)
789 GtkWidgetClass *klass = g_class;
791 klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
795 child_property_notify_dispatcher (GObject *object,
799 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
802 /* We guard against the draw signal callbacks modifying the state of the
803 * cairo context by surounding it with save/restore.
804 * Maybe we should also cairo_new_path() just to be sure?
807 gtk_widget_draw_marshaller (GClosure *closure,
808 GValue *return_value,
809 guint n_param_values,
810 const GValue *param_values,
811 gpointer invocation_hint,
812 gpointer marshal_data)
814 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
818 _gtk_marshal_BOOLEAN__BOXED (closure,
829 gtk_widget_class_init (GtkWidgetClass *klass)
831 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
832 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
833 GtkBindingSet *binding_set;
835 gtk_widget_parent_class = g_type_class_peek_parent (klass);
837 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
838 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
839 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
840 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
841 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
842 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
843 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
844 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
845 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
846 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
847 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
848 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
849 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
850 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
851 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
852 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
853 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
854 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
855 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
856 quark_enabled_devices = g_quark_from_static_string ("gtk-widget-enabled-devices");
857 quark_size_groups = g_quark_from_static_string ("gtk-widget-size-groups");
859 style_property_spec_pool = g_param_spec_pool_new (FALSE);
860 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
861 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
862 cpn_context.dispatcher = child_property_notify_dispatcher;
863 _gtk_widget_child_property_notify_context = &cpn_context;
865 gobject_class->dispose = gtk_widget_dispose;
866 gobject_class->finalize = gtk_widget_finalize;
867 gobject_class->set_property = gtk_widget_set_property;
868 gobject_class->get_property = gtk_widget_get_property;
870 klass->destroy = gtk_widget_real_destroy;
872 klass->activate_signal = 0;
873 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
874 klass->show = gtk_widget_real_show;
875 klass->show_all = gtk_widget_show;
876 klass->hide = gtk_widget_real_hide;
877 klass->map = gtk_widget_real_map;
878 klass->unmap = gtk_widget_real_unmap;
879 klass->realize = gtk_widget_real_realize;
880 klass->unrealize = gtk_widget_real_unrealize;
881 klass->size_allocate = gtk_widget_real_size_allocate;
882 klass->get_request_mode = gtk_widget_real_get_request_mode;
883 klass->get_preferred_width = gtk_widget_real_get_width;
884 klass->get_preferred_height = gtk_widget_real_get_height;
885 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
886 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
887 klass->state_changed = NULL;
888 klass->parent_set = NULL;
889 klass->hierarchy_changed = NULL;
890 klass->style_set = gtk_widget_real_style_set;
891 klass->direction_changed = gtk_widget_real_direction_changed;
892 klass->grab_notify = NULL;
893 klass->child_notify = NULL;
895 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
896 klass->grab_focus = gtk_widget_real_grab_focus;
897 klass->focus = gtk_widget_real_focus;
898 klass->move_focus = gtk_widget_real_move_focus;
899 klass->keynav_failed = gtk_widget_real_keynav_failed;
901 klass->button_press_event = NULL;
902 klass->button_release_event = NULL;
903 klass->motion_notify_event = NULL;
904 klass->delete_event = NULL;
905 klass->destroy_event = NULL;
906 klass->key_press_event = gtk_widget_real_key_press_event;
907 klass->key_release_event = gtk_widget_real_key_release_event;
908 klass->enter_notify_event = NULL;
909 klass->leave_notify_event = NULL;
910 klass->configure_event = NULL;
911 klass->focus_in_event = gtk_widget_real_focus_in_event;
912 klass->focus_out_event = gtk_widget_real_focus_out_event;
913 klass->map_event = NULL;
914 klass->unmap_event = NULL;
915 klass->window_state_event = NULL;
916 klass->property_notify_event = _gtk_selection_property_notify;
917 klass->selection_clear_event = _gtk_selection_clear;
918 klass->selection_request_event = _gtk_selection_request;
919 klass->selection_notify_event = _gtk_selection_notify;
920 klass->selection_received = NULL;
921 klass->proximity_in_event = NULL;
922 klass->proximity_out_event = NULL;
923 klass->drag_begin = NULL;
924 klass->drag_end = NULL;
925 klass->drag_data_delete = NULL;
926 klass->drag_leave = NULL;
927 klass->drag_motion = NULL;
928 klass->drag_drop = NULL;
929 klass->drag_data_received = NULL;
930 klass->screen_changed = NULL;
931 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
932 klass->grab_broken_event = NULL;
933 klass->query_tooltip = gtk_widget_real_query_tooltip;
934 klass->style_updated = gtk_widget_real_style_updated;
936 klass->show_help = gtk_widget_real_show_help;
938 /* Accessibility support */
939 klass->priv->accessible_type = GTK_TYPE_ACCESSIBLE;
940 klass->get_accessible = gtk_widget_real_get_accessible;
942 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
943 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
945 g_object_class_install_property (gobject_class,
947 g_param_spec_string ("name",
949 P_("The name of the widget"),
951 GTK_PARAM_READWRITE));
952 g_object_class_install_property (gobject_class,
954 g_param_spec_object ("parent",
956 P_("The parent widget of this widget. Must be a Container widget"),
958 GTK_PARAM_READWRITE));
960 g_object_class_install_property (gobject_class,
962 g_param_spec_int ("width-request",
964 P_("Override for width request of the widget, or -1 if natural request should be used"),
968 GTK_PARAM_READWRITE));
969 g_object_class_install_property (gobject_class,
971 g_param_spec_int ("height-request",
972 P_("Height request"),
973 P_("Override for height request of the widget, or -1 if natural request should be used"),
977 GTK_PARAM_READWRITE));
978 g_object_class_install_property (gobject_class,
980 g_param_spec_boolean ("visible",
982 P_("Whether the widget is visible"),
984 GTK_PARAM_READWRITE));
985 g_object_class_install_property (gobject_class,
987 g_param_spec_boolean ("sensitive",
989 P_("Whether the widget responds to input"),
991 GTK_PARAM_READWRITE));
992 g_object_class_install_property (gobject_class,
994 g_param_spec_boolean ("app-paintable",
995 P_("Application paintable"),
996 P_("Whether the application will paint directly on the widget"),
998 GTK_PARAM_READWRITE));
999 g_object_class_install_property (gobject_class,
1001 g_param_spec_boolean ("can-focus",
1003 P_("Whether the widget can accept the input focus"),
1005 GTK_PARAM_READWRITE));
1006 g_object_class_install_property (gobject_class,
1008 g_param_spec_boolean ("has-focus",
1010 P_("Whether the widget has the input focus"),
1012 GTK_PARAM_READWRITE));
1013 g_object_class_install_property (gobject_class,
1015 g_param_spec_boolean ("is-focus",
1017 P_("Whether the widget is the focus widget within the toplevel"),
1019 GTK_PARAM_READWRITE));
1020 g_object_class_install_property (gobject_class,
1022 g_param_spec_boolean ("can-default",
1024 P_("Whether the widget can be the default widget"),
1026 GTK_PARAM_READWRITE));
1027 g_object_class_install_property (gobject_class,
1029 g_param_spec_boolean ("has-default",
1031 P_("Whether the widget is the default widget"),
1033 GTK_PARAM_READWRITE));
1034 g_object_class_install_property (gobject_class,
1035 PROP_RECEIVES_DEFAULT,
1036 g_param_spec_boolean ("receives-default",
1037 P_("Receives default"),
1038 P_("If TRUE, the widget will receive the default action when it is focused"),
1040 GTK_PARAM_READWRITE));
1041 g_object_class_install_property (gobject_class,
1042 PROP_COMPOSITE_CHILD,
1043 g_param_spec_boolean ("composite-child",
1044 P_("Composite child"),
1045 P_("Whether the widget is part of a composite widget"),
1047 GTK_PARAM_READABLE));
1048 g_object_class_install_property (gobject_class,
1050 g_param_spec_object ("style",
1052 P_("The style of the widget, which contains information about how it will look (colors etc)"),
1054 GTK_PARAM_READWRITE));
1055 g_object_class_install_property (gobject_class,
1057 g_param_spec_flags ("events",
1059 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1060 GDK_TYPE_EVENT_MASK,
1062 GTK_PARAM_READWRITE));
1063 g_object_class_install_property (gobject_class,
1065 g_param_spec_boolean ("no-show-all",
1067 P_("Whether gtk_widget_show_all() should not affect this widget"),
1069 GTK_PARAM_READWRITE));
1072 * GtkWidget:has-tooltip:
1074 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1075 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1076 * the widget will be queried using #GtkWidget::query-tooltip to determine
1077 * whether it will provide a tooltip or not.
1079 * Note that setting this property to %TRUE for the first time will change
1080 * the event masks of the GdkWindows of this widget to include leave-notify
1081 * and motion-notify events. This cannot and will not be undone when the
1082 * property is set to %FALSE again.
1086 g_object_class_install_property (gobject_class,
1088 g_param_spec_boolean ("has-tooltip",
1090 P_("Whether this widget has a tooltip"),
1092 GTK_PARAM_READWRITE));
1094 * GtkWidget:tooltip-text:
1096 * Sets the text of tooltip to be the given string.
1098 * Also see gtk_tooltip_set_text().
1100 * This is a convenience property which will take care of getting the
1101 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1102 * will automatically be set to %TRUE and there will be taken care of
1103 * #GtkWidget::query-tooltip in the default signal handler.
1107 g_object_class_install_property (gobject_class,
1109 g_param_spec_string ("tooltip-text",
1111 P_("The contents of the tooltip for this widget"),
1113 GTK_PARAM_READWRITE));
1115 * GtkWidget:tooltip-markup:
1117 * Sets the text of tooltip to be the given string, which is marked up
1118 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1119 * Also see gtk_tooltip_set_markup().
1121 * This is a convenience property which will take care of getting the
1122 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1123 * will automatically be set to %TRUE and there will be taken care of
1124 * #GtkWidget::query-tooltip in the default signal handler.
1128 g_object_class_install_property (gobject_class,
1129 PROP_TOOLTIP_MARKUP,
1130 g_param_spec_string ("tooltip-markup",
1131 P_("Tooltip markup"),
1132 P_("The contents of the tooltip for this widget"),
1134 GTK_PARAM_READWRITE));
1139 * The widget's window if it is realized, %NULL otherwise.
1143 g_object_class_install_property (gobject_class,
1145 g_param_spec_object ("window",
1147 P_("The widget's window if it is realized"),
1149 GTK_PARAM_READABLE));
1152 * GtkWidget:double-buffered
1154 * Whether the widget is double buffered.
1158 g_object_class_install_property (gobject_class,
1159 PROP_DOUBLE_BUFFERED,
1160 g_param_spec_boolean ("double-buffered",
1161 P_("Double Buffered"),
1162 P_("Whether the widget is double buffered"),
1164 GTK_PARAM_READWRITE));
1169 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1173 g_object_class_install_property (gobject_class,
1175 g_param_spec_enum ("halign",
1176 P_("Horizontal Alignment"),
1177 P_("How to position in extra horizontal space"),
1180 GTK_PARAM_READWRITE));
1185 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1189 g_object_class_install_property (gobject_class,
1191 g_param_spec_enum ("valign",
1192 P_("Vertical Alignment"),
1193 P_("How to position in extra vertical space"),
1196 GTK_PARAM_READWRITE));
1199 * GtkWidget:margin-left
1201 * Margin on left side of widget.
1203 * This property adds margin outside of the widget's normal size
1204 * request, the margin will be added in addition to the size from
1205 * gtk_widget_set_size_request() for example.
1209 g_object_class_install_property (gobject_class,
1211 g_param_spec_int ("margin-left",
1212 P_("Margin on Left"),
1213 P_("Pixels of extra space on the left side"),
1217 GTK_PARAM_READWRITE));
1220 * GtkWidget:margin-right
1222 * Margin on right side of widget.
1224 * This property adds margin outside of the widget's normal size
1225 * request, the margin will be added in addition to the size from
1226 * gtk_widget_set_size_request() for example.
1230 g_object_class_install_property (gobject_class,
1232 g_param_spec_int ("margin-right",
1233 P_("Margin on Right"),
1234 P_("Pixels of extra space on the right side"),
1238 GTK_PARAM_READWRITE));
1241 * GtkWidget:margin-top
1243 * Margin on top side of widget.
1245 * This property adds margin outside of the widget's normal size
1246 * request, the margin will be added in addition to the size from
1247 * gtk_widget_set_size_request() for example.
1251 g_object_class_install_property (gobject_class,
1253 g_param_spec_int ("margin-top",
1254 P_("Margin on Top"),
1255 P_("Pixels of extra space on the top side"),
1259 GTK_PARAM_READWRITE));
1262 * GtkWidget:margin-bottom
1264 * Margin on bottom side of widget.
1266 * This property adds margin outside of the widget's normal size
1267 * request, the margin will be added in addition to the size from
1268 * gtk_widget_set_size_request() for example.
1272 g_object_class_install_property (gobject_class,
1274 g_param_spec_int ("margin-bottom",
1275 P_("Margin on Bottom"),
1276 P_("Pixels of extra space on the bottom side"),
1280 GTK_PARAM_READWRITE));
1285 * Sets all four sides' margin at once. If read, returns max
1286 * margin on any side.
1290 g_object_class_install_property (gobject_class,
1292 g_param_spec_int ("margin",
1294 P_("Pixels of extra space on all four sides"),
1298 GTK_PARAM_READWRITE));
1301 * GtkWidget::destroy:
1302 * @object: the object which received the signal
1304 * Signals that all holders of a reference to the widget should release
1305 * the reference that they hold. May result in finalization of the widget
1306 * if all references are released.
1308 widget_signals[DESTROY] =
1309 g_signal_new (I_("destroy"),
1310 G_TYPE_FROM_CLASS (gobject_class),
1311 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1312 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1314 _gtk_marshal_VOID__VOID,
1320 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1324 g_object_class_install_property (gobject_class,
1326 g_param_spec_boolean ("hexpand",
1327 P_("Horizontal Expand"),
1328 P_("Whether widget wants more horizontal space"),
1330 GTK_PARAM_READWRITE));
1333 * GtkWidget:hexpand-set
1335 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1339 g_object_class_install_property (gobject_class,
1341 g_param_spec_boolean ("hexpand-set",
1342 P_("Horizontal Expand Set"),
1343 P_("Whether to use the hexpand property"),
1345 GTK_PARAM_READWRITE));
1350 * Whether to expand vertically. See gtk_widget_set_vexpand().
1354 g_object_class_install_property (gobject_class,
1356 g_param_spec_boolean ("vexpand",
1357 P_("Vertical Expand"),
1358 P_("Whether widget wants more vertical space"),
1360 GTK_PARAM_READWRITE));
1363 * GtkWidget:vexpand-set
1365 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1369 g_object_class_install_property (gobject_class,
1371 g_param_spec_boolean ("vexpand-set",
1372 P_("Vertical Expand Set"),
1373 P_("Whether to use the vexpand property"),
1375 GTK_PARAM_READWRITE));
1380 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1384 g_object_class_install_property (gobject_class,
1386 g_param_spec_boolean ("expand",
1388 P_("Whether widget wants to expand in both directions"),
1390 GTK_PARAM_READWRITE));
1394 * @widget: the object which received the signal.
1396 widget_signals[SHOW] =
1397 g_signal_new (I_("show"),
1398 G_TYPE_FROM_CLASS (gobject_class),
1400 G_STRUCT_OFFSET (GtkWidgetClass, show),
1402 _gtk_marshal_VOID__VOID,
1407 * @widget: the object which received the signal.
1409 widget_signals[HIDE] =
1410 g_signal_new (I_("hide"),
1411 G_TYPE_FROM_CLASS (gobject_class),
1413 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1415 _gtk_marshal_VOID__VOID,
1420 * @widget: the object which received the signal.
1422 widget_signals[MAP] =
1423 g_signal_new (I_("map"),
1424 G_TYPE_FROM_CLASS (gobject_class),
1426 G_STRUCT_OFFSET (GtkWidgetClass, map),
1428 _gtk_marshal_VOID__VOID,
1433 * @widget: the object which received the signal.
1435 widget_signals[UNMAP] =
1436 g_signal_new (I_("unmap"),
1437 G_TYPE_FROM_CLASS (gobject_class),
1439 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1441 _gtk_marshal_VOID__VOID,
1445 * GtkWidget::realize:
1446 * @widget: the object which received the signal.
1448 widget_signals[REALIZE] =
1449 g_signal_new (I_("realize"),
1450 G_TYPE_FROM_CLASS (gobject_class),
1452 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1454 _gtk_marshal_VOID__VOID,
1458 * GtkWidget::unrealize:
1459 * @widget: the object which received the signal.
1461 widget_signals[UNREALIZE] =
1462 g_signal_new (I_("unrealize"),
1463 G_TYPE_FROM_CLASS (gobject_class),
1465 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1467 _gtk_marshal_VOID__VOID,
1471 * GtkWidget::size-allocate:
1472 * @widget: the object which received the signal.
1475 widget_signals[SIZE_ALLOCATE] =
1476 g_signal_new (I_("size-allocate"),
1477 G_TYPE_FROM_CLASS (gobject_class),
1479 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1481 _gtk_marshal_VOID__BOXED,
1483 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1486 * GtkWidget::state-changed:
1487 * @widget: the object which received the signal.
1488 * @state: the previous state
1490 * The ::state-changed signal is emitted when the widget state changes.
1491 * See gtk_widget_get_state().
1493 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1495 widget_signals[STATE_CHANGED] =
1496 g_signal_new (I_("state-changed"),
1497 G_TYPE_FROM_CLASS (gobject_class),
1499 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1501 _gtk_marshal_VOID__ENUM,
1503 GTK_TYPE_STATE_TYPE);
1506 * GtkWidget::state-flags-changed:
1507 * @widget: the object which received the signal.
1508 * @flags: The previous state flags.
1510 * The ::state-flags-changed signal is emitted when the widget state
1511 * changes, see gtk_widget_get_state_flags().
1515 widget_signals[STATE_FLAGS_CHANGED] =
1516 g_signal_new (I_("state-flags-changed"),
1517 G_TYPE_FROM_CLASS (gobject_class),
1519 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1521 _gtk_marshal_VOID__FLAGS,
1523 GTK_TYPE_STATE_FLAGS);
1526 * GtkWidget::parent-set:
1527 * @widget: the object on which the signal is emitted
1528 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1529 * just got its initial parent.
1531 * The ::parent-set signal is emitted when a new parent
1532 * has been set on a widget.
1534 widget_signals[PARENT_SET] =
1535 g_signal_new (I_("parent-set"),
1536 G_TYPE_FROM_CLASS (gobject_class),
1538 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1540 _gtk_marshal_VOID__OBJECT,
1545 * GtkWidget::hierarchy-changed:
1546 * @widget: the object on which the signal is emitted
1547 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1548 * if the widget was previously unanchored
1550 * The ::hierarchy-changed signal is emitted when the
1551 * anchored state of a widget changes. A widget is
1552 * <firstterm>anchored</firstterm> when its toplevel
1553 * ancestor is a #GtkWindow. This signal is emitted when
1554 * a widget changes from un-anchored to anchored or vice-versa.
1556 widget_signals[HIERARCHY_CHANGED] =
1557 g_signal_new (I_("hierarchy-changed"),
1558 G_TYPE_FROM_CLASS (gobject_class),
1560 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1562 _gtk_marshal_VOID__OBJECT,
1567 * GtkWidget::style-set:
1568 * @widget: the object on which the signal is emitted
1569 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1570 * just got its initial style
1572 * The ::style-set signal is emitted when a new style has been set
1573 * on a widget. Note that style-modifying functions like
1574 * gtk_widget_modify_base() also cause this signal to be emitted.
1576 * Note that this signal is emitted for changes to the deprecated
1577 * #GtkStyle. To track changes to the #GtkStyleContext associated
1578 * with a widget, use the #GtkWidget::style-updated signal.
1580 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1582 widget_signals[STYLE_SET] =
1583 g_signal_new (I_("style-set"),
1584 G_TYPE_FROM_CLASS (gobject_class),
1586 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1588 _gtk_marshal_VOID__OBJECT,
1593 * GtkWidget::style-updated:
1594 * @widget: the object on which the signal is emitted
1596 * The ::style-updated signal is emitted when the #GtkStyleContext
1597 * of a widget is changed. Note that style-modifying functions like
1598 * gtk_widget_override_color() also cause this signal to be emitted.
1602 widget_signals[STYLE_UPDATED] =
1603 g_signal_new (I_("style-updated"),
1604 G_TYPE_FROM_CLASS (gobject_class),
1606 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1608 g_cclosure_marshal_VOID__VOID,
1612 * GtkWidget::direction-changed:
1613 * @widget: the object on which the signal is emitted
1614 * @previous_direction: the previous text direction of @widget
1616 * The ::direction-changed signal is emitted when the text direction
1617 * of a widget changes.
1619 widget_signals[DIRECTION_CHANGED] =
1620 g_signal_new (I_("direction-changed"),
1621 G_TYPE_FROM_CLASS (gobject_class),
1623 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1625 _gtk_marshal_VOID__ENUM,
1627 GTK_TYPE_TEXT_DIRECTION);
1630 * GtkWidget::grab-notify:
1631 * @widget: the object which received the signal
1632 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1633 * if it becomes unshadowed
1635 * The ::grab-notify signal is emitted when a widget becomes
1636 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1637 * another widget, or when it becomes unshadowed due to a grab
1640 * A widget is shadowed by a gtk_grab_add() when the topmost
1641 * grab widget in the grab stack of its window group is not
1644 widget_signals[GRAB_NOTIFY] =
1645 g_signal_new (I_("grab-notify"),
1646 G_TYPE_FROM_CLASS (gobject_class),
1648 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1650 _gtk_marshal_VOID__BOOLEAN,
1655 * GtkWidget::child-notify:
1656 * @widget: the object which received the signal
1657 * @pspec: the #GParamSpec of the changed child property
1659 * The ::child-notify signal is emitted for each
1660 * <link linkend="child-properties">child property</link> that has
1661 * changed on an object. The signal's detail holds the property name.
1663 widget_signals[CHILD_NOTIFY] =
1664 g_signal_new (I_("child-notify"),
1665 G_TYPE_FROM_CLASS (gobject_class),
1666 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1667 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1669 g_cclosure_marshal_VOID__PARAM,
1675 * @widget: the object which received the signal
1676 * @cr: the cairo context to draw to
1678 * This signal is emitted when a widget is supposed to render itself.
1679 * The @widget's top left corner must be painted at the origin of
1680 * the passed in context and be sized to the values returned by
1681 * gtk_widget_get_allocated_width() and
1682 * gtk_widget_get_allocated_height().
1684 * Signal handlers connected to this signal can modify the cairo
1685 * context passed as @cr in any way they like and don't need to
1686 * restore it. The signal emission takes care of calling cairo_save()
1687 * before and cairo_restore() after invoking the handler.
1691 widget_signals[DRAW] =
1692 g_signal_new (I_("draw"),
1693 G_TYPE_FROM_CLASS (gobject_class),
1695 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1696 _gtk_boolean_handled_accumulator, NULL,
1697 gtk_widget_draw_marshaller,
1699 CAIRO_GOBJECT_TYPE_CONTEXT);
1702 * GtkWidget::mnemonic-activate:
1703 * @widget: the object which received the signal.
1706 widget_signals[MNEMONIC_ACTIVATE] =
1707 g_signal_new (I_("mnemonic-activate"),
1708 G_TYPE_FROM_CLASS (gobject_class),
1710 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1711 _gtk_boolean_handled_accumulator, NULL,
1712 _gtk_marshal_BOOLEAN__BOOLEAN,
1717 * GtkWidget::grab-focus:
1718 * @widget: the object which received the signal.
1720 widget_signals[GRAB_FOCUS] =
1721 g_signal_new (I_("grab-focus"),
1722 G_TYPE_FROM_CLASS (gobject_class),
1723 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1724 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1726 _gtk_marshal_VOID__VOID,
1731 * @widget: the object which received the signal.
1734 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1736 widget_signals[FOCUS] =
1737 g_signal_new (I_("focus"),
1738 G_TYPE_FROM_CLASS (klass),
1740 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1741 _gtk_boolean_handled_accumulator, NULL,
1742 _gtk_marshal_BOOLEAN__ENUM,
1744 GTK_TYPE_DIRECTION_TYPE);
1747 * GtkWidget::move-focus:
1748 * @widget: the object which received the signal.
1751 widget_signals[MOVE_FOCUS] =
1752 g_signal_new (I_("move-focus"),
1753 G_TYPE_FROM_CLASS (klass),
1754 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1755 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1757 _gtk_marshal_VOID__ENUM,
1760 GTK_TYPE_DIRECTION_TYPE);
1763 * GtkWidget::keynav-failed:
1764 * @widget: the object which received the signal
1765 * @direction: the direction of movement
1767 * Gets emitted if keyboard navigation fails.
1768 * See gtk_widget_keynav_failed() for details.
1770 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1771 * if the emitting widget should try to handle the keyboard
1772 * navigation attempt in its parent container(s).
1776 widget_signals[KEYNAV_FAILED] =
1777 g_signal_new (I_("keynav-failed"),
1778 G_TYPE_FROM_CLASS (klass),
1780 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1781 _gtk_boolean_handled_accumulator, NULL,
1782 _gtk_marshal_BOOLEAN__ENUM,
1784 GTK_TYPE_DIRECTION_TYPE);
1788 * @widget: the object which received the signal.
1789 * @event: the #GdkEvent which triggered this signal
1791 * The GTK+ main loop will emit three signals for each GDK event delivered
1792 * to a widget: one generic ::event signal, another, more specific,
1793 * signal that matches the type of event delivered (e.g.
1794 * #GtkWidget::key-press-event) and finally a generic
1795 * #GtkWidget::event-after signal.
1797 * Returns: %TRUE to stop other handlers from being invoked for the event
1798 * and to cancel the emission of the second specific ::event signal.
1799 * %FALSE to propagate the event further and to allow the emission of
1800 * the second signal. The ::event-after signal is emitted regardless of
1803 widget_signals[EVENT] =
1804 g_signal_new (I_("event"),
1805 G_TYPE_FROM_CLASS (klass),
1807 G_STRUCT_OFFSET (GtkWidgetClass, event),
1808 _gtk_boolean_handled_accumulator, NULL,
1809 _gtk_marshal_BOOLEAN__BOXED,
1811 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1814 * GtkWidget::event-after:
1815 * @widget: the object which received the signal.
1816 * @event: the #GdkEvent which triggered this signal
1818 * After the emission of the #GtkWidget::event signal and (optionally)
1819 * the second more specific signal, ::event-after will be emitted
1820 * regardless of the previous two signals handlers return values.
1823 widget_signals[EVENT_AFTER] =
1824 g_signal_new (I_("event-after"),
1825 G_TYPE_FROM_CLASS (klass),
1829 _gtk_marshal_VOID__BOXED,
1831 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1834 * GtkWidget::button-press-event:
1835 * @widget: the object which received the signal.
1836 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1839 * The ::button-press-event signal will be emitted when a button
1840 * (typically from a mouse) is pressed.
1842 * To receive this signal, the #GdkWindow associated to the
1843 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1845 * This signal will be sent to the grab widget if there is one.
1847 * Returns: %TRUE to stop other handlers from being invoked for the event.
1848 * %FALSE to propagate the event further.
1850 widget_signals[BUTTON_PRESS_EVENT] =
1851 g_signal_new (I_("button-press-event"),
1852 G_TYPE_FROM_CLASS (klass),
1854 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1855 _gtk_boolean_handled_accumulator, NULL,
1856 _gtk_marshal_BOOLEAN__BOXED,
1858 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1861 * GtkWidget::button-release-event:
1862 * @widget: the object which received the signal.
1863 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1866 * The ::button-release-event signal will be emitted when a button
1867 * (typically from a mouse) is released.
1869 * To receive this signal, the #GdkWindow associated to the
1870 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1872 * This signal will be sent to the grab widget if there is one.
1874 * Returns: %TRUE to stop other handlers from being invoked for the event.
1875 * %FALSE to propagate the event further.
1877 widget_signals[BUTTON_RELEASE_EVENT] =
1878 g_signal_new (I_("button-release-event"),
1879 G_TYPE_FROM_CLASS (klass),
1881 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1882 _gtk_boolean_handled_accumulator, NULL,
1883 _gtk_marshal_BOOLEAN__BOXED,
1885 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1888 * GtkWidget::scroll-event:
1889 * @widget: the object which received the signal.
1890 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1893 * The ::scroll-event signal is emitted when a button in the 4 to 7
1894 * range is pressed. Wheel mice are usually configured to generate
1895 * button press events for buttons 4 and 5 when the wheel is turned.
1897 * To receive this signal, the #GdkWindow associated to the widget needs
1898 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1900 * This signal will be sent to the grab widget if there is one.
1902 * Returns: %TRUE to stop other handlers from being invoked for the event.
1903 * %FALSE to propagate the event further.
1905 widget_signals[SCROLL_EVENT] =
1906 g_signal_new (I_("scroll-event"),
1907 G_TYPE_FROM_CLASS (klass),
1909 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1910 _gtk_boolean_handled_accumulator, NULL,
1911 _gtk_marshal_BOOLEAN__BOXED,
1913 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1916 * GtkWidget::motion-notify-event:
1917 * @widget: the object which received the signal.
1918 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1921 * The ::motion-notify-event signal is emitted when the pointer moves
1922 * over the widget's #GdkWindow.
1924 * To receive this signal, the #GdkWindow associated to the widget
1925 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1927 * This signal will be sent to the grab widget if there is one.
1929 * Returns: %TRUE to stop other handlers from being invoked for the event.
1930 * %FALSE to propagate the event further.
1932 widget_signals[MOTION_NOTIFY_EVENT] =
1933 g_signal_new (I_("motion-notify-event"),
1934 G_TYPE_FROM_CLASS (klass),
1936 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1937 _gtk_boolean_handled_accumulator, NULL,
1938 _gtk_marshal_BOOLEAN__BOXED,
1940 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1943 * GtkWidget::composited-changed:
1944 * @widget: the object on which the signal is emitted
1946 * The ::composited-changed signal is emitted when the composited
1947 * status of @widget<!-- -->s screen changes.
1948 * See gdk_screen_is_composited().
1950 widget_signals[COMPOSITED_CHANGED] =
1951 g_signal_new (I_("composited-changed"),
1952 G_TYPE_FROM_CLASS (klass),
1953 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1954 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1956 _gtk_marshal_VOID__VOID,
1960 * GtkWidget::delete-event:
1961 * @widget: the object which received the signal
1962 * @event: the event which triggered this signal
1964 * The ::delete-event signal is emitted if a user requests that
1965 * a toplevel window is closed. The default handler for this signal
1966 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1967 * this signal will cause the window to be hidden instead, so that
1968 * it can later be shown again without reconstructing it.
1970 * Returns: %TRUE to stop other handlers from being invoked for the event.
1971 * %FALSE to propagate the event further.
1973 widget_signals[DELETE_EVENT] =
1974 g_signal_new (I_("delete-event"),
1975 G_TYPE_FROM_CLASS (klass),
1977 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1978 _gtk_boolean_handled_accumulator, NULL,
1979 _gtk_marshal_BOOLEAN__BOXED,
1981 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1984 * GtkWidget::destroy-event:
1985 * @widget: the object which received the signal.
1986 * @event: the event which triggered this signal
1988 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1989 * You rarely get this signal, because most widgets disconnect themselves
1990 * from their window before they destroy it, so no widget owns the
1991 * window at destroy time.
1993 * To receive this signal, the #GdkWindow associated to the widget needs
1994 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1995 * automatically for all new windows.
1997 * Returns: %TRUE to stop other handlers from being invoked for the event.
1998 * %FALSE to propagate the event further.
2000 widget_signals[DESTROY_EVENT] =
2001 g_signal_new (I_("destroy-event"),
2002 G_TYPE_FROM_CLASS (klass),
2004 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
2005 _gtk_boolean_handled_accumulator, NULL,
2006 _gtk_marshal_BOOLEAN__BOXED,
2008 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2011 * GtkWidget::key-press-event:
2012 * @widget: the object which received the signal
2013 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2015 * The ::key-press-event signal is emitted when a key is pressed. The signal
2016 * emission will reoccur at the key-repeat rate when the key is kept pressed.
2018 * To receive this signal, the #GdkWindow associated to the widget needs
2019 * to enable the #GDK_KEY_PRESS_MASK mask.
2021 * This signal will be sent to the grab widget if there is one.
2023 * Returns: %TRUE to stop other handlers from being invoked for the event.
2024 * %FALSE to propagate the event further.
2026 widget_signals[KEY_PRESS_EVENT] =
2027 g_signal_new (I_("key-press-event"),
2028 G_TYPE_FROM_CLASS (klass),
2030 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
2031 _gtk_boolean_handled_accumulator, NULL,
2032 _gtk_marshal_BOOLEAN__BOXED,
2034 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2037 * GtkWidget::key-release-event:
2038 * @widget: the object which received the signal
2039 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2041 * The ::key-release-event signal is emitted when a key is released.
2043 * To receive this signal, the #GdkWindow associated to the widget needs
2044 * to enable the #GDK_KEY_RELEASE_MASK mask.
2046 * This signal will be sent to the grab widget if there is one.
2048 * Returns: %TRUE to stop other handlers from being invoked for the event.
2049 * %FALSE to propagate the event further.
2051 widget_signals[KEY_RELEASE_EVENT] =
2052 g_signal_new (I_("key-release-event"),
2053 G_TYPE_FROM_CLASS (klass),
2055 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2056 _gtk_boolean_handled_accumulator, NULL,
2057 _gtk_marshal_BOOLEAN__BOXED,
2059 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2062 * GtkWidget::enter-notify-event:
2063 * @widget: the object which received the signal
2064 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2067 * The ::enter-notify-event will be emitted when the pointer enters
2068 * the @widget's window.
2070 * To receive this signal, the #GdkWindow associated to the widget needs
2071 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2073 * This signal will be sent to the grab widget if there is one.
2075 * Returns: %TRUE to stop other handlers from being invoked for the event.
2076 * %FALSE to propagate the event further.
2078 widget_signals[ENTER_NOTIFY_EVENT] =
2079 g_signal_new (I_("enter-notify-event"),
2080 G_TYPE_FROM_CLASS (klass),
2082 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2083 _gtk_boolean_handled_accumulator, NULL,
2084 _gtk_marshal_BOOLEAN__BOXED,
2086 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2089 * GtkWidget::leave-notify-event:
2090 * @widget: the object which received the signal
2091 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2094 * The ::leave-notify-event will be emitted when the pointer leaves
2095 * the @widget's window.
2097 * To receive this signal, the #GdkWindow associated to the widget needs
2098 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2100 * This signal will be sent to the grab widget if there is one.
2102 * Returns: %TRUE to stop other handlers from being invoked for the event.
2103 * %FALSE to propagate the event further.
2105 widget_signals[LEAVE_NOTIFY_EVENT] =
2106 g_signal_new (I_("leave-notify-event"),
2107 G_TYPE_FROM_CLASS (klass),
2109 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2110 _gtk_boolean_handled_accumulator, NULL,
2111 _gtk_marshal_BOOLEAN__BOXED,
2113 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2116 * GtkWidget::configure-event:
2117 * @widget: the object which received the signal
2118 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2121 * The ::configure-event signal will be emitted when the size, position or
2122 * stacking of the @widget's window has changed.
2124 * To receive this signal, the #GdkWindow associated to the widget needs
2125 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2126 * automatically for all new windows.
2128 * Returns: %TRUE to stop other handlers from being invoked for the event.
2129 * %FALSE to propagate the event further.
2131 widget_signals[CONFIGURE_EVENT] =
2132 g_signal_new (I_("configure-event"),
2133 G_TYPE_FROM_CLASS (klass),
2135 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2136 _gtk_boolean_handled_accumulator, NULL,
2137 _gtk_marshal_BOOLEAN__BOXED,
2139 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2142 * GtkWidget::focus-in-event:
2143 * @widget: the object which received the signal
2144 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2147 * The ::focus-in-event signal will be emitted when the keyboard focus
2148 * enters the @widget's window.
2150 * To receive this signal, the #GdkWindow associated to the widget needs
2151 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2153 * Returns: %TRUE to stop other handlers from being invoked for the event.
2154 * %FALSE to propagate the event further.
2156 widget_signals[FOCUS_IN_EVENT] =
2157 g_signal_new (I_("focus-in-event"),
2158 G_TYPE_FROM_CLASS (klass),
2160 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2161 _gtk_boolean_handled_accumulator, NULL,
2162 _gtk_marshal_BOOLEAN__BOXED,
2164 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2167 * GtkWidget::focus-out-event:
2168 * @widget: the object which received the signal
2169 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2172 * The ::focus-out-event signal will be emitted when the keyboard focus
2173 * leaves the @widget's window.
2175 * To receive this signal, the #GdkWindow associated to the widget needs
2176 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2178 * Returns: %TRUE to stop other handlers from being invoked for the event.
2179 * %FALSE to propagate the event further.
2181 widget_signals[FOCUS_OUT_EVENT] =
2182 g_signal_new (I_("focus-out-event"),
2183 G_TYPE_FROM_CLASS (klass),
2185 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2186 _gtk_boolean_handled_accumulator, NULL,
2187 _gtk_marshal_BOOLEAN__BOXED,
2189 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2192 * GtkWidget::map-event:
2193 * @widget: the object which received the signal
2194 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2196 * The ::map-event signal will be emitted when the @widget's window is
2197 * mapped. A window is mapped when it becomes visible on the screen.
2199 * To receive this signal, the #GdkWindow associated to the widget needs
2200 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2201 * automatically for all new windows.
2203 * Returns: %TRUE to stop other handlers from being invoked for the event.
2204 * %FALSE to propagate the event further.
2206 widget_signals[MAP_EVENT] =
2207 g_signal_new (I_("map-event"),
2208 G_TYPE_FROM_CLASS (klass),
2210 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2211 _gtk_boolean_handled_accumulator, NULL,
2212 _gtk_marshal_BOOLEAN__BOXED,
2214 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2217 * GtkWidget::unmap-event:
2218 * @widget: the object which received the signal
2219 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2221 * The ::unmap-event signal will be emitted when the @widget's window is
2222 * unmapped. A window is unmapped when it becomes invisible on the screen.
2224 * To receive this signal, the #GdkWindow associated to the widget needs
2225 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2226 * automatically for all new windows.
2228 * Returns: %TRUE to stop other handlers from being invoked for the event.
2229 * %FALSE to propagate the event further.
2231 widget_signals[UNMAP_EVENT] =
2232 g_signal_new (I_("unmap-event"),
2233 G_TYPE_FROM_CLASS (klass),
2235 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2236 _gtk_boolean_handled_accumulator, NULL,
2237 _gtk_marshal_BOOLEAN__BOXED,
2239 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2242 * GtkWidget::property-notify-event:
2243 * @widget: the object which received the signal
2244 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2247 * The ::property-notify-event signal will be emitted when a property on
2248 * the @widget's window has been changed or deleted.
2250 * To receive this signal, the #GdkWindow associated to the widget needs
2251 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2253 * Returns: %TRUE to stop other handlers from being invoked for the event.
2254 * %FALSE to propagate the event further.
2256 widget_signals[PROPERTY_NOTIFY_EVENT] =
2257 g_signal_new (I_("property-notify-event"),
2258 G_TYPE_FROM_CLASS (klass),
2260 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2261 _gtk_boolean_handled_accumulator, NULL,
2262 _gtk_marshal_BOOLEAN__BOXED,
2264 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2267 * GtkWidget::selection-clear-event:
2268 * @widget: the object which received the signal
2269 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2272 * The ::selection-clear-event signal will be emitted when the
2273 * the @widget's window has lost ownership of a selection.
2275 * Returns: %TRUE to stop other handlers from being invoked for the event.
2276 * %FALSE to propagate the event further.
2278 widget_signals[SELECTION_CLEAR_EVENT] =
2279 g_signal_new (I_("selection-clear-event"),
2280 G_TYPE_FROM_CLASS (klass),
2282 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2283 _gtk_boolean_handled_accumulator, NULL,
2284 _gtk_marshal_BOOLEAN__BOXED,
2286 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2289 * GtkWidget::selection-request-event:
2290 * @widget: the object which received the signal
2291 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2294 * The ::selection-request-event signal will be emitted when
2295 * another client requests ownership of the selection owned by
2296 * the @widget's window.
2298 * Returns: %TRUE to stop other handlers from being invoked for the event.
2299 * %FALSE to propagate the event further.
2301 widget_signals[SELECTION_REQUEST_EVENT] =
2302 g_signal_new (I_("selection-request-event"),
2303 G_TYPE_FROM_CLASS (klass),
2305 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2306 _gtk_boolean_handled_accumulator, NULL,
2307 _gtk_marshal_BOOLEAN__BOXED,
2309 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2312 * GtkWidget::selection-notify-event:
2313 * @widget: the object which received the signal.
2314 * @event: (type Gdk.EventSelection):
2316 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2318 widget_signals[SELECTION_NOTIFY_EVENT] =
2319 g_signal_new (I_("selection-notify-event"),
2320 G_TYPE_FROM_CLASS (klass),
2322 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2323 _gtk_boolean_handled_accumulator, NULL,
2324 _gtk_marshal_BOOLEAN__BOXED,
2326 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2329 * GtkWidget::selection-received:
2330 * @widget: the object which received the signal.
2334 widget_signals[SELECTION_RECEIVED] =
2335 g_signal_new (I_("selection-received"),
2336 G_TYPE_FROM_CLASS (klass),
2338 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2340 _gtk_marshal_VOID__BOXED_UINT,
2342 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2346 * GtkWidget::selection-get:
2347 * @widget: the object which received the signal.
2352 widget_signals[SELECTION_GET] =
2353 g_signal_new (I_("selection-get"),
2354 G_TYPE_FROM_CLASS (klass),
2356 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2358 _gtk_marshal_VOID__BOXED_UINT_UINT,
2360 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2365 * GtkWidget::proximity-in-event:
2366 * @widget: the object which received the signal
2367 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2370 * To receive this signal the #GdkWindow associated to the widget needs
2371 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2373 * This signal will be sent to the grab widget if there is one.
2375 * Returns: %TRUE to stop other handlers from being invoked for the event.
2376 * %FALSE to propagate the event further.
2378 widget_signals[PROXIMITY_IN_EVENT] =
2379 g_signal_new (I_("proximity-in-event"),
2380 G_TYPE_FROM_CLASS (klass),
2382 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2383 _gtk_boolean_handled_accumulator, NULL,
2384 _gtk_marshal_BOOLEAN__BOXED,
2386 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2389 * GtkWidget::proximity-out-event:
2390 * @widget: the object which received the signal
2391 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2394 * To receive this signal the #GdkWindow associated to the widget needs
2395 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2397 * This signal will be sent to the grab widget if there is one.
2399 * Returns: %TRUE to stop other handlers from being invoked for the event.
2400 * %FALSE to propagate the event further.
2402 widget_signals[PROXIMITY_OUT_EVENT] =
2403 g_signal_new (I_("proximity-out-event"),
2404 G_TYPE_FROM_CLASS (klass),
2406 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2407 _gtk_boolean_handled_accumulator, NULL,
2408 _gtk_marshal_BOOLEAN__BOXED,
2410 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2413 * GtkWidget::drag-leave:
2414 * @widget: the object which received the signal.
2415 * @drag_context: the drag context
2416 * @time: the timestamp of the motion event
2418 * The ::drag-leave signal is emitted on the drop site when the cursor
2419 * leaves the widget. A typical reason to connect to this signal is to
2420 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2421 * with gtk_drag_unhighlight()
2423 widget_signals[DRAG_LEAVE] =
2424 g_signal_new (I_("drag-leave"),
2425 G_TYPE_FROM_CLASS (klass),
2427 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2429 _gtk_marshal_VOID__OBJECT_UINT,
2431 GDK_TYPE_DRAG_CONTEXT,
2435 * GtkWidget::drag-begin:
2436 * @widget: the object which received the signal
2437 * @drag_context: the drag context
2439 * The ::drag-begin signal is emitted on the drag source when a drag is
2440 * started. A typical reason to connect to this signal is to set up a
2441 * custom drag icon with gtk_drag_source_set_icon().
2443 * Note that some widgets set up a drag icon in the default handler of
2444 * this signal, so you may have to use g_signal_connect_after() to
2445 * override what the default handler did.
2447 widget_signals[DRAG_BEGIN] =
2448 g_signal_new (I_("drag-begin"),
2449 G_TYPE_FROM_CLASS (klass),
2451 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2453 _gtk_marshal_VOID__OBJECT,
2455 GDK_TYPE_DRAG_CONTEXT);
2458 * GtkWidget::drag-end:
2459 * @widget: the object which received the signal
2460 * @drag_context: the drag context
2462 * The ::drag-end signal is emitted on the drag source when a drag is
2463 * finished. A typical reason to connect to this signal is to undo
2464 * things done in #GtkWidget::drag-begin.
2466 widget_signals[DRAG_END] =
2467 g_signal_new (I_("drag-end"),
2468 G_TYPE_FROM_CLASS (klass),
2470 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2472 _gtk_marshal_VOID__OBJECT,
2474 GDK_TYPE_DRAG_CONTEXT);
2477 * GtkWidget::drag-data-delete:
2478 * @widget: the object which received the signal
2479 * @drag_context: the drag context
2481 * The ::drag-data-delete signal is emitted on the drag source when a drag
2482 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2483 * handler is responsible for deleting the data that has been dropped. What
2484 * "delete" means depends on the context of the drag operation.
2486 widget_signals[DRAG_DATA_DELETE] =
2487 g_signal_new (I_("drag-data-delete"),
2488 G_TYPE_FROM_CLASS (klass),
2490 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2492 _gtk_marshal_VOID__OBJECT,
2494 GDK_TYPE_DRAG_CONTEXT);
2497 * GtkWidget::drag-failed:
2498 * @widget: the object which received the signal
2499 * @drag_context: the drag context
2500 * @result: the result of the drag operation
2502 * The ::drag-failed signal is emitted on the drag source when a drag has
2503 * failed. The signal handler may hook custom code to handle a failed DND
2504 * operation based on the type of error, it returns %TRUE is the failure has
2505 * been already handled (not showing the default "drag operation failed"
2506 * animation), otherwise it returns %FALSE.
2508 * Return value: %TRUE if the failed drag operation has been already handled.
2512 widget_signals[DRAG_FAILED] =
2513 g_signal_new (I_("drag-failed"),
2514 G_TYPE_FROM_CLASS (klass),
2516 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2517 _gtk_boolean_handled_accumulator, NULL,
2518 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2520 GDK_TYPE_DRAG_CONTEXT,
2521 GTK_TYPE_DRAG_RESULT);
2524 * GtkWidget::drag-motion:
2525 * @widget: the object which received the signal
2526 * @drag_context: the drag context
2527 * @x: the x coordinate of the current cursor position
2528 * @y: the y coordinate of the current cursor position
2529 * @time: the timestamp of the motion event
2530 * @returns: whether the cursor position is in a drop zone
2532 * The drag-motion signal is emitted on the drop site when the user
2533 * moves the cursor over the widget during a drag. The signal handler
2534 * must determine whether the cursor position is in a drop zone or not.
2535 * If it is not in a drop zone, it returns %FALSE and no further processing
2536 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2537 * handler is responsible for providing the necessary information for
2538 * displaying feedback to the user, by calling gdk_drag_status().
2540 * If the decision whether the drop will be accepted or rejected can't be
2541 * made based solely on the cursor position and the type of the data, the
2542 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2543 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2544 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2545 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2546 * when using the drag-motion signal that way.
2548 * Also note that there is no drag-enter signal. The drag receiver has to
2549 * keep track of whether he has received any drag-motion signals since the
2550 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2551 * an "enter" signal. Upon an "enter", the handler will typically highlight
2552 * the drop site with gtk_drag_highlight().
2555 * drag_motion (GtkWidget *widget,
2556 * GdkDragContext *context,
2563 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2565 * if (!private_data->drag_highlight)
2567 * private_data->drag_highlight = 1;
2568 * gtk_drag_highlight (widget);
2571 * target = gtk_drag_dest_find_target (widget, context, NULL);
2572 * if (target == GDK_NONE)
2573 * gdk_drag_status (context, 0, time);
2576 * private_data->pending_status = context->suggested_action;
2577 * gtk_drag_get_data (widget, context, target, time);
2584 * drag_data_received (GtkWidget *widget,
2585 * GdkDragContext *context,
2588 * GtkSelectionData *selection_data,
2592 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2594 * if (private_data->suggested_action)
2596 * private_data->suggested_action = 0;
2598 * /* We are getting this data due to a request in drag_motion,
2599 * * rather than due to a request in drag_drop, so we are just
2600 * * supposed to call gdk_drag_status (), not actually paste in
2603 * str = gtk_selection_data_get_text (selection_data);
2604 * if (!data_is_acceptable (str))
2605 * gdk_drag_status (context, 0, time);
2607 * gdk_drag_status (context, private_data->suggested_action, time);
2611 * /* accept the drop */
2616 widget_signals[DRAG_MOTION] =
2617 g_signal_new (I_("drag-motion"),
2618 G_TYPE_FROM_CLASS (klass),
2620 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2621 _gtk_boolean_handled_accumulator, NULL,
2622 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2624 GDK_TYPE_DRAG_CONTEXT,
2630 * GtkWidget::drag-drop:
2631 * @widget: the object which received the signal
2632 * @drag_context: the drag context
2633 * @x: the x coordinate of the current cursor position
2634 * @y: the y coordinate of the current cursor position
2635 * @time: the timestamp of the motion event
2636 * @returns: whether the cursor position is in a drop zone
2638 * The ::drag-drop signal is emitted on the drop site when the user drops
2639 * the data onto the widget. The signal handler must determine whether
2640 * the cursor position is in a drop zone or not. If it is not in a drop
2641 * zone, it returns %FALSE and no further processing is necessary.
2642 * Otherwise, the handler returns %TRUE. In this case, the handler must
2643 * ensure that gtk_drag_finish() is called to let the source know that
2644 * the drop is done. The call to gtk_drag_finish() can be done either
2645 * directly or in a #GtkWidget::drag-data-received handler which gets
2646 * triggered by calling gtk_drag_get_data() to receive the data for one
2647 * or more of the supported targets.
2649 widget_signals[DRAG_DROP] =
2650 g_signal_new (I_("drag-drop"),
2651 G_TYPE_FROM_CLASS (klass),
2653 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2654 _gtk_boolean_handled_accumulator, NULL,
2655 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2657 GDK_TYPE_DRAG_CONTEXT,
2663 * GtkWidget::drag-data-get:
2664 * @widget: the object which received the signal
2665 * @drag_context: the drag context
2666 * @data: the #GtkSelectionData to be filled with the dragged data
2667 * @info: the info that has been registered with the target in the
2669 * @time: the timestamp at which the data was requested
2671 * The ::drag-data-get signal is emitted on the drag source when the drop
2672 * site requests the data which is dragged. It is the responsibility of
2673 * the signal handler to fill @data with the data in the format which
2674 * is indicated by @info. See gtk_selection_data_set() and
2675 * gtk_selection_data_set_text().
2677 widget_signals[DRAG_DATA_GET] =
2678 g_signal_new (I_("drag-data-get"),
2679 G_TYPE_FROM_CLASS (klass),
2681 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2683 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2685 GDK_TYPE_DRAG_CONTEXT,
2686 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2691 * GtkWidget::drag-data-received:
2692 * @widget: the object which received the signal
2693 * @drag_context: the drag context
2694 * @x: where the drop happened
2695 * @y: where the drop happened
2696 * @data: the received data
2697 * @info: the info that has been registered with the target in the
2699 * @time: the timestamp at which the data was received
2701 * The ::drag-data-received signal is emitted on the drop site when the
2702 * dragged data has been received. If the data was received in order to
2703 * determine whether the drop will be accepted, the handler is expected
2704 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2705 * If the data was received in response to a #GtkWidget::drag-drop signal
2706 * (and this is the last target to be received), the handler for this
2707 * signal is expected to process the received data and then call
2708 * gtk_drag_finish(), setting the @success parameter depending on whether
2709 * the data was processed successfully.
2711 * The handler may inspect and modify @drag_context->action before calling
2712 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2713 * following example:
2716 * drag_data_received (GtkWidget *widget,
2717 * GdkDragContext *drag_context,
2720 * GtkSelectionData *data,
2724 * if ((data->length >= 0) && (data->format == 8))
2726 * if (drag_context->action == GDK_ACTION_ASK)
2728 * GtkWidget *dialog;
2731 * dialog = gtk_message_dialog_new (NULL,
2732 * GTK_DIALOG_MODAL |
2733 * GTK_DIALOG_DESTROY_WITH_PARENT,
2735 * GTK_BUTTONS_YES_NO,
2736 * "Move the data ?\n");
2737 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2738 * gtk_widget_destroy (dialog);
2740 * if (response == GTK_RESPONSE_YES)
2741 * drag_context->action = GDK_ACTION_MOVE;
2743 * drag_context->action = GDK_ACTION_COPY;
2746 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2750 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2754 widget_signals[DRAG_DATA_RECEIVED] =
2755 g_signal_new (I_("drag-data-received"),
2756 G_TYPE_FROM_CLASS (klass),
2758 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2760 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2762 GDK_TYPE_DRAG_CONTEXT,
2765 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2770 * GtkWidget::visibility-notify-event:
2771 * @widget: the object which received the signal
2772 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2773 * triggered this signal.
2775 * The ::visibility-notify-event will be emitted when the @widget's window
2776 * is obscured or unobscured.
2778 * To receive this signal the #GdkWindow associated to the widget needs
2779 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2781 * Returns: %TRUE to stop other handlers from being invoked for the event.
2782 * %FALSE to propagate the event further.
2784 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2785 g_signal_new (I_("visibility-notify-event"),
2786 G_TYPE_FROM_CLASS (klass),
2788 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2789 _gtk_boolean_handled_accumulator, NULL,
2790 _gtk_marshal_BOOLEAN__BOXED,
2792 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2795 * GtkWidget::window-state-event:
2796 * @widget: the object which received the signal
2797 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2798 * triggered this signal.
2800 * The ::window-state-event will be emitted when the state of the
2801 * toplevel window associated to the @widget changes.
2803 * To receive this signal the #GdkWindow associated to the widget
2804 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2805 * this mask automatically for all new windows.
2807 * Returns: %TRUE to stop other handlers from being invoked for the
2808 * event. %FALSE to propagate the event further.
2810 widget_signals[WINDOW_STATE_EVENT] =
2811 g_signal_new (I_("window-state-event"),
2812 G_TYPE_FROM_CLASS (klass),
2814 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2815 _gtk_boolean_handled_accumulator, NULL,
2816 _gtk_marshal_BOOLEAN__BOXED,
2818 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2821 * GtkWidget::damage-event:
2822 * @widget: the object which received the signal
2823 * @event: (type Gdk.EventExpose): the #GdkEventExpose event
2825 * Emitted when a redirected window belonging to @widget gets drawn into.
2826 * The region/area members of the event shows what area of the redirected
2827 * drawable was drawn into.
2829 * Returns: %TRUE to stop other handlers from being invoked for the event.
2830 * %FALSE to propagate the event further.
2834 widget_signals[DAMAGE_EVENT] =
2835 g_signal_new (I_("damage-event"),
2836 G_TYPE_FROM_CLASS (klass),
2838 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2839 _gtk_boolean_handled_accumulator, NULL,
2840 _gtk_marshal_BOOLEAN__BOXED,
2842 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2845 * GtkWidget::grab-broken-event:
2846 * @widget: the object which received the signal
2847 * @event: (type Gdk.EventGrabBroken): the #GdkEventGrabBroken event
2849 * Emitted when a pointer or keyboard grab on a window belonging
2850 * to @widget gets broken.
2852 * On X11, this happens when the grab window becomes unviewable
2853 * (i.e. it or one of its ancestors is unmapped), or if the same
2854 * application grabs the pointer or keyboard again.
2856 * Returns: %TRUE to stop other handlers from being invoked for
2857 * the event. %FALSE to propagate the event further.
2861 widget_signals[GRAB_BROKEN_EVENT] =
2862 g_signal_new (I_("grab-broken-event"),
2863 G_TYPE_FROM_CLASS (klass),
2865 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2866 _gtk_boolean_handled_accumulator, NULL,
2867 _gtk_marshal_BOOLEAN__BOXED,
2869 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2872 * GtkWidget::query-tooltip:
2873 * @widget: the object which received the signal
2874 * @x: the x coordinate of the cursor position where the request has
2875 * been emitted, relative to @widget's left side
2876 * @y: the y coordinate of the cursor position where the request has
2877 * been emitted, relative to @widget's top
2878 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2879 * @tooltip: a #GtkTooltip
2881 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2882 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2883 * focus in keyboard mode.
2885 * Using the given coordinates, the signal handler should determine
2886 * whether a tooltip should be shown for @widget. If this is the case
2887 * %TRUE should be returned, %FALSE otherwise. Note that if
2888 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2889 * should not be used.
2891 * The signal handler is free to manipulate @tooltip with the therefore
2892 * destined function calls.
2894 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2898 widget_signals[QUERY_TOOLTIP] =
2899 g_signal_new (I_("query-tooltip"),
2900 G_TYPE_FROM_CLASS (klass),
2902 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2903 _gtk_boolean_handled_accumulator, NULL,
2904 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2912 * GtkWidget::popup-menu
2913 * @widget: the object which received the signal
2915 * This signal gets emitted whenever a widget should pop up a context
2916 * menu. This usually happens through the standard key binding mechanism;
2917 * by pressing a certain key while a widget is focused, the user can cause
2918 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2919 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2920 * for an example of how to use this signal.
2922 * Returns: %TRUE if a menu was activated
2924 widget_signals[POPUP_MENU] =
2925 g_signal_new (I_("popup-menu"),
2926 G_TYPE_FROM_CLASS (klass),
2927 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2928 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2929 _gtk_boolean_handled_accumulator, NULL,
2930 _gtk_marshal_BOOLEAN__VOID,
2934 * GtkWidget::show-help:
2935 * @widget: the object which received the signal.
2938 widget_signals[SHOW_HELP] =
2939 g_signal_new (I_("show-help"),
2940 G_TYPE_FROM_CLASS (klass),
2941 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2942 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2943 _gtk_boolean_handled_accumulator, NULL,
2944 _gtk_marshal_BOOLEAN__ENUM,
2946 GTK_TYPE_WIDGET_HELP_TYPE);
2949 * GtkWidget::accel-closures-changed:
2950 * @widget: the object which received the signal.
2952 widget_signals[ACCEL_CLOSURES_CHANGED] =
2953 g_signal_new (I_("accel-closures-changed"),
2954 G_TYPE_FROM_CLASS (klass),
2958 _gtk_marshal_VOID__VOID,
2962 * GtkWidget::screen-changed:
2963 * @widget: the object on which the signal is emitted
2964 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2965 * widget was not associated with a screen before
2967 * The ::screen-changed signal gets emitted when the
2968 * screen of a widget has changed.
2970 widget_signals[SCREEN_CHANGED] =
2971 g_signal_new (I_("screen-changed"),
2972 G_TYPE_FROM_CLASS (klass),
2974 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2976 _gtk_marshal_VOID__OBJECT,
2981 * GtkWidget::can-activate-accel:
2982 * @widget: the object which received the signal
2983 * @signal_id: the ID of a signal installed on @widget
2985 * Determines whether an accelerator that activates the signal
2986 * identified by @signal_id can currently be activated.
2987 * This signal is present to allow applications and derived
2988 * widgets to override the default #GtkWidget handling
2989 * for determining whether an accelerator can be activated.
2991 * Returns: %TRUE if the signal can be activated.
2993 widget_signals[CAN_ACTIVATE_ACCEL] =
2994 g_signal_new (I_("can-activate-accel"),
2995 G_TYPE_FROM_CLASS (klass),
2997 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2998 _gtk_boolean_handled_accumulator, NULL,
2999 _gtk_marshal_BOOLEAN__UINT,
3000 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
3002 binding_set = gtk_binding_set_by_class (klass);
3003 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
3005 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
3008 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
3010 GTK_TYPE_WIDGET_HELP_TYPE,
3011 GTK_WIDGET_HELP_TOOLTIP);
3012 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
3014 GTK_TYPE_WIDGET_HELP_TYPE,
3015 GTK_WIDGET_HELP_TOOLTIP);
3016 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
3018 GTK_TYPE_WIDGET_HELP_TYPE,
3019 GTK_WIDGET_HELP_WHATS_THIS);
3020 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
3022 GTK_TYPE_WIDGET_HELP_TYPE,
3023 GTK_WIDGET_HELP_WHATS_THIS);
3025 gtk_widget_class_install_style_property (klass,
3026 g_param_spec_boolean ("interior-focus",
3027 P_("Interior Focus"),
3028 P_("Whether to draw the focus indicator inside widgets"),
3030 GTK_PARAM_READABLE));
3032 gtk_widget_class_install_style_property (klass,
3033 g_param_spec_int ("focus-line-width",
3034 P_("Focus linewidth"),
3035 P_("Width, in pixels, of the focus indicator line"),
3037 GTK_PARAM_READABLE));
3039 gtk_widget_class_install_style_property (klass,
3040 g_param_spec_string ("focus-line-pattern",
3041 P_("Focus line dash pattern"),
3042 P_("Dash pattern used to draw the focus indicator"),
3044 GTK_PARAM_READABLE));
3045 gtk_widget_class_install_style_property (klass,
3046 g_param_spec_int ("focus-padding",
3047 P_("Focus padding"),
3048 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3050 GTK_PARAM_READABLE));
3051 gtk_widget_class_install_style_property (klass,
3052 g_param_spec_boxed ("cursor-color",
3054 P_("Color with which to draw insertion cursor"),
3056 GTK_PARAM_READABLE));
3057 gtk_widget_class_install_style_property (klass,
3058 g_param_spec_boxed ("secondary-cursor-color",
3059 P_("Secondary cursor color"),
3060 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3062 GTK_PARAM_READABLE));
3063 gtk_widget_class_install_style_property (klass,
3064 g_param_spec_float ("cursor-aspect-ratio",
3065 P_("Cursor line aspect ratio"),
3066 P_("Aspect ratio with which to draw insertion cursor"),
3068 GTK_PARAM_READABLE));
3070 gtk_widget_class_install_style_property (klass,
3071 g_param_spec_boolean ("window-dragging",
3072 P_("Window dragging"),
3073 P_("Whether windows can be dragged by clicking on empty areas"),
3075 GTK_PARAM_READABLE));
3078 * GtkWidget:link-color:
3080 * The "link-color" style property defines the color of unvisited links.
3084 gtk_widget_class_install_style_property (klass,
3085 g_param_spec_boxed ("link-color",
3086 P_("Unvisited Link Color"),
3087 P_("Color of unvisited links"),
3089 GTK_PARAM_READABLE));
3092 * GtkWidget:visited-link-color:
3094 * The "visited-link-color" style property defines the color of visited links.
3098 gtk_widget_class_install_style_property (klass,
3099 g_param_spec_boxed ("visited-link-color",
3100 P_("Visited Link Color"),
3101 P_("Color of visited links"),
3103 GTK_PARAM_READABLE));
3106 * GtkWidget:wide-separators:
3108 * The "wide-separators" style property defines whether separators have
3109 * configurable width and should be drawn using a box instead of a line.
3113 gtk_widget_class_install_style_property (klass,
3114 g_param_spec_boolean ("wide-separators",
3115 P_("Wide Separators"),
3116 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3118 GTK_PARAM_READABLE));
3121 * GtkWidget:separator-width:
3123 * The "separator-width" style property defines the width of separators.
3124 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3128 gtk_widget_class_install_style_property (klass,
3129 g_param_spec_int ("separator-width",
3130 P_("Separator Width"),
3131 P_("The width of separators if wide-separators is TRUE"),
3133 GTK_PARAM_READABLE));
3136 * GtkWidget:separator-height:
3138 * The "separator-height" style property defines the height of separators.
3139 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3143 gtk_widget_class_install_style_property (klass,
3144 g_param_spec_int ("separator-height",
3145 P_("Separator Height"),
3146 P_("The height of separators if \"wide-separators\" is TRUE"),
3148 GTK_PARAM_READABLE));
3151 * GtkWidget:scroll-arrow-hlength:
3153 * The "scroll-arrow-hlength" style property defines the length of
3154 * horizontal scroll arrows.
3158 gtk_widget_class_install_style_property (klass,
3159 g_param_spec_int ("scroll-arrow-hlength",
3160 P_("Horizontal Scroll Arrow Length"),
3161 P_("The length of horizontal scroll arrows"),
3163 GTK_PARAM_READABLE));
3166 * GtkWidget:scroll-arrow-vlength:
3168 * The "scroll-arrow-vlength" style property defines the length of
3169 * vertical scroll arrows.
3173 gtk_widget_class_install_style_property (klass,
3174 g_param_spec_int ("scroll-arrow-vlength",
3175 P_("Vertical Scroll Arrow Length"),
3176 P_("The length of vertical scroll arrows"),
3178 GTK_PARAM_READABLE));
3180 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3182 gtk_widget_class_set_accessible_type (klass, GTK_TYPE_WIDGET_ACCESSIBLE);
3186 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3190 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3191 for (node = list; node; node = node->next)
3193 GParamSpec *pspec = node->data;
3195 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3196 g_param_spec_unref (pspec);
3202 gtk_widget_set_property (GObject *object,
3204 const GValue *value,
3207 GtkWidget *widget = GTK_WIDGET (object);
3212 gchar *tooltip_markup;
3213 const gchar *tooltip_text;
3214 GtkWindow *tooltip_window;
3217 gtk_widget_set_name (widget, g_value_get_string (value));
3220 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3222 case PROP_WIDTH_REQUEST:
3223 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3225 case PROP_HEIGHT_REQUEST:
3226 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3229 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3231 case PROP_SENSITIVE:
3232 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3234 case PROP_APP_PAINTABLE:
3235 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3237 case PROP_CAN_FOCUS:
3238 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3240 case PROP_HAS_FOCUS:
3241 if (g_value_get_boolean (value))
3242 gtk_widget_grab_focus (widget);
3245 if (g_value_get_boolean (value))
3246 gtk_widget_grab_focus (widget);
3248 case PROP_CAN_DEFAULT:
3249 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3251 case PROP_HAS_DEFAULT:
3252 if (g_value_get_boolean (value))
3253 gtk_widget_grab_default (widget);
3255 case PROP_RECEIVES_DEFAULT:
3256 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3259 gtk_widget_set_style (widget, g_value_get_object (value));
3262 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3263 gtk_widget_set_events (widget, g_value_get_flags (value));
3265 case PROP_NO_SHOW_ALL:
3266 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3268 case PROP_HAS_TOOLTIP:
3269 gtk_widget_real_set_has_tooltip (widget,
3270 g_value_get_boolean (value), FALSE);
3272 case PROP_TOOLTIP_MARKUP:
3273 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3274 tooltip_markup = g_value_dup_string (value);
3276 /* Treat an empty string as a NULL string,
3277 * because an empty string would be useless for a tooltip:
3279 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3281 g_free (tooltip_markup);
3282 tooltip_markup = NULL;
3285 g_object_set_qdata_full (object, quark_tooltip_markup,
3286 tooltip_markup, g_free);
3288 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3289 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3290 if (gtk_widget_get_visible (widget))
3291 gtk_widget_queue_tooltip_query (widget);
3293 case PROP_TOOLTIP_TEXT:
3294 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3296 tooltip_text = g_value_get_string (value);
3298 /* Treat an empty string as a NULL string,
3299 * because an empty string would be useless for a tooltip:
3301 if (tooltip_text && (strlen (tooltip_text) == 0))
3302 tooltip_text = NULL;
3304 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3306 g_object_set_qdata_full (object, quark_tooltip_markup,
3307 tooltip_markup, g_free);
3309 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3310 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3311 if (gtk_widget_get_visible (widget))
3312 gtk_widget_queue_tooltip_query (widget);
3314 case PROP_DOUBLE_BUFFERED:
3315 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3318 gtk_widget_set_halign (widget, g_value_get_enum (value));
3321 gtk_widget_set_valign (widget, g_value_get_enum (value));
3323 case PROP_MARGIN_LEFT:
3324 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3326 case PROP_MARGIN_RIGHT:
3327 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3329 case PROP_MARGIN_TOP:
3330 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3332 case PROP_MARGIN_BOTTOM:
3333 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3336 g_object_freeze_notify (G_OBJECT (widget));
3337 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3338 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3339 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3340 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3341 g_object_thaw_notify (G_OBJECT (widget));
3344 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3346 case PROP_HEXPAND_SET:
3347 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3350 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3352 case PROP_VEXPAND_SET:
3353 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3356 g_object_freeze_notify (G_OBJECT (widget));
3357 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3358 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3359 g_object_thaw_notify (G_OBJECT (widget));
3362 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3368 gtk_widget_get_property (GObject *object,
3373 GtkWidget *widget = GTK_WIDGET (object);
3374 GtkWidgetPrivate *priv = widget->priv;
3382 g_value_set_string (value, priv->name);
3384 g_value_set_static_string (value, "");
3387 g_value_set_object (value, priv->parent);
3389 case PROP_WIDTH_REQUEST:
3392 gtk_widget_get_size_request (widget, &w, NULL);
3393 g_value_set_int (value, w);
3396 case PROP_HEIGHT_REQUEST:
3399 gtk_widget_get_size_request (widget, NULL, &h);
3400 g_value_set_int (value, h);
3404 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3406 case PROP_SENSITIVE:
3407 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3409 case PROP_APP_PAINTABLE:
3410 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3412 case PROP_CAN_FOCUS:
3413 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3415 case PROP_HAS_FOCUS:
3416 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3419 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3421 case PROP_CAN_DEFAULT:
3422 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3424 case PROP_HAS_DEFAULT:
3425 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3427 case PROP_RECEIVES_DEFAULT:
3428 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3430 case PROP_COMPOSITE_CHILD:
3431 g_value_set_boolean (value, widget->priv->composite_child);
3434 g_value_set_object (value, gtk_widget_get_style (widget));
3437 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3438 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3440 case PROP_NO_SHOW_ALL:
3441 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3443 case PROP_HAS_TOOLTIP:
3444 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3446 case PROP_TOOLTIP_TEXT:
3448 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3451 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3452 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3454 g_value_take_string (value, text);
3457 case PROP_TOOLTIP_MARKUP:
3458 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3461 g_value_set_object (value, gtk_widget_get_window (widget));
3463 case PROP_DOUBLE_BUFFERED:
3464 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3467 g_value_set_enum (value, gtk_widget_get_halign (widget));
3470 g_value_set_enum (value, gtk_widget_get_valign (widget));
3472 case PROP_MARGIN_LEFT:
3473 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3475 case PROP_MARGIN_RIGHT:
3476 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3478 case PROP_MARGIN_TOP:
3479 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3481 case PROP_MARGIN_BOTTOM:
3482 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3486 GtkWidgetAuxInfo *aux_info = gtk_widget_get_aux_info (widget, FALSE);
3487 if (aux_info == NULL)
3489 g_value_set_int (value, 0);
3493 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3494 aux_info->margin.right),
3495 MAX (aux_info->margin.top,
3496 aux_info->margin.bottom)));
3501 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3503 case PROP_HEXPAND_SET:
3504 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3507 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3509 case PROP_VEXPAND_SET:
3510 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3513 g_value_set_boolean (value,
3514 gtk_widget_get_hexpand (widget) &&
3515 gtk_widget_get_vexpand (widget));
3518 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3524 gtk_widget_init (GtkWidget *widget)
3526 GtkWidgetPrivate *priv;
3528 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3531 priv = widget->priv;
3533 priv->child_visible = TRUE;
3535 priv->allocation.x = -1;
3536 priv->allocation.y = -1;
3537 priv->allocation.width = 1;
3538 priv->allocation.height = 1;
3539 priv->window = NULL;
3540 priv->parent = NULL;
3542 priv->sensitive = TRUE;
3543 priv->composite_child = composite_child_stack != 0;
3544 priv->double_buffered = TRUE;
3545 priv->redraw_on_alloc = TRUE;
3546 priv->width_request_needed = TRUE;
3547 priv->height_request_needed = TRUE;
3548 priv->alloc_needed = TRUE;
3550 /* this will be set to TRUE if the widget gets a child or if the
3551 * expand flag is set on the widget, but until one of those happen
3552 * we know the expand is already properly FALSE.
3554 * We really want to default FALSE here to avoid computing expand
3555 * all over the place while initially building a widget tree.
3557 priv->need_compute_expand = FALSE;
3559 priv->style = gtk_widget_get_default_style ();
3560 g_object_ref (priv->style);
3565 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3567 GParamSpec **pspecs)
3569 GtkWidgetPrivate *priv = widget->priv;
3570 GtkWidget *container = priv->parent;
3573 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3574 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3578 * gtk_widget_freeze_child_notify:
3579 * @widget: a #GtkWidget
3581 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3582 * signals are queued until gtk_widget_thaw_child_notify() is called
3585 * This is the analogue of g_object_freeze_notify() for child properties.
3588 gtk_widget_freeze_child_notify (GtkWidget *widget)
3590 g_return_if_fail (GTK_IS_WIDGET (widget));
3592 if (!G_OBJECT (widget)->ref_count)
3595 g_object_ref (widget);
3596 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3597 g_object_unref (widget);
3601 * gtk_widget_child_notify:
3602 * @widget: a #GtkWidget
3603 * @child_property: the name of a child property installed on the
3604 * class of @widget<!-- -->'s parent
3606 * Emits a #GtkWidget::child-notify signal for the
3607 * <link linkend="child-properties">child property</link> @child_property
3610 * This is the analogue of g_object_notify() for child properties.
3612 * Also see gtk_container_child_notify().
3615 gtk_widget_child_notify (GtkWidget *widget,
3616 const gchar *child_property)
3618 if (widget->priv->parent == NULL)
3621 gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
3625 * gtk_widget_thaw_child_notify:
3626 * @widget: a #GtkWidget
3628 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3629 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3633 gtk_widget_thaw_child_notify (GtkWidget *widget)
3635 GObjectNotifyQueue *nqueue;
3637 g_return_if_fail (GTK_IS_WIDGET (widget));
3639 if (!G_OBJECT (widget)->ref_count)
3642 g_object_ref (widget);
3643 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3644 if (!nqueue || !nqueue->freeze_count)
3645 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3646 G_OBJECT_TYPE_NAME (widget), widget);
3648 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3649 g_object_unref (widget);
3655 * @type: type ID of the widget to create
3656 * @first_property_name: name of first property to set
3657 * @Varargs: value of first property, followed by more properties,
3660 * This is a convenience function for creating a widget and setting
3661 * its properties in one go. For example you might write:
3662 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3663 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3664 * g_object_new(), but returns a widget so you don't have to
3665 * cast the object yourself.
3667 * Return value: a new #GtkWidget of type @widget_type
3670 gtk_widget_new (GType type,
3671 const gchar *first_property_name,
3677 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3679 va_start (var_args, first_property_name);
3680 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3687 gtk_widget_queue_draw_child (GtkWidget *widget)
3689 GtkWidgetPrivate *priv = widget->priv;
3692 parent = priv->parent;
3693 if (parent && gtk_widget_is_drawable (parent))
3694 gtk_widget_queue_draw_area (parent,
3697 priv->allocation.width,
3698 priv->allocation.height);
3702 * gtk_widget_unparent:
3703 * @widget: a #GtkWidget
3705 * This function is only for use in widget implementations.
3706 * Should be called by implementations of the remove method
3707 * on #GtkContainer, to dissociate a child from the container.
3710 gtk_widget_unparent (GtkWidget *widget)
3712 GtkWidgetPrivate *priv;
3713 GObjectNotifyQueue *nqueue;
3714 GtkWidget *toplevel;
3715 GtkWidget *old_parent;
3717 g_return_if_fail (GTK_IS_WIDGET (widget));
3719 priv = widget->priv;
3721 if (priv->parent == NULL)
3724 /* keep this function in sync with gtk_menu_detach() */
3726 gtk_widget_push_verify_invariants (widget);
3728 g_object_freeze_notify (G_OBJECT (widget));
3729 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3731 toplevel = gtk_widget_get_toplevel (widget);
3732 if (gtk_widget_is_toplevel (toplevel))
3733 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3735 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3736 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3738 gtk_widget_queue_draw_child (widget);
3740 /* Reset the width and height here, to force reallocation if we
3741 * get added back to a new parent. This won't work if our new
3742 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3743 * (would 0x0 be OK here?)
3745 priv->allocation.width = 1;
3746 priv->allocation.height = 1;
3748 if (gtk_widget_get_realized (widget))
3750 if (priv->in_reparent)
3751 gtk_widget_unmap (widget);
3753 gtk_widget_unrealize (widget);
3756 /* If we are unanchoring the child, we save around the toplevel
3757 * to emit hierarchy changed
3759 if (priv->parent->priv->anchored)
3760 g_object_ref (toplevel);
3764 /* Removing a widget from a container restores the child visible
3765 * flag to the default state, so it doesn't affect the child
3766 * in the next parent.
3768 priv->child_visible = TRUE;
3770 old_parent = priv->parent;
3771 priv->parent = NULL;
3773 /* parent may no longer expand if the removed
3774 * child was expand=TRUE and could therefore
3777 if (gtk_widget_get_visible (widget) &&
3778 (priv->need_compute_expand ||
3779 priv->computed_hexpand ||
3780 priv->computed_vexpand))
3782 gtk_widget_queue_compute_expand (old_parent);
3785 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3788 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3789 g_object_unref (toplevel);
3792 /* Now that the parent pointer is nullified and the hierarchy-changed
3793 * already passed, go ahead and unset the parent window, if we are unparenting
3794 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
3795 * will fire again for the new subhierarchy.
3797 gtk_widget_set_parent_window (widget, NULL);
3799 g_object_notify (G_OBJECT (widget), "parent");
3800 g_object_thaw_notify (G_OBJECT (widget));
3802 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3803 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3805 gtk_widget_pop_verify_invariants (widget);
3806 g_object_unref (widget);
3810 * gtk_widget_destroy:
3811 * @widget: a #GtkWidget
3813 * Destroys a widget.
3816 * destroyed, it will break any references it holds to other objects.
3817 * If the widget is inside a container, the widget will be removed
3818 * from the container. If the widget is a toplevel (derived from
3819 * #GtkWindow), it will be removed from the list of toplevels, and the
3820 * reference GTK+ holds to it will be removed. Removing a
3821 * widget from its container or the list of toplevels results in the
3822 * widget being finalized, unless you've added additional references
3823 * to the widget with g_object_ref().
3825 * In most cases, only toplevel widgets (windows) require explicit
3826 * destruction, because when you destroy a toplevel its children will
3827 * be destroyed as well.
3830 gtk_widget_destroy (GtkWidget *widget)
3832 g_return_if_fail (GTK_IS_WIDGET (widget));
3834 if (!widget->priv->in_destruction)
3835 g_object_run_dispose (G_OBJECT (widget));
3839 * gtk_widget_destroyed:
3840 * @widget: a #GtkWidget
3841 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3843 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3844 * %NULL. It's intended to be used as a callback connected to the
3845 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3846 * as a signal handler, and pass the address of your widget variable
3847 * as user data. Then when the widget is destroyed, the variable will
3848 * be set to %NULL. Useful for example to avoid multiple copies
3849 * of the same dialog.
3852 gtk_widget_destroyed (GtkWidget *widget,
3853 GtkWidget **widget_pointer)
3855 /* Don't make any assumptions about the
3857 * Even check widget_pointer.
3860 *widget_pointer = NULL;
3865 * @widget: a #GtkWidget
3867 * Flags a widget to be displayed. Any widget that isn't shown will
3868 * not appear on the screen. If you want to show all the widgets in a
3869 * container, it's easier to call gtk_widget_show_all() on the
3870 * container, instead of individually showing the widgets.
3872 * Remember that you have to show the containers containing a widget,
3873 * in addition to the widget itself, before it will appear onscreen.
3875 * When a toplevel container is shown, it is immediately realized and
3876 * mapped; other shown widgets are realized and mapped when their
3877 * toplevel container is realized and mapped.
3880 gtk_widget_show (GtkWidget *widget)
3882 g_return_if_fail (GTK_IS_WIDGET (widget));
3884 if (!gtk_widget_get_visible (widget))
3886 g_object_ref (widget);
3887 gtk_widget_push_verify_invariants (widget);
3889 if (!gtk_widget_is_toplevel (widget))
3890 gtk_widget_queue_resize (widget);
3892 /* see comment in set_parent() for why this should and can be
3895 if (widget->priv->need_compute_expand ||
3896 widget->priv->computed_hexpand ||
3897 widget->priv->computed_vexpand)
3899 if (widget->priv->parent != NULL)
3900 gtk_widget_queue_compute_expand (widget->priv->parent);
3903 g_signal_emit (widget, widget_signals[SHOW], 0);
3904 g_object_notify (G_OBJECT (widget), "visible");
3906 gtk_widget_pop_verify_invariants (widget);
3907 g_object_unref (widget);
3912 gtk_widget_real_show (GtkWidget *widget)
3914 GtkWidgetPrivate *priv = widget->priv;
3916 if (!gtk_widget_get_visible (widget))
3918 priv->visible = TRUE;
3921 gtk_widget_get_mapped (priv->parent) &&
3922 gtk_widget_get_child_visible (widget) &&
3923 !gtk_widget_get_mapped (widget))
3924 gtk_widget_map (widget);
3929 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3932 g_signal_handlers_disconnect_by_func (widget,
3933 gtk_widget_show_map_callback,
3938 * gtk_widget_show_now:
3939 * @widget: a #GtkWidget
3941 * Shows a widget. If the widget is an unmapped toplevel widget
3942 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3943 * loop and wait for the window to actually be mapped. Be careful;
3944 * because the main loop is running, anything can happen during
3948 gtk_widget_show_now (GtkWidget *widget)
3952 g_return_if_fail (GTK_IS_WIDGET (widget));
3954 /* make sure we will get event */
3955 if (!gtk_widget_get_mapped (widget) &&
3956 gtk_widget_is_toplevel (widget))
3958 gtk_widget_show (widget);
3960 g_signal_connect (widget, "map-event",
3961 G_CALLBACK (gtk_widget_show_map_callback),
3965 gtk_main_iteration ();
3968 gtk_widget_show (widget);
3973 * @widget: a #GtkWidget
3975 * Reverses the effects of gtk_widget_show(), causing the widget to be
3976 * hidden (invisible to the user).
3979 gtk_widget_hide (GtkWidget *widget)
3981 g_return_if_fail (GTK_IS_WIDGET (widget));
3983 if (gtk_widget_get_visible (widget))
3985 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3987 g_object_ref (widget);
3988 gtk_widget_push_verify_invariants (widget);
3990 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3991 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3993 /* a parent may now be expand=FALSE since we're hidden. */
3994 if (widget->priv->need_compute_expand ||
3995 widget->priv->computed_hexpand ||
3996 widget->priv->computed_vexpand)
3998 gtk_widget_queue_compute_expand (widget);
4001 g_signal_emit (widget, widget_signals[HIDE], 0);
4002 if (!gtk_widget_is_toplevel (widget))
4003 gtk_widget_queue_resize (widget);
4004 g_object_notify (G_OBJECT (widget), "visible");
4006 gtk_widget_pop_verify_invariants (widget);
4007 g_object_unref (widget);
4012 gtk_widget_real_hide (GtkWidget *widget)
4014 if (gtk_widget_get_visible (widget))
4016 widget->priv->visible = FALSE;
4018 if (gtk_widget_get_mapped (widget))
4019 gtk_widget_unmap (widget);
4024 * gtk_widget_hide_on_delete:
4025 * @widget: a #GtkWidget
4027 * Utility function; intended to be connected to the #GtkWidget::delete-event
4028 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4029 * argument, then returns %TRUE. If connected to ::delete-event, the
4030 * result is that clicking the close button for a window (on the
4031 * window frame, top right corner usually) will hide but not destroy
4032 * the window. By default, GTK+ destroys windows when ::delete-event
4035 * Return value: %TRUE
4038 gtk_widget_hide_on_delete (GtkWidget *widget)
4040 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4042 gtk_widget_hide (widget);
4048 * gtk_widget_show_all:
4049 * @widget: a #GtkWidget
4051 * Recursively shows a widget, and any child widgets (if the widget is
4055 gtk_widget_show_all (GtkWidget *widget)
4057 GtkWidgetClass *class;
4059 g_return_if_fail (GTK_IS_WIDGET (widget));
4061 if (gtk_widget_get_no_show_all (widget))
4064 class = GTK_WIDGET_GET_CLASS (widget);
4066 if (class->show_all)
4067 class->show_all (widget);
4071 _gtk_widget_notify_state_change (GtkWidget *widget,
4079 case GTK_STATE_FLAG_ACTIVE:
4080 state = GTK_STATE_ACTIVE;
4082 case GTK_STATE_FLAG_PRELIGHT:
4083 state = GTK_STATE_PRELIGHT;
4085 case GTK_STATE_FLAG_SELECTED:
4086 state = GTK_STATE_SELECTED;
4088 case GTK_STATE_FLAG_INSENSITIVE:
4089 state = GTK_STATE_INSENSITIVE;
4091 case GTK_STATE_FLAG_INCONSISTENT:
4092 state = GTK_STATE_INCONSISTENT;
4094 case GTK_STATE_FLAG_FOCUSED:
4095 state = GTK_STATE_FOCUSED;
4101 gtk_style_context_notify_state_change (widget->priv->context,
4102 gtk_widget_get_window (widget),
4103 NULL, state, target);
4106 /* Initializes state transitions for those states that
4107 * were enabled before mapping and have a looping animation.
4110 _gtk_widget_start_state_transitions (GtkWidget *widget)
4112 GtkStateFlags state, flag;
4114 if (!widget->priv->context)
4117 state = gtk_widget_get_state_flags (widget);
4118 flag = GTK_STATE_FLAG_FOCUSED;
4122 GtkAnimationDescription *animation_desc;
4124 if ((state & flag) == 0)
4130 gtk_style_context_get (widget->priv->context, state,
4131 "transition", &animation_desc,
4136 if (_gtk_animation_description_get_loop (animation_desc))
4137 _gtk_widget_notify_state_change (widget, flag, TRUE);
4139 _gtk_animation_description_unref (animation_desc);
4148 * @widget: a #GtkWidget
4150 * This function is only for use in widget implementations. Causes
4151 * a widget to be mapped if it isn't already.
4154 gtk_widget_map (GtkWidget *widget)
4156 GtkWidgetPrivate *priv;
4158 g_return_if_fail (GTK_IS_WIDGET (widget));
4159 g_return_if_fail (gtk_widget_get_visible (widget));
4160 g_return_if_fail (gtk_widget_get_child_visible (widget));
4162 priv = widget->priv;
4164 if (!gtk_widget_get_mapped (widget))
4166 gtk_widget_push_verify_invariants (widget);
4168 if (!gtk_widget_get_realized (widget))
4169 gtk_widget_realize (widget);
4171 g_signal_emit (widget, widget_signals[MAP], 0);
4173 if (!gtk_widget_get_has_window (widget))
4174 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4176 gtk_widget_pop_verify_invariants (widget);
4178 _gtk_widget_start_state_transitions (widget);
4184 * @widget: a #GtkWidget
4186 * This function is only for use in widget implementations. Causes
4187 * a widget to be unmapped if it's currently mapped.
4190 gtk_widget_unmap (GtkWidget *widget)
4192 GtkWidgetPrivate *priv;
4194 g_return_if_fail (GTK_IS_WIDGET (widget));
4196 priv = widget->priv;
4198 if (gtk_widget_get_mapped (widget))
4200 gtk_widget_push_verify_invariants (widget);
4202 if (!gtk_widget_get_has_window (widget))
4203 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4204 _gtk_tooltip_hide (widget);
4205 g_signal_emit (widget, widget_signals[UNMAP], 0);
4207 gtk_widget_pop_verify_invariants (widget);
4210 gtk_style_context_cancel_animations (priv->context, NULL);
4212 /* Unset pointer/window info */
4213 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4218 _gtk_widget_enable_device_events (GtkWidget *widget)
4220 GHashTable *device_events;
4221 GHashTableIter iter;
4222 gpointer key, value;
4224 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4229 g_hash_table_iter_init (&iter, device_events);
4231 while (g_hash_table_iter_next (&iter, &key, &value))
4234 GdkEventMask event_mask;
4237 event_mask = GPOINTER_TO_UINT (value);
4238 gtk_widget_add_events_internal (widget, device, event_mask);
4243 get_widget_windows (GtkWidget *widget)
4245 GList *window_list, *last, *l, *children, *ret;
4247 if (gtk_widget_get_has_window (widget))
4248 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4250 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4252 last = g_list_last (window_list);
4255 for (l = window_list; l; l = l->next)
4257 GtkWidget *window_widget = NULL;
4259 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4261 if (widget != window_widget)
4264 ret = g_list_prepend (ret, l->data);
4265 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4269 last = g_list_concat (last, children);
4270 last = g_list_last (last);
4274 g_list_free (window_list);
4280 device_enable_foreach (GtkWidget *widget,
4283 GdkDevice *device = user_data;
4284 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4288 device_disable_foreach (GtkWidget *widget,
4291 GdkDevice *device = user_data;
4292 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4296 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4301 GList *window_list, *l;
4303 window_list = get_widget_windows (widget);
4305 for (l = window_list; l; l = l->next)
4307 GdkEventMask events = 0;
4313 events = gdk_window_get_events (window);
4315 gdk_window_set_device_events (window, device, events);
4318 if (recurse && GTK_IS_CONTAINER (widget))
4321 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4323 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4326 g_list_free (window_list);
4330 gtk_widget_update_devices_mask (GtkWidget *widget,
4333 GList *enabled_devices, *l;
4335 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4337 for (l = enabled_devices; l; l = l->next)
4338 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4342 * gtk_widget_realize:
4343 * @widget: a #GtkWidget
4345 * Creates the GDK (windowing system) resources associated with a
4346 * widget. For example, @widget->window will be created when a widget
4347 * is realized. Normally realization happens implicitly; if you show
4348 * a widget and all its parent containers, then the widget will be
4349 * realized and mapped automatically.
4351 * Realizing a widget requires all
4352 * the widget's parent widgets to be realized; calling
4353 * gtk_widget_realize() realizes the widget's parents in addition to
4354 * @widget itself. If a widget is not yet inside a toplevel window
4355 * when you realize it, bad things will happen.
4357 * This function is primarily used in widget implementations, and
4358 * isn't very useful otherwise. Many times when you think you might
4359 * need it, a better approach is to connect to a signal that will be
4360 * called after the widget is realized automatically, such as
4361 * #GtkWidget::draw. Or simply g_signal_connect () to the
4362 * #GtkWidget::realize signal.
4365 gtk_widget_realize (GtkWidget *widget)
4367 GtkWidgetPrivate *priv;
4368 cairo_region_t *region;
4370 g_return_if_fail (GTK_IS_WIDGET (widget));
4371 g_return_if_fail (widget->priv->anchored ||
4372 GTK_IS_INVISIBLE (widget));
4374 priv = widget->priv;
4376 if (!gtk_widget_get_realized (widget))
4378 gtk_widget_push_verify_invariants (widget);
4381 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4382 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4385 if (priv->parent == NULL &&
4386 !gtk_widget_is_toplevel (widget))
4387 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4388 "inside a toplevel window is not going to work very well. "
4389 "Widgets must be inside a toplevel container before realizing them.");
4391 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4392 gtk_widget_realize (priv->parent);
4394 gtk_widget_ensure_style (widget);
4396 if (priv->style_update_pending)
4397 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4399 g_signal_emit (widget, widget_signals[REALIZE], 0);
4401 gtk_widget_real_set_has_tooltip (widget,
4402 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4405 if (priv->has_shape_mask)
4407 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4408 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4411 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4413 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4415 if (priv->multidevice)
4416 gdk_window_set_support_multidevice (priv->window, TRUE);
4418 _gtk_widget_enable_device_events (widget);
4419 gtk_widget_update_devices_mask (widget, TRUE);
4421 gtk_widget_pop_verify_invariants (widget);
4426 * gtk_widget_unrealize:
4427 * @widget: a #GtkWidget
4429 * This function is only useful in widget implementations.
4430 * Causes a widget to be unrealized (frees all GDK resources
4431 * associated with the widget, such as @widget->window).
4434 gtk_widget_unrealize (GtkWidget *widget)
4436 g_return_if_fail (GTK_IS_WIDGET (widget));
4438 gtk_widget_push_verify_invariants (widget);
4440 if (widget->priv->has_shape_mask)
4441 gtk_widget_shape_combine_region (widget, NULL);
4443 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4444 gtk_widget_input_shape_combine_region (widget, NULL);
4446 if (gtk_widget_get_realized (widget))
4448 g_object_ref (widget);
4450 if (widget->priv->mapped)
4451 gtk_widget_unmap (widget);
4453 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4454 g_assert (!widget->priv->mapped);
4455 gtk_widget_set_realized (widget, FALSE);
4457 g_object_unref (widget);
4460 gtk_widget_pop_verify_invariants (widget);
4463 /*****************************************
4465 *****************************************/
4468 * gtk_widget_queue_draw_region:
4469 * @widget: a #GtkWidget
4470 * @region: region to draw
4472 * Invalidates the rectangular area of @widget defined by @region by
4473 * calling gdk_window_invalidate_region() on the widget's window and
4474 * all its child windows. Once the main loop becomes idle (after the
4475 * current batch of events has been processed, roughly), the window
4476 * will receive expose events for the union of all regions that have
4479 * Normally you would only use this function in widget
4480 * implementations. You might also use it to schedule a redraw of a
4481 * #GtkDrawingArea or some portion thereof.
4486 gtk_widget_queue_draw_region (GtkWidget *widget,
4487 const cairo_region_t *region)
4489 GtkWidgetPrivate *priv;
4492 g_return_if_fail (GTK_IS_WIDGET (widget));
4494 priv = widget->priv;
4496 if (!gtk_widget_get_realized (widget))
4499 /* Just return if the widget or one of its ancestors isn't mapped */
4500 for (w = widget; w != NULL; w = w->priv->parent)
4501 if (!gtk_widget_get_mapped (w))
4504 gdk_window_invalidate_region (priv->window, region, TRUE);
4508 * gtk_widget_queue_draw_area:
4509 * @widget: a #GtkWidget
4510 * @x: x coordinate of upper-left corner of rectangle to redraw
4511 * @y: y coordinate of upper-left corner of rectangle to redraw
4512 * @width: width of region to draw
4513 * @height: height of region to draw
4515 * Convenience function that calls gtk_widget_queue_draw_region() on
4516 * the region created from the given coordinates.
4518 * The region here is specified in widget coordinates.
4519 * Widget coordinates are a bit odd; for historical reasons, they are
4520 * defined as @widget->window coordinates for widgets that are not
4521 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4522 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4525 gtk_widget_queue_draw_area (GtkWidget *widget,
4532 cairo_region_t *region;
4534 g_return_if_fail (GTK_IS_WIDGET (widget));
4539 rect.height = height;
4541 region = cairo_region_create_rectangle (&rect);
4542 gtk_widget_queue_draw_region (widget, region);
4543 cairo_region_destroy (region);
4547 * gtk_widget_queue_draw:
4548 * @widget: a #GtkWidget
4550 * Equivalent to calling gtk_widget_queue_draw_area() for the
4551 * entire area of a widget.
4554 gtk_widget_queue_draw (GtkWidget *widget)
4558 g_return_if_fail (GTK_IS_WIDGET (widget));
4560 gtk_widget_get_allocation (widget, &rect);
4562 if (!gtk_widget_get_has_window (widget))
4563 gtk_widget_queue_draw_area (widget,
4564 rect.x, rect.y, rect.width, rect.height);
4566 gtk_widget_queue_draw_area (widget,
4567 0, 0, rect.width, rect.height);
4571 * gtk_widget_queue_resize:
4572 * @widget: a #GtkWidget
4574 * This function is only for use in widget implementations.
4575 * Flags a widget to have its size renegotiated; should
4576 * be called when a widget for some reason has a new size request.
4577 * For example, when you change the text in a #GtkLabel, #GtkLabel
4578 * queues a resize to ensure there's enough space for the new text.
4580 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4581 * from inside its implementation of the GtkWidgetClass::size_allocate
4582 * virtual method. Calls to gtk_widget_queue_resize() from inside
4583 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4586 gtk_widget_queue_resize (GtkWidget *widget)
4588 g_return_if_fail (GTK_IS_WIDGET (widget));
4590 if (gtk_widget_get_realized (widget))
4591 gtk_widget_queue_shallow_draw (widget);
4593 _gtk_size_group_queue_resize (widget, 0);
4597 * gtk_widget_queue_resize_no_redraw:
4598 * @widget: a #GtkWidget
4600 * This function works like gtk_widget_queue_resize(),
4601 * except that the widget is not invalidated.
4606 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4608 g_return_if_fail (GTK_IS_WIDGET (widget));
4610 _gtk_size_group_queue_resize (widget, 0);
4614 * gtk_widget_size_request:
4615 * @widget: a #GtkWidget
4616 * @requisition: (out): a #GtkRequisition to be filled in
4618 * This function is typically used when implementing a #GtkContainer
4619 * subclass. Obtains the preferred size of a widget. The container
4620 * uses this information to arrange its child widgets and decide what
4621 * size allocations to give them with gtk_widget_size_allocate().
4623 * You can also call this function from an application, with some
4624 * caveats. Most notably, getting a size request requires the widget
4625 * to be associated with a screen, because font information may be
4626 * needed. Multihead-aware applications should keep this in mind.
4628 * Also remember that the size request is not necessarily the size
4629 * a widget will actually be allocated.
4631 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4634 gtk_widget_size_request (GtkWidget *widget,
4635 GtkRequisition *requisition)
4637 g_return_if_fail (GTK_IS_WIDGET (widget));
4639 gtk_widget_get_preferred_size (widget, requisition, NULL);
4643 * gtk_widget_get_child_requisition:
4644 * @widget: a #GtkWidget
4645 * @requisition: (out): a #GtkRequisition to be filled in
4647 * This function is only for use in widget implementations. Obtains
4648 * @widget->requisition, unless someone has forced a particular
4649 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4650 * in which case it returns that geometry instead of the widget's
4653 * This function differs from gtk_widget_size_request() in that
4654 * it retrieves the last size request value from @widget->requisition,
4655 * while gtk_widget_size_request() actually calls the "size_request" method
4656 * on @widget to compute the size request and fill in @widget->requisition,
4657 * and only then returns @widget->requisition.
4659 * Because this function does not call the "size_request" method, it
4660 * can only be used when you know that @widget->requisition is
4661 * up-to-date, that is, gtk_widget_size_request() has been called
4662 * since the last time a resize was queued. In general, only container
4663 * implementations have this information; applications should use
4664 * gtk_widget_size_request().
4667 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4670 gtk_widget_get_child_requisition (GtkWidget *widget,
4671 GtkRequisition *requisition)
4673 gtk_widget_get_preferred_size (widget, requisition, NULL);
4677 invalidate_predicate (GdkWindow *window,
4682 gdk_window_get_user_data (window, &user_data);
4684 return (user_data == data);
4687 /* Invalidate @region in widget->window and all children
4688 * of widget->window owned by widget. @region is in the
4689 * same coordinates as widget->allocation and will be
4690 * modified by this call.
4693 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4694 cairo_region_t *region)
4696 GtkWidgetPrivate *priv = widget->priv;
4698 if (!gtk_widget_get_realized (widget))
4701 if (gtk_widget_get_has_window (widget) && priv->parent)
4705 gdk_window_get_position (priv->window, &x, &y);
4706 cairo_region_translate (region, -x, -y);
4709 gdk_window_invalidate_maybe_recurse (priv->window, region,
4710 invalidate_predicate, widget);
4714 * gtk_widget_queue_shallow_draw:
4715 * @widget: a #GtkWidget
4717 * Like gtk_widget_queue_draw(), but only windows owned
4718 * by @widget are invalidated.
4721 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4724 cairo_region_t *region;
4726 if (!gtk_widget_get_realized (widget))
4729 gtk_widget_get_allocation (widget, &rect);
4731 region = cairo_region_create_rectangle (&rect);
4732 gtk_widget_invalidate_widget_windows (widget, region);
4733 cairo_region_destroy (region);
4737 * gtk_widget_size_allocate:
4738 * @widget: a #GtkWidget
4739 * @allocation: position and size to be allocated to @widget
4741 * This function is only used by #GtkContainer subclasses, to assign a size
4742 * and position to their child widgets.
4744 * In this function, the allocation may be adjusted. It will be forced
4745 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4746 * method on the child will be used to adjust the allocation. Standard
4747 * adjustments include removing the widget's margins, and applying the
4748 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4751 gtk_widget_size_allocate (GtkWidget *widget,
4752 GtkAllocation *allocation)
4754 GtkWidgetPrivate *priv;
4755 GdkRectangle real_allocation;
4756 GdkRectangle old_allocation;
4757 GdkRectangle adjusted_allocation;
4758 gboolean alloc_needed;
4759 gboolean size_changed;
4760 gboolean position_changed;
4761 gint natural_width, natural_height, dummy;
4762 gint min_width, min_height;
4764 priv = widget->priv;
4766 g_return_if_fail (GTK_IS_WIDGET (widget));
4768 gtk_widget_push_verify_invariants (widget);
4770 #ifdef G_ENABLE_DEBUG
4771 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4782 parent = gtk_widget_get_parent (parent);
4785 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4786 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4787 2 * depth, " ", name,
4788 allocation->width, allocation->height);
4790 #endif /* G_ENABLE_DEBUG */
4792 alloc_needed = priv->alloc_needed;
4793 if (!priv->width_request_needed && !priv->height_request_needed)
4794 /* Preserve request/allocate ordering */
4795 priv->alloc_needed = FALSE;
4797 old_allocation = priv->allocation;
4798 real_allocation = *allocation;
4800 adjusted_allocation = real_allocation;
4801 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4803 /* Go ahead and request the height for allocated width, note that the internals
4804 * of get_height_for_width will internally limit the for_size to natural size
4805 * when aligning implicitly.
4807 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4808 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
4812 /* Go ahead and request the width for allocated height, note that the internals
4813 * of get_width_for_height will internally limit the for_size to natural size
4814 * when aligning implicitly.
4816 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4817 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
4820 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
4821 !GTK_IS_SCROLLABLE (widget))
4822 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
4823 "Allocation is %dx%d, but minimum required size is %dx%d.",
4824 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
4825 G_OBJECT_TYPE_NAME (widget), widget,
4826 real_allocation.width, real_allocation.height,
4827 min_width, min_height);
4828 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4829 * allocated sizes and possibly limit them to the natural sizes */
4830 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4831 GTK_ORIENTATION_HORIZONTAL,
4834 &adjusted_allocation.x,
4835 &adjusted_allocation.width);
4836 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4837 GTK_ORIENTATION_VERTICAL,
4840 &adjusted_allocation.y,
4841 &adjusted_allocation.height);
4843 if (adjusted_allocation.x < real_allocation.x ||
4844 adjusted_allocation.y < real_allocation.y ||
4845 (adjusted_allocation.x + adjusted_allocation.width) >
4846 (real_allocation.x + real_allocation.width) ||
4847 (adjusted_allocation.y + adjusted_allocation.height >
4848 real_allocation.y + real_allocation.height))
4850 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",
4851 G_OBJECT_TYPE_NAME (widget), widget,
4852 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4853 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4854 adjusted_allocation = real_allocation; /* veto it */
4858 real_allocation = adjusted_allocation;
4861 if (real_allocation.width < 0 || real_allocation.height < 0)
4863 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4864 real_allocation.width,
4865 real_allocation.height);
4868 real_allocation.width = MAX (real_allocation.width, 1);
4869 real_allocation.height = MAX (real_allocation.height, 1);
4871 size_changed = (old_allocation.width != real_allocation.width ||
4872 old_allocation.height != real_allocation.height);
4873 position_changed = (old_allocation.x != real_allocation.x ||
4874 old_allocation.y != real_allocation.y);
4876 if (!alloc_needed && !size_changed && !position_changed)
4879 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4881 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4882 priv->width_request_needed = FALSE;
4883 priv->height_request_needed = FALSE;
4884 priv->alloc_needed = FALSE;
4886 if (gtk_widget_get_mapped (widget))
4888 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4890 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4892 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4893 cairo_region_union_rectangle (invalidate, &old_allocation);
4895 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4896 cairo_region_destroy (invalidate);
4901 if (priv->redraw_on_alloc)
4903 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4905 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4906 cairo_region_union_rectangle (invalidate, &old_allocation);
4908 gtk_widget_invalidate_widget_windows (widget, invalidate);
4909 cairo_region_destroy (invalidate);
4913 if (size_changed || position_changed)
4915 GtkStyleContext *context;
4917 context = gtk_widget_get_style_context (widget);
4918 _gtk_style_context_invalidate_animation_areas (context);
4922 if ((size_changed || position_changed) && priv->parent &&
4923 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4925 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4926 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4927 cairo_region_destroy (invalidate);
4931 gtk_widget_pop_verify_invariants (widget);
4935 * gtk_widget_common_ancestor:
4936 * @widget_a: a #GtkWidget
4937 * @widget_b: a #GtkWidget
4939 * Find the common ancestor of @widget_a and @widget_b that
4940 * is closest to the two widgets.
4942 * Return value: the closest common ancestor of @widget_a and
4943 * @widget_b or %NULL if @widget_a and @widget_b do not
4944 * share a common ancestor.
4947 gtk_widget_common_ancestor (GtkWidget *widget_a,
4948 GtkWidget *widget_b)
4950 GtkWidget *parent_a;
4951 GtkWidget *parent_b;
4955 parent_a = widget_a;
4956 while (parent_a->priv->parent)
4958 parent_a = parent_a->priv->parent;
4962 parent_b = widget_b;
4963 while (parent_b->priv->parent)
4965 parent_b = parent_b->priv->parent;
4969 if (parent_a != parent_b)
4972 while (depth_a > depth_b)
4974 widget_a = widget_a->priv->parent;
4978 while (depth_b > depth_a)
4980 widget_b = widget_b->priv->parent;
4984 while (widget_a != widget_b)
4986 widget_a = widget_a->priv->parent;
4987 widget_b = widget_b->priv->parent;
4994 * gtk_widget_translate_coordinates:
4995 * @src_widget: a #GtkWidget
4996 * @dest_widget: a #GtkWidget
4997 * @src_x: X position relative to @src_widget
4998 * @src_y: Y position relative to @src_widget
4999 * @dest_x: (out): location to store X position relative to @dest_widget
5000 * @dest_y: (out): location to store Y position relative to @dest_widget
5002 * Translate coordinates relative to @src_widget's allocation to coordinates
5003 * relative to @dest_widget's allocations. In order to perform this
5004 * operation, both widgets must be realized, and must share a common
5007 * Return value: %FALSE if either widget was not realized, or there
5008 * was no common ancestor. In this case, nothing is stored in
5009 * *@dest_x and *@dest_y. Otherwise %TRUE.
5012 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5013 GtkWidget *dest_widget,
5019 GtkWidgetPrivate *src_priv = src_widget->priv;
5020 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5021 GtkWidget *ancestor;
5023 GList *dest_list = NULL;
5025 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5026 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5028 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5029 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5032 /* Translate from allocation relative to window relative */
5033 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5036 gdk_window_get_position (src_priv->window, &wx, &wy);
5038 src_x -= wx - src_priv->allocation.x;
5039 src_y -= wy - src_priv->allocation.y;
5043 src_x += src_priv->allocation.x;
5044 src_y += src_priv->allocation.y;
5047 /* Translate to the common ancestor */
5048 window = src_priv->window;
5049 while (window != ancestor->priv->window)
5053 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5058 window = gdk_window_get_effective_parent (window);
5060 if (!window) /* Handle GtkHandleBox */
5065 window = dest_priv->window;
5066 while (window != ancestor->priv->window)
5068 dest_list = g_list_prepend (dest_list, window);
5070 window = gdk_window_get_effective_parent (window);
5072 if (!window) /* Handle GtkHandleBox */
5074 g_list_free (dest_list);
5083 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5088 dest_list = g_list_remove (dest_list, dest_list->data);
5091 /* Translate from window relative to allocation relative */
5092 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5095 gdk_window_get_position (dest_priv->window, &wx, &wy);
5097 src_x += wx - dest_priv->allocation.x;
5098 src_y += wy - dest_priv->allocation.y;
5102 src_x -= dest_priv->allocation.x;
5103 src_y -= dest_priv->allocation.y;
5115 gtk_widget_real_size_allocate (GtkWidget *widget,
5116 GtkAllocation *allocation)
5118 GtkWidgetPrivate *priv = widget->priv;
5120 priv->allocation = *allocation;
5122 if (gtk_widget_get_realized (widget) &&
5123 gtk_widget_get_has_window (widget))
5125 gdk_window_move_resize (priv->window,
5126 allocation->x, allocation->y,
5127 allocation->width, allocation->height);
5131 /* translate initial/final into start/end */
5133 effective_align (GtkAlign align,
5134 GtkTextDirection direction)
5138 case GTK_ALIGN_START:
5139 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5141 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5148 adjust_for_align (GtkAlign align,
5150 gint *allocated_pos,
5151 gint *allocated_size)
5155 case GTK_ALIGN_FILL:
5156 /* change nothing */
5158 case GTK_ALIGN_START:
5159 /* keep *allocated_pos where it is */
5160 *allocated_size = MIN (*allocated_size, *natural_size);
5163 if (*allocated_size > *natural_size)
5165 *allocated_pos += (*allocated_size - *natural_size);
5166 *allocated_size = *natural_size;
5169 case GTK_ALIGN_CENTER:
5170 if (*allocated_size > *natural_size)
5172 *allocated_pos += (*allocated_size - *natural_size) / 2;
5173 *allocated_size = MIN (*allocated_size, *natural_size);
5180 adjust_for_margin(gint start_margin,
5184 gint *allocated_pos,
5185 gint *allocated_size)
5187 *minimum_size -= (start_margin + end_margin);
5188 *natural_size -= (start_margin + end_margin);
5189 *allocated_pos += start_margin;
5190 *allocated_size -= (start_margin + end_margin);
5194 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5195 GtkOrientation orientation,
5198 gint *allocated_pos,
5199 gint *allocated_size)
5201 const GtkWidgetAuxInfo *aux_info;
5203 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5205 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5207 adjust_for_margin (aux_info->margin.left,
5208 aux_info->margin.right,
5209 minimum_size, natural_size,
5210 allocated_pos, allocated_size);
5211 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5212 natural_size, allocated_pos, allocated_size);
5216 adjust_for_margin (aux_info->margin.top,
5217 aux_info->margin.bottom,
5218 minimum_size, natural_size,
5219 allocated_pos, allocated_size);
5220 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5221 natural_size, allocated_pos, allocated_size);
5226 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5229 GtkWidgetPrivate *priv = widget->priv;
5231 /* widgets must be onscreen for accels to take effect */
5232 return gtk_widget_is_sensitive (widget) &&
5233 gtk_widget_is_drawable (widget) &&
5234 gdk_window_is_viewable (priv->window);
5238 * gtk_widget_can_activate_accel:
5239 * @widget: a #GtkWidget
5240 * @signal_id: the ID of a signal installed on @widget
5242 * Determines whether an accelerator that activates the signal
5243 * identified by @signal_id can currently be activated.
5244 * This is done by emitting the #GtkWidget::can-activate-accel
5245 * signal on @widget; if the signal isn't overridden by a
5246 * handler or in a derived widget, then the default check is
5247 * that the widget must be sensitive, and the widget and all
5248 * its ancestors mapped.
5250 * Return value: %TRUE if the accelerator can be activated.
5255 gtk_widget_can_activate_accel (GtkWidget *widget,
5258 gboolean can_activate = FALSE;
5259 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5260 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5261 return can_activate;
5270 closure_accel_activate (GClosure *closure,
5271 GValue *return_value,
5272 guint n_param_values,
5273 const GValue *param_values,
5274 gpointer invocation_hint,
5275 gpointer marshal_data)
5277 AccelClosure *aclosure = (AccelClosure*) closure;
5278 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5281 g_signal_emit (closure->data, aclosure->signal_id, 0);
5283 /* whether accelerator was handled */
5284 g_value_set_boolean (return_value, can_activate);
5288 closures_destroy (gpointer data)
5290 GSList *slist, *closures = data;
5292 for (slist = closures; slist; slist = slist->next)
5294 g_closure_invalidate (slist->data);
5295 g_closure_unref (slist->data);
5297 g_slist_free (closures);
5301 widget_new_accel_closure (GtkWidget *widget,
5304 AccelClosure *aclosure;
5305 GClosure *closure = NULL;
5306 GSList *slist, *closures;
5308 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5309 for (slist = closures; slist; slist = slist->next)
5310 if (!gtk_accel_group_from_accel_closure (slist->data))
5312 /* reuse this closure */
5313 closure = slist->data;
5318 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5319 closures = g_slist_prepend (closures, g_closure_ref (closure));
5320 g_closure_sink (closure);
5321 g_closure_set_marshal (closure, closure_accel_activate);
5323 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5325 aclosure = (AccelClosure*) closure;
5326 g_assert (closure->data == widget);
5327 g_assert (closure->marshal == closure_accel_activate);
5328 aclosure->signal_id = signal_id;
5334 * gtk_widget_add_accelerator
5335 * @widget: widget to install an accelerator on
5336 * @accel_signal: widget signal to emit on accelerator activation
5337 * @accel_group: accel group for this widget, added to its toplevel
5338 * @accel_key: GDK keyval of the accelerator
5339 * @accel_mods: modifier key combination of the accelerator
5340 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5342 * Installs an accelerator for this @widget in @accel_group that causes
5343 * @accel_signal to be emitted if the accelerator is activated.
5344 * The @accel_group needs to be added to the widget's toplevel via
5345 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5346 * Accelerators added through this function are not user changeable during
5347 * runtime. If you want to support accelerators that can be changed by the
5348 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5349 * gtk_menu_item_set_accel_path() instead.
5352 gtk_widget_add_accelerator (GtkWidget *widget,
5353 const gchar *accel_signal,
5354 GtkAccelGroup *accel_group,
5356 GdkModifierType accel_mods,
5357 GtkAccelFlags accel_flags)
5362 g_return_if_fail (GTK_IS_WIDGET (widget));
5363 g_return_if_fail (accel_signal != NULL);
5364 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5366 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5367 if (!query.signal_id ||
5368 !(query.signal_flags & G_SIGNAL_ACTION) ||
5369 query.return_type != G_TYPE_NONE ||
5372 /* hmm, should be elaborate enough */
5373 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5374 G_OBJECT_TYPE_NAME (widget), accel_signal);
5378 closure = widget_new_accel_closure (widget, query.signal_id);
5380 g_object_ref (widget);
5382 /* install the accelerator. since we don't map this onto an accel_path,
5383 * the accelerator will automatically be locked.
5385 gtk_accel_group_connect (accel_group,
5388 accel_flags | GTK_ACCEL_LOCKED,
5391 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5393 g_object_unref (widget);
5397 * gtk_widget_remove_accelerator:
5398 * @widget: widget to install an accelerator on
5399 * @accel_group: accel group for this widget
5400 * @accel_key: GDK keyval of the accelerator
5401 * @accel_mods: modifier key combination of the accelerator
5402 * @returns: whether an accelerator was installed and could be removed
5404 * Removes an accelerator from @widget, previously installed with
5405 * gtk_widget_add_accelerator().
5408 gtk_widget_remove_accelerator (GtkWidget *widget,
5409 GtkAccelGroup *accel_group,
5411 GdkModifierType accel_mods)
5413 GtkAccelGroupEntry *ag_entry;
5414 GList *slist, *clist;
5417 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5418 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5420 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5421 clist = gtk_widget_list_accel_closures (widget);
5422 for (slist = clist; slist; slist = slist->next)
5426 for (i = 0; i < n; i++)
5427 if (slist->data == (gpointer) ag_entry[i].closure)
5429 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5431 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5433 g_list_free (clist);
5438 g_list_free (clist);
5440 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5441 accel_key, accel_mods, accel_group,
5442 G_OBJECT_TYPE_NAME (widget), widget);
5448 * gtk_widget_list_accel_closures:
5449 * @widget: widget to list accelerator closures for
5451 * Lists the closures used by @widget for accelerator group connections
5452 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5453 * The closures can be used to monitor accelerator changes on @widget,
5454 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5455 * #GtkAccelGroup of a closure which can be found out with
5456 * gtk_accel_group_from_accel_closure().
5458 * Return value: (transfer container) (element-type GClosure):
5459 * a newly allocated #GList of closures
5462 gtk_widget_list_accel_closures (GtkWidget *widget)
5465 GList *clist = NULL;
5467 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5469 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5470 if (gtk_accel_group_from_accel_closure (slist->data))
5471 clist = g_list_prepend (clist, slist->data);
5477 GtkAccelGroup *accel_group;
5482 destroy_accel_path (gpointer data)
5484 AccelPath *apath = data;
5486 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5488 /* closures_destroy takes care of unrefing the closure */
5489 g_object_unref (apath->accel_group);
5491 g_slice_free (AccelPath, apath);
5496 * gtk_widget_set_accel_path:
5497 * @widget: a #GtkWidget
5498 * @accel_path: (allow-none): path used to look up the accelerator
5499 * @accel_group: (allow-none): a #GtkAccelGroup.
5501 * Given an accelerator group, @accel_group, and an accelerator path,
5502 * @accel_path, sets up an accelerator in @accel_group so whenever the
5503 * key binding that is defined for @accel_path is pressed, @widget
5504 * will be activated. This removes any accelerators (for any
5505 * accelerator group) installed by previous calls to
5506 * gtk_widget_set_accel_path(). Associating accelerators with
5507 * paths allows them to be modified by the user and the modifications
5508 * to be saved for future use. (See gtk_accel_map_save().)
5510 * This function is a low level function that would most likely
5511 * be used by a menu creation system like #GtkUIManager. If you
5512 * use #GtkUIManager, setting up accelerator paths will be done
5515 * Even when you you aren't using #GtkUIManager, if you only want to
5516 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5517 * provides a somewhat more convenient interface.
5519 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5520 * pass a static string, you can save some memory by interning it first with
5521 * g_intern_static_string().
5524 gtk_widget_set_accel_path (GtkWidget *widget,
5525 const gchar *accel_path,
5526 GtkAccelGroup *accel_group)
5530 g_return_if_fail (GTK_IS_WIDGET (widget));
5531 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5535 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5536 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5538 gtk_accel_map_add_entry (accel_path, 0, 0);
5539 apath = g_slice_new (AccelPath);
5540 apath->accel_group = g_object_ref (accel_group);
5541 apath->path_quark = g_quark_from_string (accel_path);
5542 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5547 /* also removes possible old settings */
5548 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5551 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5553 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5557 _gtk_widget_get_accel_path (GtkWidget *widget,
5562 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5564 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5566 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5567 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5571 * gtk_widget_mnemonic_activate:
5572 * @widget: a #GtkWidget
5573 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5575 * Emits the #GtkWidget::mnemonic-activate signal.
5577 * The default handler for this signal activates the @widget if
5578 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5581 * Returns: %TRUE if the signal has been handled
5584 gtk_widget_mnemonic_activate (GtkWidget *widget,
5585 gboolean group_cycling)
5589 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5591 group_cycling = group_cycling != FALSE;
5592 if (!gtk_widget_is_sensitive (widget))
5595 g_signal_emit (widget,
5596 widget_signals[MNEMONIC_ACTIVATE],
5604 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5605 gboolean group_cycling)
5607 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5608 gtk_widget_activate (widget);
5609 else if (gtk_widget_get_can_focus (widget))
5610 gtk_widget_grab_focus (widget);
5613 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5614 G_OBJECT_TYPE_NAME (widget));
5615 gtk_widget_error_bell (widget);
5620 static const cairo_user_data_key_t event_key;
5623 _gtk_cairo_get_event (cairo_t *cr)
5625 g_return_val_if_fail (cr != NULL, NULL);
5627 return cairo_get_user_data (cr, &event_key);
5631 gtk_cairo_set_event (cairo_t *cr,
5632 GdkEventExpose *event)
5634 cairo_set_user_data (cr, &event_key, event, NULL);
5638 * gtk_cairo_should_draw_window:
5639 * @cr: a cairo context
5640 * @window: the window to check. @window may not be an input-only
5643 * This function is supposed to be called in #GtkWidget::draw
5644 * implementations for widgets that support multiple windows.
5645 * @cr must be untransformed from invoking of the draw function.
5646 * This function will return %TRUE if the contents of the given
5647 * @window are supposed to be drawn and %FALSE otherwise. Note
5648 * that when the drawing was not initiated by the windowing
5649 * system this function will return %TRUE for all windows, so
5650 * you need to draw the bottommost window first. Also, do not
5651 * use "else if" statements to check which window should be drawn.
5653 * Returns: %TRUE if @window should be drawn
5658 gtk_cairo_should_draw_window (cairo_t *cr,
5661 GdkEventExpose *event;
5663 g_return_val_if_fail (cr != NULL, FALSE);
5664 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5666 event = _gtk_cairo_get_event (cr);
5668 return event == NULL ||
5669 event->window == window;
5673 gtk_widget_get_clip_draw (GtkWidget *widget)
5675 /* labels are not clipped, because clipping them would cause
5676 * mnemonics to not appear on characters that go beyond the
5678 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
5680 if (GTK_IS_LABEL (widget))
5686 /* code shared by gtk_container_propagate_draw() and
5690 _gtk_widget_draw_internal (GtkWidget *widget,
5692 gboolean clip_to_size)
5694 GtkStyleContext *context;
5696 if (!gtk_widget_is_drawable (widget))
5699 clip_to_size &= gtk_widget_get_clip_draw (widget);
5703 cairo_rectangle (cr,
5705 widget->priv->allocation.width,
5706 widget->priv->allocation.height);
5710 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5714 g_signal_emit (widget, widget_signals[DRAW],
5719 context = gtk_widget_get_style_context (widget);
5720 _gtk_style_context_coalesce_animation_areas (context, widget);
5725 * @widget: the widget to draw. It must be drawable (see
5726 * gtk_widget_is_drawable()) and a size must have been allocated.
5727 * @cr: a cairo context to draw to
5729 * Draws @widget to @cr. The top left corner of the widget will be
5730 * drawn to the currently set origin point of @cr.
5732 * You should pass a cairo context as @cr argument that is in an
5733 * original state. Otherwise the resulting drawing is undefined. For
5734 * example changing the operator using cairo_set_operator() or the
5735 * line width using cairo_set_line_width() might have unwanted side
5737 * You may however change the context's transform matrix - like with
5738 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5739 * region with cairo_clip() prior to calling this function. Also, it
5740 * is fine to modify the context with cairo_save() and
5741 * cairo_push_group() prior to calling this function.
5743 * <note><para>Special purpose widgets may contain special code for
5744 * rendering to the screen and might appear differently on screen
5745 * and when rendered using gtk_widget_draw().</para></note>
5750 gtk_widget_draw (GtkWidget *widget,
5753 GdkEventExpose *tmp_event;
5755 g_return_if_fail (GTK_IS_WIDGET (widget));
5756 g_return_if_fail (!widget->priv->alloc_needed);
5757 g_return_if_fail (cr != NULL);
5760 /* We have to reset the event here so that draw functions can call
5761 * gtk_widget_draw() on random other widgets and get the desired
5762 * effect: Drawing all contents, not just the current window.
5764 tmp_event = _gtk_cairo_get_event (cr);
5765 gtk_cairo_set_event (cr, NULL);
5767 _gtk_widget_draw_internal (widget, cr, TRUE);
5769 gtk_cairo_set_event (cr, tmp_event);
5774 gtk_widget_real_key_press_event (GtkWidget *widget,
5777 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5781 gtk_widget_real_key_release_event (GtkWidget *widget,
5784 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5788 gtk_widget_real_focus_in_event (GtkWidget *widget,
5789 GdkEventFocus *event)
5791 gtk_widget_queue_shallow_draw (widget);
5797 gtk_widget_real_focus_out_event (GtkWidget *widget,
5798 GdkEventFocus *event)
5800 gtk_widget_queue_shallow_draw (widget);
5805 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5806 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5810 * @widget: a #GtkWidget
5811 * @event: a #GdkEvent
5813 * Rarely-used function. This function is used to emit
5814 * the event signals on a widget (those signals should never
5815 * be emitted without using this function to do so).
5816 * If you want to synthesize an event though, don't use this function;
5817 * instead, use gtk_main_do_event() so the event will behave as if
5818 * it were in the event queue. Don't synthesize expose events; instead,
5819 * use gdk_window_invalidate_rect() to invalidate a region of the
5822 * Return value: return from the event signal emission (%TRUE if
5823 * the event was handled)
5826 gtk_widget_event (GtkWidget *widget,
5829 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5830 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5832 if (event->type == GDK_EXPOSE)
5834 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5835 "the same effect, call gdk_window_invalidate_rect/region(), "
5836 "followed by gdk_window_process_updates().");
5840 return gtk_widget_event_internal (widget, event);
5843 /* Returns TRUE if a translation should be done */
5845 _gtk_widget_get_translation_to_window (GtkWidget *widget,
5850 GdkWindow *w, *widget_window;
5852 if (!gtk_widget_get_has_window (widget))
5854 *x = -widget->priv->allocation.x;
5855 *y = -widget->priv->allocation.y;
5863 widget_window = gtk_widget_get_window (widget);
5865 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5868 gdk_window_get_position (w, &wx, &wy);
5885 * gtk_cairo_transform_to_window:
5886 * @cr: the cairo context to transform
5887 * @widget: the widget the context is currently centered for
5888 * @window: the window to transform the context to
5890 * Transforms the given cairo context @cr that from @widget-relative
5891 * coordinates to @window-relative coordinates.
5892 * If the @widget's window is not an ancestor of @window, no
5893 * modification will be applied.
5895 * This is the inverse to the transformation GTK applies when
5896 * preparing an expose event to be emitted with the #GtkWidget::draw
5897 * signal. It is intended to help porting multiwindow widgets from
5898 * GTK+ 2 to the rendering architecture of GTK+ 3.
5903 gtk_cairo_transform_to_window (cairo_t *cr,
5909 g_return_if_fail (cr != NULL);
5910 g_return_if_fail (GTK_IS_WIDGET (widget));
5911 g_return_if_fail (GDK_IS_WINDOW (window));
5913 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
5914 cairo_translate (cr, x, y);
5918 * gtk_widget_send_expose:
5919 * @widget: a #GtkWidget
5920 * @event: a expose #GdkEvent
5922 * Very rarely-used function. This function is used to emit
5923 * an expose event on a widget. This function is not normally used
5924 * directly. The only time it is used is when propagating an expose
5925 * event to a child %NO_WINDOW widget, and that is normally done
5926 * using gtk_container_propagate_draw().
5928 * If you want to force an area of a window to be redrawn,
5929 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5930 * To cause the redraw to be done immediately, follow that call
5931 * with a call to gdk_window_process_updates().
5933 * Return value: return from the event signal emission (%TRUE if
5934 * the event was handled)
5937 gtk_widget_send_expose (GtkWidget *widget,
5940 gboolean result = FALSE;
5945 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5946 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5947 g_return_val_if_fail (event != NULL, TRUE);
5948 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5950 cr = gdk_cairo_create (event->expose.window);
5951 gtk_cairo_set_event (cr, &event->expose);
5953 gdk_cairo_region (cr, event->expose.region);
5956 do_clip = _gtk_widget_get_translation_to_window (widget,
5957 event->expose.window,
5959 cairo_translate (cr, -x, -y);
5961 _gtk_widget_draw_internal (widget, cr, do_clip);
5963 /* unset here, so if someone keeps a reference to cr we
5964 * don't leak the window. */
5965 gtk_cairo_set_event (cr, NULL);
5972 event_window_is_still_viewable (GdkEvent *event)
5974 /* Check that we think the event's window is viewable before
5975 * delivering the event, to prevent suprises. We do this here
5976 * at the last moment, since the event may have been queued
5977 * up behind other events, held over a recursive main loop, etc.
5979 switch (event->type)
5982 case GDK_MOTION_NOTIFY:
5983 case GDK_BUTTON_PRESS:
5984 case GDK_2BUTTON_PRESS:
5985 case GDK_3BUTTON_PRESS:
5987 case GDK_ENTER_NOTIFY:
5988 case GDK_PROXIMITY_IN:
5990 return event->any.window && gdk_window_is_viewable (event->any.window);
5993 /* The following events are the second half of paired events;
5994 * we always deliver them to deal with widgets that clean up
5995 * on the second half.
5997 case GDK_BUTTON_RELEASE:
5998 case GDK_KEY_RELEASE:
5999 case GDK_LEAVE_NOTIFY:
6000 case GDK_PROXIMITY_OUT:
6004 /* Remaining events would make sense on an not-viewable window,
6005 * or don't have an associated window.
6012 gtk_widget_event_internal (GtkWidget *widget,
6015 gboolean return_val = FALSE;
6017 /* We check only once for is-still-visible; if someone
6018 * hides the window in on of the signals on the widget,
6019 * they are responsible for returning TRUE to terminate
6022 if (!event_window_is_still_viewable (event))
6025 g_object_ref (widget);
6027 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6028 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6033 switch (event->type)
6039 case GDK_BUTTON_PRESS:
6040 case GDK_2BUTTON_PRESS:
6041 case GDK_3BUTTON_PRESS:
6042 signal_num = BUTTON_PRESS_EVENT;
6045 signal_num = SCROLL_EVENT;
6047 case GDK_BUTTON_RELEASE:
6048 signal_num = BUTTON_RELEASE_EVENT;
6050 case GDK_MOTION_NOTIFY:
6051 signal_num = MOTION_NOTIFY_EVENT;
6054 signal_num = DELETE_EVENT;
6057 signal_num = DESTROY_EVENT;
6058 _gtk_tooltip_hide (widget);
6061 signal_num = KEY_PRESS_EVENT;
6063 case GDK_KEY_RELEASE:
6064 signal_num = KEY_RELEASE_EVENT;
6066 case GDK_ENTER_NOTIFY:
6067 signal_num = ENTER_NOTIFY_EVENT;
6069 case GDK_LEAVE_NOTIFY:
6070 signal_num = LEAVE_NOTIFY_EVENT;
6072 case GDK_FOCUS_CHANGE:
6073 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6074 if (event->focus_change.in)
6075 _gtk_tooltip_focus_in (widget);
6077 _gtk_tooltip_focus_out (widget);
6080 signal_num = CONFIGURE_EVENT;
6083 signal_num = MAP_EVENT;
6086 signal_num = UNMAP_EVENT;
6088 case GDK_WINDOW_STATE:
6089 signal_num = WINDOW_STATE_EVENT;
6091 case GDK_PROPERTY_NOTIFY:
6092 signal_num = PROPERTY_NOTIFY_EVENT;
6094 case GDK_SELECTION_CLEAR:
6095 signal_num = SELECTION_CLEAR_EVENT;
6097 case GDK_SELECTION_REQUEST:
6098 signal_num = SELECTION_REQUEST_EVENT;
6100 case GDK_SELECTION_NOTIFY:
6101 signal_num = SELECTION_NOTIFY_EVENT;
6103 case GDK_PROXIMITY_IN:
6104 signal_num = PROXIMITY_IN_EVENT;
6106 case GDK_PROXIMITY_OUT:
6107 signal_num = PROXIMITY_OUT_EVENT;
6109 case GDK_VISIBILITY_NOTIFY:
6110 signal_num = VISIBILITY_NOTIFY_EVENT;
6112 case GDK_GRAB_BROKEN:
6113 signal_num = GRAB_BROKEN_EVENT;
6116 signal_num = DAMAGE_EVENT;
6119 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6123 if (signal_num != -1)
6124 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6126 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6127 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6131 g_object_unref (widget);
6137 * gtk_widget_activate:
6138 * @widget: a #GtkWidget that's activatable
6140 * For widgets that can be "activated" (buttons, menu items, etc.)
6141 * this function activates them. Activation is what happens when you
6142 * press Enter on a widget during key navigation. If @widget isn't
6143 * activatable, the function returns %FALSE.
6145 * Return value: %TRUE if the widget was activatable
6148 gtk_widget_activate (GtkWidget *widget)
6150 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6152 if (WIDGET_CLASS (widget)->activate_signal)
6154 /* FIXME: we should eventually check the signals signature here */
6155 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6164 gtk_widget_reparent_subwindows (GtkWidget *widget,
6165 GdkWindow *new_window)
6167 GtkWidgetPrivate *priv = widget->priv;
6169 if (!gtk_widget_get_has_window (widget))
6171 GList *children = gdk_window_get_children (priv->window);
6174 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6176 GdkWindow *window = tmp_list->data;
6179 gdk_window_get_user_data (window, &child);
6180 while (child && child != widget)
6181 child = ((GtkWidget*) child)->priv->parent;
6184 gdk_window_reparent (window, new_window, 0, 0);
6187 g_list_free (children);
6192 GList *tmp_list, *children;
6194 parent = gdk_window_get_parent (priv->window);
6197 gdk_window_reparent (priv->window, new_window, 0, 0);
6200 children = gdk_window_get_children (parent);
6202 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6204 GdkWindow *window = tmp_list->data;
6207 gdk_window_get_user_data (window, &child);
6209 if (child == widget)
6210 gdk_window_reparent (window, new_window, 0, 0);
6213 g_list_free (children);
6219 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6220 gpointer client_data)
6222 GtkWidgetPrivate *priv = widget->priv;
6224 g_assert (client_data != NULL);
6226 if (!gtk_widget_get_has_window (widget))
6229 g_object_unref (priv->window);
6230 priv->window = (GdkWindow*) client_data;
6232 g_object_ref (priv->window);
6234 if (GTK_IS_CONTAINER (widget))
6235 gtk_container_forall (GTK_CONTAINER (widget),
6236 gtk_widget_reparent_fixup_child,
6242 * gtk_widget_reparent:
6243 * @widget: a #GtkWidget
6244 * @new_parent: a #GtkContainer to move the widget into
6246 * Moves a widget from one #GtkContainer to another, handling reference
6247 * count issues to avoid destroying the widget.
6250 gtk_widget_reparent (GtkWidget *widget,
6251 GtkWidget *new_parent)
6253 GtkWidgetPrivate *priv;
6255 g_return_if_fail (GTK_IS_WIDGET (widget));
6256 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6257 priv = widget->priv;
6258 g_return_if_fail (priv->parent != NULL);
6260 if (priv->parent != new_parent)
6262 /* First try to see if we can get away without unrealizing
6263 * the widget as we reparent it. if so we set a flag so
6264 * that gtk_widget_unparent doesn't unrealize widget
6266 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6267 priv->in_reparent = TRUE;
6269 g_object_ref (widget);
6270 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6271 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6272 g_object_unref (widget);
6274 if (priv->in_reparent)
6276 priv->in_reparent = FALSE;
6278 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6279 gtk_widget_reparent_fixup_child (widget,
6280 gtk_widget_get_parent_window (widget));
6283 g_object_notify (G_OBJECT (widget), "parent");
6288 * gtk_widget_intersect:
6289 * @widget: a #GtkWidget
6290 * @area: a rectangle
6291 * @intersection: rectangle to store intersection of @widget and @area
6293 * Computes the intersection of a @widget's area and @area, storing
6294 * the intersection in @intersection, and returns %TRUE if there was
6295 * an intersection. @intersection may be %NULL if you're only
6296 * interested in whether there was an intersection.
6298 * Return value: %TRUE if there was an intersection
6301 gtk_widget_intersect (GtkWidget *widget,
6302 const GdkRectangle *area,
6303 GdkRectangle *intersection)
6305 GtkWidgetPrivate *priv;
6310 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6311 g_return_val_if_fail (area != NULL, FALSE);
6313 priv = widget->priv;
6316 dest = intersection;
6320 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6322 if (return_val && intersection && gtk_widget_get_has_window (widget))
6324 intersection->x -= priv->allocation.x;
6325 intersection->y -= priv->allocation.y;
6332 * gtk_widget_region_intersect:
6333 * @widget: a #GtkWidget
6334 * @region: a #cairo_region_t, in the same coordinate system as
6335 * @widget->allocation. That is, relative to @widget->window
6336 * for %NO_WINDOW widgets; relative to the parent window
6337 * of @widget->window for widgets with their own window.
6338 * @returns: A newly allocated region holding the intersection of @widget
6339 * and @region. The coordinates of the return value are
6340 * relative to @widget->window for %NO_WINDOW widgets, and
6341 * relative to the parent window of @widget->window for
6342 * widgets with their own window.
6344 * Computes the intersection of a @widget's area and @region, returning
6345 * the intersection. The result may be empty, use cairo_region_is_empty() to
6349 gtk_widget_region_intersect (GtkWidget *widget,
6350 const cairo_region_t *region)
6353 cairo_region_t *dest;
6355 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6356 g_return_val_if_fail (region != NULL, NULL);
6358 gtk_widget_get_allocation (widget, &rect);
6360 dest = cairo_region_create_rectangle (&rect);
6362 cairo_region_intersect (dest, region);
6368 * _gtk_widget_grab_notify:
6369 * @widget: a #GtkWidget
6370 * @was_grabbed: whether a grab is now in effect
6372 * Emits the #GtkWidget::grab-notify signal on @widget.
6377 _gtk_widget_grab_notify (GtkWidget *widget,
6378 gboolean was_grabbed)
6380 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6384 * gtk_widget_grab_focus:
6385 * @widget: a #GtkWidget
6387 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6388 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6389 * something like #GtkFrame won't work.
6391 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6392 * gtk_widget_set_can_focus() to modify that flag.
6394 * The widget also needs to be realized and mapped. This is indicated by the
6395 * related signals. Grabbing the focus immediately after creating the widget
6396 * will likely fail and cause critical warnings.
6399 gtk_widget_grab_focus (GtkWidget *widget)
6401 g_return_if_fail (GTK_IS_WIDGET (widget));
6403 if (!gtk_widget_is_sensitive (widget))
6406 g_object_ref (widget);
6407 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6408 g_object_notify (G_OBJECT (widget), "has-focus");
6409 g_object_unref (widget);
6413 reset_focus_recurse (GtkWidget *widget,
6416 if (GTK_IS_CONTAINER (widget))
6418 GtkContainer *container;
6420 container = GTK_CONTAINER (widget);
6421 gtk_container_set_focus_child (container, NULL);
6423 gtk_container_foreach (container,
6424 reset_focus_recurse,
6430 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6432 if (gtk_widget_get_can_focus (focus_widget))
6434 GtkWidget *toplevel;
6437 /* clear the current focus setting, break if the current widget
6438 * is the focus widget's parent, since containers above that will
6439 * be set by the next loop.
6441 toplevel = gtk_widget_get_toplevel (focus_widget);
6442 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6444 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6446 if (widget == focus_widget)
6448 /* We call _gtk_window_internal_set_focus() here so that the
6449 * toplevel window can request the focus if necessary.
6450 * This is needed when the toplevel is a GtkPlug
6452 if (!gtk_widget_has_focus (widget))
6453 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6460 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
6462 widget = widget->priv->parent;
6463 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6467 else if (toplevel != focus_widget)
6469 /* gtk_widget_grab_focus() operates on a tree without window...
6470 * actually, this is very questionable behaviour.
6473 gtk_container_foreach (GTK_CONTAINER (toplevel),
6474 reset_focus_recurse,
6478 /* now propagate the new focus up the widget tree and finally
6479 * set it on the window
6481 widget = focus_widget;
6482 while (widget->priv->parent)
6484 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6485 widget = widget->priv->parent;
6487 if (GTK_IS_WINDOW (widget))
6488 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6493 gtk_widget_real_query_tooltip (GtkWidget *widget,
6496 gboolean keyboard_tip,
6497 GtkTooltip *tooltip)
6499 gchar *tooltip_markup;
6500 gboolean has_tooltip;
6502 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6503 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6505 if (has_tooltip && tooltip_markup)
6507 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6515 gtk_widget_real_style_updated (GtkWidget *widget)
6517 GtkWidgetPrivate *priv = widget->priv;
6519 gtk_widget_update_pango_context (widget);
6521 if (priv->style != NULL &&
6522 priv->style != gtk_widget_get_default_style ())
6524 /* Trigger ::style-set for old
6525 * widgets not listening to this
6527 g_signal_emit (widget,
6528 widget_signals[STYLE_SET],
6530 widget->priv->style);
6533 if (widget->priv->context)
6535 if (gtk_widget_get_realized (widget) &&
6536 gtk_widget_get_has_window (widget))
6537 gtk_style_context_set_background (widget->priv->context,
6538 widget->priv->window);
6541 if (widget->priv->anchored)
6542 gtk_widget_queue_resize (widget);
6546 gtk_widget_real_show_help (GtkWidget *widget,
6547 GtkWidgetHelpType help_type)
6549 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6551 _gtk_tooltip_toggle_keyboard_mode (widget);
6560 gtk_widget_real_focus (GtkWidget *widget,
6561 GtkDirectionType direction)
6563 if (!gtk_widget_get_can_focus (widget))
6566 if (!gtk_widget_is_focus (widget))
6568 gtk_widget_grab_focus (widget);
6576 gtk_widget_real_move_focus (GtkWidget *widget,
6577 GtkDirectionType direction)
6579 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6581 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6583 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6589 gtk_widget_real_keynav_failed (GtkWidget *widget,
6590 GtkDirectionType direction)
6592 gboolean cursor_only;
6596 case GTK_DIR_TAB_FORWARD:
6597 case GTK_DIR_TAB_BACKWARD:
6604 g_object_get (gtk_widget_get_settings (widget),
6605 "gtk-keynav-cursor-only", &cursor_only,
6612 gtk_widget_error_bell (widget);
6618 * gtk_widget_set_can_focus:
6619 * @widget: a #GtkWidget
6620 * @can_focus: whether or not @widget can own the input focus.
6622 * Specifies whether @widget can own the input focus. See
6623 * gtk_widget_grab_focus() for actually setting the input focus on a
6629 gtk_widget_set_can_focus (GtkWidget *widget,
6632 g_return_if_fail (GTK_IS_WIDGET (widget));
6634 if (widget->priv->can_focus != can_focus)
6636 widget->priv->can_focus = can_focus;
6638 gtk_widget_queue_resize (widget);
6639 g_object_notify (G_OBJECT (widget), "can-focus");
6644 * gtk_widget_get_can_focus:
6645 * @widget: a #GtkWidget
6647 * Determines whether @widget can own the input focus. See
6648 * gtk_widget_set_can_focus().
6650 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6655 gtk_widget_get_can_focus (GtkWidget *widget)
6657 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6659 return widget->priv->can_focus;
6663 * gtk_widget_has_focus:
6664 * @widget: a #GtkWidget
6666 * Determines if the widget has the global input focus. See
6667 * gtk_widget_is_focus() for the difference between having the global
6668 * input focus, and only having the focus within a toplevel.
6670 * Return value: %TRUE if the widget has the global input focus.
6675 gtk_widget_has_focus (GtkWidget *widget)
6677 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6679 return widget->priv->has_focus;
6683 * gtk_widget_is_focus:
6684 * @widget: a #GtkWidget
6686 * Determines if the widget is the focus widget within its
6687 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6688 * necessarily set; %HAS_FOCUS will only be set if the
6689 * toplevel widget additionally has the global input focus.)
6691 * Return value: %TRUE if the widget is the focus widget.
6694 gtk_widget_is_focus (GtkWidget *widget)
6696 GtkWidget *toplevel;
6698 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6700 toplevel = gtk_widget_get_toplevel (widget);
6702 if (GTK_IS_WINDOW (toplevel))
6703 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6709 * gtk_widget_set_can_default:
6710 * @widget: a #GtkWidget
6711 * @can_default: whether or not @widget can be a default widget.
6713 * Specifies whether @widget can be a default widget. See
6714 * gtk_widget_grab_default() for details about the meaning of
6720 gtk_widget_set_can_default (GtkWidget *widget,
6721 gboolean can_default)
6723 g_return_if_fail (GTK_IS_WIDGET (widget));
6725 if (widget->priv->can_default != can_default)
6727 widget->priv->can_default = can_default;
6729 gtk_widget_queue_resize (widget);
6730 g_object_notify (G_OBJECT (widget), "can-default");
6735 * gtk_widget_get_can_default:
6736 * @widget: a #GtkWidget
6738 * Determines whether @widget can be a default widget. See
6739 * gtk_widget_set_can_default().
6741 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6746 gtk_widget_get_can_default (GtkWidget *widget)
6748 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6750 return widget->priv->can_default;
6754 * gtk_widget_has_default:
6755 * @widget: a #GtkWidget
6757 * Determines whether @widget is the current default widget within its
6758 * toplevel. See gtk_widget_set_can_default().
6760 * Return value: %TRUE if @widget is the current default widget within
6761 * its toplevel, %FALSE otherwise
6766 gtk_widget_has_default (GtkWidget *widget)
6768 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6770 return widget->priv->has_default;
6774 _gtk_widget_set_has_default (GtkWidget *widget,
6775 gboolean has_default)
6777 widget->priv->has_default = has_default;
6781 * gtk_widget_grab_default:
6782 * @widget: a #GtkWidget
6784 * Causes @widget to become the default widget. @widget must have the
6785 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6786 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6787 * %TRUE)</literal>. The default widget is activated when
6788 * the user presses Enter in a window. Default widgets must be
6789 * activatable, that is, gtk_widget_activate() should affect them. Note
6790 * that #GtkEntry widgets require the "activates-default" property
6791 * set to %TRUE before they activate the default widget when Enter
6792 * is pressed and the #GtkEntry is focused.
6795 gtk_widget_grab_default (GtkWidget *widget)
6799 g_return_if_fail (GTK_IS_WIDGET (widget));
6800 g_return_if_fail (gtk_widget_get_can_default (widget));
6802 window = gtk_widget_get_toplevel (widget);
6804 if (window && gtk_widget_is_toplevel (window))
6805 gtk_window_set_default (GTK_WINDOW (window), widget);
6807 g_warning (G_STRLOC ": widget not within a GtkWindow");
6811 * gtk_widget_set_receives_default:
6812 * @widget: a #GtkWidget
6813 * @receives_default: whether or not @widget can be a default widget.
6815 * Specifies whether @widget will be treated as the default widget
6816 * within its toplevel when it has the focus, even if another widget
6819 * See gtk_widget_grab_default() for details about the meaning of
6825 gtk_widget_set_receives_default (GtkWidget *widget,
6826 gboolean receives_default)
6828 g_return_if_fail (GTK_IS_WIDGET (widget));
6830 if (widget->priv->receives_default != receives_default)
6832 widget->priv->receives_default = receives_default;
6834 g_object_notify (G_OBJECT (widget), "receives-default");
6839 * gtk_widget_get_receives_default:
6840 * @widget: a #GtkWidget
6842 * Determines whether @widget is alyways treated as default widget
6843 * withing its toplevel when it has the focus, even if another widget
6846 * See gtk_widget_set_receives_default().
6848 * Return value: %TRUE if @widget acts as default widget when focussed,
6854 gtk_widget_get_receives_default (GtkWidget *widget)
6856 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6858 return widget->priv->receives_default;
6862 * gtk_widget_has_grab:
6863 * @widget: a #GtkWidget
6865 * Determines whether the widget is currently grabbing events, so it
6866 * is the only widget receiving input events (keyboard and mouse).
6868 * See also gtk_grab_add().
6870 * Return value: %TRUE if the widget is in the grab_widgets stack
6875 gtk_widget_has_grab (GtkWidget *widget)
6877 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6879 return widget->priv->has_grab;
6883 _gtk_widget_set_has_grab (GtkWidget *widget,
6886 widget->priv->has_grab = has_grab;
6890 * gtk_widget_device_is_shadowed:
6891 * @widget: a #GtkWidget
6892 * @device: a #GdkDevice
6894 * Returns %TRUE if @device has been shadowed by a GTK+
6895 * device grab on another widget, so it would stop sending
6896 * events to @widget. This may be used in the
6897 * #GtkWidget::grab-notify signal to check for specific
6898 * devices. See gtk_device_grab_add().
6900 * Returns: %TRUE if there is an ongoing grab on @device
6901 * by another #GtkWidget than @widget.
6906 gtk_widget_device_is_shadowed (GtkWidget *widget,
6909 GtkWindowGroup *group;
6910 GtkWidget *grab_widget, *toplevel;
6912 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6913 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6915 if (!gtk_widget_get_realized (widget))
6918 toplevel = gtk_widget_get_toplevel (widget);
6920 if (GTK_IS_WINDOW (toplevel))
6921 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6923 group = gtk_window_get_group (NULL);
6925 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6927 /* Widget not inside the hierarchy of grab_widget */
6929 widget != grab_widget &&
6930 !gtk_widget_is_ancestor (widget, grab_widget))
6933 grab_widget = gtk_window_group_get_current_grab (group);
6934 if (grab_widget && widget != grab_widget &&
6935 !gtk_widget_is_ancestor (widget, grab_widget))
6942 * gtk_widget_set_name:
6943 * @widget: a #GtkWidget
6944 * @name: name for the widget
6946 * Widgets can be named, which allows you to refer to them from a
6947 * CSS file. You can apply a style to widgets with a particular name
6948 * in the CSS file. See the documentation for the CSS syntax (on the
6949 * same page as the docs for #GtkStyleContext).
6951 * Note that the CSS syntax has certain special characters to delimit
6952 * and represent elements in a selector (period, #, >, *...),
6953 * so using these will make your widget impossible to match by name.
6954 * Any combination of alphanumeric symbols, dashes and underscores will
6958 gtk_widget_set_name (GtkWidget *widget,
6961 GtkWidgetPrivate *priv;
6964 g_return_if_fail (GTK_IS_WIDGET (widget));
6966 priv = widget->priv;
6968 new_name = g_strdup (name);
6969 g_free (priv->name);
6970 priv->name = new_name;
6972 gtk_widget_reset_style (widget);
6974 g_object_notify (G_OBJECT (widget), "name");
6978 * gtk_widget_get_name:
6979 * @widget: a #GtkWidget
6981 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6982 * significance of widget names.
6984 * Return value: name of the widget. This string is owned by GTK+ and
6985 * should not be modified or freed
6988 gtk_widget_get_name (GtkWidget *widget)
6990 GtkWidgetPrivate *priv;
6992 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6994 priv = widget->priv;
6998 return G_OBJECT_TYPE_NAME (widget);
7002 _gtk_widget_update_state_flags (GtkWidget *widget,
7003 GtkStateFlags flags,
7006 GtkWidgetPrivate *priv;
7008 priv = widget->priv;
7010 /* Handle insensitive first, since it is propagated
7011 * differently throughout the widget hierarchy.
7013 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_UNSET))
7014 gtk_widget_set_sensitive (widget, TRUE);
7015 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation != STATE_CHANGE_UNSET))
7016 gtk_widget_set_sensitive (widget, FALSE);
7017 else if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && !(flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_REPLACE))
7018 gtk_widget_set_sensitive (widget, TRUE);
7020 if (operation != STATE_CHANGE_REPLACE)
7021 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
7024 operation == STATE_CHANGE_REPLACE)
7029 data.operation = operation;
7030 data.use_forall = FALSE;
7032 gtk_widget_propagate_state (widget, &data);
7034 gtk_widget_queue_resize (widget);
7039 * gtk_widget_set_state_flags:
7040 * @widget: a #GtkWidget
7041 * @flags: State flags to turn on
7042 * @clear: Whether to clear state before turning on @flags
7044 * This function is for use in widget implementations. Turns on flag
7045 * values in the current widget state (insensitive, prelighted, etc.).
7047 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7048 * will be propagated down to all non-internal children if @widget is a
7049 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7050 * down to all #GtkContainer children by different means than turning on the
7051 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7052 * gtk_widget_is_sensitive() will make use of these.
7057 gtk_widget_set_state_flags (GtkWidget *widget,
7058 GtkStateFlags flags,
7061 g_return_if_fail (GTK_IS_WIDGET (widget));
7063 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7064 (clear && widget->priv->state_flags == flags))
7068 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7070 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
7074 * gtk_widget_unset_state_flags:
7075 * @widget: a #GtkWidget
7076 * @flags: State flags to turn off
7078 * This function is for use in widget implementations. Turns off flag
7079 * values for the current widget state (insensitive, prelighted, etc.).
7080 * See gtk_widget_set_state_flags().
7085 gtk_widget_unset_state_flags (GtkWidget *widget,
7086 GtkStateFlags flags)
7088 g_return_if_fail (GTK_IS_WIDGET (widget));
7090 if ((widget->priv->state_flags & flags) == 0)
7093 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
7097 * gtk_widget_get_state_flags:
7098 * @widget: a #GtkWidget
7100 * Returns the widget state as a flag set. It is worth mentioning
7101 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7102 * returned, that is, also based on parent insensitivity, even if
7103 * @widget itself is sensitive.
7105 * Returns: The state flags for widget
7110 gtk_widget_get_state_flags (GtkWidget *widget)
7112 GtkStateFlags flags;
7114 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7116 flags = widget->priv->state_flags;
7118 if (gtk_widget_has_focus (widget))
7119 flags |= GTK_STATE_FLAG_FOCUSED;
7125 * gtk_widget_set_state:
7126 * @widget: a #GtkWidget
7127 * @state: new state for @widget
7129 * This function is for use in widget implementations. Sets the state
7130 * of a widget (insensitive, prelighted, etc.) Usually you should set
7131 * the state using wrapper functions such as gtk_widget_set_sensitive().
7133 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7136 gtk_widget_set_state (GtkWidget *widget,
7139 GtkStateFlags flags;
7141 if (state == gtk_widget_get_state (widget))
7146 case GTK_STATE_ACTIVE:
7147 flags = GTK_STATE_FLAG_ACTIVE;
7149 case GTK_STATE_PRELIGHT:
7150 flags = GTK_STATE_FLAG_PRELIGHT;
7152 case GTK_STATE_SELECTED:
7153 flags = GTK_STATE_FLAG_SELECTED;
7155 case GTK_STATE_INSENSITIVE:
7156 flags = GTK_STATE_FLAG_INSENSITIVE;
7158 case GTK_STATE_INCONSISTENT:
7159 flags = GTK_STATE_FLAG_INCONSISTENT;
7161 case GTK_STATE_FOCUSED:
7162 flags = GTK_STATE_FLAG_FOCUSED;
7164 case GTK_STATE_NORMAL:
7170 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7174 * gtk_widget_get_state:
7175 * @widget: a #GtkWidget
7177 * Returns the widget's state. See gtk_widget_set_state().
7179 * Returns: the state of @widget.
7183 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7186 gtk_widget_get_state (GtkWidget *widget)
7188 GtkStateFlags flags;
7190 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7192 flags = gtk_widget_get_state_flags (widget);
7194 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7195 return GTK_STATE_INSENSITIVE;
7196 else if (flags & GTK_STATE_FLAG_ACTIVE)
7197 return GTK_STATE_ACTIVE;
7198 else if (flags & GTK_STATE_FLAG_SELECTED)
7199 return GTK_STATE_SELECTED;
7200 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7201 return GTK_STATE_PRELIGHT;
7203 return GTK_STATE_NORMAL;
7207 * gtk_widget_set_visible:
7208 * @widget: a #GtkWidget
7209 * @visible: whether the widget should be shown or not
7211 * Sets the visibility state of @widget. Note that setting this to
7212 * %TRUE doesn't mean the widget is actually viewable, see
7213 * gtk_widget_get_visible().
7215 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7216 * but is nicer to use when the visibility of the widget depends on
7222 gtk_widget_set_visible (GtkWidget *widget,
7225 g_return_if_fail (GTK_IS_WIDGET (widget));
7227 if (visible != gtk_widget_get_visible (widget))
7230 gtk_widget_show (widget);
7232 gtk_widget_hide (widget);
7237 _gtk_widget_set_visible_flag (GtkWidget *widget,
7240 widget->priv->visible = visible;
7244 * gtk_widget_get_visible:
7245 * @widget: a #GtkWidget
7247 * Determines whether the widget is visible. Note that this doesn't
7248 * take into account whether the widget's parent is also visible
7249 * or the widget is obscured in any way.
7251 * See gtk_widget_set_visible().
7253 * Return value: %TRUE if the widget is visible
7258 gtk_widget_get_visible (GtkWidget *widget)
7260 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7262 return widget->priv->visible;
7266 * gtk_widget_set_has_window:
7267 * @widget: a #GtkWidget
7268 * @has_window: whether or not @widget has a window.
7270 * Specifies whether @widget has a #GdkWindow of its own. Note that
7271 * all realized widgets have a non-%NULL "window" pointer
7272 * (gtk_widget_get_window() never returns a %NULL window when a widget
7273 * is realized), but for many of them it's actually the #GdkWindow of
7274 * one of its parent widgets. Widgets that do not create a %window for
7275 * themselves in #GtkWidget::realize must announce this by
7276 * calling this function with @has_window = %FALSE.
7278 * This function should only be called by widget implementations,
7279 * and they should call it in their init() function.
7284 gtk_widget_set_has_window (GtkWidget *widget,
7285 gboolean has_window)
7287 g_return_if_fail (GTK_IS_WIDGET (widget));
7289 widget->priv->no_window = !has_window;
7293 * gtk_widget_get_has_window:
7294 * @widget: a #GtkWidget
7296 * Determines whether @widget has a #GdkWindow of its own. See
7297 * gtk_widget_set_has_window().
7299 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7304 gtk_widget_get_has_window (GtkWidget *widget)
7306 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7308 return ! widget->priv->no_window;
7312 * gtk_widget_is_toplevel:
7313 * @widget: a #GtkWidget
7315 * Determines whether @widget is a toplevel widget.
7317 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7318 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7321 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7326 gtk_widget_is_toplevel (GtkWidget *widget)
7328 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7330 return widget->priv->toplevel;
7334 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7335 gboolean is_toplevel)
7337 widget->priv->toplevel = is_toplevel;
7341 * gtk_widget_is_drawable:
7342 * @widget: a #GtkWidget
7344 * Determines whether @widget can be drawn to. A widget can be drawn
7345 * to if it is mapped and visible.
7347 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7352 gtk_widget_is_drawable (GtkWidget *widget)
7354 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7356 return (gtk_widget_get_visible (widget) &&
7357 gtk_widget_get_mapped (widget));
7361 * gtk_widget_get_realized:
7362 * @widget: a #GtkWidget
7364 * Determines whether @widget is realized.
7366 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7371 gtk_widget_get_realized (GtkWidget *widget)
7373 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7375 return widget->priv->realized;
7379 * gtk_widget_set_realized:
7380 * @widget: a #GtkWidget
7381 * @realized: %TRUE to mark the widget as realized
7383 * Marks the widget as being realized.
7385 * This function should only ever be called in a derived widget's
7386 * "realize" or "unrealize" implementation.
7391 gtk_widget_set_realized (GtkWidget *widget,
7394 g_return_if_fail (GTK_IS_WIDGET (widget));
7396 widget->priv->realized = realized;
7400 * gtk_widget_get_mapped:
7401 * @widget: a #GtkWidget
7403 * Whether the widget is mapped.
7405 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7410 gtk_widget_get_mapped (GtkWidget *widget)
7412 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7414 return widget->priv->mapped;
7418 * gtk_widget_set_mapped:
7419 * @widget: a #GtkWidget
7420 * @mapped: %TRUE to mark the widget as mapped
7422 * Marks the widget as being realized.
7424 * This function should only ever be called in a derived widget's
7425 * "map" or "unmap" implementation.
7430 gtk_widget_set_mapped (GtkWidget *widget,
7433 g_return_if_fail (GTK_IS_WIDGET (widget));
7435 widget->priv->mapped = mapped;
7439 * gtk_widget_set_app_paintable:
7440 * @widget: a #GtkWidget
7441 * @app_paintable: %TRUE if the application will paint on the widget
7443 * Sets whether the application intends to draw on the widget in
7444 * an #GtkWidget::draw handler.
7446 * This is a hint to the widget and does not affect the behavior of
7447 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7448 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7449 * the effect is to suppress default themed drawing of the widget's
7450 * background. (Children of the widget will still be drawn.) The application
7451 * is then entirely responsible for drawing the widget background.
7453 * Note that the background is still drawn when the widget is mapped.
7456 gtk_widget_set_app_paintable (GtkWidget *widget,
7457 gboolean app_paintable)
7459 g_return_if_fail (GTK_IS_WIDGET (widget));
7461 app_paintable = (app_paintable != FALSE);
7463 if (widget->priv->app_paintable != app_paintable)
7465 widget->priv->app_paintable = app_paintable;
7467 if (gtk_widget_is_drawable (widget))
7468 gtk_widget_queue_draw (widget);
7470 g_object_notify (G_OBJECT (widget), "app-paintable");
7475 * gtk_widget_get_app_paintable:
7476 * @widget: a #GtkWidget
7478 * Determines whether the application intends to draw on the widget in
7479 * an #GtkWidget::draw handler.
7481 * See gtk_widget_set_app_paintable()
7483 * Return value: %TRUE if the widget is app paintable
7488 gtk_widget_get_app_paintable (GtkWidget *widget)
7490 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7492 return widget->priv->app_paintable;
7496 * gtk_widget_set_double_buffered:
7497 * @widget: a #GtkWidget
7498 * @double_buffered: %TRUE to double-buffer a widget
7500 * Widgets are double buffered by default; you can use this function
7501 * to turn off the buffering. "Double buffered" simply means that
7502 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7503 * automatically around expose events sent to the
7504 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7505 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7506 * buffer to the screen. The result is that users see the window
7507 * update in one smooth step, and don't see individual graphics
7508 * primitives being rendered.
7510 * In very simple terms, double buffered widgets don't flicker,
7511 * so you would only use this function to turn off double buffering
7512 * if you had special needs and really knew what you were doing.
7514 * Note: if you turn off double-buffering, you have to handle
7515 * expose events, since even the clearing to the background color or
7516 * pixmap will not happen automatically (as it is done in
7517 * gdk_window_begin_paint()).
7520 gtk_widget_set_double_buffered (GtkWidget *widget,
7521 gboolean double_buffered)
7523 g_return_if_fail (GTK_IS_WIDGET (widget));
7525 double_buffered = (double_buffered != FALSE);
7527 if (widget->priv->double_buffered != double_buffered)
7529 widget->priv->double_buffered = double_buffered;
7531 g_object_notify (G_OBJECT (widget), "double-buffered");
7536 * gtk_widget_get_double_buffered:
7537 * @widget: a #GtkWidget
7539 * Determines whether the widget is double buffered.
7541 * See gtk_widget_set_double_buffered()
7543 * Return value: %TRUE if the widget is double buffered
7548 gtk_widget_get_double_buffered (GtkWidget *widget)
7550 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7552 return widget->priv->double_buffered;
7556 * gtk_widget_set_redraw_on_allocate:
7557 * @widget: a #GtkWidget
7558 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7559 * when it is allocated to a new size. Otherwise, only the
7560 * new portion of the widget will be redrawn.
7562 * Sets whether the entire widget is queued for drawing when its size
7563 * allocation changes. By default, this setting is %TRUE and
7564 * the entire widget is redrawn on every size change. If your widget
7565 * leaves the upper left unchanged when made bigger, turning this
7566 * setting off will improve performance.
7568 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7569 * off all allocation on resizing: the widget will not even redraw if
7570 * its position changes; this is to allow containers that don't draw
7571 * anything to avoid excess invalidations. If you set this flag on a
7572 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7573 * you are responsible for invalidating both the old and new allocation
7574 * of the widget when the widget is moved and responsible for invalidating
7575 * regions newly when the widget increases size.
7578 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7579 gboolean redraw_on_allocate)
7581 g_return_if_fail (GTK_IS_WIDGET (widget));
7583 widget->priv->redraw_on_alloc = redraw_on_allocate;
7587 * gtk_widget_set_sensitive:
7588 * @widget: a #GtkWidget
7589 * @sensitive: %TRUE to make the widget sensitive
7591 * Sets the sensitivity of a widget. A widget is sensitive if the user
7592 * can interact with it. Insensitive widgets are "grayed out" and the
7593 * user can't interact with them. Insensitive widgets are known as
7594 * "inactive", "disabled", or "ghosted" in some other toolkits.
7597 gtk_widget_set_sensitive (GtkWidget *widget,
7600 GtkWidgetPrivate *priv;
7603 g_return_if_fail (GTK_IS_WIDGET (widget));
7605 priv = widget->priv;
7607 sensitive = (sensitive != FALSE);
7609 if (priv->sensitive == sensitive)
7612 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7616 priv->sensitive = TRUE;
7617 data.operation = STATE_CHANGE_UNSET;
7621 priv->sensitive = FALSE;
7622 data.operation = STATE_CHANGE_SET;
7625 data.use_forall = TRUE;
7627 gtk_widget_propagate_state (widget, &data);
7629 gtk_widget_queue_resize (widget);
7631 g_object_notify (G_OBJECT (widget), "sensitive");
7635 * gtk_widget_get_sensitive:
7636 * @widget: a #GtkWidget
7638 * Returns the widget's sensitivity (in the sense of returning
7639 * the value that has been set using gtk_widget_set_sensitive()).
7641 * The effective sensitivity of a widget is however determined by both its
7642 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7644 * Returns: %TRUE if the widget is sensitive
7649 gtk_widget_get_sensitive (GtkWidget *widget)
7651 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7653 return widget->priv->sensitive;
7657 * gtk_widget_is_sensitive:
7658 * @widget: a #GtkWidget
7660 * Returns the widget's effective sensitivity, which means
7661 * it is sensitive itself and also its parent widget is sensitive
7663 * Returns: %TRUE if the widget is effectively sensitive
7668 gtk_widget_is_sensitive (GtkWidget *widget)
7670 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7672 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
7676 _gtk_widget_update_path (GtkWidget *widget)
7678 if (widget->priv->path)
7680 gtk_widget_path_free (widget->priv->path);
7681 widget->priv->path = NULL;
7684 gtk_widget_get_path (widget);
7688 * gtk_widget_set_parent:
7689 * @widget: a #GtkWidget
7690 * @parent: parent container
7692 * This function is useful only when implementing subclasses of
7694 * Sets the container as the parent of @widget, and takes care of
7695 * some details such as updating the state and style of the child
7696 * to reflect its new location. The opposite function is
7697 * gtk_widget_unparent().
7700 gtk_widget_set_parent (GtkWidget *widget,
7703 GtkStateFlags parent_flags;
7704 GtkWidgetPrivate *priv;
7707 g_return_if_fail (GTK_IS_WIDGET (widget));
7708 g_return_if_fail (GTK_IS_WIDGET (parent));
7709 g_return_if_fail (widget != parent);
7711 priv = widget->priv;
7713 if (priv->parent != NULL)
7715 g_warning ("Can't set a parent on widget which has a parent\n");
7718 if (gtk_widget_is_toplevel (widget))
7720 g_warning ("Can't set a parent on a toplevel widget\n");
7724 /* keep this function in sync with gtk_menu_attach_to_widget()
7727 g_object_ref_sink (widget);
7729 gtk_widget_push_verify_invariants (widget);
7731 priv->parent = parent;
7733 parent_flags = gtk_widget_get_state_flags (parent);
7735 /* Merge both old state and current parent state,
7736 * making sure to only propagate the right states */
7737 data.flags = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
7738 data.flags |= priv->state_flags;
7740 data.operation = STATE_CHANGE_REPLACE;
7741 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7742 gtk_widget_propagate_state (widget, &data);
7744 gtk_widget_reset_style (widget);
7746 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7747 if (priv->parent->priv->anchored)
7748 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7749 g_object_notify (G_OBJECT (widget), "parent");
7751 /* Enforce realized/mapped invariants
7753 if (gtk_widget_get_realized (priv->parent))
7754 gtk_widget_realize (widget);
7756 if (gtk_widget_get_visible (priv->parent) &&
7757 gtk_widget_get_visible (widget))
7759 if (gtk_widget_get_child_visible (widget) &&
7760 gtk_widget_get_mapped (priv->parent))
7761 gtk_widget_map (widget);
7763 gtk_widget_queue_resize (widget);
7766 /* child may cause parent's expand to change, if the child is
7767 * expanded. If child is not expanded, then it can't modify the
7768 * parent's expand. If the child becomes expanded later then it will
7769 * queue compute_expand then. This optimization plus defaulting
7770 * newly-constructed widgets to need_compute_expand=FALSE should
7771 * mean that initially building a widget tree doesn't have to keep
7772 * walking up setting need_compute_expand on parents over and over.
7774 * We can't change a parent to need to expand unless we're visible.
7776 if (gtk_widget_get_visible (widget) &&
7777 (priv->need_compute_expand ||
7778 priv->computed_hexpand ||
7779 priv->computed_vexpand))
7781 gtk_widget_queue_compute_expand (parent);
7784 gtk_widget_pop_verify_invariants (widget);
7788 * gtk_widget_get_parent:
7789 * @widget: a #GtkWidget
7791 * Returns the parent container of @widget.
7793 * Return value: (transfer none): the parent container of @widget, or %NULL
7796 gtk_widget_get_parent (GtkWidget *widget)
7798 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7800 return widget->priv->parent;
7803 /*****************************************
7805 * see docs/styles.txt
7806 *****************************************/
7809 * gtk_widget_style_attach:
7810 * @widget: a #GtkWidget
7812 * This function attaches the widget's #GtkStyle to the widget's
7813 * #GdkWindow. It is a replacement for
7816 * widget->style = gtk_style_attach (widget->style, widget->window);
7819 * and should only ever be called in a derived widget's "realize"
7820 * implementation which does not chain up to its parent class'
7821 * "realize" implementation, because one of the parent classes
7822 * (finally #GtkWidget) would attach the style itself.
7826 * Deprecated: 3.0. This step is unnecessary with #GtkStyleContext.
7829 gtk_widget_style_attach (GtkWidget *widget)
7831 g_return_if_fail (GTK_IS_WIDGET (widget));
7832 g_return_if_fail (gtk_widget_get_realized (widget));
7836 * gtk_widget_has_rc_style:
7837 * @widget: a #GtkWidget
7839 * Determines if the widget style has been looked up through the rc mechanism.
7841 * Returns: %TRUE if the widget has been looked up through the rc
7842 * mechanism, %FALSE otherwise.
7846 * Deprecated:3.0: Use #GtkStyleContext instead
7849 gtk_widget_has_rc_style (GtkWidget *widget)
7851 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7853 return widget->priv->rc_style;
7857 * gtk_widget_set_style:
7858 * @widget: a #GtkWidget
7859 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect
7860 * of a previous call to gtk_widget_set_style() and go back to
7863 * Used to set the #GtkStyle for a widget (@widget->style). Since
7864 * GTK 3, this function does nothing, the passed in style is ignored.
7866 * Deprecated:3.0: Use #GtkStyleContext instead
7869 gtk_widget_set_style (GtkWidget *widget,
7872 g_return_if_fail (GTK_IS_WIDGET (widget));
7876 * gtk_widget_ensure_style:
7877 * @widget: a #GtkWidget
7879 * Ensures that @widget has a style (@widget->style).
7881 * Not a very useful function; most of the time, if you
7882 * want the style, the widget is realized, and realized
7883 * widgets are guaranteed to have a style already.
7885 * Deprecated:3.0: Use #GtkStyleContext instead
7888 gtk_widget_ensure_style (GtkWidget *widget)
7890 GtkWidgetPrivate *priv;
7892 g_return_if_fail (GTK_IS_WIDGET (widget));
7894 priv = widget->priv;
7896 if (priv->style == gtk_widget_get_default_style ())
7898 g_object_unref (priv->style);
7902 g_signal_emit (widget,
7903 widget_signals[STYLE_SET],
7909 * gtk_widget_get_style:
7910 * @widget: a #GtkWidget
7912 * Simply an accessor function that returns @widget->style.
7914 * Return value: (transfer none): the widget's #GtkStyle
7916 * Deprecated:3.0: Use #GtkStyleContext instead
7919 gtk_widget_get_style (GtkWidget *widget)
7921 GtkWidgetPrivate *priv;
7923 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7925 priv = widget->priv;
7927 if (priv->style == NULL)
7929 priv->style = g_object_new (GTK_TYPE_STYLE,
7930 "context", gtk_widget_get_style_context (widget),
7939 * gtk_widget_modify_style:
7940 * @widget: a #GtkWidget
7941 * @style: the #GtkRcStyle holding the style modifications
7943 * Modifies style values on the widget.
7945 * Modifications made using this technique take precedence over
7946 * style values set via an RC file, however, they will be overridden
7947 * if a style is explicitely set on the widget using gtk_widget_set_style().
7948 * The #GtkRcStyle structure is designed so each field can either be
7949 * set or unset, so it is possible, using this function, to modify some
7950 * style values and leave the others unchanged.
7952 * Note that modifications made with this function are not cumulative
7953 * with previous calls to gtk_widget_modify_style() or with such
7954 * functions as gtk_widget_modify_fg(). If you wish to retain
7955 * previous values, you must first call gtk_widget_get_modifier_style(),
7956 * make your modifications to the returned style, then call
7957 * gtk_widget_modify_style() with that style. On the other hand,
7958 * if you first call gtk_widget_modify_style(), subsequent calls
7959 * to such functions gtk_widget_modify_fg() will have a cumulative
7960 * effect with the initial modifications.
7962 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7965 gtk_widget_modify_style (GtkWidget *widget,
7968 g_return_if_fail (GTK_IS_WIDGET (widget));
7969 g_return_if_fail (GTK_IS_RC_STYLE (style));
7971 g_object_set_qdata_full (G_OBJECT (widget),
7973 gtk_rc_style_copy (style),
7974 (GDestroyNotify) g_object_unref);
7978 * gtk_widget_get_modifier_style:
7979 * @widget: a #GtkWidget
7981 * Returns the current modifier style for the widget. (As set by
7982 * gtk_widget_modify_style().) If no style has previously set, a new
7983 * #GtkRcStyle will be created with all values unset, and set as the
7984 * modifier style for the widget. If you make changes to this rc
7985 * style, you must call gtk_widget_modify_style(), passing in the
7986 * returned rc style, to make sure that your changes take effect.
7988 * Caution: passing the style back to gtk_widget_modify_style() will
7989 * normally end up destroying it, because gtk_widget_modify_style() copies
7990 * the passed-in style and sets the copy as the new modifier style,
7991 * thus dropping any reference to the old modifier style. Add a reference
7992 * to the modifier style if you want to keep it alive.
7994 * Return value: (transfer none): the modifier style for the widget.
7995 * This rc style is owned by the widget. If you want to keep a
7996 * pointer to value this around, you must add a refcount using
7999 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
8002 gtk_widget_get_modifier_style (GtkWidget *widget)
8004 GtkRcStyle *rc_style;
8006 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8008 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
8012 rc_style = gtk_rc_style_new ();
8013 g_object_set_qdata_full (G_OBJECT (widget),
8016 (GDestroyNotify) g_object_unref);
8023 gtk_widget_modify_color_component (GtkWidget *widget,
8024 GtkRcFlags component,
8026 const GdkColor *color)
8028 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
8035 rc_style->fg[state] = *color;
8038 rc_style->bg[state] = *color;
8041 rc_style->text[state] = *color;
8044 rc_style->base[state] = *color;
8047 g_assert_not_reached();
8050 rc_style->color_flags[state] |= component;
8053 rc_style->color_flags[state] &= ~component;
8055 gtk_widget_modify_style (widget, rc_style);
8059 modifier_style_changed (GtkModifierStyle *style,
8062 GtkStyleContext *context;
8064 context = gtk_widget_get_style_context (widget);
8065 gtk_style_context_invalidate (context);
8068 static GtkModifierStyle *
8069 _gtk_widget_get_modifier_properties (GtkWidget *widget)
8071 GtkModifierStyle *style;
8073 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
8075 if (G_UNLIKELY (!style))
8077 GtkStyleContext *context;
8079 style = _gtk_modifier_style_new ();
8080 g_object_set_qdata_full (G_OBJECT (widget),
8081 quark_modifier_style,
8083 (GDestroyNotify) g_object_unref);
8085 g_signal_connect (style, "changed",
8086 G_CALLBACK (modifier_style_changed), widget);
8088 context = gtk_widget_get_style_context (widget);
8090 gtk_style_context_add_provider (context,
8091 GTK_STYLE_PROVIDER (style),
8092 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
8099 * gtk_widget_override_color:
8100 * @widget: a #GtkWidget
8101 * @state: the state for which to set the color
8102 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8103 * of previous calls to gtk_widget_override_color()
8105 * Sets the color to use for a widget.
8107 * All other style values are left untouched.
8110 * This API is mostly meant as a quick way for applications to
8111 * change a widget appearance. If you are developing a widgets
8112 * library and intend this change to be themeable, it is better
8113 * done by setting meaningful CSS classes and regions in your
8114 * widget/container implementation through gtk_style_context_add_class()
8115 * and gtk_style_context_add_region().
8117 * This way, your widget library can install a #GtkCssProvider
8118 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
8119 * to provide a default styling for those widgets that need so, and
8120 * this theming may fully overridden by the user's theme.
8123 * Note that for complex widgets this may bring in undesired
8124 * results (such as uniform background color everywhere), in
8125 * these cases it is better to fully style such widgets through a
8126 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8133 gtk_widget_override_color (GtkWidget *widget,
8134 GtkStateFlags state,
8135 const GdkRGBA *color)
8137 GtkModifierStyle *style;
8139 g_return_if_fail (GTK_IS_WIDGET (widget));
8141 style = _gtk_widget_get_modifier_properties (widget);
8142 _gtk_modifier_style_set_color (style, state, color);
8146 * gtk_widget_override_background_color:
8147 * @widget: a #GtkWidget
8148 * @state: the state for which to set the background color
8149 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8150 * of previous calls to gtk_widget_override_background_color()
8152 * Sets the background color to use for a widget.
8154 * All other style values are left untouched.
8155 * See gtk_widget_override_color().
8160 gtk_widget_override_background_color (GtkWidget *widget,
8161 GtkStateFlags state,
8162 const GdkRGBA *color)
8164 GtkModifierStyle *style;
8166 g_return_if_fail (GTK_IS_WIDGET (widget));
8168 style = _gtk_widget_get_modifier_properties (widget);
8169 _gtk_modifier_style_set_background_color (style, state, color);
8173 * gtk_widget_override_font:
8174 * @widget: a #GtkWidget
8175 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
8176 * the effect of previous calls to gtk_widget_override_font()
8178 * Sets the font to use for a widget. All other style values are
8179 * left untouched. See gtk_widget_override_color().
8184 gtk_widget_override_font (GtkWidget *widget,
8185 const PangoFontDescription *font_desc)
8187 GtkModifierStyle *style;
8189 g_return_if_fail (GTK_IS_WIDGET (widget));
8191 style = _gtk_widget_get_modifier_properties (widget);
8192 _gtk_modifier_style_set_font (style, font_desc);
8196 * gtk_widget_override_symbolic_color:
8197 * @widget: a #GtkWidget
8198 * @name: the name of the symbolic color to modify
8199 * @color: (allow-none): the color to assign (does not need
8200 * to be allocated), or %NULL to undo the effect of previous
8201 * calls to gtk_widget_override_symbolic_color()
8203 * Sets a symbolic color for a widget.
8205 * All other style values are left untouched.
8206 * See gtk_widget_override_color() for overriding the foreground
8207 * or background color.
8212 gtk_widget_override_symbolic_color (GtkWidget *widget,
8214 const GdkRGBA *color)
8216 GtkModifierStyle *style;
8218 g_return_if_fail (GTK_IS_WIDGET (widget));
8220 style = _gtk_widget_get_modifier_properties (widget);
8221 _gtk_modifier_style_map_color (style, name, color);
8225 * gtk_widget_override_cursor:
8226 * @widget: a #GtkWidget
8227 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8228 * allocated), or %NULL to undo the effect of previous calls to
8229 * of gtk_widget_override_cursor().
8230 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8231 * need to be allocated), or %NULL to undo the effect of previous
8232 * calls to of gtk_widget_override_cursor().
8234 * Sets the cursor color to use in a widget, overriding the
8235 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8236 * style properties. All other style values are left untouched.
8237 * See also gtk_widget_modify_style().
8239 * Note that the underlying properties have the #GdkColor type,
8240 * so the alpha value in @primary and @secondary will be ignored.
8245 gtk_widget_override_cursor (GtkWidget *widget,
8246 const GdkRGBA *cursor,
8247 const GdkRGBA *secondary_cursor)
8249 GtkModifierStyle *style;
8251 g_return_if_fail (GTK_IS_WIDGET (widget));
8253 style = _gtk_widget_get_modifier_properties (widget);
8254 _gtk_modifier_style_set_color_property (style,
8256 "cursor-color", cursor);
8257 _gtk_modifier_style_set_color_property (style,
8259 "secondary-cursor-color",
8264 * gtk_widget_modify_fg:
8265 * @widget: a #GtkWidget
8266 * @state: the state for which to set the foreground color
8267 * @color: (allow-none): the color to assign (does not need to be allocated),
8268 * or %NULL to undo the effect of previous calls to
8269 * of gtk_widget_modify_fg().
8271 * Sets the foreground color for a widget in a particular state.
8273 * All other style values are left untouched.
8274 * See also gtk_widget_modify_style().
8276 * Deprecated:3.0: Use gtk_widget_override_color() instead
8279 gtk_widget_modify_fg (GtkWidget *widget,
8281 const GdkColor *color)
8283 GtkStateFlags flags;
8286 g_return_if_fail (GTK_IS_WIDGET (widget));
8287 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8291 case GTK_STATE_ACTIVE:
8292 flags = GTK_STATE_FLAG_ACTIVE;
8294 case GTK_STATE_PRELIGHT:
8295 flags = GTK_STATE_FLAG_PRELIGHT;
8297 case GTK_STATE_SELECTED:
8298 flags = GTK_STATE_FLAG_SELECTED;
8300 case GTK_STATE_INSENSITIVE:
8301 flags = GTK_STATE_FLAG_INSENSITIVE;
8303 case GTK_STATE_NORMAL:
8310 rgba.red = color->red / 65535.;
8311 rgba.green = color->green / 65535.;
8312 rgba.blue = color->blue / 65535.;
8315 gtk_widget_override_color (widget, flags, &rgba);
8318 gtk_widget_override_color (widget, flags, NULL);
8322 * gtk_widget_modify_bg:
8323 * @widget: a #GtkWidget
8324 * @state: the state for which to set the background color
8325 * @color: (allow-none): the color to assign (does not need
8326 * to be allocated), or %NULL to undo the effect of previous
8327 * calls to of gtk_widget_modify_bg().
8329 * Sets the background color for a widget in a particular state.
8331 * All other style values are left untouched.
8332 * See also gtk_widget_modify_style().
8335 * Note that "no window" widgets (which have the %GTK_NO_WINDOW
8336 * flag set) draw on their parent container's window and thus may
8337 * not draw any background themselves. This is the case for e.g.
8340 * To modify the background of such widgets, you have to set the
8341 * background color on their parent; if you want to set the background
8342 * of a rectangular area around a label, try placing the label in
8343 * a #GtkEventBox widget and setting the background color on that.
8346 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8349 gtk_widget_modify_bg (GtkWidget *widget,
8351 const GdkColor *color)
8353 GtkStateFlags flags;
8356 g_return_if_fail (GTK_IS_WIDGET (widget));
8357 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8361 case GTK_STATE_ACTIVE:
8362 flags = GTK_STATE_FLAG_ACTIVE;
8364 case GTK_STATE_PRELIGHT:
8365 flags = GTK_STATE_FLAG_PRELIGHT;
8367 case GTK_STATE_SELECTED:
8368 flags = GTK_STATE_FLAG_SELECTED;
8370 case GTK_STATE_INSENSITIVE:
8371 flags = GTK_STATE_FLAG_INSENSITIVE;
8373 case GTK_STATE_NORMAL:
8380 rgba.red = color->red / 65535.;
8381 rgba.green = color->green / 65535.;
8382 rgba.blue = color->blue / 65535.;
8385 gtk_widget_override_background_color (widget, flags, &rgba);
8388 gtk_widget_override_background_color (widget, flags, NULL);
8392 * gtk_widget_modify_text:
8393 * @widget: a #GtkWidget
8394 * @state: the state for which to set the text color
8395 * @color: (allow-none): the color to assign (does not need to
8396 * be allocated), or %NULL to undo the effect of previous
8397 * calls to of gtk_widget_modify_text().
8399 * Sets the text color for a widget in a particular state.
8401 * All other style values are left untouched.
8402 * The text color is the foreground color used along with the
8403 * base color (see gtk_widget_modify_base()) for widgets such
8404 * as #GtkEntry and #GtkTextView.
8405 * See also gtk_widget_modify_style().
8407 * Deprecated:3.0: Use gtk_widget_override_color() instead
8410 gtk_widget_modify_text (GtkWidget *widget,
8412 const GdkColor *color)
8414 g_return_if_fail (GTK_IS_WIDGET (widget));
8415 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8417 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
8421 * gtk_widget_modify_base:
8422 * @widget: a #GtkWidget
8423 * @state: the state for which to set the base color
8424 * @color: (allow-none): the color to assign (does not need to
8425 * be allocated), or %NULL to undo the effect of previous
8426 * calls to of gtk_widget_modify_base().
8428 * Sets the base color for a widget in a particular state.
8429 * All other style values are left untouched. The base color
8430 * is the background color used along with the text color
8431 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
8432 * and #GtkTextView. See also gtk_widget_modify_style().
8435 * Note that "no window" widgets (which have the %GTK_NO_WINDOW
8436 * flag set) draw on their parent container's window and thus may
8437 * not draw any background themselves. This is the case for e.g.
8440 * To modify the background of such widgets, you have to set the
8441 * base color on their parent; if you want to set the background
8442 * of a rectangular area around a label, try placing the label in
8443 * a #GtkEventBox widget and setting the base color on that.
8446 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8449 gtk_widget_modify_base (GtkWidget *widget,
8451 const GdkColor *color)
8453 g_return_if_fail (GTK_IS_WIDGET (widget));
8454 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8456 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
8460 * gtk_widget_modify_cursor:
8461 * @widget: a #GtkWidget
8462 * @primary: the color to use for primary cursor (does not need to be
8463 * allocated), or %NULL to undo the effect of previous calls to
8464 * of gtk_widget_modify_cursor().
8465 * @secondary: the color to use for secondary cursor (does not need to be
8466 * allocated), or %NULL to undo the effect of previous calls to
8467 * of gtk_widget_modify_cursor().
8469 * Sets the cursor color to use in a widget, overriding the
8470 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8473 * All other style values are left untouched.
8474 * See also gtk_widget_modify_style().
8478 * Deprecated: 3.0. Use gtk_widget_override_cursor() instead.
8481 gtk_widget_modify_cursor (GtkWidget *widget,
8482 const GdkColor *primary,
8483 const GdkColor *secondary)
8485 GdkRGBA primary_rgba, secondary_rgba;
8487 g_return_if_fail (GTK_IS_WIDGET (widget));
8489 primary_rgba.red = primary->red / 65535.;
8490 primary_rgba.green = primary->green / 65535.;
8491 primary_rgba.blue = primary->blue / 65535.;
8492 primary_rgba.alpha = 1;
8494 secondary_rgba.red = secondary->red / 65535.;
8495 secondary_rgba.green = secondary->green / 65535.;
8496 secondary_rgba.blue = secondary->blue / 65535.;
8497 secondary_rgba.alpha = 1;
8499 gtk_widget_override_cursor (widget, &primary_rgba, &secondary_rgba);
8503 * gtk_widget_modify_font:
8504 * @widget: a #GtkWidget
8505 * @font_desc: (allow-none): the font description to use, or %NULL
8506 * to undo the effect of previous calls to gtk_widget_modify_font()
8508 * Sets the font to use for a widget.
8510 * All other style values are left untouched.
8511 * See also gtk_widget_modify_style().
8513 * Deprecated:3.0: Use gtk_widget_override_font() instead
8516 gtk_widget_modify_font (GtkWidget *widget,
8517 PangoFontDescription *font_desc)
8519 g_return_if_fail (GTK_IS_WIDGET (widget));
8521 gtk_widget_override_font (widget, font_desc);
8525 gtk_widget_real_direction_changed (GtkWidget *widget,
8526 GtkTextDirection previous_direction)
8528 gtk_widget_queue_resize (widget);
8532 gtk_widget_real_style_set (GtkWidget *widget,
8533 GtkStyle *previous_style)
8538 GtkWidget *previous_toplevel;
8539 GdkScreen *previous_screen;
8540 GdkScreen *new_screen;
8541 } HierarchyChangedInfo;
8544 do_screen_change (GtkWidget *widget,
8545 GdkScreen *old_screen,
8546 GdkScreen *new_screen)
8548 if (old_screen != new_screen)
8550 GtkWidgetPrivate *priv = widget->priv;
8554 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8556 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8559 _gtk_tooltip_hide (widget);
8561 if (new_screen && priv->context)
8562 gtk_style_context_set_screen (priv->context, new_screen);
8564 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8569 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8570 gpointer client_data)
8572 GtkWidgetPrivate *priv = widget->priv;
8573 HierarchyChangedInfo *info = client_data;
8574 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8575 (priv->parent && priv->parent->priv->anchored);
8577 if (priv->anchored != new_anchored)
8579 g_object_ref (widget);
8581 priv->anchored = new_anchored;
8583 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8584 do_screen_change (widget, info->previous_screen, info->new_screen);
8586 if (GTK_IS_CONTAINER (widget))
8587 gtk_container_forall (GTK_CONTAINER (widget),
8588 gtk_widget_propagate_hierarchy_changed_recurse,
8591 g_object_unref (widget);
8596 * _gtk_widget_propagate_hierarchy_changed:
8597 * @widget: a #GtkWidget
8598 * @previous_toplevel: Previous toplevel
8600 * Propagates changes in the anchored state to a widget and all
8601 * children, unsetting or setting the %ANCHORED flag, and
8602 * emitting #GtkWidget::hierarchy-changed.
8605 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8606 GtkWidget *previous_toplevel)
8608 GtkWidgetPrivate *priv = widget->priv;
8609 HierarchyChangedInfo info;
8611 info.previous_toplevel = previous_toplevel;
8612 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8614 if (gtk_widget_is_toplevel (widget) ||
8615 (priv->parent && priv->parent->priv->anchored))
8616 info.new_screen = gtk_widget_get_screen (widget);
8618 info.new_screen = NULL;
8620 if (info.previous_screen)
8621 g_object_ref (info.previous_screen);
8622 if (previous_toplevel)
8623 g_object_ref (previous_toplevel);
8625 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8627 if (previous_toplevel)
8628 g_object_unref (previous_toplevel);
8629 if (info.previous_screen)
8630 g_object_unref (info.previous_screen);
8634 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8635 gpointer client_data)
8637 HierarchyChangedInfo *info = client_data;
8639 g_object_ref (widget);
8641 do_screen_change (widget, info->previous_screen, info->new_screen);
8643 if (GTK_IS_CONTAINER (widget))
8644 gtk_container_forall (GTK_CONTAINER (widget),
8645 gtk_widget_propagate_screen_changed_recurse,
8648 g_object_unref (widget);
8652 * gtk_widget_is_composited:
8653 * @widget: a #GtkWidget
8655 * Whether @widget can rely on having its alpha channel
8656 * drawn correctly. On X11 this function returns whether a
8657 * compositing manager is running for @widget's screen.
8659 * Please note that the semantics of this call will change
8660 * in the future if used on a widget that has a composited
8661 * window in its hierarchy (as set by gdk_window_set_composited()).
8663 * Return value: %TRUE if the widget can rely on its alpha
8664 * channel being drawn correctly.
8669 gtk_widget_is_composited (GtkWidget *widget)
8673 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8675 screen = gtk_widget_get_screen (widget);
8677 return gdk_screen_is_composited (screen);
8681 propagate_composited_changed (GtkWidget *widget,
8684 if (GTK_IS_CONTAINER (widget))
8686 gtk_container_forall (GTK_CONTAINER (widget),
8687 propagate_composited_changed,
8691 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8695 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8697 propagate_composited_changed (widget, NULL);
8701 * _gtk_widget_propagate_screen_changed:
8702 * @widget: a #GtkWidget
8703 * @previous_screen: Previous screen
8705 * Propagates changes in the screen for a widget to all
8706 * children, emitting #GtkWidget::screen-changed.
8709 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8710 GdkScreen *previous_screen)
8712 HierarchyChangedInfo info;
8714 info.previous_screen = previous_screen;
8715 info.new_screen = gtk_widget_get_screen (widget);
8717 if (previous_screen)
8718 g_object_ref (previous_screen);
8720 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8722 if (previous_screen)
8723 g_object_unref (previous_screen);
8727 reset_style_recurse (GtkWidget *widget, gpointer data)
8729 _gtk_widget_update_path (widget);
8731 if (GTK_IS_CONTAINER (widget))
8732 gtk_container_forall (GTK_CONTAINER (widget),
8733 reset_style_recurse,
8738 * gtk_widget_reset_style:
8739 * @widget: a #GtkWidget
8741 * Updates the style context of @widget and all descendents
8742 * by updating its widget path. #GtkContainer<!-- -->s may want
8743 * to use this on a child when reordering it in a way that a different
8744 * style might apply to it. See also gtk_container_get_path_for_child().
8749 gtk_widget_reset_style (GtkWidget *widget)
8751 g_return_if_fail (GTK_IS_WIDGET (widget));
8753 reset_style_recurse (widget, NULL);
8757 * gtk_widget_reset_rc_styles:
8758 * @widget: a #GtkWidget.
8760 * Reset the styles of @widget and all descendents, so when
8761 * they are looked up again, they get the correct values
8762 * for the currently loaded RC file settings.
8764 * This function is not useful for applications.
8766 * Deprecated:3.0: Use #GtkStyleContext instead, and gtk_widget_reset_style()
8769 gtk_widget_reset_rc_styles (GtkWidget *widget)
8771 g_return_if_fail (GTK_IS_WIDGET (widget));
8773 reset_style_recurse (widget, NULL);
8777 * gtk_widget_get_default_style:
8779 * Returns the default style used by all widgets initially.
8781 * Returns: (transfer none): the default style. This #GtkStyle
8782 * object is owned by GTK+ and should not be modified or freed.
8784 * Deprecated:3.0: Use #GtkStyleContext instead, and
8785 * gtk_css_provider_get_default() to obtain a #GtkStyleProvider
8786 * with the default widget style information.
8789 gtk_widget_get_default_style (void)
8791 if (!gtk_default_style)
8793 gtk_default_style = gtk_style_new ();
8794 g_object_ref (gtk_default_style);
8797 return gtk_default_style;
8800 #ifdef G_ENABLE_DEBUG
8802 /* Verify invariants, see docs/widget_system.txt for notes on much of
8803 * this. Invariants may be temporarily broken while we're in the
8804 * process of updating state, of course, so you can only
8805 * verify_invariants() after a given operation is complete.
8806 * Use push/pop_verify_invariants to help with that.
8809 gtk_widget_verify_invariants (GtkWidget *widget)
8813 if (widget->priv->verifying_invariants_count > 0)
8816 parent = widget->priv->parent;
8818 if (widget->priv->mapped)
8820 /* Mapped implies ... */
8822 if (!widget->priv->realized)
8823 g_warning ("%s %p is mapped but not realized",
8824 G_OBJECT_TYPE_NAME (widget), widget);
8826 if (!widget->priv->visible)
8827 g_warning ("%s %p is mapped but not visible",
8828 G_OBJECT_TYPE_NAME (widget), widget);
8830 if (!widget->priv->toplevel)
8832 if (!widget->priv->child_visible)
8833 g_warning ("%s %p is mapped but not child_visible",
8834 G_OBJECT_TYPE_NAME (widget), widget);
8839 /* Not mapped implies... */
8842 /* This check makes sense for normal toplevels, but for
8843 * something like a toplevel that is embedded within a clutter
8844 * state, mapping may depend on external factors.
8846 if (widget->priv->toplevel)
8848 if (widget->priv->visible)
8849 g_warning ("%s %p toplevel is visible but not mapped",
8850 G_OBJECT_TYPE_NAME (widget), widget);
8855 /* Parent related checks aren't possible if parent has
8856 * verifying_invariants_count > 0 because parent needs to recurse
8857 * children first before the invariants will hold.
8859 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8862 parent->priv->realized)
8864 /* Parent realized implies... */
8867 /* This is in widget_system.txt but appears to fail
8868 * because there's no gtk_container_realize() that
8869 * realizes all children... instead we just lazily
8870 * wait for map to fix things up.
8872 if (!widget->priv->realized)
8873 g_warning ("%s %p is realized but child %s %p is not realized",
8874 G_OBJECT_TYPE_NAME (parent), parent,
8875 G_OBJECT_TYPE_NAME (widget), widget);
8878 else if (!widget->priv->toplevel)
8880 /* No parent or parent not realized on non-toplevel implies... */
8882 if (widget->priv->realized && !widget->priv->in_reparent)
8883 g_warning ("%s %p is not realized but child %s %p is realized",
8884 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8885 G_OBJECT_TYPE_NAME (widget), widget);
8889 parent->priv->mapped &&
8890 widget->priv->visible &&
8891 widget->priv->child_visible)
8893 /* Parent mapped and we are visible implies... */
8895 if (!widget->priv->mapped)
8896 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8897 G_OBJECT_TYPE_NAME (parent), parent,
8898 G_OBJECT_TYPE_NAME (widget), widget);
8900 else if (!widget->priv->toplevel)
8902 /* No parent or parent not mapped on non-toplevel implies... */
8904 if (widget->priv->mapped && !widget->priv->in_reparent)
8905 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8906 G_OBJECT_TYPE_NAME (widget), widget,
8907 widget->priv->visible,
8908 widget->priv->child_visible,
8909 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8910 parent ? parent->priv->mapped : FALSE);
8914 if (!widget->priv->realized)
8916 /* Not realized implies... */
8919 /* widget_system.txt says these hold, but they don't. */
8920 if (widget->priv->resize_pending)
8921 g_warning ("%s %p resize pending but not realized",
8922 G_OBJECT_TYPE_NAME (widget), widget);
8924 if (widget->priv->alloc_needed)
8925 g_warning ("%s %p alloc needed but not realized",
8926 G_OBJECT_TYPE_NAME (widget), widget);
8928 if (widget->priv->width_request_needed)
8929 g_warning ("%s %p width request needed but not realized",
8930 G_OBJECT_TYPE_NAME (widget), widget);
8932 if (widget->priv->height_request_needed)
8933 g_warning ("%s %p height request needed but not realized",
8934 G_OBJECT_TYPE_NAME (widget), widget);
8939 /* The point of this push/pop is that invariants may not hold while
8940 * we're busy making changes. So we only check at the outermost call
8941 * on the call stack, after we finish updating everything.
8944 gtk_widget_push_verify_invariants (GtkWidget *widget)
8946 widget->priv->verifying_invariants_count += 1;
8950 gtk_widget_verify_child_invariants (GtkWidget *widget,
8951 gpointer client_data)
8953 /* We don't recurse further; this is a one-level check. */
8954 gtk_widget_verify_invariants (widget);
8958 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8960 g_assert (widget->priv->verifying_invariants_count > 0);
8962 widget->priv->verifying_invariants_count -= 1;
8964 if (widget->priv->verifying_invariants_count == 0)
8966 gtk_widget_verify_invariants (widget);
8968 if (GTK_IS_CONTAINER (widget))
8970 /* Check one level of children, because our
8971 * push_verify_invariants() will have prevented some of the
8972 * checks. This does not recurse because if recursion is
8973 * needed, it will happen naturally as each child has a
8974 * push/pop on that child. For example if we're recursively
8975 * mapping children, we'll push/pop on each child as we map
8978 gtk_container_forall (GTK_CONTAINER (widget),
8979 gtk_widget_verify_child_invariants,
8984 #endif /* G_ENABLE_DEBUG */
8986 static PangoContext *
8987 gtk_widget_peek_pango_context (GtkWidget *widget)
8989 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8993 * gtk_widget_get_pango_context:
8994 * @widget: a #GtkWidget
8996 * Gets a #PangoContext with the appropriate font map, font description,
8997 * and base direction for this widget. Unlike the context returned
8998 * by gtk_widget_create_pango_context(), this context is owned by
8999 * the widget (it can be used until the screen for the widget changes
9000 * or the widget is removed from its toplevel), and will be updated to
9001 * match any changes to the widget's attributes.
9003 * If you create and keep a #PangoLayout using this context, you must
9004 * deal with changes to the context by calling pango_layout_context_changed()
9005 * on the layout in response to the #GtkWidget::style-updated and
9006 * #GtkWidget::direction-changed signals for the widget.
9008 * Return value: (transfer none): the #PangoContext for the widget.
9011 gtk_widget_get_pango_context (GtkWidget *widget)
9013 PangoContext *context;
9015 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9017 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
9020 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
9021 g_object_set_qdata_full (G_OBJECT (widget),
9022 quark_pango_context,
9031 update_pango_context (GtkWidget *widget,
9032 PangoContext *context)
9034 const PangoFontDescription *font_desc;
9035 GtkStyleContext *style_context;
9037 style_context = gtk_widget_get_style_context (widget);
9039 font_desc = gtk_style_context_get_font (style_context,
9040 gtk_widget_get_state_flags (widget));
9042 pango_context_set_font_description (context, font_desc);
9043 pango_context_set_base_dir (context,
9044 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
9045 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
9049 gtk_widget_update_pango_context (GtkWidget *widget)
9051 PangoContext *context = gtk_widget_peek_pango_context (widget);
9057 update_pango_context (widget, context);
9059 screen = gtk_widget_get_screen_unchecked (widget);
9062 pango_cairo_context_set_resolution (context,
9063 gdk_screen_get_resolution (screen));
9064 pango_cairo_context_set_font_options (context,
9065 gdk_screen_get_font_options (screen));
9071 * gtk_widget_create_pango_context:
9072 * @widget: a #GtkWidget
9074 * Creates a new #PangoContext with the appropriate font map,
9075 * font description, and base direction for drawing text for
9076 * this widget. See also gtk_widget_get_pango_context().
9078 * Return value: (transfer full): the new #PangoContext
9081 gtk_widget_create_pango_context (GtkWidget *widget)
9084 PangoContext *context;
9086 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9088 screen = gtk_widget_get_screen_unchecked (widget);
9091 GTK_NOTE (MULTIHEAD,
9092 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
9094 screen = gdk_screen_get_default ();
9097 context = gdk_pango_context_get_for_screen (screen);
9099 update_pango_context (widget, context);
9100 pango_context_set_language (context, gtk_get_default_language ());
9106 * gtk_widget_create_pango_layout:
9107 * @widget: a #GtkWidget
9108 * @text: text to set on the layout (can be %NULL)
9110 * Creates a new #PangoLayout with the appropriate font map,
9111 * font description, and base direction for drawing text for
9114 * If you keep a #PangoLayout created in this way around, in order to
9115 * notify the layout of changes to the base direction or font of this
9116 * widget, you must call pango_layout_context_changed() in response to
9117 * the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
9120 * Return value: (transfer full): the new #PangoLayout
9123 gtk_widget_create_pango_layout (GtkWidget *widget,
9126 PangoLayout *layout;
9127 PangoContext *context;
9129 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9131 context = gtk_widget_get_pango_context (widget);
9132 layout = pango_layout_new (context);
9135 pango_layout_set_text (layout, text, -1);
9141 * gtk_widget_render_icon_pixbuf:
9142 * @widget: a #GtkWidget
9143 * @stock_id: a stock ID
9144 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
9145 * render at the size of the source and don't scale (if there are
9146 * multiple source sizes, GTK+ picks one of the available sizes).
9148 * A convenience function that uses the theme engine and style
9149 * settings for @widget to look up @stock_id and render it to
9150 * a pixbuf. @stock_id should be a stock icon ID such as
9151 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
9152 * such as #GTK_ICON_SIZE_MENU.
9154 * The pixels in the returned #GdkPixbuf are shared with the rest of
9155 * the application and should not be modified. The pixbuf should be freed
9156 * after use with g_object_unref().
9158 * Return value: (transfer full): a new pixbuf, or %NULL if the
9159 * stock ID wasn't known
9164 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
9165 const gchar *stock_id,
9168 GtkStyleContext *context;
9169 GtkIconSet *icon_set;
9171 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9172 g_return_val_if_fail (stock_id != NULL, NULL);
9173 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
9175 context = gtk_widget_get_style_context (widget);
9176 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
9178 if (icon_set == NULL)
9181 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
9185 * gtk_widget_render_icon:
9186 * @widget: a #GtkWidget
9187 * @stock_id: a stock ID
9188 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
9189 * render at the size of the source and don't scale (if there are
9190 * multiple source sizes, GTK+ picks one of the available sizes).
9191 * @detail: (allow-none): render detail to pass to theme engine
9193 * A convenience function that uses the theme settings for @widget
9194 * to look up @stock_id and render it to a pixbuf. @stock_id should
9195 * be a stock icon ID such as #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size
9196 * should be a size such as #GTK_ICON_SIZE_MENU. @detail should be a
9197 * string that identifies the widget or code doing the rendering, so
9198 * that theme engines can special-case rendering for that widget or
9201 * The pixels in the returned #GdkPixbuf are shared with the rest of
9202 * the application and should not be modified. The pixbuf should be
9203 * freed after use with g_object_unref().
9205 * Return value: (transfer full): a new pixbuf, or %NULL if the
9206 * stock ID wasn't known
9208 * Deprecated: 3.0: Use gtk_widget_render_icon_pixbuf() instead.
9211 gtk_widget_render_icon (GtkWidget *widget,
9212 const gchar *stock_id,
9214 const gchar *detail)
9216 gtk_widget_ensure_style (widget);
9218 return gtk_widget_render_icon_pixbuf (widget, stock_id, size);
9222 * gtk_widget_set_parent_window:
9223 * @widget: a #GtkWidget.
9224 * @parent_window: the new parent window.
9226 * Sets a non default parent window for @widget.
9228 * For GtkWindow classes, setting a @parent_window effects whether
9229 * the window is a toplevel window or can be embedded into other
9233 * For GtkWindow classes, this needs to be called before the
9234 * window is realized.
9239 gtk_widget_set_parent_window (GtkWidget *widget,
9240 GdkWindow *parent_window)
9242 GdkWindow *old_parent_window;
9244 g_return_if_fail (GTK_IS_WIDGET (widget));
9246 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
9247 quark_parent_window);
9249 if (parent_window != old_parent_window)
9253 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
9255 if (old_parent_window)
9256 g_object_unref (old_parent_window);
9258 g_object_ref (parent_window);
9260 /* Unset toplevel flag when adding a parent window to a widget,
9261 * this is the primary entry point to allow toplevels to be
9264 #ifdef GDK_WINDOWING_X11
9265 is_plug = GTK_IS_PLUG (widget);
9269 if (GTK_IS_WINDOW (widget) && !is_plug)
9270 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
9275 * gtk_widget_get_parent_window:
9276 * @widget: a #GtkWidget.
9278 * Gets @widget's parent window.
9280 * Returns: (transfer none): the parent window of @widget.
9283 gtk_widget_get_parent_window (GtkWidget *widget)
9285 GtkWidgetPrivate *priv;
9286 GdkWindow *parent_window;
9288 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9290 priv = widget->priv;
9292 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
9294 return (parent_window != NULL) ? parent_window :
9295 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
9300 * gtk_widget_set_child_visible:
9301 * @widget: a #GtkWidget
9302 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
9304 * Sets whether @widget should be mapped along with its when its parent
9305 * is mapped and @widget has been shown with gtk_widget_show().
9307 * The child visibility can be set for widget before it is added to
9308 * a container with gtk_widget_set_parent(), to avoid mapping
9309 * children unnecessary before immediately unmapping them. However
9310 * it will be reset to its default state of %TRUE when the widget
9311 * is removed from a container.
9313 * Note that changing the child visibility of a widget does not
9314 * queue a resize on the widget. Most of the time, the size of
9315 * a widget is computed from all visible children, whether or
9316 * not they are mapped. If this is not the case, the container
9317 * can queue a resize itself.
9319 * This function is only useful for container implementations and
9320 * never should be called by an application.
9323 gtk_widget_set_child_visible (GtkWidget *widget,
9324 gboolean is_visible)
9326 GtkWidgetPrivate *priv;
9328 g_return_if_fail (GTK_IS_WIDGET (widget));
9329 g_return_if_fail (!gtk_widget_is_toplevel (widget));
9331 priv = widget->priv;
9333 g_object_ref (widget);
9334 gtk_widget_verify_invariants (widget);
9337 priv->child_visible = TRUE;
9340 GtkWidget *toplevel;
9342 priv->child_visible = FALSE;
9344 toplevel = gtk_widget_get_toplevel (widget);
9345 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
9346 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
9349 if (priv->parent && gtk_widget_get_realized (priv->parent))
9351 if (gtk_widget_get_mapped (priv->parent) &&
9352 priv->child_visible &&
9353 gtk_widget_get_visible (widget))
9354 gtk_widget_map (widget);
9356 gtk_widget_unmap (widget);
9359 gtk_widget_verify_invariants (widget);
9360 g_object_unref (widget);
9364 * gtk_widget_get_child_visible:
9365 * @widget: a #GtkWidget
9367 * Gets the value set with gtk_widget_set_child_visible().
9368 * If you feel a need to use this function, your code probably
9369 * needs reorganization.
9371 * This function is only useful for container implementations and
9372 * never should be called by an application.
9374 * Return value: %TRUE if the widget is mapped with the parent.
9377 gtk_widget_get_child_visible (GtkWidget *widget)
9379 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9381 return widget->priv->child_visible;
9385 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9387 GtkWidget *toplevel;
9389 toplevel = gtk_widget_get_toplevel (widget);
9391 if (gtk_widget_is_toplevel (toplevel))
9393 if (GTK_IS_WINDOW (toplevel))
9394 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9395 else if (GTK_IS_INVISIBLE (toplevel))
9396 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9403 * gtk_widget_get_screen:
9404 * @widget: a #GtkWidget
9406 * Get the #GdkScreen from the toplevel window associated with
9407 * this widget. This function can only be called after the widget
9408 * has been added to a widget hierarchy with a #GtkWindow
9411 * In general, you should only create screen specific
9412 * resources when a widget has been realized, and you should
9413 * free those resources when the widget is unrealized.
9415 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9420 gtk_widget_get_screen (GtkWidget *widget)
9424 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9426 screen = gtk_widget_get_screen_unchecked (widget);
9433 g_warning (G_STRLOC ": Can't get associated screen"
9434 " for a widget unless it is inside a toplevel GtkWindow\n"
9435 " widget type is %s associated top level type is %s",
9436 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9437 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9439 return gdk_screen_get_default ();
9444 * gtk_widget_has_screen:
9445 * @widget: a #GtkWidget
9447 * Checks whether there is a #GdkScreen is associated with
9448 * this widget. All toplevel widgets have an associated
9449 * screen, and all widgets added into a hierarchy with a toplevel
9450 * window at the top.
9452 * Return value: %TRUE if there is a #GdkScreen associcated
9458 gtk_widget_has_screen (GtkWidget *widget)
9460 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9462 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9466 * gtk_widget_get_display:
9467 * @widget: a #GtkWidget
9469 * Get the #GdkDisplay for the toplevel window associated with
9470 * this widget. This function can only be called after the widget
9471 * has been added to a widget hierarchy with a #GtkWindow at the top.
9473 * In general, you should only create display specific
9474 * resources when a widget has been realized, and you should
9475 * free those resources when the widget is unrealized.
9477 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9482 gtk_widget_get_display (GtkWidget *widget)
9484 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9486 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9490 * gtk_widget_get_root_window:
9491 * @widget: a #GtkWidget
9493 * Get the root window where this widget is located. This function can
9494 * only be called after the widget has been added to a widget
9495 * hierarchy with #GtkWindow at the top.
9497 * The root window is useful for such purposes as creating a popup
9498 * #GdkWindow associated with the window. In general, you should only
9499 * create display specific resources when a widget has been realized,
9500 * and you should free those resources when the widget is unrealized.
9502 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9507 gtk_widget_get_root_window (GtkWidget *widget)
9509 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9511 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9515 * gtk_widget_child_focus:
9516 * @widget: a #GtkWidget
9517 * @direction: direction of focus movement
9519 * This function is used by custom widget implementations; if you're
9520 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9521 * to a particular widget, and gtk_container_set_focus_chain() to
9522 * change the focus tab order. So you may want to investigate those
9523 * functions instead.
9525 * gtk_widget_child_focus() is called by containers as the user moves
9526 * around the window using keyboard shortcuts. @direction indicates
9527 * what kind of motion is taking place (up, down, left, right, tab
9528 * forward, tab backward). gtk_widget_child_focus() emits the
9529 * #GtkWidget::focus signal; widgets override the default handler
9530 * for this signal in order to implement appropriate focus behavior.
9532 * The default ::focus handler for a widget should return %TRUE if
9533 * moving in @direction left the focus on a focusable location inside
9534 * that widget, and %FALSE if moving in @direction moved the focus
9535 * outside the widget. If returning %TRUE, widgets normally
9536 * call gtk_widget_grab_focus() to place the focus accordingly;
9537 * if returning %FALSE, they don't modify the current focus location.
9539 * Return value: %TRUE if focus ended up inside @widget
9542 gtk_widget_child_focus (GtkWidget *widget,
9543 GtkDirectionType direction)
9545 gboolean return_val;
9547 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9549 if (!gtk_widget_get_visible (widget) ||
9550 !gtk_widget_is_sensitive (widget))
9553 /* child widgets must set CAN_FOCUS, containers
9554 * don't have to though.
9556 if (!GTK_IS_CONTAINER (widget) &&
9557 !gtk_widget_get_can_focus (widget))
9560 g_signal_emit (widget,
9561 widget_signals[FOCUS],
9563 direction, &return_val);
9569 * gtk_widget_keynav_failed:
9570 * @widget: a #GtkWidget
9571 * @direction: direction of focus movement
9573 * This function should be called whenever keyboard navigation within
9574 * a single widget hits a boundary. The function emits the
9575 * #GtkWidget::keynav-failed signal on the widget and its return
9576 * value should be interpreted in a way similar to the return value of
9577 * gtk_widget_child_focus():
9579 * When %TRUE is returned, stay in the widget, the failed keyboard
9580 * navigation is Ok and/or there is nowhere we can/should move the
9583 * When %FALSE is returned, the caller should continue with keyboard
9584 * navigation outside the widget, e.g. by calling
9585 * gtk_widget_child_focus() on the widget's toplevel.
9587 * The default ::keynav-failed handler returns %TRUE for
9588 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9589 * values of #GtkDirectionType, it looks at the
9590 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9591 * if the setting is %TRUE. This way the entire user interface
9592 * becomes cursor-navigatable on input devices such as mobile phones
9593 * which only have cursor keys but no tab key.
9595 * Whenever the default handler returns %TRUE, it also calls
9596 * gtk_widget_error_bell() to notify the user of the failed keyboard
9599 * A use case for providing an own implementation of ::keynav-failed
9600 * (either by connecting to it or by overriding it) would be a row of
9601 * #GtkEntry widgets where the user should be able to navigate the
9602 * entire row with the cursor keys, as e.g. known from user interfaces
9603 * that require entering license keys.
9605 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9606 * if the emitting widget should try to handle the keyboard
9607 * navigation attempt in its parent container(s).
9612 gtk_widget_keynav_failed (GtkWidget *widget,
9613 GtkDirectionType direction)
9615 gboolean return_val;
9617 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9619 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9620 direction, &return_val);
9626 * gtk_widget_error_bell:
9627 * @widget: a #GtkWidget
9629 * Notifies the user about an input-related error on this widget.
9630 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9631 * gdk_window_beep(), otherwise it does nothing.
9633 * Note that the effect of gdk_window_beep() can be configured in many
9634 * ways, depending on the windowing backend and the desktop environment
9635 * or window manager that is used.
9640 gtk_widget_error_bell (GtkWidget *widget)
9642 GtkWidgetPrivate *priv;
9643 GtkSettings* settings;
9646 g_return_if_fail (GTK_IS_WIDGET (widget));
9648 priv = widget->priv;
9650 settings = gtk_widget_get_settings (widget);
9654 g_object_get (settings,
9655 "gtk-error-bell", &beep,
9658 if (beep && priv->window)
9659 gdk_window_beep (priv->window);
9663 gtk_widget_set_usize_internal (GtkWidget *widget,
9666 GtkQueueResizeFlags flags)
9668 GtkWidgetAuxInfo *aux_info;
9669 gboolean changed = FALSE;
9671 g_object_freeze_notify (G_OBJECT (widget));
9673 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9675 if (width > -2 && aux_info->width != width)
9677 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9678 g_object_notify (G_OBJECT (widget), "width-request");
9679 aux_info->width = width;
9682 if (height > -2 && aux_info->height != height)
9684 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9685 g_object_notify (G_OBJECT (widget), "height-request");
9686 aux_info->height = height;
9690 if (gtk_widget_get_visible (widget) && changed)
9692 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9693 gtk_widget_queue_resize (widget);
9695 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9698 g_object_thaw_notify (G_OBJECT (widget));
9702 * gtk_widget_set_size_request:
9703 * @widget: a #GtkWidget
9704 * @width: width @widget should request, or -1 to unset
9705 * @height: height @widget should request, or -1 to unset
9707 * Sets the minimum size of a widget; that is, the widget's size
9708 * request will be @width by @height. You can use this function to
9709 * force a widget to be either larger or smaller than it normally
9712 * In most cases, gtk_window_set_default_size() is a better choice for
9713 * toplevel windows than this function; setting the default size will
9714 * still allow users to shrink the window. Setting the size request
9715 * will force them to leave the window at least as large as the size
9716 * request. When dealing with window sizes,
9717 * gtk_window_set_geometry_hints() can be a useful function as well.
9719 * Note the inherent danger of setting any fixed size - themes,
9720 * translations into other languages, different fonts, and user action
9721 * can all change the appropriate size for a given widget. So, it's
9722 * basically impossible to hardcode a size that will always be
9725 * The size request of a widget is the smallest size a widget can
9726 * accept while still functioning well and drawing itself correctly.
9727 * However in some strange cases a widget may be allocated less than
9728 * its requested size, and in many cases a widget may be allocated more
9729 * space than it requested.
9731 * If the size request in a given direction is -1 (unset), then
9732 * the "natural" size request of the widget will be used instead.
9734 * Widgets can't actually be allocated a size less than 1 by 1, but
9735 * you can pass 0,0 to this function to mean "as small as possible."
9737 * The size request set here does not include any margin from the
9738 * #GtkWidget properties margin-left, margin-right, margin-top, and
9739 * margin-bottom, but it does include pretty much all other padding
9740 * or border properties set by any subclass of #GtkWidget.
9743 gtk_widget_set_size_request (GtkWidget *widget,
9747 g_return_if_fail (GTK_IS_WIDGET (widget));
9748 g_return_if_fail (width >= -1);
9749 g_return_if_fail (height >= -1);
9756 gtk_widget_set_usize_internal (widget, width, height, 0);
9761 * gtk_widget_get_size_request:
9762 * @widget: a #GtkWidget
9763 * @width: (out) (allow-none): return location for width, or %NULL
9764 * @height: (out) (allow-none): return location for height, or %NULL
9766 * Gets the size request that was explicitly set for the widget using
9767 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9768 * @height indicates that that dimension has not been set explicitly
9769 * and the natural requisition of the widget will be used intead. See
9770 * gtk_widget_set_size_request(). To get the size a widget will
9771 * actually request, call gtk_widget_get_preferred_size() instead of
9775 gtk_widget_get_size_request (GtkWidget *widget,
9779 const GtkWidgetAuxInfo *aux_info;
9781 g_return_if_fail (GTK_IS_WIDGET (widget));
9783 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9786 *width = aux_info->width;
9789 *height = aux_info->height;
9793 * _gtk_widget_override_size_request:
9794 * @widget: a #GtkWidget
9795 * @width: new forced minimum width
9796 * @height: new forced minimum height
9797 * @old_width: location to store previous forced minimum width
9798 * @old_width: location to store previous forced minumum height
9800 * Temporarily establishes a forced minimum size for a widget; this
9801 * is used by GtkWindow when calculating the size to add to the
9802 * window's geometry widget. Cached sizes for the widget and its
9803 * parents are invalidated, so that subsequent calls to the size
9804 * negotiation machinery produce the overriden result, but the
9805 * widget is not queued for relayout or redraw. The old size must
9806 * be restored with _gtk_widget_restore_size_request() or things
9810 _gtk_widget_override_size_request (GtkWidget *widget,
9816 gtk_widget_get_size_request (widget, old_width, old_height);
9817 gtk_widget_set_usize_internal (widget, width, height,
9818 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9822 * _gtk_widget_restore_size_request:
9823 * @widget: a #GtkWidget
9824 * @old_width: saved forced minimum size
9825 * @old_height: saved forced minimum size
9827 * Undoes the operation of_gtk_widget_override_size_request().
9830 _gtk_widget_restore_size_request (GtkWidget *widget,
9834 gtk_widget_set_usize_internal (widget, old_width, old_height,
9835 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9839 * gtk_widget_set_events:
9840 * @widget: a #GtkWidget
9841 * @events: event mask
9843 * Sets the event mask (see #GdkEventMask) for a widget. The event
9844 * mask determines which events a widget will receive. Keep in mind
9845 * that different widgets have different default event masks, and by
9846 * changing the event mask you may disrupt a widget's functionality,
9847 * so be careful. This function must be called while a widget is
9848 * unrealized. Consider gtk_widget_add_events() for widgets that are
9849 * already realized, or if you want to preserve the existing event
9850 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9851 * to get events on those widgets, place them inside a #GtkEventBox
9852 * and receive events on the event box.
9855 gtk_widget_set_events (GtkWidget *widget,
9858 g_return_if_fail (GTK_IS_WIDGET (widget));
9859 g_return_if_fail (!gtk_widget_get_realized (widget));
9861 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9862 GINT_TO_POINTER (events));
9863 g_object_notify (G_OBJECT (widget), "events");
9867 * gtk_widget_set_device_events:
9868 * @widget: a #GtkWidget
9869 * @device: a #GdkDevice
9870 * @events: event mask
9872 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9873 * mask determines which events a widget will receive from @device. Keep
9874 * in mind that different widgets have different default event masks, and by
9875 * changing the event mask you may disrupt a widget's functionality,
9876 * so be careful. This function must be called while a widget is
9877 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9878 * already realized, or if you want to preserve the existing event
9879 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9880 * to get events on those widgets, place them inside a #GtkEventBox
9881 * and receive events on the event box.
9886 gtk_widget_set_device_events (GtkWidget *widget,
9888 GdkEventMask events)
9890 GHashTable *device_events;
9892 g_return_if_fail (GTK_IS_WIDGET (widget));
9893 g_return_if_fail (GDK_IS_DEVICE (device));
9894 g_return_if_fail (!gtk_widget_get_realized (widget));
9896 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9898 if (G_UNLIKELY (!device_events))
9900 device_events = g_hash_table_new (NULL, NULL);
9901 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9902 (GDestroyNotify) g_hash_table_unref);
9905 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9909 * gtk_widget_set_device_enabled:
9910 * @widget: a #GtkWidget
9911 * @device: a #GdkDevice
9912 * @enabled: whether to enable the device
9914 * Enables or disables a #GdkDevice to interact with @widget
9915 * and all its children.
9917 * It does so by descending through the #GdkWindow hierarchy
9918 * and enabling the same mask that is has for core events
9919 * (i.e. the one that gdk_window_get_events() returns).
9924 gtk_widget_set_device_enabled (GtkWidget *widget,
9928 GList *enabled_devices;
9930 g_return_if_fail (GTK_IS_WIDGET (widget));
9931 g_return_if_fail (GDK_IS_DEVICE (device));
9933 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9934 enabled_devices = g_list_append (enabled_devices, device);
9936 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9937 enabled_devices, (GDestroyNotify) g_list_free);;
9939 if (gtk_widget_get_realized (widget))
9940 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9944 * gtk_widget_get_device_enabled:
9945 * @widget: a #GtkWidget
9946 * @device: a #GdkDevice
9948 * Returns whether @device can interact with @widget and its
9949 * children. See gtk_widget_set_device_enabled().
9951 * Return value: %TRUE is @device is enabled for @widget
9956 gtk_widget_get_device_enabled (GtkWidget *widget,
9959 GList *enabled_devices;
9961 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9962 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9964 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9966 return g_list_find (enabled_devices, device) != NULL;
9970 gtk_widget_add_events_internal_list (GtkWidget *widget,
9977 for (l = window_list; l != NULL; l = l->next)
9979 GdkWindow *window = l->data;
9982 gdk_window_get_user_data (window, &user_data);
9983 if (user_data == widget)
9988 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9990 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9992 children = gdk_window_get_children (window);
9993 gtk_widget_add_events_internal_list (widget, device, events, children);
9994 g_list_free (children);
10000 gtk_widget_add_events_internal (GtkWidget *widget,
10004 GtkWidgetPrivate *priv = widget->priv;
10005 GList *window_list;
10007 if (!gtk_widget_get_has_window (widget))
10008 window_list = gdk_window_get_children (priv->window);
10010 window_list = g_list_prepend (NULL, priv->window);
10012 gtk_widget_add_events_internal_list (widget, device, events, window_list);
10014 g_list_free (window_list);
10018 * gtk_widget_add_events:
10019 * @widget: a #GtkWidget
10020 * @events: an event mask, see #GdkEventMask
10022 * Adds the events in the bitfield @events to the event mask for
10023 * @widget. See gtk_widget_set_events() for details.
10026 gtk_widget_add_events (GtkWidget *widget,
10031 g_return_if_fail (GTK_IS_WIDGET (widget));
10033 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10034 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
10035 GINT_TO_POINTER (old_events | events));
10037 if (gtk_widget_get_realized (widget))
10039 gtk_widget_add_events_internal (widget, NULL, events);
10040 gtk_widget_update_devices_mask (widget, FALSE);
10043 g_object_notify (G_OBJECT (widget), "events");
10047 * gtk_widget_add_device_events:
10048 * @widget: a #GtkWidget
10049 * @device: a #GdkDevice
10050 * @events: an event mask, see #GdkEventMask
10052 * Adds the device events in the bitfield @events to the event mask for
10053 * @widget. See gtk_widget_set_device_events() for details.
10058 gtk_widget_add_device_events (GtkWidget *widget,
10060 GdkEventMask events)
10062 GdkEventMask old_events;
10063 GHashTable *device_events;
10065 g_return_if_fail (GTK_IS_WIDGET (widget));
10066 g_return_if_fail (GDK_IS_DEVICE (device));
10068 old_events = gtk_widget_get_device_events (widget, device);
10070 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10072 if (G_UNLIKELY (!device_events))
10074 device_events = g_hash_table_new (NULL, NULL);
10075 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
10076 (GDestroyNotify) g_hash_table_unref);
10079 g_hash_table_insert (device_events, device,
10080 GUINT_TO_POINTER (old_events | events));
10082 if (gtk_widget_get_realized (widget))
10083 gtk_widget_add_events_internal (widget, device, events);
10085 g_object_notify (G_OBJECT (widget), "events");
10089 * gtk_widget_get_toplevel:
10090 * @widget: a #GtkWidget
10092 * This function returns the topmost widget in the container hierarchy
10093 * @widget is a part of. If @widget has no parent widgets, it will be
10094 * returned as the topmost widget. No reference will be added to the
10095 * returned widget; it should not be unreferenced.
10097 * Note the difference in behavior vs. gtk_widget_get_ancestor();
10098 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
10100 * %NULL if @widget wasn't inside a toplevel window, and if the
10101 * window was inside a #GtkWindow-derived widget which was in turn
10102 * inside the toplevel #GtkWindow. While the second case may
10103 * seem unlikely, it actually happens when a #GtkPlug is embedded
10104 * inside a #GtkSocket within the same application.
10106 * To reliably find the toplevel #GtkWindow, use
10107 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
10108 * is set on the result.
10110 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
10111 * if (gtk_widget_is_toplevel (toplevel))
10113 * /* Perform action on toplevel. */
10117 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
10118 * if there's no ancestor.
10121 gtk_widget_get_toplevel (GtkWidget *widget)
10123 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10125 while (widget->priv->parent)
10126 widget = widget->priv->parent;
10132 * gtk_widget_get_ancestor:
10133 * @widget: a #GtkWidget
10134 * @widget_type: ancestor type
10136 * Gets the first ancestor of @widget with type @widget_type. For example,
10137 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
10138 * the first #GtkBox that's an ancestor of @widget. No reference will be
10139 * added to the returned widget; it should not be unreferenced. See note
10140 * about checking for a toplevel #GtkWindow in the docs for
10141 * gtk_widget_get_toplevel().
10143 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
10144 * considers @widget to be an ancestor of itself.
10146 * Return value: (transfer none): the ancestor widget, or %NULL if not found
10149 gtk_widget_get_ancestor (GtkWidget *widget,
10152 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10154 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
10155 widget = widget->priv->parent;
10157 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
10164 * gtk_widget_set_visual:
10165 * @widget: a #GtkWidget
10166 * @visual: visual to be used or %NULL to unset a previous one
10168 * Sets the visual that should be used for by widget and its children for
10169 * creating #GdkWindows. The visual must be on the same #GdkScreen as
10170 * returned by gdk_widget_get_screen(), so handling the
10171 * #GtkWidget::screen-changed signal is necessary.
10173 * Setting a new @visual will not cause @widget to recreate its windows,
10174 * so you should call this function before @widget is realized.
10177 gtk_widget_set_visual (GtkWidget *widget,
10180 g_return_if_fail (GTK_IS_WIDGET (widget));
10181 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
10184 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
10187 g_object_set_qdata_full (G_OBJECT (widget),
10189 g_object_ref (visual),
10194 * gtk_widget_get_visual:
10195 * @widget: a #GtkWidget
10197 * Gets the visual that will be used to render @widget.
10199 * Return value: (transfer none): the visual for @widget
10202 gtk_widget_get_visual (GtkWidget *widget)
10208 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10210 if (gtk_widget_get_has_window (widget) &&
10211 widget->priv->window)
10212 return gdk_window_get_visual (widget->priv->window);
10214 screen = gtk_widget_get_screen (widget);
10216 for (w = widget; w != NULL; w = w->priv->parent)
10218 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
10221 if (gdk_visual_get_screen (visual) == screen)
10224 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
10225 gtk_widget_get_name (widget));
10229 return gdk_screen_get_system_visual (screen);
10233 * gtk_widget_get_settings:
10234 * @widget: a #GtkWidget
10236 * Gets the settings object holding the settings used for this widget.
10238 * Note that this function can only be called when the #GtkWidget
10239 * is attached to a toplevel, since the settings object is specific
10240 * to a particular #GdkScreen.
10242 * Return value: (transfer none): the relevant #GtkSettings object
10245 gtk_widget_get_settings (GtkWidget *widget)
10247 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10249 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
10253 * gtk_widget_get_events:
10254 * @widget: a #GtkWidget
10256 * Returns the event mask for the widget (a bitfield containing flags
10257 * from the #GdkEventMask enumeration). These are the events that the widget
10260 * Return value: event mask for @widget
10263 gtk_widget_get_events (GtkWidget *widget)
10265 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10267 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10271 * gtk_widget_get_device_events:
10272 * @widget: a #GtkWidget
10273 * @device: a #GdkDevice
10275 * Returns the events mask for the widget corresponding to an specific device. These
10276 * are the events that the widget will receive when @device operates on it.
10278 * Returns: device event mask for @widget
10283 gtk_widget_get_device_events (GtkWidget *widget,
10286 GHashTable *device_events;
10288 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10289 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
10291 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10293 if (!device_events)
10296 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
10300 * gtk_widget_get_pointer:
10301 * @widget: a #GtkWidget
10302 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
10303 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
10305 * Obtains the location of the mouse pointer in widget coordinates.
10306 * Widget coordinates are a bit odd; for historical reasons, they are
10307 * defined as @widget->window coordinates for widgets that are not
10308 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
10309 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
10312 gtk_widget_get_pointer (GtkWidget *widget,
10316 GtkWidgetPrivate *priv;
10318 g_return_if_fail (GTK_IS_WIDGET (widget));
10320 priv = widget->priv;
10327 if (gtk_widget_get_realized (widget))
10329 gdk_window_get_pointer (priv->window, x, y, NULL);
10331 if (!gtk_widget_get_has_window (widget))
10334 *x -= priv->allocation.x;
10336 *y -= priv->allocation.y;
10342 * gtk_widget_is_ancestor:
10343 * @widget: a #GtkWidget
10344 * @ancestor: another #GtkWidget
10346 * Determines whether @widget is somewhere inside @ancestor, possibly with
10347 * intermediate containers.
10349 * Return value: %TRUE if @ancestor contains @widget as a child,
10350 * grandchild, great grandchild, etc.
10353 gtk_widget_is_ancestor (GtkWidget *widget,
10354 GtkWidget *ancestor)
10356 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10357 g_return_val_if_fail (ancestor != NULL, FALSE);
10361 if (widget->priv->parent == ancestor)
10363 widget = widget->priv->parent;
10369 static GQuark quark_composite_name = 0;
10372 * gtk_widget_set_composite_name:
10373 * @widget: a #GtkWidget.
10374 * @name: the name to set
10376 * Sets a widgets composite name. The widget must be
10377 * a composite child of its parent; see gtk_widget_push_composite_child().
10380 gtk_widget_set_composite_name (GtkWidget *widget,
10383 g_return_if_fail (GTK_IS_WIDGET (widget));
10384 g_return_if_fail (widget->priv->composite_child);
10385 g_return_if_fail (name != NULL);
10387 if (!quark_composite_name)
10388 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10390 g_object_set_qdata_full (G_OBJECT (widget),
10391 quark_composite_name,
10397 * gtk_widget_get_composite_name:
10398 * @widget: a #GtkWidget
10400 * Obtains the composite name of a widget.
10402 * Returns: the composite name of @widget, or %NULL if @widget is not
10403 * a composite child. The string should be freed when it is no
10407 gtk_widget_get_composite_name (GtkWidget *widget)
10409 GtkWidgetPrivate *priv;
10411 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10413 priv = widget->priv;
10415 if (widget->priv->composite_child && priv->parent)
10416 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10423 * gtk_widget_push_composite_child:
10425 * Makes all newly-created widgets as composite children until
10426 * the corresponding gtk_widget_pop_composite_child() call.
10428 * A composite child is a child that's an implementation detail of the
10429 * container it's inside and should not be visible to people using the
10430 * container. Composite children aren't treated differently by GTK (but
10431 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10432 * builders might want to treat them in a different way.
10434 * Here is a simple example:
10436 * gtk_widget_push_composite_child ();
10437 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10438 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10439 * gtk_widget_pop_composite_child ();
10440 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10441 * GTK_WIDGET (scrolled_window));
10442 * g_object_ref (scrolled_window->hscrollbar);
10446 gtk_widget_push_composite_child (void)
10448 composite_child_stack++;
10452 * gtk_widget_pop_composite_child:
10454 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10457 gtk_widget_pop_composite_child (void)
10459 if (composite_child_stack)
10460 composite_child_stack--;
10464 gtk_widget_emit_direction_changed (GtkWidget *widget,
10465 GtkTextDirection old_dir)
10467 gtk_widget_update_pango_context (widget);
10469 if (widget->priv->context)
10470 gtk_style_context_set_direction (widget->priv->context,
10471 gtk_widget_get_direction (widget));
10473 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10477 * gtk_widget_set_direction:
10478 * @widget: a #GtkWidget
10479 * @dir: the new direction
10481 * Sets the reading direction on a particular widget. This direction
10482 * controls the primary direction for widgets containing text,
10483 * and also the direction in which the children of a container are
10484 * packed. The ability to set the direction is present in order
10485 * so that correct localization into languages with right-to-left
10486 * reading directions can be done. Generally, applications will
10487 * let the default reading direction present, except for containers
10488 * where the containers are arranged in an order that is explicitely
10489 * visual rather than logical (such as buttons for text justification).
10491 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10492 * set by gtk_widget_set_default_direction() will be used.
10495 gtk_widget_set_direction (GtkWidget *widget,
10496 GtkTextDirection dir)
10498 GtkTextDirection old_dir;
10500 g_return_if_fail (GTK_IS_WIDGET (widget));
10501 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10503 old_dir = gtk_widget_get_direction (widget);
10505 widget->priv->direction = dir;
10507 if (old_dir != gtk_widget_get_direction (widget))
10508 gtk_widget_emit_direction_changed (widget, old_dir);
10512 * gtk_widget_get_direction:
10513 * @widget: a #GtkWidget
10515 * Gets the reading direction for a particular widget. See
10516 * gtk_widget_set_direction().
10518 * Return value: the reading direction for the widget.
10521 gtk_widget_get_direction (GtkWidget *widget)
10523 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10525 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10526 return gtk_default_direction;
10528 return widget->priv->direction;
10532 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10534 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10536 g_object_ref (widget);
10538 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10539 gtk_widget_emit_direction_changed (widget, old_dir);
10541 if (GTK_IS_CONTAINER (widget))
10542 gtk_container_forall (GTK_CONTAINER (widget),
10543 gtk_widget_set_default_direction_recurse,
10546 g_object_unref (widget);
10550 * gtk_widget_set_default_direction:
10551 * @dir: the new default direction. This cannot be
10552 * %GTK_TEXT_DIR_NONE.
10554 * Sets the default reading direction for widgets where the
10555 * direction has not been explicitly set by gtk_widget_set_direction().
10558 gtk_widget_set_default_direction (GtkTextDirection dir)
10560 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10562 if (dir != gtk_default_direction)
10564 GList *toplevels, *tmp_list;
10565 GtkTextDirection old_dir = gtk_default_direction;
10567 gtk_default_direction = dir;
10569 tmp_list = toplevels = gtk_window_list_toplevels ();
10570 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10574 gtk_widget_set_default_direction_recurse (tmp_list->data,
10575 GUINT_TO_POINTER (old_dir));
10576 g_object_unref (tmp_list->data);
10577 tmp_list = tmp_list->next;
10580 g_list_free (toplevels);
10585 * gtk_widget_get_default_direction:
10587 * Obtains the current default reading direction. See
10588 * gtk_widget_set_default_direction().
10590 * Return value: the current default direction.
10593 gtk_widget_get_default_direction (void)
10595 return gtk_default_direction;
10599 gtk_widget_dispose (GObject *object)
10601 GtkWidget *widget = GTK_WIDGET (object);
10602 GtkWidgetPrivate *priv = widget->priv;
10605 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10606 else if (gtk_widget_get_visible (widget))
10607 gtk_widget_hide (widget);
10609 priv->visible = FALSE;
10610 if (gtk_widget_get_realized (widget))
10611 gtk_widget_unrealize (widget);
10613 if (!priv->in_destruction)
10615 priv->in_destruction = TRUE;
10616 g_signal_emit (object, widget_signals[DESTROY], 0);
10617 priv->in_destruction = FALSE;
10620 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10624 gtk_widget_real_destroy (GtkWidget *object)
10626 /* gtk_object_destroy() will already hold a refcount on object */
10627 GtkWidget *widget = GTK_WIDGET (object);
10628 GtkWidgetPrivate *priv = widget->priv;
10630 /* wipe accelerator closures (keep order) */
10631 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10632 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10634 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10635 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10637 gtk_grab_remove (widget);
10640 g_object_unref (priv->style);
10641 priv->style = gtk_widget_get_default_style ();
10642 g_object_ref (priv->style);
10646 gtk_widget_finalize (GObject *object)
10648 GtkWidget *widget = GTK_WIDGET (object);
10649 GtkWidgetPrivate *priv = widget->priv;
10650 GtkWidgetAuxInfo *aux_info;
10651 GtkAccessible *accessible;
10653 gtk_grab_remove (widget);
10655 g_object_unref (priv->style);
10656 priv->style = NULL;
10658 g_free (priv->name);
10660 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10662 gtk_widget_aux_info_destroy (aux_info);
10664 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10666 g_object_unref (accessible);
10669 gtk_widget_path_free (priv->path);
10672 g_object_unref (priv->context);
10674 _gtk_widget_free_cached_sizes (widget);
10676 if (g_object_is_floating (object))
10677 g_warning ("A floating object was finalized. This means that someone\n"
10678 "called g_object_unref() on an object that had only a floating\n"
10679 "reference; the initial floating reference is not owned by anyone\n"
10680 "and must be removed with g_object_ref_sink().");
10682 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10685 /*****************************************
10686 * gtk_widget_real_map:
10691 *****************************************/
10694 gtk_widget_real_map (GtkWidget *widget)
10696 GtkWidgetPrivate *priv = widget->priv;
10698 g_assert (gtk_widget_get_realized (widget));
10700 if (!gtk_widget_get_mapped (widget))
10702 gtk_widget_set_mapped (widget, TRUE);
10704 if (gtk_widget_get_has_window (widget))
10705 gdk_window_show (priv->window);
10709 /*****************************************
10710 * gtk_widget_real_unmap:
10715 *****************************************/
10718 gtk_widget_real_unmap (GtkWidget *widget)
10720 GtkWidgetPrivate *priv = widget->priv;
10722 if (gtk_widget_get_mapped (widget))
10724 gtk_widget_set_mapped (widget, FALSE);
10726 if (gtk_widget_get_has_window (widget))
10727 gdk_window_hide (priv->window);
10731 /*****************************************
10732 * gtk_widget_real_realize:
10737 *****************************************/
10740 gtk_widget_real_realize (GtkWidget *widget)
10742 GtkWidgetPrivate *priv = widget->priv;
10744 g_assert (!gtk_widget_get_has_window (widget));
10746 gtk_widget_set_realized (widget, TRUE);
10749 priv->window = gtk_widget_get_parent_window (widget);
10750 g_object_ref (priv->window);
10754 /*****************************************
10755 * gtk_widget_real_unrealize:
10760 *****************************************/
10763 gtk_widget_real_unrealize (GtkWidget *widget)
10765 GtkWidgetPrivate *priv = widget->priv;
10767 g_assert (!widget->priv->mapped);
10769 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10772 /* We must do unrealize child widget BEFORE container widget.
10773 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10774 * So, unrealizing container widget bofore its children causes the problem
10775 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10778 if (GTK_IS_CONTAINER (widget))
10779 gtk_container_forall (GTK_CONTAINER (widget),
10780 (GtkCallback) gtk_widget_unrealize,
10783 if (gtk_widget_get_has_window (widget))
10785 gdk_window_set_user_data (priv->window, NULL);
10786 gdk_window_destroy (priv->window);
10787 priv->window = NULL;
10791 g_object_unref (priv->window);
10792 priv->window = NULL;
10795 gtk_selection_remove_all (widget);
10797 gtk_widget_set_realized (widget, FALSE);
10801 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10802 GtkOrientation orientation,
10803 gint *minimum_size,
10804 gint *natural_size)
10806 const GtkWidgetAuxInfo *aux_info;
10808 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10810 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10811 aux_info->width > 0)
10813 *minimum_size = MAX (*minimum_size, aux_info->width);
10815 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10816 aux_info->height > 0)
10818 *minimum_size = MAX (*minimum_size, aux_info->height);
10821 /* Fix it if set_size_request made natural size smaller than min size.
10822 * This would also silently fix broken widgets, but we warn about them
10823 * in gtksizerequest.c when calling their size request vfuncs.
10825 *natural_size = MAX (*natural_size, *minimum_size);
10827 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10829 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10830 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10834 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10835 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10840 * _gtk_widget_peek_request_cache:
10842 * Returns the address of the widget's request cache (strictly for
10843 * internal use in gtksizerequest.c)
10845 * Return value: the address of @widget's size request cache.
10848 _gtk_widget_peek_request_cache (GtkWidget *widget)
10850 /* Don't bother slowing things down with the return_if_fail guards here */
10851 return &widget->priv->requests;
10855 * _gtk_widget_set_device_window:
10856 * @widget: a #GtkWidget
10857 * @device: a #GdkDevice
10858 * @window: the new device window
10860 * Sets pointer window for @widget and @device.
10861 * Does not ref @window.
10864 _gtk_widget_set_device_window (GtkWidget *widget,
10868 GHashTable *device_window;
10870 g_return_if_fail (GTK_IS_WIDGET (widget));
10871 g_return_if_fail (GDK_IS_DEVICE (device));
10872 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10874 if (!gtk_widget_get_mapped (widget))
10877 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10879 if (!device_window && window)
10881 device_window = g_hash_table_new (NULL, NULL);
10882 g_object_set_qdata_full (G_OBJECT (widget),
10883 quark_pointer_window,
10885 (GDestroyNotify) g_hash_table_destroy);
10889 g_hash_table_insert (device_window, device, window);
10890 else if (device_window)
10892 g_hash_table_remove (device_window, device);
10894 if (g_hash_table_size (device_window) == 0)
10895 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10900 * _gtk_widget_get_device_window:
10901 * @widget: a #GtkWidget
10902 * @device: a #GdkDevice
10904 * Return value: the device window set on @widget, or %NULL
10907 _gtk_widget_get_device_window (GtkWidget *widget,
10910 GHashTable *device_window;
10912 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10913 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10915 if (!gtk_widget_get_mapped (widget))
10918 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10920 if (!device_window)
10923 return g_hash_table_lookup (device_window, device);
10927 * _gtk_widget_list_devices:
10928 * @widget: a #GtkWidget
10930 * Returns the list of #GdkDevices that is currently on top
10931 * of any window belonging to @widget.
10932 * Free the list with g_list_free(), the elements are owned
10933 * by GTK+ and must not be freed.
10936 _gtk_widget_list_devices (GtkWidget *widget)
10938 GHashTableIter iter;
10939 GHashTable *device_window;
10940 GList *devices = NULL;
10941 gpointer key, value;
10943 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10945 if (!gtk_widget_get_mapped (widget))
10948 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10950 if (G_UNLIKELY (!device_window))
10953 g_hash_table_iter_init (&iter, device_window);
10955 while (g_hash_table_iter_next (&iter, &key, &value))
10956 devices = g_list_prepend (devices, key);
10962 synth_crossing (GtkWidget *widget,
10966 GdkCrossingMode mode,
10967 GdkNotifyType detail)
10971 event = gdk_event_new (type);
10973 event->crossing.window = g_object_ref (window);
10974 event->crossing.send_event = TRUE;
10975 event->crossing.subwindow = g_object_ref (window);
10976 event->crossing.time = GDK_CURRENT_TIME;
10977 event->crossing.x = event->crossing.y = 0;
10978 event->crossing.x_root = event->crossing.y_root = 0;
10979 event->crossing.mode = mode;
10980 event->crossing.detail = detail;
10981 event->crossing.focus = FALSE;
10982 event->crossing.state = 0;
10983 gdk_event_set_device (event, device);
10986 widget = gtk_get_event_widget (event);
10989 gtk_widget_event_internal (widget, event);
10991 gdk_event_free (event);
10995 * _gtk_widget_synthesize_crossing:
10996 * @from: the #GtkWidget the virtual pointer is leaving.
10997 * @to: the #GtkWidget the virtual pointer is moving to.
10998 * @mode: the #GdkCrossingMode to place on the synthesized events.
11000 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
11002 * The real pointer window is the window that most recently received an enter notify
11003 * event. Windows that don't select for crossing events can't become the real
11004 * poiner window. The real pointer widget that owns the real pointer window. The
11005 * effective pointer window is the same as the real pointer window unless the real
11006 * pointer widget is either insensitive or there is a grab on a widget that is not
11007 * an ancestor of the real pointer widget (in which case the effective pointer
11008 * window should be the root window).
11010 * When the effective pointer window is the same as the real poiner window, we
11011 * receive crossing events from the windowing system. When the effective pointer
11012 * window changes to become different from the real pointer window we synthesize
11013 * crossing events, attempting to follow X protocol rules:
11015 * When the root window becomes the effective pointer window:
11016 * - leave notify on real pointer window, detail Ancestor
11017 * - leave notify on all of its ancestors, detail Virtual
11018 * - enter notify on root window, detail Inferior
11020 * When the root window ceases to be the effective pointer window:
11021 * - leave notify on root window, detail Inferior
11022 * - enter notify on all ancestors of real pointer window, detail Virtual
11023 * - enter notify on real pointer window, detail Ancestor
11026 _gtk_widget_synthesize_crossing (GtkWidget *from,
11029 GdkCrossingMode mode)
11031 GdkWindow *from_window = NULL, *to_window = NULL;
11033 g_return_if_fail (from != NULL || to != NULL);
11037 from_window = _gtk_widget_get_device_window (from, device);
11040 from_window = from->priv->window;
11045 to_window = _gtk_widget_get_device_window (to, device);
11048 to_window = to->priv->window;
11051 if (from_window == NULL && to_window == NULL)
11053 else if (from_window != NULL && to_window == NULL)
11055 GList *from_ancestors = NULL, *list;
11056 GdkWindow *from_ancestor = from_window;
11058 while (from_ancestor != NULL)
11060 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
11061 if (from_ancestor == NULL)
11063 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
11066 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11067 device, mode, GDK_NOTIFY_ANCESTOR);
11068 for (list = g_list_last (from_ancestors); list; list = list->prev)
11070 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11071 device, mode, GDK_NOTIFY_VIRTUAL);
11074 /* XXX: enter/inferior on root window? */
11076 g_list_free (from_ancestors);
11078 else if (from_window == NULL && to_window != NULL)
11080 GList *to_ancestors = NULL, *list;
11081 GdkWindow *to_ancestor = to_window;
11083 while (to_ancestor != NULL)
11085 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
11086 if (to_ancestor == NULL)
11088 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
11091 /* XXX: leave/inferior on root window? */
11093 for (list = to_ancestors; list; list = list->next)
11095 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11096 device, mode, GDK_NOTIFY_VIRTUAL);
11098 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11099 device, mode, GDK_NOTIFY_ANCESTOR);
11101 g_list_free (to_ancestors);
11103 else if (from_window == to_window)
11107 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
11108 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
11110 while (from_ancestor != NULL || to_ancestor != NULL)
11112 if (from_ancestor != NULL)
11114 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
11115 if (from_ancestor == to_window)
11118 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
11120 if (to_ancestor != NULL)
11122 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
11123 if (to_ancestor == from_window)
11126 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
11129 if (to_ancestor == from_window)
11131 if (mode != GDK_CROSSING_GTK_UNGRAB)
11132 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11133 device, mode, GDK_NOTIFY_INFERIOR);
11134 for (list = to_ancestors; list; list = list->next)
11135 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11136 device, mode, GDK_NOTIFY_VIRTUAL);
11137 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11138 device, mode, GDK_NOTIFY_ANCESTOR);
11140 else if (from_ancestor == to_window)
11142 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11143 device, mode, GDK_NOTIFY_ANCESTOR);
11144 for (list = g_list_last (from_ancestors); list; list = list->prev)
11146 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11147 device, mode, GDK_NOTIFY_VIRTUAL);
11149 if (mode != GDK_CROSSING_GTK_GRAB)
11150 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11151 device, mode, GDK_NOTIFY_INFERIOR);
11155 while (from_ancestors != NULL && to_ancestors != NULL
11156 && from_ancestors->data == to_ancestors->data)
11158 from_ancestors = g_list_delete_link (from_ancestors,
11160 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
11163 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11164 device, mode, GDK_NOTIFY_NONLINEAR);
11166 for (list = g_list_last (from_ancestors); list; list = list->prev)
11168 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11169 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11171 for (list = to_ancestors; list; list = list->next)
11173 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11174 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11176 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11177 device, mode, GDK_NOTIFY_NONLINEAR);
11179 g_list_free (from_ancestors);
11180 g_list_free (to_ancestors);
11185 gtk_widget_propagate_state (GtkWidget *widget,
11186 GtkStateData *data)
11188 GtkWidgetPrivate *priv = widget->priv;
11189 GtkStateFlags new_flags, old_flags = priv->state_flags;
11190 GtkStateType old_state;
11192 old_state = gtk_widget_get_state (widget);
11194 switch (data->operation)
11196 case STATE_CHANGE_REPLACE:
11197 priv->state_flags = data->flags;
11199 case STATE_CHANGE_SET:
11200 priv->state_flags |= data->flags;
11202 case STATE_CHANGE_UNSET:
11203 priv->state_flags &= ~(data->flags);
11207 /* make insensitivity unoverridable */
11208 if (!priv->sensitive)
11209 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
11211 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
11215 window = gtk_widget_get_toplevel (widget);
11217 if (window && gtk_widget_is_toplevel (window))
11218 gtk_window_set_focus (GTK_WINDOW (window), NULL);
11221 new_flags = priv->state_flags;
11223 if (old_flags != new_flags)
11225 g_object_ref (widget);
11227 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
11228 gtk_grab_remove (widget);
11230 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
11231 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
11233 if (!priv->shadowed)
11235 GList *event_windows = NULL;
11236 GList *devices, *d;
11238 devices = _gtk_widget_list_devices (widget);
11240 for (d = devices; d; d = d->next)
11246 window = _gtk_widget_get_device_window (widget, device);
11248 /* Do not propagate more than once to the
11249 * same window if non-multidevice aware.
11251 if (!gdk_window_get_support_multidevice (window) &&
11252 g_list_find (event_windows, window))
11255 if (!gtk_widget_is_sensitive (widget))
11256 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
11257 GDK_CROSSING_STATE_CHANGED);
11258 else if (old_flags & GTK_STATE_FLAG_INSENSITIVE)
11259 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
11260 GDK_CROSSING_STATE_CHANGED);
11262 event_windows = g_list_prepend (event_windows, window);
11265 g_list_free (event_windows);
11266 g_list_free (devices);
11269 if (GTK_IS_CONTAINER (widget))
11271 GtkStateData child_data = *data;
11273 /* Make sure to only propate the right states further */
11274 child_data.flags &= GTK_STATE_FLAGS_DO_PROPAGATE;
11276 if (child_data.use_forall)
11277 gtk_container_forall (GTK_CONTAINER (widget),
11278 (GtkCallback) gtk_widget_propagate_state,
11281 gtk_container_foreach (GTK_CONTAINER (widget),
11282 (GtkCallback) gtk_widget_propagate_state,
11286 /* Trigger state change transitions for the widget */
11287 if (priv->context &&
11288 gtk_widget_get_mapped (widget))
11290 gint diff, flag = 1;
11292 diff = old_flags ^ new_flags;
11296 if ((diff & flag) != 0)
11300 target = ((new_flags & flag) != 0);
11301 _gtk_widget_notify_state_change (widget, flag, target);
11310 g_object_unref (widget);
11314 static const GtkWidgetAuxInfo default_aux_info = {
11322 * gtk_widget_get_aux_info:
11323 * @widget: a #GtkWidget
11324 * @create: if %TRUE, create the structure if it doesn't exist
11326 * Get the #GtkWidgetAuxInfo structure for the widget.
11328 * Return value: the #GtkAuxInfo structure for the widget, or
11329 * %NULL if @create is %FALSE and one doesn't already exist.
11331 static GtkWidgetAuxInfo *
11332 gtk_widget_get_aux_info (GtkWidget *widget,
11335 GtkWidgetAuxInfo *aux_info;
11337 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
11338 if (!aux_info && create)
11340 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
11342 *aux_info = default_aux_info;
11344 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
11350 static const GtkWidgetAuxInfo*
11351 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11353 GtkWidgetAuxInfo *aux_info;
11355 aux_info = gtk_widget_get_aux_info (widget, FALSE);
11356 if (aux_info == NULL)
11358 return &default_aux_info;
11366 /*****************************************
11367 * gtk_widget_aux_info_destroy:
11372 *****************************************/
11375 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11377 g_slice_free (GtkWidgetAuxInfo, aux_info);
11381 * gtk_widget_shape_combine_region:
11382 * @widget: a #GtkWidget
11383 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11385 * Sets a shape for this widget's GDK window. This allows for
11386 * transparent windows etc., see gdk_window_shape_combine_region()
11387 * for more information.
11392 gtk_widget_shape_combine_region (GtkWidget *widget,
11393 cairo_region_t *region)
11395 GtkWidgetPrivate *priv;
11397 g_return_if_fail (GTK_IS_WIDGET (widget));
11398 /* set_shape doesn't work on widgets without gdk window */
11399 g_return_if_fail (gtk_widget_get_has_window (widget));
11401 priv = widget->priv;
11403 if (region == NULL)
11405 priv->has_shape_mask = FALSE;
11408 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11410 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11414 priv->has_shape_mask = TRUE;
11416 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11417 cairo_region_copy (region),
11418 (GDestroyNotify) cairo_region_destroy);
11420 /* set shape if widget has a gdk window already.
11421 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11424 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11429 * gtk_widget_input_shape_combine_region:
11430 * @widget: a #GtkWidget
11431 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11433 * Sets an input shape for this widget's GDK window. This allows for
11434 * windows which react to mouse click in a nonrectangular region, see
11435 * gdk_window_input_shape_combine_region() for more information.
11440 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11441 cairo_region_t *region)
11443 GtkWidgetPrivate *priv;
11445 g_return_if_fail (GTK_IS_WIDGET (widget));
11446 /* set_shape doesn't work on widgets without gdk window */
11447 g_return_if_fail (gtk_widget_get_has_window (widget));
11449 priv = widget->priv;
11451 if (region == NULL)
11454 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11456 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11460 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11461 cairo_region_copy (region),
11462 (GDestroyNotify) cairo_region_destroy);
11464 /* set shape if widget has a gdk window already.
11465 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11468 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11473 /* style properties
11477 * gtk_widget_class_install_style_property_parser: (skip)
11478 * @klass: a #GtkWidgetClass
11479 * @pspec: the #GParamSpec for the style property
11480 * @parser: the parser for the style property
11482 * Installs a style property on a widget class.
11485 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11487 GtkRcPropertyParser parser)
11489 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11490 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11491 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11492 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11494 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11496 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11497 G_OBJECT_CLASS_NAME (klass),
11502 g_param_spec_ref_sink (pspec);
11503 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11504 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11508 * gtk_widget_class_install_style_property:
11509 * @klass: a #GtkWidgetClass
11510 * @pspec: the #GParamSpec for the property
11512 * Installs a style property on a widget class. The parser for the
11513 * style property is determined by the value type of @pspec.
11516 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11519 GtkRcPropertyParser parser;
11521 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11522 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11524 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11526 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11530 * gtk_widget_class_find_style_property:
11531 * @klass: a #GtkWidgetClass
11532 * @property_name: the name of the style property to find
11533 * @returns: (transfer none): the #GParamSpec of the style property or
11534 * %NULL if @class has no style property with that name.
11536 * Finds a style property of a widget class by name.
11541 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11542 const gchar *property_name)
11544 g_return_val_if_fail (property_name != NULL, NULL);
11546 return g_param_spec_pool_lookup (style_property_spec_pool,
11548 G_OBJECT_CLASS_TYPE (klass),
11553 * gtk_widget_class_list_style_properties:
11554 * @klass: a #GtkWidgetClass
11555 * @n_properties: location to return the number of style properties found
11556 * @returns: (array length=n_properties) (transfer container): an
11557 * newly allocated array of #GParamSpec*. The array must be
11558 * freed with g_free().
11560 * Returns all style properties of a widget class.
11565 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11566 guint *n_properties)
11568 GParamSpec **pspecs;
11571 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11572 G_OBJECT_CLASS_TYPE (klass),
11581 * gtk_widget_style_get_property:
11582 * @widget: a #GtkWidget
11583 * @property_name: the name of a style property
11584 * @value: location to return the property value
11586 * Gets the value of a style property of @widget.
11589 gtk_widget_style_get_property (GtkWidget *widget,
11590 const gchar *property_name,
11595 g_return_if_fail (GTK_IS_WIDGET (widget));
11596 g_return_if_fail (property_name != NULL);
11597 g_return_if_fail (G_IS_VALUE (value));
11599 g_object_ref (widget);
11600 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11602 G_OBJECT_TYPE (widget),
11605 g_warning ("%s: widget class `%s' has no property named `%s'",
11607 G_OBJECT_TYPE_NAME (widget),
11611 GtkStyleContext *context;
11612 const GValue *peek_value;
11613 GtkStateFlags state;
11615 context = gtk_widget_get_style_context (widget);
11616 state = gtk_widget_get_state_flags (widget);
11618 peek_value = _gtk_style_context_peek_style_property (context,
11619 G_OBJECT_TYPE (widget),
11622 /* auto-conversion of the caller's value type
11624 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11625 g_value_copy (peek_value, value);
11626 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11627 g_value_transform (peek_value, value);
11629 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11631 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11632 G_VALUE_TYPE_NAME (value));
11634 g_object_unref (widget);
11638 * gtk_widget_style_get_valist:
11639 * @widget: a #GtkWidget
11640 * @first_property_name: the name of the first property to get
11641 * @var_args: a <type>va_list</type> of pairs of property names and
11642 * locations to return the property values, starting with the location
11643 * for @first_property_name.
11645 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11649 gtk_widget_style_get_valist (GtkWidget *widget,
11650 const gchar *first_property_name,
11653 GtkStyleContext *context;
11654 GtkStateFlags state;
11657 g_return_if_fail (GTK_IS_WIDGET (widget));
11659 g_object_ref (widget);
11660 context = gtk_widget_get_style_context (widget);
11661 state = gtk_widget_get_state_flags (widget);
11663 name = first_property_name;
11666 const GValue *peek_value;
11670 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11672 G_OBJECT_TYPE (widget),
11676 g_warning ("%s: widget class `%s' has no property named `%s'",
11678 G_OBJECT_TYPE_NAME (widget),
11682 /* style pspecs are always readable so we can spare that check here */
11684 peek_value = _gtk_style_context_peek_style_property (context,
11685 G_OBJECT_TYPE (widget),
11688 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11691 g_warning ("%s: %s", G_STRLOC, error);
11696 name = va_arg (var_args, gchar*);
11699 g_object_unref (widget);
11703 * gtk_widget_style_get:
11704 * @widget: a #GtkWidget
11705 * @first_property_name: the name of the first property to get
11706 * @Varargs: pairs of property names and locations to
11707 * return the property values, starting with the location for
11708 * @first_property_name, terminated by %NULL.
11710 * Gets the values of a multiple style properties of @widget.
11713 gtk_widget_style_get (GtkWidget *widget,
11714 const gchar *first_property_name,
11719 g_return_if_fail (GTK_IS_WIDGET (widget));
11721 va_start (var_args, first_property_name);
11722 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11728 * @widget: a #GtkWidget
11729 * @path_length: (out) (allow-none): location to store length of the path,
11731 * @path: (out) (allow-none): location to store allocated path string,
11733 * @path_reversed: (out) (allow-none): location to store allocated reverse
11734 * path string, or %NULL
11736 * Obtains the full path to @widget. The path is simply the name of a
11737 * widget and all its parents in the container hierarchy, separated by
11738 * periods. The name of a widget comes from
11739 * gtk_widget_get_name(). Paths are used to apply styles to a widget
11740 * in gtkrc configuration files. Widget names are the type of the
11741 * widget by default (e.g. "GtkButton") or can be set to an
11742 * application-specific value with gtk_widget_set_name(). By setting
11743 * the name of a widget, you allow users or theme authors to apply
11744 * styles to that specific widget in their gtkrc
11745 * file. @path_reversed_p fills in the path in reverse order,
11746 * i.e. starting with @widget's name instead of starting with the name
11747 * of @widget's outermost ancestor.
11749 * Deprecated:3.0: Use gtk_widget_get_path() instead
11752 gtk_widget_path (GtkWidget *widget,
11753 guint *path_length,
11755 gchar **path_reversed)
11757 static gchar *rev_path = NULL;
11758 static guint tmp_path_len = 0;
11761 g_return_if_fail (GTK_IS_WIDGET (widget));
11766 const gchar *string;
11771 string = gtk_widget_get_name (widget);
11772 l = strlen (string);
11773 while (tmp_path_len <= len + l + 1)
11775 tmp_path_len += INIT_PATH_SIZE;
11776 rev_path = g_realloc (rev_path, tmp_path_len);
11778 s = string + l - 1;
11779 d = rev_path + len;
11780 while (s >= string)
11784 widget = widget->priv->parent;
11787 rev_path[len++] = '.';
11789 rev_path[len++] = 0;
11794 *path_length = len - 1;
11796 *path_reversed = g_strdup (rev_path);
11799 *path = g_strdup (rev_path);
11800 g_strreverse (*path);
11805 * gtk_widget_class_path:
11806 * @widget: a #GtkWidget
11807 * @path_length: (out) (allow-none): location to store the length of the
11808 * class path, or %NULL
11809 * @path: (out) (allow-none): location to store the class path as an
11810 * allocated string, or %NULL
11811 * @path_reversed: (out) (allow-none): location to store the reverse
11812 * class path as an allocated string, or %NULL
11814 * Same as gtk_widget_path(), but always uses the name of a widget's type,
11815 * never uses a custom name set with gtk_widget_set_name().
11817 * Deprecated:3.0: Use gtk_widget_get_path() instead
11820 gtk_widget_class_path (GtkWidget *widget,
11821 guint *path_length,
11823 gchar **path_reversed)
11825 static gchar *rev_path = NULL;
11826 static guint tmp_path_len = 0;
11829 g_return_if_fail (GTK_IS_WIDGET (widget));
11834 const gchar *string;
11839 string = g_type_name (G_OBJECT_TYPE (widget));
11840 l = strlen (string);
11841 while (tmp_path_len <= len + l + 1)
11843 tmp_path_len += INIT_PATH_SIZE;
11844 rev_path = g_realloc (rev_path, tmp_path_len);
11846 s = string + l - 1;
11847 d = rev_path + len;
11848 while (s >= string)
11852 widget = widget->priv->parent;
11855 rev_path[len++] = '.';
11857 rev_path[len++] = 0;
11862 *path_length = len - 1;
11864 *path_reversed = g_strdup (rev_path);
11867 *path = g_strdup (rev_path);
11868 g_strreverse (*path);
11873 * gtk_requisition_new:
11875 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11877 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11878 * be freed with gtk_requisition_free().
11883 gtk_requisition_new (void)
11885 return g_slice_new0 (GtkRequisition);
11889 * gtk_requisition_copy:
11890 * @requisition: a #GtkRequisition
11892 * Copies a #GtkRequisition.
11894 * Returns: a copy of @requisition
11897 gtk_requisition_copy (const GtkRequisition *requisition)
11899 return g_slice_dup (GtkRequisition, requisition);
11903 * gtk_requisition_free:
11904 * @requisition: a #GtkRequisition
11906 * Frees a #GtkRequisition.
11909 gtk_requisition_free (GtkRequisition *requisition)
11911 g_slice_free (GtkRequisition, requisition);
11914 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11915 gtk_requisition_copy,
11916 gtk_requisition_free)
11919 * gtk_widget_class_set_accessible_type:
11920 * @widget_class: class to set the accessible type for
11921 * @type: The object type that implements the accessible for @widget_class
11923 * Sets the type to be used for creating accessibles for widgets of
11924 * @widget_class. The given @type must be a subtype of the type used for
11925 * accessibles of the parent class.
11927 * This function should only be called from class init functions of widgets.
11932 gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class,
11935 GtkWidgetClassPrivate *priv;
11937 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11938 g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type));
11940 priv = widget_class->priv;
11942 priv->accessible_type = type;
11946 * gtk_widget_class_get_accessible_type:
11947 * @widget_class: class to query the accessible type for
11949 * Returns the #GType for accessibles for widgets of the given
11950 * class. See gtk_widget_class_set_accessible_type().
11952 * Returns: the accessible type for @widget_class
11957 gtk_widget_class_get_accessible_type (GtkWidgetClass *widget_class)
11959 GtkWidgetClassPrivate *priv;
11961 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11963 priv = widget_class->priv;
11965 return priv->accessible_type;
11969 * gtk_widget_get_accessible:
11970 * @widget: a #GtkWidget
11972 * Returns the accessible object that describes the widget to an
11973 * assistive technology.
11975 * If no accessibility library is loaded (i.e. no ATK implementation library is
11976 * loaded via <envar>GTK_MODULES</envar> or via another application library,
11977 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
11978 * if no class-specific #AtkObject implementation is available for the widget
11979 * instance in question, it will inherit an #AtkObject implementation from the
11980 * first ancestor class for which such an implementation is defined.
11982 * The documentation of the
11983 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
11984 * library contains more information about accessible objects and their uses.
11986 * Returns: (transfer none): the #AtkObject associated with @widget
11989 gtk_widget_get_accessible (GtkWidget *widget)
11991 GtkWidgetClass *klass;
11993 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11995 klass = GTK_WIDGET_GET_CLASS (widget);
11997 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11999 return klass->get_accessible (widget);
12003 gtk_widget_real_get_accessible (GtkWidget *widget)
12005 AtkObject* accessible;
12007 accessible = g_object_get_qdata (G_OBJECT (widget),
12008 quark_accessible_object);
12011 GtkWidgetClass *widget_class;
12012 AtkObjectFactory *factory;
12013 AtkRegistry *default_registry;
12015 widget_class = GTK_WIDGET_GET_CLASS (widget);
12017 if (widget_class->priv->accessible_type == GTK_TYPE_ACCESSIBLE)
12019 default_registry = atk_get_default_registry ();
12020 factory = atk_registry_get_factory (default_registry,
12021 G_TYPE_FROM_INSTANCE (widget));
12023 atk_object_factory_create_accessible (factory,
12024 G_OBJECT (widget));
12028 accessible = g_object_new (widget_class->priv->accessible_type, NULL);
12029 atk_object_initialize (accessible, widget);
12032 g_object_set_qdata (G_OBJECT (widget),
12033 quark_accessible_object,
12040 * Initialize a AtkImplementorIface instance's virtual pointers as
12041 * appropriate to this implementor's class (GtkWidget).
12044 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
12046 iface->ref_accessible = gtk_widget_ref_accessible;
12050 gtk_widget_ref_accessible (AtkImplementor *implementor)
12052 AtkObject *accessible;
12054 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
12056 g_object_ref (accessible);
12061 * Expand flag management
12065 gtk_widget_update_computed_expand (GtkWidget *widget)
12067 GtkWidgetPrivate *priv;
12069 priv = widget->priv;
12071 if (priv->need_compute_expand)
12075 if (priv->hexpand_set)
12080 if (priv->vexpand_set)
12085 /* we don't need to use compute_expand if both expands are
12086 * forced by the app
12088 if (!(priv->hexpand_set && priv->vexpand_set))
12090 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
12094 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
12095 priv->hexpand_set ? &ignored : &h,
12096 priv->vexpand_set ? &ignored : &v);
12100 priv->need_compute_expand = FALSE;
12101 priv->computed_hexpand = h != FALSE;
12102 priv->computed_vexpand = v != FALSE;
12107 * gtk_widget_queue_compute_expand:
12108 * @widget: a #GtkWidget
12110 * Mark @widget as needing to recompute its expand flags. Call
12111 * this function when setting legacy expand child properties
12112 * on the child of a container.
12114 * See gtk_widget_compute_expand().
12117 gtk_widget_queue_compute_expand (GtkWidget *widget)
12120 gboolean changed_anything;
12122 if (widget->priv->need_compute_expand)
12125 changed_anything = FALSE;
12127 while (parent != NULL)
12129 if (!parent->priv->need_compute_expand)
12131 parent->priv->need_compute_expand = TRUE;
12132 changed_anything = TRUE;
12135 /* Note: if we had an invariant that "if a child needs to
12136 * compute expand, its parents also do" then we could stop going
12137 * up when we got to a parent that already needed to
12138 * compute. However, in general we compute expand lazily (as
12139 * soon as we see something in a subtree that is expand, we know
12140 * we're expanding) and so this invariant does not hold and we
12141 * have to always walk all the way up in case some ancestor
12142 * is not currently need_compute_expand.
12145 parent = parent->priv->parent;
12148 /* recomputing expand always requires
12149 * a relayout as well
12151 if (changed_anything)
12152 gtk_widget_queue_resize (widget);
12156 * gtk_widget_compute_expand:
12157 * @widget: the widget
12158 * @orientation: expand direction
12160 * Computes whether a container should give this widget extra space
12161 * when possible. Containers should check this, rather than
12162 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
12164 * This function already checks whether the widget is visible, so
12165 * visibility does not need to be checked separately. Non-visible
12166 * widgets are not expanded.
12168 * The computed expand value uses either the expand setting explicitly
12169 * set on the widget itself, or, if none has been explicitly set,
12170 * the widget may expand if some of its children do.
12172 * Return value: whether widget tree rooted here should be expanded
12175 gtk_widget_compute_expand (GtkWidget *widget,
12176 GtkOrientation orientation)
12178 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12180 /* We never make a widget expand if not even showing. */
12181 if (!gtk_widget_get_visible (widget))
12184 gtk_widget_update_computed_expand (widget);
12186 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12188 return widget->priv->computed_hexpand;
12192 return widget->priv->computed_vexpand;
12197 gtk_widget_set_expand (GtkWidget *widget,
12198 GtkOrientation orientation,
12201 const char *expand_prop;
12202 const char *expand_set_prop;
12204 GtkWidgetPrivate *priv;
12206 g_return_if_fail (GTK_IS_WIDGET (widget));
12208 priv = widget->priv;
12210 expand = expand != FALSE;
12212 was_both = priv->hexpand && priv->vexpand;
12214 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12216 if (priv->hexpand_set &&
12217 priv->hexpand == expand)
12220 priv->hexpand_set = TRUE;
12221 priv->hexpand = expand;
12223 expand_prop = "hexpand";
12224 expand_set_prop = "hexpand-set";
12228 if (priv->vexpand_set &&
12229 priv->vexpand == expand)
12232 priv->vexpand_set = TRUE;
12233 priv->vexpand = expand;
12235 expand_prop = "vexpand";
12236 expand_set_prop = "vexpand-set";
12239 gtk_widget_queue_compute_expand (widget);
12241 g_object_freeze_notify (G_OBJECT (widget));
12242 g_object_notify (G_OBJECT (widget), expand_prop);
12243 g_object_notify (G_OBJECT (widget), expand_set_prop);
12244 if (was_both != (priv->hexpand && priv->vexpand))
12245 g_object_notify (G_OBJECT (widget), "expand");
12246 g_object_thaw_notify (G_OBJECT (widget));
12250 gtk_widget_set_expand_set (GtkWidget *widget,
12251 GtkOrientation orientation,
12254 GtkWidgetPrivate *priv;
12257 priv = widget->priv;
12259 set = set != FALSE;
12261 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12263 if (set == priv->hexpand_set)
12266 priv->hexpand_set = set;
12267 prop = "hexpand-set";
12271 if (set == priv->vexpand_set)
12274 priv->vexpand_set = set;
12275 prop = "vexpand-set";
12278 gtk_widget_queue_compute_expand (widget);
12280 g_object_notify (G_OBJECT (widget), prop);
12284 * gtk_widget_get_hexpand:
12285 * @widget: the widget
12287 * Gets whether the widget would like any available extra horizontal
12288 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12289 * generally receive the extra space. For example, a list or
12290 * scrollable area or document in your window would often be set to
12293 * Containers should use gtk_widget_compute_expand() rather than
12294 * this function, to see whether a widget, or any of its children,
12295 * has the expand flag set. If any child of a widget wants to
12296 * expand, the parent may ask to expand also.
12298 * This function only looks at the widget's own hexpand flag, rather
12299 * than computing whether the entire widget tree rooted at this widget
12302 * Return value: whether hexpand flag is set
12305 gtk_widget_get_hexpand (GtkWidget *widget)
12307 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12309 return widget->priv->hexpand;
12313 * gtk_widget_set_hexpand:
12314 * @widget: the widget
12315 * @expand: whether to expand
12317 * Sets whether the widget would like any available extra horizontal
12318 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12319 * generally receive the extra space. For example, a list or
12320 * scrollable area or document in your window would often be set to
12323 * Call this function to set the expand flag if you would like your
12324 * widget to become larger horizontally when the window has extra
12327 * By default, widgets automatically expand if any of their children
12328 * want to expand. (To see if a widget will automatically expand given
12329 * its current children and state, call gtk_widget_compute_expand(). A
12330 * container can decide how the expandability of children affects the
12331 * expansion of the container by overriding the compute_expand virtual
12332 * method on #GtkWidget.).
12334 * Setting hexpand explicitly with this function will override the
12335 * automatic expand behavior.
12337 * This function forces the widget to expand or not to expand,
12338 * regardless of children. The override occurs because
12339 * gtk_widget_set_hexpand() sets the hexpand-set property (see
12340 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
12341 * value to be used, rather than looking at children and widget state.
12344 gtk_widget_set_hexpand (GtkWidget *widget,
12347 g_return_if_fail (GTK_IS_WIDGET (widget));
12349 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
12353 * gtk_widget_get_hexpand_set:
12354 * @widget: the widget
12356 * Gets whether gtk_widget_set_hexpand() has been used to
12357 * explicitly set the expand flag on this widget.
12359 * If hexpand is set, then it overrides any computed
12360 * expand value based on child widgets. If hexpand is not
12361 * set, then the expand value depends on whether any
12362 * children of the widget would like to expand.
12364 * There are few reasons to use this function, but it's here
12365 * for completeness and consistency.
12367 * Return value: whether hexpand has been explicitly set
12370 gtk_widget_get_hexpand_set (GtkWidget *widget)
12372 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12374 return widget->priv->hexpand_set;
12378 * gtk_widget_set_hexpand_set:
12379 * @widget: the widget
12380 * @set: value for hexpand-set property
12382 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
12385 * The hexpand-set property will be set automatically when you call
12386 * gtk_widget_set_hexpand() to set hexpand, so the most likely
12387 * reason to use this function would be to unset an explicit expand
12390 * If hexpand is set, then it overrides any computed
12391 * expand value based on child widgets. If hexpand is not
12392 * set, then the expand value depends on whether any
12393 * children of the widget would like to expand.
12395 * There are few reasons to use this function, but it's here
12396 * for completeness and consistency.
12399 gtk_widget_set_hexpand_set (GtkWidget *widget,
12402 g_return_if_fail (GTK_IS_WIDGET (widget));
12404 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
12409 * gtk_widget_get_vexpand:
12410 * @widget: the widget
12412 * Gets whether the widget would like any available extra vertical
12415 * See gtk_widget_get_hexpand() for more detail.
12417 * Return value: whether vexpand flag is set
12420 gtk_widget_get_vexpand (GtkWidget *widget)
12422 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12424 return widget->priv->vexpand;
12428 * gtk_widget_set_vexpand:
12429 * @widget: the widget
12430 * @expand: whether to expand
12432 * Sets whether the widget would like any available extra vertical
12435 * See gtk_widget_set_hexpand() for more detail.
12438 gtk_widget_set_vexpand (GtkWidget *widget,
12441 g_return_if_fail (GTK_IS_WIDGET (widget));
12443 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12447 * gtk_widget_get_vexpand_set:
12448 * @widget: the widget
12450 * Gets whether gtk_widget_set_vexpand() has been used to
12451 * explicitly set the expand flag on this widget.
12453 * See gtk_widget_get_hexpand_set() for more detail.
12455 * Return value: whether vexpand has been explicitly set
12458 gtk_widget_get_vexpand_set (GtkWidget *widget)
12460 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12462 return widget->priv->vexpand_set;
12466 * gtk_widget_set_vexpand_set:
12467 * @widget: the widget
12468 * @set: value for vexpand-set property
12470 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12473 * See gtk_widget_set_hexpand_set() for more detail.
12476 gtk_widget_set_vexpand_set (GtkWidget *widget,
12479 g_return_if_fail (GTK_IS_WIDGET (widget));
12481 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12485 * GtkBuildable implementation
12487 static GQuark quark_builder_has_default = 0;
12488 static GQuark quark_builder_has_focus = 0;
12489 static GQuark quark_builder_atk_relations = 0;
12490 static GQuark quark_builder_set_name = 0;
12493 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12495 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12496 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12497 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12498 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12500 iface->set_name = gtk_widget_buildable_set_name;
12501 iface->get_name = gtk_widget_buildable_get_name;
12502 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12503 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12504 iface->parser_finished = gtk_widget_buildable_parser_finished;
12505 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12506 iface->custom_finished = gtk_widget_buildable_custom_finished;
12510 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12513 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12514 g_strdup (name), g_free);
12517 static const gchar *
12518 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12520 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12524 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12525 GtkBuilder *builder,
12526 const gchar *childname)
12528 if (strcmp (childname, "accessible") == 0)
12529 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12535 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12536 GtkBuilder *builder,
12538 const GValue *value)
12540 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12541 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12542 GINT_TO_POINTER (TRUE));
12543 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12544 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12545 GINT_TO_POINTER (TRUE));
12547 g_object_set_property (G_OBJECT (buildable), name, value);
12552 gchar *action_name;
12553 GString *description;
12555 gboolean translatable;
12565 free_action (AtkActionData *data, gpointer user_data)
12567 g_free (data->action_name);
12568 g_string_free (data->description, TRUE);
12569 g_free (data->context);
12570 g_slice_free (AtkActionData, data);
12574 free_relation (AtkRelationData *data, gpointer user_data)
12576 g_free (data->target);
12577 g_free (data->type);
12578 g_slice_free (AtkRelationData, data);
12582 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12583 GtkBuilder *builder)
12585 GSList *atk_relations;
12587 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12588 gtk_widget_grab_default (GTK_WIDGET (buildable));
12589 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12590 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12592 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12593 quark_builder_atk_relations);
12596 AtkObject *accessible;
12597 AtkRelationSet *relation_set;
12600 AtkRelationType relation_type;
12601 AtkObject *target_accessible;
12603 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12604 relation_set = atk_object_ref_relation_set (accessible);
12606 for (l = atk_relations; l; l = l->next)
12608 AtkRelationData *relation = (AtkRelationData*)l->data;
12610 target = gtk_builder_get_object (builder, relation->target);
12613 g_warning ("Target object %s in <relation> does not exist",
12617 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12618 g_assert (target_accessible != NULL);
12620 relation_type = atk_relation_type_for_name (relation->type);
12621 if (relation_type == ATK_RELATION_NULL)
12623 g_warning ("<relation> type %s not found",
12627 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12628 target_accessible);
12630 g_object_unref (relation_set);
12632 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
12633 g_slist_free (atk_relations);
12634 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12643 } AccessibilitySubParserData;
12646 accessibility_start_element (GMarkupParseContext *context,
12647 const gchar *element_name,
12648 const gchar **names,
12649 const gchar **values,
12650 gpointer user_data,
12653 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12655 gint line_number, char_number;
12657 if (strcmp (element_name, "relation") == 0)
12659 gchar *target = NULL;
12660 gchar *type = NULL;
12661 AtkRelationData *relation;
12663 for (i = 0; names[i]; i++)
12665 if (strcmp (names[i], "target") == 0)
12666 target = g_strdup (values[i]);
12667 else if (strcmp (names[i], "type") == 0)
12668 type = g_strdup (values[i]);
12671 g_markup_parse_context_get_position (context,
12674 g_set_error (error,
12676 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12677 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12679 line_number, char_number, names[i], "relation");
12686 if (!target || !type)
12688 g_markup_parse_context_get_position (context,
12691 g_set_error (error,
12693 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12694 "%s:%d:%d <%s> requires attribute \"%s\"",
12696 line_number, char_number, "relation",
12697 type ? "target" : "type");
12703 relation = g_slice_new (AtkRelationData);
12704 relation->target = target;
12705 relation->type = type;
12707 data->relations = g_slist_prepend (data->relations, relation);
12709 else if (strcmp (element_name, "action") == 0)
12711 const gchar *action_name = NULL;
12712 const gchar *description = NULL;
12713 const gchar *msg_context = NULL;
12714 gboolean translatable = FALSE;
12715 AtkActionData *action;
12717 for (i = 0; names[i]; i++)
12719 if (strcmp (names[i], "action_name") == 0)
12720 action_name = values[i];
12721 else if (strcmp (names[i], "description") == 0)
12722 description = values[i];
12723 else if (strcmp (names[i], "translatable") == 0)
12725 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12728 else if (strcmp (names[i], "comments") == 0)
12730 /* do nothing, comments are for translators */
12732 else if (strcmp (names[i], "context") == 0)
12733 msg_context = values[i];
12736 g_markup_parse_context_get_position (context,
12739 g_set_error (error,
12741 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12742 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12744 line_number, char_number, names[i], "action");
12751 g_markup_parse_context_get_position (context,
12754 g_set_error (error,
12756 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12757 "%s:%d:%d <%s> requires attribute \"%s\"",
12759 line_number, char_number, "action",
12764 action = g_slice_new (AtkActionData);
12765 action->action_name = g_strdup (action_name);
12766 action->description = g_string_new (description);
12767 action->context = g_strdup (msg_context);
12768 action->translatable = translatable;
12770 data->actions = g_slist_prepend (data->actions, action);
12772 else if (strcmp (element_name, "accessibility") == 0)
12775 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12779 accessibility_text (GMarkupParseContext *context,
12782 gpointer user_data,
12785 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12787 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12789 AtkActionData *action = data->actions->data;
12791 g_string_append_len (action->description, text, text_len);
12795 static const GMarkupParser accessibility_parser =
12797 accessibility_start_element,
12799 accessibility_text,
12808 } AccelGroupParserData;
12811 accel_group_start_element (GMarkupParseContext *context,
12812 const gchar *element_name,
12813 const gchar **names,
12814 const gchar **values,
12815 gpointer user_data,
12820 guint modifiers = 0;
12821 gchar *signal = NULL;
12822 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12824 for (i = 0; names[i]; i++)
12826 if (strcmp (names[i], "key") == 0)
12827 key = gdk_keyval_from_name (values[i]);
12828 else if (strcmp (names[i], "modifiers") == 0)
12830 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12836 else if (strcmp (names[i], "signal") == 0)
12837 signal = g_strdup (values[i]);
12840 if (key == 0 || signal == NULL)
12842 g_warning ("<accelerator> requires key and signal attributes");
12845 parser_data->key = key;
12846 parser_data->modifiers = modifiers;
12847 parser_data->signal = signal;
12850 static const GMarkupParser accel_group_parser =
12852 accel_group_start_element,
12861 style_start_element (GMarkupParseContext *context,
12862 const gchar *element_name,
12863 const gchar **names,
12864 const gchar **values,
12865 gpointer user_data,
12868 StyleParserData *style_data = (StyleParserData *)user_data;
12871 if (strcmp (element_name, "class") == 0)
12873 if (g_markup_collect_attributes (element_name,
12877 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12878 G_MARKUP_COLLECT_INVALID))
12880 style_data->classes = g_slist_append (style_data->classes, class_name);
12883 else if (strcmp (element_name, "style") == 0)
12886 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12889 static const GMarkupParser style_parser =
12891 style_start_element,
12895 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12896 GtkBuilder *builder,
12898 const gchar *tagname,
12899 GMarkupParser *parser,
12902 g_assert (buildable);
12904 if (strcmp (tagname, "accelerator") == 0)
12906 AccelGroupParserData *parser_data;
12908 parser_data = g_slice_new0 (AccelGroupParserData);
12909 parser_data->object = g_object_ref (buildable);
12910 *parser = accel_group_parser;
12911 *data = parser_data;
12914 if (strcmp (tagname, "accessibility") == 0)
12916 AccessibilitySubParserData *parser_data;
12918 parser_data = g_slice_new0 (AccessibilitySubParserData);
12919 *parser = accessibility_parser;
12920 *data = parser_data;
12923 if (strcmp (tagname, "style") == 0)
12925 StyleParserData *parser_data;
12927 parser_data = g_slice_new0 (StyleParserData);
12928 *parser = style_parser;
12929 *data = parser_data;
12937 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12938 GtkWidget *toplevel,
12939 gpointer user_data)
12941 AccelGroupParserData *accel_data;
12942 GSList *accel_groups;
12943 GtkAccelGroup *accel_group;
12945 g_return_if_fail (GTK_IS_WIDGET (widget));
12946 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12947 g_return_if_fail (user_data != NULL);
12949 accel_data = (AccelGroupParserData*)user_data;
12950 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12951 if (g_slist_length (accel_groups) == 0)
12953 accel_group = gtk_accel_group_new ();
12954 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12958 g_assert (g_slist_length (accel_groups) == 1);
12959 accel_group = g_slist_nth_data (accel_groups, 0);
12962 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12963 accel_data->signal,
12966 accel_data->modifiers,
12967 GTK_ACCEL_VISIBLE);
12969 g_object_unref (accel_data->object);
12970 g_free (accel_data->signal);
12971 g_slice_free (AccelGroupParserData, accel_data);
12975 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12976 GtkBuilder *builder,
12978 const gchar *tagname,
12979 gpointer user_data)
12981 if (strcmp (tagname, "accelerator") == 0)
12983 AccelGroupParserData *accel_data;
12984 GtkWidget *toplevel;
12986 accel_data = (AccelGroupParserData*)user_data;
12987 g_assert (accel_data->object);
12989 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12991 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12993 else if (strcmp (tagname, "accessibility") == 0)
12995 AccessibilitySubParserData *a11y_data;
12997 a11y_data = (AccessibilitySubParserData*)user_data;
12999 if (a11y_data->actions)
13001 AtkObject *accessible;
13006 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
13008 if (ATK_IS_ACTION (accessible))
13010 action = ATK_ACTION (accessible);
13011 n_actions = atk_action_get_n_actions (action);
13013 for (l = a11y_data->actions; l; l = l->next)
13015 AtkActionData *action_data = (AtkActionData*)l->data;
13017 for (i = 0; i < n_actions; i++)
13018 if (strcmp (atk_action_get_name (action, i),
13019 action_data->action_name) == 0)
13024 gchar *description;
13026 if (action_data->translatable && action_data->description->len)
13027 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
13028 action_data->context,
13029 action_data->description->str);
13031 description = action_data->description->str;
13033 atk_action_set_description (action, i, description);
13038 g_warning ("accessibility action on a widget that does not implement AtkAction");
13040 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
13041 g_slist_free (a11y_data->actions);
13044 if (a11y_data->relations)
13045 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
13046 a11y_data->relations);
13048 g_slice_free (AccessibilitySubParserData, a11y_data);
13050 else if (strcmp (tagname, "style") == 0)
13052 StyleParserData *style_data = (StyleParserData *)user_data;
13053 GtkStyleContext *context;
13056 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
13058 for (l = style_data->classes; l; l = l->next)
13059 gtk_style_context_add_class (context, (const gchar *)l->data);
13061 gtk_widget_reset_style (GTK_WIDGET (buildable));
13063 g_slist_free_full (style_data->classes, g_free);
13064 g_slice_free (StyleParserData, style_data);
13068 static GtkSizeRequestMode
13069 gtk_widget_real_get_request_mode (GtkWidget *widget)
13071 /* By default widgets dont trade size at all. */
13072 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
13076 gtk_widget_real_get_width (GtkWidget *widget,
13077 gint *minimum_size,
13078 gint *natural_size)
13088 gtk_widget_real_get_height (GtkWidget *widget,
13089 gint *minimum_size,
13090 gint *natural_size)
13100 gtk_widget_real_get_height_for_width (GtkWidget *widget,
13102 gint *minimum_height,
13103 gint *natural_height)
13105 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
13109 gtk_widget_real_get_width_for_height (GtkWidget *widget,
13111 gint *minimum_width,
13112 gint *natural_width)
13114 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
13118 * gtk_widget_get_halign:
13119 * @widget: a #GtkWidget
13121 * Gets the value of the #GtkWidget:halign property.
13123 * Returns: the horizontal alignment of @widget
13126 gtk_widget_get_halign (GtkWidget *widget)
13128 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
13129 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
13133 * gtk_widget_set_halign:
13134 * @widget: a #GtkWidget
13135 * @align: the horizontal alignment
13137 * Sets the horizontal alignment of @widget.
13138 * See the #GtkWidget:halign property.
13141 gtk_widget_set_halign (GtkWidget *widget,
13144 GtkWidgetAuxInfo *aux_info;
13146 g_return_if_fail (GTK_IS_WIDGET (widget));
13148 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13150 if (aux_info->halign == align)
13153 aux_info->halign = align;
13154 gtk_widget_queue_resize (widget);
13155 g_object_notify (G_OBJECT (widget), "halign");
13159 * gtk_widget_get_valign:
13160 * @widget: a #GtkWidget
13162 * Gets the value of the #GtkWidget:valign property.
13164 * Returns: the vertical alignment of @widget
13167 gtk_widget_get_valign (GtkWidget *widget)
13169 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
13170 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
13174 * gtk_widget_set_valign:
13175 * @widget: a #GtkWidget
13176 * @align: the vertical alignment
13178 * Sets the vertical alignment of @widget.
13179 * See the #GtkWidget:valign property.
13182 gtk_widget_set_valign (GtkWidget *widget,
13185 GtkWidgetAuxInfo *aux_info;
13187 g_return_if_fail (GTK_IS_WIDGET (widget));
13189 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13191 if (aux_info->valign == align)
13194 aux_info->valign = align;
13195 gtk_widget_queue_resize (widget);
13196 g_object_notify (G_OBJECT (widget), "valign");
13200 * gtk_widget_get_margin_left:
13201 * @widget: a #GtkWidget
13203 * Gets the value of the #GtkWidget:margin-left property.
13205 * Returns: The left margin of @widget
13210 gtk_widget_get_margin_left (GtkWidget *widget)
13212 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13214 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
13218 * gtk_widget_set_margin_left:
13219 * @widget: a #GtkWidget
13220 * @margin: the left margin
13222 * Sets the left margin of @widget.
13223 * See the #GtkWidget:margin-left property.
13228 gtk_widget_set_margin_left (GtkWidget *widget,
13231 GtkWidgetAuxInfo *aux_info;
13233 g_return_if_fail (GTK_IS_WIDGET (widget));
13234 g_return_if_fail (margin <= G_MAXINT16);
13236 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13238 if (aux_info->margin.left == margin)
13241 aux_info->margin.left = margin;
13242 gtk_widget_queue_resize (widget);
13243 g_object_notify (G_OBJECT (widget), "margin-left");
13247 * gtk_widget_get_margin_right:
13248 * @widget: a #GtkWidget
13250 * Gets the value of the #GtkWidget:margin-right property.
13252 * Returns: The right margin of @widget
13257 gtk_widget_get_margin_right (GtkWidget *widget)
13259 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13261 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
13265 * gtk_widget_set_margin_right:
13266 * @widget: a #GtkWidget
13267 * @margin: the right margin
13269 * Sets the right margin of @widget.
13270 * See the #GtkWidget:margin-right property.
13275 gtk_widget_set_margin_right (GtkWidget *widget,
13278 GtkWidgetAuxInfo *aux_info;
13280 g_return_if_fail (GTK_IS_WIDGET (widget));
13281 g_return_if_fail (margin <= G_MAXINT16);
13283 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13285 if (aux_info->margin.right == margin)
13288 aux_info->margin.right = margin;
13289 gtk_widget_queue_resize (widget);
13290 g_object_notify (G_OBJECT (widget), "margin-right");
13294 * gtk_widget_get_margin_top:
13295 * @widget: a #GtkWidget
13297 * Gets the value of the #GtkWidget:margin-top property.
13299 * Returns: The top margin of @widget
13304 gtk_widget_get_margin_top (GtkWidget *widget)
13306 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13308 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
13312 * gtk_widget_set_margin_top:
13313 * @widget: a #GtkWidget
13314 * @margin: the top margin
13316 * Sets the top margin of @widget.
13317 * See the #GtkWidget:margin-top property.
13322 gtk_widget_set_margin_top (GtkWidget *widget,
13325 GtkWidgetAuxInfo *aux_info;
13327 g_return_if_fail (GTK_IS_WIDGET (widget));
13328 g_return_if_fail (margin <= G_MAXINT16);
13330 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13332 if (aux_info->margin.top == margin)
13335 aux_info->margin.top = margin;
13336 gtk_widget_queue_resize (widget);
13337 g_object_notify (G_OBJECT (widget), "margin-top");
13341 * gtk_widget_get_margin_bottom:
13342 * @widget: a #GtkWidget
13344 * Gets the value of the #GtkWidget:margin-bottom property.
13346 * Returns: The bottom margin of @widget
13351 gtk_widget_get_margin_bottom (GtkWidget *widget)
13353 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13355 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
13359 * gtk_widget_set_margin_bottom:
13360 * @widget: a #GtkWidget
13361 * @margin: the bottom margin
13363 * Sets the bottom margin of @widget.
13364 * See the #GtkWidget:margin-bottom property.
13369 gtk_widget_set_margin_bottom (GtkWidget *widget,
13372 GtkWidgetAuxInfo *aux_info;
13374 g_return_if_fail (GTK_IS_WIDGET (widget));
13375 g_return_if_fail (margin <= G_MAXINT16);
13377 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13379 if (aux_info->margin.bottom == margin)
13382 aux_info->margin.bottom = margin;
13383 gtk_widget_queue_resize (widget);
13384 g_object_notify (G_OBJECT (widget), "margin-bottom");
13388 * gtk_widget_get_clipboard:
13389 * @widget: a #GtkWidget
13390 * @selection: a #GdkAtom which identifies the clipboard
13391 * to use. %GDK_SELECTION_CLIPBOARD gives the
13392 * default clipboard. Another common value
13393 * is %GDK_SELECTION_PRIMARY, which gives
13394 * the primary X selection.
13396 * Returns the clipboard object for the given selection to
13397 * be used with @widget. @widget must have a #GdkDisplay
13398 * associated with it, so must be attached to a toplevel
13401 * Return value: (transfer none): the appropriate clipboard object. If no
13402 * clipboard already exists, a new one will
13403 * be created. Once a clipboard object has
13404 * been created, it is persistent for all time.
13409 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
13411 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13412 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
13414 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
13419 * gtk_widget_list_mnemonic_labels:
13420 * @widget: a #GtkWidget
13422 * Returns a newly allocated list of the widgets, normally labels, for
13423 * which this widget is the target of a mnemonic (see for example,
13424 * gtk_label_set_mnemonic_widget()).
13426 * The widgets in the list are not individually referenced. If you
13427 * want to iterate through the list and perform actions involving
13428 * callbacks that might destroy the widgets, you
13429 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
13430 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
13431 * widgets afterwards.
13433 * Return value: (element-type GtkWidget) (transfer container): the list of
13434 * mnemonic labels; free this list
13435 * with g_list_free() when you are done with it.
13440 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
13442 GList *list = NULL;
13445 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13447 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13448 list = g_list_prepend (list, l->data);
13454 * gtk_widget_add_mnemonic_label:
13455 * @widget: a #GtkWidget
13456 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13458 * Adds a widget to the list of mnemonic labels for
13459 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13460 * list of mnemonic labels for the widget is cleared when the
13461 * widget is destroyed, so the caller must make sure to update
13462 * its internal state at this point as well, by using a connection
13463 * to the #GtkWidget::destroy signal or a weak notifier.
13468 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13471 GSList *old_list, *new_list;
13473 g_return_if_fail (GTK_IS_WIDGET (widget));
13474 g_return_if_fail (GTK_IS_WIDGET (label));
13476 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13477 new_list = g_slist_prepend (old_list, label);
13479 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13480 new_list, (GDestroyNotify) g_slist_free);
13484 * gtk_widget_remove_mnemonic_label:
13485 * @widget: a #GtkWidget
13486 * @label: a #GtkWidget that was previously set as a mnemnic label for
13487 * @widget with gtk_widget_add_mnemonic_label().
13489 * Removes a widget from the list of mnemonic labels for
13490 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13491 * must have previously been added to the list with
13492 * gtk_widget_add_mnemonic_label().
13497 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13500 GSList *old_list, *new_list;
13502 g_return_if_fail (GTK_IS_WIDGET (widget));
13503 g_return_if_fail (GTK_IS_WIDGET (label));
13505 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13506 new_list = g_slist_remove (old_list, label);
13509 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13510 new_list, (GDestroyNotify) g_slist_free);
13514 * gtk_widget_get_no_show_all:
13515 * @widget: a #GtkWidget
13517 * Returns the current value of the #GtkWidget:no-show-all property,
13518 * which determines whether calls to gtk_widget_show_all()
13519 * will affect this widget.
13521 * Return value: the current value of the "no-show-all" property.
13526 gtk_widget_get_no_show_all (GtkWidget *widget)
13528 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13530 return widget->priv->no_show_all;
13534 * gtk_widget_set_no_show_all:
13535 * @widget: a #GtkWidget
13536 * @no_show_all: the new value for the "no-show-all" property
13538 * Sets the #GtkWidget:no-show-all property, which determines whether
13539 * calls to gtk_widget_show_all() will affect this widget.
13541 * This is mostly for use in constructing widget hierarchies with externally
13542 * controlled visibility, see #GtkUIManager.
13547 gtk_widget_set_no_show_all (GtkWidget *widget,
13548 gboolean no_show_all)
13550 g_return_if_fail (GTK_IS_WIDGET (widget));
13552 no_show_all = (no_show_all != FALSE);
13554 if (widget->priv->no_show_all != no_show_all)
13556 widget->priv->no_show_all = no_show_all;
13558 g_object_notify (G_OBJECT (widget), "no-show-all");
13564 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13565 gboolean has_tooltip,
13568 GtkWidgetPrivate *priv = widget->priv;
13569 gboolean priv_has_tooltip;
13571 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13572 quark_has_tooltip));
13574 if (priv_has_tooltip != has_tooltip || force)
13576 priv_has_tooltip = has_tooltip;
13578 if (priv_has_tooltip)
13580 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13581 gdk_window_set_events (priv->window,
13582 gdk_window_get_events (priv->window) |
13583 GDK_LEAVE_NOTIFY_MASK |
13584 GDK_POINTER_MOTION_MASK |
13585 GDK_POINTER_MOTION_HINT_MASK);
13587 if (gtk_widget_get_has_window (widget))
13588 gtk_widget_add_events (widget,
13589 GDK_LEAVE_NOTIFY_MASK |
13590 GDK_POINTER_MOTION_MASK |
13591 GDK_POINTER_MOTION_HINT_MASK);
13594 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13595 GUINT_TO_POINTER (priv_has_tooltip));
13600 * gtk_widget_set_tooltip_window:
13601 * @widget: a #GtkWidget
13602 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13604 * Replaces the default, usually yellow, window used for displaying
13605 * tooltips with @custom_window. GTK+ will take care of showing and
13606 * hiding @custom_window at the right moment, to behave likewise as
13607 * the default tooltip window. If @custom_window is %NULL, the default
13608 * tooltip window will be used.
13610 * If the custom window should have the default theming it needs to
13611 * have the name "gtk-tooltip", see gtk_widget_set_name().
13616 gtk_widget_set_tooltip_window (GtkWidget *widget,
13617 GtkWindow *custom_window)
13619 gboolean has_tooltip;
13620 gchar *tooltip_markup;
13622 g_return_if_fail (GTK_IS_WIDGET (widget));
13623 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13625 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13628 g_object_ref (custom_window);
13630 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13631 custom_window, g_object_unref);
13633 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13634 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13636 if (has_tooltip && gtk_widget_get_visible (widget))
13637 gtk_widget_queue_tooltip_query (widget);
13641 * gtk_widget_get_tooltip_window:
13642 * @widget: a #GtkWidget
13644 * Returns the #GtkWindow of the current tooltip. This can be the
13645 * GtkWindow created by default, or the custom tooltip window set
13646 * using gtk_widget_set_tooltip_window().
13648 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13653 gtk_widget_get_tooltip_window (GtkWidget *widget)
13655 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13657 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13661 * gtk_widget_trigger_tooltip_query:
13662 * @widget: a #GtkWidget
13664 * Triggers a tooltip query on the display where the toplevel of @widget
13665 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13671 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13673 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13676 static guint tooltip_query_id;
13677 static GSList *tooltip_query_displays;
13680 tooltip_query_idle (gpointer data)
13682 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13683 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13684 g_slist_free (tooltip_query_displays);
13686 tooltip_query_displays = NULL;
13687 tooltip_query_id = 0;
13693 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13695 GdkDisplay *display;
13697 display = gtk_widget_get_display (widget);
13699 if (!g_slist_find (tooltip_query_displays, display))
13700 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13702 if (tooltip_query_id == 0)
13703 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13707 * gtk_widget_set_tooltip_text:
13708 * @widget: a #GtkWidget
13709 * @text: the contents of the tooltip for @widget
13711 * Sets @text as the contents of the tooltip. This function will take
13712 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13713 * handler for the #GtkWidget::query-tooltip signal.
13715 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13720 gtk_widget_set_tooltip_text (GtkWidget *widget,
13723 g_return_if_fail (GTK_IS_WIDGET (widget));
13725 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13729 * gtk_widget_get_tooltip_text:
13730 * @widget: a #GtkWidget
13732 * Gets the contents of the tooltip for @widget.
13734 * Return value: the tooltip text, or %NULL. You should free the
13735 * returned string with g_free() when done.
13740 gtk_widget_get_tooltip_text (GtkWidget *widget)
13742 gchar *text = NULL;
13744 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13746 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13752 * gtk_widget_set_tooltip_markup:
13753 * @widget: a #GtkWidget
13754 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13756 * Sets @markup as the contents of the tooltip, which is marked up with
13757 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13759 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13760 * and of the default handler for the #GtkWidget::query-tooltip signal.
13762 * See also the #GtkWidget:tooltip-markup property and
13763 * gtk_tooltip_set_markup().
13768 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13769 const gchar *markup)
13771 g_return_if_fail (GTK_IS_WIDGET (widget));
13773 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13777 * gtk_widget_get_tooltip_markup:
13778 * @widget: a #GtkWidget
13780 * Gets the contents of the tooltip for @widget.
13782 * Return value: the tooltip text, or %NULL. You should free the
13783 * returned string with g_free() when done.
13788 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13790 gchar *text = NULL;
13792 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13794 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13800 * gtk_widget_set_has_tooltip:
13801 * @widget: a #GtkWidget
13802 * @has_tooltip: whether or not @widget has a tooltip.
13804 * Sets the has-tooltip property on @widget to @has_tooltip. See
13805 * #GtkWidget:has-tooltip for more information.
13810 gtk_widget_set_has_tooltip (GtkWidget *widget,
13811 gboolean has_tooltip)
13813 g_return_if_fail (GTK_IS_WIDGET (widget));
13815 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13819 * gtk_widget_get_has_tooltip:
13820 * @widget: a #GtkWidget
13822 * Returns the current value of the has-tooltip property. See
13823 * #GtkWidget:has-tooltip for more information.
13825 * Return value: current value of has-tooltip on @widget.
13830 gtk_widget_get_has_tooltip (GtkWidget *widget)
13832 gboolean has_tooltip = FALSE;
13834 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13836 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13838 return has_tooltip;
13842 * gtk_widget_get_allocation:
13843 * @widget: a #GtkWidget
13844 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13846 * Retrieves the widget's allocation.
13848 * Note, when implementing a #GtkContainer: a widget's allocation will
13849 * be its "adjusted" allocation, that is, the widget's parent
13850 * container typically calls gtk_widget_size_allocate() with an
13851 * allocation, and that allocation is then adjusted (to handle margin
13852 * and alignment for example) before assignment to the widget.
13853 * gtk_widget_get_allocation() returns the adjusted allocation that
13854 * was actually assigned to the widget. The adjusted allocation is
13855 * guaranteed to be completely contained within the
13856 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13857 * is guaranteed that its children stay inside the assigned bounds,
13858 * but not that they have exactly the bounds the container assigned.
13859 * There is no way to get the original allocation assigned by
13860 * gtk_widget_size_allocate(), since it isn't stored; if a container
13861 * implementation needs that information it will have to track it itself.
13866 gtk_widget_get_allocation (GtkWidget *widget,
13867 GtkAllocation *allocation)
13869 GtkWidgetPrivate *priv;
13871 g_return_if_fail (GTK_IS_WIDGET (widget));
13872 g_return_if_fail (allocation != NULL);
13874 priv = widget->priv;
13876 *allocation = priv->allocation;
13880 * gtk_widget_set_allocation:
13881 * @widget: a #GtkWidget
13882 * @allocation: a pointer to a #GtkAllocation to copy from
13884 * Sets the widget's allocation. This should not be used
13885 * directly, but from within a widget's size_allocate method.
13887 * The allocation set should be the "adjusted" or actual
13888 * allocation. If you're implementing a #GtkContainer, you want to use
13889 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13890 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13891 * allocation inside gtk_widget_size_allocate() to create an adjusted
13897 gtk_widget_set_allocation (GtkWidget *widget,
13898 const GtkAllocation *allocation)
13900 GtkWidgetPrivate *priv;
13902 g_return_if_fail (GTK_IS_WIDGET (widget));
13903 g_return_if_fail (allocation != NULL);
13905 priv = widget->priv;
13907 priv->allocation = *allocation;
13911 * gtk_widget_get_allocated_width:
13912 * @widget: the widget to query
13914 * Returns the width that has currently been allocated to @widget.
13915 * This function is intended to be used when implementing handlers
13916 * for the #GtkWidget::draw function.
13918 * Returns: the width of the @widget
13921 gtk_widget_get_allocated_width (GtkWidget *widget)
13923 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13925 return widget->priv->allocation.width;
13929 * gtk_widget_get_allocated_height:
13930 * @widget: the widget to query
13932 * Returns the height that has currently been allocated to @widget.
13933 * This function is intended to be used when implementing handlers
13934 * for the #GtkWidget::draw function.
13936 * Returns: the height of the @widget
13939 gtk_widget_get_allocated_height (GtkWidget *widget)
13941 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13943 return widget->priv->allocation.height;
13947 * gtk_widget_get_requisition:
13948 * @widget: a #GtkWidget
13949 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13951 * Retrieves the widget's requisition.
13953 * This function should only be used by widget implementations in
13954 * order to figure whether the widget's requisition has actually
13955 * changed after some internal state change (so that they can call
13956 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13958 * Normally, gtk_widget_size_request() should be used.
13962 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13963 * removed, If you need to cache sizes across requests and allocations,
13964 * add an explicit cache to the widget in question instead.
13967 gtk_widget_get_requisition (GtkWidget *widget,
13968 GtkRequisition *requisition)
13970 g_return_if_fail (GTK_IS_WIDGET (widget));
13971 g_return_if_fail (requisition != NULL);
13973 gtk_widget_get_preferred_size (widget, requisition, NULL);
13977 * gtk_widget_set_window:
13978 * @widget: a #GtkWidget
13979 * @window: a #GdkWindow
13981 * Sets a widget's window. This function should only be used in a
13982 * widget's #GtkWidget::realize implementation. The %window passed is
13983 * usually either new window created with gdk_window_new(), or the
13984 * window of its parent widget as returned by
13985 * gtk_widget_get_parent_window().
13987 * Widgets must indicate whether they will create their own #GdkWindow
13988 * by calling gtk_widget_set_has_window(). This is usually done in the
13989 * widget's init() function.
13991 * <note><para>This function does not add any reference to @window.</para></note>
13996 gtk_widget_set_window (GtkWidget *widget,
13999 GtkWidgetPrivate *priv;
14001 g_return_if_fail (GTK_IS_WIDGET (widget));
14002 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
14004 priv = widget->priv;
14006 if (priv->window != window)
14008 priv->window = window;
14009 g_object_notify (G_OBJECT (widget), "window");
14014 * gtk_widget_get_window:
14015 * @widget: a #GtkWidget
14017 * Returns the widget's window if it is realized, %NULL otherwise
14019 * Return value: (transfer none): @widget's window.
14024 gtk_widget_get_window (GtkWidget *widget)
14026 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14028 return widget->priv->window;
14032 * gtk_widget_get_support_multidevice:
14033 * @widget: a #GtkWidget
14035 * Returns %TRUE if @widget is multiple pointer aware. See
14036 * gtk_widget_set_support_multidevice() for more information.
14038 * Returns: %TRUE if @widget is multidevice aware.
14041 gtk_widget_get_support_multidevice (GtkWidget *widget)
14043 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
14045 return widget->priv->multidevice;
14049 * gtk_widget_set_support_multidevice:
14050 * @widget: a #GtkWidget
14051 * @support_multidevice: %TRUE to support input from multiple devices.
14053 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
14054 * @widget will start receiving multiple, per device enter/leave events. Note
14055 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
14056 * gdk_window_set_support_multidevice() will have to be called manually on them.
14061 gtk_widget_set_support_multidevice (GtkWidget *widget,
14062 gboolean support_multidevice)
14064 GtkWidgetPrivate *priv;
14066 g_return_if_fail (GTK_IS_WIDGET (widget));
14068 priv = widget->priv;
14069 priv->multidevice = (support_multidevice == TRUE);
14071 if (gtk_widget_get_realized (widget))
14072 gdk_window_set_support_multidevice (priv->window, support_multidevice);
14076 _gtk_widget_set_has_focus (GtkWidget *widget,
14077 gboolean has_focus)
14079 widget->priv->has_focus = has_focus;
14082 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
14084 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
14088 * gtk_widget_send_focus_change:
14089 * @widget: a #GtkWidget
14090 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
14092 * Sends the focus change @event to @widget
14094 * This function is not meant to be used by applications. The only time it
14095 * should be used is when it is necessary for a #GtkWidget to assign focus
14096 * to a widget that is semantically owned by the first widget even though
14097 * it's not a direct child - for instance, a search entry in a floating
14098 * window similar to the quick search in #GtkTreeView.
14100 * An example of its usage is:
14103 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
14105 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
14106 * fevent->focus_change.in = TRUE;
14107 * fevent->focus_change.window = gtk_widget_get_window (widget);
14108 * if (fevent->focus_change.window != NULL)
14109 * g_object_ref (fevent->focus_change.window);
14111 * gtk_widget_send_focus_change (widget, fevent);
14113 * gdk_event_free (event);
14116 * Return value: the return value from the event signal emission: %TRUE
14117 * if the event was handled, and %FALSE otherwise
14122 gtk_widget_send_focus_change (GtkWidget *widget,
14127 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
14128 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
14130 g_object_ref (widget);
14132 _gtk_widget_set_has_focus (widget, event->focus_change.in);
14134 res = gtk_widget_event (widget, event);
14136 g_object_notify (G_OBJECT (widget), "has-focus");
14138 g_object_unref (widget);
14144 * gtk_widget_in_destruction:
14145 * @widget: a #GtkWidget
14147 * Returns whether the widget is currently being destroyed.
14148 * This information can sometimes be used to avoid doing
14149 * unnecessary work.
14151 * Returns: %TRUE if @widget is being destroyed
14154 gtk_widget_in_destruction (GtkWidget *widget)
14156 return widget->priv->in_destruction;
14160 _gtk_widget_get_resize_pending (GtkWidget *widget)
14162 return widget->priv->resize_pending;
14166 _gtk_widget_set_resize_pending (GtkWidget *widget,
14167 gboolean resize_pending)
14169 widget->priv->resize_pending = resize_pending;
14173 _gtk_widget_get_in_reparent (GtkWidget *widget)
14175 return widget->priv->in_reparent;
14179 _gtk_widget_set_in_reparent (GtkWidget *widget,
14180 gboolean in_reparent)
14182 widget->priv->in_reparent = in_reparent;
14186 _gtk_widget_get_anchored (GtkWidget *widget)
14188 return widget->priv->anchored;
14192 _gtk_widget_set_anchored (GtkWidget *widget,
14195 widget->priv->anchored = anchored;
14199 _gtk_widget_get_shadowed (GtkWidget *widget)
14201 return widget->priv->shadowed;
14205 _gtk_widget_set_shadowed (GtkWidget *widget,
14208 widget->priv->shadowed = shadowed;
14212 _gtk_widget_get_alloc_needed (GtkWidget *widget)
14214 return widget->priv->alloc_needed;
14218 _gtk_widget_set_alloc_needed (GtkWidget *widget,
14219 gboolean alloc_needed)
14221 widget->priv->alloc_needed = alloc_needed;
14225 _gtk_widget_get_width_request_needed (GtkWidget *widget)
14227 return widget->priv->width_request_needed;
14231 _gtk_widget_set_width_request_needed (GtkWidget *widget,
14232 gboolean width_request_needed)
14234 widget->priv->width_request_needed = width_request_needed;
14238 _gtk_widget_get_height_request_needed (GtkWidget *widget)
14240 return widget->priv->height_request_needed;
14244 _gtk_widget_set_height_request_needed (GtkWidget *widget,
14245 gboolean height_request_needed)
14247 widget->priv->height_request_needed = height_request_needed;
14251 _gtk_widget_get_sizegroup_visited (GtkWidget *widget)
14253 return widget->priv->sizegroup_visited;
14257 _gtk_widget_set_sizegroup_visited (GtkWidget *widget,
14260 widget->priv->sizegroup_visited = visited;
14264 _gtk_widget_get_sizegroup_bumping (GtkWidget *widget)
14266 return widget->priv->sizegroup_bumping;
14270 _gtk_widget_set_sizegroup_bumping (GtkWidget *widget,
14273 widget->priv->sizegroup_bumping = bumping;
14277 _gtk_widget_add_sizegroup (GtkWidget *widget,
14282 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14283 groups = g_slist_prepend (groups, group);
14284 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14286 widget->priv->have_size_groups = TRUE;
14290 _gtk_widget_remove_sizegroup (GtkWidget *widget,
14295 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14296 groups = g_slist_remove (groups, group);
14297 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14299 widget->priv->have_size_groups = groups != NULL;
14303 _gtk_widget_get_sizegroups (GtkWidget *widget)
14305 if (widget->priv->have_size_groups)
14306 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14312 * gtk_widget_path_append_for_widget:
14313 * @path: a widget path
14314 * @widget: the widget to append to the widget path
14316 * Appends the data from @widget to the widget hierarchy represented
14317 * by @path. This function is a shortcut for adding information from
14318 * @widget to the given @path. This includes setting the name or
14319 * adding the style classes from @widget.
14321 * Returns: the position where the data was inserted
14326 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
14331 g_return_val_if_fail (path != NULL, 0);
14332 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14334 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
14336 if (widget->priv->name)
14337 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
14339 if (widget->priv->context)
14341 GList *classes, *l;
14343 /* Also add any persistent classes in
14344 * the style context the widget path
14346 classes = gtk_style_context_list_classes (widget->priv->context);
14348 for (l = classes; l; l = l->next)
14349 gtk_widget_path_iter_add_class (path, pos, l->data);
14351 g_list_free (classes);
14358 * gtk_widget_get_path:
14359 * @widget: a #GtkWidget
14361 * Returns the #GtkWidgetPath representing @widget, if the widget
14362 * is not connected to a toplevel widget, a partial path will be
14365 * Returns: (transfer none): The #GtkWidgetPath representing @widget
14368 gtk_widget_get_path (GtkWidget *widget)
14370 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14372 /* As strange as it may seem, this may happen on object construction.
14373 * init() implementations of parent types may eventually call this function,
14374 * each with its corresponding GType, which could leave a child
14375 * implementation with a wrong widget type in the widget path
14377 if (widget->priv->path &&
14378 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (widget->priv->path))
14380 gtk_widget_path_free (widget->priv->path);
14381 widget->priv->path = NULL;
14384 if (!widget->priv->path)
14388 parent = widget->priv->parent;
14391 widget->priv->path = gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
14394 /* Widget is either toplevel or unparented, treat both
14395 * as toplevels style wise, since there are situations
14396 * where style properties might be retrieved on that
14399 widget->priv->path = gtk_widget_path_new ();
14401 gtk_widget_path_append_for_widget (widget->priv->path, widget);
14404 if (widget->priv->context)
14405 gtk_style_context_set_path (widget->priv->context,
14406 widget->priv->path);
14409 return widget->priv->path;
14413 style_context_changed (GtkStyleContext *context,
14414 gpointer user_data)
14416 GtkWidget *widget = user_data;
14418 if (gtk_widget_get_realized (widget))
14419 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
14422 /* Compress all style updates so it
14423 * is only emitted once pre-realize.
14425 widget->priv->style_update_pending = TRUE;
14428 if (widget->priv->anchored)
14429 gtk_widget_queue_resize (widget);
14433 * gtk_widget_get_style_context:
14434 * @widget: a #GtkWidget
14436 * Returns the style context associated to @widget.
14438 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
14439 * must not be freed.
14442 gtk_widget_get_style_context (GtkWidget *widget)
14444 GtkWidgetPrivate *priv;
14445 GtkWidgetPath *path;
14447 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14449 priv = widget->priv;
14451 /* updates style context if it exists already */
14452 path = gtk_widget_get_path (widget);
14454 if (G_UNLIKELY (priv->context == NULL))
14458 priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
14459 "direction", gtk_widget_get_direction (widget),
14462 g_signal_connect (widget->priv->context, "changed",
14463 G_CALLBACK (style_context_changed), widget);
14465 screen = gtk_widget_get_screen (widget);
14468 gtk_style_context_set_screen (priv->context, screen);
14470 gtk_style_context_set_path (priv->context, path);
14473 return widget->priv->context;