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"
45 #include "gtkselectionprivate.h"
46 #include "gtksettingsprivate.h"
47 #include "gtksizegroup-private.h"
48 #include "gtkwidget.h"
49 #include "gtkwidgetprivate.h"
50 #include "gtkwindowprivate.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"
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 /* The widget's allocated size.
387 GtkAllocation allocation;
389 /* The widget's requested sizes */
390 SizeRequestCache requests;
392 /* The widget's window or its parent window if it does
393 * not have a window. (Which will be indicated by the
394 * GTK_NO_WINDOW flag being set).
398 /* The widget's parent.
402 #ifdef G_ENABLE_DEBUG
403 /* Number of gtk_widget_push_verify_invariants () */
404 guint verifying_invariants_count;
405 #endif /* G_ENABLE_DEBUG */
407 /* Widget's path for styling */
437 BUTTON_RELEASE_EVENT,
451 PROPERTY_NOTIFY_EVENT,
452 SELECTION_CLEAR_EVENT,
453 SELECTION_REQUEST_EVENT,
454 SELECTION_NOTIFY_EVENT,
459 VISIBILITY_NOTIFY_EVENT,
473 ACCEL_CLOSURES_CHANGED,
497 PROP_RECEIVES_DEFAULT,
498 PROP_COMPOSITE_CHILD,
506 PROP_DOUBLE_BUFFERED,
521 typedef struct _GtkStateData GtkStateData;
524 STATE_CHANGE_REPLACE,
533 guint use_forall : 1;
536 /* --- prototypes --- */
537 static void gtk_widget_class_init (GtkWidgetClass *klass);
538 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
539 static void gtk_widget_init (GtkWidget *widget);
540 static void gtk_widget_set_property (GObject *object,
544 static void gtk_widget_get_property (GObject *object,
548 static void gtk_widget_dispose (GObject *object);
549 static void gtk_widget_real_destroy (GtkWidget *object);
550 static void gtk_widget_finalize (GObject *object);
551 static void gtk_widget_real_show (GtkWidget *widget);
552 static void gtk_widget_real_hide (GtkWidget *widget);
553 static void gtk_widget_real_map (GtkWidget *widget);
554 static void gtk_widget_real_unmap (GtkWidget *widget);
555 static void gtk_widget_real_realize (GtkWidget *widget);
556 static void gtk_widget_real_unrealize (GtkWidget *widget);
557 static void gtk_widget_real_size_allocate (GtkWidget *widget,
558 GtkAllocation *allocation);
559 static void gtk_widget_real_style_set (GtkWidget *widget,
560 GtkStyle *previous_style);
561 static void gtk_widget_real_direction_changed(GtkWidget *widget,
562 GtkTextDirection previous_direction);
564 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
565 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
568 gboolean keyboard_tip,
569 GtkTooltip *tooltip);
570 static void gtk_widget_real_style_updated (GtkWidget *widget);
571 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
572 GtkWidgetHelpType help_type);
574 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
576 GParamSpec **pspecs);
577 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
579 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
581 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
582 GdkEventFocus *event);
583 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
584 GdkEventFocus *event);
585 static gboolean gtk_widget_real_focus (GtkWidget *widget,
586 GtkDirectionType direction);
587 static void gtk_widget_real_move_focus (GtkWidget *widget,
588 GtkDirectionType direction);
589 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
590 GtkDirectionType direction);
591 #ifdef G_ENABLE_DEBUG
592 static void gtk_widget_verify_invariants (GtkWidget *widget);
593 static void gtk_widget_push_verify_invariants (GtkWidget *widget);
594 static void gtk_widget_pop_verify_invariants (GtkWidget *widget);
596 #define gtk_widget_verify_invariants(widget)
597 #define gtk_widget_push_verify_invariants(widget)
598 #define gtk_widget_pop_verify_invariants(widget)
600 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
601 static void gtk_widget_update_pango_context (GtkWidget *widget);
602 static void gtk_widget_propagate_state (GtkWidget *widget,
605 static gint gtk_widget_event_internal (GtkWidget *widget,
607 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
608 gboolean group_cycling);
609 static void gtk_widget_real_get_width (GtkWidget *widget,
612 static void gtk_widget_real_get_height (GtkWidget *widget,
615 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
617 gint *minimum_height,
618 gint *natural_height);
619 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
622 gint *natural_width);
623 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
624 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
625 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
626 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
627 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
628 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
629 cairo_region_t *region);
630 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
631 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
632 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
635 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
636 gboolean has_tooltip,
638 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
639 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
641 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
642 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
644 const gchar *childname);
645 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
648 const GValue *value);
649 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
652 const gchar *tagname,
653 GMarkupParser *parser,
655 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
658 const gchar *tagname,
660 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
661 GtkBuilder *builder);
663 static GtkSizeRequestMode gtk_widget_real_get_request_mode (GtkWidget *widget);
664 static void gtk_widget_real_get_width (GtkWidget *widget,
667 static void gtk_widget_real_get_height (GtkWidget *widget,
671 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
674 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
675 GtkOrientation orientation,
678 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
679 GtkOrientation orientation,
683 gint *allocated_size);
685 static void gtk_widget_set_usize_internal (GtkWidget *widget,
688 GtkQueueResizeFlags flags);
690 static void gtk_widget_add_events_internal (GtkWidget *widget,
693 static void gtk_widget_set_device_enabled_internal (GtkWidget *widget,
698 /* --- variables --- */
699 static gpointer gtk_widget_parent_class = NULL;
700 static guint widget_signals[LAST_SIGNAL] = { 0 };
701 static GtkStyle *gtk_default_style = NULL;
702 static guint composite_child_stack = 0;
703 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
704 static GParamSpecPool *style_property_spec_pool = NULL;
706 static GQuark quark_property_parser = 0;
707 static GQuark quark_aux_info = 0;
708 static GQuark quark_accel_path = 0;
709 static GQuark quark_accel_closures = 0;
710 static GQuark quark_event_mask = 0;
711 static GQuark quark_device_event_mask = 0;
712 static GQuark quark_parent_window = 0;
713 static GQuark quark_pointer_window = 0;
714 static GQuark quark_shape_info = 0;
715 static GQuark quark_input_shape_info = 0;
716 static GQuark quark_pango_context = 0;
717 static GQuark quark_rc_style = 0;
718 static GQuark quark_accessible_object = 0;
719 static GQuark quark_mnemonic_labels = 0;
720 static GQuark quark_tooltip_markup = 0;
721 static GQuark quark_has_tooltip = 0;
722 static GQuark quark_tooltip_window = 0;
723 static GQuark quark_visual = 0;
724 static GQuark quark_modifier_style = 0;
725 static GQuark quark_enabled_devices = 0;
726 static GQuark quark_size_groups = 0;
727 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
728 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
730 /* --- functions --- */
732 gtk_widget_get_type (void)
734 static GType widget_type = 0;
736 if (G_UNLIKELY (widget_type == 0))
738 const GTypeInfo widget_info =
740 sizeof (GtkWidgetClass),
741 NULL, /* base_init */
742 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
743 (GClassInitFunc) gtk_widget_class_init,
744 NULL, /* class_finalize */
745 NULL, /* class_init */
748 (GInstanceInitFunc) gtk_widget_init,
749 NULL, /* value_table */
752 const GInterfaceInfo accessibility_info =
754 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
755 (GInterfaceFinalizeFunc) NULL,
756 NULL /* interface data */
759 const GInterfaceInfo buildable_info =
761 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
762 (GInterfaceFinalizeFunc) NULL,
763 NULL /* interface data */
766 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
767 &widget_info, G_TYPE_FLAG_ABSTRACT);
769 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
770 &accessibility_info) ;
771 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
779 child_property_notify_dispatcher (GObject *object,
783 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
786 /* We guard against the draw signal callbacks modifying the state of the
787 * cairo context by surounding it with save/restore.
788 * Maybe we should also cairo_new_path() just to be sure?
791 gtk_widget_draw_marshaller (GClosure *closure,
792 GValue *return_value,
793 guint n_param_values,
794 const GValue *param_values,
795 gpointer invocation_hint,
796 gpointer marshal_data)
798 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
802 _gtk_marshal_BOOLEAN__BOXED (closure,
813 gtk_widget_class_init (GtkWidgetClass *klass)
815 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
816 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
817 GtkBindingSet *binding_set;
819 gtk_widget_parent_class = g_type_class_peek_parent (klass);
821 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
822 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
823 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
824 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
825 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
826 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
827 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
828 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
829 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
830 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
831 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
832 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
833 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
834 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
835 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
836 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
837 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
838 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
839 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
840 quark_enabled_devices = g_quark_from_static_string ("gtk-widget-enabled-devices");
841 quark_size_groups = g_quark_from_static_string ("gtk-widget-size-groups");
843 style_property_spec_pool = g_param_spec_pool_new (FALSE);
844 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
845 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
846 cpn_context.dispatcher = child_property_notify_dispatcher;
847 _gtk_widget_child_property_notify_context = &cpn_context;
849 gobject_class->dispose = gtk_widget_dispose;
850 gobject_class->finalize = gtk_widget_finalize;
851 gobject_class->set_property = gtk_widget_set_property;
852 gobject_class->get_property = gtk_widget_get_property;
854 klass->destroy = gtk_widget_real_destroy;
856 klass->activate_signal = 0;
857 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
858 klass->show = gtk_widget_real_show;
859 klass->show_all = gtk_widget_show;
860 klass->hide = gtk_widget_real_hide;
861 klass->map = gtk_widget_real_map;
862 klass->unmap = gtk_widget_real_unmap;
863 klass->realize = gtk_widget_real_realize;
864 klass->unrealize = gtk_widget_real_unrealize;
865 klass->size_allocate = gtk_widget_real_size_allocate;
866 klass->get_request_mode = gtk_widget_real_get_request_mode;
867 klass->get_preferred_width = gtk_widget_real_get_width;
868 klass->get_preferred_height = gtk_widget_real_get_height;
869 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
870 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
871 klass->state_changed = NULL;
872 klass->parent_set = NULL;
873 klass->hierarchy_changed = NULL;
874 klass->style_set = gtk_widget_real_style_set;
875 klass->direction_changed = gtk_widget_real_direction_changed;
876 klass->grab_notify = NULL;
877 klass->child_notify = NULL;
879 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
880 klass->grab_focus = gtk_widget_real_grab_focus;
881 klass->focus = gtk_widget_real_focus;
882 klass->move_focus = gtk_widget_real_move_focus;
883 klass->keynav_failed = gtk_widget_real_keynav_failed;
885 klass->button_press_event = NULL;
886 klass->button_release_event = NULL;
887 klass->motion_notify_event = NULL;
888 klass->delete_event = NULL;
889 klass->destroy_event = NULL;
890 klass->key_press_event = gtk_widget_real_key_press_event;
891 klass->key_release_event = gtk_widget_real_key_release_event;
892 klass->enter_notify_event = NULL;
893 klass->leave_notify_event = NULL;
894 klass->configure_event = NULL;
895 klass->focus_in_event = gtk_widget_real_focus_in_event;
896 klass->focus_out_event = gtk_widget_real_focus_out_event;
897 klass->map_event = NULL;
898 klass->unmap_event = NULL;
899 klass->window_state_event = NULL;
900 klass->property_notify_event = _gtk_selection_property_notify;
901 klass->selection_clear_event = _gtk_selection_clear;
902 klass->selection_request_event = _gtk_selection_request;
903 klass->selection_notify_event = _gtk_selection_notify;
904 klass->selection_received = NULL;
905 klass->proximity_in_event = NULL;
906 klass->proximity_out_event = NULL;
907 klass->drag_begin = NULL;
908 klass->drag_end = NULL;
909 klass->drag_data_delete = NULL;
910 klass->drag_leave = NULL;
911 klass->drag_motion = NULL;
912 klass->drag_drop = NULL;
913 klass->drag_data_received = NULL;
914 klass->screen_changed = NULL;
915 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
916 klass->grab_broken_event = NULL;
917 klass->query_tooltip = gtk_widget_real_query_tooltip;
918 klass->style_updated = gtk_widget_real_style_updated;
920 klass->show_help = gtk_widget_real_show_help;
922 /* Accessibility support */
923 klass->get_accessible = gtk_widget_real_get_accessible;
925 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
926 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
928 g_object_class_install_property (gobject_class,
930 g_param_spec_string ("name",
932 P_("The name of the widget"),
934 GTK_PARAM_READWRITE));
935 g_object_class_install_property (gobject_class,
937 g_param_spec_object ("parent",
939 P_("The parent widget of this widget. Must be a Container widget"),
941 GTK_PARAM_READWRITE));
943 g_object_class_install_property (gobject_class,
945 g_param_spec_int ("width-request",
947 P_("Override for width request of the widget, or -1 if natural request should be used"),
951 GTK_PARAM_READWRITE));
952 g_object_class_install_property (gobject_class,
954 g_param_spec_int ("height-request",
955 P_("Height request"),
956 P_("Override for height request of the widget, or -1 if natural request should be used"),
960 GTK_PARAM_READWRITE));
961 g_object_class_install_property (gobject_class,
963 g_param_spec_boolean ("visible",
965 P_("Whether the widget is visible"),
967 GTK_PARAM_READWRITE));
968 g_object_class_install_property (gobject_class,
970 g_param_spec_boolean ("sensitive",
972 P_("Whether the widget responds to input"),
974 GTK_PARAM_READWRITE));
975 g_object_class_install_property (gobject_class,
977 g_param_spec_boolean ("app-paintable",
978 P_("Application paintable"),
979 P_("Whether the application will paint directly on the widget"),
981 GTK_PARAM_READWRITE));
982 g_object_class_install_property (gobject_class,
984 g_param_spec_boolean ("can-focus",
986 P_("Whether the widget can accept the input focus"),
988 GTK_PARAM_READWRITE));
989 g_object_class_install_property (gobject_class,
991 g_param_spec_boolean ("has-focus",
993 P_("Whether the widget has the input focus"),
995 GTK_PARAM_READWRITE));
996 g_object_class_install_property (gobject_class,
998 g_param_spec_boolean ("is-focus",
1000 P_("Whether the widget is the focus widget within the toplevel"),
1002 GTK_PARAM_READWRITE));
1003 g_object_class_install_property (gobject_class,
1005 g_param_spec_boolean ("can-default",
1007 P_("Whether the widget can be the default widget"),
1009 GTK_PARAM_READWRITE));
1010 g_object_class_install_property (gobject_class,
1012 g_param_spec_boolean ("has-default",
1014 P_("Whether the widget is the default widget"),
1016 GTK_PARAM_READWRITE));
1017 g_object_class_install_property (gobject_class,
1018 PROP_RECEIVES_DEFAULT,
1019 g_param_spec_boolean ("receives-default",
1020 P_("Receives default"),
1021 P_("If TRUE, the widget will receive the default action when it is focused"),
1023 GTK_PARAM_READWRITE));
1024 g_object_class_install_property (gobject_class,
1025 PROP_COMPOSITE_CHILD,
1026 g_param_spec_boolean ("composite-child",
1027 P_("Composite child"),
1028 P_("Whether the widget is part of a composite widget"),
1030 GTK_PARAM_READABLE));
1031 g_object_class_install_property (gobject_class,
1033 g_param_spec_object ("style",
1035 P_("The style of the widget, which contains information about how it will look (colors etc)"),
1037 GTK_PARAM_READWRITE));
1038 g_object_class_install_property (gobject_class,
1040 g_param_spec_flags ("events",
1042 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1043 GDK_TYPE_EVENT_MASK,
1045 GTK_PARAM_READWRITE));
1046 g_object_class_install_property (gobject_class,
1048 g_param_spec_boolean ("no-show-all",
1050 P_("Whether gtk_widget_show_all() should not affect this widget"),
1052 GTK_PARAM_READWRITE));
1055 * GtkWidget:has-tooltip:
1057 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1058 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1059 * the widget will be queried using #GtkWidget::query-tooltip to determine
1060 * whether it will provide a tooltip or not.
1062 * Note that setting this property to %TRUE for the first time will change
1063 * the event masks of the GdkWindows of this widget to include leave-notify
1064 * and motion-notify events. This cannot and will not be undone when the
1065 * property is set to %FALSE again.
1069 g_object_class_install_property (gobject_class,
1071 g_param_spec_boolean ("has-tooltip",
1073 P_("Whether this widget has a tooltip"),
1075 GTK_PARAM_READWRITE));
1077 * GtkWidget:tooltip-text:
1079 * Sets the text of tooltip to be the given string.
1081 * Also see gtk_tooltip_set_text().
1083 * This is a convenience property which will take care of getting the
1084 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1085 * will automatically be set to %TRUE and there will be taken care of
1086 * #GtkWidget::query-tooltip in the default signal handler.
1090 g_object_class_install_property (gobject_class,
1092 g_param_spec_string ("tooltip-text",
1094 P_("The contents of the tooltip for this widget"),
1096 GTK_PARAM_READWRITE));
1098 * GtkWidget:tooltip-markup:
1100 * Sets the text of tooltip to be the given string, which is marked up
1101 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1102 * Also see gtk_tooltip_set_markup().
1104 * This is a convenience property which will take care of getting the
1105 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1106 * will automatically be set to %TRUE and there will be taken care of
1107 * #GtkWidget::query-tooltip in the default signal handler.
1111 g_object_class_install_property (gobject_class,
1112 PROP_TOOLTIP_MARKUP,
1113 g_param_spec_string ("tooltip-markup",
1114 P_("Tooltip markup"),
1115 P_("The contents of the tooltip for this widget"),
1117 GTK_PARAM_READWRITE));
1122 * The widget's window if it is realized, %NULL otherwise.
1126 g_object_class_install_property (gobject_class,
1128 g_param_spec_object ("window",
1130 P_("The widget's window if it is realized"),
1132 GTK_PARAM_READABLE));
1135 * GtkWidget:double-buffered
1137 * Whether the widget is double buffered.
1141 g_object_class_install_property (gobject_class,
1142 PROP_DOUBLE_BUFFERED,
1143 g_param_spec_boolean ("double-buffered",
1144 P_("Double Buffered"),
1145 P_("Whether the widget is double buffered"),
1147 GTK_PARAM_READWRITE));
1152 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1156 g_object_class_install_property (gobject_class,
1158 g_param_spec_enum ("halign",
1159 P_("Horizontal Alignment"),
1160 P_("How to position in extra horizontal space"),
1163 GTK_PARAM_READWRITE));
1168 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1172 g_object_class_install_property (gobject_class,
1174 g_param_spec_enum ("valign",
1175 P_("Vertical Alignment"),
1176 P_("How to position in extra vertical space"),
1179 GTK_PARAM_READWRITE));
1182 * GtkWidget:margin-left
1184 * Margin on left side of widget.
1186 * This property adds margin outside of the widget's normal size
1187 * request, the margin will be added in addition to the size from
1188 * gtk_widget_set_size_request() for example.
1192 g_object_class_install_property (gobject_class,
1194 g_param_spec_int ("margin-left",
1195 P_("Margin on Left"),
1196 P_("Pixels of extra space on the left side"),
1200 GTK_PARAM_READWRITE));
1203 * GtkWidget:margin-right
1205 * Margin on right side of widget.
1207 * This property adds margin outside of the widget's normal size
1208 * request, the margin will be added in addition to the size from
1209 * gtk_widget_set_size_request() for example.
1213 g_object_class_install_property (gobject_class,
1215 g_param_spec_int ("margin-right",
1216 P_("Margin on Right"),
1217 P_("Pixels of extra space on the right side"),
1221 GTK_PARAM_READWRITE));
1224 * GtkWidget:margin-top
1226 * Margin on top side of widget.
1228 * This property adds margin outside of the widget's normal size
1229 * request, the margin will be added in addition to the size from
1230 * gtk_widget_set_size_request() for example.
1234 g_object_class_install_property (gobject_class,
1236 g_param_spec_int ("margin-top",
1237 P_("Margin on Top"),
1238 P_("Pixels of extra space on the top side"),
1242 GTK_PARAM_READWRITE));
1245 * GtkWidget:margin-bottom
1247 * Margin on bottom side of widget.
1249 * This property adds margin outside of the widget's normal size
1250 * request, the margin will be added in addition to the size from
1251 * gtk_widget_set_size_request() for example.
1255 g_object_class_install_property (gobject_class,
1257 g_param_spec_int ("margin-bottom",
1258 P_("Margin on Bottom"),
1259 P_("Pixels of extra space on the bottom side"),
1263 GTK_PARAM_READWRITE));
1268 * Sets all four sides' margin at once. If read, returns max
1269 * margin on any side.
1273 g_object_class_install_property (gobject_class,
1275 g_param_spec_int ("margin",
1277 P_("Pixels of extra space on all four sides"),
1281 GTK_PARAM_READWRITE));
1284 * GtkWidget::destroy:
1285 * @object: the object which received the signal
1287 * Signals that all holders of a reference to the widget should release
1288 * the reference that they hold. May result in finalization of the widget
1289 * if all references are released.
1291 widget_signals[DESTROY] =
1292 g_signal_new (I_("destroy"),
1293 G_TYPE_FROM_CLASS (gobject_class),
1294 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1295 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1297 _gtk_marshal_VOID__VOID,
1303 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1307 g_object_class_install_property (gobject_class,
1309 g_param_spec_boolean ("hexpand",
1310 P_("Horizontal Expand"),
1311 P_("Whether widget wants more horizontal space"),
1313 GTK_PARAM_READWRITE));
1316 * GtkWidget:hexpand-set
1318 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1322 g_object_class_install_property (gobject_class,
1324 g_param_spec_boolean ("hexpand-set",
1325 P_("Horizontal Expand Set"),
1326 P_("Whether to use the hexpand property"),
1328 GTK_PARAM_READWRITE));
1333 * Whether to expand vertically. See gtk_widget_set_vexpand().
1337 g_object_class_install_property (gobject_class,
1339 g_param_spec_boolean ("vexpand",
1340 P_("Vertical Expand"),
1341 P_("Whether widget wants more vertical space"),
1343 GTK_PARAM_READWRITE));
1346 * GtkWidget:vexpand-set
1348 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1352 g_object_class_install_property (gobject_class,
1354 g_param_spec_boolean ("vexpand-set",
1355 P_("Vertical Expand Set"),
1356 P_("Whether to use the vexpand property"),
1358 GTK_PARAM_READWRITE));
1363 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1367 g_object_class_install_property (gobject_class,
1369 g_param_spec_boolean ("expand",
1371 P_("Whether widget wants to expand in both directions"),
1373 GTK_PARAM_READWRITE));
1377 * @widget: the object which received the signal.
1379 widget_signals[SHOW] =
1380 g_signal_new (I_("show"),
1381 G_TYPE_FROM_CLASS (gobject_class),
1383 G_STRUCT_OFFSET (GtkWidgetClass, show),
1385 _gtk_marshal_VOID__VOID,
1390 * @widget: the object which received the signal.
1392 widget_signals[HIDE] =
1393 g_signal_new (I_("hide"),
1394 G_TYPE_FROM_CLASS (gobject_class),
1396 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1398 _gtk_marshal_VOID__VOID,
1403 * @widget: the object which received the signal.
1405 widget_signals[MAP] =
1406 g_signal_new (I_("map"),
1407 G_TYPE_FROM_CLASS (gobject_class),
1409 G_STRUCT_OFFSET (GtkWidgetClass, map),
1411 _gtk_marshal_VOID__VOID,
1416 * @widget: the object which received the signal.
1418 widget_signals[UNMAP] =
1419 g_signal_new (I_("unmap"),
1420 G_TYPE_FROM_CLASS (gobject_class),
1422 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1424 _gtk_marshal_VOID__VOID,
1428 * GtkWidget::realize:
1429 * @widget: the object which received the signal.
1431 widget_signals[REALIZE] =
1432 g_signal_new (I_("realize"),
1433 G_TYPE_FROM_CLASS (gobject_class),
1435 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1437 _gtk_marshal_VOID__VOID,
1441 * GtkWidget::unrealize:
1442 * @widget: the object which received the signal.
1444 widget_signals[UNREALIZE] =
1445 g_signal_new (I_("unrealize"),
1446 G_TYPE_FROM_CLASS (gobject_class),
1448 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1450 _gtk_marshal_VOID__VOID,
1454 * GtkWidget::size-allocate:
1455 * @widget: the object which received the signal.
1458 widget_signals[SIZE_ALLOCATE] =
1459 g_signal_new (I_("size-allocate"),
1460 G_TYPE_FROM_CLASS (gobject_class),
1462 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1464 _gtk_marshal_VOID__BOXED,
1466 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1469 * GtkWidget::state-changed:
1470 * @widget: the object which received the signal.
1471 * @state: the previous state
1473 * The ::state-changed signal is emitted when the widget state changes.
1474 * See gtk_widget_get_state().
1476 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1478 widget_signals[STATE_CHANGED] =
1479 g_signal_new (I_("state-changed"),
1480 G_TYPE_FROM_CLASS (gobject_class),
1482 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1484 _gtk_marshal_VOID__ENUM,
1486 GTK_TYPE_STATE_TYPE);
1489 * GtkWidget::state-flags-changed:
1490 * @widget: the object which received the signal.
1491 * @flags: The previous state flags.
1493 * The ::state-flags-changed signal is emitted when the widget state
1494 * changes, see gtk_widget_get_state_flags().
1498 widget_signals[STATE_FLAGS_CHANGED] =
1499 g_signal_new (I_("state-flags-changed"),
1500 G_TYPE_FROM_CLASS (gobject_class),
1502 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1504 _gtk_marshal_VOID__FLAGS,
1506 GTK_TYPE_STATE_FLAGS);
1509 * GtkWidget::parent-set:
1510 * @widget: the object on which the signal is emitted
1511 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1512 * just got its initial parent.
1514 * The ::parent-set signal is emitted when a new parent
1515 * has been set on a widget.
1517 widget_signals[PARENT_SET] =
1518 g_signal_new (I_("parent-set"),
1519 G_TYPE_FROM_CLASS (gobject_class),
1521 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1523 _gtk_marshal_VOID__OBJECT,
1528 * GtkWidget::hierarchy-changed:
1529 * @widget: the object on which the signal is emitted
1530 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1531 * if the widget was previously unanchored
1533 * The ::hierarchy-changed signal is emitted when the
1534 * anchored state of a widget changes. A widget is
1535 * <firstterm>anchored</firstterm> when its toplevel
1536 * ancestor is a #GtkWindow. This signal is emitted when
1537 * a widget changes from un-anchored to anchored or vice-versa.
1539 widget_signals[HIERARCHY_CHANGED] =
1540 g_signal_new (I_("hierarchy-changed"),
1541 G_TYPE_FROM_CLASS (gobject_class),
1543 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1545 _gtk_marshal_VOID__OBJECT,
1550 * GtkWidget::style-set:
1551 * @widget: the object on which the signal is emitted
1552 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1553 * just got its initial style
1555 * The ::style-set signal is emitted when a new style has been set
1556 * on a widget. Note that style-modifying functions like
1557 * gtk_widget_modify_base() also cause this signal to be emitted.
1559 * Note that this signal is emitted for changes to the deprecated
1560 * #GtkStyle. To track changes to the #GtkStyleContext associated
1561 * with a widget, use the #GtkWidget::style-updated signal.
1563 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1565 widget_signals[STYLE_SET] =
1566 g_signal_new (I_("style-set"),
1567 G_TYPE_FROM_CLASS (gobject_class),
1569 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1571 _gtk_marshal_VOID__OBJECT,
1576 * GtkWidget::style-updated:
1577 * @widget: the object on which the signal is emitted
1579 * The ::style-updated signal is emitted when the #GtkStyleContext
1580 * of a widget is changed. Note that style-modifying functions like
1581 * gtk_widget_override_color() also cause this signal to be emitted.
1585 widget_signals[STYLE_UPDATED] =
1586 g_signal_new (I_("style-updated"),
1587 G_TYPE_FROM_CLASS (gobject_class),
1589 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1591 g_cclosure_marshal_VOID__VOID,
1595 * GtkWidget::direction-changed:
1596 * @widget: the object on which the signal is emitted
1597 * @previous_direction: the previous text direction of @widget
1599 * The ::direction-changed signal is emitted when the text direction
1600 * of a widget changes.
1602 widget_signals[DIRECTION_CHANGED] =
1603 g_signal_new (I_("direction-changed"),
1604 G_TYPE_FROM_CLASS (gobject_class),
1606 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1608 _gtk_marshal_VOID__ENUM,
1610 GTK_TYPE_TEXT_DIRECTION);
1613 * GtkWidget::grab-notify:
1614 * @widget: the object which received the signal
1615 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1616 * if it becomes unshadowed
1618 * The ::grab-notify signal is emitted when a widget becomes
1619 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1620 * another widget, or when it becomes unshadowed due to a grab
1623 * A widget is shadowed by a gtk_grab_add() when the topmost
1624 * grab widget in the grab stack of its window group is not
1627 widget_signals[GRAB_NOTIFY] =
1628 g_signal_new (I_("grab-notify"),
1629 G_TYPE_FROM_CLASS (gobject_class),
1631 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1633 _gtk_marshal_VOID__BOOLEAN,
1638 * GtkWidget::child-notify:
1639 * @widget: the object which received the signal
1640 * @pspec: the #GParamSpec of the changed child property
1642 * The ::child-notify signal is emitted for each
1643 * <link linkend="child-properties">child property</link> that has
1644 * changed on an object. The signal's detail holds the property name.
1646 widget_signals[CHILD_NOTIFY] =
1647 g_signal_new (I_("child-notify"),
1648 G_TYPE_FROM_CLASS (gobject_class),
1649 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1650 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1652 g_cclosure_marshal_VOID__PARAM,
1658 * @widget: the object which received the signal
1659 * @cr: the cairo context to draw to
1661 * This signal is emitted when a widget is supposed to render itself.
1662 * The @widget's top left corner must be painted at the origin of
1663 * the passed in context and be sized to the values returned by
1664 * gtk_widget_get_allocated_width() and
1665 * gtk_widget_get_allocated_height().
1667 * Signal handlers connected to this signal can modify the cairo
1668 * context passed as @cr in any way they like and don't need to
1669 * restore it. The signal emission takes care of calling cairo_save()
1670 * before and cairo_restore() after invoking the handler.
1672 widget_signals[DRAW] =
1673 g_signal_new (I_("draw"),
1674 G_TYPE_FROM_CLASS (gobject_class),
1676 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1677 _gtk_boolean_handled_accumulator, NULL,
1678 gtk_widget_draw_marshaller,
1680 CAIRO_GOBJECT_TYPE_CONTEXT);
1683 * GtkWidget::mnemonic-activate:
1684 * @widget: the object which received the signal.
1687 widget_signals[MNEMONIC_ACTIVATE] =
1688 g_signal_new (I_("mnemonic-activate"),
1689 G_TYPE_FROM_CLASS (gobject_class),
1691 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1692 _gtk_boolean_handled_accumulator, NULL,
1693 _gtk_marshal_BOOLEAN__BOOLEAN,
1698 * GtkWidget::grab-focus:
1699 * @widget: the object which received the signal.
1701 widget_signals[GRAB_FOCUS] =
1702 g_signal_new (I_("grab-focus"),
1703 G_TYPE_FROM_CLASS (gobject_class),
1704 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1705 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1707 _gtk_marshal_VOID__VOID,
1712 * @widget: the object which received the signal.
1715 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1717 widget_signals[FOCUS] =
1718 g_signal_new (I_("focus"),
1719 G_TYPE_FROM_CLASS (klass),
1721 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1722 _gtk_boolean_handled_accumulator, NULL,
1723 _gtk_marshal_BOOLEAN__ENUM,
1725 GTK_TYPE_DIRECTION_TYPE);
1728 * GtkWidget::move-focus:
1729 * @widget: the object which received the signal.
1732 widget_signals[MOVE_FOCUS] =
1733 g_signal_new (I_("move-focus"),
1734 G_TYPE_FROM_CLASS (klass),
1735 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1736 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1738 _gtk_marshal_VOID__ENUM,
1741 GTK_TYPE_DIRECTION_TYPE);
1744 * GtkWidget::keynav-failed:
1745 * @widget: the object which received the signal
1746 * @direction: the direction of movement
1748 * Gets emitted if keyboard navigation fails.
1749 * See gtk_widget_keynav_failed() for details.
1751 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1752 * if the emitting widget should try to handle the keyboard
1753 * navigation attempt in its parent container(s).
1757 widget_signals[KEYNAV_FAILED] =
1758 g_signal_new (I_("keynav-failed"),
1759 G_TYPE_FROM_CLASS (klass),
1761 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1762 _gtk_boolean_handled_accumulator, NULL,
1763 _gtk_marshal_BOOLEAN__ENUM,
1765 GTK_TYPE_DIRECTION_TYPE);
1769 * @widget: the object which received the signal.
1770 * @event: the #GdkEvent which triggered this signal
1772 * The GTK+ main loop will emit three signals for each GDK event delivered
1773 * to a widget: one generic ::event signal, another, more specific,
1774 * signal that matches the type of event delivered (e.g.
1775 * #GtkWidget::key-press-event) and finally a generic
1776 * #GtkWidget::event-after signal.
1778 * Returns: %TRUE to stop other handlers from being invoked for the event
1779 * and to cancel the emission of the second specific ::event signal.
1780 * %FALSE to propagate the event further and to allow the emission of
1781 * the second signal. The ::event-after signal is emitted regardless of
1784 widget_signals[EVENT] =
1785 g_signal_new (I_("event"),
1786 G_TYPE_FROM_CLASS (klass),
1788 G_STRUCT_OFFSET (GtkWidgetClass, event),
1789 _gtk_boolean_handled_accumulator, NULL,
1790 _gtk_marshal_BOOLEAN__BOXED,
1792 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1795 * GtkWidget::event-after:
1796 * @widget: the object which received the signal.
1797 * @event: the #GdkEvent which triggered this signal
1799 * After the emission of the #GtkWidget::event signal and (optionally)
1800 * the second more specific signal, ::event-after will be emitted
1801 * regardless of the previous two signals handlers return values.
1804 widget_signals[EVENT_AFTER] =
1805 g_signal_new (I_("event-after"),
1806 G_TYPE_FROM_CLASS (klass),
1810 _gtk_marshal_VOID__BOXED,
1812 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1815 * GtkWidget::button-press-event:
1816 * @widget: the object which received the signal.
1817 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1820 * The ::button-press-event signal will be emitted when a button
1821 * (typically from a mouse) is pressed.
1823 * To receive this signal, the #GdkWindow associated to the
1824 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1826 * This signal will be sent to the grab widget if there is one.
1828 * Returns: %TRUE to stop other handlers from being invoked for the event.
1829 * %FALSE to propagate the event further.
1831 widget_signals[BUTTON_PRESS_EVENT] =
1832 g_signal_new (I_("button-press-event"),
1833 G_TYPE_FROM_CLASS (klass),
1835 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1836 _gtk_boolean_handled_accumulator, NULL,
1837 _gtk_marshal_BOOLEAN__BOXED,
1839 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1842 * GtkWidget::button-release-event:
1843 * @widget: the object which received the signal.
1844 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1847 * The ::button-release-event signal will be emitted when a button
1848 * (typically from a mouse) is released.
1850 * To receive this signal, the #GdkWindow associated to the
1851 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1853 * This signal will be sent to the grab widget if there is one.
1855 * Returns: %TRUE to stop other handlers from being invoked for the event.
1856 * %FALSE to propagate the event further.
1858 widget_signals[BUTTON_RELEASE_EVENT] =
1859 g_signal_new (I_("button-release-event"),
1860 G_TYPE_FROM_CLASS (klass),
1862 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1863 _gtk_boolean_handled_accumulator, NULL,
1864 _gtk_marshal_BOOLEAN__BOXED,
1866 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1869 * GtkWidget::scroll-event:
1870 * @widget: the object which received the signal.
1871 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1874 * The ::scroll-event signal is emitted when a button in the 4 to 7
1875 * range is pressed. Wheel mice are usually configured to generate
1876 * button press events for buttons 4 and 5 when the wheel is turned.
1878 * To receive this signal, the #GdkWindow associated to the widget needs
1879 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1881 * This signal will be sent to the grab widget if there is one.
1883 * Returns: %TRUE to stop other handlers from being invoked for the event.
1884 * %FALSE to propagate the event further.
1886 widget_signals[SCROLL_EVENT] =
1887 g_signal_new (I_("scroll-event"),
1888 G_TYPE_FROM_CLASS (klass),
1890 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1891 _gtk_boolean_handled_accumulator, NULL,
1892 _gtk_marshal_BOOLEAN__BOXED,
1894 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1897 * GtkWidget::motion-notify-event:
1898 * @widget: the object which received the signal.
1899 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1902 * The ::motion-notify-event signal is emitted when the pointer moves
1903 * over the widget's #GdkWindow.
1905 * To receive this signal, the #GdkWindow associated to the widget
1906 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1908 * This signal will be sent to the grab widget if there is one.
1910 * Returns: %TRUE to stop other handlers from being invoked for the event.
1911 * %FALSE to propagate the event further.
1913 widget_signals[MOTION_NOTIFY_EVENT] =
1914 g_signal_new (I_("motion-notify-event"),
1915 G_TYPE_FROM_CLASS (klass),
1917 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1918 _gtk_boolean_handled_accumulator, NULL,
1919 _gtk_marshal_BOOLEAN__BOXED,
1921 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1924 * GtkWidget::composited-changed:
1925 * @widget: the object on which the signal is emitted
1927 * The ::composited-changed signal is emitted when the composited
1928 * status of @widget<!-- -->s screen changes.
1929 * See gdk_screen_is_composited().
1931 widget_signals[COMPOSITED_CHANGED] =
1932 g_signal_new (I_("composited-changed"),
1933 G_TYPE_FROM_CLASS (klass),
1934 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1935 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1937 _gtk_marshal_VOID__VOID,
1941 * GtkWidget::delete-event:
1942 * @widget: the object which received the signal
1943 * @event: the event which triggered this signal
1945 * The ::delete-event signal is emitted if a user requests that
1946 * a toplevel window is closed. The default handler for this signal
1947 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1948 * this signal will cause the window to be hidden instead, so that
1949 * it can later be shown again without reconstructing it.
1951 * Returns: %TRUE to stop other handlers from being invoked for the event.
1952 * %FALSE to propagate the event further.
1954 widget_signals[DELETE_EVENT] =
1955 g_signal_new (I_("delete-event"),
1956 G_TYPE_FROM_CLASS (klass),
1958 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1959 _gtk_boolean_handled_accumulator, NULL,
1960 _gtk_marshal_BOOLEAN__BOXED,
1962 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1965 * GtkWidget::destroy-event:
1966 * @widget: the object which received the signal.
1967 * @event: the event which triggered this signal
1969 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1970 * You rarely get this signal, because most widgets disconnect themselves
1971 * from their window before they destroy it, so no widget owns the
1972 * window at destroy time.
1974 * To receive this signal, the #GdkWindow associated to the widget needs
1975 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1976 * automatically for all new windows.
1978 * Returns: %TRUE to stop other handlers from being invoked for the event.
1979 * %FALSE to propagate the event further.
1981 widget_signals[DESTROY_EVENT] =
1982 g_signal_new (I_("destroy-event"),
1983 G_TYPE_FROM_CLASS (klass),
1985 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1986 _gtk_boolean_handled_accumulator, NULL,
1987 _gtk_marshal_BOOLEAN__BOXED,
1989 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1992 * GtkWidget::key-press-event:
1993 * @widget: the object which received the signal
1994 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1996 * The ::key-press-event signal is emitted when a key is pressed. The signal
1997 * emission will reoccur at the key-repeat rate when the key is kept pressed.
1999 * To receive this signal, the #GdkWindow associated to the widget needs
2000 * to enable the #GDK_KEY_PRESS_MASK mask.
2002 * This signal will be sent to the grab widget if there is one.
2004 * Returns: %TRUE to stop other handlers from being invoked for the event.
2005 * %FALSE to propagate the event further.
2007 widget_signals[KEY_PRESS_EVENT] =
2008 g_signal_new (I_("key-press-event"),
2009 G_TYPE_FROM_CLASS (klass),
2011 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
2012 _gtk_boolean_handled_accumulator, NULL,
2013 _gtk_marshal_BOOLEAN__BOXED,
2015 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2018 * GtkWidget::key-release-event:
2019 * @widget: the object which received the signal
2020 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2022 * The ::key-release-event signal is emitted when a key is released.
2024 * To receive this signal, the #GdkWindow associated to the widget needs
2025 * to enable the #GDK_KEY_RELEASE_MASK mask.
2027 * This signal will be sent to the grab widget if there is one.
2029 * Returns: %TRUE to stop other handlers from being invoked for the event.
2030 * %FALSE to propagate the event further.
2032 widget_signals[KEY_RELEASE_EVENT] =
2033 g_signal_new (I_("key-release-event"),
2034 G_TYPE_FROM_CLASS (klass),
2036 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2037 _gtk_boolean_handled_accumulator, NULL,
2038 _gtk_marshal_BOOLEAN__BOXED,
2040 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2043 * GtkWidget::enter-notify-event:
2044 * @widget: the object which received the signal
2045 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2048 * The ::enter-notify-event will be emitted when the pointer enters
2049 * the @widget's window.
2051 * To receive this signal, the #GdkWindow associated to the widget needs
2052 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2054 * This signal will be sent to the grab widget if there is one.
2056 * Returns: %TRUE to stop other handlers from being invoked for the event.
2057 * %FALSE to propagate the event further.
2059 widget_signals[ENTER_NOTIFY_EVENT] =
2060 g_signal_new (I_("enter-notify-event"),
2061 G_TYPE_FROM_CLASS (klass),
2063 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2064 _gtk_boolean_handled_accumulator, NULL,
2065 _gtk_marshal_BOOLEAN__BOXED,
2067 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2070 * GtkWidget::leave-notify-event:
2071 * @widget: the object which received the signal
2072 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2075 * The ::leave-notify-event will be emitted when the pointer leaves
2076 * the @widget's window.
2078 * To receive this signal, the #GdkWindow associated to the widget needs
2079 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2081 * This signal will be sent to the grab widget if there is one.
2083 * Returns: %TRUE to stop other handlers from being invoked for the event.
2084 * %FALSE to propagate the event further.
2086 widget_signals[LEAVE_NOTIFY_EVENT] =
2087 g_signal_new (I_("leave-notify-event"),
2088 G_TYPE_FROM_CLASS (klass),
2090 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2091 _gtk_boolean_handled_accumulator, NULL,
2092 _gtk_marshal_BOOLEAN__BOXED,
2094 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2097 * GtkWidget::configure-event:
2098 * @widget: the object which received the signal
2099 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2102 * The ::configure-event signal will be emitted when the size, position or
2103 * stacking of the @widget's window has changed.
2105 * To receive this signal, the #GdkWindow associated to the widget needs
2106 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2107 * automatically for all new windows.
2109 * Returns: %TRUE to stop other handlers from being invoked for the event.
2110 * %FALSE to propagate the event further.
2112 widget_signals[CONFIGURE_EVENT] =
2113 g_signal_new (I_("configure-event"),
2114 G_TYPE_FROM_CLASS (klass),
2116 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2117 _gtk_boolean_handled_accumulator, NULL,
2118 _gtk_marshal_BOOLEAN__BOXED,
2120 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2123 * GtkWidget::focus-in-event:
2124 * @widget: the object which received the signal
2125 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2128 * The ::focus-in-event signal will be emitted when the keyboard focus
2129 * enters the @widget's window.
2131 * To receive this signal, the #GdkWindow associated to the widget needs
2132 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2134 * Returns: %TRUE to stop other handlers from being invoked for the event.
2135 * %FALSE to propagate the event further.
2137 widget_signals[FOCUS_IN_EVENT] =
2138 g_signal_new (I_("focus-in-event"),
2139 G_TYPE_FROM_CLASS (klass),
2141 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2142 _gtk_boolean_handled_accumulator, NULL,
2143 _gtk_marshal_BOOLEAN__BOXED,
2145 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2148 * GtkWidget::focus-out-event:
2149 * @widget: the object which received the signal
2150 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2153 * The ::focus-out-event signal will be emitted when the keyboard focus
2154 * leaves the @widget's window.
2156 * To receive this signal, the #GdkWindow associated to the widget needs
2157 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2159 * Returns: %TRUE to stop other handlers from being invoked for the event.
2160 * %FALSE to propagate the event further.
2162 widget_signals[FOCUS_OUT_EVENT] =
2163 g_signal_new (I_("focus-out-event"),
2164 G_TYPE_FROM_CLASS (klass),
2166 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2167 _gtk_boolean_handled_accumulator, NULL,
2168 _gtk_marshal_BOOLEAN__BOXED,
2170 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2173 * GtkWidget::map-event:
2174 * @widget: the object which received the signal
2175 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2177 * The ::map-event signal will be emitted when the @widget's window is
2178 * mapped. A window is mapped when it becomes visible on the screen.
2180 * To receive this signal, the #GdkWindow associated to the widget needs
2181 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2182 * automatically for all new windows.
2184 * Returns: %TRUE to stop other handlers from being invoked for the event.
2185 * %FALSE to propagate the event further.
2187 widget_signals[MAP_EVENT] =
2188 g_signal_new (I_("map-event"),
2189 G_TYPE_FROM_CLASS (klass),
2191 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2192 _gtk_boolean_handled_accumulator, NULL,
2193 _gtk_marshal_BOOLEAN__BOXED,
2195 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2198 * GtkWidget::unmap-event:
2199 * @widget: the object which received the signal
2200 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2202 * The ::unmap-event signal will be emitted when the @widget's window is
2203 * unmapped. A window is unmapped when it becomes invisible on the screen.
2205 * To receive this signal, the #GdkWindow associated to the widget needs
2206 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2207 * automatically for all new windows.
2209 * Returns: %TRUE to stop other handlers from being invoked for the event.
2210 * %FALSE to propagate the event further.
2212 widget_signals[UNMAP_EVENT] =
2213 g_signal_new (I_("unmap-event"),
2214 G_TYPE_FROM_CLASS (klass),
2216 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2217 _gtk_boolean_handled_accumulator, NULL,
2218 _gtk_marshal_BOOLEAN__BOXED,
2220 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2223 * GtkWidget::property-notify-event:
2224 * @widget: the object which received the signal
2225 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2228 * The ::property-notify-event signal will be emitted when a property on
2229 * the @widget's window has been changed or deleted.
2231 * To receive this signal, the #GdkWindow associated to the widget needs
2232 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2234 * Returns: %TRUE to stop other handlers from being invoked for the event.
2235 * %FALSE to propagate the event further.
2237 widget_signals[PROPERTY_NOTIFY_EVENT] =
2238 g_signal_new (I_("property-notify-event"),
2239 G_TYPE_FROM_CLASS (klass),
2241 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2242 _gtk_boolean_handled_accumulator, NULL,
2243 _gtk_marshal_BOOLEAN__BOXED,
2245 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2248 * GtkWidget::selection-clear-event:
2249 * @widget: the object which received the signal
2250 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2253 * The ::selection-clear-event signal will be emitted when the
2254 * the @widget's window has lost ownership of a selection.
2256 * Returns: %TRUE to stop other handlers from being invoked for the event.
2257 * %FALSE to propagate the event further.
2259 widget_signals[SELECTION_CLEAR_EVENT] =
2260 g_signal_new (I_("selection-clear-event"),
2261 G_TYPE_FROM_CLASS (klass),
2263 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2264 _gtk_boolean_handled_accumulator, NULL,
2265 _gtk_marshal_BOOLEAN__BOXED,
2267 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2270 * GtkWidget::selection-request-event:
2271 * @widget: the object which received the signal
2272 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2275 * The ::selection-request-event signal will be emitted when
2276 * another client requests ownership of the selection owned by
2277 * the @widget's window.
2279 * Returns: %TRUE to stop other handlers from being invoked for the event.
2280 * %FALSE to propagate the event further.
2282 widget_signals[SELECTION_REQUEST_EVENT] =
2283 g_signal_new (I_("selection-request-event"),
2284 G_TYPE_FROM_CLASS (klass),
2286 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2287 _gtk_boolean_handled_accumulator, NULL,
2288 _gtk_marshal_BOOLEAN__BOXED,
2290 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2293 * GtkWidget::selection-notify-event:
2294 * @widget: the object which received the signal.
2295 * @event: (type Gdk.EventSelection):
2297 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2299 widget_signals[SELECTION_NOTIFY_EVENT] =
2300 g_signal_new (I_("selection-notify-event"),
2301 G_TYPE_FROM_CLASS (klass),
2303 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2304 _gtk_boolean_handled_accumulator, NULL,
2305 _gtk_marshal_BOOLEAN__BOXED,
2307 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2310 * GtkWidget::selection-received:
2311 * @widget: the object which received the signal.
2315 widget_signals[SELECTION_RECEIVED] =
2316 g_signal_new (I_("selection-received"),
2317 G_TYPE_FROM_CLASS (klass),
2319 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2321 _gtk_marshal_VOID__BOXED_UINT,
2323 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2327 * GtkWidget::selection-get:
2328 * @widget: the object which received the signal.
2333 widget_signals[SELECTION_GET] =
2334 g_signal_new (I_("selection-get"),
2335 G_TYPE_FROM_CLASS (klass),
2337 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2339 _gtk_marshal_VOID__BOXED_UINT_UINT,
2341 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2346 * GtkWidget::proximity-in-event:
2347 * @widget: the object which received the signal
2348 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2351 * To receive this signal the #GdkWindow associated to the widget needs
2352 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2354 * This signal will be sent to the grab widget if there is one.
2356 * Returns: %TRUE to stop other handlers from being invoked for the event.
2357 * %FALSE to propagate the event further.
2359 widget_signals[PROXIMITY_IN_EVENT] =
2360 g_signal_new (I_("proximity-in-event"),
2361 G_TYPE_FROM_CLASS (klass),
2363 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2364 _gtk_boolean_handled_accumulator, NULL,
2365 _gtk_marshal_BOOLEAN__BOXED,
2367 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2370 * GtkWidget::proximity-out-event:
2371 * @widget: the object which received the signal
2372 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2375 * To receive this signal the #GdkWindow associated to the widget needs
2376 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2378 * This signal will be sent to the grab widget if there is one.
2380 * Returns: %TRUE to stop other handlers from being invoked for the event.
2381 * %FALSE to propagate the event further.
2383 widget_signals[PROXIMITY_OUT_EVENT] =
2384 g_signal_new (I_("proximity-out-event"),
2385 G_TYPE_FROM_CLASS (klass),
2387 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2388 _gtk_boolean_handled_accumulator, NULL,
2389 _gtk_marshal_BOOLEAN__BOXED,
2391 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2394 * GtkWidget::drag-leave:
2395 * @widget: the object which received the signal.
2396 * @drag_context: the drag context
2397 * @time: the timestamp of the motion event
2399 * The ::drag-leave signal is emitted on the drop site when the cursor
2400 * leaves the widget. A typical reason to connect to this signal is to
2401 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2402 * with gtk_drag_unhighlight()
2404 widget_signals[DRAG_LEAVE] =
2405 g_signal_new (I_("drag-leave"),
2406 G_TYPE_FROM_CLASS (klass),
2408 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2410 _gtk_marshal_VOID__OBJECT_UINT,
2412 GDK_TYPE_DRAG_CONTEXT,
2416 * GtkWidget::drag-begin:
2417 * @widget: the object which received the signal
2418 * @drag_context: the drag context
2420 * The ::drag-begin signal is emitted on the drag source when a drag is
2421 * started. A typical reason to connect to this signal is to set up a
2422 * custom drag icon with gtk_drag_source_set_icon().
2424 * Note that some widgets set up a drag icon in the default handler of
2425 * this signal, so you may have to use g_signal_connect_after() to
2426 * override what the default handler did.
2428 widget_signals[DRAG_BEGIN] =
2429 g_signal_new (I_("drag-begin"),
2430 G_TYPE_FROM_CLASS (klass),
2432 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2434 _gtk_marshal_VOID__OBJECT,
2436 GDK_TYPE_DRAG_CONTEXT);
2439 * GtkWidget::drag-end:
2440 * @widget: the object which received the signal
2441 * @drag_context: the drag context
2443 * The ::drag-end signal is emitted on the drag source when a drag is
2444 * finished. A typical reason to connect to this signal is to undo
2445 * things done in #GtkWidget::drag-begin.
2447 widget_signals[DRAG_END] =
2448 g_signal_new (I_("drag-end"),
2449 G_TYPE_FROM_CLASS (klass),
2451 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2453 _gtk_marshal_VOID__OBJECT,
2455 GDK_TYPE_DRAG_CONTEXT);
2458 * GtkWidget::drag-data-delete:
2459 * @widget: the object which received the signal
2460 * @drag_context: the drag context
2462 * The ::drag-data-delete signal is emitted on the drag source when a drag
2463 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2464 * handler is responsible for deleting the data that has been dropped. What
2465 * "delete" means depends on the context of the drag operation.
2467 widget_signals[DRAG_DATA_DELETE] =
2468 g_signal_new (I_("drag-data-delete"),
2469 G_TYPE_FROM_CLASS (klass),
2471 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2473 _gtk_marshal_VOID__OBJECT,
2475 GDK_TYPE_DRAG_CONTEXT);
2478 * GtkWidget::drag-failed:
2479 * @widget: the object which received the signal
2480 * @drag_context: the drag context
2481 * @result: the result of the drag operation
2483 * The ::drag-failed signal is emitted on the drag source when a drag has
2484 * failed. The signal handler may hook custom code to handle a failed DND
2485 * operation based on the type of error, it returns %TRUE is the failure has
2486 * been already handled (not showing the default "drag operation failed"
2487 * animation), otherwise it returns %FALSE.
2489 * Return value: %TRUE if the failed drag operation has been already handled.
2493 widget_signals[DRAG_FAILED] =
2494 g_signal_new (I_("drag-failed"),
2495 G_TYPE_FROM_CLASS (klass),
2497 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2498 _gtk_boolean_handled_accumulator, NULL,
2499 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2501 GDK_TYPE_DRAG_CONTEXT,
2502 GTK_TYPE_DRAG_RESULT);
2505 * GtkWidget::drag-motion:
2506 * @widget: the object which received the signal
2507 * @drag_context: the drag context
2508 * @x: the x coordinate of the current cursor position
2509 * @y: the y coordinate of the current cursor position
2510 * @time: the timestamp of the motion event
2511 * @returns: whether the cursor position is in a drop zone
2513 * The drag-motion signal is emitted on the drop site when the user
2514 * moves the cursor over the widget during a drag. The signal handler
2515 * must determine whether the cursor position is in a drop zone or not.
2516 * If it is not in a drop zone, it returns %FALSE and no further processing
2517 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2518 * handler is responsible for providing the necessary information for
2519 * displaying feedback to the user, by calling gdk_drag_status().
2521 * If the decision whether the drop will be accepted or rejected can't be
2522 * made based solely on the cursor position and the type of the data, the
2523 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2524 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2525 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2526 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2527 * when using the drag-motion signal that way.
2529 * Also note that there is no drag-enter signal. The drag receiver has to
2530 * keep track of whether he has received any drag-motion signals since the
2531 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2532 * an "enter" signal. Upon an "enter", the handler will typically highlight
2533 * the drop site with gtk_drag_highlight().
2536 * drag_motion (GtkWidget *widget,
2537 * GdkDragContext *context,
2544 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2546 * if (!private_data->drag_highlight)
2548 * private_data->drag_highlight = 1;
2549 * gtk_drag_highlight (widget);
2552 * target = gtk_drag_dest_find_target (widget, context, NULL);
2553 * if (target == GDK_NONE)
2554 * gdk_drag_status (context, 0, time);
2557 * private_data->pending_status = context->suggested_action;
2558 * gtk_drag_get_data (widget, context, target, time);
2565 * drag_data_received (GtkWidget *widget,
2566 * GdkDragContext *context,
2569 * GtkSelectionData *selection_data,
2573 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2575 * if (private_data->suggested_action)
2577 * private_data->suggested_action = 0;
2579 * /* We are getting this data due to a request in drag_motion,
2580 * * rather than due to a request in drag_drop, so we are just
2581 * * supposed to call gdk_drag_status (), not actually paste in
2584 * str = gtk_selection_data_get_text (selection_data);
2585 * if (!data_is_acceptable (str))
2586 * gdk_drag_status (context, 0, time);
2588 * gdk_drag_status (context, private_data->suggested_action, time);
2592 * /* accept the drop */
2597 widget_signals[DRAG_MOTION] =
2598 g_signal_new (I_("drag-motion"),
2599 G_TYPE_FROM_CLASS (klass),
2601 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2602 _gtk_boolean_handled_accumulator, NULL,
2603 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2605 GDK_TYPE_DRAG_CONTEXT,
2611 * GtkWidget::drag-drop:
2612 * @widget: the object which received the signal
2613 * @drag_context: the drag context
2614 * @x: the x coordinate of the current cursor position
2615 * @y: the y coordinate of the current cursor position
2616 * @time: the timestamp of the motion event
2617 * @returns: whether the cursor position is in a drop zone
2619 * The ::drag-drop signal is emitted on the drop site when the user drops
2620 * the data onto the widget. The signal handler must determine whether
2621 * the cursor position is in a drop zone or not. If it is not in a drop
2622 * zone, it returns %FALSE and no further processing is necessary.
2623 * Otherwise, the handler returns %TRUE. In this case, the handler must
2624 * ensure that gtk_drag_finish() is called to let the source know that
2625 * the drop is done. The call to gtk_drag_finish() can be done either
2626 * directly or in a #GtkWidget::drag-data-received handler which gets
2627 * triggered by calling gtk_drag_get_data() to receive the data for one
2628 * or more of the supported targets.
2630 widget_signals[DRAG_DROP] =
2631 g_signal_new (I_("drag-drop"),
2632 G_TYPE_FROM_CLASS (klass),
2634 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2635 _gtk_boolean_handled_accumulator, NULL,
2636 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2638 GDK_TYPE_DRAG_CONTEXT,
2644 * GtkWidget::drag-data-get:
2645 * @widget: the object which received the signal
2646 * @drag_context: the drag context
2647 * @data: the #GtkSelectionData to be filled with the dragged data
2648 * @info: the info that has been registered with the target in the
2650 * @time: the timestamp at which the data was requested
2652 * The ::drag-data-get signal is emitted on the drag source when the drop
2653 * site requests the data which is dragged. It is the responsibility of
2654 * the signal handler to fill @data with the data in the format which
2655 * is indicated by @info. See gtk_selection_data_set() and
2656 * gtk_selection_data_set_text().
2658 widget_signals[DRAG_DATA_GET] =
2659 g_signal_new (I_("drag-data-get"),
2660 G_TYPE_FROM_CLASS (klass),
2662 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2664 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2666 GDK_TYPE_DRAG_CONTEXT,
2667 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2672 * GtkWidget::drag-data-received:
2673 * @widget: the object which received the signal
2674 * @drag_context: the drag context
2675 * @x: where the drop happened
2676 * @y: where the drop happened
2677 * @data: the received data
2678 * @info: the info that has been registered with the target in the
2680 * @time: the timestamp at which the data was received
2682 * The ::drag-data-received signal is emitted on the drop site when the
2683 * dragged data has been received. If the data was received in order to
2684 * determine whether the drop will be accepted, the handler is expected
2685 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2686 * If the data was received in response to a #GtkWidget::drag-drop signal
2687 * (and this is the last target to be received), the handler for this
2688 * signal is expected to process the received data and then call
2689 * gtk_drag_finish(), setting the @success parameter depending on whether
2690 * the data was processed successfully.
2692 * The handler may inspect and modify @drag_context->action before calling
2693 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2694 * following example:
2697 * drag_data_received (GtkWidget *widget,
2698 * GdkDragContext *drag_context,
2701 * GtkSelectionData *data,
2705 * if ((data->length >= 0) && (data->format == 8))
2707 * if (drag_context->action == GDK_ACTION_ASK)
2709 * GtkWidget *dialog;
2712 * dialog = gtk_message_dialog_new (NULL,
2713 * GTK_DIALOG_MODAL |
2714 * GTK_DIALOG_DESTROY_WITH_PARENT,
2716 * GTK_BUTTONS_YES_NO,
2717 * "Move the data ?\n");
2718 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2719 * gtk_widget_destroy (dialog);
2721 * if (response == GTK_RESPONSE_YES)
2722 * drag_context->action = GDK_ACTION_MOVE;
2724 * drag_context->action = GDK_ACTION_COPY;
2727 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2731 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2735 widget_signals[DRAG_DATA_RECEIVED] =
2736 g_signal_new (I_("drag-data-received"),
2737 G_TYPE_FROM_CLASS (klass),
2739 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2741 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2743 GDK_TYPE_DRAG_CONTEXT,
2746 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2751 * GtkWidget::visibility-notify-event:
2752 * @widget: the object which received the signal
2753 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2754 * triggered this signal.
2756 * The ::visibility-notify-event will be emitted when the @widget's window
2757 * is obscured or unobscured.
2759 * To receive this signal the #GdkWindow associated to the widget needs
2760 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2762 * Returns: %TRUE to stop other handlers from being invoked for the event.
2763 * %FALSE to propagate the event further.
2765 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2766 g_signal_new (I_("visibility-notify-event"),
2767 G_TYPE_FROM_CLASS (klass),
2769 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2770 _gtk_boolean_handled_accumulator, NULL,
2771 _gtk_marshal_BOOLEAN__BOXED,
2773 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2776 * GtkWidget::window-state-event:
2777 * @widget: the object which received the signal
2778 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2779 * triggered this signal.
2781 * The ::window-state-event will be emitted when the state of the
2782 * toplevel window associated to the @widget changes.
2784 * To receive this signal the #GdkWindow associated to the widget
2785 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2786 * this mask automatically for all new windows.
2788 * Returns: %TRUE to stop other handlers from being invoked for the
2789 * event. %FALSE to propagate the event further.
2791 widget_signals[WINDOW_STATE_EVENT] =
2792 g_signal_new (I_("window-state-event"),
2793 G_TYPE_FROM_CLASS (klass),
2795 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2796 _gtk_boolean_handled_accumulator, NULL,
2797 _gtk_marshal_BOOLEAN__BOXED,
2799 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2802 * GtkWidget::damage-event:
2803 * @widget: the object which received the signal
2804 * @event: (type Gdk.EventExpose): the #GdkEventExpose event
2806 * Emitted when a redirected window belonging to @widget gets drawn into.
2807 * The region/area members of the event shows what area of the redirected
2808 * drawable was drawn into.
2810 * Returns: %TRUE to stop other handlers from being invoked for the event.
2811 * %FALSE to propagate the event further.
2815 widget_signals[DAMAGE_EVENT] =
2816 g_signal_new (I_("damage-event"),
2817 G_TYPE_FROM_CLASS (klass),
2819 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2820 _gtk_boolean_handled_accumulator, NULL,
2821 _gtk_marshal_BOOLEAN__BOXED,
2823 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2826 * GtkWidget::grab-broken-event:
2827 * @widget: the object which received the signal
2828 * @event: (type Gdk.EventGrabBroken): the #GdkEventGrabBroken event
2830 * Emitted when a pointer or keyboard grab on a window belonging
2831 * to @widget gets broken.
2833 * On X11, this happens when the grab window becomes unviewable
2834 * (i.e. it or one of its ancestors is unmapped), or if the same
2835 * application grabs the pointer or keyboard again.
2837 * Returns: %TRUE to stop other handlers from being invoked for
2838 * the event. %FALSE to propagate the event further.
2842 widget_signals[GRAB_BROKEN_EVENT] =
2843 g_signal_new (I_("grab-broken-event"),
2844 G_TYPE_FROM_CLASS (klass),
2846 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2847 _gtk_boolean_handled_accumulator, NULL,
2848 _gtk_marshal_BOOLEAN__BOXED,
2850 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2853 * GtkWidget::query-tooltip:
2854 * @widget: the object which received the signal
2855 * @x: the x coordinate of the cursor position where the request has
2856 * been emitted, relative to @widget->window
2857 * @y: the y coordinate of the cursor position where the request has
2858 * been emitted, relative to @widget->window
2859 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2860 * @tooltip: a #GtkTooltip
2862 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2863 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2864 * focus in keyboard mode.
2866 * Using the given coordinates, the signal handler should determine
2867 * whether a tooltip should be shown for @widget. If this is the case
2868 * %TRUE should be returned, %FALSE otherwise. Note that if
2869 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2870 * should not be used.
2872 * The signal handler is free to manipulate @tooltip with the therefore
2873 * destined function calls.
2875 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2879 widget_signals[QUERY_TOOLTIP] =
2880 g_signal_new (I_("query-tooltip"),
2881 G_TYPE_FROM_CLASS (klass),
2883 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2884 _gtk_boolean_handled_accumulator, NULL,
2885 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2893 * GtkWidget::popup-menu
2894 * @widget: the object which received the signal
2896 * This signal gets emitted whenever a widget should pop up a context
2897 * menu. This usually happens through the standard key binding mechanism;
2898 * by pressing a certain key while a widget is focused, the user can cause
2899 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2900 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2901 * for an example of how to use this signal.
2903 * Returns: %TRUE if a menu was activated
2905 widget_signals[POPUP_MENU] =
2906 g_signal_new (I_("popup-menu"),
2907 G_TYPE_FROM_CLASS (klass),
2908 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2909 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2910 _gtk_boolean_handled_accumulator, NULL,
2911 _gtk_marshal_BOOLEAN__VOID,
2915 * GtkWidget::show-help:
2916 * @widget: the object which received the signal.
2919 widget_signals[SHOW_HELP] =
2920 g_signal_new (I_("show-help"),
2921 G_TYPE_FROM_CLASS (klass),
2922 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2923 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2924 _gtk_boolean_handled_accumulator, NULL,
2925 _gtk_marshal_BOOLEAN__ENUM,
2927 GTK_TYPE_WIDGET_HELP_TYPE);
2930 * GtkWidget::accel-closures-changed:
2931 * @widget: the object which received the signal.
2933 widget_signals[ACCEL_CLOSURES_CHANGED] =
2934 g_signal_new (I_("accel-closures-changed"),
2935 G_TYPE_FROM_CLASS (klass),
2939 _gtk_marshal_VOID__VOID,
2943 * GtkWidget::screen-changed:
2944 * @widget: the object on which the signal is emitted
2945 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2946 * widget was not associated with a screen before
2948 * The ::screen-changed signal gets emitted when the
2949 * screen of a widget has changed.
2951 widget_signals[SCREEN_CHANGED] =
2952 g_signal_new (I_("screen-changed"),
2953 G_TYPE_FROM_CLASS (klass),
2955 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2957 _gtk_marshal_VOID__OBJECT,
2962 * GtkWidget::can-activate-accel:
2963 * @widget: the object which received the signal
2964 * @signal_id: the ID of a signal installed on @widget
2966 * Determines whether an accelerator that activates the signal
2967 * identified by @signal_id can currently be activated.
2968 * This signal is present to allow applications and derived
2969 * widgets to override the default #GtkWidget handling
2970 * for determining whether an accelerator can be activated.
2972 * Returns: %TRUE if the signal can be activated.
2974 widget_signals[CAN_ACTIVATE_ACCEL] =
2975 g_signal_new (I_("can-activate-accel"),
2976 G_TYPE_FROM_CLASS (klass),
2978 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2979 _gtk_boolean_handled_accumulator, NULL,
2980 _gtk_marshal_BOOLEAN__UINT,
2981 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2983 binding_set = gtk_binding_set_by_class (klass);
2984 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
2986 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
2989 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
2991 GTK_TYPE_WIDGET_HELP_TYPE,
2992 GTK_WIDGET_HELP_TOOLTIP);
2993 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
2995 GTK_TYPE_WIDGET_HELP_TYPE,
2996 GTK_WIDGET_HELP_TOOLTIP);
2997 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
2999 GTK_TYPE_WIDGET_HELP_TYPE,
3000 GTK_WIDGET_HELP_WHATS_THIS);
3001 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
3003 GTK_TYPE_WIDGET_HELP_TYPE,
3004 GTK_WIDGET_HELP_WHATS_THIS);
3006 gtk_widget_class_install_style_property (klass,
3007 g_param_spec_boolean ("interior-focus",
3008 P_("Interior Focus"),
3009 P_("Whether to draw the focus indicator inside widgets"),
3011 GTK_PARAM_READABLE));
3013 gtk_widget_class_install_style_property (klass,
3014 g_param_spec_int ("focus-line-width",
3015 P_("Focus linewidth"),
3016 P_("Width, in pixels, of the focus indicator line"),
3018 GTK_PARAM_READABLE));
3020 gtk_widget_class_install_style_property (klass,
3021 g_param_spec_string ("focus-line-pattern",
3022 P_("Focus line dash pattern"),
3023 P_("Dash pattern used to draw the focus indicator"),
3025 GTK_PARAM_READABLE));
3026 gtk_widget_class_install_style_property (klass,
3027 g_param_spec_int ("focus-padding",
3028 P_("Focus padding"),
3029 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3031 GTK_PARAM_READABLE));
3032 gtk_widget_class_install_style_property (klass,
3033 g_param_spec_boxed ("cursor-color",
3035 P_("Color with which to draw insertion cursor"),
3037 GTK_PARAM_READABLE));
3038 gtk_widget_class_install_style_property (klass,
3039 g_param_spec_boxed ("secondary-cursor-color",
3040 P_("Secondary cursor color"),
3041 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3043 GTK_PARAM_READABLE));
3044 gtk_widget_class_install_style_property (klass,
3045 g_param_spec_float ("cursor-aspect-ratio",
3046 P_("Cursor line aspect ratio"),
3047 P_("Aspect ratio with which to draw insertion cursor"),
3049 GTK_PARAM_READABLE));
3051 gtk_widget_class_install_style_property (klass,
3052 g_param_spec_boolean ("window-dragging",
3053 P_("Window dragging"),
3054 P_("Whether windows can be dragged by clicking on empty areas"),
3056 GTK_PARAM_READABLE));
3059 * GtkWidget:link-color:
3061 * The "link-color" style property defines the color of unvisited links.
3065 gtk_widget_class_install_style_property (klass,
3066 g_param_spec_boxed ("link-color",
3067 P_("Unvisited Link Color"),
3068 P_("Color of unvisited links"),
3070 GTK_PARAM_READABLE));
3073 * GtkWidget:visited-link-color:
3075 * The "visited-link-color" style property defines the color of visited links.
3079 gtk_widget_class_install_style_property (klass,
3080 g_param_spec_boxed ("visited-link-color",
3081 P_("Visited Link Color"),
3082 P_("Color of visited links"),
3084 GTK_PARAM_READABLE));
3087 * GtkWidget:wide-separators:
3089 * The "wide-separators" style property defines whether separators have
3090 * configurable width and should be drawn using a box instead of a line.
3094 gtk_widget_class_install_style_property (klass,
3095 g_param_spec_boolean ("wide-separators",
3096 P_("Wide Separators"),
3097 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3099 GTK_PARAM_READABLE));
3102 * GtkWidget:separator-width:
3104 * The "separator-width" style property defines the width of separators.
3105 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3109 gtk_widget_class_install_style_property (klass,
3110 g_param_spec_int ("separator-width",
3111 P_("Separator Width"),
3112 P_("The width of separators if wide-separators is TRUE"),
3114 GTK_PARAM_READABLE));
3117 * GtkWidget:separator-height:
3119 * The "separator-height" style property defines the height of separators.
3120 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3124 gtk_widget_class_install_style_property (klass,
3125 g_param_spec_int ("separator-height",
3126 P_("Separator Height"),
3127 P_("The height of separators if \"wide-separators\" is TRUE"),
3129 GTK_PARAM_READABLE));
3132 * GtkWidget:scroll-arrow-hlength:
3134 * The "scroll-arrow-hlength" style property defines the length of
3135 * horizontal scroll arrows.
3139 gtk_widget_class_install_style_property (klass,
3140 g_param_spec_int ("scroll-arrow-hlength",
3141 P_("Horizontal Scroll Arrow Length"),
3142 P_("The length of horizontal scroll arrows"),
3144 GTK_PARAM_READABLE));
3147 * GtkWidget:scroll-arrow-vlength:
3149 * The "scroll-arrow-vlength" style property defines the length of
3150 * vertical scroll arrows.
3154 gtk_widget_class_install_style_property (klass,
3155 g_param_spec_int ("scroll-arrow-vlength",
3156 P_("Vertical Scroll Arrow Length"),
3157 P_("The length of vertical scroll arrows"),
3159 GTK_PARAM_READABLE));
3161 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3165 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3169 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3170 for (node = list; node; node = node->next)
3172 GParamSpec *pspec = node->data;
3174 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3175 g_param_spec_unref (pspec);
3181 gtk_widget_set_property (GObject *object,
3183 const GValue *value,
3186 GtkWidget *widget = GTK_WIDGET (object);
3191 gchar *tooltip_markup;
3192 const gchar *tooltip_text;
3193 GtkWindow *tooltip_window;
3196 gtk_widget_set_name (widget, g_value_get_string (value));
3199 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3201 case PROP_WIDTH_REQUEST:
3202 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3204 case PROP_HEIGHT_REQUEST:
3205 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3208 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3210 case PROP_SENSITIVE:
3211 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3213 case PROP_APP_PAINTABLE:
3214 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3216 case PROP_CAN_FOCUS:
3217 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3219 case PROP_HAS_FOCUS:
3220 if (g_value_get_boolean (value))
3221 gtk_widget_grab_focus (widget);
3224 if (g_value_get_boolean (value))
3225 gtk_widget_grab_focus (widget);
3227 case PROP_CAN_DEFAULT:
3228 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3230 case PROP_HAS_DEFAULT:
3231 if (g_value_get_boolean (value))
3232 gtk_widget_grab_default (widget);
3234 case PROP_RECEIVES_DEFAULT:
3235 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3238 gtk_widget_set_style (widget, g_value_get_object (value));
3241 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3242 gtk_widget_set_events (widget, g_value_get_flags (value));
3244 case PROP_NO_SHOW_ALL:
3245 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3247 case PROP_HAS_TOOLTIP:
3248 gtk_widget_real_set_has_tooltip (widget,
3249 g_value_get_boolean (value), FALSE);
3251 case PROP_TOOLTIP_MARKUP:
3252 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3253 tooltip_markup = g_value_dup_string (value);
3255 /* Treat an empty string as a NULL string,
3256 * because an empty string would be useless for a tooltip:
3258 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3260 g_free (tooltip_markup);
3261 tooltip_markup = NULL;
3264 g_object_set_qdata_full (object, quark_tooltip_markup,
3265 tooltip_markup, g_free);
3267 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3268 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3269 if (gtk_widget_get_visible (widget))
3270 gtk_widget_queue_tooltip_query (widget);
3272 case PROP_TOOLTIP_TEXT:
3273 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3275 tooltip_text = g_value_get_string (value);
3277 /* Treat an empty string as a NULL string,
3278 * because an empty string would be useless for a tooltip:
3280 if (tooltip_text && (strlen (tooltip_text) == 0))
3281 tooltip_text = NULL;
3283 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : 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_DOUBLE_BUFFERED:
3294 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3297 gtk_widget_set_halign (widget, g_value_get_enum (value));
3300 gtk_widget_set_valign (widget, g_value_get_enum (value));
3302 case PROP_MARGIN_LEFT:
3303 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3305 case PROP_MARGIN_RIGHT:
3306 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3308 case PROP_MARGIN_TOP:
3309 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3311 case PROP_MARGIN_BOTTOM:
3312 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3315 g_object_freeze_notify (G_OBJECT (widget));
3316 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3317 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3318 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3319 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3320 g_object_thaw_notify (G_OBJECT (widget));
3323 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3325 case PROP_HEXPAND_SET:
3326 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3329 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3331 case PROP_VEXPAND_SET:
3332 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3335 g_object_freeze_notify (G_OBJECT (widget));
3336 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3337 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3338 g_object_thaw_notify (G_OBJECT (widget));
3341 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3347 gtk_widget_get_property (GObject *object,
3352 GtkWidget *widget = GTK_WIDGET (object);
3353 GtkWidgetPrivate *priv = widget->priv;
3361 g_value_set_string (value, priv->name);
3363 g_value_set_static_string (value, "");
3366 g_value_set_object (value, priv->parent);
3368 case PROP_WIDTH_REQUEST:
3371 gtk_widget_get_size_request (widget, &w, NULL);
3372 g_value_set_int (value, w);
3375 case PROP_HEIGHT_REQUEST:
3378 gtk_widget_get_size_request (widget, NULL, &h);
3379 g_value_set_int (value, h);
3383 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3385 case PROP_SENSITIVE:
3386 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3388 case PROP_APP_PAINTABLE:
3389 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3391 case PROP_CAN_FOCUS:
3392 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3394 case PROP_HAS_FOCUS:
3395 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3398 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3400 case PROP_CAN_DEFAULT:
3401 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3403 case PROP_HAS_DEFAULT:
3404 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3406 case PROP_RECEIVES_DEFAULT:
3407 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3409 case PROP_COMPOSITE_CHILD:
3410 g_value_set_boolean (value, widget->priv->composite_child);
3413 g_value_set_object (value, gtk_widget_get_style (widget));
3416 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3417 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3419 case PROP_NO_SHOW_ALL:
3420 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3422 case PROP_HAS_TOOLTIP:
3423 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3425 case PROP_TOOLTIP_TEXT:
3427 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3430 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3431 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3433 g_value_take_string (value, text);
3436 case PROP_TOOLTIP_MARKUP:
3437 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3440 g_value_set_object (value, gtk_widget_get_window (widget));
3442 case PROP_DOUBLE_BUFFERED:
3443 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3446 g_value_set_enum (value, gtk_widget_get_halign (widget));
3449 g_value_set_enum (value, gtk_widget_get_valign (widget));
3451 case PROP_MARGIN_LEFT:
3452 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3454 case PROP_MARGIN_RIGHT:
3455 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3457 case PROP_MARGIN_TOP:
3458 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3460 case PROP_MARGIN_BOTTOM:
3461 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3465 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3466 if (aux_info == NULL)
3468 g_value_set_int (value, 0);
3472 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3473 aux_info->margin.right),
3474 MAX (aux_info->margin.top,
3475 aux_info->margin.bottom)));
3480 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3482 case PROP_HEXPAND_SET:
3483 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3486 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3488 case PROP_VEXPAND_SET:
3489 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3492 g_value_set_boolean (value,
3493 gtk_widget_get_hexpand (widget) &&
3494 gtk_widget_get_vexpand (widget));
3497 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3503 gtk_widget_init (GtkWidget *widget)
3505 GtkWidgetPrivate *priv;
3507 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3510 priv = widget->priv;
3512 priv->child_visible = TRUE;
3514 priv->allocation.x = -1;
3515 priv->allocation.y = -1;
3516 priv->allocation.width = 1;
3517 priv->allocation.height = 1;
3518 priv->window = NULL;
3519 priv->parent = NULL;
3521 priv->sensitive = TRUE;
3522 priv->composite_child = composite_child_stack != 0;
3523 priv->double_buffered = TRUE;
3524 priv->redraw_on_alloc = TRUE;
3525 priv->width_request_needed = TRUE;
3526 priv->height_request_needed = TRUE;
3527 priv->alloc_needed = TRUE;
3529 /* this will be set to TRUE if the widget gets a child or if the
3530 * expand flag is set on the widget, but until one of those happen
3531 * we know the expand is already properly FALSE.
3533 * We really want to default FALSE here to avoid computing expand
3534 * all over the place while initially building a widget tree.
3536 priv->need_compute_expand = FALSE;
3538 priv->style = gtk_widget_get_default_style ();
3539 g_object_ref (priv->style);
3544 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3546 GParamSpec **pspecs)
3548 GtkWidgetPrivate *priv = widget->priv;
3549 GtkWidget *container = priv->parent;
3552 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3553 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3557 * gtk_widget_freeze_child_notify:
3558 * @widget: a #GtkWidget
3560 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3561 * signals are queued until gtk_widget_thaw_child_notify() is called
3564 * This is the analogue of g_object_freeze_notify() for child properties.
3567 gtk_widget_freeze_child_notify (GtkWidget *widget)
3569 g_return_if_fail (GTK_IS_WIDGET (widget));
3571 if (!G_OBJECT (widget)->ref_count)
3574 g_object_ref (widget);
3575 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3576 g_object_unref (widget);
3580 * gtk_widget_child_notify:
3581 * @widget: a #GtkWidget
3582 * @child_property: the name of a child property installed on the
3583 * class of @widget<!-- -->'s parent
3585 * Emits a #GtkWidget::child-notify signal for the
3586 * <link linkend="child-properties">child property</link> @child_property
3589 * This is the analogue of g_object_notify() for child properties.
3592 gtk_widget_child_notify (GtkWidget *widget,
3593 const gchar *child_property)
3595 GtkWidgetPrivate *priv = widget->priv;
3598 g_return_if_fail (GTK_IS_WIDGET (widget));
3599 g_return_if_fail (child_property != NULL);
3600 if (!G_OBJECT (widget)->ref_count || !priv->parent)
3603 g_object_ref (widget);
3604 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3606 G_OBJECT_TYPE (priv->parent),
3609 g_warning ("%s: container class `%s' has no child property named `%s'",
3611 G_OBJECT_TYPE_NAME (priv->parent),
3615 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3617 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3618 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3620 g_object_unref (widget);
3624 * gtk_widget_thaw_child_notify:
3625 * @widget: a #GtkWidget
3627 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3628 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3632 gtk_widget_thaw_child_notify (GtkWidget *widget)
3634 GObjectNotifyQueue *nqueue;
3636 g_return_if_fail (GTK_IS_WIDGET (widget));
3638 if (!G_OBJECT (widget)->ref_count)
3641 g_object_ref (widget);
3642 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3643 if (!nqueue || !nqueue->freeze_count)
3644 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3645 G_OBJECT_TYPE_NAME (widget), widget);
3647 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3648 g_object_unref (widget);
3654 * @type: type ID of the widget to create
3655 * @first_property_name: name of first property to set
3656 * @Varargs: value of first property, followed by more properties,
3659 * This is a convenience function for creating a widget and setting
3660 * its properties in one go. For example you might write:
3661 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3662 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3663 * g_object_new(), but returns a widget so you don't have to
3664 * cast the object yourself.
3666 * Return value: a new #GtkWidget of type @widget_type
3669 gtk_widget_new (GType type,
3670 const gchar *first_property_name,
3676 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3678 va_start (var_args, first_property_name);
3679 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3686 gtk_widget_queue_draw_child (GtkWidget *widget)
3688 GtkWidgetPrivate *priv = widget->priv;
3691 parent = priv->parent;
3692 if (parent && gtk_widget_is_drawable (parent))
3693 gtk_widget_queue_draw_area (parent,
3696 priv->allocation.width,
3697 priv->allocation.height);
3701 * gtk_widget_unparent:
3702 * @widget: a #GtkWidget
3704 * This function is only for use in widget implementations.
3705 * Should be called by implementations of the remove method
3706 * on #GtkContainer, to dissociate a child from the container.
3709 gtk_widget_unparent (GtkWidget *widget)
3711 GtkWidgetPrivate *priv;
3712 GObjectNotifyQueue *nqueue;
3713 GtkWidget *toplevel;
3714 GtkWidget *old_parent;
3716 g_return_if_fail (GTK_IS_WIDGET (widget));
3718 priv = widget->priv;
3720 if (priv->parent == NULL)
3723 /* keep this function in sync with gtk_menu_detach() */
3725 gtk_widget_push_verify_invariants (widget);
3727 g_object_freeze_notify (G_OBJECT (widget));
3728 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3730 toplevel = gtk_widget_get_toplevel (widget);
3731 if (gtk_widget_is_toplevel (toplevel))
3732 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3734 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3735 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3737 gtk_widget_queue_draw_child (widget);
3739 /* Reset the width and height here, to force reallocation if we
3740 * get added back to a new parent. This won't work if our new
3741 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3742 * (would 0x0 be OK here?)
3744 priv->allocation.width = 1;
3745 priv->allocation.height = 1;
3747 if (gtk_widget_get_realized (widget))
3749 if (priv->in_reparent)
3750 gtk_widget_unmap (widget);
3752 gtk_widget_unrealize (widget);
3755 /* If we are unanchoring the child, we save around the toplevel
3756 * to emit hierarchy changed
3758 if (priv->parent->priv->anchored)
3759 g_object_ref (toplevel);
3763 /* Removing a widget from a container restores the child visible
3764 * flag to the default state, so it doesn't affect the child
3765 * in the next parent.
3767 priv->child_visible = TRUE;
3769 old_parent = priv->parent;
3770 priv->parent = NULL;
3772 /* parent may no longer expand if the removed
3773 * child was expand=TRUE and could therefore
3776 if (gtk_widget_get_visible (widget) &&
3777 (priv->need_compute_expand ||
3778 priv->computed_hexpand ||
3779 priv->computed_vexpand))
3781 gtk_widget_queue_compute_expand (old_parent);
3784 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3787 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3788 g_object_unref (toplevel);
3791 /* Now that the parent pointer is nullified and the hierarchy-changed
3792 * already passed, go ahead and unset the parent window, if we are unparenting
3793 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
3794 * will fire again for the new subhierarchy.
3796 gtk_widget_set_parent_window (widget, NULL);
3798 g_object_notify (G_OBJECT (widget), "parent");
3799 g_object_thaw_notify (G_OBJECT (widget));
3801 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3802 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3804 gtk_widget_pop_verify_invariants (widget);
3805 g_object_unref (widget);
3809 * gtk_widget_destroy:
3810 * @widget: a #GtkWidget
3812 * Destroys a widget.
3815 * destroyed, it will break any references it holds to other objects.
3816 * If the widget is inside a container, the widget will be removed
3817 * from the container. If the widget is a toplevel (derived from
3818 * #GtkWindow), it will be removed from the list of toplevels, and the
3819 * reference GTK+ holds to it will be removed. Removing a
3820 * widget from its container or the list of toplevels results in the
3821 * widget being finalized, unless you've added additional references
3822 * to the widget with g_object_ref().
3824 * In most cases, only toplevel widgets (windows) require explicit
3825 * destruction, because when you destroy a toplevel its children will
3826 * be destroyed as well.
3829 gtk_widget_destroy (GtkWidget *widget)
3831 g_return_if_fail (GTK_IS_WIDGET (widget));
3833 if (!widget->priv->in_destruction)
3834 g_object_run_dispose (G_OBJECT (widget));
3838 * gtk_widget_destroyed:
3839 * @widget: a #GtkWidget
3840 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3842 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3843 * %NULL. It's intended to be used as a callback connected to the
3844 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3845 * as a signal handler, and pass the address of your widget variable
3846 * as user data. Then when the widget is destroyed, the variable will
3847 * be set to %NULL. Useful for example to avoid multiple copies
3848 * of the same dialog.
3851 gtk_widget_destroyed (GtkWidget *widget,
3852 GtkWidget **widget_pointer)
3854 /* Don't make any assumptions about the
3856 * Even check widget_pointer.
3859 *widget_pointer = NULL;
3864 * @widget: a #GtkWidget
3866 * Flags a widget to be displayed. Any widget that isn't shown will
3867 * not appear on the screen. If you want to show all the widgets in a
3868 * container, it's easier to call gtk_widget_show_all() on the
3869 * container, instead of individually showing the widgets.
3871 * Remember that you have to show the containers containing a widget,
3872 * in addition to the widget itself, before it will appear onscreen.
3874 * When a toplevel container is shown, it is immediately realized and
3875 * mapped; other shown widgets are realized and mapped when their
3876 * toplevel container is realized and mapped.
3879 gtk_widget_show (GtkWidget *widget)
3881 g_return_if_fail (GTK_IS_WIDGET (widget));
3883 if (!gtk_widget_get_visible (widget))
3885 g_object_ref (widget);
3886 gtk_widget_push_verify_invariants (widget);
3888 if (!gtk_widget_is_toplevel (widget))
3889 gtk_widget_queue_resize (widget);
3891 /* see comment in set_parent() for why this should and can be
3894 if (widget->priv->need_compute_expand ||
3895 widget->priv->computed_hexpand ||
3896 widget->priv->computed_vexpand)
3898 if (widget->priv->parent != NULL)
3899 gtk_widget_queue_compute_expand (widget->priv->parent);
3902 g_signal_emit (widget, widget_signals[SHOW], 0);
3903 g_object_notify (G_OBJECT (widget), "visible");
3905 gtk_widget_pop_verify_invariants (widget);
3906 g_object_unref (widget);
3911 gtk_widget_real_show (GtkWidget *widget)
3913 GtkWidgetPrivate *priv = widget->priv;
3915 if (!gtk_widget_get_visible (widget))
3917 priv->visible = TRUE;
3920 gtk_widget_get_mapped (priv->parent) &&
3921 gtk_widget_get_child_visible (widget) &&
3922 !gtk_widget_get_mapped (widget))
3923 gtk_widget_map (widget);
3928 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3931 g_signal_handlers_disconnect_by_func (widget,
3932 gtk_widget_show_map_callback,
3937 * gtk_widget_show_now:
3938 * @widget: a #GtkWidget
3940 * Shows a widget. If the widget is an unmapped toplevel widget
3941 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3942 * loop and wait for the window to actually be mapped. Be careful;
3943 * because the main loop is running, anything can happen during
3947 gtk_widget_show_now (GtkWidget *widget)
3951 g_return_if_fail (GTK_IS_WIDGET (widget));
3953 /* make sure we will get event */
3954 if (!gtk_widget_get_mapped (widget) &&
3955 gtk_widget_is_toplevel (widget))
3957 gtk_widget_show (widget);
3959 g_signal_connect (widget, "map-event",
3960 G_CALLBACK (gtk_widget_show_map_callback),
3964 gtk_main_iteration ();
3967 gtk_widget_show (widget);
3972 * @widget: a #GtkWidget
3974 * Reverses the effects of gtk_widget_show(), causing the widget to be
3975 * hidden (invisible to the user).
3978 gtk_widget_hide (GtkWidget *widget)
3980 g_return_if_fail (GTK_IS_WIDGET (widget));
3982 if (gtk_widget_get_visible (widget))
3984 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3986 g_object_ref (widget);
3987 gtk_widget_push_verify_invariants (widget);
3989 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3990 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3992 /* a parent may now be expand=FALSE since we're hidden. */
3993 if (widget->priv->need_compute_expand ||
3994 widget->priv->computed_hexpand ||
3995 widget->priv->computed_vexpand)
3997 gtk_widget_queue_compute_expand (widget);
4000 g_signal_emit (widget, widget_signals[HIDE], 0);
4001 if (!gtk_widget_is_toplevel (widget))
4002 gtk_widget_queue_resize (widget);
4003 g_object_notify (G_OBJECT (widget), "visible");
4005 gtk_widget_pop_verify_invariants (widget);
4006 g_object_unref (widget);
4011 gtk_widget_real_hide (GtkWidget *widget)
4013 if (gtk_widget_get_visible (widget))
4015 widget->priv->visible = FALSE;
4017 if (gtk_widget_get_mapped (widget))
4018 gtk_widget_unmap (widget);
4023 * gtk_widget_hide_on_delete:
4024 * @widget: a #GtkWidget
4026 * Utility function; intended to be connected to the #GtkWidget::delete-event
4027 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4028 * argument, then returns %TRUE. If connected to ::delete-event, the
4029 * result is that clicking the close button for a window (on the
4030 * window frame, top right corner usually) will hide but not destroy
4031 * the window. By default, GTK+ destroys windows when ::delete-event
4034 * Return value: %TRUE
4037 gtk_widget_hide_on_delete (GtkWidget *widget)
4039 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4041 gtk_widget_hide (widget);
4047 * gtk_widget_show_all:
4048 * @widget: a #GtkWidget
4050 * Recursively shows a widget, and any child widgets (if the widget is
4054 gtk_widget_show_all (GtkWidget *widget)
4056 GtkWidgetClass *class;
4058 g_return_if_fail (GTK_IS_WIDGET (widget));
4060 if (gtk_widget_get_no_show_all (widget))
4063 class = GTK_WIDGET_GET_CLASS (widget);
4065 if (class->show_all)
4066 class->show_all (widget);
4070 _gtk_widget_notify_state_change (GtkWidget *widget,
4078 case GTK_STATE_FLAG_ACTIVE:
4079 state = GTK_STATE_ACTIVE;
4081 case GTK_STATE_FLAG_PRELIGHT:
4082 state = GTK_STATE_PRELIGHT;
4084 case GTK_STATE_FLAG_SELECTED:
4085 state = GTK_STATE_SELECTED;
4087 case GTK_STATE_FLAG_INSENSITIVE:
4088 state = GTK_STATE_INSENSITIVE;
4090 case GTK_STATE_FLAG_INCONSISTENT:
4091 state = GTK_STATE_INCONSISTENT;
4093 case GTK_STATE_FLAG_FOCUSED:
4094 state = GTK_STATE_FOCUSED;
4100 gtk_style_context_notify_state_change (widget->priv->context,
4101 gtk_widget_get_window (widget),
4102 NULL, state, target);
4105 /* Initializes state transitions for those states that
4106 * were enabled before mapping and have a looping animation.
4109 _gtk_widget_start_state_transitions (GtkWidget *widget)
4111 GtkStateFlags state, flag;
4113 if (!widget->priv->context)
4116 state = gtk_widget_get_state_flags (widget);
4117 flag = GTK_STATE_FLAG_FOCUSED;
4121 GtkAnimationDescription *animation_desc;
4123 if ((state & flag) == 0)
4129 gtk_style_context_get (widget->priv->context, state,
4130 "transition", &animation_desc,
4135 if (_gtk_animation_description_get_loop (animation_desc))
4136 _gtk_widget_notify_state_change (widget, flag, TRUE);
4138 _gtk_animation_description_unref (animation_desc);
4147 * @widget: a #GtkWidget
4149 * This function is only for use in widget implementations. Causes
4150 * a widget to be mapped if it isn't already.
4153 gtk_widget_map (GtkWidget *widget)
4155 GtkWidgetPrivate *priv;
4157 g_return_if_fail (GTK_IS_WIDGET (widget));
4158 g_return_if_fail (gtk_widget_get_visible (widget));
4159 g_return_if_fail (gtk_widget_get_child_visible (widget));
4161 priv = widget->priv;
4163 if (!gtk_widget_get_mapped (widget))
4165 gtk_widget_push_verify_invariants (widget);
4167 if (!gtk_widget_get_realized (widget))
4168 gtk_widget_realize (widget);
4170 g_signal_emit (widget, widget_signals[MAP], 0);
4172 if (!gtk_widget_get_has_window (widget))
4173 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4175 gtk_widget_pop_verify_invariants (widget);
4177 _gtk_widget_start_state_transitions (widget);
4183 * @widget: a #GtkWidget
4185 * This function is only for use in widget implementations. Causes
4186 * a widget to be unmapped if it's currently mapped.
4189 gtk_widget_unmap (GtkWidget *widget)
4191 GtkWidgetPrivate *priv;
4193 g_return_if_fail (GTK_IS_WIDGET (widget));
4195 priv = widget->priv;
4197 if (gtk_widget_get_mapped (widget))
4199 gtk_widget_push_verify_invariants (widget);
4201 if (!gtk_widget_get_has_window (widget))
4202 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4203 _gtk_tooltip_hide (widget);
4204 g_signal_emit (widget, widget_signals[UNMAP], 0);
4206 gtk_widget_pop_verify_invariants (widget);
4209 gtk_style_context_cancel_animations (priv->context, NULL);
4211 /* Unset pointer/window info */
4212 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4217 _gtk_widget_enable_device_events (GtkWidget *widget)
4219 GHashTable *device_events;
4220 GHashTableIter iter;
4221 gpointer key, value;
4223 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4228 g_hash_table_iter_init (&iter, device_events);
4230 while (g_hash_table_iter_next (&iter, &key, &value))
4233 GdkEventMask event_mask;
4236 event_mask = GPOINTER_TO_UINT (value);
4237 gtk_widget_add_events_internal (widget, device, event_mask);
4242 get_widget_windows (GtkWidget *widget)
4244 GList *window_list, *last, *l, *children, *ret;
4246 if (gtk_widget_get_has_window (widget))
4247 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4249 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4251 last = g_list_last (window_list);
4254 for (l = window_list; l; l = l->next)
4256 GtkWidget *window_widget = NULL;
4258 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4260 if (widget != window_widget)
4263 ret = g_list_prepend (ret, l->data);
4264 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4268 last = g_list_concat (last, children);
4269 last = g_list_last (last);
4273 g_list_free (window_list);
4279 device_enable_foreach (GtkWidget *widget,
4282 GdkDevice *device = user_data;
4283 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4287 device_disable_foreach (GtkWidget *widget,
4290 GdkDevice *device = user_data;
4291 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4295 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4300 GList *window_list, *l;
4302 window_list = get_widget_windows (widget);
4304 for (l = window_list; l; l = l->next)
4306 GdkEventMask events = 0;
4312 events = gdk_window_get_events (window);
4314 gdk_window_set_device_events (window, device, events);
4317 if (recurse && GTK_IS_CONTAINER (widget))
4320 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4322 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4325 g_list_free (window_list);
4329 gtk_widget_update_devices_mask (GtkWidget *widget,
4332 GList *enabled_devices, *l;
4334 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4336 for (l = enabled_devices; l; l = l->next)
4337 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4341 * gtk_widget_realize:
4342 * @widget: a #GtkWidget
4344 * Creates the GDK (windowing system) resources associated with a
4345 * widget. For example, @widget->window will be created when a widget
4346 * is realized. Normally realization happens implicitly; if you show
4347 * a widget and all its parent containers, then the widget will be
4348 * realized and mapped automatically.
4350 * Realizing a widget requires all
4351 * the widget's parent widgets to be realized; calling
4352 * gtk_widget_realize() realizes the widget's parents in addition to
4353 * @widget itself. If a widget is not yet inside a toplevel window
4354 * when you realize it, bad things will happen.
4356 * This function is primarily used in widget implementations, and
4357 * isn't very useful otherwise. Many times when you think you might
4358 * need it, a better approach is to connect to a signal that will be
4359 * called after the widget is realized automatically, such as
4360 * #GtkWidget::draw. Or simply g_signal_connect () to the
4361 * #GtkWidget::realize signal.
4364 gtk_widget_realize (GtkWidget *widget)
4366 GtkWidgetPrivate *priv;
4367 cairo_region_t *region;
4369 g_return_if_fail (GTK_IS_WIDGET (widget));
4370 g_return_if_fail (widget->priv->anchored ||
4371 GTK_IS_INVISIBLE (widget));
4373 priv = widget->priv;
4375 if (!gtk_widget_get_realized (widget))
4377 gtk_widget_push_verify_invariants (widget);
4380 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4381 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4384 if (priv->parent == NULL &&
4385 !gtk_widget_is_toplevel (widget))
4386 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4387 "inside a toplevel window is not going to work very well. "
4388 "Widgets must be inside a toplevel container before realizing them.");
4390 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4391 gtk_widget_realize (priv->parent);
4393 gtk_widget_ensure_style (widget);
4395 if (priv->style_update_pending)
4396 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4398 g_signal_emit (widget, widget_signals[REALIZE], 0);
4400 gtk_widget_real_set_has_tooltip (widget,
4401 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4404 if (priv->has_shape_mask)
4406 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4407 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4410 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4412 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4414 if (priv->multidevice)
4415 gdk_window_set_support_multidevice (priv->window, TRUE);
4417 _gtk_widget_enable_device_events (widget);
4418 gtk_widget_update_devices_mask (widget, TRUE);
4420 gtk_widget_pop_verify_invariants (widget);
4425 * gtk_widget_unrealize:
4426 * @widget: a #GtkWidget
4428 * This function is only useful in widget implementations.
4429 * Causes a widget to be unrealized (frees all GDK resources
4430 * associated with the widget, such as @widget->window).
4433 gtk_widget_unrealize (GtkWidget *widget)
4435 g_return_if_fail (GTK_IS_WIDGET (widget));
4437 gtk_widget_push_verify_invariants (widget);
4439 if (widget->priv->has_shape_mask)
4440 gtk_widget_shape_combine_region (widget, NULL);
4442 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4443 gtk_widget_input_shape_combine_region (widget, NULL);
4445 if (gtk_widget_get_realized (widget))
4447 g_object_ref (widget);
4449 if (widget->priv->mapped)
4450 gtk_widget_unmap (widget);
4452 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4453 g_assert (!widget->priv->mapped);
4454 gtk_widget_set_realized (widget, FALSE);
4456 g_object_unref (widget);
4459 gtk_widget_pop_verify_invariants (widget);
4462 /*****************************************
4464 *****************************************/
4467 * gtk_widget_queue_draw_region:
4468 * @widget: a #GtkWidget
4469 * @region: region to draw
4471 * Invalidates the rectangular area of @widget defined by @region by
4472 * calling gdk_window_invalidate_region() on the widget's window and
4473 * all its child windows. Once the main loop becomes idle (after the
4474 * current batch of events has been processed, roughly), the window
4475 * will receive expose events for the union of all regions that have
4478 * Normally you would only use this function in widget
4479 * implementations. You might also use it to schedule a redraw of a
4480 * #GtkDrawingArea or some portion thereof.
4485 gtk_widget_queue_draw_region (GtkWidget *widget,
4486 const cairo_region_t *region)
4488 GtkWidgetPrivate *priv;
4491 g_return_if_fail (GTK_IS_WIDGET (widget));
4493 priv = widget->priv;
4495 if (!gtk_widget_get_realized (widget))
4498 /* Just return if the widget or one of its ancestors isn't mapped */
4499 for (w = widget; w != NULL; w = w->priv->parent)
4500 if (!gtk_widget_get_mapped (w))
4503 gdk_window_invalidate_region (priv->window, region, TRUE);
4507 * gtk_widget_queue_draw_area:
4508 * @widget: a #GtkWidget
4509 * @x: x coordinate of upper-left corner of rectangle to redraw
4510 * @y: y coordinate of upper-left corner of rectangle to redraw
4511 * @width: width of region to draw
4512 * @height: height of region to draw
4514 * Convenience function that calls gtk_widget_queue_draw_region() on
4515 * the region created from the given coordinates.
4517 * The region here is specified in widget coordinates.
4518 * Widget coordinates are a bit odd; for historical reasons, they are
4519 * defined as @widget->window coordinates for widgets that are not
4520 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4521 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4524 gtk_widget_queue_draw_area (GtkWidget *widget,
4531 cairo_region_t *region;
4533 g_return_if_fail (GTK_IS_WIDGET (widget));
4538 rect.height = height;
4540 region = cairo_region_create_rectangle (&rect);
4541 gtk_widget_queue_draw_region (widget, region);
4542 cairo_region_destroy (region);
4546 * gtk_widget_queue_draw:
4547 * @widget: a #GtkWidget
4549 * Equivalent to calling gtk_widget_queue_draw_area() for the
4550 * entire area of a widget.
4553 gtk_widget_queue_draw (GtkWidget *widget)
4557 g_return_if_fail (GTK_IS_WIDGET (widget));
4559 gtk_widget_get_allocation (widget, &rect);
4561 if (!gtk_widget_get_has_window (widget))
4562 gtk_widget_queue_draw_area (widget,
4563 rect.x, rect.y, rect.width, rect.height);
4565 gtk_widget_queue_draw_area (widget,
4566 0, 0, rect.width, rect.height);
4570 * gtk_widget_queue_resize:
4571 * @widget: a #GtkWidget
4573 * This function is only for use in widget implementations.
4574 * Flags a widget to have its size renegotiated; should
4575 * be called when a widget for some reason has a new size request.
4576 * For example, when you change the text in a #GtkLabel, #GtkLabel
4577 * queues a resize to ensure there's enough space for the new text.
4579 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4580 * from inside its implementation of the GtkWidgetClass::size_allocate
4581 * virtual method. Calls to gtk_widget_queue_resize() from inside
4582 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4585 gtk_widget_queue_resize (GtkWidget *widget)
4587 g_return_if_fail (GTK_IS_WIDGET (widget));
4589 if (gtk_widget_get_realized (widget))
4590 gtk_widget_queue_shallow_draw (widget);
4592 _gtk_size_group_queue_resize (widget, 0);
4596 * gtk_widget_queue_resize_no_redraw:
4597 * @widget: a #GtkWidget
4599 * This function works like gtk_widget_queue_resize(),
4600 * except that the widget is not invalidated.
4605 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4607 g_return_if_fail (GTK_IS_WIDGET (widget));
4609 _gtk_size_group_queue_resize (widget, 0);
4613 * gtk_widget_size_request:
4614 * @widget: a #GtkWidget
4615 * @requisition: (out): a #GtkRequisition to be filled in
4617 * This function is typically used when implementing a #GtkContainer
4618 * subclass. Obtains the preferred size of a widget. The container
4619 * uses this information to arrange its child widgets and decide what
4620 * size allocations to give them with gtk_widget_size_allocate().
4622 * You can also call this function from an application, with some
4623 * caveats. Most notably, getting a size request requires the widget
4624 * to be associated with a screen, because font information may be
4625 * needed. Multihead-aware applications should keep this in mind.
4627 * Also remember that the size request is not necessarily the size
4628 * a widget will actually be allocated.
4630 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4633 gtk_widget_size_request (GtkWidget *widget,
4634 GtkRequisition *requisition)
4636 g_return_if_fail (GTK_IS_WIDGET (widget));
4638 gtk_widget_get_preferred_size (widget, requisition, NULL);
4642 * gtk_widget_get_child_requisition:
4643 * @widget: a #GtkWidget
4644 * @requisition: (out): a #GtkRequisition to be filled in
4646 * This function is only for use in widget implementations. Obtains
4647 * @widget->requisition, unless someone has forced a particular
4648 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4649 * in which case it returns that geometry instead of the widget's
4652 * This function differs from gtk_widget_size_request() in that
4653 * it retrieves the last size request value from @widget->requisition,
4654 * while gtk_widget_size_request() actually calls the "size_request" method
4655 * on @widget to compute the size request and fill in @widget->requisition,
4656 * and only then returns @widget->requisition.
4658 * Because this function does not call the "size_request" method, it
4659 * can only be used when you know that @widget->requisition is
4660 * up-to-date, that is, gtk_widget_size_request() has been called
4661 * since the last time a resize was queued. In general, only container
4662 * implementations have this information; applications should use
4663 * gtk_widget_size_request().
4666 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4669 gtk_widget_get_child_requisition (GtkWidget *widget,
4670 GtkRequisition *requisition)
4672 gtk_widget_get_preferred_size (widget, requisition, NULL);
4676 invalidate_predicate (GdkWindow *window,
4681 gdk_window_get_user_data (window, &user_data);
4683 return (user_data == data);
4686 /* Invalidate @region in widget->window and all children
4687 * of widget->window owned by widget. @region is in the
4688 * same coordinates as widget->allocation and will be
4689 * modified by this call.
4692 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4693 cairo_region_t *region)
4695 GtkWidgetPrivate *priv = widget->priv;
4697 if (!gtk_widget_get_realized (widget))
4700 if (gtk_widget_get_has_window (widget) && priv->parent)
4704 gdk_window_get_position (priv->window, &x, &y);
4705 cairo_region_translate (region, -x, -y);
4708 gdk_window_invalidate_maybe_recurse (priv->window, region,
4709 invalidate_predicate, widget);
4713 * gtk_widget_queue_shallow_draw:
4714 * @widget: a #GtkWidget
4716 * Like gtk_widget_queue_draw(), but only windows owned
4717 * by @widget are invalidated.
4720 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4723 cairo_region_t *region;
4725 if (!gtk_widget_get_realized (widget))
4728 gtk_widget_get_allocation (widget, &rect);
4730 region = cairo_region_create_rectangle (&rect);
4731 gtk_widget_invalidate_widget_windows (widget, region);
4732 cairo_region_destroy (region);
4736 * gtk_widget_size_allocate:
4737 * @widget: a #GtkWidget
4738 * @allocation: position and size to be allocated to @widget
4740 * This function is only used by #GtkContainer subclasses, to assign a size
4741 * and position to their child widgets.
4743 * In this function, the allocation may be adjusted. It will be forced
4744 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4745 * method on the child will be used to adjust the allocation. Standard
4746 * adjustments include removing the widget's margins, and applying the
4747 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4750 gtk_widget_size_allocate (GtkWidget *widget,
4751 GtkAllocation *allocation)
4753 GtkWidgetPrivate *priv;
4754 GdkRectangle real_allocation;
4755 GdkRectangle old_allocation;
4756 GdkRectangle adjusted_allocation;
4757 gboolean alloc_needed;
4758 gboolean size_changed;
4759 gboolean position_changed;
4760 gint natural_width, natural_height, dummy;
4761 gint min_width, min_height;
4763 priv = widget->priv;
4765 g_return_if_fail (GTK_IS_WIDGET (widget));
4767 gtk_widget_push_verify_invariants (widget);
4769 #ifdef G_ENABLE_DEBUG
4770 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4781 parent = gtk_widget_get_parent (parent);
4784 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4785 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4786 2 * depth, " ", name,
4787 allocation->width, allocation->height);
4789 #endif /* G_ENABLE_DEBUG */
4791 alloc_needed = priv->alloc_needed;
4792 if (!priv->width_request_needed && !priv->height_request_needed)
4793 /* Preserve request/allocate ordering */
4794 priv->alloc_needed = FALSE;
4796 old_allocation = priv->allocation;
4797 real_allocation = *allocation;
4799 adjusted_allocation = real_allocation;
4800 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4802 /* Go ahead and request the height for allocated width, note that the internals
4803 * of get_height_for_width will internally limit the for_size to natural size
4804 * when aligning implicitly.
4806 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4807 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &dummy, &natural_height);
4811 /* Go ahead and request the width for allocated height, note that the internals
4812 * of get_width_for_height will internally limit the for_size to natural size
4813 * when aligning implicitly.
4815 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4816 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &dummy, &natural_width);
4819 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4820 * allocated sizes and possibly limit them to the natural sizes */
4821 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4822 GTK_ORIENTATION_HORIZONTAL,
4825 &adjusted_allocation.x,
4826 &adjusted_allocation.width);
4827 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4828 GTK_ORIENTATION_VERTICAL,
4831 &adjusted_allocation.y,
4832 &adjusted_allocation.height);
4834 if (adjusted_allocation.x < real_allocation.x ||
4835 adjusted_allocation.y < real_allocation.y ||
4836 (adjusted_allocation.x + adjusted_allocation.width) >
4837 (real_allocation.x + real_allocation.width) ||
4838 (adjusted_allocation.y + adjusted_allocation.height >
4839 real_allocation.y + real_allocation.height))
4841 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",
4842 G_OBJECT_TYPE_NAME (widget), widget,
4843 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4844 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4845 adjusted_allocation = real_allocation; /* veto it */
4849 real_allocation = adjusted_allocation;
4852 if (real_allocation.width < 0 || real_allocation.height < 0)
4854 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4855 real_allocation.width,
4856 real_allocation.height);
4859 real_allocation.width = MAX (real_allocation.width, 1);
4860 real_allocation.height = MAX (real_allocation.height, 1);
4862 size_changed = (old_allocation.width != real_allocation.width ||
4863 old_allocation.height != real_allocation.height);
4864 position_changed = (old_allocation.x != real_allocation.x ||
4865 old_allocation.y != real_allocation.y);
4867 if (!alloc_needed && !size_changed && !position_changed)
4870 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4872 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4873 priv->width_request_needed = FALSE;
4874 priv->height_request_needed = FALSE;
4875 priv->alloc_needed = FALSE;
4877 if (gtk_widget_get_mapped (widget))
4879 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4881 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4883 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4884 cairo_region_union_rectangle (invalidate, &old_allocation);
4886 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4887 cairo_region_destroy (invalidate);
4892 if (priv->redraw_on_alloc)
4894 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4896 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4897 cairo_region_union_rectangle (invalidate, &old_allocation);
4899 gtk_widget_invalidate_widget_windows (widget, invalidate);
4900 cairo_region_destroy (invalidate);
4904 if (size_changed || position_changed)
4906 GtkStyleContext *context;
4908 context = gtk_widget_get_style_context (widget);
4909 _gtk_style_context_invalidate_animation_areas (context);
4913 if ((size_changed || position_changed) && priv->parent &&
4914 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4916 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4917 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4918 cairo_region_destroy (invalidate);
4922 gtk_widget_pop_verify_invariants (widget);
4926 * gtk_widget_common_ancestor:
4927 * @widget_a: a #GtkWidget
4928 * @widget_b: a #GtkWidget
4930 * Find the common ancestor of @widget_a and @widget_b that
4931 * is closest to the two widgets.
4933 * Return value: the closest common ancestor of @widget_a and
4934 * @widget_b or %NULL if @widget_a and @widget_b do not
4935 * share a common ancestor.
4938 gtk_widget_common_ancestor (GtkWidget *widget_a,
4939 GtkWidget *widget_b)
4941 GtkWidget *parent_a;
4942 GtkWidget *parent_b;
4946 parent_a = widget_a;
4947 while (parent_a->priv->parent)
4949 parent_a = parent_a->priv->parent;
4953 parent_b = widget_b;
4954 while (parent_b->priv->parent)
4956 parent_b = parent_b->priv->parent;
4960 if (parent_a != parent_b)
4963 while (depth_a > depth_b)
4965 widget_a = widget_a->priv->parent;
4969 while (depth_b > depth_a)
4971 widget_b = widget_b->priv->parent;
4975 while (widget_a != widget_b)
4977 widget_a = widget_a->priv->parent;
4978 widget_b = widget_b->priv->parent;
4985 * gtk_widget_translate_coordinates:
4986 * @src_widget: a #GtkWidget
4987 * @dest_widget: a #GtkWidget
4988 * @src_x: X position relative to @src_widget
4989 * @src_y: Y position relative to @src_widget
4990 * @dest_x: (out): location to store X position relative to @dest_widget
4991 * @dest_y: (out): location to store Y position relative to @dest_widget
4993 * Translate coordinates relative to @src_widget's allocation to coordinates
4994 * relative to @dest_widget's allocations. In order to perform this
4995 * operation, both widgets must be realized, and must share a common
4998 * Return value: %FALSE if either widget was not realized, or there
4999 * was no common ancestor. In this case, nothing is stored in
5000 * *@dest_x and *@dest_y. Otherwise %TRUE.
5003 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5004 GtkWidget *dest_widget,
5010 GtkWidgetPrivate *src_priv = src_widget->priv;
5011 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5012 GtkWidget *ancestor;
5014 GList *dest_list = NULL;
5016 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5017 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5019 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5020 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5023 /* Translate from allocation relative to window relative */
5024 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5027 gdk_window_get_position (src_priv->window, &wx, &wy);
5029 src_x -= wx - src_priv->allocation.x;
5030 src_y -= wy - src_priv->allocation.y;
5034 src_x += src_priv->allocation.x;
5035 src_y += src_priv->allocation.y;
5038 /* Translate to the common ancestor */
5039 window = src_priv->window;
5040 while (window != ancestor->priv->window)
5044 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5049 window = gdk_window_get_effective_parent (window);
5051 if (!window) /* Handle GtkHandleBox */
5056 window = dest_priv->window;
5057 while (window != ancestor->priv->window)
5059 dest_list = g_list_prepend (dest_list, window);
5061 window = gdk_window_get_effective_parent (window);
5063 if (!window) /* Handle GtkHandleBox */
5065 g_list_free (dest_list);
5074 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5079 dest_list = g_list_remove (dest_list, dest_list->data);
5082 /* Translate from window relative to allocation relative */
5083 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5086 gdk_window_get_position (dest_priv->window, &wx, &wy);
5088 src_x += wx - dest_priv->allocation.x;
5089 src_y += wy - dest_priv->allocation.y;
5093 src_x -= dest_priv->allocation.x;
5094 src_y -= dest_priv->allocation.y;
5106 gtk_widget_real_size_allocate (GtkWidget *widget,
5107 GtkAllocation *allocation)
5109 GtkWidgetPrivate *priv = widget->priv;
5111 priv->allocation = *allocation;
5113 if (gtk_widget_get_realized (widget) &&
5114 gtk_widget_get_has_window (widget))
5116 gdk_window_move_resize (priv->window,
5117 allocation->x, allocation->y,
5118 allocation->width, allocation->height);
5122 /* translate initial/final into start/end */
5124 effective_align (GtkAlign align,
5125 GtkTextDirection direction)
5129 case GTK_ALIGN_START:
5130 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5132 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5139 adjust_for_align (GtkAlign align,
5141 gint *allocated_pos,
5142 gint *allocated_size)
5146 case GTK_ALIGN_FILL:
5147 /* change nothing */
5149 case GTK_ALIGN_START:
5150 /* keep *allocated_pos where it is */
5151 *allocated_size = MIN (*allocated_size, *natural_size);
5154 if (*allocated_size > *natural_size)
5156 *allocated_pos += (*allocated_size - *natural_size);
5157 *allocated_size = *natural_size;
5160 case GTK_ALIGN_CENTER:
5161 if (*allocated_size > *natural_size)
5163 *allocated_pos += (*allocated_size - *natural_size) / 2;
5164 *allocated_size = MIN (*allocated_size, *natural_size);
5171 adjust_for_margin(gint start_margin,
5175 gint *allocated_pos,
5176 gint *allocated_size)
5178 *minimum_size -= (start_margin + end_margin);
5179 *natural_size -= (start_margin + end_margin);
5180 *allocated_pos += start_margin;
5181 *allocated_size -= (start_margin + end_margin);
5185 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5186 GtkOrientation orientation,
5189 gint *allocated_pos,
5190 gint *allocated_size)
5192 const GtkWidgetAuxInfo *aux_info;
5194 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5196 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5198 adjust_for_margin (aux_info->margin.left,
5199 aux_info->margin.right,
5200 minimum_size, natural_size,
5201 allocated_pos, allocated_size);
5202 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5203 natural_size, allocated_pos, allocated_size);
5207 adjust_for_margin (aux_info->margin.top,
5208 aux_info->margin.bottom,
5209 minimum_size, natural_size,
5210 allocated_pos, allocated_size);
5211 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5212 natural_size, allocated_pos, allocated_size);
5217 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5220 GtkWidgetPrivate *priv = widget->priv;
5222 /* widgets must be onscreen for accels to take effect */
5223 return gtk_widget_is_sensitive (widget) &&
5224 gtk_widget_is_drawable (widget) &&
5225 gdk_window_is_viewable (priv->window);
5229 * gtk_widget_can_activate_accel:
5230 * @widget: a #GtkWidget
5231 * @signal_id: the ID of a signal installed on @widget
5233 * Determines whether an accelerator that activates the signal
5234 * identified by @signal_id can currently be activated.
5235 * This is done by emitting the #GtkWidget::can-activate-accel
5236 * signal on @widget; if the signal isn't overridden by a
5237 * handler or in a derived widget, then the default check is
5238 * that the widget must be sensitive, and the widget and all
5239 * its ancestors mapped.
5241 * Return value: %TRUE if the accelerator can be activated.
5246 gtk_widget_can_activate_accel (GtkWidget *widget,
5249 gboolean can_activate = FALSE;
5250 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5251 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5252 return can_activate;
5261 closure_accel_activate (GClosure *closure,
5262 GValue *return_value,
5263 guint n_param_values,
5264 const GValue *param_values,
5265 gpointer invocation_hint,
5266 gpointer marshal_data)
5268 AccelClosure *aclosure = (AccelClosure*) closure;
5269 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5272 g_signal_emit (closure->data, aclosure->signal_id, 0);
5274 /* whether accelerator was handled */
5275 g_value_set_boolean (return_value, can_activate);
5279 closures_destroy (gpointer data)
5281 GSList *slist, *closures = data;
5283 for (slist = closures; slist; slist = slist->next)
5285 g_closure_invalidate (slist->data);
5286 g_closure_unref (slist->data);
5288 g_slist_free (closures);
5292 widget_new_accel_closure (GtkWidget *widget,
5295 AccelClosure *aclosure;
5296 GClosure *closure = NULL;
5297 GSList *slist, *closures;
5299 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5300 for (slist = closures; slist; slist = slist->next)
5301 if (!gtk_accel_group_from_accel_closure (slist->data))
5303 /* reuse this closure */
5304 closure = slist->data;
5309 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5310 closures = g_slist_prepend (closures, g_closure_ref (closure));
5311 g_closure_sink (closure);
5312 g_closure_set_marshal (closure, closure_accel_activate);
5314 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5316 aclosure = (AccelClosure*) closure;
5317 g_assert (closure->data == widget);
5318 g_assert (closure->marshal == closure_accel_activate);
5319 aclosure->signal_id = signal_id;
5325 * gtk_widget_add_accelerator
5326 * @widget: widget to install an accelerator on
5327 * @accel_signal: widget signal to emit on accelerator activation
5328 * @accel_group: accel group for this widget, added to its toplevel
5329 * @accel_key: GDK keyval of the accelerator
5330 * @accel_mods: modifier key combination of the accelerator
5331 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5333 * Installs an accelerator for this @widget in @accel_group that causes
5334 * @accel_signal to be emitted if the accelerator is activated.
5335 * The @accel_group needs to be added to the widget's toplevel via
5336 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5337 * Accelerators added through this function are not user changeable during
5338 * runtime. If you want to support accelerators that can be changed by the
5339 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5340 * gtk_menu_item_set_accel_path() instead.
5343 gtk_widget_add_accelerator (GtkWidget *widget,
5344 const gchar *accel_signal,
5345 GtkAccelGroup *accel_group,
5347 GdkModifierType accel_mods,
5348 GtkAccelFlags accel_flags)
5353 g_return_if_fail (GTK_IS_WIDGET (widget));
5354 g_return_if_fail (accel_signal != NULL);
5355 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5357 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5358 if (!query.signal_id ||
5359 !(query.signal_flags & G_SIGNAL_ACTION) ||
5360 query.return_type != G_TYPE_NONE ||
5363 /* hmm, should be elaborate enough */
5364 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5365 G_OBJECT_TYPE_NAME (widget), accel_signal);
5369 closure = widget_new_accel_closure (widget, query.signal_id);
5371 g_object_ref (widget);
5373 /* install the accelerator. since we don't map this onto an accel_path,
5374 * the accelerator will automatically be locked.
5376 gtk_accel_group_connect (accel_group,
5379 accel_flags | GTK_ACCEL_LOCKED,
5382 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5384 g_object_unref (widget);
5388 * gtk_widget_remove_accelerator:
5389 * @widget: widget to install an accelerator on
5390 * @accel_group: accel group for this widget
5391 * @accel_key: GDK keyval of the accelerator
5392 * @accel_mods: modifier key combination of the accelerator
5393 * @returns: whether an accelerator was installed and could be removed
5395 * Removes an accelerator from @widget, previously installed with
5396 * gtk_widget_add_accelerator().
5399 gtk_widget_remove_accelerator (GtkWidget *widget,
5400 GtkAccelGroup *accel_group,
5402 GdkModifierType accel_mods)
5404 GtkAccelGroupEntry *ag_entry;
5405 GList *slist, *clist;
5408 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5409 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5411 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5412 clist = gtk_widget_list_accel_closures (widget);
5413 for (slist = clist; slist; slist = slist->next)
5417 for (i = 0; i < n; i++)
5418 if (slist->data == (gpointer) ag_entry[i].closure)
5420 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5422 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5424 g_list_free (clist);
5429 g_list_free (clist);
5431 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5432 accel_key, accel_mods, accel_group,
5433 G_OBJECT_TYPE_NAME (widget), widget);
5439 * gtk_widget_list_accel_closures:
5440 * @widget: widget to list accelerator closures for
5442 * Lists the closures used by @widget for accelerator group connections
5443 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5444 * The closures can be used to monitor accelerator changes on @widget,
5445 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5446 * #GtkAccelGroup of a closure which can be found out with
5447 * gtk_accel_group_from_accel_closure().
5449 * Return value: (transfer container) (element-type GClosure):
5450 * a newly allocated #GList of closures
5453 gtk_widget_list_accel_closures (GtkWidget *widget)
5456 GList *clist = NULL;
5458 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5460 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5461 if (gtk_accel_group_from_accel_closure (slist->data))
5462 clist = g_list_prepend (clist, slist->data);
5468 GtkAccelGroup *accel_group;
5473 destroy_accel_path (gpointer data)
5475 AccelPath *apath = data;
5477 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5479 /* closures_destroy takes care of unrefing the closure */
5480 g_object_unref (apath->accel_group);
5482 g_slice_free (AccelPath, apath);
5487 * gtk_widget_set_accel_path:
5488 * @widget: a #GtkWidget
5489 * @accel_path: (allow-none): path used to look up the accelerator
5490 * @accel_group: (allow-none): a #GtkAccelGroup.
5492 * Given an accelerator group, @accel_group, and an accelerator path,
5493 * @accel_path, sets up an accelerator in @accel_group so whenever the
5494 * key binding that is defined for @accel_path is pressed, @widget
5495 * will be activated. This removes any accelerators (for any
5496 * accelerator group) installed by previous calls to
5497 * gtk_widget_set_accel_path(). Associating accelerators with
5498 * paths allows them to be modified by the user and the modifications
5499 * to be saved for future use. (See gtk_accel_map_save().)
5501 * This function is a low level function that would most likely
5502 * be used by a menu creation system like #GtkUIManager. If you
5503 * use #GtkUIManager, setting up accelerator paths will be done
5506 * Even when you you aren't using #GtkUIManager, if you only want to
5507 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5508 * provides a somewhat more convenient interface.
5510 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5511 * pass a static string, you can save some memory by interning it first with
5512 * g_intern_static_string().
5515 gtk_widget_set_accel_path (GtkWidget *widget,
5516 const gchar *accel_path,
5517 GtkAccelGroup *accel_group)
5521 g_return_if_fail (GTK_IS_WIDGET (widget));
5522 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5526 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5527 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5529 gtk_accel_map_add_entry (accel_path, 0, 0);
5530 apath = g_slice_new (AccelPath);
5531 apath->accel_group = g_object_ref (accel_group);
5532 apath->path_quark = g_quark_from_string (accel_path);
5533 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5538 /* also removes possible old settings */
5539 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5542 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5544 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5548 _gtk_widget_get_accel_path (GtkWidget *widget,
5553 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5555 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5557 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5558 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5562 * gtk_widget_mnemonic_activate:
5563 * @widget: a #GtkWidget
5564 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5566 * Emits the #GtkWidget::mnemonic-activate signal.
5568 * The default handler for this signal activates the @widget if
5569 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5572 * Returns: %TRUE if the signal has been handled
5575 gtk_widget_mnemonic_activate (GtkWidget *widget,
5576 gboolean group_cycling)
5580 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5582 group_cycling = group_cycling != FALSE;
5583 if (!gtk_widget_is_sensitive (widget))
5586 g_signal_emit (widget,
5587 widget_signals[MNEMONIC_ACTIVATE],
5595 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5596 gboolean group_cycling)
5598 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5599 gtk_widget_activate (widget);
5600 else if (gtk_widget_get_can_focus (widget))
5601 gtk_widget_grab_focus (widget);
5604 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5605 G_OBJECT_TYPE_NAME (widget));
5606 gtk_widget_error_bell (widget);
5611 static const cairo_user_data_key_t event_key;
5614 _gtk_cairo_get_event (cairo_t *cr)
5616 g_return_val_if_fail (cr != NULL, NULL);
5618 return cairo_get_user_data (cr, &event_key);
5622 gtk_cairo_set_event (cairo_t *cr,
5623 GdkEventExpose *event)
5625 cairo_set_user_data (cr, &event_key, event, NULL);
5629 * gtk_cairo_should_draw_window:
5630 * @cr: a cairo context
5631 * @window: the window to check
5633 * This function is supposed to be called in #GtkWidget::draw
5634 * implementations for widgets that support multiple windows.
5635 * @cr must be untransformed from invoking of the draw function.
5636 * This function will return %TRUE if the contents of the given
5637 * @window are supposed to be drawn and %FALSE otherwise. Note
5638 * that when the drawing was not initiated by the windowing
5639 * system this function will return %TRUE for all windows, so
5640 * you need to draw the bottommost window first. Also, do not
5641 * use "else if" statements to check which window should be drawn.
5643 * Returns: %TRUE if @window should be drawn
5648 gtk_cairo_should_draw_window (cairo_t *cr,
5651 GdkEventExpose *event;
5653 g_return_val_if_fail (cr != NULL, FALSE);
5654 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5656 event = _gtk_cairo_get_event (cr);
5658 return event == NULL ||
5659 event->window == window;
5662 /* code shared by gtk_container_propagate_draw() and
5666 _gtk_widget_draw_internal (GtkWidget *widget,
5668 gboolean clip_to_size)
5670 GtkStyleContext *context;
5672 if (!gtk_widget_is_drawable (widget))
5677 cairo_rectangle (cr,
5679 widget->priv->allocation.width,
5680 widget->priv->allocation.height);
5684 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5688 g_signal_emit (widget, widget_signals[DRAW],
5693 context = gtk_widget_get_style_context (widget);
5694 _gtk_style_context_coalesce_animation_areas (context, widget);
5699 * @widget: the widget to draw. It must be drawable (see
5700 * gtk_widget_is_drawable()) and a size must have been allocated.
5701 * @cr: a cairo context to draw to
5703 * Draws @widget to @cr. The top left corner of the widget will be
5704 * drawn to the currently set origin point of @cr.
5706 * You should pass a cairo context as @cr argument that is in an
5707 * original state. Otherwise the resulting drawing is undefined. For
5708 * example changing the operator using cairo_set_operator() or the
5709 * line width using cairo_set_line_width() might have unwanted side
5711 * You may however change the context's transform matrix - like with
5712 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5713 * region with cairo_clip() prior to calling this function. Also, it
5714 * is fine to modify the context with cairo_save() and
5715 * cairo_push_group() prior to calling this function.
5717 * <note><para>Special purpose widgets may contain special code for
5718 * rendering to the screen and might appear differently on screen
5719 * and when rendered using gtk_widget_draw().</para></note>
5724 gtk_widget_draw (GtkWidget *widget,
5727 GdkEventExpose *tmp_event;
5729 g_return_if_fail (GTK_IS_WIDGET (widget));
5730 g_return_if_fail (!widget->priv->alloc_needed);
5731 g_return_if_fail (cr != NULL);
5734 /* We have to reset the event here so that draw functions can call
5735 * gtk_widget_draw() on random other widgets and get the desired
5736 * effect: Drawing all contents, not just the current window.
5738 tmp_event = _gtk_cairo_get_event (cr);
5739 gtk_cairo_set_event (cr, NULL);
5741 _gtk_widget_draw_internal (widget, cr, TRUE);
5743 gtk_cairo_set_event (cr, tmp_event);
5748 gtk_widget_real_key_press_event (GtkWidget *widget,
5751 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5755 gtk_widget_real_key_release_event (GtkWidget *widget,
5758 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5762 gtk_widget_real_focus_in_event (GtkWidget *widget,
5763 GdkEventFocus *event)
5765 gtk_widget_queue_shallow_draw (widget);
5771 gtk_widget_real_focus_out_event (GtkWidget *widget,
5772 GdkEventFocus *event)
5774 gtk_widget_queue_shallow_draw (widget);
5779 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5780 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5784 * @widget: a #GtkWidget
5785 * @event: a #GdkEvent
5787 * Rarely-used function. This function is used to emit
5788 * the event signals on a widget (those signals should never
5789 * be emitted without using this function to do so).
5790 * If you want to synthesize an event though, don't use this function;
5791 * instead, use gtk_main_do_event() so the event will behave as if
5792 * it were in the event queue. Don't synthesize expose events; instead,
5793 * use gdk_window_invalidate_rect() to invalidate a region of the
5796 * Return value: return from the event signal emission (%TRUE if
5797 * the event was handled)
5800 gtk_widget_event (GtkWidget *widget,
5803 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5804 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5806 if (event->type == GDK_EXPOSE)
5808 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5809 "the same effect, call gdk_window_invalidate_rect/region(), "
5810 "followed by gdk_window_process_updates().");
5814 return gtk_widget_event_internal (widget, event);
5817 /* Returns TRUE if a translation should be done */
5819 _gtk_widget_get_translation_to_window (GtkWidget *widget,
5824 GdkWindow *w, *widget_window;
5826 if (!gtk_widget_get_has_window (widget))
5828 *x = -widget->priv->allocation.x;
5829 *y = -widget->priv->allocation.y;
5837 widget_window = gtk_widget_get_window (widget);
5839 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5842 gdk_window_get_position (w, &wx, &wy);
5859 * gtk_cairo_transform_to_window:
5860 * @cr: the cairo context to transform
5861 * @widget: the widget the context is currently centered for
5862 * @window: the window to transform the context to
5864 * Transforms the given cairo context @cr that from @widget-relative
5865 * coordinates to @window-relative coordinates.
5866 * If the @widget's window is not an ancestor of @window, no
5867 * modification will be applied.
5869 * This is the inverse to the transformation GTK applies when
5870 * preparing an expose event to be emitted with the #GtkWidget::draw
5871 * signal. It is intended to help porting multiwindow widgets from
5872 * GTK+ 2 to the rendering architecture of GTK+ 3.
5877 gtk_cairo_transform_to_window (cairo_t *cr,
5883 g_return_if_fail (cr != NULL);
5884 g_return_if_fail (GTK_IS_WIDGET (widget));
5885 g_return_if_fail (GDK_IS_WINDOW (window));
5887 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
5888 cairo_translate (cr, x, y);
5892 * gtk_widget_send_expose:
5893 * @widget: a #GtkWidget
5894 * @event: a expose #GdkEvent
5896 * Very rarely-used function. This function is used to emit
5897 * an expose event on a widget. This function is not normally used
5898 * directly. The only time it is used is when propagating an expose
5899 * event to a child %NO_WINDOW widget, and that is normally done
5900 * using gtk_container_propagate_draw().
5902 * If you want to force an area of a window to be redrawn,
5903 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5904 * To cause the redraw to be done immediately, follow that call
5905 * with a call to gdk_window_process_updates().
5907 * Return value: return from the event signal emission (%TRUE if
5908 * the event was handled)
5911 gtk_widget_send_expose (GtkWidget *widget,
5914 gboolean result = FALSE;
5919 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5920 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5921 g_return_val_if_fail (event != NULL, TRUE);
5922 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5924 cr = gdk_cairo_create (event->expose.window);
5925 gtk_cairo_set_event (cr, &event->expose);
5927 gdk_cairo_region (cr, event->expose.region);
5930 do_clip = _gtk_widget_get_translation_to_window (widget,
5931 event->expose.window,
5933 cairo_translate (cr, -x, -y);
5935 _gtk_widget_draw_internal (widget, cr, do_clip);
5937 /* unset here, so if someone keeps a reference to cr we
5938 * don't leak the window. */
5939 gtk_cairo_set_event (cr, NULL);
5946 event_window_is_still_viewable (GdkEvent *event)
5948 /* Check that we think the event's window is viewable before
5949 * delivering the event, to prevent suprises. We do this here
5950 * at the last moment, since the event may have been queued
5951 * up behind other events, held over a recursive main loop, etc.
5953 switch (event->type)
5956 case GDK_MOTION_NOTIFY:
5957 case GDK_BUTTON_PRESS:
5958 case GDK_2BUTTON_PRESS:
5959 case GDK_3BUTTON_PRESS:
5961 case GDK_ENTER_NOTIFY:
5962 case GDK_PROXIMITY_IN:
5964 return event->any.window && gdk_window_is_viewable (event->any.window);
5967 /* The following events are the second half of paired events;
5968 * we always deliver them to deal with widgets that clean up
5969 * on the second half.
5971 case GDK_BUTTON_RELEASE:
5972 case GDK_KEY_RELEASE:
5973 case GDK_LEAVE_NOTIFY:
5974 case GDK_PROXIMITY_OUT:
5978 /* Remaining events would make sense on an not-viewable window,
5979 * or don't have an associated window.
5986 gtk_widget_event_internal (GtkWidget *widget,
5989 gboolean return_val = FALSE;
5991 /* We check only once for is-still-visible; if someone
5992 * hides the window in on of the signals on the widget,
5993 * they are responsible for returning TRUE to terminate
5996 if (!event_window_is_still_viewable (event))
5999 g_object_ref (widget);
6001 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6002 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6007 switch (event->type)
6013 case GDK_BUTTON_PRESS:
6014 case GDK_2BUTTON_PRESS:
6015 case GDK_3BUTTON_PRESS:
6016 signal_num = BUTTON_PRESS_EVENT;
6019 signal_num = SCROLL_EVENT;
6021 case GDK_BUTTON_RELEASE:
6022 signal_num = BUTTON_RELEASE_EVENT;
6024 case GDK_MOTION_NOTIFY:
6025 signal_num = MOTION_NOTIFY_EVENT;
6028 signal_num = DELETE_EVENT;
6031 signal_num = DESTROY_EVENT;
6032 _gtk_tooltip_hide (widget);
6035 signal_num = KEY_PRESS_EVENT;
6037 case GDK_KEY_RELEASE:
6038 signal_num = KEY_RELEASE_EVENT;
6040 case GDK_ENTER_NOTIFY:
6041 signal_num = ENTER_NOTIFY_EVENT;
6043 case GDK_LEAVE_NOTIFY:
6044 signal_num = LEAVE_NOTIFY_EVENT;
6046 case GDK_FOCUS_CHANGE:
6047 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6048 if (event->focus_change.in)
6049 _gtk_tooltip_focus_in (widget);
6051 _gtk_tooltip_focus_out (widget);
6054 signal_num = CONFIGURE_EVENT;
6057 signal_num = MAP_EVENT;
6060 signal_num = UNMAP_EVENT;
6062 case GDK_WINDOW_STATE:
6063 signal_num = WINDOW_STATE_EVENT;
6065 case GDK_PROPERTY_NOTIFY:
6066 signal_num = PROPERTY_NOTIFY_EVENT;
6068 case GDK_SELECTION_CLEAR:
6069 signal_num = SELECTION_CLEAR_EVENT;
6071 case GDK_SELECTION_REQUEST:
6072 signal_num = SELECTION_REQUEST_EVENT;
6074 case GDK_SELECTION_NOTIFY:
6075 signal_num = SELECTION_NOTIFY_EVENT;
6077 case GDK_PROXIMITY_IN:
6078 signal_num = PROXIMITY_IN_EVENT;
6080 case GDK_PROXIMITY_OUT:
6081 signal_num = PROXIMITY_OUT_EVENT;
6083 case GDK_VISIBILITY_NOTIFY:
6084 signal_num = VISIBILITY_NOTIFY_EVENT;
6086 case GDK_GRAB_BROKEN:
6087 signal_num = GRAB_BROKEN_EVENT;
6090 signal_num = DAMAGE_EVENT;
6093 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6097 if (signal_num != -1)
6098 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6100 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6101 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6105 g_object_unref (widget);
6111 * gtk_widget_activate:
6112 * @widget: a #GtkWidget that's activatable
6114 * For widgets that can be "activated" (buttons, menu items, etc.)
6115 * this function activates them. Activation is what happens when you
6116 * press Enter on a widget during key navigation. If @widget isn't
6117 * activatable, the function returns %FALSE.
6119 * Return value: %TRUE if the widget was activatable
6122 gtk_widget_activate (GtkWidget *widget)
6124 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6126 if (WIDGET_CLASS (widget)->activate_signal)
6128 /* FIXME: we should eventually check the signals signature here */
6129 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6138 gtk_widget_reparent_subwindows (GtkWidget *widget,
6139 GdkWindow *new_window)
6141 GtkWidgetPrivate *priv = widget->priv;
6143 if (!gtk_widget_get_has_window (widget))
6145 GList *children = gdk_window_get_children (priv->window);
6148 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6150 GdkWindow *window = tmp_list->data;
6153 gdk_window_get_user_data (window, &child);
6154 while (child && child != widget)
6155 child = ((GtkWidget*) child)->priv->parent;
6158 gdk_window_reparent (window, new_window, 0, 0);
6161 g_list_free (children);
6166 GList *tmp_list, *children;
6168 parent = gdk_window_get_parent (priv->window);
6171 gdk_window_reparent (priv->window, new_window, 0, 0);
6174 children = gdk_window_get_children (parent);
6176 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6178 GdkWindow *window = tmp_list->data;
6181 gdk_window_get_user_data (window, &child);
6183 if (child == widget)
6184 gdk_window_reparent (window, new_window, 0, 0);
6187 g_list_free (children);
6193 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6194 gpointer client_data)
6196 GtkWidgetPrivate *priv = widget->priv;
6198 g_assert (client_data != NULL);
6200 if (!gtk_widget_get_has_window (widget))
6203 g_object_unref (priv->window);
6204 priv->window = (GdkWindow*) client_data;
6206 g_object_ref (priv->window);
6208 if (GTK_IS_CONTAINER (widget))
6209 gtk_container_forall (GTK_CONTAINER (widget),
6210 gtk_widget_reparent_fixup_child,
6216 * gtk_widget_reparent:
6217 * @widget: a #GtkWidget
6218 * @new_parent: a #GtkContainer to move the widget into
6220 * Moves a widget from one #GtkContainer to another, handling reference
6221 * count issues to avoid destroying the widget.
6224 gtk_widget_reparent (GtkWidget *widget,
6225 GtkWidget *new_parent)
6227 GtkWidgetPrivate *priv;
6229 g_return_if_fail (GTK_IS_WIDGET (widget));
6230 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6231 priv = widget->priv;
6232 g_return_if_fail (priv->parent != NULL);
6234 if (priv->parent != new_parent)
6236 /* First try to see if we can get away without unrealizing
6237 * the widget as we reparent it. if so we set a flag so
6238 * that gtk_widget_unparent doesn't unrealize widget
6240 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6241 priv->in_reparent = TRUE;
6243 g_object_ref (widget);
6244 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6245 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6246 g_object_unref (widget);
6248 if (priv->in_reparent)
6250 priv->in_reparent = FALSE;
6252 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6253 gtk_widget_reparent_fixup_child (widget,
6254 gtk_widget_get_parent_window (widget));
6257 g_object_notify (G_OBJECT (widget), "parent");
6262 * gtk_widget_intersect:
6263 * @widget: a #GtkWidget
6264 * @area: a rectangle
6265 * @intersection: rectangle to store intersection of @widget and @area
6267 * Computes the intersection of a @widget's area and @area, storing
6268 * the intersection in @intersection, and returns %TRUE if there was
6269 * an intersection. @intersection may be %NULL if you're only
6270 * interested in whether there was an intersection.
6272 * Return value: %TRUE if there was an intersection
6275 gtk_widget_intersect (GtkWidget *widget,
6276 const GdkRectangle *area,
6277 GdkRectangle *intersection)
6279 GtkWidgetPrivate *priv;
6284 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6285 g_return_val_if_fail (area != NULL, FALSE);
6287 priv = widget->priv;
6290 dest = intersection;
6294 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6296 if (return_val && intersection && gtk_widget_get_has_window (widget))
6298 intersection->x -= priv->allocation.x;
6299 intersection->y -= priv->allocation.y;
6306 * gtk_widget_region_intersect:
6307 * @widget: a #GtkWidget
6308 * @region: a #cairo_region_t, in the same coordinate system as
6309 * @widget->allocation. That is, relative to @widget->window
6310 * for %NO_WINDOW widgets; relative to the parent window
6311 * of @widget->window for widgets with their own window.
6312 * @returns: A newly allocated region holding the intersection of @widget
6313 * and @region. The coordinates of the return value are
6314 * relative to @widget->window for %NO_WINDOW widgets, and
6315 * relative to the parent window of @widget->window for
6316 * widgets with their own window.
6318 * Computes the intersection of a @widget's area and @region, returning
6319 * the intersection. The result may be empty, use cairo_region_is_empty() to
6323 gtk_widget_region_intersect (GtkWidget *widget,
6324 const cairo_region_t *region)
6327 cairo_region_t *dest;
6329 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6330 g_return_val_if_fail (region != NULL, NULL);
6332 gtk_widget_get_allocation (widget, &rect);
6334 dest = cairo_region_create_rectangle (&rect);
6336 cairo_region_intersect (dest, region);
6342 * _gtk_widget_grab_notify:
6343 * @widget: a #GtkWidget
6344 * @was_grabbed: whether a grab is now in effect
6346 * Emits the #GtkWidget::grab-notify signal on @widget.
6351 _gtk_widget_grab_notify (GtkWidget *widget,
6352 gboolean was_grabbed)
6354 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6358 * gtk_widget_grab_focus:
6359 * @widget: a #GtkWidget
6361 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6362 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6363 * something like #GtkFrame won't work.
6365 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6366 * gtk_widget_set_can_focus() to modify that flag.
6368 * The widget also needs to be realized and mapped. This is indicated by the
6369 * related signals. Grabbing the focus immediately after creating the widget
6370 * will likely fail and cause critical warnings.
6373 gtk_widget_grab_focus (GtkWidget *widget)
6375 g_return_if_fail (GTK_IS_WIDGET (widget));
6377 if (!gtk_widget_is_sensitive (widget))
6380 g_object_ref (widget);
6381 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6382 g_object_notify (G_OBJECT (widget), "has-focus");
6383 g_object_unref (widget);
6387 reset_focus_recurse (GtkWidget *widget,
6390 if (GTK_IS_CONTAINER (widget))
6392 GtkContainer *container;
6394 container = GTK_CONTAINER (widget);
6395 gtk_container_set_focus_child (container, NULL);
6397 gtk_container_foreach (container,
6398 reset_focus_recurse,
6404 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6406 if (gtk_widget_get_can_focus (focus_widget))
6408 GtkWidget *toplevel;
6411 /* clear the current focus setting, break if the current widget
6412 * is the focus widget's parent, since containers above that will
6413 * be set by the next loop.
6415 toplevel = gtk_widget_get_toplevel (focus_widget);
6416 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6418 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6420 if (widget == focus_widget)
6422 /* We call _gtk_window_internal_set_focus() here so that the
6423 * toplevel window can request the focus if necessary.
6424 * This is needed when the toplevel is a GtkPlug
6426 if (!gtk_widget_has_focus (widget))
6427 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6434 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
6436 widget = widget->priv->parent;
6437 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6441 else if (toplevel != focus_widget)
6443 /* gtk_widget_grab_focus() operates on a tree without window...
6444 * actually, this is very questionable behaviour.
6447 gtk_container_foreach (GTK_CONTAINER (toplevel),
6448 reset_focus_recurse,
6452 /* now propagate the new focus up the widget tree and finally
6453 * set it on the window
6455 widget = focus_widget;
6456 while (widget->priv->parent)
6458 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6459 widget = widget->priv->parent;
6461 if (GTK_IS_WINDOW (widget))
6462 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6467 gtk_widget_real_query_tooltip (GtkWidget *widget,
6470 gboolean keyboard_tip,
6471 GtkTooltip *tooltip)
6473 gchar *tooltip_markup;
6474 gboolean has_tooltip;
6476 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6477 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6479 if (has_tooltip && tooltip_markup)
6481 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6489 gtk_widget_real_style_updated (GtkWidget *widget)
6491 GtkWidgetPrivate *priv = widget->priv;
6493 if (priv->style != NULL &&
6494 priv->style != gtk_widget_get_default_style ())
6496 /* Trigger ::style-set for old
6497 * widgets not listening to this
6499 g_signal_emit (widget,
6500 widget_signals[STYLE_SET],
6502 widget->priv->style);
6505 if (widget->priv->context)
6507 if (gtk_widget_get_realized (widget) &&
6508 gtk_widget_get_has_window (widget))
6509 gtk_style_context_set_background (widget->priv->context,
6510 widget->priv->window);
6513 if (widget->priv->anchored)
6514 gtk_widget_queue_resize (widget);
6518 gtk_widget_real_show_help (GtkWidget *widget,
6519 GtkWidgetHelpType help_type)
6521 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6523 _gtk_tooltip_toggle_keyboard_mode (widget);
6532 gtk_widget_real_focus (GtkWidget *widget,
6533 GtkDirectionType direction)
6535 if (!gtk_widget_get_can_focus (widget))
6538 if (!gtk_widget_is_focus (widget))
6540 gtk_widget_grab_focus (widget);
6548 gtk_widget_real_move_focus (GtkWidget *widget,
6549 GtkDirectionType direction)
6551 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6553 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6555 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6561 gtk_widget_real_keynav_failed (GtkWidget *widget,
6562 GtkDirectionType direction)
6564 gboolean cursor_only;
6568 case GTK_DIR_TAB_FORWARD:
6569 case GTK_DIR_TAB_BACKWARD:
6576 g_object_get (gtk_widget_get_settings (widget),
6577 "gtk-keynav-cursor-only", &cursor_only,
6584 gtk_widget_error_bell (widget);
6590 * gtk_widget_set_can_focus:
6591 * @widget: a #GtkWidget
6592 * @can_focus: whether or not @widget can own the input focus.
6594 * Specifies whether @widget can own the input focus. See
6595 * gtk_widget_grab_focus() for actually setting the input focus on a
6601 gtk_widget_set_can_focus (GtkWidget *widget,
6604 g_return_if_fail (GTK_IS_WIDGET (widget));
6606 if (widget->priv->can_focus != can_focus)
6608 widget->priv->can_focus = can_focus;
6610 gtk_widget_queue_resize (widget);
6611 g_object_notify (G_OBJECT (widget), "can-focus");
6616 * gtk_widget_get_can_focus:
6617 * @widget: a #GtkWidget
6619 * Determines whether @widget can own the input focus. See
6620 * gtk_widget_set_can_focus().
6622 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6627 gtk_widget_get_can_focus (GtkWidget *widget)
6629 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6631 return widget->priv->can_focus;
6635 * gtk_widget_has_focus:
6636 * @widget: a #GtkWidget
6638 * Determines if the widget has the global input focus. See
6639 * gtk_widget_is_focus() for the difference between having the global
6640 * input focus, and only having the focus within a toplevel.
6642 * Return value: %TRUE if the widget has the global input focus.
6647 gtk_widget_has_focus (GtkWidget *widget)
6649 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6651 return widget->priv->has_focus;
6655 * gtk_widget_is_focus:
6656 * @widget: a #GtkWidget
6658 * Determines if the widget is the focus widget within its
6659 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6660 * necessarily set; %HAS_FOCUS will only be set if the
6661 * toplevel widget additionally has the global input focus.)
6663 * Return value: %TRUE if the widget is the focus widget.
6666 gtk_widget_is_focus (GtkWidget *widget)
6668 GtkWidget *toplevel;
6670 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6672 toplevel = gtk_widget_get_toplevel (widget);
6674 if (GTK_IS_WINDOW (toplevel))
6675 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6681 * gtk_widget_set_can_default:
6682 * @widget: a #GtkWidget
6683 * @can_default: whether or not @widget can be a default widget.
6685 * Specifies whether @widget can be a default widget. See
6686 * gtk_widget_grab_default() for details about the meaning of
6692 gtk_widget_set_can_default (GtkWidget *widget,
6693 gboolean can_default)
6695 g_return_if_fail (GTK_IS_WIDGET (widget));
6697 if (widget->priv->can_default != can_default)
6699 widget->priv->can_default = can_default;
6701 gtk_widget_queue_resize (widget);
6702 g_object_notify (G_OBJECT (widget), "can-default");
6707 * gtk_widget_get_can_default:
6708 * @widget: a #GtkWidget
6710 * Determines whether @widget can be a default widget. See
6711 * gtk_widget_set_can_default().
6713 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6718 gtk_widget_get_can_default (GtkWidget *widget)
6720 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6722 return widget->priv->can_default;
6726 * gtk_widget_has_default:
6727 * @widget: a #GtkWidget
6729 * Determines whether @widget is the current default widget within its
6730 * toplevel. See gtk_widget_set_can_default().
6732 * Return value: %TRUE if @widget is the current default widget within
6733 * its toplevel, %FALSE otherwise
6738 gtk_widget_has_default (GtkWidget *widget)
6740 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6742 return widget->priv->has_default;
6746 _gtk_widget_set_has_default (GtkWidget *widget,
6747 gboolean has_default)
6749 widget->priv->has_default = has_default;
6753 * gtk_widget_grab_default:
6754 * @widget: a #GtkWidget
6756 * Causes @widget to become the default widget. @widget must have the
6757 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6758 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6759 * %TRUE)</literal>. The default widget is activated when
6760 * the user presses Enter in a window. Default widgets must be
6761 * activatable, that is, gtk_widget_activate() should affect them. Note
6762 * that #GtkEntry widgets require the "activates-default" property
6763 * set to %TRUE before they activate the default widget when Enter
6764 * is pressed and the #GtkEntry is focused.
6767 gtk_widget_grab_default (GtkWidget *widget)
6771 g_return_if_fail (GTK_IS_WIDGET (widget));
6772 g_return_if_fail (gtk_widget_get_can_default (widget));
6774 window = gtk_widget_get_toplevel (widget);
6776 if (window && gtk_widget_is_toplevel (window))
6777 gtk_window_set_default (GTK_WINDOW (window), widget);
6779 g_warning (G_STRLOC ": widget not within a GtkWindow");
6783 * gtk_widget_set_receives_default:
6784 * @widget: a #GtkWidget
6785 * @receives_default: whether or not @widget can be a default widget.
6787 * Specifies whether @widget will be treated as the default widget
6788 * within its toplevel when it has the focus, even if another widget
6791 * See gtk_widget_grab_default() for details about the meaning of
6797 gtk_widget_set_receives_default (GtkWidget *widget,
6798 gboolean receives_default)
6800 g_return_if_fail (GTK_IS_WIDGET (widget));
6802 if (widget->priv->receives_default != receives_default)
6804 widget->priv->receives_default = receives_default;
6806 g_object_notify (G_OBJECT (widget), "receives-default");
6811 * gtk_widget_get_receives_default:
6812 * @widget: a #GtkWidget
6814 * Determines whether @widget is alyways treated as default widget
6815 * withing its toplevel when it has the focus, even if another widget
6818 * See gtk_widget_set_receives_default().
6820 * Return value: %TRUE if @widget acts as default widget when focussed,
6826 gtk_widget_get_receives_default (GtkWidget *widget)
6828 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6830 return widget->priv->receives_default;
6834 * gtk_widget_has_grab:
6835 * @widget: a #GtkWidget
6837 * Determines whether the widget is currently grabbing events, so it
6838 * is the only widget receiving input events (keyboard and mouse).
6840 * See also gtk_grab_add().
6842 * Return value: %TRUE if the widget is in the grab_widgets stack
6847 gtk_widget_has_grab (GtkWidget *widget)
6849 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6851 return widget->priv->has_grab;
6855 _gtk_widget_set_has_grab (GtkWidget *widget,
6858 widget->priv->has_grab = has_grab;
6862 * gtk_widget_device_is_shadowed:
6863 * @widget: a #GtkWidget
6864 * @device: a #GdkDevice
6866 * Returns %TRUE if @device has been shadowed by a GTK+
6867 * device grab on another widget, so it would stop sending
6868 * events to @widget. This may be used in the
6869 * #GtkWidget::grab-notify signal to check for specific
6870 * devices. See gtk_device_grab_add().
6872 * Returns: %TRUE if there is an ongoing grab on @device
6873 * by another #GtkWidget than @widget.
6878 gtk_widget_device_is_shadowed (GtkWidget *widget,
6881 GtkWindowGroup *group;
6882 GtkWidget *grab_widget, *toplevel;
6884 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6885 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6887 if (!gtk_widget_get_realized (widget))
6890 toplevel = gtk_widget_get_toplevel (widget);
6892 if (GTK_IS_WINDOW (toplevel))
6893 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6895 group = gtk_window_get_group (NULL);
6897 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6899 /* Widget not inside the hierarchy of grab_widget */
6901 widget != grab_widget &&
6902 !gtk_widget_is_ancestor (widget, grab_widget))
6905 grab_widget = gtk_window_group_get_current_grab (group);
6906 if (grab_widget && widget != grab_widget &&
6907 !gtk_widget_is_ancestor (widget, grab_widget))
6914 * gtk_widget_set_name:
6915 * @widget: a #GtkWidget
6916 * @name: name for the widget
6918 * Widgets can be named, which allows you to refer to them from a
6919 * CSS file. You can apply a style to widgets with a particular name
6920 * in the CSS file. See the documentation for the CSS syntax (on the
6921 * same page as the docs for #GtkStyleContext).
6923 * Note that the CSS syntax has certain special characters to delimit
6924 * and represent elements in a selector (period, #, >, *...),
6925 * so using these will make your widget impossible to match by name.
6926 * Any combination of alphanumeric symbols, dashes and underscores will
6930 gtk_widget_set_name (GtkWidget *widget,
6933 GtkWidgetPrivate *priv;
6936 g_return_if_fail (GTK_IS_WIDGET (widget));
6938 priv = widget->priv;
6940 new_name = g_strdup (name);
6941 g_free (priv->name);
6942 priv->name = new_name;
6944 gtk_widget_reset_style (widget);
6946 g_object_notify (G_OBJECT (widget), "name");
6950 * gtk_widget_get_name:
6951 * @widget: a #GtkWidget
6953 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6954 * significance of widget names.
6956 * Return value: name of the widget. This string is owned by GTK+ and
6957 * should not be modified or freed
6959 G_CONST_RETURN gchar*
6960 gtk_widget_get_name (GtkWidget *widget)
6962 GtkWidgetPrivate *priv;
6964 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6966 priv = widget->priv;
6970 return G_OBJECT_TYPE_NAME (widget);
6974 _gtk_widget_update_state_flags (GtkWidget *widget,
6975 GtkStateFlags flags,
6978 GtkWidgetPrivate *priv;
6980 priv = widget->priv;
6982 /* Handle insensitive first, since it is propagated
6983 * differently throughout the widget hierarchy.
6985 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_UNSET))
6986 gtk_widget_set_sensitive (widget, TRUE);
6987 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation != STATE_CHANGE_UNSET))
6988 gtk_widget_set_sensitive (widget, FALSE);
6989 else if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && !(flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_REPLACE))
6990 gtk_widget_set_sensitive (widget, TRUE);
6992 if (operation != STATE_CHANGE_REPLACE)
6993 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
6996 operation == STATE_CHANGE_REPLACE)
7001 data.operation = operation;
7002 data.use_forall = FALSE;
7004 gtk_widget_propagate_state (widget, &data);
7006 gtk_widget_queue_resize (widget);
7011 * gtk_widget_set_state_flags:
7012 * @widget: a #GtkWidget
7013 * @flags: State flags to turn on
7014 * @clear: Whether to clear state before turning on @flags
7016 * This function is for use in widget implementations. Turns on flag
7017 * values in the current widget state (insensitive, prelighted, etc.).
7019 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7020 * will be propagated down to all non-internal children if @widget is a
7021 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7022 * down to all #GtkContainer children by different means than turning on the
7023 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7024 * gtk_widget_is_sensitive() will make use of these.
7029 gtk_widget_set_state_flags (GtkWidget *widget,
7030 GtkStateFlags flags,
7033 g_return_if_fail (GTK_IS_WIDGET (widget));
7035 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7036 (clear && widget->priv->state_flags == flags))
7040 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7042 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
7046 * gtk_widget_unset_state_flags:
7047 * @widget: a #GtkWidget
7048 * @flags: State flags to turn off
7050 * This function is for use in widget implementations. Turns off flag
7051 * values for the current widget state (insensitive, prelighted, etc.).
7052 * See gtk_widget_set_state_flags().
7057 gtk_widget_unset_state_flags (GtkWidget *widget,
7058 GtkStateFlags flags)
7060 g_return_if_fail (GTK_IS_WIDGET (widget));
7062 if ((widget->priv->state_flags & flags) == 0)
7065 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
7069 * gtk_widget_get_state_flags:
7070 * @widget: a #GtkWidget
7072 * Returns the widget state as a flag set. It is worth mentioning
7073 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7074 * returned, that is, also based on parent insensitivity, even if
7075 * @widget itself is sensitive.
7077 * Returns: The state flags for widget
7082 gtk_widget_get_state_flags (GtkWidget *widget)
7084 GtkStateFlags flags;
7086 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7088 flags = widget->priv->state_flags;
7090 if (gtk_widget_has_focus (widget))
7091 flags |= GTK_STATE_FLAG_FOCUSED;
7097 * gtk_widget_set_state:
7098 * @widget: a #GtkWidget
7099 * @state: new state for @widget
7101 * This function is for use in widget implementations. Sets the state
7102 * of a widget (insensitive, prelighted, etc.) Usually you should set
7103 * the state using wrapper functions such as gtk_widget_set_sensitive().
7105 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7108 gtk_widget_set_state (GtkWidget *widget,
7111 GtkStateFlags flags;
7113 if (state == gtk_widget_get_state (widget))
7118 case GTK_STATE_ACTIVE:
7119 flags = GTK_STATE_FLAG_ACTIVE;
7121 case GTK_STATE_PRELIGHT:
7122 flags = GTK_STATE_FLAG_PRELIGHT;
7124 case GTK_STATE_SELECTED:
7125 flags = GTK_STATE_FLAG_SELECTED;
7127 case GTK_STATE_INSENSITIVE:
7128 flags = GTK_STATE_FLAG_INSENSITIVE;
7130 case GTK_STATE_INCONSISTENT:
7131 flags = GTK_STATE_FLAG_INCONSISTENT;
7133 case GTK_STATE_FOCUSED:
7134 flags = GTK_STATE_FLAG_FOCUSED;
7136 case GTK_STATE_NORMAL:
7142 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7146 * gtk_widget_get_state:
7147 * @widget: a #GtkWidget
7149 * Returns the widget's state. See gtk_widget_set_state().
7151 * Returns: the state of @widget.
7155 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7158 gtk_widget_get_state (GtkWidget *widget)
7160 GtkStateFlags flags;
7162 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7164 flags = gtk_widget_get_state_flags (widget);
7166 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7167 return GTK_STATE_INSENSITIVE;
7168 else if (flags & GTK_STATE_FLAG_ACTIVE)
7169 return GTK_STATE_ACTIVE;
7170 else if (flags & GTK_STATE_FLAG_SELECTED)
7171 return GTK_STATE_SELECTED;
7172 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7173 return GTK_STATE_PRELIGHT;
7175 return GTK_STATE_NORMAL;
7179 * gtk_widget_set_visible:
7180 * @widget: a #GtkWidget
7181 * @visible: whether the widget should be shown or not
7183 * Sets the visibility state of @widget. Note that setting this to
7184 * %TRUE doesn't mean the widget is actually viewable, see
7185 * gtk_widget_get_visible().
7187 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7188 * but is nicer to use when the visibility of the widget depends on
7194 gtk_widget_set_visible (GtkWidget *widget,
7197 g_return_if_fail (GTK_IS_WIDGET (widget));
7199 if (visible != gtk_widget_get_visible (widget))
7202 gtk_widget_show (widget);
7204 gtk_widget_hide (widget);
7209 _gtk_widget_set_visible_flag (GtkWidget *widget,
7212 widget->priv->visible = visible;
7216 * gtk_widget_get_visible:
7217 * @widget: a #GtkWidget
7219 * Determines whether the widget is visible. Note that this doesn't
7220 * take into account whether the widget's parent is also visible
7221 * or the widget is obscured in any way.
7223 * See gtk_widget_set_visible().
7225 * Return value: %TRUE if the widget is visible
7230 gtk_widget_get_visible (GtkWidget *widget)
7232 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7234 return widget->priv->visible;
7238 * gtk_widget_set_has_window:
7239 * @widget: a #GtkWidget
7240 * @has_window: whether or not @widget has a window.
7242 * Specifies whether @widget has a #GdkWindow of its own. Note that
7243 * all realized widgets have a non-%NULL "window" pointer
7244 * (gtk_widget_get_window() never returns a %NULL window when a widget
7245 * is realized), but for many of them it's actually the #GdkWindow of
7246 * one of its parent widgets. Widgets that do not create a %window for
7247 * themselves in #GtkWidget::realize must announce this by
7248 * calling this function with @has_window = %FALSE.
7250 * This function should only be called by widget implementations,
7251 * and they should call it in their init() function.
7256 gtk_widget_set_has_window (GtkWidget *widget,
7257 gboolean has_window)
7259 g_return_if_fail (GTK_IS_WIDGET (widget));
7261 widget->priv->no_window = !has_window;
7265 * gtk_widget_get_has_window:
7266 * @widget: a #GtkWidget
7268 * Determines whether @widget has a #GdkWindow of its own. See
7269 * gtk_widget_set_has_window().
7271 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7276 gtk_widget_get_has_window (GtkWidget *widget)
7278 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7280 return ! widget->priv->no_window;
7284 * gtk_widget_is_toplevel:
7285 * @widget: a #GtkWidget
7287 * Determines whether @widget is a toplevel widget.
7289 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7290 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7293 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7298 gtk_widget_is_toplevel (GtkWidget *widget)
7300 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7302 return widget->priv->toplevel;
7306 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7307 gboolean is_toplevel)
7309 widget->priv->toplevel = is_toplevel;
7313 * gtk_widget_is_drawable:
7314 * @widget: a #GtkWidget
7316 * Determines whether @widget can be drawn to. A widget can be drawn
7317 * to if it is mapped and visible.
7319 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7324 gtk_widget_is_drawable (GtkWidget *widget)
7326 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7328 return (gtk_widget_get_visible (widget) &&
7329 gtk_widget_get_mapped (widget));
7333 * gtk_widget_get_realized:
7334 * @widget: a #GtkWidget
7336 * Determines whether @widget is realized.
7338 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7343 gtk_widget_get_realized (GtkWidget *widget)
7345 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7347 return widget->priv->realized;
7351 * gtk_widget_set_realized:
7352 * @widget: a #GtkWidget
7353 * @realized: %TRUE to mark the widget as realized
7355 * Marks the widget as being realized.
7357 * This function should only ever be called in a derived widget's
7358 * "realize" or "unrealize" implementation.
7363 gtk_widget_set_realized (GtkWidget *widget,
7366 g_return_if_fail (GTK_IS_WIDGET (widget));
7368 widget->priv->realized = realized;
7372 * gtk_widget_get_mapped:
7373 * @widget: a #GtkWidget
7375 * Whether the widget is mapped.
7377 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7382 gtk_widget_get_mapped (GtkWidget *widget)
7384 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7386 return widget->priv->mapped;
7390 * gtk_widget_set_mapped:
7391 * @widget: a #GtkWidget
7392 * @mapped: %TRUE to mark the widget as mapped
7394 * Marks the widget as being realized.
7396 * This function should only ever be called in a derived widget's
7397 * "map" or "unmap" implementation.
7402 gtk_widget_set_mapped (GtkWidget *widget,
7405 g_return_if_fail (GTK_IS_WIDGET (widget));
7407 widget->priv->mapped = mapped;
7411 * gtk_widget_set_app_paintable:
7412 * @widget: a #GtkWidget
7413 * @app_paintable: %TRUE if the application will paint on the widget
7415 * Sets whether the application intends to draw on the widget in
7416 * an #GtkWidget::draw handler.
7418 * This is a hint to the widget and does not affect the behavior of
7419 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7420 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7421 * the effect is to suppress default themed drawing of the widget's
7422 * background. (Children of the widget will still be drawn.) The application
7423 * is then entirely responsible for drawing the widget background.
7425 * Note that the background is still drawn when the widget is mapped.
7428 gtk_widget_set_app_paintable (GtkWidget *widget,
7429 gboolean app_paintable)
7431 g_return_if_fail (GTK_IS_WIDGET (widget));
7433 app_paintable = (app_paintable != FALSE);
7435 if (widget->priv->app_paintable != app_paintable)
7437 widget->priv->app_paintable = app_paintable;
7439 if (gtk_widget_is_drawable (widget))
7440 gtk_widget_queue_draw (widget);
7442 g_object_notify (G_OBJECT (widget), "app-paintable");
7447 * gtk_widget_get_app_paintable:
7448 * @widget: a #GtkWidget
7450 * Determines whether the application intends to draw on the widget in
7451 * an #GtkWidget::draw handler.
7453 * See gtk_widget_set_app_paintable()
7455 * Return value: %TRUE if the widget is app paintable
7460 gtk_widget_get_app_paintable (GtkWidget *widget)
7462 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7464 return widget->priv->app_paintable;
7468 * gtk_widget_set_double_buffered:
7469 * @widget: a #GtkWidget
7470 * @double_buffered: %TRUE to double-buffer a widget
7472 * Widgets are double buffered by default; you can use this function
7473 * to turn off the buffering. "Double buffered" simply means that
7474 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7475 * automatically around expose events sent to the
7476 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7477 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7478 * buffer to the screen. The result is that users see the window
7479 * update in one smooth step, and don't see individual graphics
7480 * primitives being rendered.
7482 * In very simple terms, double buffered widgets don't flicker,
7483 * so you would only use this function to turn off double buffering
7484 * if you had special needs and really knew what you were doing.
7486 * Note: if you turn off double-buffering, you have to handle
7487 * expose events, since even the clearing to the background color or
7488 * pixmap will not happen automatically (as it is done in
7489 * gdk_window_begin_paint()).
7492 gtk_widget_set_double_buffered (GtkWidget *widget,
7493 gboolean double_buffered)
7495 g_return_if_fail (GTK_IS_WIDGET (widget));
7497 double_buffered = (double_buffered != FALSE);
7499 if (widget->priv->double_buffered != double_buffered)
7501 widget->priv->double_buffered = double_buffered;
7503 g_object_notify (G_OBJECT (widget), "double-buffered");
7508 * gtk_widget_get_double_buffered:
7509 * @widget: a #GtkWidget
7511 * Determines whether the widget is double buffered.
7513 * See gtk_widget_set_double_buffered()
7515 * Return value: %TRUE if the widget is double buffered
7520 gtk_widget_get_double_buffered (GtkWidget *widget)
7522 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7524 return widget->priv->double_buffered;
7528 * gtk_widget_set_redraw_on_allocate:
7529 * @widget: a #GtkWidget
7530 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7531 * when it is allocated to a new size. Otherwise, only the
7532 * new portion of the widget will be redrawn.
7534 * Sets whether the entire widget is queued for drawing when its size
7535 * allocation changes. By default, this setting is %TRUE and
7536 * the entire widget is redrawn on every size change. If your widget
7537 * leaves the upper left unchanged when made bigger, turning this
7538 * setting off will improve performance.
7540 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7541 * off all allocation on resizing: the widget will not even redraw if
7542 * its position changes; this is to allow containers that don't draw
7543 * anything to avoid excess invalidations. If you set this flag on a
7544 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7545 * you are responsible for invalidating both the old and new allocation
7546 * of the widget when the widget is moved and responsible for invalidating
7547 * regions newly when the widget increases size.
7550 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7551 gboolean redraw_on_allocate)
7553 g_return_if_fail (GTK_IS_WIDGET (widget));
7555 widget->priv->redraw_on_alloc = redraw_on_allocate;
7559 * gtk_widget_set_sensitive:
7560 * @widget: a #GtkWidget
7561 * @sensitive: %TRUE to make the widget sensitive
7563 * Sets the sensitivity of a widget. A widget is sensitive if the user
7564 * can interact with it. Insensitive widgets are "grayed out" and the
7565 * user can't interact with them. Insensitive widgets are known as
7566 * "inactive", "disabled", or "ghosted" in some other toolkits.
7569 gtk_widget_set_sensitive (GtkWidget *widget,
7572 GtkWidgetPrivate *priv;
7575 g_return_if_fail (GTK_IS_WIDGET (widget));
7577 priv = widget->priv;
7579 sensitive = (sensitive != FALSE);
7581 if (widget->priv->sensitive == sensitive)
7584 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7588 widget->priv->sensitive = TRUE;
7589 data.operation = STATE_CHANGE_UNSET;
7593 widget->priv->sensitive = FALSE;
7594 data.operation = STATE_CHANGE_SET;
7597 data.use_forall = TRUE;
7599 gtk_widget_propagate_state (widget, &data);
7601 gtk_widget_queue_resize (widget);
7603 g_object_notify (G_OBJECT (widget), "sensitive");
7607 * gtk_widget_get_sensitive:
7608 * @widget: a #GtkWidget
7610 * Returns the widget's sensitivity (in the sense of returning
7611 * the value that has been set using gtk_widget_set_sensitive()).
7613 * The effective sensitivity of a widget is however determined by both its
7614 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7616 * Returns: %TRUE if the widget is sensitive
7621 gtk_widget_get_sensitive (GtkWidget *widget)
7623 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7625 return widget->priv->sensitive;
7629 * gtk_widget_is_sensitive:
7630 * @widget: a #GtkWidget
7632 * Returns the widget's effective sensitivity, which means
7633 * it is sensitive itself and also its parent widget is sensitive
7635 * Returns: %TRUE if the widget is effectively sensitive
7640 gtk_widget_is_sensitive (GtkWidget *widget)
7642 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7644 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
7648 _gtk_widget_update_path (GtkWidget *widget)
7650 if (widget->priv->path)
7652 gtk_widget_path_free (widget->priv->path);
7653 widget->priv->path = NULL;
7656 gtk_widget_get_path (widget);
7660 * gtk_widget_set_parent:
7661 * @widget: a #GtkWidget
7662 * @parent: parent container
7664 * This function is useful only when implementing subclasses of
7666 * Sets the container as the parent of @widget, and takes care of
7667 * some details such as updating the state and style of the child
7668 * to reflect its new location. The opposite function is
7669 * gtk_widget_unparent().
7672 gtk_widget_set_parent (GtkWidget *widget,
7675 GtkStateFlags parent_flags;
7676 GtkWidgetPrivate *priv;
7679 g_return_if_fail (GTK_IS_WIDGET (widget));
7680 g_return_if_fail (GTK_IS_WIDGET (parent));
7681 g_return_if_fail (widget != parent);
7683 priv = widget->priv;
7685 if (priv->parent != NULL)
7687 g_warning ("Can't set a parent on widget which has a parent\n");
7690 if (gtk_widget_is_toplevel (widget))
7692 g_warning ("Can't set a parent on a toplevel widget\n");
7696 /* keep this function in sync with gtk_menu_attach_to_widget()
7699 g_object_ref_sink (widget);
7701 gtk_widget_push_verify_invariants (widget);
7703 priv->parent = parent;
7705 parent_flags = gtk_widget_get_state_flags (parent);
7707 /* Merge both old state and current parent state,
7708 * making sure to only propagate the right states */
7709 data.flags = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
7710 data.flags |= priv->state_flags;
7712 data.operation = STATE_CHANGE_REPLACE;
7713 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7714 gtk_widget_propagate_state (widget, &data);
7716 gtk_widget_reset_style (widget);
7718 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7719 if (priv->parent->priv->anchored)
7720 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7721 g_object_notify (G_OBJECT (widget), "parent");
7723 /* Enforce realized/mapped invariants
7725 if (gtk_widget_get_realized (priv->parent))
7726 gtk_widget_realize (widget);
7728 if (gtk_widget_get_visible (priv->parent) &&
7729 gtk_widget_get_visible (widget))
7731 if (gtk_widget_get_child_visible (widget) &&
7732 gtk_widget_get_mapped (priv->parent))
7733 gtk_widget_map (widget);
7735 gtk_widget_queue_resize (widget);
7738 /* child may cause parent's expand to change, if the child is
7739 * expanded. If child is not expanded, then it can't modify the
7740 * parent's expand. If the child becomes expanded later then it will
7741 * queue compute_expand then. This optimization plus defaulting
7742 * newly-constructed widgets to need_compute_expand=FALSE should
7743 * mean that initially building a widget tree doesn't have to keep
7744 * walking up setting need_compute_expand on parents over and over.
7746 * We can't change a parent to need to expand unless we're visible.
7748 if (gtk_widget_get_visible (widget) &&
7749 (priv->need_compute_expand ||
7750 priv->computed_hexpand ||
7751 priv->computed_vexpand))
7753 gtk_widget_queue_compute_expand (parent);
7756 gtk_widget_pop_verify_invariants (widget);
7760 * gtk_widget_get_parent:
7761 * @widget: a #GtkWidget
7763 * Returns the parent container of @widget.
7765 * Return value: (transfer none): the parent container of @widget, or %NULL
7768 gtk_widget_get_parent (GtkWidget *widget)
7770 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7772 return widget->priv->parent;
7775 /*****************************************
7777 * see docs/styles.txt
7778 *****************************************/
7781 * gtk_widget_style_attach:
7782 * @widget: a #GtkWidget
7784 * This function attaches the widget's #GtkStyle to the widget's
7785 * #GdkWindow. It is a replacement for
7788 * widget->style = gtk_style_attach (widget->style, widget->window);
7791 * and should only ever be called in a derived widget's "realize"
7792 * implementation which does not chain up to its parent class'
7793 * "realize" implementation, because one of the parent classes
7794 * (finally #GtkWidget) would attach the style itself.
7798 * Deprecated: 3.0. This step is unnecessary with #GtkStyleContext.
7801 gtk_widget_style_attach (GtkWidget *widget)
7803 g_return_if_fail (GTK_IS_WIDGET (widget));
7804 g_return_if_fail (gtk_widget_get_realized (widget));
7808 * gtk_widget_has_rc_style:
7809 * @widget: a #GtkWidget
7811 * Determines if the widget style has been looked up through the rc mechanism.
7813 * Returns: %TRUE if the widget has been looked up through the rc
7814 * mechanism, %FALSE otherwise.
7818 * Deprecated:3.0: Use #GtkStyleContext instead
7821 gtk_widget_has_rc_style (GtkWidget *widget)
7823 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7825 return widget->priv->rc_style;
7829 * gtk_widget_set_style:
7830 * @widget: a #GtkWidget
7831 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect
7832 * of a previous call to gtk_widget_set_style() and go back to
7835 * Used to set the #GtkStyle for a widget (@widget->style). Since
7836 * GTK 3, this function does nothing, the passed in style is ignored.
7838 * Deprecated:3.0: Use #GtkStyleContext instead
7841 gtk_widget_set_style (GtkWidget *widget,
7844 g_return_if_fail (GTK_IS_WIDGET (widget));
7848 * gtk_widget_ensure_style:
7849 * @widget: a #GtkWidget
7851 * Ensures that @widget has a style (@widget->style).
7853 * Not a very useful function; most of the time, if you
7854 * want the style, the widget is realized, and realized
7855 * widgets are guaranteed to have a style already.
7857 * Deprecated:3.0: Use #GtkStyleContext instead
7860 gtk_widget_ensure_style (GtkWidget *widget)
7862 GtkWidgetPrivate *priv;
7864 g_return_if_fail (GTK_IS_WIDGET (widget));
7866 priv = widget->priv;
7868 if (priv->style == gtk_widget_get_default_style ())
7870 g_object_unref (priv->style);
7874 g_signal_emit (widget,
7875 widget_signals[STYLE_SET],
7881 * gtk_widget_get_style:
7882 * @widget: a #GtkWidget
7884 * Simply an accessor function that returns @widget->style.
7886 * Return value: (transfer none): the widget's #GtkStyle
7888 * Deprecated:3.0: Use #GtkStyleContext instead
7891 gtk_widget_get_style (GtkWidget *widget)
7893 GtkWidgetPrivate *priv;
7895 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7897 priv = widget->priv;
7899 if (priv->style == NULL)
7901 priv->style = g_object_new (GTK_TYPE_STYLE,
7902 "context", gtk_widget_get_style_context (widget),
7911 * gtk_widget_modify_style:
7912 * @widget: a #GtkWidget
7913 * @style: the #GtkRcStyle holding the style modifications
7915 * Modifies style values on the widget.
7917 * Modifications made using this technique take precedence over
7918 * style values set via an RC file, however, they will be overridden
7919 * if a style is explicitely set on the widget using gtk_widget_set_style().
7920 * The #GtkRcStyle structure is designed so each field can either be
7921 * set or unset, so it is possible, using this function, to modify some
7922 * style values and leave the others unchanged.
7924 * Note that modifications made with this function are not cumulative
7925 * with previous calls to gtk_widget_modify_style() or with such
7926 * functions as gtk_widget_modify_fg(). If you wish to retain
7927 * previous values, you must first call gtk_widget_get_modifier_style(),
7928 * make your modifications to the returned style, then call
7929 * gtk_widget_modify_style() with that style. On the other hand,
7930 * if you first call gtk_widget_modify_style(), subsequent calls
7931 * to such functions gtk_widget_modify_fg() will have a cumulative
7932 * effect with the initial modifications.
7934 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7937 gtk_widget_modify_style (GtkWidget *widget,
7940 g_return_if_fail (GTK_IS_WIDGET (widget));
7941 g_return_if_fail (GTK_IS_RC_STYLE (style));
7943 g_object_set_qdata_full (G_OBJECT (widget),
7945 gtk_rc_style_copy (style),
7946 (GDestroyNotify) g_object_unref);
7950 * gtk_widget_get_modifier_style:
7951 * @widget: a #GtkWidget
7953 * Returns the current modifier style for the widget. (As set by
7954 * gtk_widget_modify_style().) If no style has previously set, a new
7955 * #GtkRcStyle will be created with all values unset, and set as the
7956 * modifier style for the widget. If you make changes to this rc
7957 * style, you must call gtk_widget_modify_style(), passing in the
7958 * returned rc style, to make sure that your changes take effect.
7960 * Caution: passing the style back to gtk_widget_modify_style() will
7961 * normally end up destroying it, because gtk_widget_modify_style() copies
7962 * the passed-in style and sets the copy as the new modifier style,
7963 * thus dropping any reference to the old modifier style. Add a reference
7964 * to the modifier style if you want to keep it alive.
7966 * Return value: (transfer none): the modifier style for the widget.
7967 * This rc style is owned by the widget. If you want to keep a
7968 * pointer to value this around, you must add a refcount using
7971 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7974 gtk_widget_get_modifier_style (GtkWidget *widget)
7976 GtkRcStyle *rc_style;
7978 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7980 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7984 rc_style = gtk_rc_style_new ();
7985 g_object_set_qdata_full (G_OBJECT (widget),
7988 (GDestroyNotify) g_object_unref);
7995 gtk_widget_modify_color_component (GtkWidget *widget,
7996 GtkRcFlags component,
7998 const GdkColor *color)
8000 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
8007 rc_style->fg[state] = *color;
8010 rc_style->bg[state] = *color;
8013 rc_style->text[state] = *color;
8016 rc_style->base[state] = *color;
8019 g_assert_not_reached();
8022 rc_style->color_flags[state] |= component;
8025 rc_style->color_flags[state] &= ~component;
8027 gtk_widget_modify_style (widget, rc_style);
8031 modifier_style_changed (GtkModifierStyle *style,
8034 GtkStyleContext *context;
8036 context = gtk_widget_get_style_context (widget);
8037 gtk_style_context_invalidate (context);
8040 static GtkModifierStyle *
8041 _gtk_widget_get_modifier_properties (GtkWidget *widget)
8043 GtkModifierStyle *style;
8045 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
8047 if (G_UNLIKELY (!style))
8049 GtkStyleContext *context;
8051 style = _gtk_modifier_style_new ();
8052 g_object_set_qdata_full (G_OBJECT (widget),
8053 quark_modifier_style,
8055 (GDestroyNotify) g_object_unref);
8057 g_signal_connect (style, "changed",
8058 G_CALLBACK (modifier_style_changed), widget);
8060 context = gtk_widget_get_style_context (widget);
8062 gtk_style_context_add_provider (context,
8063 GTK_STYLE_PROVIDER (style),
8064 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
8071 * gtk_widget_override_color:
8072 * @widget: a #GtkWidget
8073 * @state: the state for which to set the color
8074 * @color: the color to assign, or %NULL to undo the effect
8075 * of previous calls to gtk_widget_override_color()
8077 * Sets the color to use for a widget.
8079 * All other style values are left untouched.
8082 * This API is mostly meant as a quick way for applications to
8083 * change a widget appearance. If you are developing a widgets
8084 * library and intend this change to be themeable, it is better
8085 * done by setting meaningful CSS classes and regions in your
8086 * widget/container implementation through gtk_style_context_add_class()
8087 * and gtk_style_context_add_region().
8089 * This way, your widget library can install a #GtkCssProvider
8090 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
8091 * to provide a default styling for those widgets that need so, and
8092 * this theming may fully overridden by the user's theme.
8095 * Note that for complex widgets this may bring in undesired
8096 * results (such as uniform background color everywhere), in
8097 * these cases it is better to fully style such widgets through a
8098 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8105 gtk_widget_override_color (GtkWidget *widget,
8106 GtkStateFlags state,
8107 const GdkRGBA *color)
8109 GtkModifierStyle *style;
8111 g_return_if_fail (GTK_IS_WIDGET (widget));
8113 style = _gtk_widget_get_modifier_properties (widget);
8114 _gtk_modifier_style_set_color (style, state, color);
8118 * gtk_widget_override_background_color:
8119 * @widget: a #GtkWidget
8120 * @state: the state for which to set the background color
8121 * @color: the color to assign, or %NULL to undo the effect
8122 * of previous calls to gtk_widget_override_background_color()
8124 * Sets the background color to use for a widget.
8126 * All other style values are left untouched.
8127 * See gtk_widget_override_color().
8132 gtk_widget_override_background_color (GtkWidget *widget,
8133 GtkStateFlags state,
8134 const GdkRGBA *color)
8136 GtkModifierStyle *style;
8138 g_return_if_fail (GTK_IS_WIDGET (widget));
8140 style = _gtk_widget_get_modifier_properties (widget);
8141 _gtk_modifier_style_set_background_color (style, state, color);
8145 * gtk_widget_override_font:
8146 * @widget: a #GtkWidget
8147 * @font_desc: the font descriptiong to use, or %NULL to undo
8148 * the effect of previous calls to gtk_widget_override_font()
8150 * Sets the font to use for a widget. All other style values are
8151 * left untouched. See gtk_widget_override_color().
8156 gtk_widget_override_font (GtkWidget *widget,
8157 const PangoFontDescription *font_desc)
8159 GtkModifierStyle *style;
8161 g_return_if_fail (GTK_IS_WIDGET (widget));
8163 style = _gtk_widget_get_modifier_properties (widget);
8164 _gtk_modifier_style_set_font (style, font_desc);
8168 * gtk_widget_override_symbolic_color:
8169 * @widget: a #GtkWidget
8170 * @name: the name of the symbolic color to modify
8171 * @color: (allow-none): the color to assign (does not need
8172 * to be allocated), or %NULL to undo the effect of previous
8173 * calls to gtk_widget_override_symbolic_color()
8175 * Sets a symbolic color for a widget.
8177 * All other style values are left untouched.
8178 * See gtk_widget_override_color() for overriding the foreground
8179 * or background color.
8184 gtk_widget_override_symbolic_color (GtkWidget *widget,
8186 const GdkRGBA *color)
8188 GtkModifierStyle *style;
8190 g_return_if_fail (GTK_IS_WIDGET (widget));
8192 style = _gtk_widget_get_modifier_properties (widget);
8193 _gtk_modifier_style_map_color (style, name, color);
8197 * gtk_widget_override_cursor:
8198 * @widget: a #GtkWidget
8199 * @cursor: the color to use for primary cursor (does not need to be
8200 * allocated), or %NULL to undo the effect of previous calls to
8201 * of gtk_widget_override_cursor().
8202 * @secondary_cursor: the color to use for secondary cursor (does not
8203 * need to be allocated), or %NULL to undo the effect of previous
8204 * calls to of gtk_widget_override_cursor().
8206 * Sets the cursor color to use in a widget, overriding the
8207 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8208 * style properties. All other style values are left untouched.
8209 * See also gtk_widget_modify_style().
8211 * Note that the underlying properties have the #GdkColor type,
8212 * so the alpha value in @primary and @secondary will be ignored.
8217 gtk_widget_override_cursor (GtkWidget *widget,
8218 const GdkRGBA *cursor,
8219 const GdkRGBA *secondary_cursor)
8221 GtkModifierStyle *style;
8223 g_return_if_fail (GTK_IS_WIDGET (widget));
8225 style = _gtk_widget_get_modifier_properties (widget);
8226 _gtk_modifier_style_set_color_property (style,
8228 "cursor-color", cursor);
8229 _gtk_modifier_style_set_color_property (style,
8231 "secondary-cursor-color",
8236 * gtk_widget_modify_fg:
8237 * @widget: a #GtkWidget
8238 * @state: the state for which to set the foreground color
8239 * @color: (allow-none): the color to assign (does not need to be allocated),
8240 * or %NULL to undo the effect of previous calls to
8241 * of gtk_widget_modify_fg().
8243 * Sets the foreground color for a widget in a particular state.
8245 * All other style values are left untouched.
8246 * See also gtk_widget_modify_style().
8248 * Deprecated:3.0: Use gtk_widget_override_color() instead
8251 gtk_widget_modify_fg (GtkWidget *widget,
8253 const GdkColor *color)
8255 GtkStateFlags flags;
8258 g_return_if_fail (GTK_IS_WIDGET (widget));
8259 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8263 case GTK_STATE_ACTIVE:
8264 flags = GTK_STATE_FLAG_ACTIVE;
8266 case GTK_STATE_PRELIGHT:
8267 flags = GTK_STATE_FLAG_PRELIGHT;
8269 case GTK_STATE_SELECTED:
8270 flags = GTK_STATE_FLAG_SELECTED;
8272 case GTK_STATE_INSENSITIVE:
8273 flags = GTK_STATE_FLAG_INSENSITIVE;
8275 case GTK_STATE_NORMAL:
8282 rgba.red = color->red / 65535.;
8283 rgba.green = color->green / 65535.;
8284 rgba.blue = color->blue / 65535.;
8287 gtk_widget_override_color (widget, flags, &rgba);
8290 gtk_widget_override_color (widget, flags, NULL);
8294 * gtk_widget_modify_bg:
8295 * @widget: a #GtkWidget
8296 * @state: the state for which to set the background color
8297 * @color: (allow-none): the color to assign (does not need
8298 * to be allocated), or %NULL to undo the effect of previous
8299 * calls to of gtk_widget_modify_bg().
8301 * Sets the background color for a widget in a particular state.
8303 * All other style values are left untouched.
8304 * See also gtk_widget_modify_style().
8307 * Note that "no window" widgets (which have the %GTK_NO_WINDOW
8308 * flag set) draw on their parent container's window and thus may
8309 * not draw any background themselves. This is the case for e.g.
8312 * To modify the background of such widgets, you have to set the
8313 * background color on their parent; if you want to set the background
8314 * of a rectangular area around a label, try placing the label in
8315 * a #GtkEventBox widget and setting the background color on that.
8318 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8321 gtk_widget_modify_bg (GtkWidget *widget,
8323 const GdkColor *color)
8325 GtkStateFlags flags;
8328 g_return_if_fail (GTK_IS_WIDGET (widget));
8329 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8333 case GTK_STATE_ACTIVE:
8334 flags = GTK_STATE_FLAG_ACTIVE;
8336 case GTK_STATE_PRELIGHT:
8337 flags = GTK_STATE_FLAG_PRELIGHT;
8339 case GTK_STATE_SELECTED:
8340 flags = GTK_STATE_FLAG_SELECTED;
8342 case GTK_STATE_INSENSITIVE:
8343 flags = GTK_STATE_FLAG_INSENSITIVE;
8345 case GTK_STATE_NORMAL:
8352 rgba.red = color->red / 65535.;
8353 rgba.green = color->green / 65535.;
8354 rgba.blue = color->blue / 65535.;
8357 gtk_widget_override_background_color (widget, flags, &rgba);
8360 gtk_widget_override_background_color (widget, flags, NULL);
8364 * gtk_widget_modify_text:
8365 * @widget: a #GtkWidget
8366 * @state: the state for which to set the text color
8367 * @color: (allow-none): the color to assign (does not need to
8368 * be allocated), or %NULL to undo the effect of previous
8369 * calls to of gtk_widget_modify_text().
8371 * Sets the text color for a widget in a particular state.
8373 * All other style values are left untouched.
8374 * The text color is the foreground color used along with the
8375 * base color (see gtk_widget_modify_base()) for widgets such
8376 * as #GtkEntry and #GtkTextView.
8377 * See also gtk_widget_modify_style().
8379 * Deprecated:3.0: Use gtk_widget_override_color() instead
8382 gtk_widget_modify_text (GtkWidget *widget,
8384 const GdkColor *color)
8386 g_return_if_fail (GTK_IS_WIDGET (widget));
8387 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8389 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
8393 * gtk_widget_modify_base:
8394 * @widget: a #GtkWidget
8395 * @state: the state for which to set the base color
8396 * @color: (allow-none): the color to assign (does not need to
8397 * be allocated), or %NULL to undo the effect of previous
8398 * calls to of gtk_widget_modify_base().
8400 * Sets the base color for a widget in a particular state.
8401 * All other style values are left untouched. The base color
8402 * is the background color used along with the text color
8403 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
8404 * and #GtkTextView. See also gtk_widget_modify_style().
8407 * Note that "no window" widgets (which have the %GTK_NO_WINDOW
8408 * flag set) draw on their parent container's window and thus may
8409 * not draw any background themselves. This is the case for e.g.
8412 * To modify the background of such widgets, you have to set the
8413 * base color on their parent; if you want to set the background
8414 * of a rectangular area around a label, try placing the label in
8415 * a #GtkEventBox widget and setting the base color on that.
8418 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8421 gtk_widget_modify_base (GtkWidget *widget,
8423 const GdkColor *color)
8425 g_return_if_fail (GTK_IS_WIDGET (widget));
8426 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8428 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
8432 * gtk_widget_modify_cursor:
8433 * @widget: a #GtkWidget
8434 * @primary: the color to use for primary cursor (does not need to be
8435 * allocated), or %NULL to undo the effect of previous calls to
8436 * of gtk_widget_modify_cursor().
8437 * @secondary: the color to use for secondary cursor (does not need to be
8438 * allocated), or %NULL to undo the effect of previous calls to
8439 * of gtk_widget_modify_cursor().
8441 * Sets the cursor color to use in a widget, overriding the
8442 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8445 * All other style values are left untouched.
8446 * See also gtk_widget_modify_style().
8450 * Deprecated: 3.0. Use gtk_widget_override_cursor() instead.
8453 gtk_widget_modify_cursor (GtkWidget *widget,
8454 const GdkColor *primary,
8455 const GdkColor *secondary)
8457 GdkRGBA primary_rgba, secondary_rgba;
8459 g_return_if_fail (GTK_IS_WIDGET (widget));
8461 primary_rgba.red = primary->red / 65535.;
8462 primary_rgba.green = primary->green / 65535.;
8463 primary_rgba.blue = primary->blue / 65535.;
8464 primary_rgba.alpha = 1;
8466 secondary_rgba.red = secondary->red / 65535.;
8467 secondary_rgba.green = secondary->green / 65535.;
8468 secondary_rgba.blue = secondary->blue / 65535.;
8469 secondary_rgba.alpha = 1;
8471 gtk_widget_override_cursor (widget, &primary_rgba, &secondary_rgba);
8475 * gtk_widget_modify_font:
8476 * @widget: a #GtkWidget
8477 * @font_desc: (allow-none): the font description to use, or %NULL
8478 * to undo the effect of previous calls to gtk_widget_modify_font()
8480 * Sets the font to use for a widget.
8482 * All other style values are left untouched.
8483 * See also gtk_widget_modify_style().
8485 * Deprecated:3.0: Use gtk_widget_override_font() instead
8488 gtk_widget_modify_font (GtkWidget *widget,
8489 PangoFontDescription *font_desc)
8491 g_return_if_fail (GTK_IS_WIDGET (widget));
8493 gtk_widget_override_font (widget, font_desc);
8497 gtk_widget_real_direction_changed (GtkWidget *widget,
8498 GtkTextDirection previous_direction)
8500 gtk_widget_queue_resize (widget);
8504 gtk_widget_real_style_set (GtkWidget *widget,
8505 GtkStyle *previous_style)
8510 GtkWidget *previous_toplevel;
8511 GdkScreen *previous_screen;
8512 GdkScreen *new_screen;
8513 } HierarchyChangedInfo;
8516 do_screen_change (GtkWidget *widget,
8517 GdkScreen *old_screen,
8518 GdkScreen *new_screen)
8520 if (old_screen != new_screen)
8522 GtkWidgetPrivate *priv = widget->priv;
8526 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8528 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8531 _gtk_tooltip_hide (widget);
8533 if (new_screen && priv->context)
8534 gtk_style_context_set_screen (priv->context, new_screen);
8536 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8541 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8542 gpointer client_data)
8544 GtkWidgetPrivate *priv = widget->priv;
8545 HierarchyChangedInfo *info = client_data;
8546 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8547 (priv->parent && priv->parent->priv->anchored);
8549 if (priv->anchored != new_anchored)
8551 g_object_ref (widget);
8553 priv->anchored = new_anchored;
8555 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8556 do_screen_change (widget, info->previous_screen, info->new_screen);
8558 if (GTK_IS_CONTAINER (widget))
8559 gtk_container_forall (GTK_CONTAINER (widget),
8560 gtk_widget_propagate_hierarchy_changed_recurse,
8563 g_object_unref (widget);
8568 * _gtk_widget_propagate_hierarchy_changed:
8569 * @widget: a #GtkWidget
8570 * @previous_toplevel: Previous toplevel
8572 * Propagates changes in the anchored state to a widget and all
8573 * children, unsetting or setting the %ANCHORED flag, and
8574 * emitting #GtkWidget::hierarchy-changed.
8577 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8578 GtkWidget *previous_toplevel)
8580 GtkWidgetPrivate *priv = widget->priv;
8581 HierarchyChangedInfo info;
8583 info.previous_toplevel = previous_toplevel;
8584 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8586 if (gtk_widget_is_toplevel (widget) ||
8587 (priv->parent && priv->parent->priv->anchored))
8588 info.new_screen = gtk_widget_get_screen (widget);
8590 info.new_screen = NULL;
8592 if (info.previous_screen)
8593 g_object_ref (info.previous_screen);
8594 if (previous_toplevel)
8595 g_object_ref (previous_toplevel);
8597 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8599 if (previous_toplevel)
8600 g_object_unref (previous_toplevel);
8601 if (info.previous_screen)
8602 g_object_unref (info.previous_screen);
8606 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8607 gpointer client_data)
8609 HierarchyChangedInfo *info = client_data;
8611 g_object_ref (widget);
8613 do_screen_change (widget, info->previous_screen, info->new_screen);
8615 if (GTK_IS_CONTAINER (widget))
8616 gtk_container_forall (GTK_CONTAINER (widget),
8617 gtk_widget_propagate_screen_changed_recurse,
8620 g_object_unref (widget);
8624 * gtk_widget_is_composited:
8625 * @widget: a #GtkWidget
8627 * Whether @widget can rely on having its alpha channel
8628 * drawn correctly. On X11 this function returns whether a
8629 * compositing manager is running for @widget's screen.
8631 * Please note that the semantics of this call will change
8632 * in the future if used on a widget that has a composited
8633 * window in its hierarchy (as set by gdk_window_set_composited()).
8635 * Return value: %TRUE if the widget can rely on its alpha
8636 * channel being drawn correctly.
8641 gtk_widget_is_composited (GtkWidget *widget)
8645 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8647 screen = gtk_widget_get_screen (widget);
8649 return gdk_screen_is_composited (screen);
8653 propagate_composited_changed (GtkWidget *widget,
8656 if (GTK_IS_CONTAINER (widget))
8658 gtk_container_forall (GTK_CONTAINER (widget),
8659 propagate_composited_changed,
8663 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8667 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8669 propagate_composited_changed (widget, NULL);
8673 * _gtk_widget_propagate_screen_changed:
8674 * @widget: a #GtkWidget
8675 * @previous_screen: Previous screen
8677 * Propagates changes in the screen for a widget to all
8678 * children, emitting #GtkWidget::screen-changed.
8681 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8682 GdkScreen *previous_screen)
8684 HierarchyChangedInfo info;
8686 info.previous_screen = previous_screen;
8687 info.new_screen = gtk_widget_get_screen (widget);
8689 if (previous_screen)
8690 g_object_ref (previous_screen);
8692 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8694 if (previous_screen)
8695 g_object_unref (previous_screen);
8699 reset_style_recurse (GtkWidget *widget, gpointer data)
8701 _gtk_widget_update_path (widget);
8703 if (GTK_IS_CONTAINER (widget))
8704 gtk_container_forall (GTK_CONTAINER (widget),
8705 reset_style_recurse,
8710 * gtk_widget_reset_style:
8711 * @widget: a #GtkWidget
8713 * Updates the style context of @widget and all descendents
8714 * by updating its widget path. #GtkContainer<!-- -->s may want
8715 * to use this on a child when reordering it in a way that a different
8716 * style might apply to it. See also gtk_container_get_path_for_child().
8721 gtk_widget_reset_style (GtkWidget *widget)
8723 g_return_if_fail (GTK_IS_WIDGET (widget));
8725 reset_style_recurse (widget, NULL);
8729 * gtk_widget_reset_rc_styles:
8730 * @widget: a #GtkWidget.
8732 * Reset the styles of @widget and all descendents, so when
8733 * they are looked up again, they get the correct values
8734 * for the currently loaded RC file settings.
8736 * This function is not useful for applications.
8738 * Deprecated:3.0: Use #GtkStyleContext instead, and gtk_widget_reset_style()
8741 gtk_widget_reset_rc_styles (GtkWidget *widget)
8743 g_return_if_fail (GTK_IS_WIDGET (widget));
8745 reset_style_recurse (widget, NULL);
8749 * gtk_widget_get_default_style:
8751 * Returns the default style used by all widgets initially.
8753 * Returns: (transfer none): the default style. This #GtkStyle
8754 * object is owned by GTK+ and should not be modified or freed.
8756 * Deprecated:3.0: Use #GtkStyleContext instead, and
8757 * gtk_css_provider_get_default() to obtain a #GtkStyleProvider
8758 * with the default widget style information.
8761 gtk_widget_get_default_style (void)
8763 if (!gtk_default_style)
8765 gtk_default_style = gtk_style_new ();
8766 g_object_ref (gtk_default_style);
8769 return gtk_default_style;
8772 #ifdef G_ENABLE_DEBUG
8774 /* Verify invariants, see docs/widget_system.txt for notes on much of
8775 * this. Invariants may be temporarily broken while we're in the
8776 * process of updating state, of course, so you can only
8777 * verify_invariants() after a given operation is complete.
8778 * Use push/pop_verify_invariants to help with that.
8781 gtk_widget_verify_invariants (GtkWidget *widget)
8785 if (widget->priv->verifying_invariants_count > 0)
8788 parent = widget->priv->parent;
8790 if (widget->priv->mapped)
8792 /* Mapped implies ... */
8794 if (!widget->priv->realized)
8795 g_warning ("%s %p is mapped but not realized",
8796 G_OBJECT_TYPE_NAME (widget), widget);
8798 if (!widget->priv->visible)
8799 g_warning ("%s %p is mapped but not visible",
8800 G_OBJECT_TYPE_NAME (widget), widget);
8802 if (!widget->priv->toplevel)
8804 if (!widget->priv->child_visible)
8805 g_warning ("%s %p is mapped but not child_visible",
8806 G_OBJECT_TYPE_NAME (widget), widget);
8811 /* Not mapped implies... */
8814 /* This check makes sense for normal toplevels, but for
8815 * something like a toplevel that is embedded within a clutter
8816 * state, mapping may depend on external factors.
8818 if (widget->priv->toplevel)
8820 if (widget->priv->visible)
8821 g_warning ("%s %p toplevel is visible but not mapped",
8822 G_OBJECT_TYPE_NAME (widget), widget);
8827 /* Parent related checks aren't possible if parent has
8828 * verifying_invariants_count > 0 because parent needs to recurse
8829 * children first before the invariants will hold.
8831 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8834 parent->priv->realized)
8836 /* Parent realized implies... */
8839 /* This is in widget_system.txt but appears to fail
8840 * because there's no gtk_container_realize() that
8841 * realizes all children... instead we just lazily
8842 * wait for map to fix things up.
8844 if (!widget->priv->realized)
8845 g_warning ("%s %p is realized but child %s %p is not realized",
8846 G_OBJECT_TYPE_NAME (parent), parent,
8847 G_OBJECT_TYPE_NAME (widget), widget);
8850 else if (!widget->priv->toplevel)
8852 /* No parent or parent not realized on non-toplevel implies... */
8854 if (widget->priv->realized && !widget->priv->in_reparent)
8855 g_warning ("%s %p is not realized but child %s %p is realized",
8856 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8857 G_OBJECT_TYPE_NAME (widget), widget);
8861 parent->priv->mapped &&
8862 widget->priv->visible &&
8863 widget->priv->child_visible)
8865 /* Parent mapped and we are visible implies... */
8867 if (!widget->priv->mapped)
8868 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8869 G_OBJECT_TYPE_NAME (parent), parent,
8870 G_OBJECT_TYPE_NAME (widget), widget);
8872 else if (!widget->priv->toplevel)
8874 /* No parent or parent not mapped on non-toplevel implies... */
8876 if (widget->priv->mapped && !widget->priv->in_reparent)
8877 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8878 G_OBJECT_TYPE_NAME (widget), widget,
8879 widget->priv->visible,
8880 widget->priv->child_visible,
8881 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8882 parent ? parent->priv->mapped : FALSE);
8886 if (!widget->priv->realized)
8888 /* Not realized implies... */
8891 /* widget_system.txt says these hold, but they don't. */
8892 if (widget->priv->resize_pending)
8893 g_warning ("%s %p resize pending but not realized",
8894 G_OBJECT_TYPE_NAME (widget), widget);
8896 if (widget->priv->alloc_needed)
8897 g_warning ("%s %p alloc needed but not realized",
8898 G_OBJECT_TYPE_NAME (widget), widget);
8900 if (widget->priv->width_request_needed)
8901 g_warning ("%s %p width request needed but not realized",
8902 G_OBJECT_TYPE_NAME (widget), widget);
8904 if (widget->priv->height_request_needed)
8905 g_warning ("%s %p height request needed but not realized",
8906 G_OBJECT_TYPE_NAME (widget), widget);
8911 /* The point of this push/pop is that invariants may not hold while
8912 * we're busy making changes. So we only check at the outermost call
8913 * on the call stack, after we finish updating everything.
8916 gtk_widget_push_verify_invariants (GtkWidget *widget)
8918 widget->priv->verifying_invariants_count += 1;
8922 gtk_widget_verify_child_invariants (GtkWidget *widget,
8923 gpointer client_data)
8925 /* We don't recurse further; this is a one-level check. */
8926 gtk_widget_verify_invariants (widget);
8930 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8932 g_assert (widget->priv->verifying_invariants_count > 0);
8934 widget->priv->verifying_invariants_count -= 1;
8936 if (widget->priv->verifying_invariants_count == 0)
8938 gtk_widget_verify_invariants (widget);
8940 if (GTK_IS_CONTAINER (widget))
8942 /* Check one level of children, because our
8943 * push_verify_invariants() will have prevented some of the
8944 * checks. This does not recurse because if recursion is
8945 * needed, it will happen naturally as each child has a
8946 * push/pop on that child. For example if we're recursively
8947 * mapping children, we'll push/pop on each child as we map
8950 gtk_container_forall (GTK_CONTAINER (widget),
8951 gtk_widget_verify_child_invariants,
8956 #endif /* G_ENABLE_DEBUG */
8958 static PangoContext *
8959 gtk_widget_peek_pango_context (GtkWidget *widget)
8961 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8965 * gtk_widget_get_pango_context:
8966 * @widget: a #GtkWidget
8968 * Gets a #PangoContext with the appropriate font map, font description,
8969 * and base direction for this widget. Unlike the context returned
8970 * by gtk_widget_create_pango_context(), this context is owned by
8971 * the widget (it can be used until the screen for the widget changes
8972 * or the widget is removed from its toplevel), and will be updated to
8973 * match any changes to the widget's attributes.
8975 * If you create and keep a #PangoLayout using this context, you must
8976 * deal with changes to the context by calling pango_layout_context_changed()
8977 * on the layout in response to the #GtkWidget::style-updated and
8978 * #GtkWidget::direction-changed signals for the widget.
8980 * Return value: (transfer none): the #PangoContext for the widget.
8983 gtk_widget_get_pango_context (GtkWidget *widget)
8985 PangoContext *context;
8987 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8989 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8992 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8993 g_object_set_qdata_full (G_OBJECT (widget),
8994 quark_pango_context,
9003 update_pango_context (GtkWidget *widget,
9004 PangoContext *context)
9006 PangoFontDescription *font_desc;
9007 GtkStyleContext *style_context;
9009 style_context = gtk_widget_get_style_context (widget);
9011 gtk_style_context_get (style_context,
9012 gtk_widget_get_state_flags (widget),
9016 pango_context_set_font_description (context, font_desc);
9017 pango_context_set_base_dir (context,
9018 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
9019 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
9021 pango_font_description_free (font_desc);
9025 gtk_widget_update_pango_context (GtkWidget *widget)
9027 PangoContext *context = gtk_widget_peek_pango_context (widget);
9033 update_pango_context (widget, context);
9035 screen = gtk_widget_get_screen_unchecked (widget);
9038 pango_cairo_context_set_resolution (context,
9039 gdk_screen_get_resolution (screen));
9040 pango_cairo_context_set_font_options (context,
9041 gdk_screen_get_font_options (screen));
9047 * gtk_widget_create_pango_context:
9048 * @widget: a #GtkWidget
9050 * Creates a new #PangoContext with the appropriate font map,
9051 * font description, and base direction for drawing text for
9052 * this widget. See also gtk_widget_get_pango_context().
9054 * Return value: (transfer full): the new #PangoContext
9057 gtk_widget_create_pango_context (GtkWidget *widget)
9060 PangoContext *context;
9062 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9064 screen = gtk_widget_get_screen_unchecked (widget);
9067 GTK_NOTE (MULTIHEAD,
9068 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
9070 screen = gdk_screen_get_default ();
9073 context = gdk_pango_context_get_for_screen (screen);
9075 update_pango_context (widget, context);
9076 pango_context_set_language (context, gtk_get_default_language ());
9082 * gtk_widget_create_pango_layout:
9083 * @widget: a #GtkWidget
9084 * @text: text to set on the layout (can be %NULL)
9086 * Creates a new #PangoLayout with the appropriate font map,
9087 * font description, and base direction for drawing text for
9090 * If you keep a #PangoLayout created in this way around, in order to
9091 * notify the layout of changes to the base direction or font of this
9092 * widget, you must call pango_layout_context_changed() in response to
9093 * the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
9096 * Return value: (transfer full): the new #PangoLayout
9099 gtk_widget_create_pango_layout (GtkWidget *widget,
9102 PangoLayout *layout;
9103 PangoContext *context;
9105 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9107 context = gtk_widget_get_pango_context (widget);
9108 layout = pango_layout_new (context);
9111 pango_layout_set_text (layout, text, -1);
9117 * gtk_widget_render_icon_pixbuf:
9118 * @widget: a #GtkWidget
9119 * @stock_id: a stock ID
9120 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
9121 * render at the size of the source and don't scale (if there are
9122 * multiple source sizes, GTK+ picks one of the available sizes).
9124 * A convenience function that uses the theme engine and style
9125 * settings for @widget to look up @stock_id and render it to
9126 * a pixbuf. @stock_id should be a stock icon ID such as
9127 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
9128 * such as #GTK_ICON_SIZE_MENU.
9130 * The pixels in the returned #GdkPixbuf are shared with the rest of
9131 * the application and should not be modified. The pixbuf should be freed
9132 * after use with g_object_unref().
9134 * Return value: (transfer full): a new pixbuf, or %NULL if the
9135 * stock ID wasn't known
9140 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
9141 const gchar *stock_id,
9144 GtkStyleContext *context;
9145 GtkIconSet *icon_set;
9147 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9148 g_return_val_if_fail (stock_id != NULL, NULL);
9149 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
9151 context = gtk_widget_get_style_context (widget);
9152 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
9154 if (icon_set == NULL)
9157 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
9161 * gtk_widget_render_icon:
9162 * @widget: a #GtkWidget
9163 * @stock_id: a stock ID
9164 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
9165 * render at the size of the source and don't scale (if there are
9166 * multiple source sizes, GTK+ picks one of the available sizes).
9167 * @detail: (allow-none): render detail to pass to theme engine
9169 * A convenience function that uses the theme settings for @widget
9170 * to look up @stock_id and render it to a pixbuf. @stock_id should
9171 * be a stock icon ID such as #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size
9172 * should be a size such as #GTK_ICON_SIZE_MENU. @detail should be a
9173 * string that identifies the widget or code doing the rendering, so
9174 * that theme engines can special-case rendering for that widget or
9177 * The pixels in the returned #GdkPixbuf are shared with the rest of
9178 * the application and should not be modified. The pixbuf should be
9179 * freed after use with g_object_unref().
9181 * Return value: (transfer full): a new pixbuf, or %NULL if the
9182 * stock ID wasn't known
9184 * Deprecated: 3.0: Use gtk_widget_render_icon_pixbuf() instead.
9187 gtk_widget_render_icon (GtkWidget *widget,
9188 const gchar *stock_id,
9190 const gchar *detail)
9192 gtk_widget_ensure_style (widget);
9194 return gtk_widget_render_icon_pixbuf (widget, stock_id, size);
9198 * gtk_widget_set_parent_window:
9199 * @widget: a #GtkWidget.
9200 * @parent_window: the new parent window.
9202 * Sets a non default parent window for @widget.
9204 * For GtkWindow classes, setting a @parent_window effects whether
9205 * the window is a toplevel window or can be embedded into other
9209 * For GtkWindow classes, this needs to be called before the
9210 * window is realized.
9215 gtk_widget_set_parent_window (GtkWidget *widget,
9216 GdkWindow *parent_window)
9218 GdkWindow *old_parent_window;
9220 g_return_if_fail (GTK_IS_WIDGET (widget));
9222 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
9223 quark_parent_window);
9225 if (parent_window != old_parent_window)
9229 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
9231 if (old_parent_window)
9232 g_object_unref (old_parent_window);
9234 g_object_ref (parent_window);
9236 /* Unset toplevel flag when adding a parent window to a widget,
9237 * this is the primary entry point to allow toplevels to be
9240 #ifdef GDK_WINDOWING_X11
9241 is_plug = GTK_IS_PLUG (widget);
9245 if (GTK_IS_WINDOW (widget) && !is_plug)
9246 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
9251 * gtk_widget_get_parent_window:
9252 * @widget: a #GtkWidget.
9254 * Gets @widget's parent window.
9256 * Returns: (transfer none): the parent window of @widget.
9259 gtk_widget_get_parent_window (GtkWidget *widget)
9261 GtkWidgetPrivate *priv;
9262 GdkWindow *parent_window;
9264 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9266 priv = widget->priv;
9268 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
9270 return (parent_window != NULL) ? parent_window :
9271 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
9276 * gtk_widget_set_child_visible:
9277 * @widget: a #GtkWidget
9278 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
9280 * Sets whether @widget should be mapped along with its when its parent
9281 * is mapped and @widget has been shown with gtk_widget_show().
9283 * The child visibility can be set for widget before it is added to
9284 * a container with gtk_widget_set_parent(), to avoid mapping
9285 * children unnecessary before immediately unmapping them. However
9286 * it will be reset to its default state of %TRUE when the widget
9287 * is removed from a container.
9289 * Note that changing the child visibility of a widget does not
9290 * queue a resize on the widget. Most of the time, the size of
9291 * a widget is computed from all visible children, whether or
9292 * not they are mapped. If this is not the case, the container
9293 * can queue a resize itself.
9295 * This function is only useful for container implementations and
9296 * never should be called by an application.
9299 gtk_widget_set_child_visible (GtkWidget *widget,
9300 gboolean is_visible)
9302 GtkWidgetPrivate *priv;
9304 g_return_if_fail (GTK_IS_WIDGET (widget));
9305 g_return_if_fail (!gtk_widget_is_toplevel (widget));
9307 priv = widget->priv;
9309 g_object_ref (widget);
9310 gtk_widget_verify_invariants (widget);
9313 priv->child_visible = TRUE;
9316 GtkWidget *toplevel;
9318 priv->child_visible = FALSE;
9320 toplevel = gtk_widget_get_toplevel (widget);
9321 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
9322 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
9325 if (priv->parent && gtk_widget_get_realized (priv->parent))
9327 if (gtk_widget_get_mapped (priv->parent) &&
9328 priv->child_visible &&
9329 gtk_widget_get_visible (widget))
9330 gtk_widget_map (widget);
9332 gtk_widget_unmap (widget);
9335 gtk_widget_verify_invariants (widget);
9336 g_object_unref (widget);
9340 * gtk_widget_get_child_visible:
9341 * @widget: a #GtkWidget
9343 * Gets the value set with gtk_widget_set_child_visible().
9344 * If you feel a need to use this function, your code probably
9345 * needs reorganization.
9347 * This function is only useful for container implementations and
9348 * never should be called by an application.
9350 * Return value: %TRUE if the widget is mapped with the parent.
9353 gtk_widget_get_child_visible (GtkWidget *widget)
9355 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9357 return widget->priv->child_visible;
9361 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9363 GtkWidget *toplevel;
9365 toplevel = gtk_widget_get_toplevel (widget);
9367 if (gtk_widget_is_toplevel (toplevel))
9369 if (GTK_IS_WINDOW (toplevel))
9370 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9371 else if (GTK_IS_INVISIBLE (toplevel))
9372 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9379 * gtk_widget_get_screen:
9380 * @widget: a #GtkWidget
9382 * Get the #GdkScreen from the toplevel window associated with
9383 * this widget. This function can only be called after the widget
9384 * has been added to a widget hierarchy with a #GtkWindow
9387 * In general, you should only create screen specific
9388 * resources when a widget has been realized, and you should
9389 * free those resources when the widget is unrealized.
9391 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9396 gtk_widget_get_screen (GtkWidget *widget)
9400 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9402 screen = gtk_widget_get_screen_unchecked (widget);
9409 g_warning (G_STRLOC ": Can't get associated screen"
9410 " for a widget unless it is inside a toplevel GtkWindow\n"
9411 " widget type is %s associated top level type is %s",
9412 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9413 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9415 return gdk_screen_get_default ();
9420 * gtk_widget_has_screen:
9421 * @widget: a #GtkWidget
9423 * Checks whether there is a #GdkScreen is associated with
9424 * this widget. All toplevel widgets have an associated
9425 * screen, and all widgets added into a hierarchy with a toplevel
9426 * window at the top.
9428 * Return value: %TRUE if there is a #GdkScreen associcated
9434 gtk_widget_has_screen (GtkWidget *widget)
9436 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9438 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9442 * gtk_widget_get_display:
9443 * @widget: a #GtkWidget
9445 * Get the #GdkDisplay for the toplevel window associated with
9446 * this widget. This function can only be called after the widget
9447 * has been added to a widget hierarchy with a #GtkWindow at the top.
9449 * In general, you should only create display specific
9450 * resources when a widget has been realized, and you should
9451 * free those resources when the widget is unrealized.
9453 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9458 gtk_widget_get_display (GtkWidget *widget)
9460 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9462 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9466 * gtk_widget_get_root_window:
9467 * @widget: a #GtkWidget
9469 * Get the root window where this widget is located. This function can
9470 * only be called after the widget has been added to a widget
9471 * hierarchy with #GtkWindow at the top.
9473 * The root window is useful for such purposes as creating a popup
9474 * #GdkWindow associated with the window. In general, you should only
9475 * create display specific resources when a widget has been realized,
9476 * and you should free those resources when the widget is unrealized.
9478 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9483 gtk_widget_get_root_window (GtkWidget *widget)
9485 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9487 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9491 * gtk_widget_child_focus:
9492 * @widget: a #GtkWidget
9493 * @direction: direction of focus movement
9495 * This function is used by custom widget implementations; if you're
9496 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9497 * to a particular widget, and gtk_container_set_focus_chain() to
9498 * change the focus tab order. So you may want to investigate those
9499 * functions instead.
9501 * gtk_widget_child_focus() is called by containers as the user moves
9502 * around the window using keyboard shortcuts. @direction indicates
9503 * what kind of motion is taking place (up, down, left, right, tab
9504 * forward, tab backward). gtk_widget_child_focus() emits the
9505 * #GtkWidget::focus signal; widgets override the default handler
9506 * for this signal in order to implement appropriate focus behavior.
9508 * The default ::focus handler for a widget should return %TRUE if
9509 * moving in @direction left the focus on a focusable location inside
9510 * that widget, and %FALSE if moving in @direction moved the focus
9511 * outside the widget. If returning %TRUE, widgets normally
9512 * call gtk_widget_grab_focus() to place the focus accordingly;
9513 * if returning %FALSE, they don't modify the current focus location.
9515 * Return value: %TRUE if focus ended up inside @widget
9518 gtk_widget_child_focus (GtkWidget *widget,
9519 GtkDirectionType direction)
9521 gboolean return_val;
9523 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9525 if (!gtk_widget_get_visible (widget) ||
9526 !gtk_widget_is_sensitive (widget))
9529 /* child widgets must set CAN_FOCUS, containers
9530 * don't have to though.
9532 if (!GTK_IS_CONTAINER (widget) &&
9533 !gtk_widget_get_can_focus (widget))
9536 g_signal_emit (widget,
9537 widget_signals[FOCUS],
9539 direction, &return_val);
9545 * gtk_widget_keynav_failed:
9546 * @widget: a #GtkWidget
9547 * @direction: direction of focus movement
9549 * This function should be called whenever keyboard navigation within
9550 * a single widget hits a boundary. The function emits the
9551 * #GtkWidget::keynav-failed signal on the widget and its return
9552 * value should be interpreted in a way similar to the return value of
9553 * gtk_widget_child_focus():
9555 * When %TRUE is returned, stay in the widget, the failed keyboard
9556 * navigation is Ok and/or there is nowhere we can/should move the
9559 * When %FALSE is returned, the caller should continue with keyboard
9560 * navigation outside the widget, e.g. by calling
9561 * gtk_widget_child_focus() on the widget's toplevel.
9563 * The default ::keynav-failed handler returns %TRUE for
9564 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9565 * values of #GtkDirectionType, it looks at the
9566 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9567 * if the setting is %TRUE. This way the entire user interface
9568 * becomes cursor-navigatable on input devices such as mobile phones
9569 * which only have cursor keys but no tab key.
9571 * Whenever the default handler returns %TRUE, it also calls
9572 * gtk_widget_error_bell() to notify the user of the failed keyboard
9575 * A use case for providing an own implementation of ::keynav-failed
9576 * (either by connecting to it or by overriding it) would be a row of
9577 * #GtkEntry widgets where the user should be able to navigate the
9578 * entire row with the cursor keys, as e.g. known from user interfaces
9579 * that require entering license keys.
9581 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9582 * if the emitting widget should try to handle the keyboard
9583 * navigation attempt in its parent container(s).
9588 gtk_widget_keynav_failed (GtkWidget *widget,
9589 GtkDirectionType direction)
9591 gboolean return_val;
9593 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9595 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9596 direction, &return_val);
9602 * gtk_widget_error_bell:
9603 * @widget: a #GtkWidget
9605 * Notifies the user about an input-related error on this widget.
9606 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9607 * gdk_window_beep(), otherwise it does nothing.
9609 * Note that the effect of gdk_window_beep() can be configured in many
9610 * ways, depending on the windowing backend and the desktop environment
9611 * or window manager that is used.
9616 gtk_widget_error_bell (GtkWidget *widget)
9618 GtkWidgetPrivate *priv;
9619 GtkSettings* settings;
9622 g_return_if_fail (GTK_IS_WIDGET (widget));
9624 priv = widget->priv;
9626 settings = gtk_widget_get_settings (widget);
9630 g_object_get (settings,
9631 "gtk-error-bell", &beep,
9634 if (beep && priv->window)
9635 gdk_window_beep (priv->window);
9639 gtk_widget_set_usize_internal (GtkWidget *widget,
9642 GtkQueueResizeFlags flags)
9644 GtkWidgetAuxInfo *aux_info;
9645 gboolean changed = FALSE;
9647 g_object_freeze_notify (G_OBJECT (widget));
9649 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
9651 if (width > -2 && aux_info->width != width)
9653 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9654 g_object_notify (G_OBJECT (widget), "width-request");
9655 aux_info->width = width;
9658 if (height > -2 && aux_info->height != height)
9660 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9661 g_object_notify (G_OBJECT (widget), "height-request");
9662 aux_info->height = height;
9666 if (gtk_widget_get_visible (widget) && changed)
9668 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9669 gtk_widget_queue_resize (widget);
9671 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9674 g_object_thaw_notify (G_OBJECT (widget));
9678 * gtk_widget_set_size_request:
9679 * @widget: a #GtkWidget
9680 * @width: width @widget should request, or -1 to unset
9681 * @height: height @widget should request, or -1 to unset
9683 * Sets the minimum size of a widget; that is, the widget's size
9684 * request will be @width by @height. You can use this function to
9685 * force a widget to be either larger or smaller than it normally
9688 * In most cases, gtk_window_set_default_size() is a better choice for
9689 * toplevel windows than this function; setting the default size will
9690 * still allow users to shrink the window. Setting the size request
9691 * will force them to leave the window at least as large as the size
9692 * request. When dealing with window sizes,
9693 * gtk_window_set_geometry_hints() can be a useful function as well.
9695 * Note the inherent danger of setting any fixed size - themes,
9696 * translations into other languages, different fonts, and user action
9697 * can all change the appropriate size for a given widget. So, it's
9698 * basically impossible to hardcode a size that will always be
9701 * The size request of a widget is the smallest size a widget can
9702 * accept while still functioning well and drawing itself correctly.
9703 * However in some strange cases a widget may be allocated less than
9704 * its requested size, and in many cases a widget may be allocated more
9705 * space than it requested.
9707 * If the size request in a given direction is -1 (unset), then
9708 * the "natural" size request of the widget will be used instead.
9710 * Widgets can't actually be allocated a size less than 1 by 1, but
9711 * you can pass 0,0 to this function to mean "as small as possible."
9713 * The size request set here does not include any margin from the
9714 * #GtkWidget properties margin-left, margin-right, margin-top, and
9715 * margin-bottom, but it does include pretty much all other padding
9716 * or border properties set by any subclass of #GtkWidget.
9719 gtk_widget_set_size_request (GtkWidget *widget,
9723 g_return_if_fail (GTK_IS_WIDGET (widget));
9724 g_return_if_fail (width >= -1);
9725 g_return_if_fail (height >= -1);
9732 gtk_widget_set_usize_internal (widget, width, height, 0);
9737 * gtk_widget_get_size_request:
9738 * @widget: a #GtkWidget
9739 * @width: (out) (allow-none): return location for width, or %NULL
9740 * @height: (out) (allow-none): return location for height, or %NULL
9742 * Gets the size request that was explicitly set for the widget using
9743 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9744 * @height indicates that that dimension has not been set explicitly
9745 * and the natural requisition of the widget will be used intead. See
9746 * gtk_widget_set_size_request(). To get the size a widget will
9747 * actually request, call gtk_widget_get_preferred_size() instead of
9751 gtk_widget_get_size_request (GtkWidget *widget,
9755 const GtkWidgetAuxInfo *aux_info;
9757 g_return_if_fail (GTK_IS_WIDGET (widget));
9759 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9762 *width = aux_info->width;
9765 *height = aux_info->height;
9769 * _gtk_widget_override_size_request:
9770 * @widget: a #GtkWidget
9771 * @width: new forced minimum width
9772 * @height: new forced minimum height
9773 * @old_width: location to store previous forced minimum width
9774 * @old_width: location to store previous forced minumum height
9776 * Temporarily establishes a forced minimum size for a widget; this
9777 * is used by GtkWindow when calculating the size to add to the
9778 * window's geometry widget. Cached sizes for the widget and its
9779 * parents are invalidated, so that subsequent calls to the size
9780 * negotiation machinery produce the overriden result, but the
9781 * widget is not queued for relayout or redraw. The old size must
9782 * be restored with _gtk_widget_restore_size_request() or things
9786 _gtk_widget_override_size_request (GtkWidget *widget,
9792 gtk_widget_get_size_request (widget, old_width, old_height);
9793 gtk_widget_set_usize_internal (widget, width, height,
9794 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9798 * _gtk_widget_restore_size_request:
9799 * @widget: a #GtkWidget
9800 * @old_width: saved forced minimum size
9801 * @old_height: saved forced minimum size
9803 * Undoes the operation of_gtk_widget_override_size_request().
9806 _gtk_widget_restore_size_request (GtkWidget *widget,
9810 gtk_widget_set_usize_internal (widget, old_width, old_height,
9811 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9815 * gtk_widget_set_events:
9816 * @widget: a #GtkWidget
9817 * @events: event mask
9819 * Sets the event mask (see #GdkEventMask) for a widget. The event
9820 * mask determines which events a widget will receive. Keep in mind
9821 * that different widgets have different default event masks, and by
9822 * changing the event mask you may disrupt a widget's functionality,
9823 * so be careful. This function must be called while a widget is
9824 * unrealized. Consider gtk_widget_add_events() for widgets that are
9825 * already realized, or if you want to preserve the existing event
9826 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9827 * to get events on those widgets, place them inside a #GtkEventBox
9828 * and receive events on the event box.
9831 gtk_widget_set_events (GtkWidget *widget,
9834 g_return_if_fail (GTK_IS_WIDGET (widget));
9835 g_return_if_fail (!gtk_widget_get_realized (widget));
9837 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9838 GINT_TO_POINTER (events));
9839 g_object_notify (G_OBJECT (widget), "events");
9843 * gtk_widget_set_device_events:
9844 * @widget: a #GtkWidget
9845 * @device: a #GdkDevice
9846 * @events: event mask
9848 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9849 * mask determines which events a widget will receive from @device. Keep
9850 * in mind that different widgets have different default event masks, and by
9851 * changing the event mask you may disrupt a widget's functionality,
9852 * so be careful. This function must be called while a widget is
9853 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9854 * already realized, or if you want to preserve the existing event
9855 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9856 * to get events on those widgets, place them inside a #GtkEventBox
9857 * and receive events on the event box.
9862 gtk_widget_set_device_events (GtkWidget *widget,
9864 GdkEventMask events)
9866 GHashTable *device_events;
9868 g_return_if_fail (GTK_IS_WIDGET (widget));
9869 g_return_if_fail (GDK_IS_DEVICE (device));
9870 g_return_if_fail (!gtk_widget_get_realized (widget));
9872 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9874 if (G_UNLIKELY (!device_events))
9876 device_events = g_hash_table_new (NULL, NULL);
9877 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9878 (GDestroyNotify) g_hash_table_unref);
9881 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9885 * gtk_widget_set_device_enabled:
9886 * @widget: a #GtkWidget
9887 * @device: a #GdkDevice
9888 * @enabled: whether to enable the device
9890 * Enables or disables a #GdkDevice to interact with @widget
9891 * and all its children.
9893 * It does so by descending through the #GdkWindow hierarchy
9894 * and enabling the same mask that is has for core events
9895 * (i.e. the one that gdk_window_get_events() returns).
9900 gtk_widget_set_device_enabled (GtkWidget *widget,
9904 GList *enabled_devices;
9906 g_return_if_fail (GTK_IS_WIDGET (widget));
9907 g_return_if_fail (GDK_IS_DEVICE (device));
9909 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9910 enabled_devices = g_list_append (enabled_devices, device);
9912 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9913 enabled_devices, (GDestroyNotify) g_list_free);;
9915 if (gtk_widget_get_realized (widget))
9916 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9920 * gtk_widget_get_device_enabled:
9921 * @widget: a #GtkWidget
9922 * @device: a #GdkDevice
9924 * Returns whether @device can interact with @widget and its
9925 * children. See gtk_widget_set_device_enabled().
9927 * Return value: %TRUE is @device is enabled for @widget
9932 gtk_widget_get_device_enabled (GtkWidget *widget,
9935 GList *enabled_devices;
9937 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9938 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9940 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9942 return g_list_find (enabled_devices, device) != NULL;
9946 gtk_widget_add_events_internal_list (GtkWidget *widget,
9953 for (l = window_list; l != NULL; l = l->next)
9955 GdkWindow *window = l->data;
9958 gdk_window_get_user_data (window, &user_data);
9959 if (user_data == widget)
9964 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9966 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9968 children = gdk_window_get_children (window);
9969 gtk_widget_add_events_internal_list (widget, device, events, children);
9970 g_list_free (children);
9976 gtk_widget_add_events_internal (GtkWidget *widget,
9980 GtkWidgetPrivate *priv = widget->priv;
9983 if (!gtk_widget_get_has_window (widget))
9984 window_list = gdk_window_get_children (priv->window);
9986 window_list = g_list_prepend (NULL, priv->window);
9988 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9990 g_list_free (window_list);
9994 * gtk_widget_add_events:
9995 * @widget: a #GtkWidget
9996 * @events: an event mask, see #GdkEventMask
9998 * Adds the events in the bitfield @events to the event mask for
9999 * @widget. See gtk_widget_set_events() for details.
10002 gtk_widget_add_events (GtkWidget *widget,
10007 g_return_if_fail (GTK_IS_WIDGET (widget));
10009 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10010 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
10011 GINT_TO_POINTER (old_events | events));
10013 if (gtk_widget_get_realized (widget))
10015 gtk_widget_add_events_internal (widget, NULL, events);
10016 gtk_widget_update_devices_mask (widget, FALSE);
10019 g_object_notify (G_OBJECT (widget), "events");
10023 * gtk_widget_add_device_events:
10024 * @widget: a #GtkWidget
10025 * @device: a #GdkDevice
10026 * @events: an event mask, see #GdkEventMask
10028 * Adds the device events in the bitfield @events to the event mask for
10029 * @widget. See gtk_widget_set_device_events() for details.
10034 gtk_widget_add_device_events (GtkWidget *widget,
10036 GdkEventMask events)
10038 GdkEventMask old_events;
10039 GHashTable *device_events;
10041 g_return_if_fail (GTK_IS_WIDGET (widget));
10042 g_return_if_fail (GDK_IS_DEVICE (device));
10044 old_events = gtk_widget_get_device_events (widget, device);
10046 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10048 if (G_UNLIKELY (!device_events))
10050 device_events = g_hash_table_new (NULL, NULL);
10051 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
10052 (GDestroyNotify) g_hash_table_unref);
10055 g_hash_table_insert (device_events, device,
10056 GUINT_TO_POINTER (old_events | events));
10058 if (gtk_widget_get_realized (widget))
10059 gtk_widget_add_events_internal (widget, device, events);
10061 g_object_notify (G_OBJECT (widget), "events");
10065 * gtk_widget_get_toplevel:
10066 * @widget: a #GtkWidget
10068 * This function returns the topmost widget in the container hierarchy
10069 * @widget is a part of. If @widget has no parent widgets, it will be
10070 * returned as the topmost widget. No reference will be added to the
10071 * returned widget; it should not be unreferenced.
10073 * Note the difference in behavior vs. gtk_widget_get_ancestor();
10074 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
10076 * %NULL if @widget wasn't inside a toplevel window, and if the
10077 * window was inside a #GtkWindow-derived widget which was in turn
10078 * inside the toplevel #GtkWindow. While the second case may
10079 * seem unlikely, it actually happens when a #GtkPlug is embedded
10080 * inside a #GtkSocket within the same application.
10082 * To reliably find the toplevel #GtkWindow, use
10083 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
10084 * is set on the result.
10086 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
10087 * if (gtk_widget_is_toplevel (toplevel))
10089 * /* Perform action on toplevel. */
10093 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
10094 * if there's no ancestor.
10097 gtk_widget_get_toplevel (GtkWidget *widget)
10099 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10101 while (widget->priv->parent)
10102 widget = widget->priv->parent;
10108 * gtk_widget_get_ancestor:
10109 * @widget: a #GtkWidget
10110 * @widget_type: ancestor type
10112 * Gets the first ancestor of @widget with type @widget_type. For example,
10113 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
10114 * the first #GtkBox that's an ancestor of @widget. No reference will be
10115 * added to the returned widget; it should not be unreferenced. See note
10116 * about checking for a toplevel #GtkWindow in the docs for
10117 * gtk_widget_get_toplevel().
10119 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
10120 * considers @widget to be an ancestor of itself.
10122 * Return value: (transfer none): the ancestor widget, or %NULL if not found
10125 gtk_widget_get_ancestor (GtkWidget *widget,
10128 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10130 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
10131 widget = widget->priv->parent;
10133 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
10140 * gtk_widget_set_visual:
10141 * @widget: a #GtkWidget
10142 * @visual: visual to be used or %NULL to unset a previous one
10144 * Sets the visual that should be used for by widget and its children for
10145 * creating #GdkWindows. The visual must be on the same #GdkScreen as
10146 * returned by gdk_widget_get_screen(), so handling the
10147 * #GtkWidget::screen-changed signal is necessary.
10149 * Setting a new @visual will not cause @widget to recreate its windows,
10150 * so you should call this function before @widget is realized.
10153 gtk_widget_set_visual (GtkWidget *widget,
10156 g_return_if_fail (GTK_IS_WIDGET (widget));
10157 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
10160 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
10163 g_object_set_qdata_full (G_OBJECT (widget),
10165 g_object_ref (visual),
10170 * gtk_widget_get_visual:
10171 * @widget: a #GtkWidget
10173 * Gets the visual that will be used to render @widget.
10175 * Return value: (transfer none): the visual for @widget
10178 gtk_widget_get_visual (GtkWidget *widget)
10184 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10186 if (gtk_widget_get_has_window (widget) &&
10187 widget->priv->window)
10188 return gdk_window_get_visual (widget->priv->window);
10190 screen = gtk_widget_get_screen (widget);
10192 for (w = widget; w != NULL; w = w->priv->parent)
10194 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
10197 if (gdk_visual_get_screen (visual) == screen)
10200 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
10201 gtk_widget_get_name (widget));
10205 return gdk_screen_get_system_visual (screen);
10209 * gtk_widget_get_settings:
10210 * @widget: a #GtkWidget
10212 * Gets the settings object holding the settings used for this widget.
10214 * Note that this function can only be called when the #GtkWidget
10215 * is attached to a toplevel, since the settings object is specific
10216 * to a particular #GdkScreen.
10218 * Return value: (transfer none): the relevant #GtkSettings object
10221 gtk_widget_get_settings (GtkWidget *widget)
10223 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10225 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
10229 * gtk_widget_get_events:
10230 * @widget: a #GtkWidget
10232 * Returns the event mask for the widget (a bitfield containing flags
10233 * from the #GdkEventMask enumeration). These are the events that the widget
10236 * Return value: event mask for @widget
10239 gtk_widget_get_events (GtkWidget *widget)
10241 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10243 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10247 * gtk_widget_get_device_events:
10248 * @widget: a #GtkWidget
10249 * @device: a #GdkDevice
10251 * Returns the events mask for the widget corresponding to an specific device. These
10252 * are the events that the widget will receive when @device operates on it.
10254 * Returns: device event mask for @widget
10259 gtk_widget_get_device_events (GtkWidget *widget,
10262 GHashTable *device_events;
10264 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10265 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
10267 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10269 if (!device_events)
10272 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
10276 * gtk_widget_get_pointer:
10277 * @widget: a #GtkWidget
10278 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
10279 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
10281 * Obtains the location of the mouse pointer in widget coordinates.
10282 * Widget coordinates are a bit odd; for historical reasons, they are
10283 * defined as @widget->window coordinates for widgets that are not
10284 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
10285 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
10288 gtk_widget_get_pointer (GtkWidget *widget,
10292 GtkWidgetPrivate *priv;
10294 g_return_if_fail (GTK_IS_WIDGET (widget));
10296 priv = widget->priv;
10303 if (gtk_widget_get_realized (widget))
10305 gdk_window_get_pointer (priv->window, x, y, NULL);
10307 if (!gtk_widget_get_has_window (widget))
10310 *x -= priv->allocation.x;
10312 *y -= priv->allocation.y;
10318 * gtk_widget_is_ancestor:
10319 * @widget: a #GtkWidget
10320 * @ancestor: another #GtkWidget
10322 * Determines whether @widget is somewhere inside @ancestor, possibly with
10323 * intermediate containers.
10325 * Return value: %TRUE if @ancestor contains @widget as a child,
10326 * grandchild, great grandchild, etc.
10329 gtk_widget_is_ancestor (GtkWidget *widget,
10330 GtkWidget *ancestor)
10332 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10333 g_return_val_if_fail (ancestor != NULL, FALSE);
10337 if (widget->priv->parent == ancestor)
10339 widget = widget->priv->parent;
10345 static GQuark quark_composite_name = 0;
10348 * gtk_widget_set_composite_name:
10349 * @widget: a #GtkWidget.
10350 * @name: the name to set
10352 * Sets a widgets composite name. The widget must be
10353 * a composite child of its parent; see gtk_widget_push_composite_child().
10356 gtk_widget_set_composite_name (GtkWidget *widget,
10359 g_return_if_fail (GTK_IS_WIDGET (widget));
10360 g_return_if_fail (widget->priv->composite_child);
10361 g_return_if_fail (name != NULL);
10363 if (!quark_composite_name)
10364 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10366 g_object_set_qdata_full (G_OBJECT (widget),
10367 quark_composite_name,
10373 * gtk_widget_get_composite_name:
10374 * @widget: a #GtkWidget
10376 * Obtains the composite name of a widget.
10378 * Returns: the composite name of @widget, or %NULL if @widget is not
10379 * a composite child. The string should be freed when it is no
10383 gtk_widget_get_composite_name (GtkWidget *widget)
10385 GtkWidgetPrivate *priv;
10387 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10389 priv = widget->priv;
10391 if (widget->priv->composite_child && priv->parent)
10392 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10399 * gtk_widget_push_composite_child:
10401 * Makes all newly-created widgets as composite children until
10402 * the corresponding gtk_widget_pop_composite_child() call.
10404 * A composite child is a child that's an implementation detail of the
10405 * container it's inside and should not be visible to people using the
10406 * container. Composite children aren't treated differently by GTK (but
10407 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10408 * builders might want to treat them in a different way.
10410 * Here is a simple example:
10412 * gtk_widget_push_composite_child ();
10413 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10414 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10415 * gtk_widget_pop_composite_child ();
10416 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10417 * GTK_WIDGET (scrolled_window));
10418 * g_object_ref (scrolled_window->hscrollbar);
10422 gtk_widget_push_composite_child (void)
10424 composite_child_stack++;
10428 * gtk_widget_pop_composite_child:
10430 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10433 gtk_widget_pop_composite_child (void)
10435 if (composite_child_stack)
10436 composite_child_stack--;
10440 gtk_widget_emit_direction_changed (GtkWidget *widget,
10441 GtkTextDirection old_dir)
10443 gtk_widget_update_pango_context (widget);
10445 if (widget->priv->context)
10446 gtk_style_context_set_direction (widget->priv->context,
10447 gtk_widget_get_direction (widget));
10449 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10453 * gtk_widget_set_direction:
10454 * @widget: a #GtkWidget
10455 * @dir: the new direction
10457 * Sets the reading direction on a particular widget. This direction
10458 * controls the primary direction for widgets containing text,
10459 * and also the direction in which the children of a container are
10460 * packed. The ability to set the direction is present in order
10461 * so that correct localization into languages with right-to-left
10462 * reading directions can be done. Generally, applications will
10463 * let the default reading direction present, except for containers
10464 * where the containers are arranged in an order that is explicitely
10465 * visual rather than logical (such as buttons for text justification).
10467 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10468 * set by gtk_widget_set_default_direction() will be used.
10471 gtk_widget_set_direction (GtkWidget *widget,
10472 GtkTextDirection dir)
10474 GtkTextDirection old_dir;
10476 g_return_if_fail (GTK_IS_WIDGET (widget));
10477 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10479 old_dir = gtk_widget_get_direction (widget);
10481 widget->priv->direction = dir;
10483 if (old_dir != gtk_widget_get_direction (widget))
10484 gtk_widget_emit_direction_changed (widget, old_dir);
10488 * gtk_widget_get_direction:
10489 * @widget: a #GtkWidget
10491 * Gets the reading direction for a particular widget. See
10492 * gtk_widget_set_direction().
10494 * Return value: the reading direction for the widget.
10497 gtk_widget_get_direction (GtkWidget *widget)
10499 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10501 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10502 return gtk_default_direction;
10504 return widget->priv->direction;
10508 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10510 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10512 g_object_ref (widget);
10514 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10515 gtk_widget_emit_direction_changed (widget, old_dir);
10517 if (GTK_IS_CONTAINER (widget))
10518 gtk_container_forall (GTK_CONTAINER (widget),
10519 gtk_widget_set_default_direction_recurse,
10522 g_object_unref (widget);
10526 * gtk_widget_set_default_direction:
10527 * @dir: the new default direction. This cannot be
10528 * %GTK_TEXT_DIR_NONE.
10530 * Sets the default reading direction for widgets where the
10531 * direction has not been explicitly set by gtk_widget_set_direction().
10534 gtk_widget_set_default_direction (GtkTextDirection dir)
10536 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10538 if (dir != gtk_default_direction)
10540 GList *toplevels, *tmp_list;
10541 GtkTextDirection old_dir = gtk_default_direction;
10543 gtk_default_direction = dir;
10545 tmp_list = toplevels = gtk_window_list_toplevels ();
10546 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10550 gtk_widget_set_default_direction_recurse (tmp_list->data,
10551 GUINT_TO_POINTER (old_dir));
10552 g_object_unref (tmp_list->data);
10553 tmp_list = tmp_list->next;
10556 g_list_free (toplevels);
10561 * gtk_widget_get_default_direction:
10563 * Obtains the current default reading direction. See
10564 * gtk_widget_set_default_direction().
10566 * Return value: the current default direction.
10569 gtk_widget_get_default_direction (void)
10571 return gtk_default_direction;
10575 gtk_widget_dispose (GObject *object)
10577 GtkWidget *widget = GTK_WIDGET (object);
10578 GtkWidgetPrivate *priv = widget->priv;
10581 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10582 else if (gtk_widget_get_visible (widget))
10583 gtk_widget_hide (widget);
10585 priv->visible = FALSE;
10586 if (gtk_widget_get_realized (widget))
10587 gtk_widget_unrealize (widget);
10589 if (!priv->in_destruction)
10591 priv->in_destruction = TRUE;
10592 g_signal_emit (object, widget_signals[DESTROY], 0);
10593 priv->in_destruction = FALSE;
10596 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10600 gtk_widget_real_destroy (GtkWidget *object)
10602 /* gtk_object_destroy() will already hold a refcount on object */
10603 GtkWidget *widget = GTK_WIDGET (object);
10604 GtkWidgetPrivate *priv = widget->priv;
10606 /* wipe accelerator closures (keep order) */
10607 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10608 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10610 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10611 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10613 gtk_grab_remove (widget);
10616 g_object_unref (priv->style);
10617 priv->style = gtk_widget_get_default_style ();
10618 g_object_ref (priv->style);
10622 gtk_widget_finalize (GObject *object)
10624 GtkWidget *widget = GTK_WIDGET (object);
10625 GtkWidgetPrivate *priv = widget->priv;
10626 GtkWidgetAuxInfo *aux_info;
10627 GtkAccessible *accessible;
10629 gtk_grab_remove (widget);
10631 g_object_unref (priv->style);
10632 priv->style = NULL;
10634 g_free (priv->name);
10636 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
10638 gtk_widget_aux_info_destroy (aux_info);
10640 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10642 g_object_unref (accessible);
10645 gtk_widget_path_free (priv->path);
10648 g_object_unref (priv->context);
10650 _gtk_widget_free_cached_sizes (widget);
10652 if (g_object_is_floating (object))
10653 g_warning ("A floating object was finalized. This means that someone\n"
10654 "called g_object_unref() on an object that had only a floating\n"
10655 "reference; the initial floating reference is not owned by anyone\n"
10656 "and must be removed with g_object_ref_sink().");
10658 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10661 /*****************************************
10662 * gtk_widget_real_map:
10667 *****************************************/
10670 gtk_widget_real_map (GtkWidget *widget)
10672 GtkWidgetPrivate *priv = widget->priv;
10674 g_assert (gtk_widget_get_realized (widget));
10676 if (!gtk_widget_get_mapped (widget))
10678 gtk_widget_set_mapped (widget, TRUE);
10680 if (gtk_widget_get_has_window (widget))
10681 gdk_window_show (priv->window);
10685 /*****************************************
10686 * gtk_widget_real_unmap:
10691 *****************************************/
10694 gtk_widget_real_unmap (GtkWidget *widget)
10696 GtkWidgetPrivate *priv = widget->priv;
10698 if (gtk_widget_get_mapped (widget))
10700 gtk_widget_set_mapped (widget, FALSE);
10702 if (gtk_widget_get_has_window (widget))
10703 gdk_window_hide (priv->window);
10707 /*****************************************
10708 * gtk_widget_real_realize:
10713 *****************************************/
10716 gtk_widget_real_realize (GtkWidget *widget)
10718 GtkWidgetPrivate *priv = widget->priv;
10720 g_assert (!gtk_widget_get_has_window (widget));
10722 gtk_widget_set_realized (widget, TRUE);
10725 priv->window = gtk_widget_get_parent_window (widget);
10726 g_object_ref (priv->window);
10730 /*****************************************
10731 * gtk_widget_real_unrealize:
10736 *****************************************/
10739 gtk_widget_real_unrealize (GtkWidget *widget)
10741 GtkWidgetPrivate *priv = widget->priv;
10743 g_assert (!widget->priv->mapped);
10745 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10748 /* We must do unrealize child widget BEFORE container widget.
10749 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10750 * So, unrealizing container widget bofore its children causes the problem
10751 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10754 if (GTK_IS_CONTAINER (widget))
10755 gtk_container_forall (GTK_CONTAINER (widget),
10756 (GtkCallback) gtk_widget_unrealize,
10759 if (gtk_widget_get_has_window (widget))
10761 gdk_window_set_user_data (priv->window, NULL);
10762 gdk_window_destroy (priv->window);
10763 priv->window = NULL;
10767 g_object_unref (priv->window);
10768 priv->window = NULL;
10771 gtk_selection_remove_all (widget);
10773 gtk_widget_set_realized (widget, FALSE);
10777 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10778 GtkOrientation orientation,
10779 gint *minimum_size,
10780 gint *natural_size)
10782 const GtkWidgetAuxInfo *aux_info;
10784 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10786 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10787 aux_info->width > 0)
10789 *minimum_size = MAX (*minimum_size, aux_info->width);
10791 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10792 aux_info->height > 0)
10794 *minimum_size = MAX (*minimum_size, aux_info->height);
10797 /* Fix it if set_size_request made natural size smaller than min size.
10798 * This would also silently fix broken widgets, but we warn about them
10799 * in gtksizerequest.c when calling their size request vfuncs.
10801 *natural_size = MAX (*natural_size, *minimum_size);
10803 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10805 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10806 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10810 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10811 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10816 * _gtk_widget_peek_request_cache:
10818 * Returns the address of the widget's request cache (strictly for
10819 * internal use in gtksizerequest.c)
10821 * Return value: the address of @widget's size request cache.
10824 _gtk_widget_peek_request_cache (GtkWidget *widget)
10826 /* Don't bother slowing things down with the return_if_fail guards here */
10827 return &widget->priv->requests;
10831 * _gtk_widget_set_device_window:
10832 * @widget: a #GtkWidget
10833 * @device: a #GdkDevice
10834 * @window: the new device window
10836 * Sets pointer window for @widget and @device.
10837 * Does not ref @window.
10840 _gtk_widget_set_device_window (GtkWidget *widget,
10844 GHashTable *device_window;
10846 g_return_if_fail (GTK_IS_WIDGET (widget));
10847 g_return_if_fail (GDK_IS_DEVICE (device));
10848 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10850 if (!gtk_widget_get_mapped (widget))
10853 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10855 if (!device_window && window)
10857 device_window = g_hash_table_new (NULL, NULL);
10858 g_object_set_qdata_full (G_OBJECT (widget),
10859 quark_pointer_window,
10861 (GDestroyNotify) g_hash_table_destroy);
10865 g_hash_table_insert (device_window, device, window);
10866 else if (device_window)
10868 g_hash_table_remove (device_window, device);
10870 if (g_hash_table_size (device_window) == 0)
10871 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10876 * _gtk_widget_get_device_window:
10877 * @widget: a #GtkWidget
10878 * @device: a #GdkDevice
10880 * Return value: the device window set on @widget, or %NULL
10883 _gtk_widget_get_device_window (GtkWidget *widget,
10886 GHashTable *device_window;
10888 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10889 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10891 if (!gtk_widget_get_mapped (widget))
10894 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10896 if (!device_window)
10899 return g_hash_table_lookup (device_window, device);
10903 * _gtk_widget_list_devices:
10904 * @widget: a #GtkWidget
10906 * Returns the list of #GdkDevices that is currently on top
10907 * of any window belonging to @widget.
10908 * Free the list with g_list_free(), the elements are owned
10909 * by GTK+ and must not be freed.
10912 _gtk_widget_list_devices (GtkWidget *widget)
10914 GHashTableIter iter;
10915 GHashTable *device_window;
10916 GList *devices = NULL;
10917 gpointer key, value;
10919 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10921 if (!gtk_widget_get_mapped (widget))
10924 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10926 if (G_UNLIKELY (!device_window))
10929 g_hash_table_iter_init (&iter, device_window);
10931 while (g_hash_table_iter_next (&iter, &key, &value))
10932 devices = g_list_prepend (devices, key);
10938 synth_crossing (GtkWidget *widget,
10942 GdkCrossingMode mode,
10943 GdkNotifyType detail)
10947 event = gdk_event_new (type);
10949 event->crossing.window = g_object_ref (window);
10950 event->crossing.send_event = TRUE;
10951 event->crossing.subwindow = g_object_ref (window);
10952 event->crossing.time = GDK_CURRENT_TIME;
10953 event->crossing.x = event->crossing.y = 0;
10954 event->crossing.x_root = event->crossing.y_root = 0;
10955 event->crossing.mode = mode;
10956 event->crossing.detail = detail;
10957 event->crossing.focus = FALSE;
10958 event->crossing.state = 0;
10959 gdk_event_set_device (event, device);
10962 widget = gtk_get_event_widget (event);
10965 gtk_widget_event_internal (widget, event);
10967 gdk_event_free (event);
10971 * _gtk_widget_synthesize_crossing:
10972 * @from: the #GtkWidget the virtual pointer is leaving.
10973 * @to: the #GtkWidget the virtual pointer is moving to.
10974 * @mode: the #GdkCrossingMode to place on the synthesized events.
10976 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10978 * The real pointer window is the window that most recently received an enter notify
10979 * event. Windows that don't select for crossing events can't become the real
10980 * poiner window. The real pointer widget that owns the real pointer window. The
10981 * effective pointer window is the same as the real pointer window unless the real
10982 * pointer widget is either insensitive or there is a grab on a widget that is not
10983 * an ancestor of the real pointer widget (in which case the effective pointer
10984 * window should be the root window).
10986 * When the effective pointer window is the same as the real poiner window, we
10987 * receive crossing events from the windowing system. When the effective pointer
10988 * window changes to become different from the real pointer window we synthesize
10989 * crossing events, attempting to follow X protocol rules:
10991 * When the root window becomes the effective pointer window:
10992 * - leave notify on real pointer window, detail Ancestor
10993 * - leave notify on all of its ancestors, detail Virtual
10994 * - enter notify on root window, detail Inferior
10996 * When the root window ceases to be the effective pointer window:
10997 * - leave notify on root window, detail Inferior
10998 * - enter notify on all ancestors of real pointer window, detail Virtual
10999 * - enter notify on real pointer window, detail Ancestor
11002 _gtk_widget_synthesize_crossing (GtkWidget *from,
11005 GdkCrossingMode mode)
11007 GdkWindow *from_window = NULL, *to_window = NULL;
11009 g_return_if_fail (from != NULL || to != NULL);
11013 from_window = _gtk_widget_get_device_window (from, device);
11016 from_window = from->priv->window;
11021 to_window = _gtk_widget_get_device_window (to, device);
11024 to_window = to->priv->window;
11027 if (from_window == NULL && to_window == NULL)
11029 else if (from_window != NULL && to_window == NULL)
11031 GList *from_ancestors = NULL, *list;
11032 GdkWindow *from_ancestor = from_window;
11034 while (from_ancestor != NULL)
11036 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
11037 if (from_ancestor == NULL)
11039 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
11042 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11043 device, mode, GDK_NOTIFY_ANCESTOR);
11044 for (list = g_list_last (from_ancestors); list; list = list->prev)
11046 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11047 device, mode, GDK_NOTIFY_VIRTUAL);
11050 /* XXX: enter/inferior on root window? */
11052 g_list_free (from_ancestors);
11054 else if (from_window == NULL && to_window != NULL)
11056 GList *to_ancestors = NULL, *list;
11057 GdkWindow *to_ancestor = to_window;
11059 while (to_ancestor != NULL)
11061 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
11062 if (to_ancestor == NULL)
11064 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
11067 /* XXX: leave/inferior on root window? */
11069 for (list = to_ancestors; list; list = list->next)
11071 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11072 device, mode, GDK_NOTIFY_VIRTUAL);
11074 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11075 device, mode, GDK_NOTIFY_ANCESTOR);
11077 g_list_free (to_ancestors);
11079 else if (from_window == to_window)
11083 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
11084 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
11086 while (from_ancestor != NULL || to_ancestor != NULL)
11088 if (from_ancestor != NULL)
11090 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
11091 if (from_ancestor == to_window)
11094 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
11096 if (to_ancestor != NULL)
11098 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
11099 if (to_ancestor == from_window)
11102 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
11105 if (to_ancestor == from_window)
11107 if (mode != GDK_CROSSING_GTK_UNGRAB)
11108 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11109 device, mode, GDK_NOTIFY_INFERIOR);
11110 for (list = to_ancestors; list; list = list->next)
11111 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11112 device, mode, GDK_NOTIFY_VIRTUAL);
11113 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11114 device, mode, GDK_NOTIFY_ANCESTOR);
11116 else if (from_ancestor == to_window)
11118 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11119 device, mode, GDK_NOTIFY_ANCESTOR);
11120 for (list = g_list_last (from_ancestors); list; list = list->prev)
11122 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11123 device, mode, GDK_NOTIFY_VIRTUAL);
11125 if (mode != GDK_CROSSING_GTK_GRAB)
11126 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11127 device, mode, GDK_NOTIFY_INFERIOR);
11131 while (from_ancestors != NULL && to_ancestors != NULL
11132 && from_ancestors->data == to_ancestors->data)
11134 from_ancestors = g_list_delete_link (from_ancestors,
11136 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
11139 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11140 device, mode, GDK_NOTIFY_NONLINEAR);
11142 for (list = g_list_last (from_ancestors); list; list = list->prev)
11144 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11145 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11147 for (list = to_ancestors; list; list = list->next)
11149 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11150 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11152 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11153 device, mode, GDK_NOTIFY_NONLINEAR);
11155 g_list_free (from_ancestors);
11156 g_list_free (to_ancestors);
11161 gtk_widget_propagate_state (GtkWidget *widget,
11162 GtkStateData *data)
11164 GtkWidgetPrivate *priv = widget->priv;
11165 GtkStateFlags new_flags, old_flags = priv->state_flags;
11166 GtkStateType old_state;
11168 old_state = gtk_widget_get_state (widget);
11170 switch (data->operation)
11172 case STATE_CHANGE_REPLACE:
11173 priv->state_flags = data->flags;
11175 case STATE_CHANGE_SET:
11176 priv->state_flags |= data->flags;
11178 case STATE_CHANGE_UNSET:
11179 priv->state_flags &= ~(data->flags);
11183 /* make insensitivity unoverridable */
11184 if (!priv->sensitive)
11185 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
11187 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
11191 window = gtk_widget_get_toplevel (widget);
11193 if (window && gtk_widget_is_toplevel (window))
11194 gtk_window_set_focus (GTK_WINDOW (window), NULL);
11197 new_flags = priv->state_flags;
11199 if (old_flags != new_flags)
11201 g_object_ref (widget);
11203 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
11204 gtk_grab_remove (widget);
11206 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
11207 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
11209 if (!priv->shadowed)
11211 GList *event_windows = NULL;
11212 GList *devices, *d;
11214 devices = _gtk_widget_list_devices (widget);
11216 for (d = devices; d; d = d->next)
11222 window = _gtk_widget_get_device_window (widget, device);
11224 /* Do not propagate more than once to the
11225 * same window if non-multidevice aware.
11227 if (!gdk_window_get_support_multidevice (window) &&
11228 g_list_find (event_windows, window))
11231 if (!gtk_widget_is_sensitive (widget))
11232 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
11233 GDK_CROSSING_STATE_CHANGED);
11234 else if (old_flags & GTK_STATE_FLAG_INSENSITIVE)
11235 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
11236 GDK_CROSSING_STATE_CHANGED);
11238 event_windows = g_list_prepend (event_windows, window);
11241 g_list_free (event_windows);
11242 g_list_free (devices);
11245 if (GTK_IS_CONTAINER (widget))
11247 GtkStateData child_data = *data;
11249 /* Make sure to only propate the right states further */
11250 child_data.flags &= GTK_STATE_FLAGS_DO_PROPAGATE;
11252 if (child_data.use_forall)
11253 gtk_container_forall (GTK_CONTAINER (widget),
11254 (GtkCallback) gtk_widget_propagate_state,
11257 gtk_container_foreach (GTK_CONTAINER (widget),
11258 (GtkCallback) gtk_widget_propagate_state,
11262 /* Trigger state change transitions for the widget */
11263 if (priv->context &&
11264 gtk_widget_get_mapped (widget))
11266 gint diff, flag = 1;
11268 diff = old_flags ^ new_flags;
11272 if ((diff & flag) != 0)
11276 target = ((new_flags & flag) != 0);
11277 _gtk_widget_notify_state_change (widget, flag, target);
11286 g_object_unref (widget);
11290 static const GtkWidgetAuxInfo default_aux_info = {
11298 * _gtk_widget_get_aux_info:
11299 * @widget: a #GtkWidget
11300 * @create: if %TRUE, create the structure if it doesn't exist
11302 * Get the #GtkWidgetAuxInfo structure for the widget.
11304 * Return value: the #GtkAuxInfo structure for the widget, or
11305 * %NULL if @create is %FALSE and one doesn't already exist.
11308 _gtk_widget_get_aux_info (GtkWidget *widget,
11311 GtkWidgetAuxInfo *aux_info;
11313 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
11314 if (!aux_info && create)
11316 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
11318 *aux_info = default_aux_info;
11320 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
11326 static const GtkWidgetAuxInfo*
11327 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11329 GtkWidgetAuxInfo *aux_info;
11331 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
11332 if (aux_info == NULL)
11334 return &default_aux_info;
11342 /*****************************************
11343 * gtk_widget_aux_info_destroy:
11348 *****************************************/
11351 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11353 g_slice_free (GtkWidgetAuxInfo, aux_info);
11357 * gtk_widget_shape_combine_region:
11358 * @widget: a #GtkWidget
11359 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11361 * Sets a shape for this widget's GDK window. This allows for
11362 * transparent windows etc., see gdk_window_shape_combine_region()
11363 * for more information.
11368 gtk_widget_shape_combine_region (GtkWidget *widget,
11369 cairo_region_t *region)
11371 GtkWidgetPrivate *priv;
11373 g_return_if_fail (GTK_IS_WIDGET (widget));
11374 /* set_shape doesn't work on widgets without gdk window */
11375 g_return_if_fail (gtk_widget_get_has_window (widget));
11377 priv = widget->priv;
11379 if (region == NULL)
11381 priv->has_shape_mask = FALSE;
11384 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11386 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11390 priv->has_shape_mask = TRUE;
11392 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11393 cairo_region_copy (region),
11394 (GDestroyNotify) cairo_region_destroy);
11396 /* set shape if widget has a gdk window already.
11397 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11400 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11405 * gtk_widget_input_shape_combine_region:
11406 * @widget: a #GtkWidget
11407 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11409 * Sets an input shape for this widget's GDK window. This allows for
11410 * windows which react to mouse click in a nonrectangular region, see
11411 * gdk_window_input_shape_combine_region() for more information.
11416 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11417 cairo_region_t *region)
11419 GtkWidgetPrivate *priv;
11421 g_return_if_fail (GTK_IS_WIDGET (widget));
11422 /* set_shape doesn't work on widgets without gdk window */
11423 g_return_if_fail (gtk_widget_get_has_window (widget));
11425 priv = widget->priv;
11427 if (region == NULL)
11430 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11432 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11436 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11437 cairo_region_copy (region),
11438 (GDestroyNotify) cairo_region_destroy);
11440 /* set shape if widget has a gdk window already.
11441 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11444 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11449 /* style properties
11453 * gtk_widget_class_install_style_property_parser: (skip)
11454 * @klass: a #GtkWidgetClass
11455 * @pspec: the #GParamSpec for the style property
11456 * @parser: the parser for the style property
11458 * Installs a style property on a widget class.
11461 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11463 GtkRcPropertyParser parser)
11465 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11466 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11467 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11468 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11470 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11472 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11473 G_OBJECT_CLASS_NAME (klass),
11478 g_param_spec_ref_sink (pspec);
11479 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11480 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11484 * gtk_widget_class_install_style_property:
11485 * @klass: a #GtkWidgetClass
11486 * @pspec: the #GParamSpec for the property
11488 * Installs a style property on a widget class. The parser for the
11489 * style property is determined by the value type of @pspec.
11492 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11495 GtkRcPropertyParser parser;
11497 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11498 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11500 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11502 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11506 * gtk_widget_class_find_style_property:
11507 * @klass: a #GtkWidgetClass
11508 * @property_name: the name of the style property to find
11509 * @returns: (transfer none): the #GParamSpec of the style property or
11510 * %NULL if @class has no style property with that name.
11512 * Finds a style property of a widget class by name.
11517 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11518 const gchar *property_name)
11520 g_return_val_if_fail (property_name != NULL, NULL);
11522 return g_param_spec_pool_lookup (style_property_spec_pool,
11524 G_OBJECT_CLASS_TYPE (klass),
11529 * gtk_widget_class_list_style_properties:
11530 * @klass: a #GtkWidgetClass
11531 * @n_properties: location to return the number of style properties found
11532 * @returns: (array length=n_properties) (transfer container): an
11533 * newly allocated array of #GParamSpec*. The array must be
11534 * freed with g_free().
11536 * Returns all style properties of a widget class.
11541 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11542 guint *n_properties)
11544 GParamSpec **pspecs;
11547 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11548 G_OBJECT_CLASS_TYPE (klass),
11557 * gtk_widget_style_get_property:
11558 * @widget: a #GtkWidget
11559 * @property_name: the name of a style property
11560 * @value: location to return the property value
11562 * Gets the value of a style property of @widget.
11565 gtk_widget_style_get_property (GtkWidget *widget,
11566 const gchar *property_name,
11571 g_return_if_fail (GTK_IS_WIDGET (widget));
11572 g_return_if_fail (property_name != NULL);
11573 g_return_if_fail (G_IS_VALUE (value));
11575 g_object_ref (widget);
11576 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11578 G_OBJECT_TYPE (widget),
11581 g_warning ("%s: widget class `%s' has no property named `%s'",
11583 G_OBJECT_TYPE_NAME (widget),
11587 GtkStyleContext *context;
11588 const GValue *peek_value;
11589 GtkStateFlags state;
11591 context = gtk_widget_get_style_context (widget);
11592 state = gtk_widget_get_state_flags (widget);
11594 peek_value = _gtk_style_context_peek_style_property (context,
11595 G_OBJECT_TYPE (widget),
11598 /* auto-conversion of the caller's value type
11600 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11601 g_value_copy (peek_value, value);
11602 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11603 g_value_transform (peek_value, value);
11605 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11607 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11608 G_VALUE_TYPE_NAME (value));
11610 g_object_unref (widget);
11614 * gtk_widget_style_get_valist:
11615 * @widget: a #GtkWidget
11616 * @first_property_name: the name of the first property to get
11617 * @var_args: a <type>va_list</type> of pairs of property names and
11618 * locations to return the property values, starting with the location
11619 * for @first_property_name.
11621 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11625 gtk_widget_style_get_valist (GtkWidget *widget,
11626 const gchar *first_property_name,
11629 GtkStyleContext *context;
11630 GtkStateFlags state;
11633 g_return_if_fail (GTK_IS_WIDGET (widget));
11635 g_object_ref (widget);
11636 context = gtk_widget_get_style_context (widget);
11637 state = gtk_widget_get_state_flags (widget);
11639 name = first_property_name;
11642 const GValue *peek_value;
11646 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11648 G_OBJECT_TYPE (widget),
11652 g_warning ("%s: widget class `%s' has no property named `%s'",
11654 G_OBJECT_TYPE_NAME (widget),
11658 /* style pspecs are always readable so we can spare that check here */
11660 peek_value = _gtk_style_context_peek_style_property (context,
11661 G_OBJECT_TYPE (widget),
11664 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11667 g_warning ("%s: %s", G_STRLOC, error);
11672 name = va_arg (var_args, gchar*);
11675 g_object_unref (widget);
11679 * gtk_widget_style_get:
11680 * @widget: a #GtkWidget
11681 * @first_property_name: the name of the first property to get
11682 * @Varargs: pairs of property names and locations to
11683 * return the property values, starting with the location for
11684 * @first_property_name, terminated by %NULL.
11686 * Gets the values of a multiple style properties of @widget.
11689 gtk_widget_style_get (GtkWidget *widget,
11690 const gchar *first_property_name,
11695 g_return_if_fail (GTK_IS_WIDGET (widget));
11697 va_start (var_args, first_property_name);
11698 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11704 * @widget: a #GtkWidget
11705 * @path_length: (out) (allow-none): location to store length of the path,
11707 * @path: (out) (allow-none): location to store allocated path string,
11709 * @path_reversed: (out) (allow-none): location to store allocated reverse
11710 * path string, or %NULL
11712 * Obtains the full path to @widget. The path is simply the name of a
11713 * widget and all its parents in the container hierarchy, separated by
11714 * periods. The name of a widget comes from
11715 * gtk_widget_get_name(). Paths are used to apply styles to a widget
11716 * in gtkrc configuration files. Widget names are the type of the
11717 * widget by default (e.g. "GtkButton") or can be set to an
11718 * application-specific value with gtk_widget_set_name(). By setting
11719 * the name of a widget, you allow users or theme authors to apply
11720 * styles to that specific widget in their gtkrc
11721 * file. @path_reversed_p fills in the path in reverse order,
11722 * i.e. starting with @widget's name instead of starting with the name
11723 * of @widget's outermost ancestor.
11725 * Deprecated:3.0: Use gtk_widget_get_path() instead
11728 gtk_widget_path (GtkWidget *widget,
11729 guint *path_length,
11731 gchar **path_reversed)
11733 static gchar *rev_path = NULL;
11734 static guint tmp_path_len = 0;
11737 g_return_if_fail (GTK_IS_WIDGET (widget));
11742 const gchar *string;
11747 string = gtk_widget_get_name (widget);
11748 l = strlen (string);
11749 while (tmp_path_len <= len + l + 1)
11751 tmp_path_len += INIT_PATH_SIZE;
11752 rev_path = g_realloc (rev_path, tmp_path_len);
11754 s = string + l - 1;
11755 d = rev_path + len;
11756 while (s >= string)
11760 widget = widget->priv->parent;
11763 rev_path[len++] = '.';
11765 rev_path[len++] = 0;
11770 *path_length = len - 1;
11772 *path_reversed = g_strdup (rev_path);
11775 *path = g_strdup (rev_path);
11776 g_strreverse (*path);
11781 * gtk_widget_class_path:
11782 * @widget: a #GtkWidget
11783 * @path_length: (out) (allow-none): location to store the length of the
11784 * class path, or %NULL
11785 * @path: (out) (allow-none): location to store the class path as an
11786 * allocated string, or %NULL
11787 * @path_reversed: (out) (allow-none): location to store the reverse
11788 * class path as an allocated string, or %NULL
11790 * Same as gtk_widget_path(), but always uses the name of a widget's type,
11791 * never uses a custom name set with gtk_widget_set_name().
11793 * Deprecated:3.0: Use gtk_widget_get_path() instead
11796 gtk_widget_class_path (GtkWidget *widget,
11797 guint *path_length,
11799 gchar **path_reversed)
11801 static gchar *rev_path = NULL;
11802 static guint tmp_path_len = 0;
11805 g_return_if_fail (GTK_IS_WIDGET (widget));
11810 const gchar *string;
11815 string = g_type_name (G_OBJECT_TYPE (widget));
11816 l = strlen (string);
11817 while (tmp_path_len <= len + l + 1)
11819 tmp_path_len += INIT_PATH_SIZE;
11820 rev_path = g_realloc (rev_path, tmp_path_len);
11822 s = string + l - 1;
11823 d = rev_path + len;
11824 while (s >= string)
11828 widget = widget->priv->parent;
11831 rev_path[len++] = '.';
11833 rev_path[len++] = 0;
11838 *path_length = len - 1;
11840 *path_reversed = g_strdup (rev_path);
11843 *path = g_strdup (rev_path);
11844 g_strreverse (*path);
11849 * gtk_requisition_new:
11851 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11853 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11854 * be freed with gtk_requisition_free().
11859 gtk_requisition_new (void)
11861 return g_slice_new0 (GtkRequisition);
11865 * gtk_requisition_copy:
11866 * @requisition: a #GtkRequisition
11868 * Copies a #GtkRequisition.
11870 * Returns: a copy of @requisition
11873 gtk_requisition_copy (const GtkRequisition *requisition)
11875 return g_slice_dup (GtkRequisition, requisition);
11879 * gtk_requisition_free:
11880 * @requisition: a #GtkRequisition
11882 * Frees a #GtkRequisition.
11885 gtk_requisition_free (GtkRequisition *requisition)
11887 g_slice_free (GtkRequisition, requisition);
11890 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11891 gtk_requisition_copy,
11892 gtk_requisition_free)
11895 * gtk_widget_get_accessible:
11896 * @widget: a #GtkWidget
11898 * Returns the accessible object that describes the widget to an
11899 * assistive technology.
11901 * If no accessibility library is loaded (i.e. no ATK implementation library is
11902 * loaded via <envar>GTK_MODULES</envar> or via another application library,
11903 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
11904 * if no class-specific #AtkObject implementation is available for the widget
11905 * instance in question, it will inherit an #AtkObject implementation from the
11906 * first ancestor class for which such an implementation is defined.
11908 * The documentation of the
11909 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
11910 * library contains more information about accessible objects and their uses.
11912 * Returns: (transfer none): the #AtkObject associated with @widget
11915 gtk_widget_get_accessible (GtkWidget *widget)
11917 GtkWidgetClass *klass;
11919 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11921 klass = GTK_WIDGET_GET_CLASS (widget);
11923 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11925 return klass->get_accessible (widget);
11929 gtk_widget_real_get_accessible (GtkWidget *widget)
11931 AtkObject* accessible;
11933 accessible = g_object_get_qdata (G_OBJECT (widget),
11934 quark_accessible_object);
11937 AtkObjectFactory *factory;
11938 AtkRegistry *default_registry;
11940 default_registry = atk_get_default_registry ();
11941 factory = atk_registry_get_factory (default_registry,
11942 G_TYPE_FROM_INSTANCE (widget));
11944 atk_object_factory_create_accessible (factory,
11945 G_OBJECT (widget));
11946 g_object_set_qdata (G_OBJECT (widget),
11947 quark_accessible_object,
11954 * Initialize a AtkImplementorIface instance's virtual pointers as
11955 * appropriate to this implementor's class (GtkWidget).
11958 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11960 iface->ref_accessible = gtk_widget_ref_accessible;
11964 gtk_widget_ref_accessible (AtkImplementor *implementor)
11966 AtkObject *accessible;
11968 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11970 g_object_ref (accessible);
11975 * Expand flag management
11979 gtk_widget_update_computed_expand (GtkWidget *widget)
11981 GtkWidgetPrivate *priv;
11983 priv = widget->priv;
11985 if (priv->need_compute_expand)
11989 if (priv->hexpand_set)
11994 if (priv->vexpand_set)
11999 /* we don't need to use compute_expand if both expands are
12000 * forced by the app
12002 if (!(priv->hexpand_set && priv->vexpand_set))
12004 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
12008 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
12009 priv->hexpand_set ? &ignored : &h,
12010 priv->vexpand_set ? &ignored : &v);
12014 priv->need_compute_expand = FALSE;
12015 priv->computed_hexpand = h != FALSE;
12016 priv->computed_vexpand = v != FALSE;
12021 * gtk_widget_queue_compute_expand:
12022 * @widget: a #GtkWidget
12024 * Mark @widget as needing to recompute its expand flags. Call
12025 * this function when setting legacy expand child properties
12026 * on the child of a container.
12028 * See gtk_widget_compute_expand().
12031 gtk_widget_queue_compute_expand (GtkWidget *widget)
12034 gboolean changed_anything;
12036 if (widget->priv->need_compute_expand)
12039 changed_anything = FALSE;
12041 while (parent != NULL)
12043 if (!parent->priv->need_compute_expand)
12045 parent->priv->need_compute_expand = TRUE;
12046 changed_anything = TRUE;
12049 /* Note: if we had an invariant that "if a child needs to
12050 * compute expand, its parents also do" then we could stop going
12051 * up when we got to a parent that already needed to
12052 * compute. However, in general we compute expand lazily (as
12053 * soon as we see something in a subtree that is expand, we know
12054 * we're expanding) and so this invariant does not hold and we
12055 * have to always walk all the way up in case some ancestor
12056 * is not currently need_compute_expand.
12059 parent = parent->priv->parent;
12062 /* recomputing expand always requires
12063 * a relayout as well
12065 if (changed_anything)
12066 gtk_widget_queue_resize (widget);
12070 * gtk_widget_compute_expand:
12071 * @widget: the widget
12072 * @orientation: expand direction
12074 * Computes whether a container should give this widget extra space
12075 * when possible. Containers should check this, rather than
12076 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
12078 * This function already checks whether the widget is visible, so
12079 * visibility does not need to be checked separately. Non-visible
12080 * widgets are not expanded.
12082 * The computed expand value uses either the expand setting explicitly
12083 * set on the widget itself, or, if none has been explicitly set,
12084 * the widget may expand if some of its children do.
12086 * Return value: whether widget tree rooted here should be expanded
12089 gtk_widget_compute_expand (GtkWidget *widget,
12090 GtkOrientation orientation)
12092 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12094 /* We never make a widget expand if not even showing. */
12095 if (!gtk_widget_get_visible (widget))
12098 gtk_widget_update_computed_expand (widget);
12100 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12102 return widget->priv->computed_hexpand;
12106 return widget->priv->computed_vexpand;
12111 gtk_widget_set_expand (GtkWidget *widget,
12112 GtkOrientation orientation,
12115 const char *expand_prop;
12116 const char *expand_set_prop;
12118 GtkWidgetPrivate *priv;
12120 g_return_if_fail (GTK_IS_WIDGET (widget));
12122 priv = widget->priv;
12124 expand = expand != FALSE;
12126 was_both = priv->hexpand && priv->vexpand;
12128 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12130 if (priv->hexpand_set &&
12131 priv->hexpand == expand)
12134 priv->hexpand_set = TRUE;
12135 priv->hexpand = expand;
12137 expand_prop = "hexpand";
12138 expand_set_prop = "hexpand-set";
12142 if (priv->vexpand_set &&
12143 priv->vexpand == expand)
12146 priv->vexpand_set = TRUE;
12147 priv->vexpand = expand;
12149 expand_prop = "vexpand";
12150 expand_set_prop = "vexpand-set";
12153 gtk_widget_queue_compute_expand (widget);
12155 g_object_freeze_notify (G_OBJECT (widget));
12156 g_object_notify (G_OBJECT (widget), expand_prop);
12157 g_object_notify (G_OBJECT (widget), expand_set_prop);
12158 if (was_both != (priv->hexpand && priv->vexpand))
12159 g_object_notify (G_OBJECT (widget), "expand");
12160 g_object_thaw_notify (G_OBJECT (widget));
12164 gtk_widget_set_expand_set (GtkWidget *widget,
12165 GtkOrientation orientation,
12168 GtkWidgetPrivate *priv;
12171 priv = widget->priv;
12173 set = set != FALSE;
12175 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12177 if (set == priv->hexpand_set)
12180 priv->hexpand_set = set;
12181 prop = "hexpand-set";
12185 if (set == priv->vexpand_set)
12188 priv->vexpand_set = set;
12189 prop = "vexpand-set";
12192 gtk_widget_queue_compute_expand (widget);
12194 g_object_notify (G_OBJECT (widget), prop);
12198 * gtk_widget_get_hexpand:
12199 * @widget: the widget
12201 * Gets whether the widget would like any available extra horizontal
12202 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12203 * generally receive the extra space. For example, a list or
12204 * scrollable area or document in your window would often be set to
12207 * Containers should use gtk_widget_compute_expand() rather than
12208 * this function, to see whether a widget, or any of its children,
12209 * has the expand flag set. If any child of a widget wants to
12210 * expand, the parent may ask to expand also.
12212 * This function only looks at the widget's own hexpand flag, rather
12213 * than computing whether the entire widget tree rooted at this widget
12216 * Return value: whether hexpand flag is set
12219 gtk_widget_get_hexpand (GtkWidget *widget)
12221 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12223 return widget->priv->hexpand;
12227 * gtk_widget_set_hexpand:
12228 * @widget: the widget
12229 * @expand: whether to expand
12231 * Sets whether the widget would like any available extra horizontal
12232 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12233 * generally receive the extra space. For example, a list or
12234 * scrollable area or document in your window would often be set to
12237 * Call this function to set the expand flag if you would like your
12238 * widget to become larger horizontally when the window has extra
12241 * By default, widgets automatically expand if any of their children
12242 * want to expand. (To see if a widget will automatically expand given
12243 * its current children and state, call gtk_widget_compute_expand(). A
12244 * container can decide how the expandability of children affects the
12245 * expansion of the container by overriding the compute_expand virtual
12246 * method on #GtkWidget.).
12248 * Setting hexpand explicitly with this function will override the
12249 * automatic expand behavior.
12251 * This function forces the widget to expand or not to expand,
12252 * regardless of children. The override occurs because
12253 * gtk_widget_set_hexpand() sets the hexpand-set property (see
12254 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
12255 * value to be used, rather than looking at children and widget state.
12258 gtk_widget_set_hexpand (GtkWidget *widget,
12261 g_return_if_fail (GTK_IS_WIDGET (widget));
12263 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
12267 * gtk_widget_get_hexpand_set:
12268 * @widget: the widget
12270 * Gets whether gtk_widget_set_hexpand() has been used to
12271 * explicitly set the expand flag on this widget.
12273 * If hexpand is set, then it overrides any computed
12274 * expand value based on child widgets. If hexpand is not
12275 * set, then the expand value depends on whether any
12276 * children of the widget would like to expand.
12278 * There are few reasons to use this function, but it's here
12279 * for completeness and consistency.
12281 * Return value: whether hexpand has been explicitly set
12284 gtk_widget_get_hexpand_set (GtkWidget *widget)
12286 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12288 return widget->priv->hexpand_set;
12292 * gtk_widget_set_hexpand_set:
12293 * @widget: the widget
12294 * @set: value for hexpand-set property
12296 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
12299 * The hexpand-set property will be set automatically when you call
12300 * gtk_widget_set_hexpand() to set hexpand, so the most likely
12301 * reason to use this function would be to unset an explicit expand
12304 * If hexpand is set, then it overrides any computed
12305 * expand value based on child widgets. If hexpand is not
12306 * set, then the expand value depends on whether any
12307 * children of the widget would like to expand.
12309 * There are few reasons to use this function, but it's here
12310 * for completeness and consistency.
12313 gtk_widget_set_hexpand_set (GtkWidget *widget,
12316 g_return_if_fail (GTK_IS_WIDGET (widget));
12318 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
12323 * gtk_widget_get_vexpand:
12324 * @widget: the widget
12326 * Gets whether the widget would like any available extra vertical
12329 * See gtk_widget_get_hexpand() for more detail.
12331 * Return value: whether vexpand flag is set
12334 gtk_widget_get_vexpand (GtkWidget *widget)
12336 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12338 return widget->priv->vexpand;
12342 * gtk_widget_set_vexpand:
12343 * @widget: the widget
12344 * @expand: whether to expand
12346 * Sets whether the widget would like any available extra vertical
12349 * See gtk_widget_set_hexpand() for more detail.
12352 gtk_widget_set_vexpand (GtkWidget *widget,
12355 g_return_if_fail (GTK_IS_WIDGET (widget));
12357 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12361 * gtk_widget_get_vexpand_set:
12362 * @widget: the widget
12364 * Gets whether gtk_widget_set_vexpand() has been used to
12365 * explicitly set the expand flag on this widget.
12367 * See gtk_widget_get_hexpand_set() for more detail.
12369 * Return value: whether vexpand has been explicitly set
12372 gtk_widget_get_vexpand_set (GtkWidget *widget)
12374 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12376 return widget->priv->vexpand_set;
12380 * gtk_widget_set_vexpand_set:
12381 * @widget: the widget
12382 * @set: value for vexpand-set property
12384 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12387 * See gtk_widget_set_hexpand_set() for more detail.
12390 gtk_widget_set_vexpand_set (GtkWidget *widget,
12393 g_return_if_fail (GTK_IS_WIDGET (widget));
12395 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12399 * GtkBuildable implementation
12401 static GQuark quark_builder_has_default = 0;
12402 static GQuark quark_builder_has_focus = 0;
12403 static GQuark quark_builder_atk_relations = 0;
12404 static GQuark quark_builder_set_name = 0;
12407 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12409 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12410 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12411 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12412 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12414 iface->set_name = gtk_widget_buildable_set_name;
12415 iface->get_name = gtk_widget_buildable_get_name;
12416 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12417 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12418 iface->parser_finished = gtk_widget_buildable_parser_finished;
12419 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12420 iface->custom_finished = gtk_widget_buildable_custom_finished;
12424 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12427 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12428 g_strdup (name), g_free);
12431 static const gchar *
12432 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12434 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12438 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12439 GtkBuilder *builder,
12440 const gchar *childname)
12442 if (strcmp (childname, "accessible") == 0)
12443 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12449 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12450 GtkBuilder *builder,
12452 const GValue *value)
12454 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12455 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12456 GINT_TO_POINTER (TRUE));
12457 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12458 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12459 GINT_TO_POINTER (TRUE));
12461 g_object_set_property (G_OBJECT (buildable), name, value);
12466 gchar *action_name;
12467 GString *description;
12469 gboolean translatable;
12479 free_action (AtkActionData *data, gpointer user_data)
12481 g_free (data->action_name);
12482 g_string_free (data->description, TRUE);
12483 g_free (data->context);
12484 g_slice_free (AtkActionData, data);
12488 free_relation (AtkRelationData *data, gpointer user_data)
12490 g_free (data->target);
12491 g_free (data->type);
12492 g_slice_free (AtkRelationData, data);
12496 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12497 GtkBuilder *builder)
12499 GSList *atk_relations;
12501 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12502 gtk_widget_grab_default (GTK_WIDGET (buildable));
12503 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12504 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12506 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12507 quark_builder_atk_relations);
12510 AtkObject *accessible;
12511 AtkRelationSet *relation_set;
12514 AtkRelationType relation_type;
12515 AtkObject *target_accessible;
12517 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12518 relation_set = atk_object_ref_relation_set (accessible);
12520 for (l = atk_relations; l; l = l->next)
12522 AtkRelationData *relation = (AtkRelationData*)l->data;
12524 target = gtk_builder_get_object (builder, relation->target);
12527 g_warning ("Target object %s in <relation> does not exist",
12531 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12532 g_assert (target_accessible != NULL);
12534 relation_type = atk_relation_type_for_name (relation->type);
12535 if (relation_type == ATK_RELATION_NULL)
12537 g_warning ("<relation> type %s not found",
12541 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12542 target_accessible);
12544 g_object_unref (relation_set);
12546 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
12547 g_slist_free (atk_relations);
12548 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12557 } AccessibilitySubParserData;
12560 accessibility_start_element (GMarkupParseContext *context,
12561 const gchar *element_name,
12562 const gchar **names,
12563 const gchar **values,
12564 gpointer user_data,
12567 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12569 gint line_number, char_number;
12571 if (strcmp (element_name, "relation") == 0)
12573 gchar *target = NULL;
12574 gchar *type = NULL;
12575 AtkRelationData *relation;
12577 for (i = 0; names[i]; i++)
12579 if (strcmp (names[i], "target") == 0)
12580 target = g_strdup (values[i]);
12581 else if (strcmp (names[i], "type") == 0)
12582 type = g_strdup (values[i]);
12585 g_markup_parse_context_get_position (context,
12588 g_set_error (error,
12590 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12591 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12593 line_number, char_number, names[i], "relation");
12600 if (!target || !type)
12602 g_markup_parse_context_get_position (context,
12605 g_set_error (error,
12607 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12608 "%s:%d:%d <%s> requires attribute \"%s\"",
12610 line_number, char_number, "relation",
12611 type ? "target" : "type");
12617 relation = g_slice_new (AtkRelationData);
12618 relation->target = target;
12619 relation->type = type;
12621 data->relations = g_slist_prepend (data->relations, relation);
12623 else if (strcmp (element_name, "action") == 0)
12625 const gchar *action_name = NULL;
12626 const gchar *description = NULL;
12627 const gchar *msg_context = NULL;
12628 gboolean translatable = FALSE;
12629 AtkActionData *action;
12631 for (i = 0; names[i]; i++)
12633 if (strcmp (names[i], "action_name") == 0)
12634 action_name = values[i];
12635 else if (strcmp (names[i], "description") == 0)
12636 description = values[i];
12637 else if (strcmp (names[i], "translatable") == 0)
12639 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12642 else if (strcmp (names[i], "comments") == 0)
12644 /* do nothing, comments are for translators */
12646 else if (strcmp (names[i], "context") == 0)
12647 msg_context = values[i];
12650 g_markup_parse_context_get_position (context,
12653 g_set_error (error,
12655 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12656 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12658 line_number, char_number, names[i], "action");
12665 g_markup_parse_context_get_position (context,
12668 g_set_error (error,
12670 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12671 "%s:%d:%d <%s> requires attribute \"%s\"",
12673 line_number, char_number, "action",
12678 action = g_slice_new (AtkActionData);
12679 action->action_name = g_strdup (action_name);
12680 action->description = g_string_new (description);
12681 action->context = g_strdup (msg_context);
12682 action->translatable = translatable;
12684 data->actions = g_slist_prepend (data->actions, action);
12686 else if (strcmp (element_name, "accessibility") == 0)
12689 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12693 accessibility_text (GMarkupParseContext *context,
12696 gpointer user_data,
12699 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12701 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12703 AtkActionData *action = data->actions->data;
12705 g_string_append_len (action->description, text, text_len);
12709 static const GMarkupParser accessibility_parser =
12711 accessibility_start_element,
12713 accessibility_text,
12722 } AccelGroupParserData;
12725 accel_group_start_element (GMarkupParseContext *context,
12726 const gchar *element_name,
12727 const gchar **names,
12728 const gchar **values,
12729 gpointer user_data,
12734 guint modifiers = 0;
12735 gchar *signal = NULL;
12736 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12738 for (i = 0; names[i]; i++)
12740 if (strcmp (names[i], "key") == 0)
12741 key = gdk_keyval_from_name (values[i]);
12742 else if (strcmp (names[i], "modifiers") == 0)
12744 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12750 else if (strcmp (names[i], "signal") == 0)
12751 signal = g_strdup (values[i]);
12754 if (key == 0 || signal == NULL)
12756 g_warning ("<accelerator> requires key and signal attributes");
12759 parser_data->key = key;
12760 parser_data->modifiers = modifiers;
12761 parser_data->signal = signal;
12764 static const GMarkupParser accel_group_parser =
12766 accel_group_start_element,
12775 style_start_element (GMarkupParseContext *context,
12776 const gchar *element_name,
12777 const gchar **names,
12778 const gchar **values,
12779 gpointer user_data,
12782 StyleParserData *style_data = (StyleParserData *)user_data;
12785 if (strcmp (element_name, "class") == 0)
12787 if (g_markup_collect_attributes (element_name,
12791 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12792 G_MARKUP_COLLECT_INVALID))
12794 style_data->classes = g_slist_append (style_data->classes, class_name);
12797 else if (strcmp (element_name, "style") == 0)
12800 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12803 static const GMarkupParser style_parser =
12805 style_start_element,
12809 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12810 GtkBuilder *builder,
12812 const gchar *tagname,
12813 GMarkupParser *parser,
12816 g_assert (buildable);
12818 if (strcmp (tagname, "accelerator") == 0)
12820 AccelGroupParserData *parser_data;
12822 parser_data = g_slice_new0 (AccelGroupParserData);
12823 parser_data->object = g_object_ref (buildable);
12824 *parser = accel_group_parser;
12825 *data = parser_data;
12828 if (strcmp (tagname, "accessibility") == 0)
12830 AccessibilitySubParserData *parser_data;
12832 parser_data = g_slice_new0 (AccessibilitySubParserData);
12833 *parser = accessibility_parser;
12834 *data = parser_data;
12837 if (strcmp (tagname, "style") == 0)
12839 StyleParserData *parser_data;
12841 parser_data = g_slice_new0 (StyleParserData);
12842 *parser = style_parser;
12843 *data = parser_data;
12851 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12852 GtkWidget *toplevel,
12853 gpointer user_data)
12855 AccelGroupParserData *accel_data;
12856 GSList *accel_groups;
12857 GtkAccelGroup *accel_group;
12859 g_return_if_fail (GTK_IS_WIDGET (widget));
12860 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12861 g_return_if_fail (user_data != NULL);
12863 accel_data = (AccelGroupParserData*)user_data;
12864 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12865 if (g_slist_length (accel_groups) == 0)
12867 accel_group = gtk_accel_group_new ();
12868 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12872 g_assert (g_slist_length (accel_groups) == 1);
12873 accel_group = g_slist_nth_data (accel_groups, 0);
12876 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12877 accel_data->signal,
12880 accel_data->modifiers,
12881 GTK_ACCEL_VISIBLE);
12883 g_object_unref (accel_data->object);
12884 g_free (accel_data->signal);
12885 g_slice_free (AccelGroupParserData, accel_data);
12889 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12890 GtkBuilder *builder,
12892 const gchar *tagname,
12893 gpointer user_data)
12895 if (strcmp (tagname, "accelerator") == 0)
12897 AccelGroupParserData *accel_data;
12898 GtkWidget *toplevel;
12900 accel_data = (AccelGroupParserData*)user_data;
12901 g_assert (accel_data->object);
12903 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12905 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12907 else if (strcmp (tagname, "accessibility") == 0)
12909 AccessibilitySubParserData *a11y_data;
12911 a11y_data = (AccessibilitySubParserData*)user_data;
12913 if (a11y_data->actions)
12915 AtkObject *accessible;
12920 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12922 if (ATK_IS_ACTION (accessible))
12924 action = ATK_ACTION (accessible);
12925 n_actions = atk_action_get_n_actions (action);
12927 for (l = a11y_data->actions; l; l = l->next)
12929 AtkActionData *action_data = (AtkActionData*)l->data;
12931 for (i = 0; i < n_actions; i++)
12932 if (strcmp (atk_action_get_name (action, i),
12933 action_data->action_name) == 0)
12938 gchar *description;
12940 if (action_data->translatable && action_data->description->len)
12941 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12942 action_data->context,
12943 action_data->description->str);
12945 description = action_data->description->str;
12947 atk_action_set_description (action, i, description);
12952 g_warning ("accessibility action on a widget that does not implement AtkAction");
12954 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
12955 g_slist_free (a11y_data->actions);
12958 if (a11y_data->relations)
12959 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12960 a11y_data->relations);
12962 g_slice_free (AccessibilitySubParserData, a11y_data);
12964 else if (strcmp (tagname, "style") == 0)
12966 StyleParserData *style_data = (StyleParserData *)user_data;
12967 GtkStyleContext *context;
12970 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
12972 for (l = style_data->classes; l; l = l->next)
12973 gtk_style_context_add_class (context, (const gchar *)l->data);
12975 gtk_widget_reset_style (GTK_WIDGET (buildable));
12977 g_slist_free_full (style_data->classes, g_free);
12978 g_slice_free (StyleParserData, style_data);
12982 static GtkSizeRequestMode
12983 gtk_widget_real_get_request_mode (GtkWidget *widget)
12985 /* By default widgets dont trade size at all. */
12986 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
12990 gtk_widget_real_get_width (GtkWidget *widget,
12991 gint *minimum_size,
12992 gint *natural_size)
13002 gtk_widget_real_get_height (GtkWidget *widget,
13003 gint *minimum_size,
13004 gint *natural_size)
13014 gtk_widget_real_get_height_for_width (GtkWidget *widget,
13016 gint *minimum_height,
13017 gint *natural_height)
13019 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
13023 gtk_widget_real_get_width_for_height (GtkWidget *widget,
13025 gint *minimum_width,
13026 gint *natural_width)
13028 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
13032 * gtk_widget_get_halign:
13033 * @widget: a #GtkWidget
13035 * Gets the value of the #GtkWidget:halign property.
13037 * Returns: the horizontal alignment of @widget
13040 gtk_widget_get_halign (GtkWidget *widget)
13042 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
13043 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
13047 * gtk_widget_set_halign:
13048 * @widget: a #GtkWidget
13049 * @align: the horizontal alignment
13051 * Sets the horizontal alignment of @widget.
13052 * See the #GtkWidget:halign property.
13055 gtk_widget_set_halign (GtkWidget *widget,
13058 GtkWidgetAuxInfo *aux_info;
13060 g_return_if_fail (GTK_IS_WIDGET (widget));
13062 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
13064 if (aux_info->halign == align)
13067 aux_info->halign = align;
13068 gtk_widget_queue_resize (widget);
13069 g_object_notify (G_OBJECT (widget), "halign");
13073 * gtk_widget_get_valign:
13074 * @widget: a #GtkWidget
13076 * Gets the value of the #GtkWidget:valign property.
13078 * Returns: the vertical alignment of @widget
13081 gtk_widget_get_valign (GtkWidget *widget)
13083 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
13084 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
13088 * gtk_widget_set_valign:
13089 * @widget: a #GtkWidget
13090 * @align: the vertical alignment
13092 * Sets the vertical alignment of @widget.
13093 * See the #GtkWidget:valign property.
13096 gtk_widget_set_valign (GtkWidget *widget,
13099 GtkWidgetAuxInfo *aux_info;
13101 g_return_if_fail (GTK_IS_WIDGET (widget));
13103 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
13105 if (aux_info->valign == align)
13108 aux_info->valign = align;
13109 gtk_widget_queue_resize (widget);
13110 g_object_notify (G_OBJECT (widget), "valign");
13114 * gtk_widget_get_margin_left:
13115 * @widget: a #GtkWidget
13117 * Gets the value of the #GtkWidget:margin-left property.
13119 * Returns: The left margin of @widget
13122 gtk_widget_get_margin_left (GtkWidget *widget)
13124 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13126 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
13130 * gtk_widget_set_margin_left:
13131 * @widget: a #GtkWidget
13132 * @margin: the left margin
13134 * Sets the left margin of @widget.
13135 * See the #GtkWidget:margin-left property.
13138 gtk_widget_set_margin_left (GtkWidget *widget,
13141 GtkWidgetAuxInfo *aux_info;
13143 g_return_if_fail (GTK_IS_WIDGET (widget));
13144 g_return_if_fail (margin <= G_MAXINT16);
13146 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
13148 if (aux_info->margin.left == margin)
13151 aux_info->margin.left = margin;
13152 gtk_widget_queue_resize (widget);
13153 g_object_notify (G_OBJECT (widget), "margin-left");
13157 * gtk_widget_get_margin_right:
13158 * @widget: a #GtkWidget
13160 * Gets the value of the #GtkWidget:margin-right property.
13162 * Returns: The left margin of @widget
13165 gtk_widget_get_margin_right (GtkWidget *widget)
13167 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13169 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
13173 * gtk_widget_set_margin_right:
13174 * @widget: a #GtkWidget
13175 * @margin: the right margin
13177 * Sets the right margin of @widget.
13178 * See the #GtkWidget:margin-right property.
13181 gtk_widget_set_margin_right (GtkWidget *widget,
13184 GtkWidgetAuxInfo *aux_info;
13186 g_return_if_fail (GTK_IS_WIDGET (widget));
13187 g_return_if_fail (margin <= G_MAXINT16);
13189 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
13191 if (aux_info->margin.right == margin)
13194 aux_info->margin.right = margin;
13195 gtk_widget_queue_resize (widget);
13196 g_object_notify (G_OBJECT (widget), "margin-right");
13200 * gtk_widget_get_margin_top:
13201 * @widget: a #GtkWidget
13203 * Gets the value of the #GtkWidget:margin-top property.
13205 * Returns: The top margin of @widget
13208 gtk_widget_get_margin_top (GtkWidget *widget)
13210 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13212 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
13216 * gtk_widget_set_margin_top:
13217 * @widget: a #GtkWidget
13218 * @margin: the top margin
13220 * Sets the top margin of @widget.
13221 * See the #GtkWidget:margin-top property.
13224 gtk_widget_set_margin_top (GtkWidget *widget,
13227 GtkWidgetAuxInfo *aux_info;
13229 g_return_if_fail (GTK_IS_WIDGET (widget));
13230 g_return_if_fail (margin <= G_MAXINT16);
13232 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
13234 if (aux_info->margin.top == margin)
13237 aux_info->margin.top = margin;
13238 gtk_widget_queue_resize (widget);
13239 g_object_notify (G_OBJECT (widget), "margin-top");
13243 * gtk_widget_get_margin_bottom:
13244 * @widget: a #GtkWidget
13246 * Gets the value of the #GtkWidget:margin-bottom property.
13248 * Returns: The bottom margin of @widget
13251 gtk_widget_get_margin_bottom (GtkWidget *widget)
13253 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13255 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
13259 * gtk_widget_set_margin_bottom:
13260 * @widget: a #GtkWidget
13261 * @margin: the bottom margin
13263 * Sets the bottom margin of @widget.
13264 * See the #GtkWidget:margin-bottom property.
13267 gtk_widget_set_margin_bottom (GtkWidget *widget,
13270 GtkWidgetAuxInfo *aux_info;
13272 g_return_if_fail (GTK_IS_WIDGET (widget));
13273 g_return_if_fail (margin <= G_MAXINT16);
13275 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
13277 if (aux_info->margin.bottom == margin)
13280 aux_info->margin.bottom = margin;
13281 gtk_widget_queue_resize (widget);
13282 g_object_notify (G_OBJECT (widget), "margin-bottom");
13286 * gtk_widget_get_clipboard:
13287 * @widget: a #GtkWidget
13288 * @selection: a #GdkAtom which identifies the clipboard
13289 * to use. %GDK_SELECTION_CLIPBOARD gives the
13290 * default clipboard. Another common value
13291 * is %GDK_SELECTION_PRIMARY, which gives
13292 * the primary X selection.
13294 * Returns the clipboard object for the given selection to
13295 * be used with @widget. @widget must have a #GdkDisplay
13296 * associated with it, so must be attached to a toplevel
13299 * Return value: (transfer none): the appropriate clipboard object. If no
13300 * clipboard already exists, a new one will
13301 * be created. Once a clipboard object has
13302 * been created, it is persistent for all time.
13307 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
13309 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13310 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
13312 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
13317 * gtk_widget_list_mnemonic_labels:
13318 * @widget: a #GtkWidget
13320 * Returns a newly allocated list of the widgets, normally labels, for
13321 * which this widget is the target of a mnemonic (see for example,
13322 * gtk_label_set_mnemonic_widget()).
13324 * The widgets in the list are not individually referenced. If you
13325 * want to iterate through the list and perform actions involving
13326 * callbacks that might destroy the widgets, you
13327 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
13328 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
13329 * widgets afterwards.
13331 * Return value: (element-type GtkWidget) (transfer container): the list of
13332 * mnemonic labels; free this list
13333 * with g_list_free() when you are done with it.
13338 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
13340 GList *list = NULL;
13343 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13345 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13346 list = g_list_prepend (list, l->data);
13352 * gtk_widget_add_mnemonic_label:
13353 * @widget: a #GtkWidget
13354 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13356 * Adds a widget to the list of mnemonic labels for
13357 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13358 * list of mnemonic labels for the widget is cleared when the
13359 * widget is destroyed, so the caller must make sure to update
13360 * its internal state at this point as well, by using a connection
13361 * to the #GtkWidget::destroy signal or a weak notifier.
13366 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13369 GSList *old_list, *new_list;
13371 g_return_if_fail (GTK_IS_WIDGET (widget));
13372 g_return_if_fail (GTK_IS_WIDGET (label));
13374 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13375 new_list = g_slist_prepend (old_list, label);
13377 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13378 new_list, (GDestroyNotify) g_slist_free);
13382 * gtk_widget_remove_mnemonic_label:
13383 * @widget: a #GtkWidget
13384 * @label: a #GtkWidget that was previously set as a mnemnic label for
13385 * @widget with gtk_widget_add_mnemonic_label().
13387 * Removes a widget from the list of mnemonic labels for
13388 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13389 * must have previously been added to the list with
13390 * gtk_widget_add_mnemonic_label().
13395 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13398 GSList *old_list, *new_list;
13400 g_return_if_fail (GTK_IS_WIDGET (widget));
13401 g_return_if_fail (GTK_IS_WIDGET (label));
13403 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13404 new_list = g_slist_remove (old_list, label);
13407 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13408 new_list, (GDestroyNotify) g_slist_free);
13412 * gtk_widget_get_no_show_all:
13413 * @widget: a #GtkWidget
13415 * Returns the current value of the #GtkWidget:no-show-all property,
13416 * which determines whether calls to gtk_widget_show_all()
13417 * will affect this widget.
13419 * Return value: the current value of the "no-show-all" property.
13424 gtk_widget_get_no_show_all (GtkWidget *widget)
13426 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13428 return widget->priv->no_show_all;
13432 * gtk_widget_set_no_show_all:
13433 * @widget: a #GtkWidget
13434 * @no_show_all: the new value for the "no-show-all" property
13436 * Sets the #GtkWidget:no-show-all property, which determines whether
13437 * calls to gtk_widget_show_all() will affect this widget.
13439 * This is mostly for use in constructing widget hierarchies with externally
13440 * controlled visibility, see #GtkUIManager.
13445 gtk_widget_set_no_show_all (GtkWidget *widget,
13446 gboolean no_show_all)
13448 g_return_if_fail (GTK_IS_WIDGET (widget));
13450 no_show_all = (no_show_all != FALSE);
13452 if (widget->priv->no_show_all != no_show_all)
13454 widget->priv->no_show_all = no_show_all;
13456 g_object_notify (G_OBJECT (widget), "no-show-all");
13462 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13463 gboolean has_tooltip,
13466 GtkWidgetPrivate *priv = widget->priv;
13467 gboolean priv_has_tooltip;
13469 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13470 quark_has_tooltip));
13472 if (priv_has_tooltip != has_tooltip || force)
13474 priv_has_tooltip = has_tooltip;
13476 if (priv_has_tooltip)
13478 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13479 gdk_window_set_events (priv->window,
13480 gdk_window_get_events (priv->window) |
13481 GDK_LEAVE_NOTIFY_MASK |
13482 GDK_POINTER_MOTION_MASK |
13483 GDK_POINTER_MOTION_HINT_MASK);
13485 if (gtk_widget_get_has_window (widget))
13486 gtk_widget_add_events (widget,
13487 GDK_LEAVE_NOTIFY_MASK |
13488 GDK_POINTER_MOTION_MASK |
13489 GDK_POINTER_MOTION_HINT_MASK);
13492 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13493 GUINT_TO_POINTER (priv_has_tooltip));
13498 * gtk_widget_set_tooltip_window:
13499 * @widget: a #GtkWidget
13500 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13502 * Replaces the default, usually yellow, window used for displaying
13503 * tooltips with @custom_window. GTK+ will take care of showing and
13504 * hiding @custom_window at the right moment, to behave likewise as
13505 * the default tooltip window. If @custom_window is %NULL, the default
13506 * tooltip window will be used.
13508 * If the custom window should have the default theming it needs to
13509 * have the name "gtk-tooltip", see gtk_widget_set_name().
13514 gtk_widget_set_tooltip_window (GtkWidget *widget,
13515 GtkWindow *custom_window)
13517 gboolean has_tooltip;
13518 gchar *tooltip_markup;
13520 g_return_if_fail (GTK_IS_WIDGET (widget));
13521 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13523 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13526 g_object_ref (custom_window);
13528 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13529 custom_window, g_object_unref);
13531 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13532 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13534 if (has_tooltip && gtk_widget_get_visible (widget))
13535 gtk_widget_queue_tooltip_query (widget);
13539 * gtk_widget_get_tooltip_window:
13540 * @widget: a #GtkWidget
13542 * Returns the #GtkWindow of the current tooltip. This can be the
13543 * GtkWindow created by default, or the custom tooltip window set
13544 * using gtk_widget_set_tooltip_window().
13546 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13551 gtk_widget_get_tooltip_window (GtkWidget *widget)
13553 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13555 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13559 * gtk_widget_trigger_tooltip_query:
13560 * @widget: a #GtkWidget
13562 * Triggers a tooltip query on the display where the toplevel of @widget
13563 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13569 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13571 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13574 static guint tooltip_query_id;
13575 static GSList *tooltip_query_displays;
13578 tooltip_query_idle (gpointer data)
13580 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13581 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13582 g_slist_free (tooltip_query_displays);
13584 tooltip_query_displays = NULL;
13585 tooltip_query_id = 0;
13591 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13593 GdkDisplay *display;
13595 display = gtk_widget_get_display (widget);
13597 if (!g_slist_find (tooltip_query_displays, display))
13598 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13600 if (tooltip_query_id == 0)
13601 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13605 * gtk_widget_set_tooltip_text:
13606 * @widget: a #GtkWidget
13607 * @text: the contents of the tooltip for @widget
13609 * Sets @text as the contents of the tooltip. This function will take
13610 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13611 * handler for the #GtkWidget::query-tooltip signal.
13613 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13618 gtk_widget_set_tooltip_text (GtkWidget *widget,
13621 g_return_if_fail (GTK_IS_WIDGET (widget));
13623 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13627 * gtk_widget_get_tooltip_text:
13628 * @widget: a #GtkWidget
13630 * Gets the contents of the tooltip for @widget.
13632 * Return value: the tooltip text, or %NULL. You should free the
13633 * returned string with g_free() when done.
13638 gtk_widget_get_tooltip_text (GtkWidget *widget)
13640 gchar *text = NULL;
13642 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13644 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13650 * gtk_widget_set_tooltip_markup:
13651 * @widget: a #GtkWidget
13652 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13654 * Sets @markup as the contents of the tooltip, which is marked up with
13655 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13657 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13658 * and of the default handler for the #GtkWidget::query-tooltip signal.
13660 * See also the #GtkWidget:tooltip-markup property and
13661 * gtk_tooltip_set_markup().
13666 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13667 const gchar *markup)
13669 g_return_if_fail (GTK_IS_WIDGET (widget));
13671 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13675 * gtk_widget_get_tooltip_markup:
13676 * @widget: a #GtkWidget
13678 * Gets the contents of the tooltip for @widget.
13680 * Return value: the tooltip text, or %NULL. You should free the
13681 * returned string with g_free() when done.
13686 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13688 gchar *text = NULL;
13690 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13692 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13698 * gtk_widget_set_has_tooltip:
13699 * @widget: a #GtkWidget
13700 * @has_tooltip: whether or not @widget has a tooltip.
13702 * Sets the has-tooltip property on @widget to @has_tooltip. See
13703 * #GtkWidget:has-tooltip for more information.
13708 gtk_widget_set_has_tooltip (GtkWidget *widget,
13709 gboolean has_tooltip)
13711 g_return_if_fail (GTK_IS_WIDGET (widget));
13713 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13717 * gtk_widget_get_has_tooltip:
13718 * @widget: a #GtkWidget
13720 * Returns the current value of the has-tooltip property. See
13721 * #GtkWidget:has-tooltip for more information.
13723 * Return value: current value of has-tooltip on @widget.
13728 gtk_widget_get_has_tooltip (GtkWidget *widget)
13730 gboolean has_tooltip = FALSE;
13732 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13734 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13736 return has_tooltip;
13740 * gtk_widget_get_allocation:
13741 * @widget: a #GtkWidget
13742 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13744 * Retrieves the widget's allocation.
13746 * Note, when implementing a #GtkContainer: a widget's allocation will
13747 * be its "adjusted" allocation, that is, the widget's parent
13748 * container typically calls gtk_widget_size_allocate() with an
13749 * allocation, and that allocation is then adjusted (to handle margin
13750 * and alignment for example) before assignment to the widget.
13751 * gtk_widget_get_allocation() returns the adjusted allocation that
13752 * was actually assigned to the widget. The adjusted allocation is
13753 * guaranteed to be completely contained within the
13754 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13755 * is guaranteed that its children stay inside the assigned bounds,
13756 * but not that they have exactly the bounds the container assigned.
13757 * There is no way to get the original allocation assigned by
13758 * gtk_widget_size_allocate(), since it isn't stored; if a container
13759 * implementation needs that information it will have to track it itself.
13764 gtk_widget_get_allocation (GtkWidget *widget,
13765 GtkAllocation *allocation)
13767 GtkWidgetPrivate *priv;
13769 g_return_if_fail (GTK_IS_WIDGET (widget));
13770 g_return_if_fail (allocation != NULL);
13772 priv = widget->priv;
13774 *allocation = priv->allocation;
13778 * gtk_widget_set_allocation:
13779 * @widget: a #GtkWidget
13780 * @allocation: a pointer to a #GtkAllocation to copy from
13782 * Sets the widget's allocation. This should not be used
13783 * directly, but from within a widget's size_allocate method.
13785 * The allocation set should be the "adjusted" or actual
13786 * allocation. If you're implementing a #GtkContainer, you want to use
13787 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13788 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13789 * allocation inside gtk_widget_size_allocate() to create an adjusted
13795 gtk_widget_set_allocation (GtkWidget *widget,
13796 const GtkAllocation *allocation)
13798 GtkWidgetPrivate *priv;
13800 g_return_if_fail (GTK_IS_WIDGET (widget));
13801 g_return_if_fail (allocation != NULL);
13803 priv = widget->priv;
13805 priv->allocation = *allocation;
13809 * gtk_widget_get_allocated_width:
13810 * @widget: the widget to query
13812 * Returns the width that has currently been allocated to @widget.
13813 * This function is intended to be used when implementing handlers
13814 * for the #GtkWidget::draw function.
13816 * Returns: the width of the @widget
13819 gtk_widget_get_allocated_width (GtkWidget *widget)
13821 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13823 return widget->priv->allocation.width;
13827 * gtk_widget_get_allocated_height:
13828 * @widget: the widget to query
13830 * Returns the height that has currently been allocated to @widget.
13831 * This function is intended to be used when implementing handlers
13832 * for the #GtkWidget::draw function.
13834 * Returns: the height of the @widget
13837 gtk_widget_get_allocated_height (GtkWidget *widget)
13839 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13841 return widget->priv->allocation.height;
13845 * gtk_widget_get_requisition:
13846 * @widget: a #GtkWidget
13847 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13849 * Retrieves the widget's requisition.
13851 * This function should only be used by widget implementations in
13852 * order to figure whether the widget's requisition has actually
13853 * changed after some internal state change (so that they can call
13854 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13856 * Normally, gtk_widget_size_request() should be used.
13860 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13861 * removed, If you need to cache sizes across requests and allocations,
13862 * add an explicit cache to the widget in question instead.
13865 gtk_widget_get_requisition (GtkWidget *widget,
13866 GtkRequisition *requisition)
13868 g_return_if_fail (GTK_IS_WIDGET (widget));
13869 g_return_if_fail (requisition != NULL);
13871 gtk_widget_get_preferred_size (widget, requisition, NULL);
13875 * gtk_widget_set_window:
13876 * @widget: a #GtkWidget
13877 * @window: a #GdkWindow
13879 * Sets a widget's window. This function should only be used in a
13880 * widget's #GtkWidget::realize implementation. The %window passed is
13881 * usually either new window created with gdk_window_new(), or the
13882 * window of its parent widget as returned by
13883 * gtk_widget_get_parent_window().
13885 * Widgets must indicate whether they will create their own #GdkWindow
13886 * by calling gtk_widget_set_has_window(). This is usually done in the
13887 * widget's init() function.
13889 * <note><para>This function does not add any reference to @window.</para></note>
13894 gtk_widget_set_window (GtkWidget *widget,
13897 GtkWidgetPrivate *priv;
13899 g_return_if_fail (GTK_IS_WIDGET (widget));
13900 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13902 priv = widget->priv;
13904 if (priv->window != window)
13906 priv->window = window;
13907 g_object_notify (G_OBJECT (widget), "window");
13912 * gtk_widget_get_window:
13913 * @widget: a #GtkWidget
13915 * Returns the widget's window if it is realized, %NULL otherwise
13917 * Return value: (transfer none): @widget's window.
13922 gtk_widget_get_window (GtkWidget *widget)
13924 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13926 return widget->priv->window;
13930 * gtk_widget_get_support_multidevice:
13931 * @widget: a #GtkWidget
13933 * Returns %TRUE if @widget is multiple pointer aware. See
13934 * gtk_widget_set_support_multidevice() for more information.
13936 * Returns: %TRUE if @widget is multidevice aware.
13939 gtk_widget_get_support_multidevice (GtkWidget *widget)
13941 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13943 return widget->priv->multidevice;
13947 * gtk_widget_set_support_multidevice:
13948 * @widget: a #GtkWidget
13949 * @support_multidevice: %TRUE to support input from multiple devices.
13951 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13952 * @widget will start receiving multiple, per device enter/leave events. Note
13953 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13954 * gdk_window_set_support_multidevice() will have to be called manually on them.
13959 gtk_widget_set_support_multidevice (GtkWidget *widget,
13960 gboolean support_multidevice)
13962 GtkWidgetPrivate *priv;
13964 g_return_if_fail (GTK_IS_WIDGET (widget));
13966 priv = widget->priv;
13967 priv->multidevice = (support_multidevice == TRUE);
13969 if (gtk_widget_get_realized (widget))
13970 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13974 _gtk_widget_set_has_focus (GtkWidget *widget,
13975 gboolean has_focus)
13977 widget->priv->has_focus = has_focus;
13980 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
13982 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
13986 * gtk_widget_send_focus_change:
13987 * @widget: a #GtkWidget
13988 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13990 * Sends the focus change @event to @widget
13992 * This function is not meant to be used by applications. The only time it
13993 * should be used is when it is necessary for a #GtkWidget to assign focus
13994 * to a widget that is semantically owned by the first widget even though
13995 * it's not a direct child - for instance, a search entry in a floating
13996 * window similar to the quick search in #GtkTreeView.
13998 * An example of its usage is:
14001 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
14003 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
14004 * fevent->focus_change.in = TRUE;
14005 * fevent->focus_change.window = gtk_widget_get_window (widget);
14006 * if (fevent->focus_change.window != NULL)
14007 * g_object_ref (fevent->focus_change.window);
14009 * gtk_widget_send_focus_change (widget, fevent);
14011 * gdk_event_free (event);
14014 * Return value: the return value from the event signal emission: %TRUE
14015 * if the event was handled, and %FALSE otherwise
14020 gtk_widget_send_focus_change (GtkWidget *widget,
14025 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
14026 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
14028 g_object_ref (widget);
14030 _gtk_widget_set_has_focus (widget, event->focus_change.in);
14032 res = gtk_widget_event (widget, event);
14034 g_object_notify (G_OBJECT (widget), "has-focus");
14036 g_object_unref (widget);
14042 * gtk_widget_in_destruction:
14043 * @widget: a #GtkWidget
14045 * Returns whether the widget is currently being destroyed.
14046 * This information can sometimes be used to avoid doing
14047 * unnecessary work.
14049 * Returns: %TRUE if @widget is being destroyed
14052 gtk_widget_in_destruction (GtkWidget *widget)
14054 return widget->priv->in_destruction;
14058 _gtk_widget_get_resize_pending (GtkWidget *widget)
14060 return widget->priv->resize_pending;
14064 _gtk_widget_set_resize_pending (GtkWidget *widget,
14065 gboolean resize_pending)
14067 widget->priv->resize_pending = resize_pending;
14071 _gtk_widget_get_in_reparent (GtkWidget *widget)
14073 return widget->priv->in_reparent;
14077 _gtk_widget_set_in_reparent (GtkWidget *widget,
14078 gboolean in_reparent)
14080 widget->priv->in_reparent = in_reparent;
14084 _gtk_widget_get_anchored (GtkWidget *widget)
14086 return widget->priv->anchored;
14090 _gtk_widget_set_anchored (GtkWidget *widget,
14093 widget->priv->anchored = anchored;
14097 _gtk_widget_get_shadowed (GtkWidget *widget)
14099 return widget->priv->shadowed;
14103 _gtk_widget_set_shadowed (GtkWidget *widget,
14106 widget->priv->shadowed = shadowed;
14110 _gtk_widget_get_alloc_needed (GtkWidget *widget)
14112 return widget->priv->alloc_needed;
14116 _gtk_widget_set_alloc_needed (GtkWidget *widget,
14117 gboolean alloc_needed)
14119 widget->priv->alloc_needed = alloc_needed;
14123 _gtk_widget_get_width_request_needed (GtkWidget *widget)
14125 return widget->priv->width_request_needed;
14129 _gtk_widget_set_width_request_needed (GtkWidget *widget,
14130 gboolean width_request_needed)
14132 widget->priv->width_request_needed = width_request_needed;
14136 _gtk_widget_get_height_request_needed (GtkWidget *widget)
14138 return widget->priv->height_request_needed;
14142 _gtk_widget_set_height_request_needed (GtkWidget *widget,
14143 gboolean height_request_needed)
14145 widget->priv->height_request_needed = height_request_needed;
14149 _gtk_widget_get_sizegroup_visited (GtkWidget *widget)
14151 return widget->priv->sizegroup_visited;
14155 _gtk_widget_set_sizegroup_visited (GtkWidget *widget,
14158 widget->priv->sizegroup_visited = visited;
14162 _gtk_widget_get_sizegroup_bumping (GtkWidget *widget)
14164 return widget->priv->sizegroup_bumping;
14168 _gtk_widget_set_sizegroup_bumping (GtkWidget *widget,
14171 widget->priv->sizegroup_bumping = bumping;
14175 _gtk_widget_add_sizegroup (GtkWidget *widget,
14180 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14181 groups = g_slist_prepend (groups, group);
14182 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14184 widget->priv->have_size_groups = TRUE;
14188 _gtk_widget_remove_sizegroup (GtkWidget *widget,
14193 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14194 groups = g_slist_remove (groups, group);
14195 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14197 widget->priv->have_size_groups = groups != NULL;
14201 _gtk_widget_get_sizegroups (GtkWidget *widget)
14203 if (widget->priv->have_size_groups)
14204 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14210 * gtk_widget_get_path:
14211 * @widget: a #GtkWidget
14213 * Returns the #GtkWidgetPath representing @widget, if the widget
14214 * is not connected to a toplevel widget, a partial path will be
14217 * Returns: (transfer none): The #GtkWidgetPath representing @widget
14220 gtk_widget_get_path (GtkWidget *widget)
14222 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14224 /* As strange as it may seem, this may happen on object construction.
14225 * init() implementations of parent types may eventually call this function,
14226 * each with its corresponding GType, which could leave a child
14227 * implementation with a wrong widget type in the widget path
14229 if (widget->priv->path &&
14230 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (widget->priv->path))
14232 gtk_widget_path_free (widget->priv->path);
14233 widget->priv->path = NULL;
14236 if (!widget->priv->path)
14241 parent = widget->priv->parent;
14244 widget->priv->path = gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
14247 /* Widget is either toplevel or unparented, treat both
14248 * as toplevels style wise, since there are situations
14249 * where style properties might be retrieved on that
14252 widget->priv->path = gtk_widget_path_new ();
14255 pos = gtk_widget_path_append_type (widget->priv->path, G_OBJECT_TYPE (widget));
14257 if (widget->priv->name)
14258 gtk_widget_path_iter_set_name (widget->priv->path, pos, widget->priv->name);
14260 if (widget->priv->context)
14262 GList *classes, *l;
14264 /* Also add any persistent classes in
14265 * the style context the widget path
14267 classes = gtk_style_context_list_classes (widget->priv->context);
14269 for (l = classes; l; l = l->next)
14270 gtk_widget_path_iter_add_class (widget->priv->path, pos, l->data);
14272 gtk_style_context_set_path (widget->priv->context,
14273 widget->priv->path);
14275 g_list_free (classes);
14279 return widget->priv->path;
14283 style_context_changed (GtkStyleContext *context,
14284 gpointer user_data)
14286 GtkWidget *widget = user_data;
14288 gtk_widget_update_pango_context (widget);
14290 if (gtk_widget_get_realized (widget))
14291 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
14294 /* Compress all style updates so it
14295 * is only emitted once pre-realize.
14297 widget->priv->style_update_pending = TRUE;
14300 if (widget->priv->anchored)
14301 gtk_widget_queue_resize (widget);
14305 * gtk_widget_get_style_context:
14306 * @widget: a #GtkWidget
14308 * Returns the style context associated to @widget.
14310 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
14311 * must not be freed.
14314 gtk_widget_get_style_context (GtkWidget *widget)
14316 GtkWidgetPrivate *priv;
14317 GtkWidgetPath *path;
14319 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14321 priv = widget->priv;
14323 /* updates style context if it exists already */
14324 path = gtk_widget_get_path (widget);
14326 if (G_UNLIKELY (priv->context == NULL))
14330 priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
14331 "direction", gtk_widget_get_direction (widget),
14334 g_signal_connect (widget->priv->context, "changed",
14335 G_CALLBACK (style_context_changed), widget);
14337 screen = gtk_widget_get_screen (widget);
14340 gtk_style_context_set_screen (priv->context, screen);
14342 gtk_style_context_set_path (priv->context, path);
14345 return widget->priv->context;