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 /* Widget's path for styling */
388 /* The widget's allocated size */
389 GtkAllocation allocation;
391 /* The widget's requested sizes */
392 SizeRequestCache requests;
394 /* The widget's window or its parent window if it does
395 * not have a window. (Which will be indicated by the
396 * GTK_NO_WINDOW flag being set).
400 /* The widget's parent */
403 #ifdef G_ENABLE_DEBUG
404 /* Number of gtk_widget_push_verify_invariants () */
405 guint verifying_invariants_count;
406 #endif /* G_ENABLE_DEBUG */
435 BUTTON_RELEASE_EVENT,
449 PROPERTY_NOTIFY_EVENT,
450 SELECTION_CLEAR_EVENT,
451 SELECTION_REQUEST_EVENT,
452 SELECTION_NOTIFY_EVENT,
457 VISIBILITY_NOTIFY_EVENT,
471 ACCEL_CLOSURES_CHANGED,
495 PROP_RECEIVES_DEFAULT,
496 PROP_COMPOSITE_CHILD,
504 PROP_DOUBLE_BUFFERED,
519 typedef struct _GtkStateData GtkStateData;
522 STATE_CHANGE_REPLACE,
531 guint use_forall : 1;
534 /* --- prototypes --- */
535 static void gtk_widget_class_init (GtkWidgetClass *klass);
536 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
537 static void gtk_widget_init (GtkWidget *widget);
538 static void gtk_widget_set_property (GObject *object,
542 static void gtk_widget_get_property (GObject *object,
546 static void gtk_widget_dispose (GObject *object);
547 static void gtk_widget_real_destroy (GtkWidget *object);
548 static void gtk_widget_finalize (GObject *object);
549 static void gtk_widget_real_show (GtkWidget *widget);
550 static void gtk_widget_real_hide (GtkWidget *widget);
551 static void gtk_widget_real_map (GtkWidget *widget);
552 static void gtk_widget_real_unmap (GtkWidget *widget);
553 static void gtk_widget_real_realize (GtkWidget *widget);
554 static void gtk_widget_real_unrealize (GtkWidget *widget);
555 static void gtk_widget_real_size_allocate (GtkWidget *widget,
556 GtkAllocation *allocation);
557 static void gtk_widget_real_style_set (GtkWidget *widget,
558 GtkStyle *previous_style);
559 static void gtk_widget_real_direction_changed(GtkWidget *widget,
560 GtkTextDirection previous_direction);
562 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
563 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
566 gboolean keyboard_tip,
567 GtkTooltip *tooltip);
568 static void gtk_widget_real_style_updated (GtkWidget *widget);
569 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
570 GtkWidgetHelpType help_type);
572 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
574 GParamSpec **pspecs);
575 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
577 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
579 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
580 GdkEventFocus *event);
581 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
582 GdkEventFocus *event);
583 static gboolean gtk_widget_real_focus (GtkWidget *widget,
584 GtkDirectionType direction);
585 static void gtk_widget_real_move_focus (GtkWidget *widget,
586 GtkDirectionType direction);
587 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
588 GtkDirectionType direction);
589 #ifdef G_ENABLE_DEBUG
590 static void gtk_widget_verify_invariants (GtkWidget *widget);
591 static void gtk_widget_push_verify_invariants (GtkWidget *widget);
592 static void gtk_widget_pop_verify_invariants (GtkWidget *widget);
594 #define gtk_widget_verify_invariants(widget)
595 #define gtk_widget_push_verify_invariants(widget)
596 #define gtk_widget_pop_verify_invariants(widget)
598 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
599 static void gtk_widget_update_pango_context (GtkWidget *widget);
600 static void gtk_widget_propagate_state (GtkWidget *widget,
603 static gint gtk_widget_event_internal (GtkWidget *widget,
605 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
606 gboolean group_cycling);
607 static void gtk_widget_real_get_width (GtkWidget *widget,
610 static void gtk_widget_real_get_height (GtkWidget *widget,
613 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
615 gint *minimum_height,
616 gint *natural_height);
617 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
620 gint *natural_width);
621 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
622 static GtkWidgetAuxInfo* gtk_widget_get_aux_info (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's left side
2857 * @y: the y coordinate of the cursor position where the request has
2858 * been emitted, relative to @widget's top
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.
3591 * Also see gtk_container_child_notify().
3594 gtk_widget_child_notify (GtkWidget *widget,
3595 const gchar *child_property)
3597 if (widget->priv->parent == NULL)
3600 gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
3604 * gtk_widget_thaw_child_notify:
3605 * @widget: a #GtkWidget
3607 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3608 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3612 gtk_widget_thaw_child_notify (GtkWidget *widget)
3614 GObjectNotifyQueue *nqueue;
3616 g_return_if_fail (GTK_IS_WIDGET (widget));
3618 if (!G_OBJECT (widget)->ref_count)
3621 g_object_ref (widget);
3622 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3623 if (!nqueue || !nqueue->freeze_count)
3624 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3625 G_OBJECT_TYPE_NAME (widget), widget);
3627 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3628 g_object_unref (widget);
3634 * @type: type ID of the widget to create
3635 * @first_property_name: name of first property to set
3636 * @Varargs: value of first property, followed by more properties,
3639 * This is a convenience function for creating a widget and setting
3640 * its properties in one go. For example you might write:
3641 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3642 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3643 * g_object_new(), but returns a widget so you don't have to
3644 * cast the object yourself.
3646 * Return value: a new #GtkWidget of type @widget_type
3649 gtk_widget_new (GType type,
3650 const gchar *first_property_name,
3656 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3658 va_start (var_args, first_property_name);
3659 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3666 gtk_widget_queue_draw_child (GtkWidget *widget)
3668 GtkWidgetPrivate *priv = widget->priv;
3671 parent = priv->parent;
3672 if (parent && gtk_widget_is_drawable (parent))
3673 gtk_widget_queue_draw_area (parent,
3676 priv->allocation.width,
3677 priv->allocation.height);
3681 * gtk_widget_unparent:
3682 * @widget: a #GtkWidget
3684 * This function is only for use in widget implementations.
3685 * Should be called by implementations of the remove method
3686 * on #GtkContainer, to dissociate a child from the container.
3689 gtk_widget_unparent (GtkWidget *widget)
3691 GtkWidgetPrivate *priv;
3692 GObjectNotifyQueue *nqueue;
3693 GtkWidget *toplevel;
3694 GtkWidget *old_parent;
3696 g_return_if_fail (GTK_IS_WIDGET (widget));
3698 priv = widget->priv;
3700 if (priv->parent == NULL)
3703 /* keep this function in sync with gtk_menu_detach() */
3705 gtk_widget_push_verify_invariants (widget);
3707 g_object_freeze_notify (G_OBJECT (widget));
3708 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3710 toplevel = gtk_widget_get_toplevel (widget);
3711 if (gtk_widget_is_toplevel (toplevel))
3712 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3714 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3715 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3717 gtk_widget_queue_draw_child (widget);
3719 /* Reset the width and height here, to force reallocation if we
3720 * get added back to a new parent. This won't work if our new
3721 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3722 * (would 0x0 be OK here?)
3724 priv->allocation.width = 1;
3725 priv->allocation.height = 1;
3727 if (gtk_widget_get_realized (widget))
3729 if (priv->in_reparent)
3730 gtk_widget_unmap (widget);
3732 gtk_widget_unrealize (widget);
3735 /* If we are unanchoring the child, we save around the toplevel
3736 * to emit hierarchy changed
3738 if (priv->parent->priv->anchored)
3739 g_object_ref (toplevel);
3743 /* Removing a widget from a container restores the child visible
3744 * flag to the default state, so it doesn't affect the child
3745 * in the next parent.
3747 priv->child_visible = TRUE;
3749 old_parent = priv->parent;
3750 priv->parent = NULL;
3752 /* parent may no longer expand if the removed
3753 * child was expand=TRUE and could therefore
3756 if (gtk_widget_get_visible (widget) &&
3757 (priv->need_compute_expand ||
3758 priv->computed_hexpand ||
3759 priv->computed_vexpand))
3761 gtk_widget_queue_compute_expand (old_parent);
3764 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3767 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3768 g_object_unref (toplevel);
3771 /* Now that the parent pointer is nullified and the hierarchy-changed
3772 * already passed, go ahead and unset the parent window, if we are unparenting
3773 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
3774 * will fire again for the new subhierarchy.
3776 gtk_widget_set_parent_window (widget, NULL);
3778 g_object_notify (G_OBJECT (widget), "parent");
3779 g_object_thaw_notify (G_OBJECT (widget));
3781 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3782 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3784 gtk_widget_pop_verify_invariants (widget);
3785 g_object_unref (widget);
3789 * gtk_widget_destroy:
3790 * @widget: a #GtkWidget
3792 * Destroys a widget.
3795 * destroyed, it will break any references it holds to other objects.
3796 * If the widget is inside a container, the widget will be removed
3797 * from the container. If the widget is a toplevel (derived from
3798 * #GtkWindow), it will be removed from the list of toplevels, and the
3799 * reference GTK+ holds to it will be removed. Removing a
3800 * widget from its container or the list of toplevels results in the
3801 * widget being finalized, unless you've added additional references
3802 * to the widget with g_object_ref().
3804 * In most cases, only toplevel widgets (windows) require explicit
3805 * destruction, because when you destroy a toplevel its children will
3806 * be destroyed as well.
3809 gtk_widget_destroy (GtkWidget *widget)
3811 g_return_if_fail (GTK_IS_WIDGET (widget));
3813 if (!widget->priv->in_destruction)
3814 g_object_run_dispose (G_OBJECT (widget));
3818 * gtk_widget_destroyed:
3819 * @widget: a #GtkWidget
3820 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3822 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3823 * %NULL. It's intended to be used as a callback connected to the
3824 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3825 * as a signal handler, and pass the address of your widget variable
3826 * as user data. Then when the widget is destroyed, the variable will
3827 * be set to %NULL. Useful for example to avoid multiple copies
3828 * of the same dialog.
3831 gtk_widget_destroyed (GtkWidget *widget,
3832 GtkWidget **widget_pointer)
3834 /* Don't make any assumptions about the
3836 * Even check widget_pointer.
3839 *widget_pointer = NULL;
3844 * @widget: a #GtkWidget
3846 * Flags a widget to be displayed. Any widget that isn't shown will
3847 * not appear on the screen. If you want to show all the widgets in a
3848 * container, it's easier to call gtk_widget_show_all() on the
3849 * container, instead of individually showing the widgets.
3851 * Remember that you have to show the containers containing a widget,
3852 * in addition to the widget itself, before it will appear onscreen.
3854 * When a toplevel container is shown, it is immediately realized and
3855 * mapped; other shown widgets are realized and mapped when their
3856 * toplevel container is realized and mapped.
3859 gtk_widget_show (GtkWidget *widget)
3861 g_return_if_fail (GTK_IS_WIDGET (widget));
3863 if (!gtk_widget_get_visible (widget))
3865 g_object_ref (widget);
3866 gtk_widget_push_verify_invariants (widget);
3868 if (!gtk_widget_is_toplevel (widget))
3869 gtk_widget_queue_resize (widget);
3871 /* see comment in set_parent() for why this should and can be
3874 if (widget->priv->need_compute_expand ||
3875 widget->priv->computed_hexpand ||
3876 widget->priv->computed_vexpand)
3878 if (widget->priv->parent != NULL)
3879 gtk_widget_queue_compute_expand (widget->priv->parent);
3882 g_signal_emit (widget, widget_signals[SHOW], 0);
3883 g_object_notify (G_OBJECT (widget), "visible");
3885 gtk_widget_pop_verify_invariants (widget);
3886 g_object_unref (widget);
3891 gtk_widget_real_show (GtkWidget *widget)
3893 GtkWidgetPrivate *priv = widget->priv;
3895 if (!gtk_widget_get_visible (widget))
3897 priv->visible = TRUE;
3900 gtk_widget_get_mapped (priv->parent) &&
3901 gtk_widget_get_child_visible (widget) &&
3902 !gtk_widget_get_mapped (widget))
3903 gtk_widget_map (widget);
3908 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3911 g_signal_handlers_disconnect_by_func (widget,
3912 gtk_widget_show_map_callback,
3917 * gtk_widget_show_now:
3918 * @widget: a #GtkWidget
3920 * Shows a widget. If the widget is an unmapped toplevel widget
3921 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3922 * loop and wait for the window to actually be mapped. Be careful;
3923 * because the main loop is running, anything can happen during
3927 gtk_widget_show_now (GtkWidget *widget)
3931 g_return_if_fail (GTK_IS_WIDGET (widget));
3933 /* make sure we will get event */
3934 if (!gtk_widget_get_mapped (widget) &&
3935 gtk_widget_is_toplevel (widget))
3937 gtk_widget_show (widget);
3939 g_signal_connect (widget, "map-event",
3940 G_CALLBACK (gtk_widget_show_map_callback),
3944 gtk_main_iteration ();
3947 gtk_widget_show (widget);
3952 * @widget: a #GtkWidget
3954 * Reverses the effects of gtk_widget_show(), causing the widget to be
3955 * hidden (invisible to the user).
3958 gtk_widget_hide (GtkWidget *widget)
3960 g_return_if_fail (GTK_IS_WIDGET (widget));
3962 if (gtk_widget_get_visible (widget))
3964 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3966 g_object_ref (widget);
3967 gtk_widget_push_verify_invariants (widget);
3969 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3970 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3972 /* a parent may now be expand=FALSE since we're hidden. */
3973 if (widget->priv->need_compute_expand ||
3974 widget->priv->computed_hexpand ||
3975 widget->priv->computed_vexpand)
3977 gtk_widget_queue_compute_expand (widget);
3980 g_signal_emit (widget, widget_signals[HIDE], 0);
3981 if (!gtk_widget_is_toplevel (widget))
3982 gtk_widget_queue_resize (widget);
3983 g_object_notify (G_OBJECT (widget), "visible");
3985 gtk_widget_pop_verify_invariants (widget);
3986 g_object_unref (widget);
3991 gtk_widget_real_hide (GtkWidget *widget)
3993 if (gtk_widget_get_visible (widget))
3995 widget->priv->visible = FALSE;
3997 if (gtk_widget_get_mapped (widget))
3998 gtk_widget_unmap (widget);
4003 * gtk_widget_hide_on_delete:
4004 * @widget: a #GtkWidget
4006 * Utility function; intended to be connected to the #GtkWidget::delete-event
4007 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4008 * argument, then returns %TRUE. If connected to ::delete-event, the
4009 * result is that clicking the close button for a window (on the
4010 * window frame, top right corner usually) will hide but not destroy
4011 * the window. By default, GTK+ destroys windows when ::delete-event
4014 * Return value: %TRUE
4017 gtk_widget_hide_on_delete (GtkWidget *widget)
4019 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4021 gtk_widget_hide (widget);
4027 * gtk_widget_show_all:
4028 * @widget: a #GtkWidget
4030 * Recursively shows a widget, and any child widgets (if the widget is
4034 gtk_widget_show_all (GtkWidget *widget)
4036 GtkWidgetClass *class;
4038 g_return_if_fail (GTK_IS_WIDGET (widget));
4040 if (gtk_widget_get_no_show_all (widget))
4043 class = GTK_WIDGET_GET_CLASS (widget);
4045 if (class->show_all)
4046 class->show_all (widget);
4050 _gtk_widget_notify_state_change (GtkWidget *widget,
4058 case GTK_STATE_FLAG_ACTIVE:
4059 state = GTK_STATE_ACTIVE;
4061 case GTK_STATE_FLAG_PRELIGHT:
4062 state = GTK_STATE_PRELIGHT;
4064 case GTK_STATE_FLAG_SELECTED:
4065 state = GTK_STATE_SELECTED;
4067 case GTK_STATE_FLAG_INSENSITIVE:
4068 state = GTK_STATE_INSENSITIVE;
4070 case GTK_STATE_FLAG_INCONSISTENT:
4071 state = GTK_STATE_INCONSISTENT;
4073 case GTK_STATE_FLAG_FOCUSED:
4074 state = GTK_STATE_FOCUSED;
4080 gtk_style_context_notify_state_change (widget->priv->context,
4081 gtk_widget_get_window (widget),
4082 NULL, state, target);
4085 /* Initializes state transitions for those states that
4086 * were enabled before mapping and have a looping animation.
4089 _gtk_widget_start_state_transitions (GtkWidget *widget)
4091 GtkStateFlags state, flag;
4093 if (!widget->priv->context)
4096 state = gtk_widget_get_state_flags (widget);
4097 flag = GTK_STATE_FLAG_FOCUSED;
4101 GtkAnimationDescription *animation_desc;
4103 if ((state & flag) == 0)
4109 gtk_style_context_get (widget->priv->context, state,
4110 "transition", &animation_desc,
4115 if (_gtk_animation_description_get_loop (animation_desc))
4116 _gtk_widget_notify_state_change (widget, flag, TRUE);
4118 _gtk_animation_description_unref (animation_desc);
4127 * @widget: a #GtkWidget
4129 * This function is only for use in widget implementations. Causes
4130 * a widget to be mapped if it isn't already.
4133 gtk_widget_map (GtkWidget *widget)
4135 GtkWidgetPrivate *priv;
4137 g_return_if_fail (GTK_IS_WIDGET (widget));
4138 g_return_if_fail (gtk_widget_get_visible (widget));
4139 g_return_if_fail (gtk_widget_get_child_visible (widget));
4141 priv = widget->priv;
4143 if (!gtk_widget_get_mapped (widget))
4145 gtk_widget_push_verify_invariants (widget);
4147 if (!gtk_widget_get_realized (widget))
4148 gtk_widget_realize (widget);
4150 g_signal_emit (widget, widget_signals[MAP], 0);
4152 if (!gtk_widget_get_has_window (widget))
4153 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4155 gtk_widget_pop_verify_invariants (widget);
4157 _gtk_widget_start_state_transitions (widget);
4163 * @widget: a #GtkWidget
4165 * This function is only for use in widget implementations. Causes
4166 * a widget to be unmapped if it's currently mapped.
4169 gtk_widget_unmap (GtkWidget *widget)
4171 GtkWidgetPrivate *priv;
4173 g_return_if_fail (GTK_IS_WIDGET (widget));
4175 priv = widget->priv;
4177 if (gtk_widget_get_mapped (widget))
4179 gtk_widget_push_verify_invariants (widget);
4181 if (!gtk_widget_get_has_window (widget))
4182 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4183 _gtk_tooltip_hide (widget);
4184 g_signal_emit (widget, widget_signals[UNMAP], 0);
4186 gtk_widget_pop_verify_invariants (widget);
4189 gtk_style_context_cancel_animations (priv->context, NULL);
4191 /* Unset pointer/window info */
4192 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4197 _gtk_widget_enable_device_events (GtkWidget *widget)
4199 GHashTable *device_events;
4200 GHashTableIter iter;
4201 gpointer key, value;
4203 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4208 g_hash_table_iter_init (&iter, device_events);
4210 while (g_hash_table_iter_next (&iter, &key, &value))
4213 GdkEventMask event_mask;
4216 event_mask = GPOINTER_TO_UINT (value);
4217 gtk_widget_add_events_internal (widget, device, event_mask);
4222 get_widget_windows (GtkWidget *widget)
4224 GList *window_list, *last, *l, *children, *ret;
4226 if (gtk_widget_get_has_window (widget))
4227 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4229 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4231 last = g_list_last (window_list);
4234 for (l = window_list; l; l = l->next)
4236 GtkWidget *window_widget = NULL;
4238 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4240 if (widget != window_widget)
4243 ret = g_list_prepend (ret, l->data);
4244 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4248 last = g_list_concat (last, children);
4249 last = g_list_last (last);
4253 g_list_free (window_list);
4259 device_enable_foreach (GtkWidget *widget,
4262 GdkDevice *device = user_data;
4263 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4267 device_disable_foreach (GtkWidget *widget,
4270 GdkDevice *device = user_data;
4271 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4275 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4280 GList *window_list, *l;
4282 window_list = get_widget_windows (widget);
4284 for (l = window_list; l; l = l->next)
4286 GdkEventMask events = 0;
4292 events = gdk_window_get_events (window);
4294 gdk_window_set_device_events (window, device, events);
4297 if (recurse && GTK_IS_CONTAINER (widget))
4300 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4302 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4305 g_list_free (window_list);
4309 gtk_widget_update_devices_mask (GtkWidget *widget,
4312 GList *enabled_devices, *l;
4314 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4316 for (l = enabled_devices; l; l = l->next)
4317 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4321 * gtk_widget_realize:
4322 * @widget: a #GtkWidget
4324 * Creates the GDK (windowing system) resources associated with a
4325 * widget. For example, @widget->window will be created when a widget
4326 * is realized. Normally realization happens implicitly; if you show
4327 * a widget and all its parent containers, then the widget will be
4328 * realized and mapped automatically.
4330 * Realizing a widget requires all
4331 * the widget's parent widgets to be realized; calling
4332 * gtk_widget_realize() realizes the widget's parents in addition to
4333 * @widget itself. If a widget is not yet inside a toplevel window
4334 * when you realize it, bad things will happen.
4336 * This function is primarily used in widget implementations, and
4337 * isn't very useful otherwise. Many times when you think you might
4338 * need it, a better approach is to connect to a signal that will be
4339 * called after the widget is realized automatically, such as
4340 * #GtkWidget::draw. Or simply g_signal_connect () to the
4341 * #GtkWidget::realize signal.
4344 gtk_widget_realize (GtkWidget *widget)
4346 GtkWidgetPrivate *priv;
4347 cairo_region_t *region;
4349 g_return_if_fail (GTK_IS_WIDGET (widget));
4350 g_return_if_fail (widget->priv->anchored ||
4351 GTK_IS_INVISIBLE (widget));
4353 priv = widget->priv;
4355 if (!gtk_widget_get_realized (widget))
4357 gtk_widget_push_verify_invariants (widget);
4360 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4361 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4364 if (priv->parent == NULL &&
4365 !gtk_widget_is_toplevel (widget))
4366 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4367 "inside a toplevel window is not going to work very well. "
4368 "Widgets must be inside a toplevel container before realizing them.");
4370 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4371 gtk_widget_realize (priv->parent);
4373 gtk_widget_ensure_style (widget);
4375 if (priv->style_update_pending)
4376 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4378 g_signal_emit (widget, widget_signals[REALIZE], 0);
4380 gtk_widget_real_set_has_tooltip (widget,
4381 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4384 if (priv->has_shape_mask)
4386 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4387 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4390 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4392 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4394 if (priv->multidevice)
4395 gdk_window_set_support_multidevice (priv->window, TRUE);
4397 _gtk_widget_enable_device_events (widget);
4398 gtk_widget_update_devices_mask (widget, TRUE);
4400 gtk_widget_pop_verify_invariants (widget);
4405 * gtk_widget_unrealize:
4406 * @widget: a #GtkWidget
4408 * This function is only useful in widget implementations.
4409 * Causes a widget to be unrealized (frees all GDK resources
4410 * associated with the widget, such as @widget->window).
4413 gtk_widget_unrealize (GtkWidget *widget)
4415 g_return_if_fail (GTK_IS_WIDGET (widget));
4417 gtk_widget_push_verify_invariants (widget);
4419 if (widget->priv->has_shape_mask)
4420 gtk_widget_shape_combine_region (widget, NULL);
4422 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4423 gtk_widget_input_shape_combine_region (widget, NULL);
4425 if (gtk_widget_get_realized (widget))
4427 g_object_ref (widget);
4429 if (widget->priv->mapped)
4430 gtk_widget_unmap (widget);
4432 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4433 g_assert (!widget->priv->mapped);
4434 gtk_widget_set_realized (widget, FALSE);
4436 g_object_unref (widget);
4439 gtk_widget_pop_verify_invariants (widget);
4442 /*****************************************
4444 *****************************************/
4447 * gtk_widget_queue_draw_region:
4448 * @widget: a #GtkWidget
4449 * @region: region to draw
4451 * Invalidates the rectangular area of @widget defined by @region by
4452 * calling gdk_window_invalidate_region() on the widget's window and
4453 * all its child windows. Once the main loop becomes idle (after the
4454 * current batch of events has been processed, roughly), the window
4455 * will receive expose events for the union of all regions that have
4458 * Normally you would only use this function in widget
4459 * implementations. You might also use it to schedule a redraw of a
4460 * #GtkDrawingArea or some portion thereof.
4465 gtk_widget_queue_draw_region (GtkWidget *widget,
4466 const cairo_region_t *region)
4468 GtkWidgetPrivate *priv;
4471 g_return_if_fail (GTK_IS_WIDGET (widget));
4473 priv = widget->priv;
4475 if (!gtk_widget_get_realized (widget))
4478 /* Just return if the widget or one of its ancestors isn't mapped */
4479 for (w = widget; w != NULL; w = w->priv->parent)
4480 if (!gtk_widget_get_mapped (w))
4483 gdk_window_invalidate_region (priv->window, region, TRUE);
4487 * gtk_widget_queue_draw_area:
4488 * @widget: a #GtkWidget
4489 * @x: x coordinate of upper-left corner of rectangle to redraw
4490 * @y: y coordinate of upper-left corner of rectangle to redraw
4491 * @width: width of region to draw
4492 * @height: height of region to draw
4494 * Convenience function that calls gtk_widget_queue_draw_region() on
4495 * the region created from the given coordinates.
4497 * The region here is specified in widget coordinates.
4498 * Widget coordinates are a bit odd; for historical reasons, they are
4499 * defined as @widget->window coordinates for widgets that are not
4500 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4501 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4504 gtk_widget_queue_draw_area (GtkWidget *widget,
4511 cairo_region_t *region;
4513 g_return_if_fail (GTK_IS_WIDGET (widget));
4518 rect.height = height;
4520 region = cairo_region_create_rectangle (&rect);
4521 gtk_widget_queue_draw_region (widget, region);
4522 cairo_region_destroy (region);
4526 * gtk_widget_queue_draw:
4527 * @widget: a #GtkWidget
4529 * Equivalent to calling gtk_widget_queue_draw_area() for the
4530 * entire area of a widget.
4533 gtk_widget_queue_draw (GtkWidget *widget)
4537 g_return_if_fail (GTK_IS_WIDGET (widget));
4539 gtk_widget_get_allocation (widget, &rect);
4541 if (!gtk_widget_get_has_window (widget))
4542 gtk_widget_queue_draw_area (widget,
4543 rect.x, rect.y, rect.width, rect.height);
4545 gtk_widget_queue_draw_area (widget,
4546 0, 0, rect.width, rect.height);
4550 * gtk_widget_queue_resize:
4551 * @widget: a #GtkWidget
4553 * This function is only for use in widget implementations.
4554 * Flags a widget to have its size renegotiated; should
4555 * be called when a widget for some reason has a new size request.
4556 * For example, when you change the text in a #GtkLabel, #GtkLabel
4557 * queues a resize to ensure there's enough space for the new text.
4559 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4560 * from inside its implementation of the GtkWidgetClass::size_allocate
4561 * virtual method. Calls to gtk_widget_queue_resize() from inside
4562 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4565 gtk_widget_queue_resize (GtkWidget *widget)
4567 g_return_if_fail (GTK_IS_WIDGET (widget));
4569 if (gtk_widget_get_realized (widget))
4570 gtk_widget_queue_shallow_draw (widget);
4572 _gtk_size_group_queue_resize (widget, 0);
4576 * gtk_widget_queue_resize_no_redraw:
4577 * @widget: a #GtkWidget
4579 * This function works like gtk_widget_queue_resize(),
4580 * except that the widget is not invalidated.
4585 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4587 g_return_if_fail (GTK_IS_WIDGET (widget));
4589 _gtk_size_group_queue_resize (widget, 0);
4593 * gtk_widget_size_request:
4594 * @widget: a #GtkWidget
4595 * @requisition: (out): a #GtkRequisition to be filled in
4597 * This function is typically used when implementing a #GtkContainer
4598 * subclass. Obtains the preferred size of a widget. The container
4599 * uses this information to arrange its child widgets and decide what
4600 * size allocations to give them with gtk_widget_size_allocate().
4602 * You can also call this function from an application, with some
4603 * caveats. Most notably, getting a size request requires the widget
4604 * to be associated with a screen, because font information may be
4605 * needed. Multihead-aware applications should keep this in mind.
4607 * Also remember that the size request is not necessarily the size
4608 * a widget will actually be allocated.
4610 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4613 gtk_widget_size_request (GtkWidget *widget,
4614 GtkRequisition *requisition)
4616 g_return_if_fail (GTK_IS_WIDGET (widget));
4618 gtk_widget_get_preferred_size (widget, requisition, NULL);
4622 * gtk_widget_get_child_requisition:
4623 * @widget: a #GtkWidget
4624 * @requisition: (out): a #GtkRequisition to be filled in
4626 * This function is only for use in widget implementations. Obtains
4627 * @widget->requisition, unless someone has forced a particular
4628 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4629 * in which case it returns that geometry instead of the widget's
4632 * This function differs from gtk_widget_size_request() in that
4633 * it retrieves the last size request value from @widget->requisition,
4634 * while gtk_widget_size_request() actually calls the "size_request" method
4635 * on @widget to compute the size request and fill in @widget->requisition,
4636 * and only then returns @widget->requisition.
4638 * Because this function does not call the "size_request" method, it
4639 * can only be used when you know that @widget->requisition is
4640 * up-to-date, that is, gtk_widget_size_request() has been called
4641 * since the last time a resize was queued. In general, only container
4642 * implementations have this information; applications should use
4643 * gtk_widget_size_request().
4646 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4649 gtk_widget_get_child_requisition (GtkWidget *widget,
4650 GtkRequisition *requisition)
4652 gtk_widget_get_preferred_size (widget, requisition, NULL);
4656 invalidate_predicate (GdkWindow *window,
4661 gdk_window_get_user_data (window, &user_data);
4663 return (user_data == data);
4666 /* Invalidate @region in widget->window and all children
4667 * of widget->window owned by widget. @region is in the
4668 * same coordinates as widget->allocation and will be
4669 * modified by this call.
4672 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4673 cairo_region_t *region)
4675 GtkWidgetPrivate *priv = widget->priv;
4677 if (!gtk_widget_get_realized (widget))
4680 if (gtk_widget_get_has_window (widget) && priv->parent)
4684 gdk_window_get_position (priv->window, &x, &y);
4685 cairo_region_translate (region, -x, -y);
4688 gdk_window_invalidate_maybe_recurse (priv->window, region,
4689 invalidate_predicate, widget);
4693 * gtk_widget_queue_shallow_draw:
4694 * @widget: a #GtkWidget
4696 * Like gtk_widget_queue_draw(), but only windows owned
4697 * by @widget are invalidated.
4700 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4703 cairo_region_t *region;
4705 if (!gtk_widget_get_realized (widget))
4708 gtk_widget_get_allocation (widget, &rect);
4710 region = cairo_region_create_rectangle (&rect);
4711 gtk_widget_invalidate_widget_windows (widget, region);
4712 cairo_region_destroy (region);
4716 * gtk_widget_size_allocate:
4717 * @widget: a #GtkWidget
4718 * @allocation: position and size to be allocated to @widget
4720 * This function is only used by #GtkContainer subclasses, to assign a size
4721 * and position to their child widgets.
4723 * In this function, the allocation may be adjusted. It will be forced
4724 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4725 * method on the child will be used to adjust the allocation. Standard
4726 * adjustments include removing the widget's margins, and applying the
4727 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4730 gtk_widget_size_allocate (GtkWidget *widget,
4731 GtkAllocation *allocation)
4733 GtkWidgetPrivate *priv;
4734 GdkRectangle real_allocation;
4735 GdkRectangle old_allocation;
4736 GdkRectangle adjusted_allocation;
4737 gboolean alloc_needed;
4738 gboolean size_changed;
4739 gboolean position_changed;
4740 gint natural_width, natural_height, dummy;
4741 gint min_width, min_height;
4743 priv = widget->priv;
4745 g_return_if_fail (GTK_IS_WIDGET (widget));
4747 gtk_widget_push_verify_invariants (widget);
4749 #ifdef G_ENABLE_DEBUG
4750 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4761 parent = gtk_widget_get_parent (parent);
4764 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4765 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4766 2 * depth, " ", name,
4767 allocation->width, allocation->height);
4769 #endif /* G_ENABLE_DEBUG */
4771 alloc_needed = priv->alloc_needed;
4772 if (!priv->width_request_needed && !priv->height_request_needed)
4773 /* Preserve request/allocate ordering */
4774 priv->alloc_needed = FALSE;
4776 old_allocation = priv->allocation;
4777 real_allocation = *allocation;
4779 adjusted_allocation = real_allocation;
4780 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4782 /* Go ahead and request the height for allocated width, note that the internals
4783 * of get_height_for_width will internally limit the for_size to natural size
4784 * when aligning implicitly.
4786 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4787 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
4791 /* Go ahead and request the width for allocated height, note that the internals
4792 * of get_width_for_height will internally limit the for_size to natural size
4793 * when aligning implicitly.
4795 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4796 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
4799 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
4800 !GTK_IS_SCROLLABLE (widget))
4801 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
4802 "Allocation is %dx%d, but minimum required size is %dx%d.",
4803 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
4804 G_OBJECT_TYPE_NAME (widget), widget,
4805 real_allocation.width, real_allocation.height,
4806 min_width, min_height);
4807 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4808 * allocated sizes and possibly limit them to the natural sizes */
4809 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4810 GTK_ORIENTATION_HORIZONTAL,
4813 &adjusted_allocation.x,
4814 &adjusted_allocation.width);
4815 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4816 GTK_ORIENTATION_VERTICAL,
4819 &adjusted_allocation.y,
4820 &adjusted_allocation.height);
4822 if (adjusted_allocation.x < real_allocation.x ||
4823 adjusted_allocation.y < real_allocation.y ||
4824 (adjusted_allocation.x + adjusted_allocation.width) >
4825 (real_allocation.x + real_allocation.width) ||
4826 (adjusted_allocation.y + adjusted_allocation.height >
4827 real_allocation.y + real_allocation.height))
4829 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",
4830 G_OBJECT_TYPE_NAME (widget), widget,
4831 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4832 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4833 adjusted_allocation = real_allocation; /* veto it */
4837 real_allocation = adjusted_allocation;
4840 if (real_allocation.width < 0 || real_allocation.height < 0)
4842 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4843 real_allocation.width,
4844 real_allocation.height);
4847 real_allocation.width = MAX (real_allocation.width, 1);
4848 real_allocation.height = MAX (real_allocation.height, 1);
4850 size_changed = (old_allocation.width != real_allocation.width ||
4851 old_allocation.height != real_allocation.height);
4852 position_changed = (old_allocation.x != real_allocation.x ||
4853 old_allocation.y != real_allocation.y);
4855 if (!alloc_needed && !size_changed && !position_changed)
4858 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4860 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4861 priv->width_request_needed = FALSE;
4862 priv->height_request_needed = FALSE;
4863 priv->alloc_needed = FALSE;
4865 if (gtk_widget_get_mapped (widget))
4867 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4869 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4871 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4872 cairo_region_union_rectangle (invalidate, &old_allocation);
4874 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4875 cairo_region_destroy (invalidate);
4880 if (priv->redraw_on_alloc)
4882 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4884 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4885 cairo_region_union_rectangle (invalidate, &old_allocation);
4887 gtk_widget_invalidate_widget_windows (widget, invalidate);
4888 cairo_region_destroy (invalidate);
4892 if (size_changed || position_changed)
4894 GtkStyleContext *context;
4896 context = gtk_widget_get_style_context (widget);
4897 _gtk_style_context_invalidate_animation_areas (context);
4901 if ((size_changed || position_changed) && priv->parent &&
4902 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4904 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4905 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4906 cairo_region_destroy (invalidate);
4910 gtk_widget_pop_verify_invariants (widget);
4914 * gtk_widget_common_ancestor:
4915 * @widget_a: a #GtkWidget
4916 * @widget_b: a #GtkWidget
4918 * Find the common ancestor of @widget_a and @widget_b that
4919 * is closest to the two widgets.
4921 * Return value: the closest common ancestor of @widget_a and
4922 * @widget_b or %NULL if @widget_a and @widget_b do not
4923 * share a common ancestor.
4926 gtk_widget_common_ancestor (GtkWidget *widget_a,
4927 GtkWidget *widget_b)
4929 GtkWidget *parent_a;
4930 GtkWidget *parent_b;
4934 parent_a = widget_a;
4935 while (parent_a->priv->parent)
4937 parent_a = parent_a->priv->parent;
4941 parent_b = widget_b;
4942 while (parent_b->priv->parent)
4944 parent_b = parent_b->priv->parent;
4948 if (parent_a != parent_b)
4951 while (depth_a > depth_b)
4953 widget_a = widget_a->priv->parent;
4957 while (depth_b > depth_a)
4959 widget_b = widget_b->priv->parent;
4963 while (widget_a != widget_b)
4965 widget_a = widget_a->priv->parent;
4966 widget_b = widget_b->priv->parent;
4973 * gtk_widget_translate_coordinates:
4974 * @src_widget: a #GtkWidget
4975 * @dest_widget: a #GtkWidget
4976 * @src_x: X position relative to @src_widget
4977 * @src_y: Y position relative to @src_widget
4978 * @dest_x: (out): location to store X position relative to @dest_widget
4979 * @dest_y: (out): location to store Y position relative to @dest_widget
4981 * Translate coordinates relative to @src_widget's allocation to coordinates
4982 * relative to @dest_widget's allocations. In order to perform this
4983 * operation, both widgets must be realized, and must share a common
4986 * Return value: %FALSE if either widget was not realized, or there
4987 * was no common ancestor. In this case, nothing is stored in
4988 * *@dest_x and *@dest_y. Otherwise %TRUE.
4991 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4992 GtkWidget *dest_widget,
4998 GtkWidgetPrivate *src_priv = src_widget->priv;
4999 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5000 GtkWidget *ancestor;
5002 GList *dest_list = NULL;
5004 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5005 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5007 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5008 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5011 /* Translate from allocation relative to window relative */
5012 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5015 gdk_window_get_position (src_priv->window, &wx, &wy);
5017 src_x -= wx - src_priv->allocation.x;
5018 src_y -= wy - src_priv->allocation.y;
5022 src_x += src_priv->allocation.x;
5023 src_y += src_priv->allocation.y;
5026 /* Translate to the common ancestor */
5027 window = src_priv->window;
5028 while (window != ancestor->priv->window)
5032 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5037 window = gdk_window_get_effective_parent (window);
5039 if (!window) /* Handle GtkHandleBox */
5044 window = dest_priv->window;
5045 while (window != ancestor->priv->window)
5047 dest_list = g_list_prepend (dest_list, window);
5049 window = gdk_window_get_effective_parent (window);
5051 if (!window) /* Handle GtkHandleBox */
5053 g_list_free (dest_list);
5062 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5067 dest_list = g_list_remove (dest_list, dest_list->data);
5070 /* Translate from window relative to allocation relative */
5071 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5074 gdk_window_get_position (dest_priv->window, &wx, &wy);
5076 src_x += wx - dest_priv->allocation.x;
5077 src_y += wy - dest_priv->allocation.y;
5081 src_x -= dest_priv->allocation.x;
5082 src_y -= dest_priv->allocation.y;
5094 gtk_widget_real_size_allocate (GtkWidget *widget,
5095 GtkAllocation *allocation)
5097 GtkWidgetPrivate *priv = widget->priv;
5099 priv->allocation = *allocation;
5101 if (gtk_widget_get_realized (widget) &&
5102 gtk_widget_get_has_window (widget))
5104 gdk_window_move_resize (priv->window,
5105 allocation->x, allocation->y,
5106 allocation->width, allocation->height);
5110 /* translate initial/final into start/end */
5112 effective_align (GtkAlign align,
5113 GtkTextDirection direction)
5117 case GTK_ALIGN_START:
5118 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5120 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5127 adjust_for_align (GtkAlign align,
5129 gint *allocated_pos,
5130 gint *allocated_size)
5134 case GTK_ALIGN_FILL:
5135 /* change nothing */
5137 case GTK_ALIGN_START:
5138 /* keep *allocated_pos where it is */
5139 *allocated_size = MIN (*allocated_size, *natural_size);
5142 if (*allocated_size > *natural_size)
5144 *allocated_pos += (*allocated_size - *natural_size);
5145 *allocated_size = *natural_size;
5148 case GTK_ALIGN_CENTER:
5149 if (*allocated_size > *natural_size)
5151 *allocated_pos += (*allocated_size - *natural_size) / 2;
5152 *allocated_size = MIN (*allocated_size, *natural_size);
5159 adjust_for_margin(gint start_margin,
5163 gint *allocated_pos,
5164 gint *allocated_size)
5166 *minimum_size -= (start_margin + end_margin);
5167 *natural_size -= (start_margin + end_margin);
5168 *allocated_pos += start_margin;
5169 *allocated_size -= (start_margin + end_margin);
5173 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5174 GtkOrientation orientation,
5177 gint *allocated_pos,
5178 gint *allocated_size)
5180 const GtkWidgetAuxInfo *aux_info;
5182 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5184 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5186 adjust_for_margin (aux_info->margin.left,
5187 aux_info->margin.right,
5188 minimum_size, natural_size,
5189 allocated_pos, allocated_size);
5190 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5191 natural_size, allocated_pos, allocated_size);
5195 adjust_for_margin (aux_info->margin.top,
5196 aux_info->margin.bottom,
5197 minimum_size, natural_size,
5198 allocated_pos, allocated_size);
5199 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5200 natural_size, allocated_pos, allocated_size);
5205 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5208 GtkWidgetPrivate *priv = widget->priv;
5210 /* widgets must be onscreen for accels to take effect */
5211 return gtk_widget_is_sensitive (widget) &&
5212 gtk_widget_is_drawable (widget) &&
5213 gdk_window_is_viewable (priv->window);
5217 * gtk_widget_can_activate_accel:
5218 * @widget: a #GtkWidget
5219 * @signal_id: the ID of a signal installed on @widget
5221 * Determines whether an accelerator that activates the signal
5222 * identified by @signal_id can currently be activated.
5223 * This is done by emitting the #GtkWidget::can-activate-accel
5224 * signal on @widget; if the signal isn't overridden by a
5225 * handler or in a derived widget, then the default check is
5226 * that the widget must be sensitive, and the widget and all
5227 * its ancestors mapped.
5229 * Return value: %TRUE if the accelerator can be activated.
5234 gtk_widget_can_activate_accel (GtkWidget *widget,
5237 gboolean can_activate = FALSE;
5238 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5239 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5240 return can_activate;
5249 closure_accel_activate (GClosure *closure,
5250 GValue *return_value,
5251 guint n_param_values,
5252 const GValue *param_values,
5253 gpointer invocation_hint,
5254 gpointer marshal_data)
5256 AccelClosure *aclosure = (AccelClosure*) closure;
5257 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5260 g_signal_emit (closure->data, aclosure->signal_id, 0);
5262 /* whether accelerator was handled */
5263 g_value_set_boolean (return_value, can_activate);
5267 closures_destroy (gpointer data)
5269 GSList *slist, *closures = data;
5271 for (slist = closures; slist; slist = slist->next)
5273 g_closure_invalidate (slist->data);
5274 g_closure_unref (slist->data);
5276 g_slist_free (closures);
5280 widget_new_accel_closure (GtkWidget *widget,
5283 AccelClosure *aclosure;
5284 GClosure *closure = NULL;
5285 GSList *slist, *closures;
5287 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5288 for (slist = closures; slist; slist = slist->next)
5289 if (!gtk_accel_group_from_accel_closure (slist->data))
5291 /* reuse this closure */
5292 closure = slist->data;
5297 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5298 closures = g_slist_prepend (closures, g_closure_ref (closure));
5299 g_closure_sink (closure);
5300 g_closure_set_marshal (closure, closure_accel_activate);
5302 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5304 aclosure = (AccelClosure*) closure;
5305 g_assert (closure->data == widget);
5306 g_assert (closure->marshal == closure_accel_activate);
5307 aclosure->signal_id = signal_id;
5313 * gtk_widget_add_accelerator
5314 * @widget: widget to install an accelerator on
5315 * @accel_signal: widget signal to emit on accelerator activation
5316 * @accel_group: accel group for this widget, added to its toplevel
5317 * @accel_key: GDK keyval of the accelerator
5318 * @accel_mods: modifier key combination of the accelerator
5319 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5321 * Installs an accelerator for this @widget in @accel_group that causes
5322 * @accel_signal to be emitted if the accelerator is activated.
5323 * The @accel_group needs to be added to the widget's toplevel via
5324 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5325 * Accelerators added through this function are not user changeable during
5326 * runtime. If you want to support accelerators that can be changed by the
5327 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5328 * gtk_menu_item_set_accel_path() instead.
5331 gtk_widget_add_accelerator (GtkWidget *widget,
5332 const gchar *accel_signal,
5333 GtkAccelGroup *accel_group,
5335 GdkModifierType accel_mods,
5336 GtkAccelFlags accel_flags)
5341 g_return_if_fail (GTK_IS_WIDGET (widget));
5342 g_return_if_fail (accel_signal != NULL);
5343 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5345 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5346 if (!query.signal_id ||
5347 !(query.signal_flags & G_SIGNAL_ACTION) ||
5348 query.return_type != G_TYPE_NONE ||
5351 /* hmm, should be elaborate enough */
5352 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5353 G_OBJECT_TYPE_NAME (widget), accel_signal);
5357 closure = widget_new_accel_closure (widget, query.signal_id);
5359 g_object_ref (widget);
5361 /* install the accelerator. since we don't map this onto an accel_path,
5362 * the accelerator will automatically be locked.
5364 gtk_accel_group_connect (accel_group,
5367 accel_flags | GTK_ACCEL_LOCKED,
5370 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5372 g_object_unref (widget);
5376 * gtk_widget_remove_accelerator:
5377 * @widget: widget to install an accelerator on
5378 * @accel_group: accel group for this widget
5379 * @accel_key: GDK keyval of the accelerator
5380 * @accel_mods: modifier key combination of the accelerator
5381 * @returns: whether an accelerator was installed and could be removed
5383 * Removes an accelerator from @widget, previously installed with
5384 * gtk_widget_add_accelerator().
5387 gtk_widget_remove_accelerator (GtkWidget *widget,
5388 GtkAccelGroup *accel_group,
5390 GdkModifierType accel_mods)
5392 GtkAccelGroupEntry *ag_entry;
5393 GList *slist, *clist;
5396 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5397 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5399 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5400 clist = gtk_widget_list_accel_closures (widget);
5401 for (slist = clist; slist; slist = slist->next)
5405 for (i = 0; i < n; i++)
5406 if (slist->data == (gpointer) ag_entry[i].closure)
5408 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5410 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5412 g_list_free (clist);
5417 g_list_free (clist);
5419 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5420 accel_key, accel_mods, accel_group,
5421 G_OBJECT_TYPE_NAME (widget), widget);
5427 * gtk_widget_list_accel_closures:
5428 * @widget: widget to list accelerator closures for
5430 * Lists the closures used by @widget for accelerator group connections
5431 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5432 * The closures can be used to monitor accelerator changes on @widget,
5433 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5434 * #GtkAccelGroup of a closure which can be found out with
5435 * gtk_accel_group_from_accel_closure().
5437 * Return value: (transfer container) (element-type GClosure):
5438 * a newly allocated #GList of closures
5441 gtk_widget_list_accel_closures (GtkWidget *widget)
5444 GList *clist = NULL;
5446 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5448 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5449 if (gtk_accel_group_from_accel_closure (slist->data))
5450 clist = g_list_prepend (clist, slist->data);
5456 GtkAccelGroup *accel_group;
5461 destroy_accel_path (gpointer data)
5463 AccelPath *apath = data;
5465 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5467 /* closures_destroy takes care of unrefing the closure */
5468 g_object_unref (apath->accel_group);
5470 g_slice_free (AccelPath, apath);
5475 * gtk_widget_set_accel_path:
5476 * @widget: a #GtkWidget
5477 * @accel_path: (allow-none): path used to look up the accelerator
5478 * @accel_group: (allow-none): a #GtkAccelGroup.
5480 * Given an accelerator group, @accel_group, and an accelerator path,
5481 * @accel_path, sets up an accelerator in @accel_group so whenever the
5482 * key binding that is defined for @accel_path is pressed, @widget
5483 * will be activated. This removes any accelerators (for any
5484 * accelerator group) installed by previous calls to
5485 * gtk_widget_set_accel_path(). Associating accelerators with
5486 * paths allows them to be modified by the user and the modifications
5487 * to be saved for future use. (See gtk_accel_map_save().)
5489 * This function is a low level function that would most likely
5490 * be used by a menu creation system like #GtkUIManager. If you
5491 * use #GtkUIManager, setting up accelerator paths will be done
5494 * Even when you you aren't using #GtkUIManager, if you only want to
5495 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5496 * provides a somewhat more convenient interface.
5498 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5499 * pass a static string, you can save some memory by interning it first with
5500 * g_intern_static_string().
5503 gtk_widget_set_accel_path (GtkWidget *widget,
5504 const gchar *accel_path,
5505 GtkAccelGroup *accel_group)
5509 g_return_if_fail (GTK_IS_WIDGET (widget));
5510 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5514 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5515 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5517 gtk_accel_map_add_entry (accel_path, 0, 0);
5518 apath = g_slice_new (AccelPath);
5519 apath->accel_group = g_object_ref (accel_group);
5520 apath->path_quark = g_quark_from_string (accel_path);
5521 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5526 /* also removes possible old settings */
5527 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5530 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5532 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5536 _gtk_widget_get_accel_path (GtkWidget *widget,
5541 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5543 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5545 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5546 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5550 * gtk_widget_mnemonic_activate:
5551 * @widget: a #GtkWidget
5552 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5554 * Emits the #GtkWidget::mnemonic-activate signal.
5556 * The default handler for this signal activates the @widget if
5557 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5560 * Returns: %TRUE if the signal has been handled
5563 gtk_widget_mnemonic_activate (GtkWidget *widget,
5564 gboolean group_cycling)
5568 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5570 group_cycling = group_cycling != FALSE;
5571 if (!gtk_widget_is_sensitive (widget))
5574 g_signal_emit (widget,
5575 widget_signals[MNEMONIC_ACTIVATE],
5583 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5584 gboolean group_cycling)
5586 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5587 gtk_widget_activate (widget);
5588 else if (gtk_widget_get_can_focus (widget))
5589 gtk_widget_grab_focus (widget);
5592 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5593 G_OBJECT_TYPE_NAME (widget));
5594 gtk_widget_error_bell (widget);
5599 static const cairo_user_data_key_t event_key;
5602 _gtk_cairo_get_event (cairo_t *cr)
5604 g_return_val_if_fail (cr != NULL, NULL);
5606 return cairo_get_user_data (cr, &event_key);
5610 gtk_cairo_set_event (cairo_t *cr,
5611 GdkEventExpose *event)
5613 cairo_set_user_data (cr, &event_key, event, NULL);
5617 * gtk_cairo_should_draw_window:
5618 * @cr: a cairo context
5619 * @window: the window to check. @window may not be an input-only
5622 * This function is supposed to be called in #GtkWidget::draw
5623 * implementations for widgets that support multiple windows.
5624 * @cr must be untransformed from invoking of the draw function.
5625 * This function will return %TRUE if the contents of the given
5626 * @window are supposed to be drawn and %FALSE otherwise. Note
5627 * that when the drawing was not initiated by the windowing
5628 * system this function will return %TRUE for all windows, so
5629 * you need to draw the bottommost window first. Also, do not
5630 * use "else if" statements to check which window should be drawn.
5632 * Returns: %TRUE if @window should be drawn
5637 gtk_cairo_should_draw_window (cairo_t *cr,
5640 GdkEventExpose *event;
5642 g_return_val_if_fail (cr != NULL, FALSE);
5643 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5645 event = _gtk_cairo_get_event (cr);
5647 return event == NULL ||
5648 event->window == window;
5652 gtk_widget_get_clip_draw (GtkWidget *widget)
5654 /* labels are not clipped, because clipping them would cause
5655 * mnemonics to not appear on characters that go beyond the
5657 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
5659 if (GTK_IS_LABEL (widget))
5665 /* code shared by gtk_container_propagate_draw() and
5669 _gtk_widget_draw_internal (GtkWidget *widget,
5671 gboolean clip_to_size)
5673 GtkStyleContext *context;
5675 if (!gtk_widget_is_drawable (widget))
5678 clip_to_size &= gtk_widget_get_clip_draw (widget);
5682 cairo_rectangle (cr,
5684 widget->priv->allocation.width,
5685 widget->priv->allocation.height);
5689 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5693 g_signal_emit (widget, widget_signals[DRAW],
5698 context = gtk_widget_get_style_context (widget);
5699 _gtk_style_context_coalesce_animation_areas (context, widget);
5704 * @widget: the widget to draw. It must be drawable (see
5705 * gtk_widget_is_drawable()) and a size must have been allocated.
5706 * @cr: a cairo context to draw to
5708 * Draws @widget to @cr. The top left corner of the widget will be
5709 * drawn to the currently set origin point of @cr.
5711 * You should pass a cairo context as @cr argument that is in an
5712 * original state. Otherwise the resulting drawing is undefined. For
5713 * example changing the operator using cairo_set_operator() or the
5714 * line width using cairo_set_line_width() might have unwanted side
5716 * You may however change the context's transform matrix - like with
5717 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5718 * region with cairo_clip() prior to calling this function. Also, it
5719 * is fine to modify the context with cairo_save() and
5720 * cairo_push_group() prior to calling this function.
5722 * <note><para>Special purpose widgets may contain special code for
5723 * rendering to the screen and might appear differently on screen
5724 * and when rendered using gtk_widget_draw().</para></note>
5729 gtk_widget_draw (GtkWidget *widget,
5732 GdkEventExpose *tmp_event;
5734 g_return_if_fail (GTK_IS_WIDGET (widget));
5735 g_return_if_fail (!widget->priv->alloc_needed);
5736 g_return_if_fail (cr != NULL);
5739 /* We have to reset the event here so that draw functions can call
5740 * gtk_widget_draw() on random other widgets and get the desired
5741 * effect: Drawing all contents, not just the current window.
5743 tmp_event = _gtk_cairo_get_event (cr);
5744 gtk_cairo_set_event (cr, NULL);
5746 _gtk_widget_draw_internal (widget, cr, TRUE);
5748 gtk_cairo_set_event (cr, tmp_event);
5753 gtk_widget_real_key_press_event (GtkWidget *widget,
5756 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5760 gtk_widget_real_key_release_event (GtkWidget *widget,
5763 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5767 gtk_widget_real_focus_in_event (GtkWidget *widget,
5768 GdkEventFocus *event)
5770 gtk_widget_queue_shallow_draw (widget);
5776 gtk_widget_real_focus_out_event (GtkWidget *widget,
5777 GdkEventFocus *event)
5779 gtk_widget_queue_shallow_draw (widget);
5784 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5785 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5789 * @widget: a #GtkWidget
5790 * @event: a #GdkEvent
5792 * Rarely-used function. This function is used to emit
5793 * the event signals on a widget (those signals should never
5794 * be emitted without using this function to do so).
5795 * If you want to synthesize an event though, don't use this function;
5796 * instead, use gtk_main_do_event() so the event will behave as if
5797 * it were in the event queue. Don't synthesize expose events; instead,
5798 * use gdk_window_invalidate_rect() to invalidate a region of the
5801 * Return value: return from the event signal emission (%TRUE if
5802 * the event was handled)
5805 gtk_widget_event (GtkWidget *widget,
5808 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5809 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5811 if (event->type == GDK_EXPOSE)
5813 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5814 "the same effect, call gdk_window_invalidate_rect/region(), "
5815 "followed by gdk_window_process_updates().");
5819 return gtk_widget_event_internal (widget, event);
5822 /* Returns TRUE if a translation should be done */
5824 _gtk_widget_get_translation_to_window (GtkWidget *widget,
5829 GdkWindow *w, *widget_window;
5831 if (!gtk_widget_get_has_window (widget))
5833 *x = -widget->priv->allocation.x;
5834 *y = -widget->priv->allocation.y;
5842 widget_window = gtk_widget_get_window (widget);
5844 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5847 gdk_window_get_position (w, &wx, &wy);
5864 * gtk_cairo_transform_to_window:
5865 * @cr: the cairo context to transform
5866 * @widget: the widget the context is currently centered for
5867 * @window: the window to transform the context to
5869 * Transforms the given cairo context @cr that from @widget-relative
5870 * coordinates to @window-relative coordinates.
5871 * If the @widget's window is not an ancestor of @window, no
5872 * modification will be applied.
5874 * This is the inverse to the transformation GTK applies when
5875 * preparing an expose event to be emitted with the #GtkWidget::draw
5876 * signal. It is intended to help porting multiwindow widgets from
5877 * GTK+ 2 to the rendering architecture of GTK+ 3.
5882 gtk_cairo_transform_to_window (cairo_t *cr,
5888 g_return_if_fail (cr != NULL);
5889 g_return_if_fail (GTK_IS_WIDGET (widget));
5890 g_return_if_fail (GDK_IS_WINDOW (window));
5892 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
5893 cairo_translate (cr, x, y);
5897 * gtk_widget_send_expose:
5898 * @widget: a #GtkWidget
5899 * @event: a expose #GdkEvent
5901 * Very rarely-used function. This function is used to emit
5902 * an expose event on a widget. This function is not normally used
5903 * directly. The only time it is used is when propagating an expose
5904 * event to a child %NO_WINDOW widget, and that is normally done
5905 * using gtk_container_propagate_draw().
5907 * If you want to force an area of a window to be redrawn,
5908 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5909 * To cause the redraw to be done immediately, follow that call
5910 * with a call to gdk_window_process_updates().
5912 * Return value: return from the event signal emission (%TRUE if
5913 * the event was handled)
5916 gtk_widget_send_expose (GtkWidget *widget,
5919 gboolean result = FALSE;
5924 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5925 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5926 g_return_val_if_fail (event != NULL, TRUE);
5927 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5929 cr = gdk_cairo_create (event->expose.window);
5930 gtk_cairo_set_event (cr, &event->expose);
5932 gdk_cairo_region (cr, event->expose.region);
5935 do_clip = _gtk_widget_get_translation_to_window (widget,
5936 event->expose.window,
5938 cairo_translate (cr, -x, -y);
5940 _gtk_widget_draw_internal (widget, cr, do_clip);
5942 /* unset here, so if someone keeps a reference to cr we
5943 * don't leak the window. */
5944 gtk_cairo_set_event (cr, NULL);
5951 event_window_is_still_viewable (GdkEvent *event)
5953 /* Check that we think the event's window is viewable before
5954 * delivering the event, to prevent suprises. We do this here
5955 * at the last moment, since the event may have been queued
5956 * up behind other events, held over a recursive main loop, etc.
5958 switch (event->type)
5961 case GDK_MOTION_NOTIFY:
5962 case GDK_BUTTON_PRESS:
5963 case GDK_2BUTTON_PRESS:
5964 case GDK_3BUTTON_PRESS:
5966 case GDK_ENTER_NOTIFY:
5967 case GDK_PROXIMITY_IN:
5969 return event->any.window && gdk_window_is_viewable (event->any.window);
5972 /* The following events are the second half of paired events;
5973 * we always deliver them to deal with widgets that clean up
5974 * on the second half.
5976 case GDK_BUTTON_RELEASE:
5977 case GDK_KEY_RELEASE:
5978 case GDK_LEAVE_NOTIFY:
5979 case GDK_PROXIMITY_OUT:
5983 /* Remaining events would make sense on an not-viewable window,
5984 * or don't have an associated window.
5991 gtk_widget_event_internal (GtkWidget *widget,
5994 gboolean return_val = FALSE;
5996 /* We check only once for is-still-visible; if someone
5997 * hides the window in on of the signals on the widget,
5998 * they are responsible for returning TRUE to terminate
6001 if (!event_window_is_still_viewable (event))
6004 g_object_ref (widget);
6006 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6007 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6012 switch (event->type)
6018 case GDK_BUTTON_PRESS:
6019 case GDK_2BUTTON_PRESS:
6020 case GDK_3BUTTON_PRESS:
6021 signal_num = BUTTON_PRESS_EVENT;
6024 signal_num = SCROLL_EVENT;
6026 case GDK_BUTTON_RELEASE:
6027 signal_num = BUTTON_RELEASE_EVENT;
6029 case GDK_MOTION_NOTIFY:
6030 signal_num = MOTION_NOTIFY_EVENT;
6033 signal_num = DELETE_EVENT;
6036 signal_num = DESTROY_EVENT;
6037 _gtk_tooltip_hide (widget);
6040 signal_num = KEY_PRESS_EVENT;
6042 case GDK_KEY_RELEASE:
6043 signal_num = KEY_RELEASE_EVENT;
6045 case GDK_ENTER_NOTIFY:
6046 signal_num = ENTER_NOTIFY_EVENT;
6048 case GDK_LEAVE_NOTIFY:
6049 signal_num = LEAVE_NOTIFY_EVENT;
6051 case GDK_FOCUS_CHANGE:
6052 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6053 if (event->focus_change.in)
6054 _gtk_tooltip_focus_in (widget);
6056 _gtk_tooltip_focus_out (widget);
6059 signal_num = CONFIGURE_EVENT;
6062 signal_num = MAP_EVENT;
6065 signal_num = UNMAP_EVENT;
6067 case GDK_WINDOW_STATE:
6068 signal_num = WINDOW_STATE_EVENT;
6070 case GDK_PROPERTY_NOTIFY:
6071 signal_num = PROPERTY_NOTIFY_EVENT;
6073 case GDK_SELECTION_CLEAR:
6074 signal_num = SELECTION_CLEAR_EVENT;
6076 case GDK_SELECTION_REQUEST:
6077 signal_num = SELECTION_REQUEST_EVENT;
6079 case GDK_SELECTION_NOTIFY:
6080 signal_num = SELECTION_NOTIFY_EVENT;
6082 case GDK_PROXIMITY_IN:
6083 signal_num = PROXIMITY_IN_EVENT;
6085 case GDK_PROXIMITY_OUT:
6086 signal_num = PROXIMITY_OUT_EVENT;
6088 case GDK_VISIBILITY_NOTIFY:
6089 signal_num = VISIBILITY_NOTIFY_EVENT;
6091 case GDK_GRAB_BROKEN:
6092 signal_num = GRAB_BROKEN_EVENT;
6095 signal_num = DAMAGE_EVENT;
6098 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6102 if (signal_num != -1)
6103 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6105 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6106 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6110 g_object_unref (widget);
6116 * gtk_widget_activate:
6117 * @widget: a #GtkWidget that's activatable
6119 * For widgets that can be "activated" (buttons, menu items, etc.)
6120 * this function activates them. Activation is what happens when you
6121 * press Enter on a widget during key navigation. If @widget isn't
6122 * activatable, the function returns %FALSE.
6124 * Return value: %TRUE if the widget was activatable
6127 gtk_widget_activate (GtkWidget *widget)
6129 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6131 if (WIDGET_CLASS (widget)->activate_signal)
6133 /* FIXME: we should eventually check the signals signature here */
6134 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6143 gtk_widget_reparent_subwindows (GtkWidget *widget,
6144 GdkWindow *new_window)
6146 GtkWidgetPrivate *priv = widget->priv;
6148 if (!gtk_widget_get_has_window (widget))
6150 GList *children = gdk_window_get_children (priv->window);
6153 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6155 GdkWindow *window = tmp_list->data;
6158 gdk_window_get_user_data (window, &child);
6159 while (child && child != widget)
6160 child = ((GtkWidget*) child)->priv->parent;
6163 gdk_window_reparent (window, new_window, 0, 0);
6166 g_list_free (children);
6171 GList *tmp_list, *children;
6173 parent = gdk_window_get_parent (priv->window);
6176 gdk_window_reparent (priv->window, new_window, 0, 0);
6179 children = gdk_window_get_children (parent);
6181 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6183 GdkWindow *window = tmp_list->data;
6186 gdk_window_get_user_data (window, &child);
6188 if (child == widget)
6189 gdk_window_reparent (window, new_window, 0, 0);
6192 g_list_free (children);
6198 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6199 gpointer client_data)
6201 GtkWidgetPrivate *priv = widget->priv;
6203 g_assert (client_data != NULL);
6205 if (!gtk_widget_get_has_window (widget))
6208 g_object_unref (priv->window);
6209 priv->window = (GdkWindow*) client_data;
6211 g_object_ref (priv->window);
6213 if (GTK_IS_CONTAINER (widget))
6214 gtk_container_forall (GTK_CONTAINER (widget),
6215 gtk_widget_reparent_fixup_child,
6221 * gtk_widget_reparent:
6222 * @widget: a #GtkWidget
6223 * @new_parent: a #GtkContainer to move the widget into
6225 * Moves a widget from one #GtkContainer to another, handling reference
6226 * count issues to avoid destroying the widget.
6229 gtk_widget_reparent (GtkWidget *widget,
6230 GtkWidget *new_parent)
6232 GtkWidgetPrivate *priv;
6234 g_return_if_fail (GTK_IS_WIDGET (widget));
6235 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6236 priv = widget->priv;
6237 g_return_if_fail (priv->parent != NULL);
6239 if (priv->parent != new_parent)
6241 /* First try to see if we can get away without unrealizing
6242 * the widget as we reparent it. if so we set a flag so
6243 * that gtk_widget_unparent doesn't unrealize widget
6245 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6246 priv->in_reparent = TRUE;
6248 g_object_ref (widget);
6249 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6250 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6251 g_object_unref (widget);
6253 if (priv->in_reparent)
6255 priv->in_reparent = FALSE;
6257 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6258 gtk_widget_reparent_fixup_child (widget,
6259 gtk_widget_get_parent_window (widget));
6262 g_object_notify (G_OBJECT (widget), "parent");
6267 * gtk_widget_intersect:
6268 * @widget: a #GtkWidget
6269 * @area: a rectangle
6270 * @intersection: rectangle to store intersection of @widget and @area
6272 * Computes the intersection of a @widget's area and @area, storing
6273 * the intersection in @intersection, and returns %TRUE if there was
6274 * an intersection. @intersection may be %NULL if you're only
6275 * interested in whether there was an intersection.
6277 * Return value: %TRUE if there was an intersection
6280 gtk_widget_intersect (GtkWidget *widget,
6281 const GdkRectangle *area,
6282 GdkRectangle *intersection)
6284 GtkWidgetPrivate *priv;
6289 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6290 g_return_val_if_fail (area != NULL, FALSE);
6292 priv = widget->priv;
6295 dest = intersection;
6299 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6301 if (return_val && intersection && gtk_widget_get_has_window (widget))
6303 intersection->x -= priv->allocation.x;
6304 intersection->y -= priv->allocation.y;
6311 * gtk_widget_region_intersect:
6312 * @widget: a #GtkWidget
6313 * @region: a #cairo_region_t, in the same coordinate system as
6314 * @widget->allocation. That is, relative to @widget->window
6315 * for %NO_WINDOW widgets; relative to the parent window
6316 * of @widget->window for widgets with their own window.
6317 * @returns: A newly allocated region holding the intersection of @widget
6318 * and @region. The coordinates of the return value are
6319 * relative to @widget->window for %NO_WINDOW widgets, and
6320 * relative to the parent window of @widget->window for
6321 * widgets with their own window.
6323 * Computes the intersection of a @widget's area and @region, returning
6324 * the intersection. The result may be empty, use cairo_region_is_empty() to
6328 gtk_widget_region_intersect (GtkWidget *widget,
6329 const cairo_region_t *region)
6332 cairo_region_t *dest;
6334 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6335 g_return_val_if_fail (region != NULL, NULL);
6337 gtk_widget_get_allocation (widget, &rect);
6339 dest = cairo_region_create_rectangle (&rect);
6341 cairo_region_intersect (dest, region);
6347 * _gtk_widget_grab_notify:
6348 * @widget: a #GtkWidget
6349 * @was_grabbed: whether a grab is now in effect
6351 * Emits the #GtkWidget::grab-notify signal on @widget.
6356 _gtk_widget_grab_notify (GtkWidget *widget,
6357 gboolean was_grabbed)
6359 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6363 * gtk_widget_grab_focus:
6364 * @widget: a #GtkWidget
6366 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6367 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6368 * something like #GtkFrame won't work.
6370 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6371 * gtk_widget_set_can_focus() to modify that flag.
6373 * The widget also needs to be realized and mapped. This is indicated by the
6374 * related signals. Grabbing the focus immediately after creating the widget
6375 * will likely fail and cause critical warnings.
6378 gtk_widget_grab_focus (GtkWidget *widget)
6380 g_return_if_fail (GTK_IS_WIDGET (widget));
6382 if (!gtk_widget_is_sensitive (widget))
6385 g_object_ref (widget);
6386 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6387 g_object_notify (G_OBJECT (widget), "has-focus");
6388 g_object_unref (widget);
6392 reset_focus_recurse (GtkWidget *widget,
6395 if (GTK_IS_CONTAINER (widget))
6397 GtkContainer *container;
6399 container = GTK_CONTAINER (widget);
6400 gtk_container_set_focus_child (container, NULL);
6402 gtk_container_foreach (container,
6403 reset_focus_recurse,
6409 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6411 if (gtk_widget_get_can_focus (focus_widget))
6413 GtkWidget *toplevel;
6416 /* clear the current focus setting, break if the current widget
6417 * is the focus widget's parent, since containers above that will
6418 * be set by the next loop.
6420 toplevel = gtk_widget_get_toplevel (focus_widget);
6421 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6423 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6425 if (widget == focus_widget)
6427 /* We call _gtk_window_internal_set_focus() here so that the
6428 * toplevel window can request the focus if necessary.
6429 * This is needed when the toplevel is a GtkPlug
6431 if (!gtk_widget_has_focus (widget))
6432 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6439 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
6441 widget = widget->priv->parent;
6442 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6446 else if (toplevel != focus_widget)
6448 /* gtk_widget_grab_focus() operates on a tree without window...
6449 * actually, this is very questionable behaviour.
6452 gtk_container_foreach (GTK_CONTAINER (toplevel),
6453 reset_focus_recurse,
6457 /* now propagate the new focus up the widget tree and finally
6458 * set it on the window
6460 widget = focus_widget;
6461 while (widget->priv->parent)
6463 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6464 widget = widget->priv->parent;
6466 if (GTK_IS_WINDOW (widget))
6467 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6472 gtk_widget_real_query_tooltip (GtkWidget *widget,
6475 gboolean keyboard_tip,
6476 GtkTooltip *tooltip)
6478 gchar *tooltip_markup;
6479 gboolean has_tooltip;
6481 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6482 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6484 if (has_tooltip && tooltip_markup)
6486 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6494 gtk_widget_real_style_updated (GtkWidget *widget)
6496 GtkWidgetPrivate *priv = widget->priv;
6498 if (priv->style != NULL &&
6499 priv->style != gtk_widget_get_default_style ())
6501 /* Trigger ::style-set for old
6502 * widgets not listening to this
6504 g_signal_emit (widget,
6505 widget_signals[STYLE_SET],
6507 widget->priv->style);
6510 if (widget->priv->context)
6512 if (gtk_widget_get_realized (widget) &&
6513 gtk_widget_get_has_window (widget))
6514 gtk_style_context_set_background (widget->priv->context,
6515 widget->priv->window);
6518 if (widget->priv->anchored)
6519 gtk_widget_queue_resize (widget);
6523 gtk_widget_real_show_help (GtkWidget *widget,
6524 GtkWidgetHelpType help_type)
6526 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6528 _gtk_tooltip_toggle_keyboard_mode (widget);
6537 gtk_widget_real_focus (GtkWidget *widget,
6538 GtkDirectionType direction)
6540 if (!gtk_widget_get_can_focus (widget))
6543 if (!gtk_widget_is_focus (widget))
6545 gtk_widget_grab_focus (widget);
6553 gtk_widget_real_move_focus (GtkWidget *widget,
6554 GtkDirectionType direction)
6556 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6558 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6560 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6566 gtk_widget_real_keynav_failed (GtkWidget *widget,
6567 GtkDirectionType direction)
6569 gboolean cursor_only;
6573 case GTK_DIR_TAB_FORWARD:
6574 case GTK_DIR_TAB_BACKWARD:
6581 g_object_get (gtk_widget_get_settings (widget),
6582 "gtk-keynav-cursor-only", &cursor_only,
6589 gtk_widget_error_bell (widget);
6595 * gtk_widget_set_can_focus:
6596 * @widget: a #GtkWidget
6597 * @can_focus: whether or not @widget can own the input focus.
6599 * Specifies whether @widget can own the input focus. See
6600 * gtk_widget_grab_focus() for actually setting the input focus on a
6606 gtk_widget_set_can_focus (GtkWidget *widget,
6609 g_return_if_fail (GTK_IS_WIDGET (widget));
6611 if (widget->priv->can_focus != can_focus)
6613 widget->priv->can_focus = can_focus;
6615 gtk_widget_queue_resize (widget);
6616 g_object_notify (G_OBJECT (widget), "can-focus");
6621 * gtk_widget_get_can_focus:
6622 * @widget: a #GtkWidget
6624 * Determines whether @widget can own the input focus. See
6625 * gtk_widget_set_can_focus().
6627 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6632 gtk_widget_get_can_focus (GtkWidget *widget)
6634 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6636 return widget->priv->can_focus;
6640 * gtk_widget_has_focus:
6641 * @widget: a #GtkWidget
6643 * Determines if the widget has the global input focus. See
6644 * gtk_widget_is_focus() for the difference between having the global
6645 * input focus, and only having the focus within a toplevel.
6647 * Return value: %TRUE if the widget has the global input focus.
6652 gtk_widget_has_focus (GtkWidget *widget)
6654 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6656 return widget->priv->has_focus;
6660 * gtk_widget_is_focus:
6661 * @widget: a #GtkWidget
6663 * Determines if the widget is the focus widget within its
6664 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6665 * necessarily set; %HAS_FOCUS will only be set if the
6666 * toplevel widget additionally has the global input focus.)
6668 * Return value: %TRUE if the widget is the focus widget.
6671 gtk_widget_is_focus (GtkWidget *widget)
6673 GtkWidget *toplevel;
6675 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6677 toplevel = gtk_widget_get_toplevel (widget);
6679 if (GTK_IS_WINDOW (toplevel))
6680 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6686 * gtk_widget_set_can_default:
6687 * @widget: a #GtkWidget
6688 * @can_default: whether or not @widget can be a default widget.
6690 * Specifies whether @widget can be a default widget. See
6691 * gtk_widget_grab_default() for details about the meaning of
6697 gtk_widget_set_can_default (GtkWidget *widget,
6698 gboolean can_default)
6700 g_return_if_fail (GTK_IS_WIDGET (widget));
6702 if (widget->priv->can_default != can_default)
6704 widget->priv->can_default = can_default;
6706 gtk_widget_queue_resize (widget);
6707 g_object_notify (G_OBJECT (widget), "can-default");
6712 * gtk_widget_get_can_default:
6713 * @widget: a #GtkWidget
6715 * Determines whether @widget can be a default widget. See
6716 * gtk_widget_set_can_default().
6718 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6723 gtk_widget_get_can_default (GtkWidget *widget)
6725 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6727 return widget->priv->can_default;
6731 * gtk_widget_has_default:
6732 * @widget: a #GtkWidget
6734 * Determines whether @widget is the current default widget within its
6735 * toplevel. See gtk_widget_set_can_default().
6737 * Return value: %TRUE if @widget is the current default widget within
6738 * its toplevel, %FALSE otherwise
6743 gtk_widget_has_default (GtkWidget *widget)
6745 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6747 return widget->priv->has_default;
6751 _gtk_widget_set_has_default (GtkWidget *widget,
6752 gboolean has_default)
6754 widget->priv->has_default = has_default;
6758 * gtk_widget_grab_default:
6759 * @widget: a #GtkWidget
6761 * Causes @widget to become the default widget. @widget must have the
6762 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6763 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6764 * %TRUE)</literal>. The default widget is activated when
6765 * the user presses Enter in a window. Default widgets must be
6766 * activatable, that is, gtk_widget_activate() should affect them. Note
6767 * that #GtkEntry widgets require the "activates-default" property
6768 * set to %TRUE before they activate the default widget when Enter
6769 * is pressed and the #GtkEntry is focused.
6772 gtk_widget_grab_default (GtkWidget *widget)
6776 g_return_if_fail (GTK_IS_WIDGET (widget));
6777 g_return_if_fail (gtk_widget_get_can_default (widget));
6779 window = gtk_widget_get_toplevel (widget);
6781 if (window && gtk_widget_is_toplevel (window))
6782 gtk_window_set_default (GTK_WINDOW (window), widget);
6784 g_warning (G_STRLOC ": widget not within a GtkWindow");
6788 * gtk_widget_set_receives_default:
6789 * @widget: a #GtkWidget
6790 * @receives_default: whether or not @widget can be a default widget.
6792 * Specifies whether @widget will be treated as the default widget
6793 * within its toplevel when it has the focus, even if another widget
6796 * See gtk_widget_grab_default() for details about the meaning of
6802 gtk_widget_set_receives_default (GtkWidget *widget,
6803 gboolean receives_default)
6805 g_return_if_fail (GTK_IS_WIDGET (widget));
6807 if (widget->priv->receives_default != receives_default)
6809 widget->priv->receives_default = receives_default;
6811 g_object_notify (G_OBJECT (widget), "receives-default");
6816 * gtk_widget_get_receives_default:
6817 * @widget: a #GtkWidget
6819 * Determines whether @widget is alyways treated as default widget
6820 * withing its toplevel when it has the focus, even if another widget
6823 * See gtk_widget_set_receives_default().
6825 * Return value: %TRUE if @widget acts as default widget when focussed,
6831 gtk_widget_get_receives_default (GtkWidget *widget)
6833 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6835 return widget->priv->receives_default;
6839 * gtk_widget_has_grab:
6840 * @widget: a #GtkWidget
6842 * Determines whether the widget is currently grabbing events, so it
6843 * is the only widget receiving input events (keyboard and mouse).
6845 * See also gtk_grab_add().
6847 * Return value: %TRUE if the widget is in the grab_widgets stack
6852 gtk_widget_has_grab (GtkWidget *widget)
6854 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6856 return widget->priv->has_grab;
6860 _gtk_widget_set_has_grab (GtkWidget *widget,
6863 widget->priv->has_grab = has_grab;
6867 * gtk_widget_device_is_shadowed:
6868 * @widget: a #GtkWidget
6869 * @device: a #GdkDevice
6871 * Returns %TRUE if @device has been shadowed by a GTK+
6872 * device grab on another widget, so it would stop sending
6873 * events to @widget. This may be used in the
6874 * #GtkWidget::grab-notify signal to check for specific
6875 * devices. See gtk_device_grab_add().
6877 * Returns: %TRUE if there is an ongoing grab on @device
6878 * by another #GtkWidget than @widget.
6883 gtk_widget_device_is_shadowed (GtkWidget *widget,
6886 GtkWindowGroup *group;
6887 GtkWidget *grab_widget, *toplevel;
6889 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6890 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6892 if (!gtk_widget_get_realized (widget))
6895 toplevel = gtk_widget_get_toplevel (widget);
6897 if (GTK_IS_WINDOW (toplevel))
6898 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6900 group = gtk_window_get_group (NULL);
6902 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6904 /* Widget not inside the hierarchy of grab_widget */
6906 widget != grab_widget &&
6907 !gtk_widget_is_ancestor (widget, grab_widget))
6910 grab_widget = gtk_window_group_get_current_grab (group);
6911 if (grab_widget && widget != grab_widget &&
6912 !gtk_widget_is_ancestor (widget, grab_widget))
6919 * gtk_widget_set_name:
6920 * @widget: a #GtkWidget
6921 * @name: name for the widget
6923 * Widgets can be named, which allows you to refer to them from a
6924 * CSS file. You can apply a style to widgets with a particular name
6925 * in the CSS file. See the documentation for the CSS syntax (on the
6926 * same page as the docs for #GtkStyleContext).
6928 * Note that the CSS syntax has certain special characters to delimit
6929 * and represent elements in a selector (period, #, >, *...),
6930 * so using these will make your widget impossible to match by name.
6931 * Any combination of alphanumeric symbols, dashes and underscores will
6935 gtk_widget_set_name (GtkWidget *widget,
6938 GtkWidgetPrivate *priv;
6941 g_return_if_fail (GTK_IS_WIDGET (widget));
6943 priv = widget->priv;
6945 new_name = g_strdup (name);
6946 g_free (priv->name);
6947 priv->name = new_name;
6949 gtk_widget_reset_style (widget);
6951 g_object_notify (G_OBJECT (widget), "name");
6955 * gtk_widget_get_name:
6956 * @widget: a #GtkWidget
6958 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6959 * significance of widget names.
6961 * Return value: name of the widget. This string is owned by GTK+ and
6962 * should not be modified or freed
6964 G_CONST_RETURN gchar*
6965 gtk_widget_get_name (GtkWidget *widget)
6967 GtkWidgetPrivate *priv;
6969 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6971 priv = widget->priv;
6975 return G_OBJECT_TYPE_NAME (widget);
6979 _gtk_widget_update_state_flags (GtkWidget *widget,
6980 GtkStateFlags flags,
6983 GtkWidgetPrivate *priv;
6985 priv = widget->priv;
6987 /* Handle insensitive first, since it is propagated
6988 * differently throughout the widget hierarchy.
6990 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_UNSET))
6991 gtk_widget_set_sensitive (widget, TRUE);
6992 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation != STATE_CHANGE_UNSET))
6993 gtk_widget_set_sensitive (widget, FALSE);
6994 else if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && !(flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_REPLACE))
6995 gtk_widget_set_sensitive (widget, TRUE);
6997 if (operation != STATE_CHANGE_REPLACE)
6998 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
7001 operation == STATE_CHANGE_REPLACE)
7006 data.operation = operation;
7007 data.use_forall = FALSE;
7009 gtk_widget_propagate_state (widget, &data);
7011 gtk_widget_queue_resize (widget);
7016 * gtk_widget_set_state_flags:
7017 * @widget: a #GtkWidget
7018 * @flags: State flags to turn on
7019 * @clear: Whether to clear state before turning on @flags
7021 * This function is for use in widget implementations. Turns on flag
7022 * values in the current widget state (insensitive, prelighted, etc.).
7024 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7025 * will be propagated down to all non-internal children if @widget is a
7026 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7027 * down to all #GtkContainer children by different means than turning on the
7028 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7029 * gtk_widget_is_sensitive() will make use of these.
7034 gtk_widget_set_state_flags (GtkWidget *widget,
7035 GtkStateFlags flags,
7038 g_return_if_fail (GTK_IS_WIDGET (widget));
7040 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7041 (clear && widget->priv->state_flags == flags))
7045 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7047 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
7051 * gtk_widget_unset_state_flags:
7052 * @widget: a #GtkWidget
7053 * @flags: State flags to turn off
7055 * This function is for use in widget implementations. Turns off flag
7056 * values for the current widget state (insensitive, prelighted, etc.).
7057 * See gtk_widget_set_state_flags().
7062 gtk_widget_unset_state_flags (GtkWidget *widget,
7063 GtkStateFlags flags)
7065 g_return_if_fail (GTK_IS_WIDGET (widget));
7067 if ((widget->priv->state_flags & flags) == 0)
7070 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
7074 * gtk_widget_get_state_flags:
7075 * @widget: a #GtkWidget
7077 * Returns the widget state as a flag set. It is worth mentioning
7078 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7079 * returned, that is, also based on parent insensitivity, even if
7080 * @widget itself is sensitive.
7082 * Returns: The state flags for widget
7087 gtk_widget_get_state_flags (GtkWidget *widget)
7089 GtkStateFlags flags;
7091 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7093 flags = widget->priv->state_flags;
7095 if (gtk_widget_has_focus (widget))
7096 flags |= GTK_STATE_FLAG_FOCUSED;
7102 * gtk_widget_set_state:
7103 * @widget: a #GtkWidget
7104 * @state: new state for @widget
7106 * This function is for use in widget implementations. Sets the state
7107 * of a widget (insensitive, prelighted, etc.) Usually you should set
7108 * the state using wrapper functions such as gtk_widget_set_sensitive().
7110 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7113 gtk_widget_set_state (GtkWidget *widget,
7116 GtkStateFlags flags;
7118 if (state == gtk_widget_get_state (widget))
7123 case GTK_STATE_ACTIVE:
7124 flags = GTK_STATE_FLAG_ACTIVE;
7126 case GTK_STATE_PRELIGHT:
7127 flags = GTK_STATE_FLAG_PRELIGHT;
7129 case GTK_STATE_SELECTED:
7130 flags = GTK_STATE_FLAG_SELECTED;
7132 case GTK_STATE_INSENSITIVE:
7133 flags = GTK_STATE_FLAG_INSENSITIVE;
7135 case GTK_STATE_INCONSISTENT:
7136 flags = GTK_STATE_FLAG_INCONSISTENT;
7138 case GTK_STATE_FOCUSED:
7139 flags = GTK_STATE_FLAG_FOCUSED;
7141 case GTK_STATE_NORMAL:
7147 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7151 * gtk_widget_get_state:
7152 * @widget: a #GtkWidget
7154 * Returns the widget's state. See gtk_widget_set_state().
7156 * Returns: the state of @widget.
7160 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7163 gtk_widget_get_state (GtkWidget *widget)
7165 GtkStateFlags flags;
7167 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7169 flags = gtk_widget_get_state_flags (widget);
7171 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7172 return GTK_STATE_INSENSITIVE;
7173 else if (flags & GTK_STATE_FLAG_ACTIVE)
7174 return GTK_STATE_ACTIVE;
7175 else if (flags & GTK_STATE_FLAG_SELECTED)
7176 return GTK_STATE_SELECTED;
7177 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7178 return GTK_STATE_PRELIGHT;
7180 return GTK_STATE_NORMAL;
7184 * gtk_widget_set_visible:
7185 * @widget: a #GtkWidget
7186 * @visible: whether the widget should be shown or not
7188 * Sets the visibility state of @widget. Note that setting this to
7189 * %TRUE doesn't mean the widget is actually viewable, see
7190 * gtk_widget_get_visible().
7192 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7193 * but is nicer to use when the visibility of the widget depends on
7199 gtk_widget_set_visible (GtkWidget *widget,
7202 g_return_if_fail (GTK_IS_WIDGET (widget));
7204 if (visible != gtk_widget_get_visible (widget))
7207 gtk_widget_show (widget);
7209 gtk_widget_hide (widget);
7214 _gtk_widget_set_visible_flag (GtkWidget *widget,
7217 widget->priv->visible = visible;
7221 * gtk_widget_get_visible:
7222 * @widget: a #GtkWidget
7224 * Determines whether the widget is visible. Note that this doesn't
7225 * take into account whether the widget's parent is also visible
7226 * or the widget is obscured in any way.
7228 * See gtk_widget_set_visible().
7230 * Return value: %TRUE if the widget is visible
7235 gtk_widget_get_visible (GtkWidget *widget)
7237 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7239 return widget->priv->visible;
7243 * gtk_widget_set_has_window:
7244 * @widget: a #GtkWidget
7245 * @has_window: whether or not @widget has a window.
7247 * Specifies whether @widget has a #GdkWindow of its own. Note that
7248 * all realized widgets have a non-%NULL "window" pointer
7249 * (gtk_widget_get_window() never returns a %NULL window when a widget
7250 * is realized), but for many of them it's actually the #GdkWindow of
7251 * one of its parent widgets. Widgets that do not create a %window for
7252 * themselves in #GtkWidget::realize must announce this by
7253 * calling this function with @has_window = %FALSE.
7255 * This function should only be called by widget implementations,
7256 * and they should call it in their init() function.
7261 gtk_widget_set_has_window (GtkWidget *widget,
7262 gboolean has_window)
7264 g_return_if_fail (GTK_IS_WIDGET (widget));
7266 widget->priv->no_window = !has_window;
7270 * gtk_widget_get_has_window:
7271 * @widget: a #GtkWidget
7273 * Determines whether @widget has a #GdkWindow of its own. See
7274 * gtk_widget_set_has_window().
7276 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7281 gtk_widget_get_has_window (GtkWidget *widget)
7283 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7285 return ! widget->priv->no_window;
7289 * gtk_widget_is_toplevel:
7290 * @widget: a #GtkWidget
7292 * Determines whether @widget is a toplevel widget.
7294 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7295 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7298 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7303 gtk_widget_is_toplevel (GtkWidget *widget)
7305 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7307 return widget->priv->toplevel;
7311 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7312 gboolean is_toplevel)
7314 widget->priv->toplevel = is_toplevel;
7318 * gtk_widget_is_drawable:
7319 * @widget: a #GtkWidget
7321 * Determines whether @widget can be drawn to. A widget can be drawn
7322 * to if it is mapped and visible.
7324 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7329 gtk_widget_is_drawable (GtkWidget *widget)
7331 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7333 return (gtk_widget_get_visible (widget) &&
7334 gtk_widget_get_mapped (widget));
7338 * gtk_widget_get_realized:
7339 * @widget: a #GtkWidget
7341 * Determines whether @widget is realized.
7343 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7348 gtk_widget_get_realized (GtkWidget *widget)
7350 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7352 return widget->priv->realized;
7356 * gtk_widget_set_realized:
7357 * @widget: a #GtkWidget
7358 * @realized: %TRUE to mark the widget as realized
7360 * Marks the widget as being realized.
7362 * This function should only ever be called in a derived widget's
7363 * "realize" or "unrealize" implementation.
7368 gtk_widget_set_realized (GtkWidget *widget,
7371 g_return_if_fail (GTK_IS_WIDGET (widget));
7373 widget->priv->realized = realized;
7377 * gtk_widget_get_mapped:
7378 * @widget: a #GtkWidget
7380 * Whether the widget is mapped.
7382 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7387 gtk_widget_get_mapped (GtkWidget *widget)
7389 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7391 return widget->priv->mapped;
7395 * gtk_widget_set_mapped:
7396 * @widget: a #GtkWidget
7397 * @mapped: %TRUE to mark the widget as mapped
7399 * Marks the widget as being realized.
7401 * This function should only ever be called in a derived widget's
7402 * "map" or "unmap" implementation.
7407 gtk_widget_set_mapped (GtkWidget *widget,
7410 g_return_if_fail (GTK_IS_WIDGET (widget));
7412 widget->priv->mapped = mapped;
7416 * gtk_widget_set_app_paintable:
7417 * @widget: a #GtkWidget
7418 * @app_paintable: %TRUE if the application will paint on the widget
7420 * Sets whether the application intends to draw on the widget in
7421 * an #GtkWidget::draw handler.
7423 * This is a hint to the widget and does not affect the behavior of
7424 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7425 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7426 * the effect is to suppress default themed drawing of the widget's
7427 * background. (Children of the widget will still be drawn.) The application
7428 * is then entirely responsible for drawing the widget background.
7430 * Note that the background is still drawn when the widget is mapped.
7433 gtk_widget_set_app_paintable (GtkWidget *widget,
7434 gboolean app_paintable)
7436 g_return_if_fail (GTK_IS_WIDGET (widget));
7438 app_paintable = (app_paintable != FALSE);
7440 if (widget->priv->app_paintable != app_paintable)
7442 widget->priv->app_paintable = app_paintable;
7444 if (gtk_widget_is_drawable (widget))
7445 gtk_widget_queue_draw (widget);
7447 g_object_notify (G_OBJECT (widget), "app-paintable");
7452 * gtk_widget_get_app_paintable:
7453 * @widget: a #GtkWidget
7455 * Determines whether the application intends to draw on the widget in
7456 * an #GtkWidget::draw handler.
7458 * See gtk_widget_set_app_paintable()
7460 * Return value: %TRUE if the widget is app paintable
7465 gtk_widget_get_app_paintable (GtkWidget *widget)
7467 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7469 return widget->priv->app_paintable;
7473 * gtk_widget_set_double_buffered:
7474 * @widget: a #GtkWidget
7475 * @double_buffered: %TRUE to double-buffer a widget
7477 * Widgets are double buffered by default; you can use this function
7478 * to turn off the buffering. "Double buffered" simply means that
7479 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7480 * automatically around expose events sent to the
7481 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7482 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7483 * buffer to the screen. The result is that users see the window
7484 * update in one smooth step, and don't see individual graphics
7485 * primitives being rendered.
7487 * In very simple terms, double buffered widgets don't flicker,
7488 * so you would only use this function to turn off double buffering
7489 * if you had special needs and really knew what you were doing.
7491 * Note: if you turn off double-buffering, you have to handle
7492 * expose events, since even the clearing to the background color or
7493 * pixmap will not happen automatically (as it is done in
7494 * gdk_window_begin_paint()).
7497 gtk_widget_set_double_buffered (GtkWidget *widget,
7498 gboolean double_buffered)
7500 g_return_if_fail (GTK_IS_WIDGET (widget));
7502 double_buffered = (double_buffered != FALSE);
7504 if (widget->priv->double_buffered != double_buffered)
7506 widget->priv->double_buffered = double_buffered;
7508 g_object_notify (G_OBJECT (widget), "double-buffered");
7513 * gtk_widget_get_double_buffered:
7514 * @widget: a #GtkWidget
7516 * Determines whether the widget is double buffered.
7518 * See gtk_widget_set_double_buffered()
7520 * Return value: %TRUE if the widget is double buffered
7525 gtk_widget_get_double_buffered (GtkWidget *widget)
7527 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7529 return widget->priv->double_buffered;
7533 * gtk_widget_set_redraw_on_allocate:
7534 * @widget: a #GtkWidget
7535 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7536 * when it is allocated to a new size. Otherwise, only the
7537 * new portion of the widget will be redrawn.
7539 * Sets whether the entire widget is queued for drawing when its size
7540 * allocation changes. By default, this setting is %TRUE and
7541 * the entire widget is redrawn on every size change. If your widget
7542 * leaves the upper left unchanged when made bigger, turning this
7543 * setting off will improve performance.
7545 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7546 * off all allocation on resizing: the widget will not even redraw if
7547 * its position changes; this is to allow containers that don't draw
7548 * anything to avoid excess invalidations. If you set this flag on a
7549 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7550 * you are responsible for invalidating both the old and new allocation
7551 * of the widget when the widget is moved and responsible for invalidating
7552 * regions newly when the widget increases size.
7555 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7556 gboolean redraw_on_allocate)
7558 g_return_if_fail (GTK_IS_WIDGET (widget));
7560 widget->priv->redraw_on_alloc = redraw_on_allocate;
7564 * gtk_widget_set_sensitive:
7565 * @widget: a #GtkWidget
7566 * @sensitive: %TRUE to make the widget sensitive
7568 * Sets the sensitivity of a widget. A widget is sensitive if the user
7569 * can interact with it. Insensitive widgets are "grayed out" and the
7570 * user can't interact with them. Insensitive widgets are known as
7571 * "inactive", "disabled", or "ghosted" in some other toolkits.
7574 gtk_widget_set_sensitive (GtkWidget *widget,
7577 GtkWidgetPrivate *priv;
7580 g_return_if_fail (GTK_IS_WIDGET (widget));
7582 priv = widget->priv;
7584 sensitive = (sensitive != FALSE);
7586 if (priv->sensitive == sensitive)
7589 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7593 priv->sensitive = TRUE;
7594 data.operation = STATE_CHANGE_UNSET;
7598 priv->sensitive = FALSE;
7599 data.operation = STATE_CHANGE_SET;
7602 data.use_forall = TRUE;
7604 gtk_widget_propagate_state (widget, &data);
7606 gtk_widget_queue_resize (widget);
7608 g_object_notify (G_OBJECT (widget), "sensitive");
7612 * gtk_widget_get_sensitive:
7613 * @widget: a #GtkWidget
7615 * Returns the widget's sensitivity (in the sense of returning
7616 * the value that has been set using gtk_widget_set_sensitive()).
7618 * The effective sensitivity of a widget is however determined by both its
7619 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7621 * Returns: %TRUE if the widget is sensitive
7626 gtk_widget_get_sensitive (GtkWidget *widget)
7628 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7630 return widget->priv->sensitive;
7634 * gtk_widget_is_sensitive:
7635 * @widget: a #GtkWidget
7637 * Returns the widget's effective sensitivity, which means
7638 * it is sensitive itself and also its parent widget is sensitive
7640 * Returns: %TRUE if the widget is effectively sensitive
7645 gtk_widget_is_sensitive (GtkWidget *widget)
7647 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7649 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
7653 _gtk_widget_update_path (GtkWidget *widget)
7655 if (widget->priv->path)
7657 gtk_widget_path_free (widget->priv->path);
7658 widget->priv->path = NULL;
7661 gtk_widget_get_path (widget);
7665 * gtk_widget_set_parent:
7666 * @widget: a #GtkWidget
7667 * @parent: parent container
7669 * This function is useful only when implementing subclasses of
7671 * Sets the container as the parent of @widget, and takes care of
7672 * some details such as updating the state and style of the child
7673 * to reflect its new location. The opposite function is
7674 * gtk_widget_unparent().
7677 gtk_widget_set_parent (GtkWidget *widget,
7680 GtkStateFlags parent_flags;
7681 GtkWidgetPrivate *priv;
7684 g_return_if_fail (GTK_IS_WIDGET (widget));
7685 g_return_if_fail (GTK_IS_WIDGET (parent));
7686 g_return_if_fail (widget != parent);
7688 priv = widget->priv;
7690 if (priv->parent != NULL)
7692 g_warning ("Can't set a parent on widget which has a parent\n");
7695 if (gtk_widget_is_toplevel (widget))
7697 g_warning ("Can't set a parent on a toplevel widget\n");
7701 /* keep this function in sync with gtk_menu_attach_to_widget()
7704 g_object_ref_sink (widget);
7706 gtk_widget_push_verify_invariants (widget);
7708 priv->parent = parent;
7710 parent_flags = gtk_widget_get_state_flags (parent);
7712 /* Merge both old state and current parent state,
7713 * making sure to only propagate the right states */
7714 data.flags = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
7715 data.flags |= priv->state_flags;
7717 data.operation = STATE_CHANGE_REPLACE;
7718 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7719 gtk_widget_propagate_state (widget, &data);
7721 gtk_widget_reset_style (widget);
7723 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7724 if (priv->parent->priv->anchored)
7725 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7726 g_object_notify (G_OBJECT (widget), "parent");
7728 /* Enforce realized/mapped invariants
7730 if (gtk_widget_get_realized (priv->parent))
7731 gtk_widget_realize (widget);
7733 if (gtk_widget_get_visible (priv->parent) &&
7734 gtk_widget_get_visible (widget))
7736 if (gtk_widget_get_child_visible (widget) &&
7737 gtk_widget_get_mapped (priv->parent))
7738 gtk_widget_map (widget);
7740 gtk_widget_queue_resize (widget);
7743 /* child may cause parent's expand to change, if the child is
7744 * expanded. If child is not expanded, then it can't modify the
7745 * parent's expand. If the child becomes expanded later then it will
7746 * queue compute_expand then. This optimization plus defaulting
7747 * newly-constructed widgets to need_compute_expand=FALSE should
7748 * mean that initially building a widget tree doesn't have to keep
7749 * walking up setting need_compute_expand on parents over and over.
7751 * We can't change a parent to need to expand unless we're visible.
7753 if (gtk_widget_get_visible (widget) &&
7754 (priv->need_compute_expand ||
7755 priv->computed_hexpand ||
7756 priv->computed_vexpand))
7758 gtk_widget_queue_compute_expand (parent);
7761 gtk_widget_pop_verify_invariants (widget);
7765 * gtk_widget_get_parent:
7766 * @widget: a #GtkWidget
7768 * Returns the parent container of @widget.
7770 * Return value: (transfer none): the parent container of @widget, or %NULL
7773 gtk_widget_get_parent (GtkWidget *widget)
7775 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7777 return widget->priv->parent;
7780 /*****************************************
7782 * see docs/styles.txt
7783 *****************************************/
7786 * gtk_widget_style_attach:
7787 * @widget: a #GtkWidget
7789 * This function attaches the widget's #GtkStyle to the widget's
7790 * #GdkWindow. It is a replacement for
7793 * widget->style = gtk_style_attach (widget->style, widget->window);
7796 * and should only ever be called in a derived widget's "realize"
7797 * implementation which does not chain up to its parent class'
7798 * "realize" implementation, because one of the parent classes
7799 * (finally #GtkWidget) would attach the style itself.
7803 * Deprecated: 3.0. This step is unnecessary with #GtkStyleContext.
7806 gtk_widget_style_attach (GtkWidget *widget)
7808 g_return_if_fail (GTK_IS_WIDGET (widget));
7809 g_return_if_fail (gtk_widget_get_realized (widget));
7813 * gtk_widget_has_rc_style:
7814 * @widget: a #GtkWidget
7816 * Determines if the widget style has been looked up through the rc mechanism.
7818 * Returns: %TRUE if the widget has been looked up through the rc
7819 * mechanism, %FALSE otherwise.
7823 * Deprecated:3.0: Use #GtkStyleContext instead
7826 gtk_widget_has_rc_style (GtkWidget *widget)
7828 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7830 return widget->priv->rc_style;
7834 * gtk_widget_set_style:
7835 * @widget: a #GtkWidget
7836 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect
7837 * of a previous call to gtk_widget_set_style() and go back to
7840 * Used to set the #GtkStyle for a widget (@widget->style). Since
7841 * GTK 3, this function does nothing, the passed in style is ignored.
7843 * Deprecated:3.0: Use #GtkStyleContext instead
7846 gtk_widget_set_style (GtkWidget *widget,
7849 g_return_if_fail (GTK_IS_WIDGET (widget));
7853 * gtk_widget_ensure_style:
7854 * @widget: a #GtkWidget
7856 * Ensures that @widget has a style (@widget->style).
7858 * Not a very useful function; most of the time, if you
7859 * want the style, the widget is realized, and realized
7860 * widgets are guaranteed to have a style already.
7862 * Deprecated:3.0: Use #GtkStyleContext instead
7865 gtk_widget_ensure_style (GtkWidget *widget)
7867 GtkWidgetPrivate *priv;
7869 g_return_if_fail (GTK_IS_WIDGET (widget));
7871 priv = widget->priv;
7873 if (priv->style == gtk_widget_get_default_style ())
7875 g_object_unref (priv->style);
7879 g_signal_emit (widget,
7880 widget_signals[STYLE_SET],
7886 * gtk_widget_get_style:
7887 * @widget: a #GtkWidget
7889 * Simply an accessor function that returns @widget->style.
7891 * Return value: (transfer none): the widget's #GtkStyle
7893 * Deprecated:3.0: Use #GtkStyleContext instead
7896 gtk_widget_get_style (GtkWidget *widget)
7898 GtkWidgetPrivate *priv;
7900 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7902 priv = widget->priv;
7904 if (priv->style == NULL)
7906 priv->style = g_object_new (GTK_TYPE_STYLE,
7907 "context", gtk_widget_get_style_context (widget),
7916 * gtk_widget_modify_style:
7917 * @widget: a #GtkWidget
7918 * @style: the #GtkRcStyle holding the style modifications
7920 * Modifies style values on the widget.
7922 * Modifications made using this technique take precedence over
7923 * style values set via an RC file, however, they will be overridden
7924 * if a style is explicitely set on the widget using gtk_widget_set_style().
7925 * The #GtkRcStyle structure is designed so each field can either be
7926 * set or unset, so it is possible, using this function, to modify some
7927 * style values and leave the others unchanged.
7929 * Note that modifications made with this function are not cumulative
7930 * with previous calls to gtk_widget_modify_style() or with such
7931 * functions as gtk_widget_modify_fg(). If you wish to retain
7932 * previous values, you must first call gtk_widget_get_modifier_style(),
7933 * make your modifications to the returned style, then call
7934 * gtk_widget_modify_style() with that style. On the other hand,
7935 * if you first call gtk_widget_modify_style(), subsequent calls
7936 * to such functions gtk_widget_modify_fg() will have a cumulative
7937 * effect with the initial modifications.
7939 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7942 gtk_widget_modify_style (GtkWidget *widget,
7945 g_return_if_fail (GTK_IS_WIDGET (widget));
7946 g_return_if_fail (GTK_IS_RC_STYLE (style));
7948 g_object_set_qdata_full (G_OBJECT (widget),
7950 gtk_rc_style_copy (style),
7951 (GDestroyNotify) g_object_unref);
7955 * gtk_widget_get_modifier_style:
7956 * @widget: a #GtkWidget
7958 * Returns the current modifier style for the widget. (As set by
7959 * gtk_widget_modify_style().) If no style has previously set, a new
7960 * #GtkRcStyle will be created with all values unset, and set as the
7961 * modifier style for the widget. If you make changes to this rc
7962 * style, you must call gtk_widget_modify_style(), passing in the
7963 * returned rc style, to make sure that your changes take effect.
7965 * Caution: passing the style back to gtk_widget_modify_style() will
7966 * normally end up destroying it, because gtk_widget_modify_style() copies
7967 * the passed-in style and sets the copy as the new modifier style,
7968 * thus dropping any reference to the old modifier style. Add a reference
7969 * to the modifier style if you want to keep it alive.
7971 * Return value: (transfer none): the modifier style for the widget.
7972 * This rc style is owned by the widget. If you want to keep a
7973 * pointer to value this around, you must add a refcount using
7976 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7979 gtk_widget_get_modifier_style (GtkWidget *widget)
7981 GtkRcStyle *rc_style;
7983 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7985 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7989 rc_style = gtk_rc_style_new ();
7990 g_object_set_qdata_full (G_OBJECT (widget),
7993 (GDestroyNotify) g_object_unref);
8000 gtk_widget_modify_color_component (GtkWidget *widget,
8001 GtkRcFlags component,
8003 const GdkColor *color)
8005 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
8012 rc_style->fg[state] = *color;
8015 rc_style->bg[state] = *color;
8018 rc_style->text[state] = *color;
8021 rc_style->base[state] = *color;
8024 g_assert_not_reached();
8027 rc_style->color_flags[state] |= component;
8030 rc_style->color_flags[state] &= ~component;
8032 gtk_widget_modify_style (widget, rc_style);
8036 modifier_style_changed (GtkModifierStyle *style,
8039 GtkStyleContext *context;
8041 context = gtk_widget_get_style_context (widget);
8042 gtk_style_context_invalidate (context);
8045 static GtkModifierStyle *
8046 _gtk_widget_get_modifier_properties (GtkWidget *widget)
8048 GtkModifierStyle *style;
8050 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
8052 if (G_UNLIKELY (!style))
8054 GtkStyleContext *context;
8056 style = _gtk_modifier_style_new ();
8057 g_object_set_qdata_full (G_OBJECT (widget),
8058 quark_modifier_style,
8060 (GDestroyNotify) g_object_unref);
8062 g_signal_connect (style, "changed",
8063 G_CALLBACK (modifier_style_changed), widget);
8065 context = gtk_widget_get_style_context (widget);
8067 gtk_style_context_add_provider (context,
8068 GTK_STYLE_PROVIDER (style),
8069 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
8076 * gtk_widget_override_color:
8077 * @widget: a #GtkWidget
8078 * @state: the state for which to set the color
8079 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8080 * of previous calls to gtk_widget_override_color()
8082 * Sets the color to use for a widget.
8084 * All other style values are left untouched.
8087 * This API is mostly meant as a quick way for applications to
8088 * change a widget appearance. If you are developing a widgets
8089 * library and intend this change to be themeable, it is better
8090 * done by setting meaningful CSS classes and regions in your
8091 * widget/container implementation through gtk_style_context_add_class()
8092 * and gtk_style_context_add_region().
8094 * This way, your widget library can install a #GtkCssProvider
8095 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
8096 * to provide a default styling for those widgets that need so, and
8097 * this theming may fully overridden by the user's theme.
8100 * Note that for complex widgets this may bring in undesired
8101 * results (such as uniform background color everywhere), in
8102 * these cases it is better to fully style such widgets through a
8103 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8110 gtk_widget_override_color (GtkWidget *widget,
8111 GtkStateFlags state,
8112 const GdkRGBA *color)
8114 GtkModifierStyle *style;
8116 g_return_if_fail (GTK_IS_WIDGET (widget));
8118 style = _gtk_widget_get_modifier_properties (widget);
8119 _gtk_modifier_style_set_color (style, state, color);
8123 * gtk_widget_override_background_color:
8124 * @widget: a #GtkWidget
8125 * @state: the state for which to set the background color
8126 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8127 * of previous calls to gtk_widget_override_background_color()
8129 * Sets the background color to use for a widget.
8131 * All other style values are left untouched.
8132 * See gtk_widget_override_color().
8137 gtk_widget_override_background_color (GtkWidget *widget,
8138 GtkStateFlags state,
8139 const GdkRGBA *color)
8141 GtkModifierStyle *style;
8143 g_return_if_fail (GTK_IS_WIDGET (widget));
8145 style = _gtk_widget_get_modifier_properties (widget);
8146 _gtk_modifier_style_set_background_color (style, state, color);
8150 * gtk_widget_override_font:
8151 * @widget: a #GtkWidget
8152 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
8153 * the effect of previous calls to gtk_widget_override_font()
8155 * Sets the font to use for a widget. All other style values are
8156 * left untouched. See gtk_widget_override_color().
8161 gtk_widget_override_font (GtkWidget *widget,
8162 const PangoFontDescription *font_desc)
8164 GtkModifierStyle *style;
8166 g_return_if_fail (GTK_IS_WIDGET (widget));
8168 style = _gtk_widget_get_modifier_properties (widget);
8169 _gtk_modifier_style_set_font (style, font_desc);
8173 * gtk_widget_override_symbolic_color:
8174 * @widget: a #GtkWidget
8175 * @name: the name of the symbolic color to modify
8176 * @color: (allow-none): the color to assign (does not need
8177 * to be allocated), or %NULL to undo the effect of previous
8178 * calls to gtk_widget_override_symbolic_color()
8180 * Sets a symbolic color for a widget.
8182 * All other style values are left untouched.
8183 * See gtk_widget_override_color() for overriding the foreground
8184 * or background color.
8189 gtk_widget_override_symbolic_color (GtkWidget *widget,
8191 const GdkRGBA *color)
8193 GtkModifierStyle *style;
8195 g_return_if_fail (GTK_IS_WIDGET (widget));
8197 style = _gtk_widget_get_modifier_properties (widget);
8198 _gtk_modifier_style_map_color (style, name, color);
8202 * gtk_widget_override_cursor:
8203 * @widget: a #GtkWidget
8204 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8205 * allocated), or %NULL to undo the effect of previous calls to
8206 * of gtk_widget_override_cursor().
8207 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8208 * need to be allocated), or %NULL to undo the effect of previous
8209 * calls to of gtk_widget_override_cursor().
8211 * Sets the cursor color to use in a widget, overriding the
8212 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8213 * style properties. All other style values are left untouched.
8214 * See also gtk_widget_modify_style().
8216 * Note that the underlying properties have the #GdkColor type,
8217 * so the alpha value in @primary and @secondary will be ignored.
8222 gtk_widget_override_cursor (GtkWidget *widget,
8223 const GdkRGBA *cursor,
8224 const GdkRGBA *secondary_cursor)
8226 GtkModifierStyle *style;
8228 g_return_if_fail (GTK_IS_WIDGET (widget));
8230 style = _gtk_widget_get_modifier_properties (widget);
8231 _gtk_modifier_style_set_color_property (style,
8233 "cursor-color", cursor);
8234 _gtk_modifier_style_set_color_property (style,
8236 "secondary-cursor-color",
8241 * gtk_widget_modify_fg:
8242 * @widget: a #GtkWidget
8243 * @state: the state for which to set the foreground color
8244 * @color: (allow-none): the color to assign (does not need to be allocated),
8245 * or %NULL to undo the effect of previous calls to
8246 * of gtk_widget_modify_fg().
8248 * Sets the foreground color for a widget in a particular state.
8250 * All other style values are left untouched.
8251 * See also gtk_widget_modify_style().
8253 * Deprecated:3.0: Use gtk_widget_override_color() instead
8256 gtk_widget_modify_fg (GtkWidget *widget,
8258 const GdkColor *color)
8260 GtkStateFlags flags;
8263 g_return_if_fail (GTK_IS_WIDGET (widget));
8264 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8268 case GTK_STATE_ACTIVE:
8269 flags = GTK_STATE_FLAG_ACTIVE;
8271 case GTK_STATE_PRELIGHT:
8272 flags = GTK_STATE_FLAG_PRELIGHT;
8274 case GTK_STATE_SELECTED:
8275 flags = GTK_STATE_FLAG_SELECTED;
8277 case GTK_STATE_INSENSITIVE:
8278 flags = GTK_STATE_FLAG_INSENSITIVE;
8280 case GTK_STATE_NORMAL:
8287 rgba.red = color->red / 65535.;
8288 rgba.green = color->green / 65535.;
8289 rgba.blue = color->blue / 65535.;
8292 gtk_widget_override_color (widget, flags, &rgba);
8295 gtk_widget_override_color (widget, flags, NULL);
8299 * gtk_widget_modify_bg:
8300 * @widget: a #GtkWidget
8301 * @state: the state for which to set the background color
8302 * @color: (allow-none): the color to assign (does not need
8303 * to be allocated), or %NULL to undo the effect of previous
8304 * calls to of gtk_widget_modify_bg().
8306 * Sets the background color for a widget in a particular state.
8308 * All other style values are left untouched.
8309 * See also gtk_widget_modify_style().
8312 * Note that "no window" widgets (which have the %GTK_NO_WINDOW
8313 * flag set) draw on their parent container's window and thus may
8314 * not draw any background themselves. This is the case for e.g.
8317 * To modify the background of such widgets, you have to set the
8318 * background color on their parent; if you want to set the background
8319 * of a rectangular area around a label, try placing the label in
8320 * a #GtkEventBox widget and setting the background color on that.
8323 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8326 gtk_widget_modify_bg (GtkWidget *widget,
8328 const GdkColor *color)
8330 GtkStateFlags flags;
8333 g_return_if_fail (GTK_IS_WIDGET (widget));
8334 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8338 case GTK_STATE_ACTIVE:
8339 flags = GTK_STATE_FLAG_ACTIVE;
8341 case GTK_STATE_PRELIGHT:
8342 flags = GTK_STATE_FLAG_PRELIGHT;
8344 case GTK_STATE_SELECTED:
8345 flags = GTK_STATE_FLAG_SELECTED;
8347 case GTK_STATE_INSENSITIVE:
8348 flags = GTK_STATE_FLAG_INSENSITIVE;
8350 case GTK_STATE_NORMAL:
8357 rgba.red = color->red / 65535.;
8358 rgba.green = color->green / 65535.;
8359 rgba.blue = color->blue / 65535.;
8362 gtk_widget_override_background_color (widget, flags, &rgba);
8365 gtk_widget_override_background_color (widget, flags, NULL);
8369 * gtk_widget_modify_text:
8370 * @widget: a #GtkWidget
8371 * @state: the state for which to set the text color
8372 * @color: (allow-none): the color to assign (does not need to
8373 * be allocated), or %NULL to undo the effect of previous
8374 * calls to of gtk_widget_modify_text().
8376 * Sets the text color for a widget in a particular state.
8378 * All other style values are left untouched.
8379 * The text color is the foreground color used along with the
8380 * base color (see gtk_widget_modify_base()) for widgets such
8381 * as #GtkEntry and #GtkTextView.
8382 * See also gtk_widget_modify_style().
8384 * Deprecated:3.0: Use gtk_widget_override_color() instead
8387 gtk_widget_modify_text (GtkWidget *widget,
8389 const GdkColor *color)
8391 g_return_if_fail (GTK_IS_WIDGET (widget));
8392 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8394 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
8398 * gtk_widget_modify_base:
8399 * @widget: a #GtkWidget
8400 * @state: the state for which to set the base color
8401 * @color: (allow-none): the color to assign (does not need to
8402 * be allocated), or %NULL to undo the effect of previous
8403 * calls to of gtk_widget_modify_base().
8405 * Sets the base color for a widget in a particular state.
8406 * All other style values are left untouched. The base color
8407 * is the background color used along with the text color
8408 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
8409 * and #GtkTextView. See also gtk_widget_modify_style().
8412 * Note that "no window" widgets (which have the %GTK_NO_WINDOW
8413 * flag set) draw on their parent container's window and thus may
8414 * not draw any background themselves. This is the case for e.g.
8417 * To modify the background of such widgets, you have to set the
8418 * base color on their parent; if you want to set the background
8419 * of a rectangular area around a label, try placing the label in
8420 * a #GtkEventBox widget and setting the base color on that.
8423 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8426 gtk_widget_modify_base (GtkWidget *widget,
8428 const GdkColor *color)
8430 g_return_if_fail (GTK_IS_WIDGET (widget));
8431 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8433 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
8437 * gtk_widget_modify_cursor:
8438 * @widget: a #GtkWidget
8439 * @primary: the color to use for primary cursor (does not need to be
8440 * allocated), or %NULL to undo the effect of previous calls to
8441 * of gtk_widget_modify_cursor().
8442 * @secondary: the color to use for secondary cursor (does not need to be
8443 * allocated), or %NULL to undo the effect of previous calls to
8444 * of gtk_widget_modify_cursor().
8446 * Sets the cursor color to use in a widget, overriding the
8447 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8450 * All other style values are left untouched.
8451 * See also gtk_widget_modify_style().
8455 * Deprecated: 3.0. Use gtk_widget_override_cursor() instead.
8458 gtk_widget_modify_cursor (GtkWidget *widget,
8459 const GdkColor *primary,
8460 const GdkColor *secondary)
8462 GdkRGBA primary_rgba, secondary_rgba;
8464 g_return_if_fail (GTK_IS_WIDGET (widget));
8466 primary_rgba.red = primary->red / 65535.;
8467 primary_rgba.green = primary->green / 65535.;
8468 primary_rgba.blue = primary->blue / 65535.;
8469 primary_rgba.alpha = 1;
8471 secondary_rgba.red = secondary->red / 65535.;
8472 secondary_rgba.green = secondary->green / 65535.;
8473 secondary_rgba.blue = secondary->blue / 65535.;
8474 secondary_rgba.alpha = 1;
8476 gtk_widget_override_cursor (widget, &primary_rgba, &secondary_rgba);
8480 * gtk_widget_modify_font:
8481 * @widget: a #GtkWidget
8482 * @font_desc: (allow-none): the font description to use, or %NULL
8483 * to undo the effect of previous calls to gtk_widget_modify_font()
8485 * Sets the font to use for a widget.
8487 * All other style values are left untouched.
8488 * See also gtk_widget_modify_style().
8490 * Deprecated:3.0: Use gtk_widget_override_font() instead
8493 gtk_widget_modify_font (GtkWidget *widget,
8494 PangoFontDescription *font_desc)
8496 g_return_if_fail (GTK_IS_WIDGET (widget));
8498 gtk_widget_override_font (widget, font_desc);
8502 gtk_widget_real_direction_changed (GtkWidget *widget,
8503 GtkTextDirection previous_direction)
8505 gtk_widget_queue_resize (widget);
8509 gtk_widget_real_style_set (GtkWidget *widget,
8510 GtkStyle *previous_style)
8515 GtkWidget *previous_toplevel;
8516 GdkScreen *previous_screen;
8517 GdkScreen *new_screen;
8518 } HierarchyChangedInfo;
8521 do_screen_change (GtkWidget *widget,
8522 GdkScreen *old_screen,
8523 GdkScreen *new_screen)
8525 if (old_screen != new_screen)
8527 GtkWidgetPrivate *priv = widget->priv;
8531 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8533 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8536 _gtk_tooltip_hide (widget);
8538 if (new_screen && priv->context)
8539 gtk_style_context_set_screen (priv->context, new_screen);
8541 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8546 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8547 gpointer client_data)
8549 GtkWidgetPrivate *priv = widget->priv;
8550 HierarchyChangedInfo *info = client_data;
8551 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8552 (priv->parent && priv->parent->priv->anchored);
8554 if (priv->anchored != new_anchored)
8556 g_object_ref (widget);
8558 priv->anchored = new_anchored;
8560 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8561 do_screen_change (widget, info->previous_screen, info->new_screen);
8563 if (GTK_IS_CONTAINER (widget))
8564 gtk_container_forall (GTK_CONTAINER (widget),
8565 gtk_widget_propagate_hierarchy_changed_recurse,
8568 g_object_unref (widget);
8573 * _gtk_widget_propagate_hierarchy_changed:
8574 * @widget: a #GtkWidget
8575 * @previous_toplevel: Previous toplevel
8577 * Propagates changes in the anchored state to a widget and all
8578 * children, unsetting or setting the %ANCHORED flag, and
8579 * emitting #GtkWidget::hierarchy-changed.
8582 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8583 GtkWidget *previous_toplevel)
8585 GtkWidgetPrivate *priv = widget->priv;
8586 HierarchyChangedInfo info;
8588 info.previous_toplevel = previous_toplevel;
8589 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8591 if (gtk_widget_is_toplevel (widget) ||
8592 (priv->parent && priv->parent->priv->anchored))
8593 info.new_screen = gtk_widget_get_screen (widget);
8595 info.new_screen = NULL;
8597 if (info.previous_screen)
8598 g_object_ref (info.previous_screen);
8599 if (previous_toplevel)
8600 g_object_ref (previous_toplevel);
8602 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8604 if (previous_toplevel)
8605 g_object_unref (previous_toplevel);
8606 if (info.previous_screen)
8607 g_object_unref (info.previous_screen);
8611 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8612 gpointer client_data)
8614 HierarchyChangedInfo *info = client_data;
8616 g_object_ref (widget);
8618 do_screen_change (widget, info->previous_screen, info->new_screen);
8620 if (GTK_IS_CONTAINER (widget))
8621 gtk_container_forall (GTK_CONTAINER (widget),
8622 gtk_widget_propagate_screen_changed_recurse,
8625 g_object_unref (widget);
8629 * gtk_widget_is_composited:
8630 * @widget: a #GtkWidget
8632 * Whether @widget can rely on having its alpha channel
8633 * drawn correctly. On X11 this function returns whether a
8634 * compositing manager is running for @widget's screen.
8636 * Please note that the semantics of this call will change
8637 * in the future if used on a widget that has a composited
8638 * window in its hierarchy (as set by gdk_window_set_composited()).
8640 * Return value: %TRUE if the widget can rely on its alpha
8641 * channel being drawn correctly.
8646 gtk_widget_is_composited (GtkWidget *widget)
8650 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8652 screen = gtk_widget_get_screen (widget);
8654 return gdk_screen_is_composited (screen);
8658 propagate_composited_changed (GtkWidget *widget,
8661 if (GTK_IS_CONTAINER (widget))
8663 gtk_container_forall (GTK_CONTAINER (widget),
8664 propagate_composited_changed,
8668 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8672 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8674 propagate_composited_changed (widget, NULL);
8678 * _gtk_widget_propagate_screen_changed:
8679 * @widget: a #GtkWidget
8680 * @previous_screen: Previous screen
8682 * Propagates changes in the screen for a widget to all
8683 * children, emitting #GtkWidget::screen-changed.
8686 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8687 GdkScreen *previous_screen)
8689 HierarchyChangedInfo info;
8691 info.previous_screen = previous_screen;
8692 info.new_screen = gtk_widget_get_screen (widget);
8694 if (previous_screen)
8695 g_object_ref (previous_screen);
8697 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8699 if (previous_screen)
8700 g_object_unref (previous_screen);
8704 reset_style_recurse (GtkWidget *widget, gpointer data)
8706 _gtk_widget_update_path (widget);
8708 if (GTK_IS_CONTAINER (widget))
8709 gtk_container_forall (GTK_CONTAINER (widget),
8710 reset_style_recurse,
8715 * gtk_widget_reset_style:
8716 * @widget: a #GtkWidget
8718 * Updates the style context of @widget and all descendents
8719 * by updating its widget path. #GtkContainer<!-- -->s may want
8720 * to use this on a child when reordering it in a way that a different
8721 * style might apply to it. See also gtk_container_get_path_for_child().
8726 gtk_widget_reset_style (GtkWidget *widget)
8728 g_return_if_fail (GTK_IS_WIDGET (widget));
8730 reset_style_recurse (widget, NULL);
8734 * gtk_widget_reset_rc_styles:
8735 * @widget: a #GtkWidget.
8737 * Reset the styles of @widget and all descendents, so when
8738 * they are looked up again, they get the correct values
8739 * for the currently loaded RC file settings.
8741 * This function is not useful for applications.
8743 * Deprecated:3.0: Use #GtkStyleContext instead, and gtk_widget_reset_style()
8746 gtk_widget_reset_rc_styles (GtkWidget *widget)
8748 g_return_if_fail (GTK_IS_WIDGET (widget));
8750 reset_style_recurse (widget, NULL);
8754 * gtk_widget_get_default_style:
8756 * Returns the default style used by all widgets initially.
8758 * Returns: (transfer none): the default style. This #GtkStyle
8759 * object is owned by GTK+ and should not be modified or freed.
8761 * Deprecated:3.0: Use #GtkStyleContext instead, and
8762 * gtk_css_provider_get_default() to obtain a #GtkStyleProvider
8763 * with the default widget style information.
8766 gtk_widget_get_default_style (void)
8768 if (!gtk_default_style)
8770 gtk_default_style = gtk_style_new ();
8771 g_object_ref (gtk_default_style);
8774 return gtk_default_style;
8777 #ifdef G_ENABLE_DEBUG
8779 /* Verify invariants, see docs/widget_system.txt for notes on much of
8780 * this. Invariants may be temporarily broken while we're in the
8781 * process of updating state, of course, so you can only
8782 * verify_invariants() after a given operation is complete.
8783 * Use push/pop_verify_invariants to help with that.
8786 gtk_widget_verify_invariants (GtkWidget *widget)
8790 if (widget->priv->verifying_invariants_count > 0)
8793 parent = widget->priv->parent;
8795 if (widget->priv->mapped)
8797 /* Mapped implies ... */
8799 if (!widget->priv->realized)
8800 g_warning ("%s %p is mapped but not realized",
8801 G_OBJECT_TYPE_NAME (widget), widget);
8803 if (!widget->priv->visible)
8804 g_warning ("%s %p is mapped but not visible",
8805 G_OBJECT_TYPE_NAME (widget), widget);
8807 if (!widget->priv->toplevel)
8809 if (!widget->priv->child_visible)
8810 g_warning ("%s %p is mapped but not child_visible",
8811 G_OBJECT_TYPE_NAME (widget), widget);
8816 /* Not mapped implies... */
8819 /* This check makes sense for normal toplevels, but for
8820 * something like a toplevel that is embedded within a clutter
8821 * state, mapping may depend on external factors.
8823 if (widget->priv->toplevel)
8825 if (widget->priv->visible)
8826 g_warning ("%s %p toplevel is visible but not mapped",
8827 G_OBJECT_TYPE_NAME (widget), widget);
8832 /* Parent related checks aren't possible if parent has
8833 * verifying_invariants_count > 0 because parent needs to recurse
8834 * children first before the invariants will hold.
8836 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8839 parent->priv->realized)
8841 /* Parent realized implies... */
8844 /* This is in widget_system.txt but appears to fail
8845 * because there's no gtk_container_realize() that
8846 * realizes all children... instead we just lazily
8847 * wait for map to fix things up.
8849 if (!widget->priv->realized)
8850 g_warning ("%s %p is realized but child %s %p is not realized",
8851 G_OBJECT_TYPE_NAME (parent), parent,
8852 G_OBJECT_TYPE_NAME (widget), widget);
8855 else if (!widget->priv->toplevel)
8857 /* No parent or parent not realized on non-toplevel implies... */
8859 if (widget->priv->realized && !widget->priv->in_reparent)
8860 g_warning ("%s %p is not realized but child %s %p is realized",
8861 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8862 G_OBJECT_TYPE_NAME (widget), widget);
8866 parent->priv->mapped &&
8867 widget->priv->visible &&
8868 widget->priv->child_visible)
8870 /* Parent mapped and we are visible implies... */
8872 if (!widget->priv->mapped)
8873 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8874 G_OBJECT_TYPE_NAME (parent), parent,
8875 G_OBJECT_TYPE_NAME (widget), widget);
8877 else if (!widget->priv->toplevel)
8879 /* No parent or parent not mapped on non-toplevel implies... */
8881 if (widget->priv->mapped && !widget->priv->in_reparent)
8882 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8883 G_OBJECT_TYPE_NAME (widget), widget,
8884 widget->priv->visible,
8885 widget->priv->child_visible,
8886 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8887 parent ? parent->priv->mapped : FALSE);
8891 if (!widget->priv->realized)
8893 /* Not realized implies... */
8896 /* widget_system.txt says these hold, but they don't. */
8897 if (widget->priv->resize_pending)
8898 g_warning ("%s %p resize pending but not realized",
8899 G_OBJECT_TYPE_NAME (widget), widget);
8901 if (widget->priv->alloc_needed)
8902 g_warning ("%s %p alloc needed but not realized",
8903 G_OBJECT_TYPE_NAME (widget), widget);
8905 if (widget->priv->width_request_needed)
8906 g_warning ("%s %p width request needed but not realized",
8907 G_OBJECT_TYPE_NAME (widget), widget);
8909 if (widget->priv->height_request_needed)
8910 g_warning ("%s %p height request needed but not realized",
8911 G_OBJECT_TYPE_NAME (widget), widget);
8916 /* The point of this push/pop is that invariants may not hold while
8917 * we're busy making changes. So we only check at the outermost call
8918 * on the call stack, after we finish updating everything.
8921 gtk_widget_push_verify_invariants (GtkWidget *widget)
8923 widget->priv->verifying_invariants_count += 1;
8927 gtk_widget_verify_child_invariants (GtkWidget *widget,
8928 gpointer client_data)
8930 /* We don't recurse further; this is a one-level check. */
8931 gtk_widget_verify_invariants (widget);
8935 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8937 g_assert (widget->priv->verifying_invariants_count > 0);
8939 widget->priv->verifying_invariants_count -= 1;
8941 if (widget->priv->verifying_invariants_count == 0)
8943 gtk_widget_verify_invariants (widget);
8945 if (GTK_IS_CONTAINER (widget))
8947 /* Check one level of children, because our
8948 * push_verify_invariants() will have prevented some of the
8949 * checks. This does not recurse because if recursion is
8950 * needed, it will happen naturally as each child has a
8951 * push/pop on that child. For example if we're recursively
8952 * mapping children, we'll push/pop on each child as we map
8955 gtk_container_forall (GTK_CONTAINER (widget),
8956 gtk_widget_verify_child_invariants,
8961 #endif /* G_ENABLE_DEBUG */
8963 static PangoContext *
8964 gtk_widget_peek_pango_context (GtkWidget *widget)
8966 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8970 * gtk_widget_get_pango_context:
8971 * @widget: a #GtkWidget
8973 * Gets a #PangoContext with the appropriate font map, font description,
8974 * and base direction for this widget. Unlike the context returned
8975 * by gtk_widget_create_pango_context(), this context is owned by
8976 * the widget (it can be used until the screen for the widget changes
8977 * or the widget is removed from its toplevel), and will be updated to
8978 * match any changes to the widget's attributes.
8980 * If you create and keep a #PangoLayout using this context, you must
8981 * deal with changes to the context by calling pango_layout_context_changed()
8982 * on the layout in response to the #GtkWidget::style-updated and
8983 * #GtkWidget::direction-changed signals for the widget.
8985 * Return value: (transfer none): the #PangoContext for the widget.
8988 gtk_widget_get_pango_context (GtkWidget *widget)
8990 PangoContext *context;
8992 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8994 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8997 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8998 g_object_set_qdata_full (G_OBJECT (widget),
8999 quark_pango_context,
9008 update_pango_context (GtkWidget *widget,
9009 PangoContext *context)
9011 const PangoFontDescription *font_desc;
9012 GtkStyleContext *style_context;
9014 style_context = gtk_widget_get_style_context (widget);
9016 font_desc = gtk_style_context_get_font (style_context,
9017 gtk_widget_get_state_flags (widget));
9019 pango_context_set_font_description (context, font_desc);
9020 pango_context_set_base_dir (context,
9021 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
9022 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
9026 gtk_widget_update_pango_context (GtkWidget *widget)
9028 PangoContext *context = gtk_widget_peek_pango_context (widget);
9034 update_pango_context (widget, context);
9036 screen = gtk_widget_get_screen_unchecked (widget);
9039 pango_cairo_context_set_resolution (context,
9040 gdk_screen_get_resolution (screen));
9041 pango_cairo_context_set_font_options (context,
9042 gdk_screen_get_font_options (screen));
9048 * gtk_widget_create_pango_context:
9049 * @widget: a #GtkWidget
9051 * Creates a new #PangoContext with the appropriate font map,
9052 * font description, and base direction for drawing text for
9053 * this widget. See also gtk_widget_get_pango_context().
9055 * Return value: (transfer full): the new #PangoContext
9058 gtk_widget_create_pango_context (GtkWidget *widget)
9061 PangoContext *context;
9063 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9065 screen = gtk_widget_get_screen_unchecked (widget);
9068 GTK_NOTE (MULTIHEAD,
9069 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
9071 screen = gdk_screen_get_default ();
9074 context = gdk_pango_context_get_for_screen (screen);
9076 update_pango_context (widget, context);
9077 pango_context_set_language (context, gtk_get_default_language ());
9083 * gtk_widget_create_pango_layout:
9084 * @widget: a #GtkWidget
9085 * @text: text to set on the layout (can be %NULL)
9087 * Creates a new #PangoLayout with the appropriate font map,
9088 * font description, and base direction for drawing text for
9091 * If you keep a #PangoLayout created in this way around, in order to
9092 * notify the layout of changes to the base direction or font of this
9093 * widget, you must call pango_layout_context_changed() in response to
9094 * the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
9097 * Return value: (transfer full): the new #PangoLayout
9100 gtk_widget_create_pango_layout (GtkWidget *widget,
9103 PangoLayout *layout;
9104 PangoContext *context;
9106 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9108 context = gtk_widget_get_pango_context (widget);
9109 layout = pango_layout_new (context);
9112 pango_layout_set_text (layout, text, -1);
9118 * gtk_widget_render_icon_pixbuf:
9119 * @widget: a #GtkWidget
9120 * @stock_id: a stock ID
9121 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
9122 * render at the size of the source and don't scale (if there are
9123 * multiple source sizes, GTK+ picks one of the available sizes).
9125 * A convenience function that uses the theme engine and style
9126 * settings for @widget to look up @stock_id and render it to
9127 * a pixbuf. @stock_id should be a stock icon ID such as
9128 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
9129 * such as #GTK_ICON_SIZE_MENU.
9131 * The pixels in the returned #GdkPixbuf are shared with the rest of
9132 * the application and should not be modified. The pixbuf should be freed
9133 * after use with g_object_unref().
9135 * Return value: (transfer full): a new pixbuf, or %NULL if the
9136 * stock ID wasn't known
9141 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
9142 const gchar *stock_id,
9145 GtkStyleContext *context;
9146 GtkIconSet *icon_set;
9148 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9149 g_return_val_if_fail (stock_id != NULL, NULL);
9150 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
9152 context = gtk_widget_get_style_context (widget);
9153 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
9155 if (icon_set == NULL)
9158 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
9162 * gtk_widget_render_icon:
9163 * @widget: a #GtkWidget
9164 * @stock_id: a stock ID
9165 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
9166 * render at the size of the source and don't scale (if there are
9167 * multiple source sizes, GTK+ picks one of the available sizes).
9168 * @detail: (allow-none): render detail to pass to theme engine
9170 * A convenience function that uses the theme settings for @widget
9171 * to look up @stock_id and render it to a pixbuf. @stock_id should
9172 * be a stock icon ID such as #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size
9173 * should be a size such as #GTK_ICON_SIZE_MENU. @detail should be a
9174 * string that identifies the widget or code doing the rendering, so
9175 * that theme engines can special-case rendering for that widget or
9178 * The pixels in the returned #GdkPixbuf are shared with the rest of
9179 * the application and should not be modified. The pixbuf should be
9180 * freed after use with g_object_unref().
9182 * Return value: (transfer full): a new pixbuf, or %NULL if the
9183 * stock ID wasn't known
9185 * Deprecated: 3.0: Use gtk_widget_render_icon_pixbuf() instead.
9188 gtk_widget_render_icon (GtkWidget *widget,
9189 const gchar *stock_id,
9191 const gchar *detail)
9193 gtk_widget_ensure_style (widget);
9195 return gtk_widget_render_icon_pixbuf (widget, stock_id, size);
9199 * gtk_widget_set_parent_window:
9200 * @widget: a #GtkWidget.
9201 * @parent_window: the new parent window.
9203 * Sets a non default parent window for @widget.
9205 * For GtkWindow classes, setting a @parent_window effects whether
9206 * the window is a toplevel window or can be embedded into other
9210 * For GtkWindow classes, this needs to be called before the
9211 * window is realized.
9216 gtk_widget_set_parent_window (GtkWidget *widget,
9217 GdkWindow *parent_window)
9219 GdkWindow *old_parent_window;
9221 g_return_if_fail (GTK_IS_WIDGET (widget));
9223 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
9224 quark_parent_window);
9226 if (parent_window != old_parent_window)
9230 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
9232 if (old_parent_window)
9233 g_object_unref (old_parent_window);
9235 g_object_ref (parent_window);
9237 /* Unset toplevel flag when adding a parent window to a widget,
9238 * this is the primary entry point to allow toplevels to be
9241 #ifdef GDK_WINDOWING_X11
9242 is_plug = GTK_IS_PLUG (widget);
9246 if (GTK_IS_WINDOW (widget) && !is_plug)
9247 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
9252 * gtk_widget_get_parent_window:
9253 * @widget: a #GtkWidget.
9255 * Gets @widget's parent window.
9257 * Returns: (transfer none): the parent window of @widget.
9260 gtk_widget_get_parent_window (GtkWidget *widget)
9262 GtkWidgetPrivate *priv;
9263 GdkWindow *parent_window;
9265 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9267 priv = widget->priv;
9269 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
9271 return (parent_window != NULL) ? parent_window :
9272 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
9277 * gtk_widget_set_child_visible:
9278 * @widget: a #GtkWidget
9279 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
9281 * Sets whether @widget should be mapped along with its when its parent
9282 * is mapped and @widget has been shown with gtk_widget_show().
9284 * The child visibility can be set for widget before it is added to
9285 * a container with gtk_widget_set_parent(), to avoid mapping
9286 * children unnecessary before immediately unmapping them. However
9287 * it will be reset to its default state of %TRUE when the widget
9288 * is removed from a container.
9290 * Note that changing the child visibility of a widget does not
9291 * queue a resize on the widget. Most of the time, the size of
9292 * a widget is computed from all visible children, whether or
9293 * not they are mapped. If this is not the case, the container
9294 * can queue a resize itself.
9296 * This function is only useful for container implementations and
9297 * never should be called by an application.
9300 gtk_widget_set_child_visible (GtkWidget *widget,
9301 gboolean is_visible)
9303 GtkWidgetPrivate *priv;
9305 g_return_if_fail (GTK_IS_WIDGET (widget));
9306 g_return_if_fail (!gtk_widget_is_toplevel (widget));
9308 priv = widget->priv;
9310 g_object_ref (widget);
9311 gtk_widget_verify_invariants (widget);
9314 priv->child_visible = TRUE;
9317 GtkWidget *toplevel;
9319 priv->child_visible = FALSE;
9321 toplevel = gtk_widget_get_toplevel (widget);
9322 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
9323 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
9326 if (priv->parent && gtk_widget_get_realized (priv->parent))
9328 if (gtk_widget_get_mapped (priv->parent) &&
9329 priv->child_visible &&
9330 gtk_widget_get_visible (widget))
9331 gtk_widget_map (widget);
9333 gtk_widget_unmap (widget);
9336 gtk_widget_verify_invariants (widget);
9337 g_object_unref (widget);
9341 * gtk_widget_get_child_visible:
9342 * @widget: a #GtkWidget
9344 * Gets the value set with gtk_widget_set_child_visible().
9345 * If you feel a need to use this function, your code probably
9346 * needs reorganization.
9348 * This function is only useful for container implementations and
9349 * never should be called by an application.
9351 * Return value: %TRUE if the widget is mapped with the parent.
9354 gtk_widget_get_child_visible (GtkWidget *widget)
9356 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9358 return widget->priv->child_visible;
9362 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9364 GtkWidget *toplevel;
9366 toplevel = gtk_widget_get_toplevel (widget);
9368 if (gtk_widget_is_toplevel (toplevel))
9370 if (GTK_IS_WINDOW (toplevel))
9371 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9372 else if (GTK_IS_INVISIBLE (toplevel))
9373 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9380 * gtk_widget_get_screen:
9381 * @widget: a #GtkWidget
9383 * Get the #GdkScreen from the toplevel window associated with
9384 * this widget. This function can only be called after the widget
9385 * has been added to a widget hierarchy with a #GtkWindow
9388 * In general, you should only create screen specific
9389 * resources when a widget has been realized, and you should
9390 * free those resources when the widget is unrealized.
9392 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9397 gtk_widget_get_screen (GtkWidget *widget)
9401 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9403 screen = gtk_widget_get_screen_unchecked (widget);
9410 g_warning (G_STRLOC ": Can't get associated screen"
9411 " for a widget unless it is inside a toplevel GtkWindow\n"
9412 " widget type is %s associated top level type is %s",
9413 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9414 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9416 return gdk_screen_get_default ();
9421 * gtk_widget_has_screen:
9422 * @widget: a #GtkWidget
9424 * Checks whether there is a #GdkScreen is associated with
9425 * this widget. All toplevel widgets have an associated
9426 * screen, and all widgets added into a hierarchy with a toplevel
9427 * window at the top.
9429 * Return value: %TRUE if there is a #GdkScreen associcated
9435 gtk_widget_has_screen (GtkWidget *widget)
9437 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9439 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9443 * gtk_widget_get_display:
9444 * @widget: a #GtkWidget
9446 * Get the #GdkDisplay for the toplevel window associated with
9447 * this widget. This function can only be called after the widget
9448 * has been added to a widget hierarchy with a #GtkWindow at the top.
9450 * In general, you should only create display specific
9451 * resources when a widget has been realized, and you should
9452 * free those resources when the widget is unrealized.
9454 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9459 gtk_widget_get_display (GtkWidget *widget)
9461 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9463 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9467 * gtk_widget_get_root_window:
9468 * @widget: a #GtkWidget
9470 * Get the root window where this widget is located. This function can
9471 * only be called after the widget has been added to a widget
9472 * hierarchy with #GtkWindow at the top.
9474 * The root window is useful for such purposes as creating a popup
9475 * #GdkWindow associated with the window. In general, you should only
9476 * create display specific resources when a widget has been realized,
9477 * and you should free those resources when the widget is unrealized.
9479 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9484 gtk_widget_get_root_window (GtkWidget *widget)
9486 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9488 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9492 * gtk_widget_child_focus:
9493 * @widget: a #GtkWidget
9494 * @direction: direction of focus movement
9496 * This function is used by custom widget implementations; if you're
9497 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9498 * to a particular widget, and gtk_container_set_focus_chain() to
9499 * change the focus tab order. So you may want to investigate those
9500 * functions instead.
9502 * gtk_widget_child_focus() is called by containers as the user moves
9503 * around the window using keyboard shortcuts. @direction indicates
9504 * what kind of motion is taking place (up, down, left, right, tab
9505 * forward, tab backward). gtk_widget_child_focus() emits the
9506 * #GtkWidget::focus signal; widgets override the default handler
9507 * for this signal in order to implement appropriate focus behavior.
9509 * The default ::focus handler for a widget should return %TRUE if
9510 * moving in @direction left the focus on a focusable location inside
9511 * that widget, and %FALSE if moving in @direction moved the focus
9512 * outside the widget. If returning %TRUE, widgets normally
9513 * call gtk_widget_grab_focus() to place the focus accordingly;
9514 * if returning %FALSE, they don't modify the current focus location.
9516 * Return value: %TRUE if focus ended up inside @widget
9519 gtk_widget_child_focus (GtkWidget *widget,
9520 GtkDirectionType direction)
9522 gboolean return_val;
9524 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9526 if (!gtk_widget_get_visible (widget) ||
9527 !gtk_widget_is_sensitive (widget))
9530 /* child widgets must set CAN_FOCUS, containers
9531 * don't have to though.
9533 if (!GTK_IS_CONTAINER (widget) &&
9534 !gtk_widget_get_can_focus (widget))
9537 g_signal_emit (widget,
9538 widget_signals[FOCUS],
9540 direction, &return_val);
9546 * gtk_widget_keynav_failed:
9547 * @widget: a #GtkWidget
9548 * @direction: direction of focus movement
9550 * This function should be called whenever keyboard navigation within
9551 * a single widget hits a boundary. The function emits the
9552 * #GtkWidget::keynav-failed signal on the widget and its return
9553 * value should be interpreted in a way similar to the return value of
9554 * gtk_widget_child_focus():
9556 * When %TRUE is returned, stay in the widget, the failed keyboard
9557 * navigation is Ok and/or there is nowhere we can/should move the
9560 * When %FALSE is returned, the caller should continue with keyboard
9561 * navigation outside the widget, e.g. by calling
9562 * gtk_widget_child_focus() on the widget's toplevel.
9564 * The default ::keynav-failed handler returns %TRUE for
9565 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9566 * values of #GtkDirectionType, it looks at the
9567 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9568 * if the setting is %TRUE. This way the entire user interface
9569 * becomes cursor-navigatable on input devices such as mobile phones
9570 * which only have cursor keys but no tab key.
9572 * Whenever the default handler returns %TRUE, it also calls
9573 * gtk_widget_error_bell() to notify the user of the failed keyboard
9576 * A use case for providing an own implementation of ::keynav-failed
9577 * (either by connecting to it or by overriding it) would be a row of
9578 * #GtkEntry widgets where the user should be able to navigate the
9579 * entire row with the cursor keys, as e.g. known from user interfaces
9580 * that require entering license keys.
9582 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9583 * if the emitting widget should try to handle the keyboard
9584 * navigation attempt in its parent container(s).
9589 gtk_widget_keynav_failed (GtkWidget *widget,
9590 GtkDirectionType direction)
9592 gboolean return_val;
9594 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9596 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9597 direction, &return_val);
9603 * gtk_widget_error_bell:
9604 * @widget: a #GtkWidget
9606 * Notifies the user about an input-related error on this widget.
9607 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9608 * gdk_window_beep(), otherwise it does nothing.
9610 * Note that the effect of gdk_window_beep() can be configured in many
9611 * ways, depending on the windowing backend and the desktop environment
9612 * or window manager that is used.
9617 gtk_widget_error_bell (GtkWidget *widget)
9619 GtkWidgetPrivate *priv;
9620 GtkSettings* settings;
9623 g_return_if_fail (GTK_IS_WIDGET (widget));
9625 priv = widget->priv;
9627 settings = gtk_widget_get_settings (widget);
9631 g_object_get (settings,
9632 "gtk-error-bell", &beep,
9635 if (beep && priv->window)
9636 gdk_window_beep (priv->window);
9640 gtk_widget_set_usize_internal (GtkWidget *widget,
9643 GtkQueueResizeFlags flags)
9645 GtkWidgetAuxInfo *aux_info;
9646 gboolean changed = FALSE;
9648 g_object_freeze_notify (G_OBJECT (widget));
9650 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9652 if (width > -2 && aux_info->width != width)
9654 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9655 g_object_notify (G_OBJECT (widget), "width-request");
9656 aux_info->width = width;
9659 if (height > -2 && aux_info->height != height)
9661 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9662 g_object_notify (G_OBJECT (widget), "height-request");
9663 aux_info->height = height;
9667 if (gtk_widget_get_visible (widget) && changed)
9669 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9670 gtk_widget_queue_resize (widget);
9672 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9675 g_object_thaw_notify (G_OBJECT (widget));
9679 * gtk_widget_set_size_request:
9680 * @widget: a #GtkWidget
9681 * @width: width @widget should request, or -1 to unset
9682 * @height: height @widget should request, or -1 to unset
9684 * Sets the minimum size of a widget; that is, the widget's size
9685 * request will be @width by @height. You can use this function to
9686 * force a widget to be either larger or smaller than it normally
9689 * In most cases, gtk_window_set_default_size() is a better choice for
9690 * toplevel windows than this function; setting the default size will
9691 * still allow users to shrink the window. Setting the size request
9692 * will force them to leave the window at least as large as the size
9693 * request. When dealing with window sizes,
9694 * gtk_window_set_geometry_hints() can be a useful function as well.
9696 * Note the inherent danger of setting any fixed size - themes,
9697 * translations into other languages, different fonts, and user action
9698 * can all change the appropriate size for a given widget. So, it's
9699 * basically impossible to hardcode a size that will always be
9702 * The size request of a widget is the smallest size a widget can
9703 * accept while still functioning well and drawing itself correctly.
9704 * However in some strange cases a widget may be allocated less than
9705 * its requested size, and in many cases a widget may be allocated more
9706 * space than it requested.
9708 * If the size request in a given direction is -1 (unset), then
9709 * the "natural" size request of the widget will be used instead.
9711 * Widgets can't actually be allocated a size less than 1 by 1, but
9712 * you can pass 0,0 to this function to mean "as small as possible."
9714 * The size request set here does not include any margin from the
9715 * #GtkWidget properties margin-left, margin-right, margin-top, and
9716 * margin-bottom, but it does include pretty much all other padding
9717 * or border properties set by any subclass of #GtkWidget.
9720 gtk_widget_set_size_request (GtkWidget *widget,
9724 g_return_if_fail (GTK_IS_WIDGET (widget));
9725 g_return_if_fail (width >= -1);
9726 g_return_if_fail (height >= -1);
9733 gtk_widget_set_usize_internal (widget, width, height, 0);
9738 * gtk_widget_get_size_request:
9739 * @widget: a #GtkWidget
9740 * @width: (out) (allow-none): return location for width, or %NULL
9741 * @height: (out) (allow-none): return location for height, or %NULL
9743 * Gets the size request that was explicitly set for the widget using
9744 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9745 * @height indicates that that dimension has not been set explicitly
9746 * and the natural requisition of the widget will be used intead. See
9747 * gtk_widget_set_size_request(). To get the size a widget will
9748 * actually request, call gtk_widget_get_preferred_size() instead of
9752 gtk_widget_get_size_request (GtkWidget *widget,
9756 const GtkWidgetAuxInfo *aux_info;
9758 g_return_if_fail (GTK_IS_WIDGET (widget));
9760 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9763 *width = aux_info->width;
9766 *height = aux_info->height;
9770 * _gtk_widget_override_size_request:
9771 * @widget: a #GtkWidget
9772 * @width: new forced minimum width
9773 * @height: new forced minimum height
9774 * @old_width: location to store previous forced minimum width
9775 * @old_width: location to store previous forced minumum height
9777 * Temporarily establishes a forced minimum size for a widget; this
9778 * is used by GtkWindow when calculating the size to add to the
9779 * window's geometry widget. Cached sizes for the widget and its
9780 * parents are invalidated, so that subsequent calls to the size
9781 * negotiation machinery produce the overriden result, but the
9782 * widget is not queued for relayout or redraw. The old size must
9783 * be restored with _gtk_widget_restore_size_request() or things
9787 _gtk_widget_override_size_request (GtkWidget *widget,
9793 gtk_widget_get_size_request (widget, old_width, old_height);
9794 gtk_widget_set_usize_internal (widget, width, height,
9795 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9799 * _gtk_widget_restore_size_request:
9800 * @widget: a #GtkWidget
9801 * @old_width: saved forced minimum size
9802 * @old_height: saved forced minimum size
9804 * Undoes the operation of_gtk_widget_override_size_request().
9807 _gtk_widget_restore_size_request (GtkWidget *widget,
9811 gtk_widget_set_usize_internal (widget, old_width, old_height,
9812 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9816 * gtk_widget_set_events:
9817 * @widget: a #GtkWidget
9818 * @events: event mask
9820 * Sets the event mask (see #GdkEventMask) for a widget. The event
9821 * mask determines which events a widget will receive. Keep in mind
9822 * that different widgets have different default event masks, and by
9823 * changing the event mask you may disrupt a widget's functionality,
9824 * so be careful. This function must be called while a widget is
9825 * unrealized. Consider gtk_widget_add_events() for widgets that are
9826 * already realized, or if you want to preserve the existing event
9827 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9828 * to get events on those widgets, place them inside a #GtkEventBox
9829 * and receive events on the event box.
9832 gtk_widget_set_events (GtkWidget *widget,
9835 g_return_if_fail (GTK_IS_WIDGET (widget));
9836 g_return_if_fail (!gtk_widget_get_realized (widget));
9838 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9839 GINT_TO_POINTER (events));
9840 g_object_notify (G_OBJECT (widget), "events");
9844 * gtk_widget_set_device_events:
9845 * @widget: a #GtkWidget
9846 * @device: a #GdkDevice
9847 * @events: event mask
9849 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9850 * mask determines which events a widget will receive from @device. Keep
9851 * in mind that different widgets have different default event masks, and by
9852 * changing the event mask you may disrupt a widget's functionality,
9853 * so be careful. This function must be called while a widget is
9854 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9855 * already realized, or if you want to preserve the existing event
9856 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9857 * to get events on those widgets, place them inside a #GtkEventBox
9858 * and receive events on the event box.
9863 gtk_widget_set_device_events (GtkWidget *widget,
9865 GdkEventMask events)
9867 GHashTable *device_events;
9869 g_return_if_fail (GTK_IS_WIDGET (widget));
9870 g_return_if_fail (GDK_IS_DEVICE (device));
9871 g_return_if_fail (!gtk_widget_get_realized (widget));
9873 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9875 if (G_UNLIKELY (!device_events))
9877 device_events = g_hash_table_new (NULL, NULL);
9878 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9879 (GDestroyNotify) g_hash_table_unref);
9882 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9886 * gtk_widget_set_device_enabled:
9887 * @widget: a #GtkWidget
9888 * @device: a #GdkDevice
9889 * @enabled: whether to enable the device
9891 * Enables or disables a #GdkDevice to interact with @widget
9892 * and all its children.
9894 * It does so by descending through the #GdkWindow hierarchy
9895 * and enabling the same mask that is has for core events
9896 * (i.e. the one that gdk_window_get_events() returns).
9901 gtk_widget_set_device_enabled (GtkWidget *widget,
9905 GList *enabled_devices;
9907 g_return_if_fail (GTK_IS_WIDGET (widget));
9908 g_return_if_fail (GDK_IS_DEVICE (device));
9910 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9911 enabled_devices = g_list_append (enabled_devices, device);
9913 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9914 enabled_devices, (GDestroyNotify) g_list_free);;
9916 if (gtk_widget_get_realized (widget))
9917 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9921 * gtk_widget_get_device_enabled:
9922 * @widget: a #GtkWidget
9923 * @device: a #GdkDevice
9925 * Returns whether @device can interact with @widget and its
9926 * children. See gtk_widget_set_device_enabled().
9928 * Return value: %TRUE is @device is enabled for @widget
9933 gtk_widget_get_device_enabled (GtkWidget *widget,
9936 GList *enabled_devices;
9938 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9939 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9941 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9943 return g_list_find (enabled_devices, device) != NULL;
9947 gtk_widget_add_events_internal_list (GtkWidget *widget,
9954 for (l = window_list; l != NULL; l = l->next)
9956 GdkWindow *window = l->data;
9959 gdk_window_get_user_data (window, &user_data);
9960 if (user_data == widget)
9965 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9967 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9969 children = gdk_window_get_children (window);
9970 gtk_widget_add_events_internal_list (widget, device, events, children);
9971 g_list_free (children);
9977 gtk_widget_add_events_internal (GtkWidget *widget,
9981 GtkWidgetPrivate *priv = widget->priv;
9984 if (!gtk_widget_get_has_window (widget))
9985 window_list = gdk_window_get_children (priv->window);
9987 window_list = g_list_prepend (NULL, priv->window);
9989 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9991 g_list_free (window_list);
9995 * gtk_widget_add_events:
9996 * @widget: a #GtkWidget
9997 * @events: an event mask, see #GdkEventMask
9999 * Adds the events in the bitfield @events to the event mask for
10000 * @widget. See gtk_widget_set_events() for details.
10003 gtk_widget_add_events (GtkWidget *widget,
10008 g_return_if_fail (GTK_IS_WIDGET (widget));
10010 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10011 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
10012 GINT_TO_POINTER (old_events | events));
10014 if (gtk_widget_get_realized (widget))
10016 gtk_widget_add_events_internal (widget, NULL, events);
10017 gtk_widget_update_devices_mask (widget, FALSE);
10020 g_object_notify (G_OBJECT (widget), "events");
10024 * gtk_widget_add_device_events:
10025 * @widget: a #GtkWidget
10026 * @device: a #GdkDevice
10027 * @events: an event mask, see #GdkEventMask
10029 * Adds the device events in the bitfield @events to the event mask for
10030 * @widget. See gtk_widget_set_device_events() for details.
10035 gtk_widget_add_device_events (GtkWidget *widget,
10037 GdkEventMask events)
10039 GdkEventMask old_events;
10040 GHashTable *device_events;
10042 g_return_if_fail (GTK_IS_WIDGET (widget));
10043 g_return_if_fail (GDK_IS_DEVICE (device));
10045 old_events = gtk_widget_get_device_events (widget, device);
10047 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10049 if (G_UNLIKELY (!device_events))
10051 device_events = g_hash_table_new (NULL, NULL);
10052 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
10053 (GDestroyNotify) g_hash_table_unref);
10056 g_hash_table_insert (device_events, device,
10057 GUINT_TO_POINTER (old_events | events));
10059 if (gtk_widget_get_realized (widget))
10060 gtk_widget_add_events_internal (widget, device, events);
10062 g_object_notify (G_OBJECT (widget), "events");
10066 * gtk_widget_get_toplevel:
10067 * @widget: a #GtkWidget
10069 * This function returns the topmost widget in the container hierarchy
10070 * @widget is a part of. If @widget has no parent widgets, it will be
10071 * returned as the topmost widget. No reference will be added to the
10072 * returned widget; it should not be unreferenced.
10074 * Note the difference in behavior vs. gtk_widget_get_ancestor();
10075 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
10077 * %NULL if @widget wasn't inside a toplevel window, and if the
10078 * window was inside a #GtkWindow-derived widget which was in turn
10079 * inside the toplevel #GtkWindow. While the second case may
10080 * seem unlikely, it actually happens when a #GtkPlug is embedded
10081 * inside a #GtkSocket within the same application.
10083 * To reliably find the toplevel #GtkWindow, use
10084 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
10085 * is set on the result.
10087 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
10088 * if (gtk_widget_is_toplevel (toplevel))
10090 * /* Perform action on toplevel. */
10094 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
10095 * if there's no ancestor.
10098 gtk_widget_get_toplevel (GtkWidget *widget)
10100 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10102 while (widget->priv->parent)
10103 widget = widget->priv->parent;
10109 * gtk_widget_get_ancestor:
10110 * @widget: a #GtkWidget
10111 * @widget_type: ancestor type
10113 * Gets the first ancestor of @widget with type @widget_type. For example,
10114 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
10115 * the first #GtkBox that's an ancestor of @widget. No reference will be
10116 * added to the returned widget; it should not be unreferenced. See note
10117 * about checking for a toplevel #GtkWindow in the docs for
10118 * gtk_widget_get_toplevel().
10120 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
10121 * considers @widget to be an ancestor of itself.
10123 * Return value: (transfer none): the ancestor widget, or %NULL if not found
10126 gtk_widget_get_ancestor (GtkWidget *widget,
10129 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10131 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
10132 widget = widget->priv->parent;
10134 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
10141 * gtk_widget_set_visual:
10142 * @widget: a #GtkWidget
10143 * @visual: visual to be used or %NULL to unset a previous one
10145 * Sets the visual that should be used for by widget and its children for
10146 * creating #GdkWindows. The visual must be on the same #GdkScreen as
10147 * returned by gdk_widget_get_screen(), so handling the
10148 * #GtkWidget::screen-changed signal is necessary.
10150 * Setting a new @visual will not cause @widget to recreate its windows,
10151 * so you should call this function before @widget is realized.
10154 gtk_widget_set_visual (GtkWidget *widget,
10157 g_return_if_fail (GTK_IS_WIDGET (widget));
10158 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
10161 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
10164 g_object_set_qdata_full (G_OBJECT (widget),
10166 g_object_ref (visual),
10171 * gtk_widget_get_visual:
10172 * @widget: a #GtkWidget
10174 * Gets the visual that will be used to render @widget.
10176 * Return value: (transfer none): the visual for @widget
10179 gtk_widget_get_visual (GtkWidget *widget)
10185 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10187 if (gtk_widget_get_has_window (widget) &&
10188 widget->priv->window)
10189 return gdk_window_get_visual (widget->priv->window);
10191 screen = gtk_widget_get_screen (widget);
10193 for (w = widget; w != NULL; w = w->priv->parent)
10195 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
10198 if (gdk_visual_get_screen (visual) == screen)
10201 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
10202 gtk_widget_get_name (widget));
10206 return gdk_screen_get_system_visual (screen);
10210 * gtk_widget_get_settings:
10211 * @widget: a #GtkWidget
10213 * Gets the settings object holding the settings used for this widget.
10215 * Note that this function can only be called when the #GtkWidget
10216 * is attached to a toplevel, since the settings object is specific
10217 * to a particular #GdkScreen.
10219 * Return value: (transfer none): the relevant #GtkSettings object
10222 gtk_widget_get_settings (GtkWidget *widget)
10224 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10226 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
10230 * gtk_widget_get_events:
10231 * @widget: a #GtkWidget
10233 * Returns the event mask for the widget (a bitfield containing flags
10234 * from the #GdkEventMask enumeration). These are the events that the widget
10237 * Return value: event mask for @widget
10240 gtk_widget_get_events (GtkWidget *widget)
10242 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10244 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10248 * gtk_widget_get_device_events:
10249 * @widget: a #GtkWidget
10250 * @device: a #GdkDevice
10252 * Returns the events mask for the widget corresponding to an specific device. These
10253 * are the events that the widget will receive when @device operates on it.
10255 * Returns: device event mask for @widget
10260 gtk_widget_get_device_events (GtkWidget *widget,
10263 GHashTable *device_events;
10265 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10266 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
10268 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10270 if (!device_events)
10273 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
10277 * gtk_widget_get_pointer:
10278 * @widget: a #GtkWidget
10279 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
10280 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
10282 * Obtains the location of the mouse pointer in widget coordinates.
10283 * Widget coordinates are a bit odd; for historical reasons, they are
10284 * defined as @widget->window coordinates for widgets that are not
10285 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
10286 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
10289 gtk_widget_get_pointer (GtkWidget *widget,
10293 GtkWidgetPrivate *priv;
10295 g_return_if_fail (GTK_IS_WIDGET (widget));
10297 priv = widget->priv;
10304 if (gtk_widget_get_realized (widget))
10306 gdk_window_get_pointer (priv->window, x, y, NULL);
10308 if (!gtk_widget_get_has_window (widget))
10311 *x -= priv->allocation.x;
10313 *y -= priv->allocation.y;
10319 * gtk_widget_is_ancestor:
10320 * @widget: a #GtkWidget
10321 * @ancestor: another #GtkWidget
10323 * Determines whether @widget is somewhere inside @ancestor, possibly with
10324 * intermediate containers.
10326 * Return value: %TRUE if @ancestor contains @widget as a child,
10327 * grandchild, great grandchild, etc.
10330 gtk_widget_is_ancestor (GtkWidget *widget,
10331 GtkWidget *ancestor)
10333 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10334 g_return_val_if_fail (ancestor != NULL, FALSE);
10338 if (widget->priv->parent == ancestor)
10340 widget = widget->priv->parent;
10346 static GQuark quark_composite_name = 0;
10349 * gtk_widget_set_composite_name:
10350 * @widget: a #GtkWidget.
10351 * @name: the name to set
10353 * Sets a widgets composite name. The widget must be
10354 * a composite child of its parent; see gtk_widget_push_composite_child().
10357 gtk_widget_set_composite_name (GtkWidget *widget,
10360 g_return_if_fail (GTK_IS_WIDGET (widget));
10361 g_return_if_fail (widget->priv->composite_child);
10362 g_return_if_fail (name != NULL);
10364 if (!quark_composite_name)
10365 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10367 g_object_set_qdata_full (G_OBJECT (widget),
10368 quark_composite_name,
10374 * gtk_widget_get_composite_name:
10375 * @widget: a #GtkWidget
10377 * Obtains the composite name of a widget.
10379 * Returns: the composite name of @widget, or %NULL if @widget is not
10380 * a composite child. The string should be freed when it is no
10384 gtk_widget_get_composite_name (GtkWidget *widget)
10386 GtkWidgetPrivate *priv;
10388 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10390 priv = widget->priv;
10392 if (widget->priv->composite_child && priv->parent)
10393 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10400 * gtk_widget_push_composite_child:
10402 * Makes all newly-created widgets as composite children until
10403 * the corresponding gtk_widget_pop_composite_child() call.
10405 * A composite child is a child that's an implementation detail of the
10406 * container it's inside and should not be visible to people using the
10407 * container. Composite children aren't treated differently by GTK (but
10408 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10409 * builders might want to treat them in a different way.
10411 * Here is a simple example:
10413 * gtk_widget_push_composite_child ();
10414 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10415 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10416 * gtk_widget_pop_composite_child ();
10417 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10418 * GTK_WIDGET (scrolled_window));
10419 * g_object_ref (scrolled_window->hscrollbar);
10423 gtk_widget_push_composite_child (void)
10425 composite_child_stack++;
10429 * gtk_widget_pop_composite_child:
10431 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10434 gtk_widget_pop_composite_child (void)
10436 if (composite_child_stack)
10437 composite_child_stack--;
10441 gtk_widget_emit_direction_changed (GtkWidget *widget,
10442 GtkTextDirection old_dir)
10444 gtk_widget_update_pango_context (widget);
10446 if (widget->priv->context)
10447 gtk_style_context_set_direction (widget->priv->context,
10448 gtk_widget_get_direction (widget));
10450 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10454 * gtk_widget_set_direction:
10455 * @widget: a #GtkWidget
10456 * @dir: the new direction
10458 * Sets the reading direction on a particular widget. This direction
10459 * controls the primary direction for widgets containing text,
10460 * and also the direction in which the children of a container are
10461 * packed. The ability to set the direction is present in order
10462 * so that correct localization into languages with right-to-left
10463 * reading directions can be done. Generally, applications will
10464 * let the default reading direction present, except for containers
10465 * where the containers are arranged in an order that is explicitely
10466 * visual rather than logical (such as buttons for text justification).
10468 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10469 * set by gtk_widget_set_default_direction() will be used.
10472 gtk_widget_set_direction (GtkWidget *widget,
10473 GtkTextDirection dir)
10475 GtkTextDirection old_dir;
10477 g_return_if_fail (GTK_IS_WIDGET (widget));
10478 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10480 old_dir = gtk_widget_get_direction (widget);
10482 widget->priv->direction = dir;
10484 if (old_dir != gtk_widget_get_direction (widget))
10485 gtk_widget_emit_direction_changed (widget, old_dir);
10489 * gtk_widget_get_direction:
10490 * @widget: a #GtkWidget
10492 * Gets the reading direction for a particular widget. See
10493 * gtk_widget_set_direction().
10495 * Return value: the reading direction for the widget.
10498 gtk_widget_get_direction (GtkWidget *widget)
10500 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10502 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10503 return gtk_default_direction;
10505 return widget->priv->direction;
10509 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10511 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10513 g_object_ref (widget);
10515 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10516 gtk_widget_emit_direction_changed (widget, old_dir);
10518 if (GTK_IS_CONTAINER (widget))
10519 gtk_container_forall (GTK_CONTAINER (widget),
10520 gtk_widget_set_default_direction_recurse,
10523 g_object_unref (widget);
10527 * gtk_widget_set_default_direction:
10528 * @dir: the new default direction. This cannot be
10529 * %GTK_TEXT_DIR_NONE.
10531 * Sets the default reading direction for widgets where the
10532 * direction has not been explicitly set by gtk_widget_set_direction().
10535 gtk_widget_set_default_direction (GtkTextDirection dir)
10537 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10539 if (dir != gtk_default_direction)
10541 GList *toplevels, *tmp_list;
10542 GtkTextDirection old_dir = gtk_default_direction;
10544 gtk_default_direction = dir;
10546 tmp_list = toplevels = gtk_window_list_toplevels ();
10547 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10551 gtk_widget_set_default_direction_recurse (tmp_list->data,
10552 GUINT_TO_POINTER (old_dir));
10553 g_object_unref (tmp_list->data);
10554 tmp_list = tmp_list->next;
10557 g_list_free (toplevels);
10562 * gtk_widget_get_default_direction:
10564 * Obtains the current default reading direction. See
10565 * gtk_widget_set_default_direction().
10567 * Return value: the current default direction.
10570 gtk_widget_get_default_direction (void)
10572 return gtk_default_direction;
10576 gtk_widget_dispose (GObject *object)
10578 GtkWidget *widget = GTK_WIDGET (object);
10579 GtkWidgetPrivate *priv = widget->priv;
10582 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10583 else if (gtk_widget_get_visible (widget))
10584 gtk_widget_hide (widget);
10586 priv->visible = FALSE;
10587 if (gtk_widget_get_realized (widget))
10588 gtk_widget_unrealize (widget);
10590 if (!priv->in_destruction)
10592 priv->in_destruction = TRUE;
10593 g_signal_emit (object, widget_signals[DESTROY], 0);
10594 priv->in_destruction = FALSE;
10597 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10601 gtk_widget_real_destroy (GtkWidget *object)
10603 /* gtk_object_destroy() will already hold a refcount on object */
10604 GtkWidget *widget = GTK_WIDGET (object);
10605 GtkWidgetPrivate *priv = widget->priv;
10607 /* wipe accelerator closures (keep order) */
10608 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10609 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10611 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10612 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10614 gtk_grab_remove (widget);
10617 g_object_unref (priv->style);
10618 priv->style = gtk_widget_get_default_style ();
10619 g_object_ref (priv->style);
10623 gtk_widget_finalize (GObject *object)
10625 GtkWidget *widget = GTK_WIDGET (object);
10626 GtkWidgetPrivate *priv = widget->priv;
10627 GtkWidgetAuxInfo *aux_info;
10628 GtkAccessible *accessible;
10630 gtk_grab_remove (widget);
10632 g_object_unref (priv->style);
10633 priv->style = NULL;
10635 g_free (priv->name);
10637 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10639 gtk_widget_aux_info_destroy (aux_info);
10641 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10643 g_object_unref (accessible);
10646 gtk_widget_path_free (priv->path);
10649 g_object_unref (priv->context);
10651 _gtk_widget_free_cached_sizes (widget);
10653 if (g_object_is_floating (object))
10654 g_warning ("A floating object was finalized. This means that someone\n"
10655 "called g_object_unref() on an object that had only a floating\n"
10656 "reference; the initial floating reference is not owned by anyone\n"
10657 "and must be removed with g_object_ref_sink().");
10659 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10662 /*****************************************
10663 * gtk_widget_real_map:
10668 *****************************************/
10671 gtk_widget_real_map (GtkWidget *widget)
10673 GtkWidgetPrivate *priv = widget->priv;
10675 g_assert (gtk_widget_get_realized (widget));
10677 if (!gtk_widget_get_mapped (widget))
10679 gtk_widget_set_mapped (widget, TRUE);
10681 if (gtk_widget_get_has_window (widget))
10682 gdk_window_show (priv->window);
10686 /*****************************************
10687 * gtk_widget_real_unmap:
10692 *****************************************/
10695 gtk_widget_real_unmap (GtkWidget *widget)
10697 GtkWidgetPrivate *priv = widget->priv;
10699 if (gtk_widget_get_mapped (widget))
10701 gtk_widget_set_mapped (widget, FALSE);
10703 if (gtk_widget_get_has_window (widget))
10704 gdk_window_hide (priv->window);
10708 /*****************************************
10709 * gtk_widget_real_realize:
10714 *****************************************/
10717 gtk_widget_real_realize (GtkWidget *widget)
10719 GtkWidgetPrivate *priv = widget->priv;
10721 g_assert (!gtk_widget_get_has_window (widget));
10723 gtk_widget_set_realized (widget, TRUE);
10726 priv->window = gtk_widget_get_parent_window (widget);
10727 g_object_ref (priv->window);
10731 /*****************************************
10732 * gtk_widget_real_unrealize:
10737 *****************************************/
10740 gtk_widget_real_unrealize (GtkWidget *widget)
10742 GtkWidgetPrivate *priv = widget->priv;
10744 g_assert (!widget->priv->mapped);
10746 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10749 /* We must do unrealize child widget BEFORE container widget.
10750 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10751 * So, unrealizing container widget bofore its children causes the problem
10752 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10755 if (GTK_IS_CONTAINER (widget))
10756 gtk_container_forall (GTK_CONTAINER (widget),
10757 (GtkCallback) gtk_widget_unrealize,
10760 if (gtk_widget_get_has_window (widget))
10762 gdk_window_set_user_data (priv->window, NULL);
10763 gdk_window_destroy (priv->window);
10764 priv->window = NULL;
10768 g_object_unref (priv->window);
10769 priv->window = NULL;
10772 gtk_selection_remove_all (widget);
10774 gtk_widget_set_realized (widget, FALSE);
10778 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10779 GtkOrientation orientation,
10780 gint *minimum_size,
10781 gint *natural_size)
10783 const GtkWidgetAuxInfo *aux_info;
10785 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10787 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10788 aux_info->width > 0)
10790 *minimum_size = MAX (*minimum_size, aux_info->width);
10792 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10793 aux_info->height > 0)
10795 *minimum_size = MAX (*minimum_size, aux_info->height);
10798 /* Fix it if set_size_request made natural size smaller than min size.
10799 * This would also silently fix broken widgets, but we warn about them
10800 * in gtksizerequest.c when calling their size request vfuncs.
10802 *natural_size = MAX (*natural_size, *minimum_size);
10804 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10806 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10807 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10811 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10812 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10817 * _gtk_widget_peek_request_cache:
10819 * Returns the address of the widget's request cache (strictly for
10820 * internal use in gtksizerequest.c)
10822 * Return value: the address of @widget's size request cache.
10825 _gtk_widget_peek_request_cache (GtkWidget *widget)
10827 /* Don't bother slowing things down with the return_if_fail guards here */
10828 return &widget->priv->requests;
10832 * _gtk_widget_set_device_window:
10833 * @widget: a #GtkWidget
10834 * @device: a #GdkDevice
10835 * @window: the new device window
10837 * Sets pointer window for @widget and @device.
10838 * Does not ref @window.
10841 _gtk_widget_set_device_window (GtkWidget *widget,
10845 GHashTable *device_window;
10847 g_return_if_fail (GTK_IS_WIDGET (widget));
10848 g_return_if_fail (GDK_IS_DEVICE (device));
10849 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10851 if (!gtk_widget_get_mapped (widget))
10854 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10856 if (!device_window && window)
10858 device_window = g_hash_table_new (NULL, NULL);
10859 g_object_set_qdata_full (G_OBJECT (widget),
10860 quark_pointer_window,
10862 (GDestroyNotify) g_hash_table_destroy);
10866 g_hash_table_insert (device_window, device, window);
10867 else if (device_window)
10869 g_hash_table_remove (device_window, device);
10871 if (g_hash_table_size (device_window) == 0)
10872 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10877 * _gtk_widget_get_device_window:
10878 * @widget: a #GtkWidget
10879 * @device: a #GdkDevice
10881 * Return value: the device window set on @widget, or %NULL
10884 _gtk_widget_get_device_window (GtkWidget *widget,
10887 GHashTable *device_window;
10889 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10890 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10892 if (!gtk_widget_get_mapped (widget))
10895 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10897 if (!device_window)
10900 return g_hash_table_lookup (device_window, device);
10904 * _gtk_widget_list_devices:
10905 * @widget: a #GtkWidget
10907 * Returns the list of #GdkDevices that is currently on top
10908 * of any window belonging to @widget.
10909 * Free the list with g_list_free(), the elements are owned
10910 * by GTK+ and must not be freed.
10913 _gtk_widget_list_devices (GtkWidget *widget)
10915 GHashTableIter iter;
10916 GHashTable *device_window;
10917 GList *devices = NULL;
10918 gpointer key, value;
10920 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10922 if (!gtk_widget_get_mapped (widget))
10925 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10927 if (G_UNLIKELY (!device_window))
10930 g_hash_table_iter_init (&iter, device_window);
10932 while (g_hash_table_iter_next (&iter, &key, &value))
10933 devices = g_list_prepend (devices, key);
10939 synth_crossing (GtkWidget *widget,
10943 GdkCrossingMode mode,
10944 GdkNotifyType detail)
10948 event = gdk_event_new (type);
10950 event->crossing.window = g_object_ref (window);
10951 event->crossing.send_event = TRUE;
10952 event->crossing.subwindow = g_object_ref (window);
10953 event->crossing.time = GDK_CURRENT_TIME;
10954 event->crossing.x = event->crossing.y = 0;
10955 event->crossing.x_root = event->crossing.y_root = 0;
10956 event->crossing.mode = mode;
10957 event->crossing.detail = detail;
10958 event->crossing.focus = FALSE;
10959 event->crossing.state = 0;
10960 gdk_event_set_device (event, device);
10963 widget = gtk_get_event_widget (event);
10966 gtk_widget_event_internal (widget, event);
10968 gdk_event_free (event);
10972 * _gtk_widget_synthesize_crossing:
10973 * @from: the #GtkWidget the virtual pointer is leaving.
10974 * @to: the #GtkWidget the virtual pointer is moving to.
10975 * @mode: the #GdkCrossingMode to place on the synthesized events.
10977 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10979 * The real pointer window is the window that most recently received an enter notify
10980 * event. Windows that don't select for crossing events can't become the real
10981 * poiner window. The real pointer widget that owns the real pointer window. The
10982 * effective pointer window is the same as the real pointer window unless the real
10983 * pointer widget is either insensitive or there is a grab on a widget that is not
10984 * an ancestor of the real pointer widget (in which case the effective pointer
10985 * window should be the root window).
10987 * When the effective pointer window is the same as the real poiner window, we
10988 * receive crossing events from the windowing system. When the effective pointer
10989 * window changes to become different from the real pointer window we synthesize
10990 * crossing events, attempting to follow X protocol rules:
10992 * When the root window becomes the effective pointer window:
10993 * - leave notify on real pointer window, detail Ancestor
10994 * - leave notify on all of its ancestors, detail Virtual
10995 * - enter notify on root window, detail Inferior
10997 * When the root window ceases to be the effective pointer window:
10998 * - leave notify on root window, detail Inferior
10999 * - enter notify on all ancestors of real pointer window, detail Virtual
11000 * - enter notify on real pointer window, detail Ancestor
11003 _gtk_widget_synthesize_crossing (GtkWidget *from,
11006 GdkCrossingMode mode)
11008 GdkWindow *from_window = NULL, *to_window = NULL;
11010 g_return_if_fail (from != NULL || to != NULL);
11014 from_window = _gtk_widget_get_device_window (from, device);
11017 from_window = from->priv->window;
11022 to_window = _gtk_widget_get_device_window (to, device);
11025 to_window = to->priv->window;
11028 if (from_window == NULL && to_window == NULL)
11030 else if (from_window != NULL && to_window == NULL)
11032 GList *from_ancestors = NULL, *list;
11033 GdkWindow *from_ancestor = from_window;
11035 while (from_ancestor != NULL)
11037 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
11038 if (from_ancestor == NULL)
11040 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
11043 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11044 device, mode, GDK_NOTIFY_ANCESTOR);
11045 for (list = g_list_last (from_ancestors); list; list = list->prev)
11047 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11048 device, mode, GDK_NOTIFY_VIRTUAL);
11051 /* XXX: enter/inferior on root window? */
11053 g_list_free (from_ancestors);
11055 else if (from_window == NULL && to_window != NULL)
11057 GList *to_ancestors = NULL, *list;
11058 GdkWindow *to_ancestor = to_window;
11060 while (to_ancestor != NULL)
11062 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
11063 if (to_ancestor == NULL)
11065 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
11068 /* XXX: leave/inferior on root window? */
11070 for (list = to_ancestors; list; list = list->next)
11072 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11073 device, mode, GDK_NOTIFY_VIRTUAL);
11075 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11076 device, mode, GDK_NOTIFY_ANCESTOR);
11078 g_list_free (to_ancestors);
11080 else if (from_window == to_window)
11084 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
11085 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
11087 while (from_ancestor != NULL || to_ancestor != NULL)
11089 if (from_ancestor != NULL)
11091 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
11092 if (from_ancestor == to_window)
11095 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
11097 if (to_ancestor != NULL)
11099 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
11100 if (to_ancestor == from_window)
11103 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
11106 if (to_ancestor == from_window)
11108 if (mode != GDK_CROSSING_GTK_UNGRAB)
11109 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11110 device, mode, GDK_NOTIFY_INFERIOR);
11111 for (list = to_ancestors; list; list = list->next)
11112 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11113 device, mode, GDK_NOTIFY_VIRTUAL);
11114 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11115 device, mode, GDK_NOTIFY_ANCESTOR);
11117 else if (from_ancestor == to_window)
11119 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11120 device, mode, GDK_NOTIFY_ANCESTOR);
11121 for (list = g_list_last (from_ancestors); list; list = list->prev)
11123 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11124 device, mode, GDK_NOTIFY_VIRTUAL);
11126 if (mode != GDK_CROSSING_GTK_GRAB)
11127 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11128 device, mode, GDK_NOTIFY_INFERIOR);
11132 while (from_ancestors != NULL && to_ancestors != NULL
11133 && from_ancestors->data == to_ancestors->data)
11135 from_ancestors = g_list_delete_link (from_ancestors,
11137 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
11140 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11141 device, mode, GDK_NOTIFY_NONLINEAR);
11143 for (list = g_list_last (from_ancestors); list; list = list->prev)
11145 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11146 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11148 for (list = to_ancestors; list; list = list->next)
11150 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11151 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11153 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11154 device, mode, GDK_NOTIFY_NONLINEAR);
11156 g_list_free (from_ancestors);
11157 g_list_free (to_ancestors);
11162 gtk_widget_propagate_state (GtkWidget *widget,
11163 GtkStateData *data)
11165 GtkWidgetPrivate *priv = widget->priv;
11166 GtkStateFlags new_flags, old_flags = priv->state_flags;
11167 GtkStateType old_state;
11169 old_state = gtk_widget_get_state (widget);
11171 switch (data->operation)
11173 case STATE_CHANGE_REPLACE:
11174 priv->state_flags = data->flags;
11176 case STATE_CHANGE_SET:
11177 priv->state_flags |= data->flags;
11179 case STATE_CHANGE_UNSET:
11180 priv->state_flags &= ~(data->flags);
11184 /* make insensitivity unoverridable */
11185 if (!priv->sensitive)
11186 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
11188 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
11192 window = gtk_widget_get_toplevel (widget);
11194 if (window && gtk_widget_is_toplevel (window))
11195 gtk_window_set_focus (GTK_WINDOW (window), NULL);
11198 new_flags = priv->state_flags;
11200 if (old_flags != new_flags)
11202 g_object_ref (widget);
11204 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
11205 gtk_grab_remove (widget);
11207 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
11208 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
11210 if (!priv->shadowed)
11212 GList *event_windows = NULL;
11213 GList *devices, *d;
11215 devices = _gtk_widget_list_devices (widget);
11217 for (d = devices; d; d = d->next)
11223 window = _gtk_widget_get_device_window (widget, device);
11225 /* Do not propagate more than once to the
11226 * same window if non-multidevice aware.
11228 if (!gdk_window_get_support_multidevice (window) &&
11229 g_list_find (event_windows, window))
11232 if (!gtk_widget_is_sensitive (widget))
11233 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
11234 GDK_CROSSING_STATE_CHANGED);
11235 else if (old_flags & GTK_STATE_FLAG_INSENSITIVE)
11236 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
11237 GDK_CROSSING_STATE_CHANGED);
11239 event_windows = g_list_prepend (event_windows, window);
11242 g_list_free (event_windows);
11243 g_list_free (devices);
11246 if (GTK_IS_CONTAINER (widget))
11248 GtkStateData child_data = *data;
11250 /* Make sure to only propate the right states further */
11251 child_data.flags &= GTK_STATE_FLAGS_DO_PROPAGATE;
11253 if (child_data.use_forall)
11254 gtk_container_forall (GTK_CONTAINER (widget),
11255 (GtkCallback) gtk_widget_propagate_state,
11258 gtk_container_foreach (GTK_CONTAINER (widget),
11259 (GtkCallback) gtk_widget_propagate_state,
11263 /* Trigger state change transitions for the widget */
11264 if (priv->context &&
11265 gtk_widget_get_mapped (widget))
11267 gint diff, flag = 1;
11269 diff = old_flags ^ new_flags;
11273 if ((diff & flag) != 0)
11277 target = ((new_flags & flag) != 0);
11278 _gtk_widget_notify_state_change (widget, flag, target);
11287 g_object_unref (widget);
11291 static const GtkWidgetAuxInfo default_aux_info = {
11299 * gtk_widget_get_aux_info:
11300 * @widget: a #GtkWidget
11301 * @create: if %TRUE, create the structure if it doesn't exist
11303 * Get the #GtkWidgetAuxInfo structure for the widget.
11305 * Return value: the #GtkAuxInfo structure for the widget, or
11306 * %NULL if @create is %FALSE and one doesn't already exist.
11308 static GtkWidgetAuxInfo *
11309 gtk_widget_get_aux_info (GtkWidget *widget,
11312 GtkWidgetAuxInfo *aux_info;
11314 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
11315 if (!aux_info && create)
11317 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
11319 *aux_info = default_aux_info;
11321 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
11327 static const GtkWidgetAuxInfo*
11328 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11330 GtkWidgetAuxInfo *aux_info;
11332 aux_info = gtk_widget_get_aux_info (widget, FALSE);
11333 if (aux_info == NULL)
11335 return &default_aux_info;
11343 /*****************************************
11344 * gtk_widget_aux_info_destroy:
11349 *****************************************/
11352 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11354 g_slice_free (GtkWidgetAuxInfo, aux_info);
11358 * gtk_widget_shape_combine_region:
11359 * @widget: a #GtkWidget
11360 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11362 * Sets a shape for this widget's GDK window. This allows for
11363 * transparent windows etc., see gdk_window_shape_combine_region()
11364 * for more information.
11369 gtk_widget_shape_combine_region (GtkWidget *widget,
11370 cairo_region_t *region)
11372 GtkWidgetPrivate *priv;
11374 g_return_if_fail (GTK_IS_WIDGET (widget));
11375 /* set_shape doesn't work on widgets without gdk window */
11376 g_return_if_fail (gtk_widget_get_has_window (widget));
11378 priv = widget->priv;
11380 if (region == NULL)
11382 priv->has_shape_mask = FALSE;
11385 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11387 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11391 priv->has_shape_mask = TRUE;
11393 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11394 cairo_region_copy (region),
11395 (GDestroyNotify) cairo_region_destroy);
11397 /* set shape if widget has a gdk window already.
11398 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11401 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11406 * gtk_widget_input_shape_combine_region:
11407 * @widget: a #GtkWidget
11408 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11410 * Sets an input shape for this widget's GDK window. This allows for
11411 * windows which react to mouse click in a nonrectangular region, see
11412 * gdk_window_input_shape_combine_region() for more information.
11417 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11418 cairo_region_t *region)
11420 GtkWidgetPrivate *priv;
11422 g_return_if_fail (GTK_IS_WIDGET (widget));
11423 /* set_shape doesn't work on widgets without gdk window */
11424 g_return_if_fail (gtk_widget_get_has_window (widget));
11426 priv = widget->priv;
11428 if (region == NULL)
11431 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11433 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11437 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11438 cairo_region_copy (region),
11439 (GDestroyNotify) cairo_region_destroy);
11441 /* set shape if widget has a gdk window already.
11442 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11445 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11450 /* style properties
11454 * gtk_widget_class_install_style_property_parser: (skip)
11455 * @klass: a #GtkWidgetClass
11456 * @pspec: the #GParamSpec for the style property
11457 * @parser: the parser for the style property
11459 * Installs a style property on a widget class.
11462 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11464 GtkRcPropertyParser parser)
11466 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11467 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11468 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11469 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11471 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11473 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11474 G_OBJECT_CLASS_NAME (klass),
11479 g_param_spec_ref_sink (pspec);
11480 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11481 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11485 * gtk_widget_class_install_style_property:
11486 * @klass: a #GtkWidgetClass
11487 * @pspec: the #GParamSpec for the property
11489 * Installs a style property on a widget class. The parser for the
11490 * style property is determined by the value type of @pspec.
11493 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11496 GtkRcPropertyParser parser;
11498 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11499 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11501 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11503 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11507 * gtk_widget_class_find_style_property:
11508 * @klass: a #GtkWidgetClass
11509 * @property_name: the name of the style property to find
11510 * @returns: (transfer none): the #GParamSpec of the style property or
11511 * %NULL if @class has no style property with that name.
11513 * Finds a style property of a widget class by name.
11518 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11519 const gchar *property_name)
11521 g_return_val_if_fail (property_name != NULL, NULL);
11523 return g_param_spec_pool_lookup (style_property_spec_pool,
11525 G_OBJECT_CLASS_TYPE (klass),
11530 * gtk_widget_class_list_style_properties:
11531 * @klass: a #GtkWidgetClass
11532 * @n_properties: location to return the number of style properties found
11533 * @returns: (array length=n_properties) (transfer container): an
11534 * newly allocated array of #GParamSpec*. The array must be
11535 * freed with g_free().
11537 * Returns all style properties of a widget class.
11542 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11543 guint *n_properties)
11545 GParamSpec **pspecs;
11548 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11549 G_OBJECT_CLASS_TYPE (klass),
11558 * gtk_widget_style_get_property:
11559 * @widget: a #GtkWidget
11560 * @property_name: the name of a style property
11561 * @value: location to return the property value
11563 * Gets the value of a style property of @widget.
11566 gtk_widget_style_get_property (GtkWidget *widget,
11567 const gchar *property_name,
11572 g_return_if_fail (GTK_IS_WIDGET (widget));
11573 g_return_if_fail (property_name != NULL);
11574 g_return_if_fail (G_IS_VALUE (value));
11576 g_object_ref (widget);
11577 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11579 G_OBJECT_TYPE (widget),
11582 g_warning ("%s: widget class `%s' has no property named `%s'",
11584 G_OBJECT_TYPE_NAME (widget),
11588 GtkStyleContext *context;
11589 const GValue *peek_value;
11590 GtkStateFlags state;
11592 context = gtk_widget_get_style_context (widget);
11593 state = gtk_widget_get_state_flags (widget);
11595 peek_value = _gtk_style_context_peek_style_property (context,
11596 G_OBJECT_TYPE (widget),
11599 /* auto-conversion of the caller's value type
11601 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11602 g_value_copy (peek_value, value);
11603 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11604 g_value_transform (peek_value, value);
11606 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11608 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11609 G_VALUE_TYPE_NAME (value));
11611 g_object_unref (widget);
11615 * gtk_widget_style_get_valist:
11616 * @widget: a #GtkWidget
11617 * @first_property_name: the name of the first property to get
11618 * @var_args: a <type>va_list</type> of pairs of property names and
11619 * locations to return the property values, starting with the location
11620 * for @first_property_name.
11622 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11626 gtk_widget_style_get_valist (GtkWidget *widget,
11627 const gchar *first_property_name,
11630 GtkStyleContext *context;
11631 GtkStateFlags state;
11634 g_return_if_fail (GTK_IS_WIDGET (widget));
11636 g_object_ref (widget);
11637 context = gtk_widget_get_style_context (widget);
11638 state = gtk_widget_get_state_flags (widget);
11640 name = first_property_name;
11643 const GValue *peek_value;
11647 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11649 G_OBJECT_TYPE (widget),
11653 g_warning ("%s: widget class `%s' has no property named `%s'",
11655 G_OBJECT_TYPE_NAME (widget),
11659 /* style pspecs are always readable so we can spare that check here */
11661 peek_value = _gtk_style_context_peek_style_property (context,
11662 G_OBJECT_TYPE (widget),
11665 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11668 g_warning ("%s: %s", G_STRLOC, error);
11673 name = va_arg (var_args, gchar*);
11676 g_object_unref (widget);
11680 * gtk_widget_style_get:
11681 * @widget: a #GtkWidget
11682 * @first_property_name: the name of the first property to get
11683 * @Varargs: pairs of property names and locations to
11684 * return the property values, starting with the location for
11685 * @first_property_name, terminated by %NULL.
11687 * Gets the values of a multiple style properties of @widget.
11690 gtk_widget_style_get (GtkWidget *widget,
11691 const gchar *first_property_name,
11696 g_return_if_fail (GTK_IS_WIDGET (widget));
11698 va_start (var_args, first_property_name);
11699 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11705 * @widget: a #GtkWidget
11706 * @path_length: (out) (allow-none): location to store length of the path,
11708 * @path: (out) (allow-none): location to store allocated path string,
11710 * @path_reversed: (out) (allow-none): location to store allocated reverse
11711 * path string, or %NULL
11713 * Obtains the full path to @widget. The path is simply the name of a
11714 * widget and all its parents in the container hierarchy, separated by
11715 * periods. The name of a widget comes from
11716 * gtk_widget_get_name(). Paths are used to apply styles to a widget
11717 * in gtkrc configuration files. Widget names are the type of the
11718 * widget by default (e.g. "GtkButton") or can be set to an
11719 * application-specific value with gtk_widget_set_name(). By setting
11720 * the name of a widget, you allow users or theme authors to apply
11721 * styles to that specific widget in their gtkrc
11722 * file. @path_reversed_p fills in the path in reverse order,
11723 * i.e. starting with @widget's name instead of starting with the name
11724 * of @widget's outermost ancestor.
11726 * Deprecated:3.0: Use gtk_widget_get_path() instead
11729 gtk_widget_path (GtkWidget *widget,
11730 guint *path_length,
11732 gchar **path_reversed)
11734 static gchar *rev_path = NULL;
11735 static guint tmp_path_len = 0;
11738 g_return_if_fail (GTK_IS_WIDGET (widget));
11743 const gchar *string;
11748 string = gtk_widget_get_name (widget);
11749 l = strlen (string);
11750 while (tmp_path_len <= len + l + 1)
11752 tmp_path_len += INIT_PATH_SIZE;
11753 rev_path = g_realloc (rev_path, tmp_path_len);
11755 s = string + l - 1;
11756 d = rev_path + len;
11757 while (s >= string)
11761 widget = widget->priv->parent;
11764 rev_path[len++] = '.';
11766 rev_path[len++] = 0;
11771 *path_length = len - 1;
11773 *path_reversed = g_strdup (rev_path);
11776 *path = g_strdup (rev_path);
11777 g_strreverse (*path);
11782 * gtk_widget_class_path:
11783 * @widget: a #GtkWidget
11784 * @path_length: (out) (allow-none): location to store the length of the
11785 * class path, or %NULL
11786 * @path: (out) (allow-none): location to store the class path as an
11787 * allocated string, or %NULL
11788 * @path_reversed: (out) (allow-none): location to store the reverse
11789 * class path as an allocated string, or %NULL
11791 * Same as gtk_widget_path(), but always uses the name of a widget's type,
11792 * never uses a custom name set with gtk_widget_set_name().
11794 * Deprecated:3.0: Use gtk_widget_get_path() instead
11797 gtk_widget_class_path (GtkWidget *widget,
11798 guint *path_length,
11800 gchar **path_reversed)
11802 static gchar *rev_path = NULL;
11803 static guint tmp_path_len = 0;
11806 g_return_if_fail (GTK_IS_WIDGET (widget));
11811 const gchar *string;
11816 string = g_type_name (G_OBJECT_TYPE (widget));
11817 l = strlen (string);
11818 while (tmp_path_len <= len + l + 1)
11820 tmp_path_len += INIT_PATH_SIZE;
11821 rev_path = g_realloc (rev_path, tmp_path_len);
11823 s = string + l - 1;
11824 d = rev_path + len;
11825 while (s >= string)
11829 widget = widget->priv->parent;
11832 rev_path[len++] = '.';
11834 rev_path[len++] = 0;
11839 *path_length = len - 1;
11841 *path_reversed = g_strdup (rev_path);
11844 *path = g_strdup (rev_path);
11845 g_strreverse (*path);
11850 * gtk_requisition_new:
11852 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11854 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11855 * be freed with gtk_requisition_free().
11860 gtk_requisition_new (void)
11862 return g_slice_new0 (GtkRequisition);
11866 * gtk_requisition_copy:
11867 * @requisition: a #GtkRequisition
11869 * Copies a #GtkRequisition.
11871 * Returns: a copy of @requisition
11874 gtk_requisition_copy (const GtkRequisition *requisition)
11876 return g_slice_dup (GtkRequisition, requisition);
11880 * gtk_requisition_free:
11881 * @requisition: a #GtkRequisition
11883 * Frees a #GtkRequisition.
11886 gtk_requisition_free (GtkRequisition *requisition)
11888 g_slice_free (GtkRequisition, requisition);
11891 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11892 gtk_requisition_copy,
11893 gtk_requisition_free)
11896 * gtk_widget_get_accessible:
11897 * @widget: a #GtkWidget
11899 * Returns the accessible object that describes the widget to an
11900 * assistive technology.
11902 * If no accessibility library is loaded (i.e. no ATK implementation library is
11903 * loaded via <envar>GTK_MODULES</envar> or via another application library,
11904 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
11905 * if no class-specific #AtkObject implementation is available for the widget
11906 * instance in question, it will inherit an #AtkObject implementation from the
11907 * first ancestor class for which such an implementation is defined.
11909 * The documentation of the
11910 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
11911 * library contains more information about accessible objects and their uses.
11913 * Returns: (transfer none): the #AtkObject associated with @widget
11916 gtk_widget_get_accessible (GtkWidget *widget)
11918 GtkWidgetClass *klass;
11920 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11922 klass = GTK_WIDGET_GET_CLASS (widget);
11924 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11926 return klass->get_accessible (widget);
11930 gtk_widget_real_get_accessible (GtkWidget *widget)
11932 AtkObject* accessible;
11934 accessible = g_object_get_qdata (G_OBJECT (widget),
11935 quark_accessible_object);
11938 AtkObjectFactory *factory;
11939 AtkRegistry *default_registry;
11941 default_registry = atk_get_default_registry ();
11942 factory = atk_registry_get_factory (default_registry,
11943 G_TYPE_FROM_INSTANCE (widget));
11945 atk_object_factory_create_accessible (factory,
11946 G_OBJECT (widget));
11947 g_object_set_qdata (G_OBJECT (widget),
11948 quark_accessible_object,
11955 * Initialize a AtkImplementorIface instance's virtual pointers as
11956 * appropriate to this implementor's class (GtkWidget).
11959 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11961 iface->ref_accessible = gtk_widget_ref_accessible;
11965 gtk_widget_ref_accessible (AtkImplementor *implementor)
11967 AtkObject *accessible;
11969 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11971 g_object_ref (accessible);
11976 * Expand flag management
11980 gtk_widget_update_computed_expand (GtkWidget *widget)
11982 GtkWidgetPrivate *priv;
11984 priv = widget->priv;
11986 if (priv->need_compute_expand)
11990 if (priv->hexpand_set)
11995 if (priv->vexpand_set)
12000 /* we don't need to use compute_expand if both expands are
12001 * forced by the app
12003 if (!(priv->hexpand_set && priv->vexpand_set))
12005 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
12009 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
12010 priv->hexpand_set ? &ignored : &h,
12011 priv->vexpand_set ? &ignored : &v);
12015 priv->need_compute_expand = FALSE;
12016 priv->computed_hexpand = h != FALSE;
12017 priv->computed_vexpand = v != FALSE;
12022 * gtk_widget_queue_compute_expand:
12023 * @widget: a #GtkWidget
12025 * Mark @widget as needing to recompute its expand flags. Call
12026 * this function when setting legacy expand child properties
12027 * on the child of a container.
12029 * See gtk_widget_compute_expand().
12032 gtk_widget_queue_compute_expand (GtkWidget *widget)
12035 gboolean changed_anything;
12037 if (widget->priv->need_compute_expand)
12040 changed_anything = FALSE;
12042 while (parent != NULL)
12044 if (!parent->priv->need_compute_expand)
12046 parent->priv->need_compute_expand = TRUE;
12047 changed_anything = TRUE;
12050 /* Note: if we had an invariant that "if a child needs to
12051 * compute expand, its parents also do" then we could stop going
12052 * up when we got to a parent that already needed to
12053 * compute. However, in general we compute expand lazily (as
12054 * soon as we see something in a subtree that is expand, we know
12055 * we're expanding) and so this invariant does not hold and we
12056 * have to always walk all the way up in case some ancestor
12057 * is not currently need_compute_expand.
12060 parent = parent->priv->parent;
12063 /* recomputing expand always requires
12064 * a relayout as well
12066 if (changed_anything)
12067 gtk_widget_queue_resize (widget);
12071 * gtk_widget_compute_expand:
12072 * @widget: the widget
12073 * @orientation: expand direction
12075 * Computes whether a container should give this widget extra space
12076 * when possible. Containers should check this, rather than
12077 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
12079 * This function already checks whether the widget is visible, so
12080 * visibility does not need to be checked separately. Non-visible
12081 * widgets are not expanded.
12083 * The computed expand value uses either the expand setting explicitly
12084 * set on the widget itself, or, if none has been explicitly set,
12085 * the widget may expand if some of its children do.
12087 * Return value: whether widget tree rooted here should be expanded
12090 gtk_widget_compute_expand (GtkWidget *widget,
12091 GtkOrientation orientation)
12093 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12095 /* We never make a widget expand if not even showing. */
12096 if (!gtk_widget_get_visible (widget))
12099 gtk_widget_update_computed_expand (widget);
12101 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12103 return widget->priv->computed_hexpand;
12107 return widget->priv->computed_vexpand;
12112 gtk_widget_set_expand (GtkWidget *widget,
12113 GtkOrientation orientation,
12116 const char *expand_prop;
12117 const char *expand_set_prop;
12119 GtkWidgetPrivate *priv;
12121 g_return_if_fail (GTK_IS_WIDGET (widget));
12123 priv = widget->priv;
12125 expand = expand != FALSE;
12127 was_both = priv->hexpand && priv->vexpand;
12129 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12131 if (priv->hexpand_set &&
12132 priv->hexpand == expand)
12135 priv->hexpand_set = TRUE;
12136 priv->hexpand = expand;
12138 expand_prop = "hexpand";
12139 expand_set_prop = "hexpand-set";
12143 if (priv->vexpand_set &&
12144 priv->vexpand == expand)
12147 priv->vexpand_set = TRUE;
12148 priv->vexpand = expand;
12150 expand_prop = "vexpand";
12151 expand_set_prop = "vexpand-set";
12154 gtk_widget_queue_compute_expand (widget);
12156 g_object_freeze_notify (G_OBJECT (widget));
12157 g_object_notify (G_OBJECT (widget), expand_prop);
12158 g_object_notify (G_OBJECT (widget), expand_set_prop);
12159 if (was_both != (priv->hexpand && priv->vexpand))
12160 g_object_notify (G_OBJECT (widget), "expand");
12161 g_object_thaw_notify (G_OBJECT (widget));
12165 gtk_widget_set_expand_set (GtkWidget *widget,
12166 GtkOrientation orientation,
12169 GtkWidgetPrivate *priv;
12172 priv = widget->priv;
12174 set = set != FALSE;
12176 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12178 if (set == priv->hexpand_set)
12181 priv->hexpand_set = set;
12182 prop = "hexpand-set";
12186 if (set == priv->vexpand_set)
12189 priv->vexpand_set = set;
12190 prop = "vexpand-set";
12193 gtk_widget_queue_compute_expand (widget);
12195 g_object_notify (G_OBJECT (widget), prop);
12199 * gtk_widget_get_hexpand:
12200 * @widget: the widget
12202 * Gets whether the widget would like any available extra horizontal
12203 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12204 * generally receive the extra space. For example, a list or
12205 * scrollable area or document in your window would often be set to
12208 * Containers should use gtk_widget_compute_expand() rather than
12209 * this function, to see whether a widget, or any of its children,
12210 * has the expand flag set. If any child of a widget wants to
12211 * expand, the parent may ask to expand also.
12213 * This function only looks at the widget's own hexpand flag, rather
12214 * than computing whether the entire widget tree rooted at this widget
12217 * Return value: whether hexpand flag is set
12220 gtk_widget_get_hexpand (GtkWidget *widget)
12222 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12224 return widget->priv->hexpand;
12228 * gtk_widget_set_hexpand:
12229 * @widget: the widget
12230 * @expand: whether to expand
12232 * Sets whether the widget would like any available extra horizontal
12233 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12234 * generally receive the extra space. For example, a list or
12235 * scrollable area or document in your window would often be set to
12238 * Call this function to set the expand flag if you would like your
12239 * widget to become larger horizontally when the window has extra
12242 * By default, widgets automatically expand if any of their children
12243 * want to expand. (To see if a widget will automatically expand given
12244 * its current children and state, call gtk_widget_compute_expand(). A
12245 * container can decide how the expandability of children affects the
12246 * expansion of the container by overriding the compute_expand virtual
12247 * method on #GtkWidget.).
12249 * Setting hexpand explicitly with this function will override the
12250 * automatic expand behavior.
12252 * This function forces the widget to expand or not to expand,
12253 * regardless of children. The override occurs because
12254 * gtk_widget_set_hexpand() sets the hexpand-set property (see
12255 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
12256 * value to be used, rather than looking at children and widget state.
12259 gtk_widget_set_hexpand (GtkWidget *widget,
12262 g_return_if_fail (GTK_IS_WIDGET (widget));
12264 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
12268 * gtk_widget_get_hexpand_set:
12269 * @widget: the widget
12271 * Gets whether gtk_widget_set_hexpand() has been used to
12272 * explicitly set the expand flag on this widget.
12274 * If hexpand is set, then it overrides any computed
12275 * expand value based on child widgets. If hexpand is not
12276 * set, then the expand value depends on whether any
12277 * children of the widget would like to expand.
12279 * There are few reasons to use this function, but it's here
12280 * for completeness and consistency.
12282 * Return value: whether hexpand has been explicitly set
12285 gtk_widget_get_hexpand_set (GtkWidget *widget)
12287 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12289 return widget->priv->hexpand_set;
12293 * gtk_widget_set_hexpand_set:
12294 * @widget: the widget
12295 * @set: value for hexpand-set property
12297 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
12300 * The hexpand-set property will be set automatically when you call
12301 * gtk_widget_set_hexpand() to set hexpand, so the most likely
12302 * reason to use this function would be to unset an explicit expand
12305 * If hexpand is set, then it overrides any computed
12306 * expand value based on child widgets. If hexpand is not
12307 * set, then the expand value depends on whether any
12308 * children of the widget would like to expand.
12310 * There are few reasons to use this function, but it's here
12311 * for completeness and consistency.
12314 gtk_widget_set_hexpand_set (GtkWidget *widget,
12317 g_return_if_fail (GTK_IS_WIDGET (widget));
12319 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
12324 * gtk_widget_get_vexpand:
12325 * @widget: the widget
12327 * Gets whether the widget would like any available extra vertical
12330 * See gtk_widget_get_hexpand() for more detail.
12332 * Return value: whether vexpand flag is set
12335 gtk_widget_get_vexpand (GtkWidget *widget)
12337 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12339 return widget->priv->vexpand;
12343 * gtk_widget_set_vexpand:
12344 * @widget: the widget
12345 * @expand: whether to expand
12347 * Sets whether the widget would like any available extra vertical
12350 * See gtk_widget_set_hexpand() for more detail.
12353 gtk_widget_set_vexpand (GtkWidget *widget,
12356 g_return_if_fail (GTK_IS_WIDGET (widget));
12358 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12362 * gtk_widget_get_vexpand_set:
12363 * @widget: the widget
12365 * Gets whether gtk_widget_set_vexpand() has been used to
12366 * explicitly set the expand flag on this widget.
12368 * See gtk_widget_get_hexpand_set() for more detail.
12370 * Return value: whether vexpand has been explicitly set
12373 gtk_widget_get_vexpand_set (GtkWidget *widget)
12375 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12377 return widget->priv->vexpand_set;
12381 * gtk_widget_set_vexpand_set:
12382 * @widget: the widget
12383 * @set: value for vexpand-set property
12385 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12388 * See gtk_widget_set_hexpand_set() for more detail.
12391 gtk_widget_set_vexpand_set (GtkWidget *widget,
12394 g_return_if_fail (GTK_IS_WIDGET (widget));
12396 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12400 * GtkBuildable implementation
12402 static GQuark quark_builder_has_default = 0;
12403 static GQuark quark_builder_has_focus = 0;
12404 static GQuark quark_builder_atk_relations = 0;
12405 static GQuark quark_builder_set_name = 0;
12408 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12410 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12411 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12412 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12413 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12415 iface->set_name = gtk_widget_buildable_set_name;
12416 iface->get_name = gtk_widget_buildable_get_name;
12417 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12418 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12419 iface->parser_finished = gtk_widget_buildable_parser_finished;
12420 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12421 iface->custom_finished = gtk_widget_buildable_custom_finished;
12425 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12428 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12429 g_strdup (name), g_free);
12432 static const gchar *
12433 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12435 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12439 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12440 GtkBuilder *builder,
12441 const gchar *childname)
12443 if (strcmp (childname, "accessible") == 0)
12444 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12450 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12451 GtkBuilder *builder,
12453 const GValue *value)
12455 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12456 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12457 GINT_TO_POINTER (TRUE));
12458 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12459 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12460 GINT_TO_POINTER (TRUE));
12462 g_object_set_property (G_OBJECT (buildable), name, value);
12467 gchar *action_name;
12468 GString *description;
12470 gboolean translatable;
12480 free_action (AtkActionData *data, gpointer user_data)
12482 g_free (data->action_name);
12483 g_string_free (data->description, TRUE);
12484 g_free (data->context);
12485 g_slice_free (AtkActionData, data);
12489 free_relation (AtkRelationData *data, gpointer user_data)
12491 g_free (data->target);
12492 g_free (data->type);
12493 g_slice_free (AtkRelationData, data);
12497 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12498 GtkBuilder *builder)
12500 GSList *atk_relations;
12502 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12503 gtk_widget_grab_default (GTK_WIDGET (buildable));
12504 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12505 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12507 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12508 quark_builder_atk_relations);
12511 AtkObject *accessible;
12512 AtkRelationSet *relation_set;
12515 AtkRelationType relation_type;
12516 AtkObject *target_accessible;
12518 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12519 relation_set = atk_object_ref_relation_set (accessible);
12521 for (l = atk_relations; l; l = l->next)
12523 AtkRelationData *relation = (AtkRelationData*)l->data;
12525 target = gtk_builder_get_object (builder, relation->target);
12528 g_warning ("Target object %s in <relation> does not exist",
12532 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12533 g_assert (target_accessible != NULL);
12535 relation_type = atk_relation_type_for_name (relation->type);
12536 if (relation_type == ATK_RELATION_NULL)
12538 g_warning ("<relation> type %s not found",
12542 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12543 target_accessible);
12545 g_object_unref (relation_set);
12547 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
12548 g_slist_free (atk_relations);
12549 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12558 } AccessibilitySubParserData;
12561 accessibility_start_element (GMarkupParseContext *context,
12562 const gchar *element_name,
12563 const gchar **names,
12564 const gchar **values,
12565 gpointer user_data,
12568 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12570 gint line_number, char_number;
12572 if (strcmp (element_name, "relation") == 0)
12574 gchar *target = NULL;
12575 gchar *type = NULL;
12576 AtkRelationData *relation;
12578 for (i = 0; names[i]; i++)
12580 if (strcmp (names[i], "target") == 0)
12581 target = g_strdup (values[i]);
12582 else if (strcmp (names[i], "type") == 0)
12583 type = g_strdup (values[i]);
12586 g_markup_parse_context_get_position (context,
12589 g_set_error (error,
12591 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12592 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12594 line_number, char_number, names[i], "relation");
12601 if (!target || !type)
12603 g_markup_parse_context_get_position (context,
12606 g_set_error (error,
12608 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12609 "%s:%d:%d <%s> requires attribute \"%s\"",
12611 line_number, char_number, "relation",
12612 type ? "target" : "type");
12618 relation = g_slice_new (AtkRelationData);
12619 relation->target = target;
12620 relation->type = type;
12622 data->relations = g_slist_prepend (data->relations, relation);
12624 else if (strcmp (element_name, "action") == 0)
12626 const gchar *action_name = NULL;
12627 const gchar *description = NULL;
12628 const gchar *msg_context = NULL;
12629 gboolean translatable = FALSE;
12630 AtkActionData *action;
12632 for (i = 0; names[i]; i++)
12634 if (strcmp (names[i], "action_name") == 0)
12635 action_name = values[i];
12636 else if (strcmp (names[i], "description") == 0)
12637 description = values[i];
12638 else if (strcmp (names[i], "translatable") == 0)
12640 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12643 else if (strcmp (names[i], "comments") == 0)
12645 /* do nothing, comments are for translators */
12647 else if (strcmp (names[i], "context") == 0)
12648 msg_context = values[i];
12651 g_markup_parse_context_get_position (context,
12654 g_set_error (error,
12656 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12657 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12659 line_number, char_number, names[i], "action");
12666 g_markup_parse_context_get_position (context,
12669 g_set_error (error,
12671 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12672 "%s:%d:%d <%s> requires attribute \"%s\"",
12674 line_number, char_number, "action",
12679 action = g_slice_new (AtkActionData);
12680 action->action_name = g_strdup (action_name);
12681 action->description = g_string_new (description);
12682 action->context = g_strdup (msg_context);
12683 action->translatable = translatable;
12685 data->actions = g_slist_prepend (data->actions, action);
12687 else if (strcmp (element_name, "accessibility") == 0)
12690 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12694 accessibility_text (GMarkupParseContext *context,
12697 gpointer user_data,
12700 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12702 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12704 AtkActionData *action = data->actions->data;
12706 g_string_append_len (action->description, text, text_len);
12710 static const GMarkupParser accessibility_parser =
12712 accessibility_start_element,
12714 accessibility_text,
12723 } AccelGroupParserData;
12726 accel_group_start_element (GMarkupParseContext *context,
12727 const gchar *element_name,
12728 const gchar **names,
12729 const gchar **values,
12730 gpointer user_data,
12735 guint modifiers = 0;
12736 gchar *signal = NULL;
12737 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12739 for (i = 0; names[i]; i++)
12741 if (strcmp (names[i], "key") == 0)
12742 key = gdk_keyval_from_name (values[i]);
12743 else if (strcmp (names[i], "modifiers") == 0)
12745 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12751 else if (strcmp (names[i], "signal") == 0)
12752 signal = g_strdup (values[i]);
12755 if (key == 0 || signal == NULL)
12757 g_warning ("<accelerator> requires key and signal attributes");
12760 parser_data->key = key;
12761 parser_data->modifiers = modifiers;
12762 parser_data->signal = signal;
12765 static const GMarkupParser accel_group_parser =
12767 accel_group_start_element,
12776 style_start_element (GMarkupParseContext *context,
12777 const gchar *element_name,
12778 const gchar **names,
12779 const gchar **values,
12780 gpointer user_data,
12783 StyleParserData *style_data = (StyleParserData *)user_data;
12786 if (strcmp (element_name, "class") == 0)
12788 if (g_markup_collect_attributes (element_name,
12792 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12793 G_MARKUP_COLLECT_INVALID))
12795 style_data->classes = g_slist_append (style_data->classes, class_name);
12798 else if (strcmp (element_name, "style") == 0)
12801 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12804 static const GMarkupParser style_parser =
12806 style_start_element,
12810 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12811 GtkBuilder *builder,
12813 const gchar *tagname,
12814 GMarkupParser *parser,
12817 g_assert (buildable);
12819 if (strcmp (tagname, "accelerator") == 0)
12821 AccelGroupParserData *parser_data;
12823 parser_data = g_slice_new0 (AccelGroupParserData);
12824 parser_data->object = g_object_ref (buildable);
12825 *parser = accel_group_parser;
12826 *data = parser_data;
12829 if (strcmp (tagname, "accessibility") == 0)
12831 AccessibilitySubParserData *parser_data;
12833 parser_data = g_slice_new0 (AccessibilitySubParserData);
12834 *parser = accessibility_parser;
12835 *data = parser_data;
12838 if (strcmp (tagname, "style") == 0)
12840 StyleParserData *parser_data;
12842 parser_data = g_slice_new0 (StyleParserData);
12843 *parser = style_parser;
12844 *data = parser_data;
12852 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12853 GtkWidget *toplevel,
12854 gpointer user_data)
12856 AccelGroupParserData *accel_data;
12857 GSList *accel_groups;
12858 GtkAccelGroup *accel_group;
12860 g_return_if_fail (GTK_IS_WIDGET (widget));
12861 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12862 g_return_if_fail (user_data != NULL);
12864 accel_data = (AccelGroupParserData*)user_data;
12865 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12866 if (g_slist_length (accel_groups) == 0)
12868 accel_group = gtk_accel_group_new ();
12869 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12873 g_assert (g_slist_length (accel_groups) == 1);
12874 accel_group = g_slist_nth_data (accel_groups, 0);
12877 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12878 accel_data->signal,
12881 accel_data->modifiers,
12882 GTK_ACCEL_VISIBLE);
12884 g_object_unref (accel_data->object);
12885 g_free (accel_data->signal);
12886 g_slice_free (AccelGroupParserData, accel_data);
12890 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12891 GtkBuilder *builder,
12893 const gchar *tagname,
12894 gpointer user_data)
12896 if (strcmp (tagname, "accelerator") == 0)
12898 AccelGroupParserData *accel_data;
12899 GtkWidget *toplevel;
12901 accel_data = (AccelGroupParserData*)user_data;
12902 g_assert (accel_data->object);
12904 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12906 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12908 else if (strcmp (tagname, "accessibility") == 0)
12910 AccessibilitySubParserData *a11y_data;
12912 a11y_data = (AccessibilitySubParserData*)user_data;
12914 if (a11y_data->actions)
12916 AtkObject *accessible;
12921 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12923 if (ATK_IS_ACTION (accessible))
12925 action = ATK_ACTION (accessible);
12926 n_actions = atk_action_get_n_actions (action);
12928 for (l = a11y_data->actions; l; l = l->next)
12930 AtkActionData *action_data = (AtkActionData*)l->data;
12932 for (i = 0; i < n_actions; i++)
12933 if (strcmp (atk_action_get_name (action, i),
12934 action_data->action_name) == 0)
12939 gchar *description;
12941 if (action_data->translatable && action_data->description->len)
12942 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12943 action_data->context,
12944 action_data->description->str);
12946 description = action_data->description->str;
12948 atk_action_set_description (action, i, description);
12953 g_warning ("accessibility action on a widget that does not implement AtkAction");
12955 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
12956 g_slist_free (a11y_data->actions);
12959 if (a11y_data->relations)
12960 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12961 a11y_data->relations);
12963 g_slice_free (AccessibilitySubParserData, a11y_data);
12965 else if (strcmp (tagname, "style") == 0)
12967 StyleParserData *style_data = (StyleParserData *)user_data;
12968 GtkStyleContext *context;
12971 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
12973 for (l = style_data->classes; l; l = l->next)
12974 gtk_style_context_add_class (context, (const gchar *)l->data);
12976 gtk_widget_reset_style (GTK_WIDGET (buildable));
12978 g_slist_free_full (style_data->classes, g_free);
12979 g_slice_free (StyleParserData, style_data);
12983 static GtkSizeRequestMode
12984 gtk_widget_real_get_request_mode (GtkWidget *widget)
12986 /* By default widgets dont trade size at all. */
12987 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
12991 gtk_widget_real_get_width (GtkWidget *widget,
12992 gint *minimum_size,
12993 gint *natural_size)
13003 gtk_widget_real_get_height (GtkWidget *widget,
13004 gint *minimum_size,
13005 gint *natural_size)
13015 gtk_widget_real_get_height_for_width (GtkWidget *widget,
13017 gint *minimum_height,
13018 gint *natural_height)
13020 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
13024 gtk_widget_real_get_width_for_height (GtkWidget *widget,
13026 gint *minimum_width,
13027 gint *natural_width)
13029 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
13033 * gtk_widget_get_halign:
13034 * @widget: a #GtkWidget
13036 * Gets the value of the #GtkWidget:halign property.
13038 * Returns: the horizontal alignment of @widget
13041 gtk_widget_get_halign (GtkWidget *widget)
13043 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
13044 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
13048 * gtk_widget_set_halign:
13049 * @widget: a #GtkWidget
13050 * @align: the horizontal alignment
13052 * Sets the horizontal alignment of @widget.
13053 * See the #GtkWidget:halign property.
13056 gtk_widget_set_halign (GtkWidget *widget,
13059 GtkWidgetAuxInfo *aux_info;
13061 g_return_if_fail (GTK_IS_WIDGET (widget));
13063 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13065 if (aux_info->halign == align)
13068 aux_info->halign = align;
13069 gtk_widget_queue_resize (widget);
13070 g_object_notify (G_OBJECT (widget), "halign");
13074 * gtk_widget_get_valign:
13075 * @widget: a #GtkWidget
13077 * Gets the value of the #GtkWidget:valign property.
13079 * Returns: the vertical alignment of @widget
13082 gtk_widget_get_valign (GtkWidget *widget)
13084 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
13085 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
13089 * gtk_widget_set_valign:
13090 * @widget: a #GtkWidget
13091 * @align: the vertical alignment
13093 * Sets the vertical alignment of @widget.
13094 * See the #GtkWidget:valign property.
13097 gtk_widget_set_valign (GtkWidget *widget,
13100 GtkWidgetAuxInfo *aux_info;
13102 g_return_if_fail (GTK_IS_WIDGET (widget));
13104 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13106 if (aux_info->valign == align)
13109 aux_info->valign = align;
13110 gtk_widget_queue_resize (widget);
13111 g_object_notify (G_OBJECT (widget), "valign");
13115 * gtk_widget_get_margin_left:
13116 * @widget: a #GtkWidget
13118 * Gets the value of the #GtkWidget:margin-left property.
13120 * Returns: The left margin of @widget
13125 gtk_widget_get_margin_left (GtkWidget *widget)
13127 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13129 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
13133 * gtk_widget_set_margin_left:
13134 * @widget: a #GtkWidget
13135 * @margin: the left margin
13137 * Sets the left margin of @widget.
13138 * See the #GtkWidget:margin-left property.
13143 gtk_widget_set_margin_left (GtkWidget *widget,
13146 GtkWidgetAuxInfo *aux_info;
13148 g_return_if_fail (GTK_IS_WIDGET (widget));
13149 g_return_if_fail (margin <= G_MAXINT16);
13151 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13153 if (aux_info->margin.left == margin)
13156 aux_info->margin.left = margin;
13157 gtk_widget_queue_resize (widget);
13158 g_object_notify (G_OBJECT (widget), "margin-left");
13162 * gtk_widget_get_margin_right:
13163 * @widget: a #GtkWidget
13165 * Gets the value of the #GtkWidget:margin-right property.
13167 * Returns: The right margin of @widget
13172 gtk_widget_get_margin_right (GtkWidget *widget)
13174 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13176 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
13180 * gtk_widget_set_margin_right:
13181 * @widget: a #GtkWidget
13182 * @margin: the right margin
13184 * Sets the right margin of @widget.
13185 * See the #GtkWidget:margin-right property.
13190 gtk_widget_set_margin_right (GtkWidget *widget,
13193 GtkWidgetAuxInfo *aux_info;
13195 g_return_if_fail (GTK_IS_WIDGET (widget));
13196 g_return_if_fail (margin <= G_MAXINT16);
13198 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13200 if (aux_info->margin.right == margin)
13203 aux_info->margin.right = margin;
13204 gtk_widget_queue_resize (widget);
13205 g_object_notify (G_OBJECT (widget), "margin-right");
13209 * gtk_widget_get_margin_top:
13210 * @widget: a #GtkWidget
13212 * Gets the value of the #GtkWidget:margin-top property.
13214 * Returns: The top margin of @widget
13219 gtk_widget_get_margin_top (GtkWidget *widget)
13221 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13223 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
13227 * gtk_widget_set_margin_top:
13228 * @widget: a #GtkWidget
13229 * @margin: the top margin
13231 * Sets the top margin of @widget.
13232 * See the #GtkWidget:margin-top property.
13237 gtk_widget_set_margin_top (GtkWidget *widget,
13240 GtkWidgetAuxInfo *aux_info;
13242 g_return_if_fail (GTK_IS_WIDGET (widget));
13243 g_return_if_fail (margin <= G_MAXINT16);
13245 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13247 if (aux_info->margin.top == margin)
13250 aux_info->margin.top = margin;
13251 gtk_widget_queue_resize (widget);
13252 g_object_notify (G_OBJECT (widget), "margin-top");
13256 * gtk_widget_get_margin_bottom:
13257 * @widget: a #GtkWidget
13259 * Gets the value of the #GtkWidget:margin-bottom property.
13261 * Returns: The bottom margin of @widget
13266 gtk_widget_get_margin_bottom (GtkWidget *widget)
13268 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13270 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
13274 * gtk_widget_set_margin_bottom:
13275 * @widget: a #GtkWidget
13276 * @margin: the bottom margin
13278 * Sets the bottom margin of @widget.
13279 * See the #GtkWidget:margin-bottom property.
13284 gtk_widget_set_margin_bottom (GtkWidget *widget,
13287 GtkWidgetAuxInfo *aux_info;
13289 g_return_if_fail (GTK_IS_WIDGET (widget));
13290 g_return_if_fail (margin <= G_MAXINT16);
13292 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13294 if (aux_info->margin.bottom == margin)
13297 aux_info->margin.bottom = margin;
13298 gtk_widget_queue_resize (widget);
13299 g_object_notify (G_OBJECT (widget), "margin-bottom");
13303 * gtk_widget_get_clipboard:
13304 * @widget: a #GtkWidget
13305 * @selection: a #GdkAtom which identifies the clipboard
13306 * to use. %GDK_SELECTION_CLIPBOARD gives the
13307 * default clipboard. Another common value
13308 * is %GDK_SELECTION_PRIMARY, which gives
13309 * the primary X selection.
13311 * Returns the clipboard object for the given selection to
13312 * be used with @widget. @widget must have a #GdkDisplay
13313 * associated with it, so must be attached to a toplevel
13316 * Return value: (transfer none): the appropriate clipboard object. If no
13317 * clipboard already exists, a new one will
13318 * be created. Once a clipboard object has
13319 * been created, it is persistent for all time.
13324 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
13326 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13327 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
13329 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
13334 * gtk_widget_list_mnemonic_labels:
13335 * @widget: a #GtkWidget
13337 * Returns a newly allocated list of the widgets, normally labels, for
13338 * which this widget is the target of a mnemonic (see for example,
13339 * gtk_label_set_mnemonic_widget()).
13341 * The widgets in the list are not individually referenced. If you
13342 * want to iterate through the list and perform actions involving
13343 * callbacks that might destroy the widgets, you
13344 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
13345 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
13346 * widgets afterwards.
13348 * Return value: (element-type GtkWidget) (transfer container): the list of
13349 * mnemonic labels; free this list
13350 * with g_list_free() when you are done with it.
13355 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
13357 GList *list = NULL;
13360 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13362 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13363 list = g_list_prepend (list, l->data);
13369 * gtk_widget_add_mnemonic_label:
13370 * @widget: a #GtkWidget
13371 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13373 * Adds a widget to the list of mnemonic labels for
13374 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13375 * list of mnemonic labels for the widget is cleared when the
13376 * widget is destroyed, so the caller must make sure to update
13377 * its internal state at this point as well, by using a connection
13378 * to the #GtkWidget::destroy signal or a weak notifier.
13383 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13386 GSList *old_list, *new_list;
13388 g_return_if_fail (GTK_IS_WIDGET (widget));
13389 g_return_if_fail (GTK_IS_WIDGET (label));
13391 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13392 new_list = g_slist_prepend (old_list, label);
13394 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13395 new_list, (GDestroyNotify) g_slist_free);
13399 * gtk_widget_remove_mnemonic_label:
13400 * @widget: a #GtkWidget
13401 * @label: a #GtkWidget that was previously set as a mnemnic label for
13402 * @widget with gtk_widget_add_mnemonic_label().
13404 * Removes a widget from the list of mnemonic labels for
13405 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13406 * must have previously been added to the list with
13407 * gtk_widget_add_mnemonic_label().
13412 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13415 GSList *old_list, *new_list;
13417 g_return_if_fail (GTK_IS_WIDGET (widget));
13418 g_return_if_fail (GTK_IS_WIDGET (label));
13420 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13421 new_list = g_slist_remove (old_list, label);
13424 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13425 new_list, (GDestroyNotify) g_slist_free);
13429 * gtk_widget_get_no_show_all:
13430 * @widget: a #GtkWidget
13432 * Returns the current value of the #GtkWidget:no-show-all property,
13433 * which determines whether calls to gtk_widget_show_all()
13434 * will affect this widget.
13436 * Return value: the current value of the "no-show-all" property.
13441 gtk_widget_get_no_show_all (GtkWidget *widget)
13443 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13445 return widget->priv->no_show_all;
13449 * gtk_widget_set_no_show_all:
13450 * @widget: a #GtkWidget
13451 * @no_show_all: the new value for the "no-show-all" property
13453 * Sets the #GtkWidget:no-show-all property, which determines whether
13454 * calls to gtk_widget_show_all() will affect this widget.
13456 * This is mostly for use in constructing widget hierarchies with externally
13457 * controlled visibility, see #GtkUIManager.
13462 gtk_widget_set_no_show_all (GtkWidget *widget,
13463 gboolean no_show_all)
13465 g_return_if_fail (GTK_IS_WIDGET (widget));
13467 no_show_all = (no_show_all != FALSE);
13469 if (widget->priv->no_show_all != no_show_all)
13471 widget->priv->no_show_all = no_show_all;
13473 g_object_notify (G_OBJECT (widget), "no-show-all");
13479 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13480 gboolean has_tooltip,
13483 GtkWidgetPrivate *priv = widget->priv;
13484 gboolean priv_has_tooltip;
13486 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13487 quark_has_tooltip));
13489 if (priv_has_tooltip != has_tooltip || force)
13491 priv_has_tooltip = has_tooltip;
13493 if (priv_has_tooltip)
13495 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13496 gdk_window_set_events (priv->window,
13497 gdk_window_get_events (priv->window) |
13498 GDK_LEAVE_NOTIFY_MASK |
13499 GDK_POINTER_MOTION_MASK |
13500 GDK_POINTER_MOTION_HINT_MASK);
13502 if (gtk_widget_get_has_window (widget))
13503 gtk_widget_add_events (widget,
13504 GDK_LEAVE_NOTIFY_MASK |
13505 GDK_POINTER_MOTION_MASK |
13506 GDK_POINTER_MOTION_HINT_MASK);
13509 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13510 GUINT_TO_POINTER (priv_has_tooltip));
13515 * gtk_widget_set_tooltip_window:
13516 * @widget: a #GtkWidget
13517 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13519 * Replaces the default, usually yellow, window used for displaying
13520 * tooltips with @custom_window. GTK+ will take care of showing and
13521 * hiding @custom_window at the right moment, to behave likewise as
13522 * the default tooltip window. If @custom_window is %NULL, the default
13523 * tooltip window will be used.
13525 * If the custom window should have the default theming it needs to
13526 * have the name "gtk-tooltip", see gtk_widget_set_name().
13531 gtk_widget_set_tooltip_window (GtkWidget *widget,
13532 GtkWindow *custom_window)
13534 gboolean has_tooltip;
13535 gchar *tooltip_markup;
13537 g_return_if_fail (GTK_IS_WIDGET (widget));
13538 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13540 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13543 g_object_ref (custom_window);
13545 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13546 custom_window, g_object_unref);
13548 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13549 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13551 if (has_tooltip && gtk_widget_get_visible (widget))
13552 gtk_widget_queue_tooltip_query (widget);
13556 * gtk_widget_get_tooltip_window:
13557 * @widget: a #GtkWidget
13559 * Returns the #GtkWindow of the current tooltip. This can be the
13560 * GtkWindow created by default, or the custom tooltip window set
13561 * using gtk_widget_set_tooltip_window().
13563 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13568 gtk_widget_get_tooltip_window (GtkWidget *widget)
13570 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13572 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13576 * gtk_widget_trigger_tooltip_query:
13577 * @widget: a #GtkWidget
13579 * Triggers a tooltip query on the display where the toplevel of @widget
13580 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13586 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13588 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13591 static guint tooltip_query_id;
13592 static GSList *tooltip_query_displays;
13595 tooltip_query_idle (gpointer data)
13597 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13598 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13599 g_slist_free (tooltip_query_displays);
13601 tooltip_query_displays = NULL;
13602 tooltip_query_id = 0;
13608 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13610 GdkDisplay *display;
13612 display = gtk_widget_get_display (widget);
13614 if (!g_slist_find (tooltip_query_displays, display))
13615 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13617 if (tooltip_query_id == 0)
13618 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13622 * gtk_widget_set_tooltip_text:
13623 * @widget: a #GtkWidget
13624 * @text: the contents of the tooltip for @widget
13626 * Sets @text as the contents of the tooltip. This function will take
13627 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13628 * handler for the #GtkWidget::query-tooltip signal.
13630 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13635 gtk_widget_set_tooltip_text (GtkWidget *widget,
13638 g_return_if_fail (GTK_IS_WIDGET (widget));
13640 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13644 * gtk_widget_get_tooltip_text:
13645 * @widget: a #GtkWidget
13647 * Gets the contents of the tooltip for @widget.
13649 * Return value: the tooltip text, or %NULL. You should free the
13650 * returned string with g_free() when done.
13655 gtk_widget_get_tooltip_text (GtkWidget *widget)
13657 gchar *text = NULL;
13659 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13661 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13667 * gtk_widget_set_tooltip_markup:
13668 * @widget: a #GtkWidget
13669 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13671 * Sets @markup as the contents of the tooltip, which is marked up with
13672 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13674 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13675 * and of the default handler for the #GtkWidget::query-tooltip signal.
13677 * See also the #GtkWidget:tooltip-markup property and
13678 * gtk_tooltip_set_markup().
13683 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13684 const gchar *markup)
13686 g_return_if_fail (GTK_IS_WIDGET (widget));
13688 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13692 * gtk_widget_get_tooltip_markup:
13693 * @widget: a #GtkWidget
13695 * Gets the contents of the tooltip for @widget.
13697 * Return value: the tooltip text, or %NULL. You should free the
13698 * returned string with g_free() when done.
13703 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13705 gchar *text = NULL;
13707 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13709 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13715 * gtk_widget_set_has_tooltip:
13716 * @widget: a #GtkWidget
13717 * @has_tooltip: whether or not @widget has a tooltip.
13719 * Sets the has-tooltip property on @widget to @has_tooltip. See
13720 * #GtkWidget:has-tooltip for more information.
13725 gtk_widget_set_has_tooltip (GtkWidget *widget,
13726 gboolean has_tooltip)
13728 g_return_if_fail (GTK_IS_WIDGET (widget));
13730 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13734 * gtk_widget_get_has_tooltip:
13735 * @widget: a #GtkWidget
13737 * Returns the current value of the has-tooltip property. See
13738 * #GtkWidget:has-tooltip for more information.
13740 * Return value: current value of has-tooltip on @widget.
13745 gtk_widget_get_has_tooltip (GtkWidget *widget)
13747 gboolean has_tooltip = FALSE;
13749 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13751 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13753 return has_tooltip;
13757 * gtk_widget_get_allocation:
13758 * @widget: a #GtkWidget
13759 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13761 * Retrieves the widget's allocation.
13763 * Note, when implementing a #GtkContainer: a widget's allocation will
13764 * be its "adjusted" allocation, that is, the widget's parent
13765 * container typically calls gtk_widget_size_allocate() with an
13766 * allocation, and that allocation is then adjusted (to handle margin
13767 * and alignment for example) before assignment to the widget.
13768 * gtk_widget_get_allocation() returns the adjusted allocation that
13769 * was actually assigned to the widget. The adjusted allocation is
13770 * guaranteed to be completely contained within the
13771 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13772 * is guaranteed that its children stay inside the assigned bounds,
13773 * but not that they have exactly the bounds the container assigned.
13774 * There is no way to get the original allocation assigned by
13775 * gtk_widget_size_allocate(), since it isn't stored; if a container
13776 * implementation needs that information it will have to track it itself.
13781 gtk_widget_get_allocation (GtkWidget *widget,
13782 GtkAllocation *allocation)
13784 GtkWidgetPrivate *priv;
13786 g_return_if_fail (GTK_IS_WIDGET (widget));
13787 g_return_if_fail (allocation != NULL);
13789 priv = widget->priv;
13791 *allocation = priv->allocation;
13795 * gtk_widget_set_allocation:
13796 * @widget: a #GtkWidget
13797 * @allocation: a pointer to a #GtkAllocation to copy from
13799 * Sets the widget's allocation. This should not be used
13800 * directly, but from within a widget's size_allocate method.
13802 * The allocation set should be the "adjusted" or actual
13803 * allocation. If you're implementing a #GtkContainer, you want to use
13804 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13805 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13806 * allocation inside gtk_widget_size_allocate() to create an adjusted
13812 gtk_widget_set_allocation (GtkWidget *widget,
13813 const GtkAllocation *allocation)
13815 GtkWidgetPrivate *priv;
13817 g_return_if_fail (GTK_IS_WIDGET (widget));
13818 g_return_if_fail (allocation != NULL);
13820 priv = widget->priv;
13822 priv->allocation = *allocation;
13826 * gtk_widget_get_allocated_width:
13827 * @widget: the widget to query
13829 * Returns the width that has currently been allocated to @widget.
13830 * This function is intended to be used when implementing handlers
13831 * for the #GtkWidget::draw function.
13833 * Returns: the width of the @widget
13836 gtk_widget_get_allocated_width (GtkWidget *widget)
13838 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13840 return widget->priv->allocation.width;
13844 * gtk_widget_get_allocated_height:
13845 * @widget: the widget to query
13847 * Returns the height that has currently been allocated to @widget.
13848 * This function is intended to be used when implementing handlers
13849 * for the #GtkWidget::draw function.
13851 * Returns: the height of the @widget
13854 gtk_widget_get_allocated_height (GtkWidget *widget)
13856 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13858 return widget->priv->allocation.height;
13862 * gtk_widget_get_requisition:
13863 * @widget: a #GtkWidget
13864 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13866 * Retrieves the widget's requisition.
13868 * This function should only be used by widget implementations in
13869 * order to figure whether the widget's requisition has actually
13870 * changed after some internal state change (so that they can call
13871 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13873 * Normally, gtk_widget_size_request() should be used.
13877 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13878 * removed, If you need to cache sizes across requests and allocations,
13879 * add an explicit cache to the widget in question instead.
13882 gtk_widget_get_requisition (GtkWidget *widget,
13883 GtkRequisition *requisition)
13885 g_return_if_fail (GTK_IS_WIDGET (widget));
13886 g_return_if_fail (requisition != NULL);
13888 gtk_widget_get_preferred_size (widget, requisition, NULL);
13892 * gtk_widget_set_window:
13893 * @widget: a #GtkWidget
13894 * @window: a #GdkWindow
13896 * Sets a widget's window. This function should only be used in a
13897 * widget's #GtkWidget::realize implementation. The %window passed is
13898 * usually either new window created with gdk_window_new(), or the
13899 * window of its parent widget as returned by
13900 * gtk_widget_get_parent_window().
13902 * Widgets must indicate whether they will create their own #GdkWindow
13903 * by calling gtk_widget_set_has_window(). This is usually done in the
13904 * widget's init() function.
13906 * <note><para>This function does not add any reference to @window.</para></note>
13911 gtk_widget_set_window (GtkWidget *widget,
13914 GtkWidgetPrivate *priv;
13916 g_return_if_fail (GTK_IS_WIDGET (widget));
13917 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13919 priv = widget->priv;
13921 if (priv->window != window)
13923 priv->window = window;
13924 g_object_notify (G_OBJECT (widget), "window");
13929 * gtk_widget_get_window:
13930 * @widget: a #GtkWidget
13932 * Returns the widget's window if it is realized, %NULL otherwise
13934 * Return value: (transfer none): @widget's window.
13939 gtk_widget_get_window (GtkWidget *widget)
13941 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13943 return widget->priv->window;
13947 * gtk_widget_get_support_multidevice:
13948 * @widget: a #GtkWidget
13950 * Returns %TRUE if @widget is multiple pointer aware. See
13951 * gtk_widget_set_support_multidevice() for more information.
13953 * Returns: %TRUE if @widget is multidevice aware.
13956 gtk_widget_get_support_multidevice (GtkWidget *widget)
13958 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13960 return widget->priv->multidevice;
13964 * gtk_widget_set_support_multidevice:
13965 * @widget: a #GtkWidget
13966 * @support_multidevice: %TRUE to support input from multiple devices.
13968 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13969 * @widget will start receiving multiple, per device enter/leave events. Note
13970 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13971 * gdk_window_set_support_multidevice() will have to be called manually on them.
13976 gtk_widget_set_support_multidevice (GtkWidget *widget,
13977 gboolean support_multidevice)
13979 GtkWidgetPrivate *priv;
13981 g_return_if_fail (GTK_IS_WIDGET (widget));
13983 priv = widget->priv;
13984 priv->multidevice = (support_multidevice == TRUE);
13986 if (gtk_widget_get_realized (widget))
13987 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13991 _gtk_widget_set_has_focus (GtkWidget *widget,
13992 gboolean has_focus)
13994 widget->priv->has_focus = has_focus;
13997 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
13999 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
14003 * gtk_widget_send_focus_change:
14004 * @widget: a #GtkWidget
14005 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
14007 * Sends the focus change @event to @widget
14009 * This function is not meant to be used by applications. The only time it
14010 * should be used is when it is necessary for a #GtkWidget to assign focus
14011 * to a widget that is semantically owned by the first widget even though
14012 * it's not a direct child - for instance, a search entry in a floating
14013 * window similar to the quick search in #GtkTreeView.
14015 * An example of its usage is:
14018 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
14020 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
14021 * fevent->focus_change.in = TRUE;
14022 * fevent->focus_change.window = gtk_widget_get_window (widget);
14023 * if (fevent->focus_change.window != NULL)
14024 * g_object_ref (fevent->focus_change.window);
14026 * gtk_widget_send_focus_change (widget, fevent);
14028 * gdk_event_free (event);
14031 * Return value: the return value from the event signal emission: %TRUE
14032 * if the event was handled, and %FALSE otherwise
14037 gtk_widget_send_focus_change (GtkWidget *widget,
14042 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
14043 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
14045 g_object_ref (widget);
14047 _gtk_widget_set_has_focus (widget, event->focus_change.in);
14049 res = gtk_widget_event (widget, event);
14051 g_object_notify (G_OBJECT (widget), "has-focus");
14053 g_object_unref (widget);
14059 * gtk_widget_in_destruction:
14060 * @widget: a #GtkWidget
14062 * Returns whether the widget is currently being destroyed.
14063 * This information can sometimes be used to avoid doing
14064 * unnecessary work.
14066 * Returns: %TRUE if @widget is being destroyed
14069 gtk_widget_in_destruction (GtkWidget *widget)
14071 return widget->priv->in_destruction;
14075 _gtk_widget_get_resize_pending (GtkWidget *widget)
14077 return widget->priv->resize_pending;
14081 _gtk_widget_set_resize_pending (GtkWidget *widget,
14082 gboolean resize_pending)
14084 widget->priv->resize_pending = resize_pending;
14088 _gtk_widget_get_in_reparent (GtkWidget *widget)
14090 return widget->priv->in_reparent;
14094 _gtk_widget_set_in_reparent (GtkWidget *widget,
14095 gboolean in_reparent)
14097 widget->priv->in_reparent = in_reparent;
14101 _gtk_widget_get_anchored (GtkWidget *widget)
14103 return widget->priv->anchored;
14107 _gtk_widget_set_anchored (GtkWidget *widget,
14110 widget->priv->anchored = anchored;
14114 _gtk_widget_get_shadowed (GtkWidget *widget)
14116 return widget->priv->shadowed;
14120 _gtk_widget_set_shadowed (GtkWidget *widget,
14123 widget->priv->shadowed = shadowed;
14127 _gtk_widget_get_alloc_needed (GtkWidget *widget)
14129 return widget->priv->alloc_needed;
14133 _gtk_widget_set_alloc_needed (GtkWidget *widget,
14134 gboolean alloc_needed)
14136 widget->priv->alloc_needed = alloc_needed;
14140 _gtk_widget_get_width_request_needed (GtkWidget *widget)
14142 return widget->priv->width_request_needed;
14146 _gtk_widget_set_width_request_needed (GtkWidget *widget,
14147 gboolean width_request_needed)
14149 widget->priv->width_request_needed = width_request_needed;
14153 _gtk_widget_get_height_request_needed (GtkWidget *widget)
14155 return widget->priv->height_request_needed;
14159 _gtk_widget_set_height_request_needed (GtkWidget *widget,
14160 gboolean height_request_needed)
14162 widget->priv->height_request_needed = height_request_needed;
14166 _gtk_widget_get_sizegroup_visited (GtkWidget *widget)
14168 return widget->priv->sizegroup_visited;
14172 _gtk_widget_set_sizegroup_visited (GtkWidget *widget,
14175 widget->priv->sizegroup_visited = visited;
14179 _gtk_widget_get_sizegroup_bumping (GtkWidget *widget)
14181 return widget->priv->sizegroup_bumping;
14185 _gtk_widget_set_sizegroup_bumping (GtkWidget *widget,
14188 widget->priv->sizegroup_bumping = bumping;
14192 _gtk_widget_add_sizegroup (GtkWidget *widget,
14197 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14198 groups = g_slist_prepend (groups, group);
14199 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14201 widget->priv->have_size_groups = TRUE;
14205 _gtk_widget_remove_sizegroup (GtkWidget *widget,
14210 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14211 groups = g_slist_remove (groups, group);
14212 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14214 widget->priv->have_size_groups = groups != NULL;
14218 _gtk_widget_get_sizegroups (GtkWidget *widget)
14220 if (widget->priv->have_size_groups)
14221 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14227 * gtk_widget_path_append_for_widget:
14228 * @path: a widget path
14229 * @widget: the widget to append to the widget path
14231 * Appends the data from @widget to the widget hierarchy represented
14232 * by @path. This function is a shortcut for adding information from
14233 * @widget to the given @path. This includes setting the name or
14234 * adding the style classes from @widget.
14236 * Returns: the position where the data was inserted
14241 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
14246 g_return_val_if_fail (path != NULL, 0);
14247 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14249 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
14251 if (widget->priv->name)
14252 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
14254 if (widget->priv->context)
14256 GList *classes, *l;
14258 /* Also add any persistent classes in
14259 * the style context the widget path
14261 classes = gtk_style_context_list_classes (widget->priv->context);
14263 for (l = classes; l; l = l->next)
14264 gtk_widget_path_iter_add_class (path, pos, l->data);
14266 g_list_free (classes);
14273 * gtk_widget_get_path:
14274 * @widget: a #GtkWidget
14276 * Returns the #GtkWidgetPath representing @widget, if the widget
14277 * is not connected to a toplevel widget, a partial path will be
14280 * Returns: (transfer none): The #GtkWidgetPath representing @widget
14283 gtk_widget_get_path (GtkWidget *widget)
14285 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14287 /* As strange as it may seem, this may happen on object construction.
14288 * init() implementations of parent types may eventually call this function,
14289 * each with its corresponding GType, which could leave a child
14290 * implementation with a wrong widget type in the widget path
14292 if (widget->priv->path &&
14293 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (widget->priv->path))
14295 gtk_widget_path_free (widget->priv->path);
14296 widget->priv->path = NULL;
14299 if (!widget->priv->path)
14303 parent = widget->priv->parent;
14306 widget->priv->path = gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
14309 /* Widget is either toplevel or unparented, treat both
14310 * as toplevels style wise, since there are situations
14311 * where style properties might be retrieved on that
14314 widget->priv->path = gtk_widget_path_new ();
14316 gtk_widget_path_append_for_widget (widget->priv->path, widget);
14319 if (widget->priv->context)
14320 gtk_style_context_set_path (widget->priv->context,
14321 widget->priv->path);
14324 return widget->priv->path;
14328 style_context_changed (GtkStyleContext *context,
14329 gpointer user_data)
14331 GtkWidget *widget = user_data;
14333 gtk_widget_update_pango_context (widget);
14335 if (gtk_widget_get_realized (widget))
14336 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
14339 /* Compress all style updates so it
14340 * is only emitted once pre-realize.
14342 widget->priv->style_update_pending = TRUE;
14345 if (widget->priv->anchored)
14346 gtk_widget_queue_resize (widget);
14350 * gtk_widget_get_style_context:
14351 * @widget: a #GtkWidget
14353 * Returns the style context associated to @widget.
14355 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
14356 * must not be freed.
14359 gtk_widget_get_style_context (GtkWidget *widget)
14361 GtkWidgetPrivate *priv;
14362 GtkWidgetPath *path;
14364 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14366 priv = widget->priv;
14368 /* updates style context if it exists already */
14369 path = gtk_widget_get_path (widget);
14371 if (G_UNLIKELY (priv->context == NULL))
14375 priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
14376 "direction", gtk_widget_get_direction (widget),
14379 g_signal_connect (widget->priv->context, "changed",
14380 G_CALLBACK (style_context_changed), widget);
14382 screen = gtk_widget_get_screen (widget);
14385 gtk_style_context_set_screen (priv->context, screen);
14387 gtk_style_context_set_path (priv->context, path);
14390 return widget->priv->context;