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 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
303 #define INIT_PATH_SIZE (512)
305 struct _GtkWidgetPrivate
307 /* The state of the widget. There are actually only
308 * 5 widget states (defined in "gtkenums.h")
311 guint state_flags : 6;
315 guint in_destruction : 1;
318 guint composite_child : 1;
324 guint parent_sensitive : 1;
327 guint can_default : 1;
328 guint has_default : 1;
329 guint receives_default : 1;
333 guint style_update_pending : 1;
334 guint app_paintable : 1;
335 guint double_buffered : 1;
336 guint redraw_on_alloc : 1;
337 guint no_show_all : 1;
338 guint child_visible : 1;
339 guint multidevice : 1;
340 guint has_shape_mask : 1;
341 guint in_reparent : 1;
343 /* Queue-resize related flags */
344 guint resize_pending : 1;
345 guint alloc_needed : 1;
346 guint width_request_needed : 1;
347 guint height_request_needed : 1;
349 /* Expand-related flags */
350 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
351 guint computed_hexpand : 1; /* computed results (composite of child flags) */
352 guint computed_vexpand : 1;
353 guint hexpand : 1; /* application-forced expand */
355 guint hexpand_set : 1; /* whether to use application-forced */
356 guint vexpand_set : 1; /* instead of computing from children */
358 /* SizeGroup related flags */
359 guint sizegroup_visited : 1;
360 guint sizegroup_bumping : 1;
361 guint have_size_groups : 1;
363 /* The widget's name. If the widget does not have a name
364 * (the name is NULL), then its name (as returned by
365 * "gtk_widget_get_name") is its class's name.
366 * Among other things, the widget name is used to determine
367 * the style to use for a widget.
371 /* The style for the widget. The style contains the
372 * colors the widget should be drawn in for each state
373 * along with graphics contexts used to draw with and
374 * the font to use for text.
377 GtkStyleContext *context;
379 /* The widget's allocated size.
381 GtkAllocation allocation;
383 /* The widget's requested sizes */
384 SizeRequestCache requests;
386 /* The widget's window or its parent window if it does
387 * not have a window. (Which will be indicated by the
388 * GTK_NO_WINDOW flag being set).
392 /* The widget's parent.
396 #ifdef G_ENABLE_DEBUG
397 /* Number of gtk_widget_push_verify_invariants () */
398 guint verifying_invariants_count;
399 #endif /* G_ENABLE_DEBUG */
401 /* Widget's path for styling */
431 BUTTON_RELEASE_EVENT,
445 PROPERTY_NOTIFY_EVENT,
446 SELECTION_CLEAR_EVENT,
447 SELECTION_REQUEST_EVENT,
448 SELECTION_NOTIFY_EVENT,
453 VISIBILITY_NOTIFY_EVENT,
467 ACCEL_CLOSURES_CHANGED,
491 PROP_RECEIVES_DEFAULT,
492 PROP_COMPOSITE_CHILD,
500 PROP_DOUBLE_BUFFERED,
515 typedef struct _GtkStateData GtkStateData;
518 STATE_CHANGE_REPLACE,
527 guint parent_sensitive : 1;
528 guint use_forall : 1;
531 /* --- prototypes --- */
532 static void gtk_widget_class_init (GtkWidgetClass *klass);
533 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
534 static void gtk_widget_init (GtkWidget *widget);
535 static void gtk_widget_set_property (GObject *object,
539 static void gtk_widget_get_property (GObject *object,
543 static void gtk_widget_dispose (GObject *object);
544 static void gtk_widget_real_destroy (GtkWidget *object);
545 static void gtk_widget_finalize (GObject *object);
546 static void gtk_widget_real_show (GtkWidget *widget);
547 static void gtk_widget_real_hide (GtkWidget *widget);
548 static void gtk_widget_real_map (GtkWidget *widget);
549 static void gtk_widget_real_unmap (GtkWidget *widget);
550 static void gtk_widget_real_realize (GtkWidget *widget);
551 static void gtk_widget_real_unrealize (GtkWidget *widget);
552 static void gtk_widget_real_size_allocate (GtkWidget *widget,
553 GtkAllocation *allocation);
554 static void gtk_widget_real_style_set (GtkWidget *widget,
555 GtkStyle *previous_style);
556 static void gtk_widget_real_direction_changed(GtkWidget *widget,
557 GtkTextDirection previous_direction);
559 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
560 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
563 gboolean keyboard_tip,
564 GtkTooltip *tooltip);
565 static void gtk_widget_real_style_updated (GtkWidget *widget);
566 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
567 GtkWidgetHelpType help_type);
569 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
571 GParamSpec **pspecs);
572 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
574 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
576 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
577 GdkEventFocus *event);
578 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
579 GdkEventFocus *event);
580 static gboolean gtk_widget_real_focus (GtkWidget *widget,
581 GtkDirectionType direction);
582 static void gtk_widget_real_move_focus (GtkWidget *widget,
583 GtkDirectionType direction);
584 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
585 GtkDirectionType direction);
586 #ifdef G_ENABLE_DEBUG
587 static void gtk_widget_verify_invariants (GtkWidget *widget);
588 static void gtk_widget_push_verify_invariants (GtkWidget *widget);
589 static void gtk_widget_pop_verify_invariants (GtkWidget *widget);
591 #define gtk_widget_verify_invariants(widget)
592 #define gtk_widget_push_verify_invariants(widget)
593 #define gtk_widget_pop_verify_invariants(widget)
595 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
596 static void gtk_widget_update_pango_context (GtkWidget *widget);
597 static void gtk_widget_propagate_state (GtkWidget *widget,
600 static gint gtk_widget_event_internal (GtkWidget *widget,
602 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
603 gboolean group_cycling);
604 static void gtk_widget_real_get_width (GtkWidget *widget,
607 static void gtk_widget_real_get_height (GtkWidget *widget,
610 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
612 gint *minimum_height,
613 gint *natural_height);
614 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
617 gint *natural_width);
618 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
619 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
620 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
621 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
622 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
623 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
624 cairo_region_t *region);
625 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
626 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
627 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
630 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
631 gboolean has_tooltip,
633 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
634 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
636 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
637 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
639 const gchar *childname);
640 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
643 const GValue *value);
644 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
647 const gchar *tagname,
648 GMarkupParser *parser,
650 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
653 const gchar *tagname,
655 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
656 GtkBuilder *builder);
658 static GtkSizeRequestMode gtk_widget_real_get_request_mode (GtkWidget *widget);
659 static void gtk_widget_real_get_width (GtkWidget *widget,
662 static void gtk_widget_real_get_height (GtkWidget *widget,
666 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
669 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
670 GtkOrientation orientation,
673 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
674 GtkOrientation orientation,
678 gint *allocated_size);
680 static void gtk_widget_set_usize_internal (GtkWidget *widget,
683 GtkQueueResizeFlags flags);
685 static void gtk_widget_add_events_internal (GtkWidget *widget,
688 static void gtk_widget_set_device_enabled_internal (GtkWidget *widget,
693 /* --- variables --- */
694 static gpointer gtk_widget_parent_class = NULL;
695 static guint widget_signals[LAST_SIGNAL] = { 0 };
696 static GtkStyle *gtk_default_style = NULL;
697 static guint composite_child_stack = 0;
698 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
699 static GParamSpecPool *style_property_spec_pool = NULL;
701 static GQuark quark_property_parser = 0;
702 static GQuark quark_aux_info = 0;
703 static GQuark quark_accel_path = 0;
704 static GQuark quark_accel_closures = 0;
705 static GQuark quark_event_mask = 0;
706 static GQuark quark_device_event_mask = 0;
707 static GQuark quark_parent_window = 0;
708 static GQuark quark_pointer_window = 0;
709 static GQuark quark_shape_info = 0;
710 static GQuark quark_input_shape_info = 0;
711 static GQuark quark_pango_context = 0;
712 static GQuark quark_rc_style = 0;
713 static GQuark quark_accessible_object = 0;
714 static GQuark quark_mnemonic_labels = 0;
715 static GQuark quark_tooltip_markup = 0;
716 static GQuark quark_has_tooltip = 0;
717 static GQuark quark_tooltip_window = 0;
718 static GQuark quark_visual = 0;
719 static GQuark quark_modifier_style = 0;
720 static GQuark quark_enabled_devices = 0;
721 static GQuark quark_size_groups = 0;
722 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
723 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
725 /* --- functions --- */
727 gtk_widget_get_type (void)
729 static GType widget_type = 0;
731 if (G_UNLIKELY (widget_type == 0))
733 const GTypeInfo widget_info =
735 sizeof (GtkWidgetClass),
736 NULL, /* base_init */
737 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
738 (GClassInitFunc) gtk_widget_class_init,
739 NULL, /* class_finalize */
740 NULL, /* class_init */
743 (GInstanceInitFunc) gtk_widget_init,
744 NULL, /* value_table */
747 const GInterfaceInfo accessibility_info =
749 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
750 (GInterfaceFinalizeFunc) NULL,
751 NULL /* interface data */
754 const GInterfaceInfo buildable_info =
756 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
757 (GInterfaceFinalizeFunc) NULL,
758 NULL /* interface data */
761 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
762 &widget_info, G_TYPE_FLAG_ABSTRACT);
764 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
765 &accessibility_info) ;
766 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
774 child_property_notify_dispatcher (GObject *object,
778 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
781 /* We guard against the draw signal callbacks modifying the state of the
782 * cairo context by surounding it with save/restore.
783 * Maybe we should also cairo_new_path() just to be sure?
786 gtk_widget_draw_marshaller (GClosure *closure,
787 GValue *return_value,
788 guint n_param_values,
789 const GValue *param_values,
790 gpointer invocation_hint,
791 gpointer marshal_data)
793 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
797 _gtk_marshal_BOOLEAN__BOXED (closure,
808 gtk_widget_class_init (GtkWidgetClass *klass)
810 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
811 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
812 GtkBindingSet *binding_set;
814 gtk_widget_parent_class = g_type_class_peek_parent (klass);
816 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
817 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
818 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
819 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
820 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
821 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
822 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
823 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
824 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
825 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
826 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
827 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
828 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
829 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
830 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
831 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
832 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
833 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
834 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
835 quark_enabled_devices = g_quark_from_static_string ("gtk-widget-enabled-devices");
836 quark_size_groups = g_quark_from_static_string ("gtk-widget-size-groups");
838 style_property_spec_pool = g_param_spec_pool_new (FALSE);
839 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
840 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
841 cpn_context.dispatcher = child_property_notify_dispatcher;
842 _gtk_widget_child_property_notify_context = &cpn_context;
844 gobject_class->dispose = gtk_widget_dispose;
845 gobject_class->finalize = gtk_widget_finalize;
846 gobject_class->set_property = gtk_widget_set_property;
847 gobject_class->get_property = gtk_widget_get_property;
849 klass->destroy = gtk_widget_real_destroy;
851 klass->activate_signal = 0;
852 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
853 klass->show = gtk_widget_real_show;
854 klass->show_all = gtk_widget_show;
855 klass->hide = gtk_widget_real_hide;
856 klass->map = gtk_widget_real_map;
857 klass->unmap = gtk_widget_real_unmap;
858 klass->realize = gtk_widget_real_realize;
859 klass->unrealize = gtk_widget_real_unrealize;
860 klass->size_allocate = gtk_widget_real_size_allocate;
861 klass->get_request_mode = gtk_widget_real_get_request_mode;
862 klass->get_preferred_width = gtk_widget_real_get_width;
863 klass->get_preferred_height = gtk_widget_real_get_height;
864 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
865 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
866 klass->state_changed = NULL;
867 klass->parent_set = NULL;
868 klass->hierarchy_changed = NULL;
869 klass->style_set = gtk_widget_real_style_set;
870 klass->direction_changed = gtk_widget_real_direction_changed;
871 klass->grab_notify = NULL;
872 klass->child_notify = NULL;
874 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
875 klass->grab_focus = gtk_widget_real_grab_focus;
876 klass->focus = gtk_widget_real_focus;
877 klass->move_focus = gtk_widget_real_move_focus;
878 klass->keynav_failed = gtk_widget_real_keynav_failed;
880 klass->button_press_event = NULL;
881 klass->button_release_event = NULL;
882 klass->motion_notify_event = NULL;
883 klass->delete_event = NULL;
884 klass->destroy_event = NULL;
885 klass->key_press_event = gtk_widget_real_key_press_event;
886 klass->key_release_event = gtk_widget_real_key_release_event;
887 klass->enter_notify_event = NULL;
888 klass->leave_notify_event = NULL;
889 klass->configure_event = NULL;
890 klass->focus_in_event = gtk_widget_real_focus_in_event;
891 klass->focus_out_event = gtk_widget_real_focus_out_event;
892 klass->map_event = NULL;
893 klass->unmap_event = NULL;
894 klass->window_state_event = NULL;
895 klass->property_notify_event = _gtk_selection_property_notify;
896 klass->selection_clear_event = _gtk_selection_clear;
897 klass->selection_request_event = _gtk_selection_request;
898 klass->selection_notify_event = _gtk_selection_notify;
899 klass->selection_received = NULL;
900 klass->proximity_in_event = NULL;
901 klass->proximity_out_event = NULL;
902 klass->drag_begin = NULL;
903 klass->drag_end = NULL;
904 klass->drag_data_delete = NULL;
905 klass->drag_leave = NULL;
906 klass->drag_motion = NULL;
907 klass->drag_drop = NULL;
908 klass->drag_data_received = NULL;
909 klass->screen_changed = NULL;
910 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
911 klass->grab_broken_event = NULL;
912 klass->query_tooltip = gtk_widget_real_query_tooltip;
913 klass->style_updated = gtk_widget_real_style_updated;
915 klass->show_help = gtk_widget_real_show_help;
917 /* Accessibility support */
918 klass->get_accessible = gtk_widget_real_get_accessible;
920 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
921 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
923 g_object_class_install_property (gobject_class,
925 g_param_spec_string ("name",
927 P_("The name of the widget"),
929 GTK_PARAM_READWRITE));
930 g_object_class_install_property (gobject_class,
932 g_param_spec_object ("parent",
934 P_("The parent widget of this widget. Must be a Container widget"),
936 GTK_PARAM_READWRITE));
938 g_object_class_install_property (gobject_class,
940 g_param_spec_int ("width-request",
942 P_("Override for width request of the widget, or -1 if natural request should be used"),
946 GTK_PARAM_READWRITE));
947 g_object_class_install_property (gobject_class,
949 g_param_spec_int ("height-request",
950 P_("Height request"),
951 P_("Override for height request of the widget, or -1 if natural request should be used"),
955 GTK_PARAM_READWRITE));
956 g_object_class_install_property (gobject_class,
958 g_param_spec_boolean ("visible",
960 P_("Whether the widget is visible"),
962 GTK_PARAM_READWRITE));
963 g_object_class_install_property (gobject_class,
965 g_param_spec_boolean ("sensitive",
967 P_("Whether the widget responds to input"),
969 GTK_PARAM_READWRITE));
970 g_object_class_install_property (gobject_class,
972 g_param_spec_boolean ("app-paintable",
973 P_("Application paintable"),
974 P_("Whether the application will paint directly on the widget"),
976 GTK_PARAM_READWRITE));
977 g_object_class_install_property (gobject_class,
979 g_param_spec_boolean ("can-focus",
981 P_("Whether the widget can accept the input focus"),
983 GTK_PARAM_READWRITE));
984 g_object_class_install_property (gobject_class,
986 g_param_spec_boolean ("has-focus",
988 P_("Whether the widget has the input focus"),
990 GTK_PARAM_READWRITE));
991 g_object_class_install_property (gobject_class,
993 g_param_spec_boolean ("is-focus",
995 P_("Whether the widget is the focus widget within the toplevel"),
997 GTK_PARAM_READWRITE));
998 g_object_class_install_property (gobject_class,
1000 g_param_spec_boolean ("can-default",
1002 P_("Whether the widget can be the default widget"),
1004 GTK_PARAM_READWRITE));
1005 g_object_class_install_property (gobject_class,
1007 g_param_spec_boolean ("has-default",
1009 P_("Whether the widget is the default widget"),
1011 GTK_PARAM_READWRITE));
1012 g_object_class_install_property (gobject_class,
1013 PROP_RECEIVES_DEFAULT,
1014 g_param_spec_boolean ("receives-default",
1015 P_("Receives default"),
1016 P_("If TRUE, the widget will receive the default action when it is focused"),
1018 GTK_PARAM_READWRITE));
1019 g_object_class_install_property (gobject_class,
1020 PROP_COMPOSITE_CHILD,
1021 g_param_spec_boolean ("composite-child",
1022 P_("Composite child"),
1023 P_("Whether the widget is part of a composite widget"),
1025 GTK_PARAM_READABLE));
1026 g_object_class_install_property (gobject_class,
1028 g_param_spec_object ("style",
1030 P_("The style of the widget, which contains information about how it will look (colors etc)"),
1032 GTK_PARAM_READWRITE));
1033 g_object_class_install_property (gobject_class,
1035 g_param_spec_flags ("events",
1037 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1038 GDK_TYPE_EVENT_MASK,
1040 GTK_PARAM_READWRITE));
1041 g_object_class_install_property (gobject_class,
1043 g_param_spec_boolean ("no-show-all",
1045 P_("Whether gtk_widget_show_all() should not affect this widget"),
1047 GTK_PARAM_READWRITE));
1050 * GtkWidget:has-tooltip:
1052 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1053 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1054 * the widget will be queried using #GtkWidget::query-tooltip to determine
1055 * whether it will provide a tooltip or not.
1057 * Note that setting this property to %TRUE for the first time will change
1058 * the event masks of the GdkWindows of this widget to include leave-notify
1059 * and motion-notify events. This cannot and will not be undone when the
1060 * property is set to %FALSE again.
1064 g_object_class_install_property (gobject_class,
1066 g_param_spec_boolean ("has-tooltip",
1068 P_("Whether this widget has a tooltip"),
1070 GTK_PARAM_READWRITE));
1072 * GtkWidget:tooltip-text:
1074 * Sets the text of tooltip to be the given string.
1076 * Also see gtk_tooltip_set_text().
1078 * This is a convenience property which will take care of getting the
1079 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1080 * will automatically be set to %TRUE and there will be taken care of
1081 * #GtkWidget::query-tooltip in the default signal handler.
1085 g_object_class_install_property (gobject_class,
1087 g_param_spec_string ("tooltip-text",
1089 P_("The contents of the tooltip for this widget"),
1091 GTK_PARAM_READWRITE));
1093 * GtkWidget:tooltip-markup:
1095 * Sets the text of tooltip to be the given string, which is marked up
1096 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1097 * Also see gtk_tooltip_set_markup().
1099 * This is a convenience property which will take care of getting the
1100 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1101 * will automatically be set to %TRUE and there will be taken care of
1102 * #GtkWidget::query-tooltip in the default signal handler.
1106 g_object_class_install_property (gobject_class,
1107 PROP_TOOLTIP_MARKUP,
1108 g_param_spec_string ("tooltip-markup",
1109 P_("Tooltip markup"),
1110 P_("The contents of the tooltip for this widget"),
1112 GTK_PARAM_READWRITE));
1117 * The widget's window if it is realized, %NULL otherwise.
1121 g_object_class_install_property (gobject_class,
1123 g_param_spec_object ("window",
1125 P_("The widget's window if it is realized"),
1127 GTK_PARAM_READABLE));
1130 * GtkWidget:double-buffered
1132 * Whether the widget is double buffered.
1136 g_object_class_install_property (gobject_class,
1137 PROP_DOUBLE_BUFFERED,
1138 g_param_spec_boolean ("double-buffered",
1139 P_("Double Buffered"),
1140 P_("Whether the widget is double buffered"),
1142 GTK_PARAM_READWRITE));
1147 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1151 g_object_class_install_property (gobject_class,
1153 g_param_spec_enum ("halign",
1154 P_("Horizontal Alignment"),
1155 P_("How to position in extra horizontal space"),
1158 GTK_PARAM_READWRITE));
1163 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1167 g_object_class_install_property (gobject_class,
1169 g_param_spec_enum ("valign",
1170 P_("Vertical Alignment"),
1171 P_("How to position in extra vertical space"),
1174 GTK_PARAM_READWRITE));
1177 * GtkWidget:margin-left
1179 * Margin on left side of widget.
1181 * This property adds margin outside of the widget's normal size
1182 * request, the margin will be added in addition to the size from
1183 * gtk_widget_set_size_request() for example.
1187 g_object_class_install_property (gobject_class,
1189 g_param_spec_int ("margin-left",
1190 P_("Margin on Left"),
1191 P_("Pixels of extra space on the left side"),
1195 GTK_PARAM_READWRITE));
1198 * GtkWidget:margin-right
1200 * Margin on right side of widget.
1202 * This property adds margin outside of the widget's normal size
1203 * request, the margin will be added in addition to the size from
1204 * gtk_widget_set_size_request() for example.
1208 g_object_class_install_property (gobject_class,
1210 g_param_spec_int ("margin-right",
1211 P_("Margin on Right"),
1212 P_("Pixels of extra space on the right side"),
1216 GTK_PARAM_READWRITE));
1219 * GtkWidget:margin-top
1221 * Margin on top side of widget.
1223 * This property adds margin outside of the widget's normal size
1224 * request, the margin will be added in addition to the size from
1225 * gtk_widget_set_size_request() for example.
1229 g_object_class_install_property (gobject_class,
1231 g_param_spec_int ("margin-top",
1232 P_("Margin on Top"),
1233 P_("Pixels of extra space on the top side"),
1237 GTK_PARAM_READWRITE));
1240 * GtkWidget:margin-bottom
1242 * Margin on bottom side of widget.
1244 * This property adds margin outside of the widget's normal size
1245 * request, the margin will be added in addition to the size from
1246 * gtk_widget_set_size_request() for example.
1250 g_object_class_install_property (gobject_class,
1252 g_param_spec_int ("margin-bottom",
1253 P_("Margin on Bottom"),
1254 P_("Pixels of extra space on the bottom side"),
1258 GTK_PARAM_READWRITE));
1263 * Sets all four sides' margin at once. If read, returns max
1264 * margin on any side.
1268 g_object_class_install_property (gobject_class,
1270 g_param_spec_int ("margin",
1272 P_("Pixels of extra space on all four sides"),
1276 GTK_PARAM_READWRITE));
1279 * GtkWidget::destroy:
1280 * @object: the object which received the signal
1282 * Signals that all holders of a reference to the widget should release
1283 * the reference that they hold. May result in finalization of the widget
1284 * if all references are released.
1286 widget_signals[DESTROY] =
1287 g_signal_new (I_("destroy"),
1288 G_TYPE_FROM_CLASS (gobject_class),
1289 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1290 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1292 _gtk_marshal_VOID__VOID,
1298 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1302 g_object_class_install_property (gobject_class,
1304 g_param_spec_boolean ("hexpand",
1305 P_("Horizontal Expand"),
1306 P_("Whether widget wants more horizontal space"),
1308 GTK_PARAM_READWRITE));
1311 * GtkWidget:hexpand-set
1313 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1317 g_object_class_install_property (gobject_class,
1319 g_param_spec_boolean ("hexpand-set",
1320 P_("Horizontal Expand Set"),
1321 P_("Whether to use the hexpand property"),
1323 GTK_PARAM_READWRITE));
1328 * Whether to expand vertically. See gtk_widget_set_vexpand().
1332 g_object_class_install_property (gobject_class,
1334 g_param_spec_boolean ("vexpand",
1335 P_("Vertical Expand"),
1336 P_("Whether widget wants more vertical space"),
1338 GTK_PARAM_READWRITE));
1341 * GtkWidget:vexpand-set
1343 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1347 g_object_class_install_property (gobject_class,
1349 g_param_spec_boolean ("vexpand-set",
1350 P_("Vertical Expand Set"),
1351 P_("Whether to use the vexpand property"),
1353 GTK_PARAM_READWRITE));
1358 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1362 g_object_class_install_property (gobject_class,
1364 g_param_spec_boolean ("expand",
1366 P_("Whether widget wants to expand in both directions"),
1368 GTK_PARAM_READWRITE));
1372 * @widget: the object which received the signal.
1374 widget_signals[SHOW] =
1375 g_signal_new (I_("show"),
1376 G_TYPE_FROM_CLASS (gobject_class),
1378 G_STRUCT_OFFSET (GtkWidgetClass, show),
1380 _gtk_marshal_VOID__VOID,
1385 * @widget: the object which received the signal.
1387 widget_signals[HIDE] =
1388 g_signal_new (I_("hide"),
1389 G_TYPE_FROM_CLASS (gobject_class),
1391 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1393 _gtk_marshal_VOID__VOID,
1398 * @widget: the object which received the signal.
1400 widget_signals[MAP] =
1401 g_signal_new (I_("map"),
1402 G_TYPE_FROM_CLASS (gobject_class),
1404 G_STRUCT_OFFSET (GtkWidgetClass, map),
1406 _gtk_marshal_VOID__VOID,
1411 * @widget: the object which received the signal.
1413 widget_signals[UNMAP] =
1414 g_signal_new (I_("unmap"),
1415 G_TYPE_FROM_CLASS (gobject_class),
1417 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1419 _gtk_marshal_VOID__VOID,
1423 * GtkWidget::realize:
1424 * @widget: the object which received the signal.
1426 widget_signals[REALIZE] =
1427 g_signal_new (I_("realize"),
1428 G_TYPE_FROM_CLASS (gobject_class),
1430 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1432 _gtk_marshal_VOID__VOID,
1436 * GtkWidget::unrealize:
1437 * @widget: the object which received the signal.
1439 widget_signals[UNREALIZE] =
1440 g_signal_new (I_("unrealize"),
1441 G_TYPE_FROM_CLASS (gobject_class),
1443 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1445 _gtk_marshal_VOID__VOID,
1449 * GtkWidget::size-allocate:
1450 * @widget: the object which received the signal.
1453 widget_signals[SIZE_ALLOCATE] =
1454 g_signal_new (I_("size-allocate"),
1455 G_TYPE_FROM_CLASS (gobject_class),
1457 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1459 _gtk_marshal_VOID__BOXED,
1461 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1464 * GtkWidget::state-changed:
1465 * @widget: the object which received the signal.
1466 * @state: the previous state
1468 * The ::state-changed signal is emitted when the widget state changes.
1469 * See gtk_widget_get_state().
1471 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1473 widget_signals[STATE_CHANGED] =
1474 g_signal_new (I_("state-changed"),
1475 G_TYPE_FROM_CLASS (gobject_class),
1477 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1479 _gtk_marshal_VOID__ENUM,
1481 GTK_TYPE_STATE_TYPE);
1484 * GtkWidget::state-flags-changed:
1485 * @widget: the object which received the signal.
1486 * @flags: The previous state flags.
1488 * The ::state-flags-changed signal is emitted when the widget state
1489 * changes, see gtk_widget_get_state_flags().
1493 widget_signals[STATE_FLAGS_CHANGED] =
1494 g_signal_new (I_("state-flags-changed"),
1495 G_TYPE_FROM_CLASS (gobject_class),
1497 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1499 _gtk_marshal_VOID__FLAGS,
1501 GTK_TYPE_STATE_FLAGS);
1504 * GtkWidget::parent-set:
1505 * @widget: the object on which the signal is emitted
1506 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1507 * just got its initial parent.
1509 * The ::parent-set signal is emitted when a new parent
1510 * has been set on a widget.
1512 widget_signals[PARENT_SET] =
1513 g_signal_new (I_("parent-set"),
1514 G_TYPE_FROM_CLASS (gobject_class),
1516 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1518 _gtk_marshal_VOID__OBJECT,
1523 * GtkWidget::hierarchy-changed:
1524 * @widget: the object on which the signal is emitted
1525 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1526 * if the widget was previously unanchored
1528 * The ::hierarchy-changed signal is emitted when the
1529 * anchored state of a widget changes. A widget is
1530 * <firstterm>anchored</firstterm> when its toplevel
1531 * ancestor is a #GtkWindow. This signal is emitted when
1532 * a widget changes from un-anchored to anchored or vice-versa.
1534 widget_signals[HIERARCHY_CHANGED] =
1535 g_signal_new (I_("hierarchy-changed"),
1536 G_TYPE_FROM_CLASS (gobject_class),
1538 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1540 _gtk_marshal_VOID__OBJECT,
1545 * GtkWidget::style-set:
1546 * @widget: the object on which the signal is emitted
1547 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1548 * just got its initial style
1550 * The ::style-set signal is emitted when a new style has been set
1551 * on a widget. Note that style-modifying functions like
1552 * gtk_widget_modify_base() also cause this signal to be emitted.
1554 * Note that this signal is emitted for changes to the deprecated
1555 * #GtkStyle. To track changes to the #GtkStyleContext associated
1556 * with a widget, use the #GtkWidget::style-updated signal.
1558 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1560 widget_signals[STYLE_SET] =
1561 g_signal_new (I_("style-set"),
1562 G_TYPE_FROM_CLASS (gobject_class),
1564 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1566 _gtk_marshal_VOID__OBJECT,
1571 * GtkWidget::style-updated:
1572 * @widget: the object on which the signal is emitted
1574 * The ::style-updated signal is emitted when the #GtkStyleContext
1575 * of a widget is changed. Note that style-modifying functions like
1576 * gtk_widget_override_color() also cause this signal to be emitted.
1580 widget_signals[STYLE_UPDATED] =
1581 g_signal_new (I_("style-updated"),
1582 G_TYPE_FROM_CLASS (gobject_class),
1584 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1586 g_cclosure_marshal_VOID__VOID,
1590 * GtkWidget::direction-changed:
1591 * @widget: the object on which the signal is emitted
1592 * @previous_direction: the previous text direction of @widget
1594 * The ::direction-changed signal is emitted when the text direction
1595 * of a widget changes.
1597 widget_signals[DIRECTION_CHANGED] =
1598 g_signal_new (I_("direction-changed"),
1599 G_TYPE_FROM_CLASS (gobject_class),
1601 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1603 _gtk_marshal_VOID__ENUM,
1605 GTK_TYPE_TEXT_DIRECTION);
1608 * GtkWidget::grab-notify:
1609 * @widget: the object which received the signal
1610 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1611 * if it becomes unshadowed
1613 * The ::grab-notify signal is emitted when a widget becomes
1614 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1615 * another widget, or when it becomes unshadowed due to a grab
1618 * A widget is shadowed by a gtk_grab_add() when the topmost
1619 * grab widget in the grab stack of its window group is not
1622 widget_signals[GRAB_NOTIFY] =
1623 g_signal_new (I_("grab-notify"),
1624 G_TYPE_FROM_CLASS (gobject_class),
1626 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1628 _gtk_marshal_VOID__BOOLEAN,
1633 * GtkWidget::child-notify:
1634 * @widget: the object which received the signal
1635 * @pspec: the #GParamSpec of the changed child property
1637 * The ::child-notify signal is emitted for each
1638 * <link linkend="child-properties">child property</link> that has
1639 * changed on an object. The signal's detail holds the property name.
1641 widget_signals[CHILD_NOTIFY] =
1642 g_signal_new (I_("child-notify"),
1643 G_TYPE_FROM_CLASS (gobject_class),
1644 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1645 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1647 g_cclosure_marshal_VOID__PARAM,
1653 * @widget: the object which received the signal
1654 * @cr: the cairo context to draw to
1656 * This signal is emitted when a widget is supposed to render itself.
1657 * The @widget's top left corner must be painted at the origin of
1658 * the passed in context and be sized to the values returned by
1659 * gtk_widget_get_allocated_width() and
1660 * gtk_widget_get_allocated_height().
1662 * Signal handlers connected to this signal can modify the cairo
1663 * context passed as @cr in any way they like and don't need to
1664 * restore it. The signal emission takes care of calling cairo_save()
1665 * before and cairo_restore() after invoking the handler.
1667 widget_signals[DRAW] =
1668 g_signal_new (I_("draw"),
1669 G_TYPE_FROM_CLASS (gobject_class),
1671 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1672 _gtk_boolean_handled_accumulator, NULL,
1673 gtk_widget_draw_marshaller,
1675 CAIRO_GOBJECT_TYPE_CONTEXT);
1678 * GtkWidget::mnemonic-activate:
1679 * @widget: the object which received the signal.
1682 widget_signals[MNEMONIC_ACTIVATE] =
1683 g_signal_new (I_("mnemonic-activate"),
1684 G_TYPE_FROM_CLASS (gobject_class),
1686 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1687 _gtk_boolean_handled_accumulator, NULL,
1688 _gtk_marshal_BOOLEAN__BOOLEAN,
1693 * GtkWidget::grab-focus:
1694 * @widget: the object which received the signal.
1696 widget_signals[GRAB_FOCUS] =
1697 g_signal_new (I_("grab-focus"),
1698 G_TYPE_FROM_CLASS (gobject_class),
1699 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1700 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1702 _gtk_marshal_VOID__VOID,
1707 * @widget: the object which received the signal.
1710 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1712 widget_signals[FOCUS] =
1713 g_signal_new (I_("focus"),
1714 G_TYPE_FROM_CLASS (klass),
1716 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1717 _gtk_boolean_handled_accumulator, NULL,
1718 _gtk_marshal_BOOLEAN__ENUM,
1720 GTK_TYPE_DIRECTION_TYPE);
1723 * GtkWidget::move-focus:
1724 * @widget: the object which received the signal.
1727 widget_signals[MOVE_FOCUS] =
1728 g_signal_new (I_("move-focus"),
1729 G_TYPE_FROM_CLASS (klass),
1730 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1731 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1733 _gtk_marshal_VOID__ENUM,
1736 GTK_TYPE_DIRECTION_TYPE);
1739 * GtkWidget::keynav-failed:
1740 * @widget: the object which received the signal
1741 * @direction: the direction of movement
1743 * Gets emitted if keyboard navigation fails.
1744 * See gtk_widget_keynav_failed() for details.
1746 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1747 * if the emitting widget should try to handle the keyboard
1748 * navigation attempt in its parent container(s).
1752 widget_signals[KEYNAV_FAILED] =
1753 g_signal_new (I_("keynav-failed"),
1754 G_TYPE_FROM_CLASS (klass),
1756 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1757 _gtk_boolean_handled_accumulator, NULL,
1758 _gtk_marshal_BOOLEAN__ENUM,
1760 GTK_TYPE_DIRECTION_TYPE);
1764 * @widget: the object which received the signal.
1765 * @event: the #GdkEvent which triggered this signal
1767 * The GTK+ main loop will emit three signals for each GDK event delivered
1768 * to a widget: one generic ::event signal, another, more specific,
1769 * signal that matches the type of event delivered (e.g.
1770 * #GtkWidget::key-press-event) and finally a generic
1771 * #GtkWidget::event-after signal.
1773 * Returns: %TRUE to stop other handlers from being invoked for the event
1774 * and to cancel the emission of the second specific ::event signal.
1775 * %FALSE to propagate the event further and to allow the emission of
1776 * the second signal. The ::event-after signal is emitted regardless of
1779 widget_signals[EVENT] =
1780 g_signal_new (I_("event"),
1781 G_TYPE_FROM_CLASS (klass),
1783 G_STRUCT_OFFSET (GtkWidgetClass, event),
1784 _gtk_boolean_handled_accumulator, NULL,
1785 _gtk_marshal_BOOLEAN__BOXED,
1787 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1790 * GtkWidget::event-after:
1791 * @widget: the object which received the signal.
1792 * @event: the #GdkEvent which triggered this signal
1794 * After the emission of the #GtkWidget::event signal and (optionally)
1795 * the second more specific signal, ::event-after will be emitted
1796 * regardless of the previous two signals handlers return values.
1799 widget_signals[EVENT_AFTER] =
1800 g_signal_new (I_("event-after"),
1801 G_TYPE_FROM_CLASS (klass),
1805 _gtk_marshal_VOID__BOXED,
1807 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1810 * GtkWidget::button-press-event:
1811 * @widget: the object which received the signal.
1812 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1815 * The ::button-press-event signal will be emitted when a button
1816 * (typically from a mouse) is pressed.
1818 * To receive this signal, the #GdkWindow associated to the
1819 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1821 * This signal will be sent to the grab widget if there is one.
1823 * Returns: %TRUE to stop other handlers from being invoked for the event.
1824 * %FALSE to propagate the event further.
1826 widget_signals[BUTTON_PRESS_EVENT] =
1827 g_signal_new (I_("button-press-event"),
1828 G_TYPE_FROM_CLASS (klass),
1830 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1831 _gtk_boolean_handled_accumulator, NULL,
1832 _gtk_marshal_BOOLEAN__BOXED,
1834 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1837 * GtkWidget::button-release-event:
1838 * @widget: the object which received the signal.
1839 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1842 * The ::button-release-event signal will be emitted when a button
1843 * (typically from a mouse) is released.
1845 * To receive this signal, the #GdkWindow associated to the
1846 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1848 * This signal will be sent to the grab widget if there is one.
1850 * Returns: %TRUE to stop other handlers from being invoked for the event.
1851 * %FALSE to propagate the event further.
1853 widget_signals[BUTTON_RELEASE_EVENT] =
1854 g_signal_new (I_("button-release-event"),
1855 G_TYPE_FROM_CLASS (klass),
1857 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1858 _gtk_boolean_handled_accumulator, NULL,
1859 _gtk_marshal_BOOLEAN__BOXED,
1861 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1864 * GtkWidget::scroll-event:
1865 * @widget: the object which received the signal.
1866 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1869 * The ::scroll-event signal is emitted when a button in the 4 to 7
1870 * range is pressed. Wheel mice are usually configured to generate
1871 * button press events for buttons 4 and 5 when the wheel is turned.
1873 * To receive this signal, the #GdkWindow associated to the widget needs
1874 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1876 * This signal will be sent to the grab widget if there is one.
1878 * Returns: %TRUE to stop other handlers from being invoked for the event.
1879 * %FALSE to propagate the event further.
1881 widget_signals[SCROLL_EVENT] =
1882 g_signal_new (I_("scroll-event"),
1883 G_TYPE_FROM_CLASS (klass),
1885 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1886 _gtk_boolean_handled_accumulator, NULL,
1887 _gtk_marshal_BOOLEAN__BOXED,
1889 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1892 * GtkWidget::motion-notify-event:
1893 * @widget: the object which received the signal.
1894 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1897 * The ::motion-notify-event signal is emitted when the pointer moves
1898 * over the widget's #GdkWindow.
1900 * To receive this signal, the #GdkWindow associated to the widget
1901 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1903 * This signal will be sent to the grab widget if there is one.
1905 * Returns: %TRUE to stop other handlers from being invoked for the event.
1906 * %FALSE to propagate the event further.
1908 widget_signals[MOTION_NOTIFY_EVENT] =
1909 g_signal_new (I_("motion-notify-event"),
1910 G_TYPE_FROM_CLASS (klass),
1912 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1913 _gtk_boolean_handled_accumulator, NULL,
1914 _gtk_marshal_BOOLEAN__BOXED,
1916 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1919 * GtkWidget::composited-changed:
1920 * @widget: the object on which the signal is emitted
1922 * The ::composited-changed signal is emitted when the composited
1923 * status of @widget<!-- -->s screen changes.
1924 * See gdk_screen_is_composited().
1926 widget_signals[COMPOSITED_CHANGED] =
1927 g_signal_new (I_("composited-changed"),
1928 G_TYPE_FROM_CLASS (klass),
1929 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1930 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1932 _gtk_marshal_VOID__VOID,
1936 * GtkWidget::delete-event:
1937 * @widget: the object which received the signal
1938 * @event: the event which triggered this signal
1940 * The ::delete-event signal is emitted if a user requests that
1941 * a toplevel window is closed. The default handler for this signal
1942 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1943 * this signal will cause the window to be hidden instead, so that
1944 * it can later be shown again without reconstructing it.
1946 * Returns: %TRUE to stop other handlers from being invoked for the event.
1947 * %FALSE to propagate the event further.
1949 widget_signals[DELETE_EVENT] =
1950 g_signal_new (I_("delete-event"),
1951 G_TYPE_FROM_CLASS (klass),
1953 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1954 _gtk_boolean_handled_accumulator, NULL,
1955 _gtk_marshal_BOOLEAN__BOXED,
1957 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1960 * GtkWidget::destroy-event:
1961 * @widget: the object which received the signal.
1962 * @event: the event which triggered this signal
1964 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1965 * You rarely get this signal, because most widgets disconnect themselves
1966 * from their window before they destroy it, so no widget owns the
1967 * window at destroy time.
1969 * To receive this signal, the #GdkWindow associated to the widget needs
1970 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1971 * automatically for all new windows.
1973 * Returns: %TRUE to stop other handlers from being invoked for the event.
1974 * %FALSE to propagate the event further.
1976 widget_signals[DESTROY_EVENT] =
1977 g_signal_new (I_("destroy-event"),
1978 G_TYPE_FROM_CLASS (klass),
1980 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1981 _gtk_boolean_handled_accumulator, NULL,
1982 _gtk_marshal_BOOLEAN__BOXED,
1984 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1987 * GtkWidget::key-press-event:
1988 * @widget: the object which received the signal
1989 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1991 * The ::key-press-event signal is emitted when a key is pressed. The signal
1992 * emission will reoccur at the key-repeat rate when the key is kept pressed.
1994 * To receive this signal, the #GdkWindow associated to the widget needs
1995 * to enable the #GDK_KEY_PRESS_MASK mask.
1997 * This signal will be sent to the grab widget if there is one.
1999 * Returns: %TRUE to stop other handlers from being invoked for the event.
2000 * %FALSE to propagate the event further.
2002 widget_signals[KEY_PRESS_EVENT] =
2003 g_signal_new (I_("key-press-event"),
2004 G_TYPE_FROM_CLASS (klass),
2006 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
2007 _gtk_boolean_handled_accumulator, NULL,
2008 _gtk_marshal_BOOLEAN__BOXED,
2010 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2013 * GtkWidget::key-release-event:
2014 * @widget: the object which received the signal
2015 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2017 * The ::key-release-event signal is emitted when a key is released.
2019 * To receive this signal, the #GdkWindow associated to the widget needs
2020 * to enable the #GDK_KEY_RELEASE_MASK mask.
2022 * This signal will be sent to the grab widget if there is one.
2024 * Returns: %TRUE to stop other handlers from being invoked for the event.
2025 * %FALSE to propagate the event further.
2027 widget_signals[KEY_RELEASE_EVENT] =
2028 g_signal_new (I_("key-release-event"),
2029 G_TYPE_FROM_CLASS (klass),
2031 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2032 _gtk_boolean_handled_accumulator, NULL,
2033 _gtk_marshal_BOOLEAN__BOXED,
2035 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2038 * GtkWidget::enter-notify-event:
2039 * @widget: the object which received the signal
2040 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2043 * The ::enter-notify-event will be emitted when the pointer enters
2044 * the @widget's window.
2046 * To receive this signal, the #GdkWindow associated to the widget needs
2047 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2049 * This signal will be sent to the grab widget if there is one.
2051 * Returns: %TRUE to stop other handlers from being invoked for the event.
2052 * %FALSE to propagate the event further.
2054 widget_signals[ENTER_NOTIFY_EVENT] =
2055 g_signal_new (I_("enter-notify-event"),
2056 G_TYPE_FROM_CLASS (klass),
2058 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2059 _gtk_boolean_handled_accumulator, NULL,
2060 _gtk_marshal_BOOLEAN__BOXED,
2062 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2065 * GtkWidget::leave-notify-event:
2066 * @widget: the object which received the signal
2067 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2070 * The ::leave-notify-event will be emitted when the pointer leaves
2071 * the @widget's window.
2073 * To receive this signal, the #GdkWindow associated to the widget needs
2074 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2076 * This signal will be sent to the grab widget if there is one.
2078 * Returns: %TRUE to stop other handlers from being invoked for the event.
2079 * %FALSE to propagate the event further.
2081 widget_signals[LEAVE_NOTIFY_EVENT] =
2082 g_signal_new (I_("leave-notify-event"),
2083 G_TYPE_FROM_CLASS (klass),
2085 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2086 _gtk_boolean_handled_accumulator, NULL,
2087 _gtk_marshal_BOOLEAN__BOXED,
2089 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2092 * GtkWidget::configure-event:
2093 * @widget: the object which received the signal
2094 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2097 * The ::configure-event signal will be emitted when the size, position or
2098 * stacking of the @widget's window has changed.
2100 * To receive this signal, the #GdkWindow associated to the widget needs
2101 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2102 * automatically for all new windows.
2104 * Returns: %TRUE to stop other handlers from being invoked for the event.
2105 * %FALSE to propagate the event further.
2107 widget_signals[CONFIGURE_EVENT] =
2108 g_signal_new (I_("configure-event"),
2109 G_TYPE_FROM_CLASS (klass),
2111 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2112 _gtk_boolean_handled_accumulator, NULL,
2113 _gtk_marshal_BOOLEAN__BOXED,
2115 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2118 * GtkWidget::focus-in-event:
2119 * @widget: the object which received the signal
2120 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2123 * The ::focus-in-event signal will be emitted when the keyboard focus
2124 * enters the @widget's window.
2126 * To receive this signal, the #GdkWindow associated to the widget needs
2127 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2129 * Returns: %TRUE to stop other handlers from being invoked for the event.
2130 * %FALSE to propagate the event further.
2132 widget_signals[FOCUS_IN_EVENT] =
2133 g_signal_new (I_("focus-in-event"),
2134 G_TYPE_FROM_CLASS (klass),
2136 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2137 _gtk_boolean_handled_accumulator, NULL,
2138 _gtk_marshal_BOOLEAN__BOXED,
2140 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2143 * GtkWidget::focus-out-event:
2144 * @widget: the object which received the signal
2145 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2148 * The ::focus-out-event signal will be emitted when the keyboard focus
2149 * leaves the @widget's window.
2151 * To receive this signal, the #GdkWindow associated to the widget needs
2152 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2154 * Returns: %TRUE to stop other handlers from being invoked for the event.
2155 * %FALSE to propagate the event further.
2157 widget_signals[FOCUS_OUT_EVENT] =
2158 g_signal_new (I_("focus-out-event"),
2159 G_TYPE_FROM_CLASS (klass),
2161 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2162 _gtk_boolean_handled_accumulator, NULL,
2163 _gtk_marshal_BOOLEAN__BOXED,
2165 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2168 * GtkWidget::map-event:
2169 * @widget: the object which received the signal
2170 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2172 * The ::map-event signal will be emitted when the @widget's window is
2173 * mapped. A window is mapped when it becomes visible on the screen.
2175 * To receive this signal, the #GdkWindow associated to the widget needs
2176 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2177 * automatically for all new windows.
2179 * Returns: %TRUE to stop other handlers from being invoked for the event.
2180 * %FALSE to propagate the event further.
2182 widget_signals[MAP_EVENT] =
2183 g_signal_new (I_("map-event"),
2184 G_TYPE_FROM_CLASS (klass),
2186 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2187 _gtk_boolean_handled_accumulator, NULL,
2188 _gtk_marshal_BOOLEAN__BOXED,
2190 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2193 * GtkWidget::unmap-event:
2194 * @widget: the object which received the signal
2195 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2197 * The ::unmap-event signal will be emitted when the @widget's window is
2198 * unmapped. A window is unmapped when it becomes invisible on the screen.
2200 * To receive this signal, the #GdkWindow associated to the widget needs
2201 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2202 * automatically for all new windows.
2204 * Returns: %TRUE to stop other handlers from being invoked for the event.
2205 * %FALSE to propagate the event further.
2207 widget_signals[UNMAP_EVENT] =
2208 g_signal_new (I_("unmap-event"),
2209 G_TYPE_FROM_CLASS (klass),
2211 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2212 _gtk_boolean_handled_accumulator, NULL,
2213 _gtk_marshal_BOOLEAN__BOXED,
2215 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2218 * GtkWidget::property-notify-event:
2219 * @widget: the object which received the signal
2220 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2223 * The ::property-notify-event signal will be emitted when a property on
2224 * the @widget's window has been changed or deleted.
2226 * To receive this signal, the #GdkWindow associated to the widget needs
2227 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2229 * Returns: %TRUE to stop other handlers from being invoked for the event.
2230 * %FALSE to propagate the event further.
2232 widget_signals[PROPERTY_NOTIFY_EVENT] =
2233 g_signal_new (I_("property-notify-event"),
2234 G_TYPE_FROM_CLASS (klass),
2236 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2237 _gtk_boolean_handled_accumulator, NULL,
2238 _gtk_marshal_BOOLEAN__BOXED,
2240 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2243 * GtkWidget::selection-clear-event:
2244 * @widget: the object which received the signal
2245 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2248 * The ::selection-clear-event signal will be emitted when the
2249 * the @widget's window has lost ownership of a selection.
2251 * Returns: %TRUE to stop other handlers from being invoked for the event.
2252 * %FALSE to propagate the event further.
2254 widget_signals[SELECTION_CLEAR_EVENT] =
2255 g_signal_new (I_("selection-clear-event"),
2256 G_TYPE_FROM_CLASS (klass),
2258 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2259 _gtk_boolean_handled_accumulator, NULL,
2260 _gtk_marshal_BOOLEAN__BOXED,
2262 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2265 * GtkWidget::selection-request-event:
2266 * @widget: the object which received the signal
2267 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2270 * The ::selection-request-event signal will be emitted when
2271 * another client requests ownership of the selection owned by
2272 * the @widget's window.
2274 * Returns: %TRUE to stop other handlers from being invoked for the event.
2275 * %FALSE to propagate the event further.
2277 widget_signals[SELECTION_REQUEST_EVENT] =
2278 g_signal_new (I_("selection-request-event"),
2279 G_TYPE_FROM_CLASS (klass),
2281 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2282 _gtk_boolean_handled_accumulator, NULL,
2283 _gtk_marshal_BOOLEAN__BOXED,
2285 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2288 * GtkWidget::selection-notify-event:
2289 * @widget: the object which received the signal.
2290 * @event: (type Gdk.EventSelection):
2292 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2294 widget_signals[SELECTION_NOTIFY_EVENT] =
2295 g_signal_new (I_("selection-notify-event"),
2296 G_TYPE_FROM_CLASS (klass),
2298 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2299 _gtk_boolean_handled_accumulator, NULL,
2300 _gtk_marshal_BOOLEAN__BOXED,
2302 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2305 * GtkWidget::selection-received:
2306 * @widget: the object which received the signal.
2310 widget_signals[SELECTION_RECEIVED] =
2311 g_signal_new (I_("selection-received"),
2312 G_TYPE_FROM_CLASS (klass),
2314 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2316 _gtk_marshal_VOID__BOXED_UINT,
2318 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2322 * GtkWidget::selection-get:
2323 * @widget: the object which received the signal.
2328 widget_signals[SELECTION_GET] =
2329 g_signal_new (I_("selection-get"),
2330 G_TYPE_FROM_CLASS (klass),
2332 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2334 _gtk_marshal_VOID__BOXED_UINT_UINT,
2336 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2341 * GtkWidget::proximity-in-event:
2342 * @widget: the object which received the signal
2343 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2346 * To receive this signal the #GdkWindow associated to the widget needs
2347 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2349 * This signal will be sent to the grab widget if there is one.
2351 * Returns: %TRUE to stop other handlers from being invoked for the event.
2352 * %FALSE to propagate the event further.
2354 widget_signals[PROXIMITY_IN_EVENT] =
2355 g_signal_new (I_("proximity-in-event"),
2356 G_TYPE_FROM_CLASS (klass),
2358 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2359 _gtk_boolean_handled_accumulator, NULL,
2360 _gtk_marshal_BOOLEAN__BOXED,
2362 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2365 * GtkWidget::proximity-out-event:
2366 * @widget: the object which received the signal
2367 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2370 * To receive this signal the #GdkWindow associated to the widget needs
2371 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2373 * This signal will be sent to the grab widget if there is one.
2375 * Returns: %TRUE to stop other handlers from being invoked for the event.
2376 * %FALSE to propagate the event further.
2378 widget_signals[PROXIMITY_OUT_EVENT] =
2379 g_signal_new (I_("proximity-out-event"),
2380 G_TYPE_FROM_CLASS (klass),
2382 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2383 _gtk_boolean_handled_accumulator, NULL,
2384 _gtk_marshal_BOOLEAN__BOXED,
2386 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2389 * GtkWidget::drag-leave:
2390 * @widget: the object which received the signal.
2391 * @drag_context: the drag context
2392 * @time: the timestamp of the motion event
2394 * The ::drag-leave signal is emitted on the drop site when the cursor
2395 * leaves the widget. A typical reason to connect to this signal is to
2396 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2397 * with gtk_drag_unhighlight()
2399 widget_signals[DRAG_LEAVE] =
2400 g_signal_new (I_("drag-leave"),
2401 G_TYPE_FROM_CLASS (klass),
2403 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2405 _gtk_marshal_VOID__OBJECT_UINT,
2407 GDK_TYPE_DRAG_CONTEXT,
2411 * GtkWidget::drag-begin:
2412 * @widget: the object which received the signal
2413 * @drag_context: the drag context
2415 * The ::drag-begin signal is emitted on the drag source when a drag is
2416 * started. A typical reason to connect to this signal is to set up a
2417 * custom drag icon with gtk_drag_source_set_icon().
2419 * Note that some widgets set up a drag icon in the default handler of
2420 * this signal, so you may have to use g_signal_connect_after() to
2421 * override what the default handler did.
2423 widget_signals[DRAG_BEGIN] =
2424 g_signal_new (I_("drag-begin"),
2425 G_TYPE_FROM_CLASS (klass),
2427 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2429 _gtk_marshal_VOID__OBJECT,
2431 GDK_TYPE_DRAG_CONTEXT);
2434 * GtkWidget::drag-end:
2435 * @widget: the object which received the signal
2436 * @drag_context: the drag context
2438 * The ::drag-end signal is emitted on the drag source when a drag is
2439 * finished. A typical reason to connect to this signal is to undo
2440 * things done in #GtkWidget::drag-begin.
2442 widget_signals[DRAG_END] =
2443 g_signal_new (I_("drag-end"),
2444 G_TYPE_FROM_CLASS (klass),
2446 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2448 _gtk_marshal_VOID__OBJECT,
2450 GDK_TYPE_DRAG_CONTEXT);
2453 * GtkWidget::drag-data-delete:
2454 * @widget: the object which received the signal
2455 * @drag_context: the drag context
2457 * The ::drag-data-delete signal is emitted on the drag source when a drag
2458 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2459 * handler is responsible for deleting the data that has been dropped. What
2460 * "delete" means depends on the context of the drag operation.
2462 widget_signals[DRAG_DATA_DELETE] =
2463 g_signal_new (I_("drag-data-delete"),
2464 G_TYPE_FROM_CLASS (klass),
2466 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2468 _gtk_marshal_VOID__OBJECT,
2470 GDK_TYPE_DRAG_CONTEXT);
2473 * GtkWidget::drag-failed:
2474 * @widget: the object which received the signal
2475 * @drag_context: the drag context
2476 * @result: the result of the drag operation
2478 * The ::drag-failed signal is emitted on the drag source when a drag has
2479 * failed. The signal handler may hook custom code to handle a failed DND
2480 * operation based on the type of error, it returns %TRUE is the failure has
2481 * been already handled (not showing the default "drag operation failed"
2482 * animation), otherwise it returns %FALSE.
2484 * Return value: %TRUE if the failed drag operation has been already handled.
2488 widget_signals[DRAG_FAILED] =
2489 g_signal_new (I_("drag-failed"),
2490 G_TYPE_FROM_CLASS (klass),
2492 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2493 _gtk_boolean_handled_accumulator, NULL,
2494 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2496 GDK_TYPE_DRAG_CONTEXT,
2497 GTK_TYPE_DRAG_RESULT);
2500 * GtkWidget::drag-motion:
2501 * @widget: the object which received the signal
2502 * @drag_context: the drag context
2503 * @x: the x coordinate of the current cursor position
2504 * @y: the y coordinate of the current cursor position
2505 * @time: the timestamp of the motion event
2506 * @returns: whether the cursor position is in a drop zone
2508 * The drag-motion signal is emitted on the drop site when the user
2509 * moves the cursor over the widget during a drag. The signal handler
2510 * must determine whether the cursor position is in a drop zone or not.
2511 * If it is not in a drop zone, it returns %FALSE and no further processing
2512 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2513 * handler is responsible for providing the necessary information for
2514 * displaying feedback to the user, by calling gdk_drag_status().
2516 * If the decision whether the drop will be accepted or rejected can't be
2517 * made based solely on the cursor position and the type of the data, the
2518 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2519 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2520 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2521 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2522 * when using the drag-motion signal that way.
2524 * Also note that there is no drag-enter signal. The drag receiver has to
2525 * keep track of whether he has received any drag-motion signals since the
2526 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2527 * an "enter" signal. Upon an "enter", the handler will typically highlight
2528 * the drop site with gtk_drag_highlight().
2531 * drag_motion (GtkWidget *widget,
2532 * GdkDragContext *context,
2539 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2541 * if (!private_data->drag_highlight)
2543 * private_data->drag_highlight = 1;
2544 * gtk_drag_highlight (widget);
2547 * target = gtk_drag_dest_find_target (widget, context, NULL);
2548 * if (target == GDK_NONE)
2549 * gdk_drag_status (context, 0, time);
2552 * private_data->pending_status = context->suggested_action;
2553 * gtk_drag_get_data (widget, context, target, time);
2560 * drag_data_received (GtkWidget *widget,
2561 * GdkDragContext *context,
2564 * GtkSelectionData *selection_data,
2568 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2570 * if (private_data->suggested_action)
2572 * private_data->suggested_action = 0;
2574 * /* We are getting this data due to a request in drag_motion,
2575 * * rather than due to a request in drag_drop, so we are just
2576 * * supposed to call gdk_drag_status (), not actually paste in
2579 * str = gtk_selection_data_get_text (selection_data);
2580 * if (!data_is_acceptable (str))
2581 * gdk_drag_status (context, 0, time);
2583 * gdk_drag_status (context, private_data->suggested_action, time);
2587 * /* accept the drop */
2592 widget_signals[DRAG_MOTION] =
2593 g_signal_new (I_("drag-motion"),
2594 G_TYPE_FROM_CLASS (klass),
2596 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2597 _gtk_boolean_handled_accumulator, NULL,
2598 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2600 GDK_TYPE_DRAG_CONTEXT,
2606 * GtkWidget::drag-drop:
2607 * @widget: the object which received the signal
2608 * @drag_context: the drag context
2609 * @x: the x coordinate of the current cursor position
2610 * @y: the y coordinate of the current cursor position
2611 * @time: the timestamp of the motion event
2612 * @returns: whether the cursor position is in a drop zone
2614 * The ::drag-drop signal is emitted on the drop site when the user drops
2615 * the data onto the widget. The signal handler must determine whether
2616 * the cursor position is in a drop zone or not. If it is not in a drop
2617 * zone, it returns %FALSE and no further processing is necessary.
2618 * Otherwise, the handler returns %TRUE. In this case, the handler must
2619 * ensure that gtk_drag_finish() is called to let the source know that
2620 * the drop is done. The call to gtk_drag_finish() can be done either
2621 * directly or in a #GtkWidget::drag-data-received handler which gets
2622 * triggered by calling gtk_drag_get_data() to receive the data for one
2623 * or more of the supported targets.
2625 widget_signals[DRAG_DROP] =
2626 g_signal_new (I_("drag-drop"),
2627 G_TYPE_FROM_CLASS (klass),
2629 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2630 _gtk_boolean_handled_accumulator, NULL,
2631 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2633 GDK_TYPE_DRAG_CONTEXT,
2639 * GtkWidget::drag-data-get:
2640 * @widget: the object which received the signal
2641 * @drag_context: the drag context
2642 * @data: the #GtkSelectionData to be filled with the dragged data
2643 * @info: the info that has been registered with the target in the
2645 * @time: the timestamp at which the data was requested
2647 * The ::drag-data-get signal is emitted on the drag source when the drop
2648 * site requests the data which is dragged. It is the responsibility of
2649 * the signal handler to fill @data with the data in the format which
2650 * is indicated by @info. See gtk_selection_data_set() and
2651 * gtk_selection_data_set_text().
2653 widget_signals[DRAG_DATA_GET] =
2654 g_signal_new (I_("drag-data-get"),
2655 G_TYPE_FROM_CLASS (klass),
2657 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2659 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2661 GDK_TYPE_DRAG_CONTEXT,
2662 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2667 * GtkWidget::drag-data-received:
2668 * @widget: the object which received the signal
2669 * @drag_context: the drag context
2670 * @x: where the drop happened
2671 * @y: where the drop happened
2672 * @data: the received data
2673 * @info: the info that has been registered with the target in the
2675 * @time: the timestamp at which the data was received
2677 * The ::drag-data-received signal is emitted on the drop site when the
2678 * dragged data has been received. If the data was received in order to
2679 * determine whether the drop will be accepted, the handler is expected
2680 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2681 * If the data was received in response to a #GtkWidget::drag-drop signal
2682 * (and this is the last target to be received), the handler for this
2683 * signal is expected to process the received data and then call
2684 * gtk_drag_finish(), setting the @success parameter depending on whether
2685 * the data was processed successfully.
2687 * The handler may inspect and modify @drag_context->action before calling
2688 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2689 * following example:
2692 * drag_data_received (GtkWidget *widget,
2693 * GdkDragContext *drag_context,
2696 * GtkSelectionData *data,
2700 * if ((data->length >= 0) && (data->format == 8))
2702 * if (drag_context->action == GDK_ACTION_ASK)
2704 * GtkWidget *dialog;
2707 * dialog = gtk_message_dialog_new (NULL,
2708 * GTK_DIALOG_MODAL |
2709 * GTK_DIALOG_DESTROY_WITH_PARENT,
2711 * GTK_BUTTONS_YES_NO,
2712 * "Move the data ?\n");
2713 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2714 * gtk_widget_destroy (dialog);
2716 * if (response == GTK_RESPONSE_YES)
2717 * drag_context->action = GDK_ACTION_MOVE;
2719 * drag_context->action = GDK_ACTION_COPY;
2722 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2726 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2730 widget_signals[DRAG_DATA_RECEIVED] =
2731 g_signal_new (I_("drag-data-received"),
2732 G_TYPE_FROM_CLASS (klass),
2734 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2736 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2738 GDK_TYPE_DRAG_CONTEXT,
2741 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2746 * GtkWidget::visibility-notify-event:
2747 * @widget: the object which received the signal
2748 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2749 * triggered this signal.
2751 * The ::visibility-notify-event will be emitted when the @widget's window
2752 * is obscured or unobscured.
2754 * To receive this signal the #GdkWindow associated to the widget needs
2755 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2757 * Returns: %TRUE to stop other handlers from being invoked for the event.
2758 * %FALSE to propagate the event further.
2760 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2761 g_signal_new (I_("visibility-notify-event"),
2762 G_TYPE_FROM_CLASS (klass),
2764 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2765 _gtk_boolean_handled_accumulator, NULL,
2766 _gtk_marshal_BOOLEAN__BOXED,
2768 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2771 * GtkWidget::window-state-event:
2772 * @widget: the object which received the signal
2773 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2774 * triggered this signal.
2776 * The ::window-state-event will be emitted when the state of the
2777 * toplevel window associated to the @widget changes.
2779 * To receive this signal the #GdkWindow associated to the widget
2780 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2781 * this mask automatically for all new windows.
2783 * Returns: %TRUE to stop other handlers from being invoked for the
2784 * event. %FALSE to propagate the event further.
2786 widget_signals[WINDOW_STATE_EVENT] =
2787 g_signal_new (I_("window-state-event"),
2788 G_TYPE_FROM_CLASS (klass),
2790 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2791 _gtk_boolean_handled_accumulator, NULL,
2792 _gtk_marshal_BOOLEAN__BOXED,
2794 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2797 * GtkWidget::damage-event:
2798 * @widget: the object which received the signal
2799 * @event: (type Gdk.EventExpose): the #GdkEventExpose event
2801 * Emitted when a redirected window belonging to @widget gets drawn into.
2802 * The region/area members of the event shows what area of the redirected
2803 * drawable was drawn into.
2805 * Returns: %TRUE to stop other handlers from being invoked for the event.
2806 * %FALSE to propagate the event further.
2810 widget_signals[DAMAGE_EVENT] =
2811 g_signal_new (I_("damage-event"),
2812 G_TYPE_FROM_CLASS (klass),
2814 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2815 _gtk_boolean_handled_accumulator, NULL,
2816 _gtk_marshal_BOOLEAN__BOXED,
2818 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2821 * GtkWidget::grab-broken-event:
2822 * @widget: the object which received the signal
2823 * @event: (type Gdk.EventGrabBroken): the #GdkEventGrabBroken event
2825 * Emitted when a pointer or keyboard grab on a window belonging
2826 * to @widget gets broken.
2828 * On X11, this happens when the grab window becomes unviewable
2829 * (i.e. it or one of its ancestors is unmapped), or if the same
2830 * application grabs the pointer or keyboard again.
2832 * Returns: %TRUE to stop other handlers from being invoked for
2833 * the event. %FALSE to propagate the event further.
2837 widget_signals[GRAB_BROKEN_EVENT] =
2838 g_signal_new (I_("grab-broken-event"),
2839 G_TYPE_FROM_CLASS (klass),
2841 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2842 _gtk_boolean_handled_accumulator, NULL,
2843 _gtk_marshal_BOOLEAN__BOXED,
2845 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2848 * GtkWidget::query-tooltip:
2849 * @widget: the object which received the signal
2850 * @x: the x coordinate of the cursor position where the request has
2851 * been emitted, relative to @widget->window
2852 * @y: the y coordinate of the cursor position where the request has
2853 * been emitted, relative to @widget->window
2854 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2855 * @tooltip: a #GtkTooltip
2857 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2858 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2859 * focus in keyboard mode.
2861 * Using the given coordinates, the signal handler should determine
2862 * whether a tooltip should be shown for @widget. If this is the case
2863 * %TRUE should be returned, %FALSE otherwise. Note that if
2864 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2865 * should not be used.
2867 * The signal handler is free to manipulate @tooltip with the therefore
2868 * destined function calls.
2870 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2874 widget_signals[QUERY_TOOLTIP] =
2875 g_signal_new (I_("query-tooltip"),
2876 G_TYPE_FROM_CLASS (klass),
2878 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2879 _gtk_boolean_handled_accumulator, NULL,
2880 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2888 * GtkWidget::popup-menu
2889 * @widget: the object which received the signal
2891 * This signal gets emitted whenever a widget should pop up a context
2892 * menu. This usually happens through the standard key binding mechanism;
2893 * by pressing a certain key while a widget is focused, the user can cause
2894 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2895 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2896 * for an example of how to use this signal.
2898 * Returns: %TRUE if a menu was activated
2900 widget_signals[POPUP_MENU] =
2901 g_signal_new (I_("popup-menu"),
2902 G_TYPE_FROM_CLASS (klass),
2903 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2904 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2905 _gtk_boolean_handled_accumulator, NULL,
2906 _gtk_marshal_BOOLEAN__VOID,
2910 * GtkWidget::show-help:
2911 * @widget: the object which received the signal.
2914 widget_signals[SHOW_HELP] =
2915 g_signal_new (I_("show-help"),
2916 G_TYPE_FROM_CLASS (klass),
2917 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2918 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2919 _gtk_boolean_handled_accumulator, NULL,
2920 _gtk_marshal_BOOLEAN__ENUM,
2922 GTK_TYPE_WIDGET_HELP_TYPE);
2925 * GtkWidget::accel-closures-changed:
2926 * @widget: the object which received the signal.
2928 widget_signals[ACCEL_CLOSURES_CHANGED] =
2929 g_signal_new (I_("accel-closures-changed"),
2930 G_TYPE_FROM_CLASS (klass),
2934 _gtk_marshal_VOID__VOID,
2938 * GtkWidget::screen-changed:
2939 * @widget: the object on which the signal is emitted
2940 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2941 * widget was not associated with a screen before
2943 * The ::screen-changed signal gets emitted when the
2944 * screen of a widget has changed.
2946 widget_signals[SCREEN_CHANGED] =
2947 g_signal_new (I_("screen-changed"),
2948 G_TYPE_FROM_CLASS (klass),
2950 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2952 _gtk_marshal_VOID__OBJECT,
2957 * GtkWidget::can-activate-accel:
2958 * @widget: the object which received the signal
2959 * @signal_id: the ID of a signal installed on @widget
2961 * Determines whether an accelerator that activates the signal
2962 * identified by @signal_id can currently be activated.
2963 * This signal is present to allow applications and derived
2964 * widgets to override the default #GtkWidget handling
2965 * for determining whether an accelerator can be activated.
2967 * Returns: %TRUE if the signal can be activated.
2969 widget_signals[CAN_ACTIVATE_ACCEL] =
2970 g_signal_new (I_("can-activate-accel"),
2971 G_TYPE_FROM_CLASS (klass),
2973 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2974 _gtk_boolean_handled_accumulator, NULL,
2975 _gtk_marshal_BOOLEAN__UINT,
2976 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2978 binding_set = gtk_binding_set_by_class (klass);
2979 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
2981 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
2984 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
2986 GTK_TYPE_WIDGET_HELP_TYPE,
2987 GTK_WIDGET_HELP_TOOLTIP);
2988 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
2990 GTK_TYPE_WIDGET_HELP_TYPE,
2991 GTK_WIDGET_HELP_TOOLTIP);
2992 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
2994 GTK_TYPE_WIDGET_HELP_TYPE,
2995 GTK_WIDGET_HELP_WHATS_THIS);
2996 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
2998 GTK_TYPE_WIDGET_HELP_TYPE,
2999 GTK_WIDGET_HELP_WHATS_THIS);
3001 gtk_widget_class_install_style_property (klass,
3002 g_param_spec_boolean ("interior-focus",
3003 P_("Interior Focus"),
3004 P_("Whether to draw the focus indicator inside widgets"),
3006 GTK_PARAM_READABLE));
3008 gtk_widget_class_install_style_property (klass,
3009 g_param_spec_int ("focus-line-width",
3010 P_("Focus linewidth"),
3011 P_("Width, in pixels, of the focus indicator line"),
3013 GTK_PARAM_READABLE));
3015 gtk_widget_class_install_style_property (klass,
3016 g_param_spec_string ("focus-line-pattern",
3017 P_("Focus line dash pattern"),
3018 P_("Dash pattern used to draw the focus indicator"),
3020 GTK_PARAM_READABLE));
3021 gtk_widget_class_install_style_property (klass,
3022 g_param_spec_int ("focus-padding",
3023 P_("Focus padding"),
3024 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3026 GTK_PARAM_READABLE));
3027 gtk_widget_class_install_style_property (klass,
3028 g_param_spec_boxed ("cursor-color",
3030 P_("Color with which to draw insertion cursor"),
3032 GTK_PARAM_READABLE));
3033 gtk_widget_class_install_style_property (klass,
3034 g_param_spec_boxed ("secondary-cursor-color",
3035 P_("Secondary cursor color"),
3036 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3038 GTK_PARAM_READABLE));
3039 gtk_widget_class_install_style_property (klass,
3040 g_param_spec_float ("cursor-aspect-ratio",
3041 P_("Cursor line aspect ratio"),
3042 P_("Aspect ratio with which to draw insertion cursor"),
3044 GTK_PARAM_READABLE));
3046 gtk_widget_class_install_style_property (klass,
3047 g_param_spec_boolean ("window-dragging",
3048 P_("Window dragging"),
3049 P_("Whether windows can be dragged by clicking on empty areas"),
3051 GTK_PARAM_READABLE));
3054 * GtkWidget:link-color:
3056 * The "link-color" style property defines the color of unvisited links.
3060 gtk_widget_class_install_style_property (klass,
3061 g_param_spec_boxed ("link-color",
3062 P_("Unvisited Link Color"),
3063 P_("Color of unvisited links"),
3065 GTK_PARAM_READABLE));
3068 * GtkWidget:visited-link-color:
3070 * The "visited-link-color" style property defines the color of visited links.
3074 gtk_widget_class_install_style_property (klass,
3075 g_param_spec_boxed ("visited-link-color",
3076 P_("Visited Link Color"),
3077 P_("Color of visited links"),
3079 GTK_PARAM_READABLE));
3082 * GtkWidget:wide-separators:
3084 * The "wide-separators" style property defines whether separators have
3085 * configurable width and should be drawn using a box instead of a line.
3089 gtk_widget_class_install_style_property (klass,
3090 g_param_spec_boolean ("wide-separators",
3091 P_("Wide Separators"),
3092 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3094 GTK_PARAM_READABLE));
3097 * GtkWidget:separator-width:
3099 * The "separator-width" style property defines the width of separators.
3100 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3104 gtk_widget_class_install_style_property (klass,
3105 g_param_spec_int ("separator-width",
3106 P_("Separator Width"),
3107 P_("The width of separators if wide-separators is TRUE"),
3109 GTK_PARAM_READABLE));
3112 * GtkWidget:separator-height:
3114 * The "separator-height" style property defines the height of separators.
3115 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3119 gtk_widget_class_install_style_property (klass,
3120 g_param_spec_int ("separator-height",
3121 P_("Separator Height"),
3122 P_("The height of separators if \"wide-separators\" is TRUE"),
3124 GTK_PARAM_READABLE));
3127 * GtkWidget:scroll-arrow-hlength:
3129 * The "scroll-arrow-hlength" style property defines the length of
3130 * horizontal scroll arrows.
3134 gtk_widget_class_install_style_property (klass,
3135 g_param_spec_int ("scroll-arrow-hlength",
3136 P_("Horizontal Scroll Arrow Length"),
3137 P_("The length of horizontal scroll arrows"),
3139 GTK_PARAM_READABLE));
3142 * GtkWidget:scroll-arrow-vlength:
3144 * The "scroll-arrow-vlength" style property defines the length of
3145 * vertical scroll arrows.
3149 gtk_widget_class_install_style_property (klass,
3150 g_param_spec_int ("scroll-arrow-vlength",
3151 P_("Vertical Scroll Arrow Length"),
3152 P_("The length of vertical scroll arrows"),
3154 GTK_PARAM_READABLE));
3156 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3160 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3164 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3165 for (node = list; node; node = node->next)
3167 GParamSpec *pspec = node->data;
3169 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3170 g_param_spec_unref (pspec);
3176 gtk_widget_set_property (GObject *object,
3178 const GValue *value,
3181 GtkWidget *widget = GTK_WIDGET (object);
3186 gchar *tooltip_markup;
3187 const gchar *tooltip_text;
3188 GtkWindow *tooltip_window;
3191 gtk_widget_set_name (widget, g_value_get_string (value));
3194 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3196 case PROP_WIDTH_REQUEST:
3197 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3199 case PROP_HEIGHT_REQUEST:
3200 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3203 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3205 case PROP_SENSITIVE:
3206 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3208 case PROP_APP_PAINTABLE:
3209 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3211 case PROP_CAN_FOCUS:
3212 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3214 case PROP_HAS_FOCUS:
3215 if (g_value_get_boolean (value))
3216 gtk_widget_grab_focus (widget);
3219 if (g_value_get_boolean (value))
3220 gtk_widget_grab_focus (widget);
3222 case PROP_CAN_DEFAULT:
3223 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3225 case PROP_HAS_DEFAULT:
3226 if (g_value_get_boolean (value))
3227 gtk_widget_grab_default (widget);
3229 case PROP_RECEIVES_DEFAULT:
3230 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3233 gtk_widget_set_style (widget, g_value_get_object (value));
3236 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3237 gtk_widget_set_events (widget, g_value_get_flags (value));
3239 case PROP_NO_SHOW_ALL:
3240 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3242 case PROP_HAS_TOOLTIP:
3243 gtk_widget_real_set_has_tooltip (widget,
3244 g_value_get_boolean (value), FALSE);
3246 case PROP_TOOLTIP_MARKUP:
3247 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3248 tooltip_markup = g_value_dup_string (value);
3250 /* Treat an empty string as a NULL string,
3251 * because an empty string would be useless for a tooltip:
3253 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3255 g_free (tooltip_markup);
3256 tooltip_markup = NULL;
3259 g_object_set_qdata_full (object, quark_tooltip_markup,
3260 tooltip_markup, g_free);
3262 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3263 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3264 if (gtk_widget_get_visible (widget))
3265 gtk_widget_queue_tooltip_query (widget);
3267 case PROP_TOOLTIP_TEXT:
3268 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3270 tooltip_text = g_value_get_string (value);
3272 /* Treat an empty string as a NULL string,
3273 * because an empty string would be useless for a tooltip:
3275 if (tooltip_text && (strlen (tooltip_text) == 0))
3276 tooltip_text = NULL;
3278 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3280 g_object_set_qdata_full (object, quark_tooltip_markup,
3281 tooltip_markup, g_free);
3283 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3284 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3285 if (gtk_widget_get_visible (widget))
3286 gtk_widget_queue_tooltip_query (widget);
3288 case PROP_DOUBLE_BUFFERED:
3289 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3292 gtk_widget_set_halign (widget, g_value_get_enum (value));
3295 gtk_widget_set_valign (widget, g_value_get_enum (value));
3297 case PROP_MARGIN_LEFT:
3298 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3300 case PROP_MARGIN_RIGHT:
3301 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3303 case PROP_MARGIN_TOP:
3304 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3306 case PROP_MARGIN_BOTTOM:
3307 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3310 g_object_freeze_notify (G_OBJECT (widget));
3311 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3312 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3313 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3314 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3315 g_object_thaw_notify (G_OBJECT (widget));
3318 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3320 case PROP_HEXPAND_SET:
3321 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3324 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3326 case PROP_VEXPAND_SET:
3327 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3330 g_object_freeze_notify (G_OBJECT (widget));
3331 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3332 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3333 g_object_thaw_notify (G_OBJECT (widget));
3336 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3342 gtk_widget_get_property (GObject *object,
3347 GtkWidget *widget = GTK_WIDGET (object);
3348 GtkWidgetPrivate *priv = widget->priv;
3356 g_value_set_string (value, priv->name);
3358 g_value_set_static_string (value, "");
3361 g_value_set_object (value, priv->parent);
3363 case PROP_WIDTH_REQUEST:
3366 gtk_widget_get_size_request (widget, &w, NULL);
3367 g_value_set_int (value, w);
3370 case PROP_HEIGHT_REQUEST:
3373 gtk_widget_get_size_request (widget, NULL, &h);
3374 g_value_set_int (value, h);
3378 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3380 case PROP_SENSITIVE:
3381 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3383 case PROP_APP_PAINTABLE:
3384 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3386 case PROP_CAN_FOCUS:
3387 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3389 case PROP_HAS_FOCUS:
3390 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3393 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3395 case PROP_CAN_DEFAULT:
3396 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3398 case PROP_HAS_DEFAULT:
3399 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3401 case PROP_RECEIVES_DEFAULT:
3402 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3404 case PROP_COMPOSITE_CHILD:
3405 g_value_set_boolean (value, widget->priv->composite_child);
3408 g_value_set_object (value, gtk_widget_get_style (widget));
3411 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3412 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3414 case PROP_NO_SHOW_ALL:
3415 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3417 case PROP_HAS_TOOLTIP:
3418 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3420 case PROP_TOOLTIP_TEXT:
3422 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3425 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3426 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3428 g_value_take_string (value, text);
3431 case PROP_TOOLTIP_MARKUP:
3432 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3435 g_value_set_object (value, gtk_widget_get_window (widget));
3437 case PROP_DOUBLE_BUFFERED:
3438 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3441 g_value_set_enum (value, gtk_widget_get_halign (widget));
3444 g_value_set_enum (value, gtk_widget_get_valign (widget));
3446 case PROP_MARGIN_LEFT:
3447 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3449 case PROP_MARGIN_RIGHT:
3450 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3452 case PROP_MARGIN_TOP:
3453 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3455 case PROP_MARGIN_BOTTOM:
3456 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3460 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3461 if (aux_info == NULL)
3463 g_value_set_int (value, 0);
3467 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3468 aux_info->margin.right),
3469 MAX (aux_info->margin.top,
3470 aux_info->margin.bottom)));
3475 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3477 case PROP_HEXPAND_SET:
3478 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3481 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3483 case PROP_VEXPAND_SET:
3484 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3487 g_value_set_boolean (value,
3488 gtk_widget_get_hexpand (widget) &&
3489 gtk_widget_get_vexpand (widget));
3492 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3498 gtk_widget_init (GtkWidget *widget)
3500 GtkWidgetPrivate *priv;
3502 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3505 priv = widget->priv;
3507 priv->child_visible = TRUE;
3509 priv->allocation.x = -1;
3510 priv->allocation.y = -1;
3511 priv->allocation.width = 1;
3512 priv->allocation.height = 1;
3513 priv->window = NULL;
3514 priv->parent = NULL;
3516 priv->sensitive = TRUE;
3517 priv->parent_sensitive = TRUE;
3518 priv->composite_child = composite_child_stack != 0;
3519 priv->double_buffered = TRUE;
3520 priv->redraw_on_alloc = TRUE;
3521 priv->width_request_needed = TRUE;
3522 priv->height_request_needed = TRUE;
3523 priv->alloc_needed = TRUE;
3525 /* this will be set to TRUE if the widget gets a child or if the
3526 * expand flag is set on the widget, but until one of those happen
3527 * we know the expand is already properly FALSE.
3529 * We really want to default FALSE here to avoid computing expand
3530 * all over the place while initially building a widget tree.
3532 priv->need_compute_expand = FALSE;
3534 priv->style = gtk_widget_get_default_style ();
3535 g_object_ref (priv->style);
3540 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3542 GParamSpec **pspecs)
3544 GtkWidgetPrivate *priv = widget->priv;
3545 GtkWidget *container = priv->parent;
3548 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3549 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3553 * gtk_widget_freeze_child_notify:
3554 * @widget: a #GtkWidget
3556 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3557 * signals are queued until gtk_widget_thaw_child_notify() is called
3560 * This is the analogue of g_object_freeze_notify() for child properties.
3563 gtk_widget_freeze_child_notify (GtkWidget *widget)
3565 g_return_if_fail (GTK_IS_WIDGET (widget));
3567 if (!G_OBJECT (widget)->ref_count)
3570 g_object_ref (widget);
3571 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3572 g_object_unref (widget);
3576 * gtk_widget_child_notify:
3577 * @widget: a #GtkWidget
3578 * @child_property: the name of a child property installed on the
3579 * class of @widget<!-- -->'s parent
3581 * Emits a #GtkWidget::child-notify signal for the
3582 * <link linkend="child-properties">child property</link> @child_property
3585 * This is the analogue of g_object_notify() for child properties.
3588 gtk_widget_child_notify (GtkWidget *widget,
3589 const gchar *child_property)
3591 GtkWidgetPrivate *priv = widget->priv;
3594 g_return_if_fail (GTK_IS_WIDGET (widget));
3595 g_return_if_fail (child_property != NULL);
3596 if (!G_OBJECT (widget)->ref_count || !priv->parent)
3599 g_object_ref (widget);
3600 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3602 G_OBJECT_TYPE (priv->parent),
3605 g_warning ("%s: container class `%s' has no child property named `%s'",
3607 G_OBJECT_TYPE_NAME (priv->parent),
3611 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3613 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3614 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3616 g_object_unref (widget);
3620 * gtk_widget_thaw_child_notify:
3621 * @widget: a #GtkWidget
3623 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3624 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3628 gtk_widget_thaw_child_notify (GtkWidget *widget)
3630 GObjectNotifyQueue *nqueue;
3632 g_return_if_fail (GTK_IS_WIDGET (widget));
3634 if (!G_OBJECT (widget)->ref_count)
3637 g_object_ref (widget);
3638 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3639 if (!nqueue || !nqueue->freeze_count)
3640 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3641 G_OBJECT_TYPE_NAME (widget), widget);
3643 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3644 g_object_unref (widget);
3650 * @type: type ID of the widget to create
3651 * @first_property_name: name of first property to set
3652 * @Varargs: value of first property, followed by more properties,
3655 * This is a convenience function for creating a widget and setting
3656 * its properties in one go. For example you might write:
3657 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3658 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3659 * g_object_new(), but returns a widget so you don't have to
3660 * cast the object yourself.
3662 * Return value: a new #GtkWidget of type @widget_type
3665 gtk_widget_new (GType type,
3666 const gchar *first_property_name,
3672 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3674 va_start (var_args, first_property_name);
3675 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3682 gtk_widget_queue_draw_child (GtkWidget *widget)
3684 GtkWidgetPrivate *priv = widget->priv;
3687 parent = priv->parent;
3688 if (parent && gtk_widget_is_drawable (parent))
3689 gtk_widget_queue_draw_area (parent,
3692 priv->allocation.width,
3693 priv->allocation.height);
3697 * gtk_widget_unparent:
3698 * @widget: a #GtkWidget
3700 * This function is only for use in widget implementations.
3701 * Should be called by implementations of the remove method
3702 * on #GtkContainer, to dissociate a child from the container.
3705 gtk_widget_unparent (GtkWidget *widget)
3707 GtkWidgetPrivate *priv;
3708 GObjectNotifyQueue *nqueue;
3709 GtkWidget *toplevel;
3710 GtkWidget *old_parent;
3712 g_return_if_fail (GTK_IS_WIDGET (widget));
3714 priv = widget->priv;
3716 if (priv->parent == NULL)
3719 /* keep this function in sync with gtk_menu_detach() */
3721 gtk_widget_push_verify_invariants (widget);
3723 g_object_freeze_notify (G_OBJECT (widget));
3724 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3726 toplevel = gtk_widget_get_toplevel (widget);
3727 if (gtk_widget_is_toplevel (toplevel))
3728 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3730 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3731 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3733 gtk_widget_queue_draw_child (widget);
3735 /* Reset the width and height here, to force reallocation if we
3736 * get added back to a new parent. This won't work if our new
3737 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3738 * (would 0x0 be OK here?)
3740 priv->allocation.width = 1;
3741 priv->allocation.height = 1;
3743 if (gtk_widget_get_realized (widget))
3745 if (priv->in_reparent)
3746 gtk_widget_unmap (widget);
3748 gtk_widget_unrealize (widget);
3751 /* If we are unanchoring the child, we save around the toplevel
3752 * to emit hierarchy changed
3754 if (priv->parent->priv->anchored)
3755 g_object_ref (toplevel);
3759 /* Removing a widget from a container restores the child visible
3760 * flag to the default state, so it doesn't affect the child
3761 * in the next parent.
3763 priv->child_visible = TRUE;
3765 old_parent = priv->parent;
3766 priv->parent = NULL;
3768 /* parent may no longer expand if the removed
3769 * child was expand=TRUE and could therefore
3772 if (gtk_widget_get_visible (widget) &&
3773 (priv->need_compute_expand ||
3774 priv->computed_hexpand ||
3775 priv->computed_vexpand))
3777 gtk_widget_queue_compute_expand (old_parent);
3780 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3783 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3784 g_object_unref (toplevel);
3787 /* Now that the parent pointer is nullified and the hierarchy-changed
3788 * already passed, go ahead and unset the parent window, if we are unparenting
3789 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
3790 * will fire again for the new subhierarchy.
3792 gtk_widget_set_parent_window (widget, NULL);
3794 g_object_notify (G_OBJECT (widget), "parent");
3795 g_object_thaw_notify (G_OBJECT (widget));
3797 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3798 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3800 gtk_widget_pop_verify_invariants (widget);
3801 g_object_unref (widget);
3805 * gtk_widget_destroy:
3806 * @widget: a #GtkWidget
3808 * Destroys a widget.
3811 * destroyed, it will break any references it holds to other objects.
3812 * If the widget is inside a container, the widget will be removed
3813 * from the container. If the widget is a toplevel (derived from
3814 * #GtkWindow), it will be removed from the list of toplevels, and the
3815 * reference GTK+ holds to it will be removed. Removing a
3816 * widget from its container or the list of toplevels results in the
3817 * widget being finalized, unless you've added additional references
3818 * to the widget with g_object_ref().
3820 * In most cases, only toplevel widgets (windows) require explicit
3821 * destruction, because when you destroy a toplevel its children will
3822 * be destroyed as well.
3825 gtk_widget_destroy (GtkWidget *widget)
3827 g_return_if_fail (GTK_IS_WIDGET (widget));
3829 if (!widget->priv->in_destruction)
3830 g_object_run_dispose (G_OBJECT (widget));
3834 * gtk_widget_destroyed:
3835 * @widget: a #GtkWidget
3836 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3838 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3839 * %NULL. It's intended to be used as a callback connected to the
3840 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3841 * as a signal handler, and pass the address of your widget variable
3842 * as user data. Then when the widget is destroyed, the variable will
3843 * be set to %NULL. Useful for example to avoid multiple copies
3844 * of the same dialog.
3847 gtk_widget_destroyed (GtkWidget *widget,
3848 GtkWidget **widget_pointer)
3850 /* Don't make any assumptions about the
3852 * Even check widget_pointer.
3855 *widget_pointer = NULL;
3860 * @widget: a #GtkWidget
3862 * Flags a widget to be displayed. Any widget that isn't shown will
3863 * not appear on the screen. If you want to show all the widgets in a
3864 * container, it's easier to call gtk_widget_show_all() on the
3865 * container, instead of individually showing the widgets.
3867 * Remember that you have to show the containers containing a widget,
3868 * in addition to the widget itself, before it will appear onscreen.
3870 * When a toplevel container is shown, it is immediately realized and
3871 * mapped; other shown widgets are realized and mapped when their
3872 * toplevel container is realized and mapped.
3875 gtk_widget_show (GtkWidget *widget)
3877 g_return_if_fail (GTK_IS_WIDGET (widget));
3879 if (!gtk_widget_get_visible (widget))
3881 g_object_ref (widget);
3882 gtk_widget_push_verify_invariants (widget);
3884 if (!gtk_widget_is_toplevel (widget))
3885 gtk_widget_queue_resize (widget);
3887 /* see comment in set_parent() for why this should and can be
3890 if (widget->priv->need_compute_expand ||
3891 widget->priv->computed_hexpand ||
3892 widget->priv->computed_vexpand)
3894 if (widget->priv->parent != NULL)
3895 gtk_widget_queue_compute_expand (widget->priv->parent);
3898 g_signal_emit (widget, widget_signals[SHOW], 0);
3899 g_object_notify (G_OBJECT (widget), "visible");
3901 gtk_widget_pop_verify_invariants (widget);
3902 g_object_unref (widget);
3907 gtk_widget_real_show (GtkWidget *widget)
3909 GtkWidgetPrivate *priv = widget->priv;
3911 if (!gtk_widget_get_visible (widget))
3913 priv->visible = TRUE;
3916 gtk_widget_get_mapped (priv->parent) &&
3917 gtk_widget_get_child_visible (widget) &&
3918 !gtk_widget_get_mapped (widget))
3919 gtk_widget_map (widget);
3924 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3927 g_signal_handlers_disconnect_by_func (widget,
3928 gtk_widget_show_map_callback,
3933 * gtk_widget_show_now:
3934 * @widget: a #GtkWidget
3936 * Shows a widget. If the widget is an unmapped toplevel widget
3937 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3938 * loop and wait for the window to actually be mapped. Be careful;
3939 * because the main loop is running, anything can happen during
3943 gtk_widget_show_now (GtkWidget *widget)
3947 g_return_if_fail (GTK_IS_WIDGET (widget));
3949 /* make sure we will get event */
3950 if (!gtk_widget_get_mapped (widget) &&
3951 gtk_widget_is_toplevel (widget))
3953 gtk_widget_show (widget);
3955 g_signal_connect (widget, "map-event",
3956 G_CALLBACK (gtk_widget_show_map_callback),
3960 gtk_main_iteration ();
3963 gtk_widget_show (widget);
3968 * @widget: a #GtkWidget
3970 * Reverses the effects of gtk_widget_show(), causing the widget to be
3971 * hidden (invisible to the user).
3974 gtk_widget_hide (GtkWidget *widget)
3976 g_return_if_fail (GTK_IS_WIDGET (widget));
3978 if (gtk_widget_get_visible (widget))
3980 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3982 g_object_ref (widget);
3983 gtk_widget_push_verify_invariants (widget);
3985 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3986 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3988 /* a parent may now be expand=FALSE since we're hidden. */
3989 if (widget->priv->need_compute_expand ||
3990 widget->priv->computed_hexpand ||
3991 widget->priv->computed_vexpand)
3993 gtk_widget_queue_compute_expand (widget);
3996 g_signal_emit (widget, widget_signals[HIDE], 0);
3997 if (!gtk_widget_is_toplevel (widget))
3998 gtk_widget_queue_resize (widget);
3999 g_object_notify (G_OBJECT (widget), "visible");
4001 gtk_widget_pop_verify_invariants (widget);
4002 g_object_unref (widget);
4007 gtk_widget_real_hide (GtkWidget *widget)
4009 if (gtk_widget_get_visible (widget))
4011 widget->priv->visible = FALSE;
4013 if (gtk_widget_get_mapped (widget))
4014 gtk_widget_unmap (widget);
4019 * gtk_widget_hide_on_delete:
4020 * @widget: a #GtkWidget
4022 * Utility function; intended to be connected to the #GtkWidget::delete-event
4023 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4024 * argument, then returns %TRUE. If connected to ::delete-event, the
4025 * result is that clicking the close button for a window (on the
4026 * window frame, top right corner usually) will hide but not destroy
4027 * the window. By default, GTK+ destroys windows when ::delete-event
4030 * Return value: %TRUE
4033 gtk_widget_hide_on_delete (GtkWidget *widget)
4035 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4037 gtk_widget_hide (widget);
4043 * gtk_widget_show_all:
4044 * @widget: a #GtkWidget
4046 * Recursively shows a widget, and any child widgets (if the widget is
4050 gtk_widget_show_all (GtkWidget *widget)
4052 GtkWidgetClass *class;
4054 g_return_if_fail (GTK_IS_WIDGET (widget));
4056 if (gtk_widget_get_no_show_all (widget))
4059 class = GTK_WIDGET_GET_CLASS (widget);
4061 if (class->show_all)
4062 class->show_all (widget);
4066 _gtk_widget_notify_state_change (GtkWidget *widget,
4074 case GTK_STATE_FLAG_ACTIVE:
4075 state = GTK_STATE_ACTIVE;
4077 case GTK_STATE_FLAG_PRELIGHT:
4078 state = GTK_STATE_PRELIGHT;
4080 case GTK_STATE_FLAG_SELECTED:
4081 state = GTK_STATE_SELECTED;
4083 case GTK_STATE_FLAG_INSENSITIVE:
4084 state = GTK_STATE_INSENSITIVE;
4086 case GTK_STATE_FLAG_INCONSISTENT:
4087 state = GTK_STATE_INCONSISTENT;
4089 case GTK_STATE_FLAG_FOCUSED:
4090 state = GTK_STATE_FOCUSED;
4096 gtk_style_context_notify_state_change (widget->priv->context,
4097 gtk_widget_get_window (widget),
4098 NULL, state, target);
4101 /* Initializes state transitions for those states that
4102 * were enabled before mapping and have a looping animation.
4105 _gtk_widget_start_state_transitions (GtkWidget *widget)
4107 GtkStateFlags state, flag;
4109 if (!widget->priv->context)
4112 state = gtk_widget_get_state_flags (widget);
4113 flag = GTK_STATE_FLAG_FOCUSED;
4117 GtkAnimationDescription *animation_desc;
4119 if ((state & flag) == 0)
4125 gtk_style_context_get (widget->priv->context, state,
4126 "transition", &animation_desc,
4131 if (_gtk_animation_description_get_loop (animation_desc))
4132 _gtk_widget_notify_state_change (widget, flag, TRUE);
4134 _gtk_animation_description_unref (animation_desc);
4143 * @widget: a #GtkWidget
4145 * This function is only for use in widget implementations. Causes
4146 * a widget to be mapped if it isn't already.
4149 gtk_widget_map (GtkWidget *widget)
4151 GtkWidgetPrivate *priv;
4153 g_return_if_fail (GTK_IS_WIDGET (widget));
4154 g_return_if_fail (gtk_widget_get_visible (widget));
4155 g_return_if_fail (gtk_widget_get_child_visible (widget));
4157 priv = widget->priv;
4159 if (!gtk_widget_get_mapped (widget))
4161 gtk_widget_push_verify_invariants (widget);
4163 if (!gtk_widget_get_realized (widget))
4164 gtk_widget_realize (widget);
4166 g_signal_emit (widget, widget_signals[MAP], 0);
4168 if (!gtk_widget_get_has_window (widget))
4169 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4171 gtk_widget_pop_verify_invariants (widget);
4173 _gtk_widget_start_state_transitions (widget);
4179 * @widget: a #GtkWidget
4181 * This function is only for use in widget implementations. Causes
4182 * a widget to be unmapped if it's currently mapped.
4185 gtk_widget_unmap (GtkWidget *widget)
4187 GtkWidgetPrivate *priv;
4189 g_return_if_fail (GTK_IS_WIDGET (widget));
4191 priv = widget->priv;
4193 if (gtk_widget_get_mapped (widget))
4195 gtk_widget_push_verify_invariants (widget);
4197 if (!gtk_widget_get_has_window (widget))
4198 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4199 _gtk_tooltip_hide (widget);
4200 g_signal_emit (widget, widget_signals[UNMAP], 0);
4202 gtk_widget_pop_verify_invariants (widget);
4205 gtk_style_context_cancel_animations (priv->context, NULL);
4207 /* Unset pointer/window info */
4208 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4213 _gtk_widget_enable_device_events (GtkWidget *widget)
4215 GHashTable *device_events;
4216 GHashTableIter iter;
4217 gpointer key, value;
4219 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4224 g_hash_table_iter_init (&iter, device_events);
4226 while (g_hash_table_iter_next (&iter, &key, &value))
4229 GdkEventMask event_mask;
4232 event_mask = GPOINTER_TO_UINT (value);
4233 gtk_widget_add_events_internal (widget, device, event_mask);
4238 get_widget_windows (GtkWidget *widget)
4240 GList *window_list, *last, *l, *children, *ret;
4242 if (gtk_widget_get_has_window (widget))
4243 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4245 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4247 last = g_list_last (window_list);
4250 for (l = window_list; l; l = l->next)
4252 GtkWidget *window_widget = NULL;
4254 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4256 if (widget != window_widget)
4259 ret = g_list_prepend (ret, l->data);
4260 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4264 last = g_list_concat (last, children);
4265 last = g_list_last (last);
4269 g_list_free (window_list);
4275 device_enable_foreach (GtkWidget *widget,
4278 GdkDevice *device = user_data;
4279 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4283 device_disable_foreach (GtkWidget *widget,
4286 GdkDevice *device = user_data;
4287 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4291 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4296 GList *window_list, *l;
4298 window_list = get_widget_windows (widget);
4300 for (l = window_list; l; l = l->next)
4302 GdkEventMask events = 0;
4308 events = gdk_window_get_events (window);
4310 gdk_window_set_device_events (window, device, events);
4313 if (recurse && GTK_IS_CONTAINER (widget))
4316 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4318 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4321 g_list_free (window_list);
4325 gtk_widget_update_devices_mask (GtkWidget *widget,
4328 GList *enabled_devices, *l;
4330 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4332 for (l = enabled_devices; l; l = l->next)
4333 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4337 * gtk_widget_realize:
4338 * @widget: a #GtkWidget
4340 * Creates the GDK (windowing system) resources associated with a
4341 * widget. For example, @widget->window will be created when a widget
4342 * is realized. Normally realization happens implicitly; if you show
4343 * a widget and all its parent containers, then the widget will be
4344 * realized and mapped automatically.
4346 * Realizing a widget requires all
4347 * the widget's parent widgets to be realized; calling
4348 * gtk_widget_realize() realizes the widget's parents in addition to
4349 * @widget itself. If a widget is not yet inside a toplevel window
4350 * when you realize it, bad things will happen.
4352 * This function is primarily used in widget implementations, and
4353 * isn't very useful otherwise. Many times when you think you might
4354 * need it, a better approach is to connect to a signal that will be
4355 * called after the widget is realized automatically, such as
4356 * #GtkWidget::draw. Or simply g_signal_connect () to the
4357 * #GtkWidget::realize signal.
4360 gtk_widget_realize (GtkWidget *widget)
4362 GtkWidgetPrivate *priv;
4363 cairo_region_t *region;
4365 g_return_if_fail (GTK_IS_WIDGET (widget));
4366 g_return_if_fail (widget->priv->anchored ||
4367 GTK_IS_INVISIBLE (widget));
4369 priv = widget->priv;
4371 if (!gtk_widget_get_realized (widget))
4373 gtk_widget_push_verify_invariants (widget);
4376 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4377 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4380 if (priv->parent == NULL &&
4381 !gtk_widget_is_toplevel (widget))
4382 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4383 "inside a toplevel window is not going to work very well. "
4384 "Widgets must be inside a toplevel container before realizing them.");
4386 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4387 gtk_widget_realize (priv->parent);
4389 gtk_widget_ensure_style (widget);
4391 if (priv->style_update_pending)
4392 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4394 g_signal_emit (widget, widget_signals[REALIZE], 0);
4396 gtk_widget_real_set_has_tooltip (widget,
4397 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4400 if (priv->has_shape_mask)
4402 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4403 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4406 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4408 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4410 if (priv->multidevice)
4411 gdk_window_set_support_multidevice (priv->window, TRUE);
4413 _gtk_widget_enable_device_events (widget);
4414 gtk_widget_update_devices_mask (widget, TRUE);
4416 gtk_widget_pop_verify_invariants (widget);
4421 * gtk_widget_unrealize:
4422 * @widget: a #GtkWidget
4424 * This function is only useful in widget implementations.
4425 * Causes a widget to be unrealized (frees all GDK resources
4426 * associated with the widget, such as @widget->window).
4429 gtk_widget_unrealize (GtkWidget *widget)
4431 g_return_if_fail (GTK_IS_WIDGET (widget));
4433 gtk_widget_push_verify_invariants (widget);
4435 if (widget->priv->has_shape_mask)
4436 gtk_widget_shape_combine_region (widget, NULL);
4438 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4439 gtk_widget_input_shape_combine_region (widget, NULL);
4441 if (gtk_widget_get_realized (widget))
4443 g_object_ref (widget);
4445 if (widget->priv->mapped)
4446 gtk_widget_unmap (widget);
4448 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4449 g_assert (!widget->priv->mapped);
4450 gtk_widget_set_realized (widget, FALSE);
4452 g_object_unref (widget);
4455 gtk_widget_pop_verify_invariants (widget);
4458 /*****************************************
4460 *****************************************/
4463 * gtk_widget_queue_draw_region:
4464 * @widget: a #GtkWidget
4465 * @region: region to draw
4467 * Invalidates the rectangular area of @widget defined by @region by
4468 * calling gdk_window_invalidate_region() on the widget's window and
4469 * all its child windows. Once the main loop becomes idle (after the
4470 * current batch of events has been processed, roughly), the window
4471 * will receive expose events for the union of all regions that have
4474 * Normally you would only use this function in widget
4475 * implementations. You might also use it to schedule a redraw of a
4476 * #GtkDrawingArea or some portion thereof.
4481 gtk_widget_queue_draw_region (GtkWidget *widget,
4482 cairo_region_t *region)
4484 GtkWidgetPrivate *priv;
4487 g_return_if_fail (GTK_IS_WIDGET (widget));
4489 priv = widget->priv;
4491 if (!gtk_widget_get_realized (widget))
4494 /* Just return if the widget or one of its ancestors isn't mapped */
4495 for (w = widget; w != NULL; w = w->priv->parent)
4496 if (!gtk_widget_get_mapped (w))
4499 gdk_window_invalidate_region (priv->window, region, TRUE);
4503 * gtk_widget_queue_draw_area:
4504 * @widget: a #GtkWidget
4505 * @x: x coordinate of upper-left corner of rectangle to redraw
4506 * @y: y coordinate of upper-left corner of rectangle to redraw
4507 * @width: width of region to draw
4508 * @height: height of region to draw
4510 * Convenience function that calls gtk_widget_queue_draw_region() on
4511 * the region created from the given coordinates.
4513 * The region here is specified in widget coordinates.
4514 * Widget coordinates are a bit odd; for historical reasons, they are
4515 * defined as @widget->window coordinates for widgets that are not
4516 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4517 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4520 gtk_widget_queue_draw_area (GtkWidget *widget,
4527 cairo_region_t *region;
4529 g_return_if_fail (GTK_IS_WIDGET (widget));
4534 rect.height = height;
4536 region = cairo_region_create_rectangle (&rect);
4537 gtk_widget_queue_draw_region (widget, region);
4538 cairo_region_destroy (region);
4542 * gtk_widget_queue_draw:
4543 * @widget: a #GtkWidget
4545 * Equivalent to calling gtk_widget_queue_draw_area() for the
4546 * entire area of a widget.
4549 gtk_widget_queue_draw (GtkWidget *widget)
4553 g_return_if_fail (GTK_IS_WIDGET (widget));
4555 gtk_widget_get_allocation (widget, &rect);
4557 if (!gtk_widget_get_has_window (widget))
4558 gtk_widget_queue_draw_area (widget,
4559 rect.x, rect.y, rect.width, rect.height);
4561 gtk_widget_queue_draw_area (widget,
4562 0, 0, rect.width, rect.height);
4566 * gtk_widget_queue_resize:
4567 * @widget: a #GtkWidget
4569 * This function is only for use in widget implementations.
4570 * Flags a widget to have its size renegotiated; should
4571 * be called when a widget for some reason has a new size request.
4572 * For example, when you change the text in a #GtkLabel, #GtkLabel
4573 * queues a resize to ensure there's enough space for the new text.
4575 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4576 * from inside its implementation of the GtkWidgetClass::size_allocate
4577 * virtual method. Calls to gtk_widget_queue_resize() from inside
4578 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4581 gtk_widget_queue_resize (GtkWidget *widget)
4583 g_return_if_fail (GTK_IS_WIDGET (widget));
4585 if (gtk_widget_get_realized (widget))
4586 gtk_widget_queue_shallow_draw (widget);
4588 _gtk_size_group_queue_resize (widget, 0);
4592 * gtk_widget_queue_resize_no_redraw:
4593 * @widget: a #GtkWidget
4595 * This function works like gtk_widget_queue_resize(),
4596 * except that the widget is not invalidated.
4601 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4603 g_return_if_fail (GTK_IS_WIDGET (widget));
4605 _gtk_size_group_queue_resize (widget, 0);
4609 * gtk_widget_size_request:
4610 * @widget: a #GtkWidget
4611 * @requisition: (out): a #GtkRequisition to be filled in
4613 * This function is typically used when implementing a #GtkContainer
4614 * subclass. Obtains the preferred size of a widget. The container
4615 * uses this information to arrange its child widgets and decide what
4616 * size allocations to give them with gtk_widget_size_allocate().
4618 * You can also call this function from an application, with some
4619 * caveats. Most notably, getting a size request requires the widget
4620 * to be associated with a screen, because font information may be
4621 * needed. Multihead-aware applications should keep this in mind.
4623 * Also remember that the size request is not necessarily the size
4624 * a widget will actually be allocated.
4626 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4629 gtk_widget_size_request (GtkWidget *widget,
4630 GtkRequisition *requisition)
4632 g_return_if_fail (GTK_IS_WIDGET (widget));
4634 gtk_widget_get_preferred_size (widget, requisition, NULL);
4638 * gtk_widget_get_child_requisition:
4639 * @widget: a #GtkWidget
4640 * @requisition: (out): a #GtkRequisition to be filled in
4642 * This function is only for use in widget implementations. Obtains
4643 * @widget->requisition, unless someone has forced a particular
4644 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4645 * in which case it returns that geometry instead of the widget's
4648 * This function differs from gtk_widget_size_request() in that
4649 * it retrieves the last size request value from @widget->requisition,
4650 * while gtk_widget_size_request() actually calls the "size_request" method
4651 * on @widget to compute the size request and fill in @widget->requisition,
4652 * and only then returns @widget->requisition.
4654 * Because this function does not call the "size_request" method, it
4655 * can only be used when you know that @widget->requisition is
4656 * up-to-date, that is, gtk_widget_size_request() has been called
4657 * since the last time a resize was queued. In general, only container
4658 * implementations have this information; applications should use
4659 * gtk_widget_size_request().
4662 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4665 gtk_widget_get_child_requisition (GtkWidget *widget,
4666 GtkRequisition *requisition)
4668 gtk_widget_get_preferred_size (widget, requisition, NULL);
4672 invalidate_predicate (GdkWindow *window,
4677 gdk_window_get_user_data (window, &user_data);
4679 return (user_data == data);
4682 /* Invalidate @region in widget->window and all children
4683 * of widget->window owned by widget. @region is in the
4684 * same coordinates as widget->allocation and will be
4685 * modified by this call.
4688 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4689 cairo_region_t *region)
4691 GtkWidgetPrivate *priv = widget->priv;
4693 if (!gtk_widget_get_realized (widget))
4696 if (gtk_widget_get_has_window (widget) && priv->parent)
4700 gdk_window_get_position (priv->window, &x, &y);
4701 cairo_region_translate (region, -x, -y);
4704 gdk_window_invalidate_maybe_recurse (priv->window, region,
4705 invalidate_predicate, widget);
4709 * gtk_widget_queue_shallow_draw:
4710 * @widget: a #GtkWidget
4712 * Like gtk_widget_queue_draw(), but only windows owned
4713 * by @widget are invalidated.
4716 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4719 cairo_region_t *region;
4721 if (!gtk_widget_get_realized (widget))
4724 gtk_widget_get_allocation (widget, &rect);
4726 region = cairo_region_create_rectangle (&rect);
4727 gtk_widget_invalidate_widget_windows (widget, region);
4728 cairo_region_destroy (region);
4732 * gtk_widget_size_allocate:
4733 * @widget: a #GtkWidget
4734 * @allocation: position and size to be allocated to @widget
4736 * This function is only used by #GtkContainer subclasses, to assign a size
4737 * and position to their child widgets.
4739 * In this function, the allocation may be adjusted. It will be forced
4740 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4741 * method on the child will be used to adjust the allocation. Standard
4742 * adjustments include removing the widget's margins, and applying the
4743 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4746 gtk_widget_size_allocate (GtkWidget *widget,
4747 GtkAllocation *allocation)
4749 GtkWidgetPrivate *priv;
4750 GdkRectangle real_allocation;
4751 GdkRectangle old_allocation;
4752 GdkRectangle adjusted_allocation;
4753 gboolean alloc_needed;
4754 gboolean size_changed;
4755 gboolean position_changed;
4756 gint natural_width, natural_height, dummy;
4757 gint min_width, min_height;
4759 priv = widget->priv;
4761 g_return_if_fail (GTK_IS_WIDGET (widget));
4763 gtk_widget_push_verify_invariants (widget);
4765 #ifdef G_ENABLE_DEBUG
4766 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4777 parent = gtk_widget_get_parent (parent);
4780 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4781 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4782 2 * depth, " ", name,
4783 allocation->width, allocation->height);
4785 #endif /* G_ENABLE_DEBUG */
4787 alloc_needed = priv->alloc_needed;
4788 if (!priv->width_request_needed && !priv->height_request_needed)
4789 /* Preserve request/allocate ordering */
4790 priv->alloc_needed = FALSE;
4792 old_allocation = priv->allocation;
4793 real_allocation = *allocation;
4795 adjusted_allocation = real_allocation;
4796 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4798 /* Go ahead and request the height for allocated width, note that the internals
4799 * of get_height_for_width will internally limit the for_size to natural size
4800 * when aligning implicitly.
4802 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4803 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &dummy, &natural_height);
4807 /* Go ahead and request the width for allocated height, note that the internals
4808 * of get_width_for_height will internally limit the for_size to natural size
4809 * when aligning implicitly.
4811 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4812 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &dummy, &natural_width);
4815 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4816 * allocated sizes and possibly limit them to the natural sizes */
4817 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4818 GTK_ORIENTATION_HORIZONTAL,
4821 &adjusted_allocation.x,
4822 &adjusted_allocation.width);
4823 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4824 GTK_ORIENTATION_VERTICAL,
4827 &adjusted_allocation.y,
4828 &adjusted_allocation.height);
4830 if (adjusted_allocation.x < real_allocation.x ||
4831 adjusted_allocation.y < real_allocation.y ||
4832 (adjusted_allocation.x + adjusted_allocation.width) >
4833 (real_allocation.x + real_allocation.width) ||
4834 (adjusted_allocation.y + adjusted_allocation.height >
4835 real_allocation.y + real_allocation.height))
4837 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",
4838 G_OBJECT_TYPE_NAME (widget), widget,
4839 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4840 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4841 adjusted_allocation = real_allocation; /* veto it */
4845 real_allocation = adjusted_allocation;
4848 if (real_allocation.width < 0 || real_allocation.height < 0)
4850 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4851 real_allocation.width,
4852 real_allocation.height);
4855 real_allocation.width = MAX (real_allocation.width, 1);
4856 real_allocation.height = MAX (real_allocation.height, 1);
4858 size_changed = (old_allocation.width != real_allocation.width ||
4859 old_allocation.height != real_allocation.height);
4860 position_changed = (old_allocation.x != real_allocation.x ||
4861 old_allocation.y != real_allocation.y);
4863 if (!alloc_needed && !size_changed && !position_changed)
4866 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4868 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4869 priv->width_request_needed = FALSE;
4870 priv->height_request_needed = FALSE;
4871 priv->alloc_needed = FALSE;
4873 if (gtk_widget_get_mapped (widget))
4875 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4877 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4879 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4880 cairo_region_union_rectangle (invalidate, &old_allocation);
4882 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4883 cairo_region_destroy (invalidate);
4888 if (priv->redraw_on_alloc)
4890 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4892 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4893 cairo_region_union_rectangle (invalidate, &old_allocation);
4895 gtk_widget_invalidate_widget_windows (widget, invalidate);
4896 cairo_region_destroy (invalidate);
4900 if (size_changed || position_changed)
4902 GtkStyleContext *context;
4904 context = gtk_widget_get_style_context (widget);
4905 _gtk_style_context_invalidate_animation_areas (context);
4909 if ((size_changed || position_changed) && priv->parent &&
4910 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4912 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4913 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4914 cairo_region_destroy (invalidate);
4918 gtk_widget_pop_verify_invariants (widget);
4922 * gtk_widget_common_ancestor:
4923 * @widget_a: a #GtkWidget
4924 * @widget_b: a #GtkWidget
4926 * Find the common ancestor of @widget_a and @widget_b that
4927 * is closest to the two widgets.
4929 * Return value: the closest common ancestor of @widget_a and
4930 * @widget_b or %NULL if @widget_a and @widget_b do not
4931 * share a common ancestor.
4934 gtk_widget_common_ancestor (GtkWidget *widget_a,
4935 GtkWidget *widget_b)
4937 GtkWidget *parent_a;
4938 GtkWidget *parent_b;
4942 parent_a = widget_a;
4943 while (parent_a->priv->parent)
4945 parent_a = parent_a->priv->parent;
4949 parent_b = widget_b;
4950 while (parent_b->priv->parent)
4952 parent_b = parent_b->priv->parent;
4956 if (parent_a != parent_b)
4959 while (depth_a > depth_b)
4961 widget_a = widget_a->priv->parent;
4965 while (depth_b > depth_a)
4967 widget_b = widget_b->priv->parent;
4971 while (widget_a != widget_b)
4973 widget_a = widget_a->priv->parent;
4974 widget_b = widget_b->priv->parent;
4981 * gtk_widget_translate_coordinates:
4982 * @src_widget: a #GtkWidget
4983 * @dest_widget: a #GtkWidget
4984 * @src_x: X position relative to @src_widget
4985 * @src_y: Y position relative to @src_widget
4986 * @dest_x: (out): location to store X position relative to @dest_widget
4987 * @dest_y: (out): location to store Y position relative to @dest_widget
4989 * Translate coordinates relative to @src_widget's allocation to coordinates
4990 * relative to @dest_widget's allocations. In order to perform this
4991 * operation, both widgets must be realized, and must share a common
4994 * Return value: %FALSE if either widget was not realized, or there
4995 * was no common ancestor. In this case, nothing is stored in
4996 * *@dest_x and *@dest_y. Otherwise %TRUE.
4999 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5000 GtkWidget *dest_widget,
5006 GtkWidgetPrivate *src_priv = src_widget->priv;
5007 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5008 GtkWidget *ancestor;
5010 GList *dest_list = NULL;
5012 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5013 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5015 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5016 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5019 /* Translate from allocation relative to window relative */
5020 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5023 gdk_window_get_position (src_priv->window, &wx, &wy);
5025 src_x -= wx - src_priv->allocation.x;
5026 src_y -= wy - src_priv->allocation.y;
5030 src_x += src_priv->allocation.x;
5031 src_y += src_priv->allocation.y;
5034 /* Translate to the common ancestor */
5035 window = src_priv->window;
5036 while (window != ancestor->priv->window)
5040 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5045 window = gdk_window_get_effective_parent (window);
5047 if (!window) /* Handle GtkHandleBox */
5052 window = dest_priv->window;
5053 while (window != ancestor->priv->window)
5055 dest_list = g_list_prepend (dest_list, window);
5057 window = gdk_window_get_effective_parent (window);
5059 if (!window) /* Handle GtkHandleBox */
5061 g_list_free (dest_list);
5070 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5075 dest_list = g_list_remove (dest_list, dest_list->data);
5078 /* Translate from window relative to allocation relative */
5079 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5082 gdk_window_get_position (dest_priv->window, &wx, &wy);
5084 src_x += wx - dest_priv->allocation.x;
5085 src_y += wy - dest_priv->allocation.y;
5089 src_x -= dest_priv->allocation.x;
5090 src_y -= dest_priv->allocation.y;
5102 gtk_widget_real_size_allocate (GtkWidget *widget,
5103 GtkAllocation *allocation)
5105 GtkWidgetPrivate *priv = widget->priv;
5107 priv->allocation = *allocation;
5109 if (gtk_widget_get_realized (widget) &&
5110 gtk_widget_get_has_window (widget))
5112 gdk_window_move_resize (priv->window,
5113 allocation->x, allocation->y,
5114 allocation->width, allocation->height);
5119 adjust_for_align(GtkAlign align,
5121 gint *allocated_pos,
5122 gint *allocated_size)
5126 case GTK_ALIGN_FILL:
5127 /* change nothing */
5129 case GTK_ALIGN_START:
5130 /* keep *allocated_pos where it is */
5131 *allocated_size = MIN (*allocated_size, *natural_size);
5134 if (*allocated_size > *natural_size)
5136 *allocated_pos += (*allocated_size - *natural_size);
5137 *allocated_size = *natural_size;
5140 case GTK_ALIGN_CENTER:
5141 if (*allocated_size > *natural_size)
5143 *allocated_pos += (*allocated_size - *natural_size) / 2;
5144 *allocated_size = MIN (*allocated_size, *natural_size);
5151 adjust_for_margin(gint start_margin,
5155 gint *allocated_pos,
5156 gint *allocated_size)
5158 *minimum_size -= (start_margin + end_margin);
5159 *natural_size -= (start_margin + end_margin);
5160 *allocated_pos += start_margin;
5161 *allocated_size -= (start_margin + end_margin);
5165 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5166 GtkOrientation orientation,
5169 gint *allocated_pos,
5170 gint *allocated_size)
5172 const GtkWidgetAuxInfo *aux_info;
5174 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5176 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5178 adjust_for_margin (aux_info->margin.left,
5179 aux_info->margin.right,
5180 minimum_size, natural_size,
5181 allocated_pos, allocated_size);
5182 adjust_for_align (aux_info->halign,
5183 natural_size, allocated_pos, allocated_size);
5187 adjust_for_margin (aux_info->margin.top,
5188 aux_info->margin.bottom,
5189 minimum_size, natural_size,
5190 allocated_pos, allocated_size);
5191 adjust_for_align (aux_info->valign,
5192 natural_size, allocated_pos, allocated_size);
5197 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5200 GtkWidgetPrivate *priv = widget->priv;
5202 /* widgets must be onscreen for accels to take effect */
5203 return gtk_widget_is_sensitive (widget) &&
5204 gtk_widget_is_drawable (widget) &&
5205 gdk_window_is_viewable (priv->window);
5209 * gtk_widget_can_activate_accel:
5210 * @widget: a #GtkWidget
5211 * @signal_id: the ID of a signal installed on @widget
5213 * Determines whether an accelerator that activates the signal
5214 * identified by @signal_id can currently be activated.
5215 * This is done by emitting the #GtkWidget::can-activate-accel
5216 * signal on @widget; if the signal isn't overridden by a
5217 * handler or in a derived widget, then the default check is
5218 * that the widget must be sensitive, and the widget and all
5219 * its ancestors mapped.
5221 * Return value: %TRUE if the accelerator can be activated.
5226 gtk_widget_can_activate_accel (GtkWidget *widget,
5229 gboolean can_activate = FALSE;
5230 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5231 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5232 return can_activate;
5241 closure_accel_activate (GClosure *closure,
5242 GValue *return_value,
5243 guint n_param_values,
5244 const GValue *param_values,
5245 gpointer invocation_hint,
5246 gpointer marshal_data)
5248 AccelClosure *aclosure = (AccelClosure*) closure;
5249 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5252 g_signal_emit (closure->data, aclosure->signal_id, 0);
5254 /* whether accelerator was handled */
5255 g_value_set_boolean (return_value, can_activate);
5259 closures_destroy (gpointer data)
5261 GSList *slist, *closures = data;
5263 for (slist = closures; slist; slist = slist->next)
5265 g_closure_invalidate (slist->data);
5266 g_closure_unref (slist->data);
5268 g_slist_free (closures);
5272 widget_new_accel_closure (GtkWidget *widget,
5275 AccelClosure *aclosure;
5276 GClosure *closure = NULL;
5277 GSList *slist, *closures;
5279 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5280 for (slist = closures; slist; slist = slist->next)
5281 if (!gtk_accel_group_from_accel_closure (slist->data))
5283 /* reuse this closure */
5284 closure = slist->data;
5289 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5290 closures = g_slist_prepend (closures, g_closure_ref (closure));
5291 g_closure_sink (closure);
5292 g_closure_set_marshal (closure, closure_accel_activate);
5294 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5296 aclosure = (AccelClosure*) closure;
5297 g_assert (closure->data == widget);
5298 g_assert (closure->marshal == closure_accel_activate);
5299 aclosure->signal_id = signal_id;
5305 * gtk_widget_add_accelerator
5306 * @widget: widget to install an accelerator on
5307 * @accel_signal: widget signal to emit on accelerator activation
5308 * @accel_group: accel group for this widget, added to its toplevel
5309 * @accel_key: GDK keyval of the accelerator
5310 * @accel_mods: modifier key combination of the accelerator
5311 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5313 * Installs an accelerator for this @widget in @accel_group that causes
5314 * @accel_signal to be emitted if the accelerator is activated.
5315 * The @accel_group needs to be added to the widget's toplevel via
5316 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5317 * Accelerators added through this function are not user changeable during
5318 * runtime. If you want to support accelerators that can be changed by the
5319 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5320 * gtk_menu_item_set_accel_path() instead.
5323 gtk_widget_add_accelerator (GtkWidget *widget,
5324 const gchar *accel_signal,
5325 GtkAccelGroup *accel_group,
5327 GdkModifierType accel_mods,
5328 GtkAccelFlags accel_flags)
5333 g_return_if_fail (GTK_IS_WIDGET (widget));
5334 g_return_if_fail (accel_signal != NULL);
5335 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5337 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5338 if (!query.signal_id ||
5339 !(query.signal_flags & G_SIGNAL_ACTION) ||
5340 query.return_type != G_TYPE_NONE ||
5343 /* hmm, should be elaborate enough */
5344 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5345 G_OBJECT_TYPE_NAME (widget), accel_signal);
5349 closure = widget_new_accel_closure (widget, query.signal_id);
5351 g_object_ref (widget);
5353 /* install the accelerator. since we don't map this onto an accel_path,
5354 * the accelerator will automatically be locked.
5356 gtk_accel_group_connect (accel_group,
5359 accel_flags | GTK_ACCEL_LOCKED,
5362 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5364 g_object_unref (widget);
5368 * gtk_widget_remove_accelerator:
5369 * @widget: widget to install an accelerator on
5370 * @accel_group: accel group for this widget
5371 * @accel_key: GDK keyval of the accelerator
5372 * @accel_mods: modifier key combination of the accelerator
5373 * @returns: whether an accelerator was installed and could be removed
5375 * Removes an accelerator from @widget, previously installed with
5376 * gtk_widget_add_accelerator().
5379 gtk_widget_remove_accelerator (GtkWidget *widget,
5380 GtkAccelGroup *accel_group,
5382 GdkModifierType accel_mods)
5384 GtkAccelGroupEntry *ag_entry;
5385 GList *slist, *clist;
5388 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5389 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5391 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5392 clist = gtk_widget_list_accel_closures (widget);
5393 for (slist = clist; slist; slist = slist->next)
5397 for (i = 0; i < n; i++)
5398 if (slist->data == (gpointer) ag_entry[i].closure)
5400 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5402 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5404 g_list_free (clist);
5409 g_list_free (clist);
5411 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5412 accel_key, accel_mods, accel_group,
5413 G_OBJECT_TYPE_NAME (widget), widget);
5419 * gtk_widget_list_accel_closures:
5420 * @widget: widget to list accelerator closures for
5422 * Lists the closures used by @widget for accelerator group connections
5423 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5424 * The closures can be used to monitor accelerator changes on @widget,
5425 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5426 * #GtkAccelGroup of a closure which can be found out with
5427 * gtk_accel_group_from_accel_closure().
5429 * Return value: (transfer container) (element-type GClosure):
5430 * a newly allocated #GList of closures
5433 gtk_widget_list_accel_closures (GtkWidget *widget)
5436 GList *clist = NULL;
5438 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5440 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5441 if (gtk_accel_group_from_accel_closure (slist->data))
5442 clist = g_list_prepend (clist, slist->data);
5448 GtkAccelGroup *accel_group;
5453 destroy_accel_path (gpointer data)
5455 AccelPath *apath = data;
5457 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5459 /* closures_destroy takes care of unrefing the closure */
5460 g_object_unref (apath->accel_group);
5462 g_slice_free (AccelPath, apath);
5467 * gtk_widget_set_accel_path:
5468 * @widget: a #GtkWidget
5469 * @accel_path: (allow-none): path used to look up the accelerator
5470 * @accel_group: (allow-none): a #GtkAccelGroup.
5472 * Given an accelerator group, @accel_group, and an accelerator path,
5473 * @accel_path, sets up an accelerator in @accel_group so whenever the
5474 * key binding that is defined for @accel_path is pressed, @widget
5475 * will be activated. This removes any accelerators (for any
5476 * accelerator group) installed by previous calls to
5477 * gtk_widget_set_accel_path(). Associating accelerators with
5478 * paths allows them to be modified by the user and the modifications
5479 * to be saved for future use. (See gtk_accel_map_save().)
5481 * This function is a low level function that would most likely
5482 * be used by a menu creation system like #GtkUIManager. If you
5483 * use #GtkUIManager, setting up accelerator paths will be done
5486 * Even when you you aren't using #GtkUIManager, if you only want to
5487 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5488 * provides a somewhat more convenient interface.
5490 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5491 * pass a static string, you can save some memory by interning it first with
5492 * g_intern_static_string().
5495 gtk_widget_set_accel_path (GtkWidget *widget,
5496 const gchar *accel_path,
5497 GtkAccelGroup *accel_group)
5501 g_return_if_fail (GTK_IS_WIDGET (widget));
5502 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5506 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5507 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5509 gtk_accel_map_add_entry (accel_path, 0, 0);
5510 apath = g_slice_new (AccelPath);
5511 apath->accel_group = g_object_ref (accel_group);
5512 apath->path_quark = g_quark_from_string (accel_path);
5513 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5518 /* also removes possible old settings */
5519 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5522 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5524 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5528 _gtk_widget_get_accel_path (GtkWidget *widget,
5533 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5535 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5537 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5538 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5542 * gtk_widget_mnemonic_activate:
5543 * @widget: a #GtkWidget
5544 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5546 * Emits the #GtkWidget::mnemonic-activate signal.
5548 * The default handler for this signal activates the @widget if
5549 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5552 * Returns: %TRUE if the signal has been handled
5555 gtk_widget_mnemonic_activate (GtkWidget *widget,
5556 gboolean group_cycling)
5560 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5562 group_cycling = group_cycling != FALSE;
5563 if (!gtk_widget_is_sensitive (widget))
5566 g_signal_emit (widget,
5567 widget_signals[MNEMONIC_ACTIVATE],
5575 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5576 gboolean group_cycling)
5578 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5579 gtk_widget_activate (widget);
5580 else if (gtk_widget_get_can_focus (widget))
5581 gtk_widget_grab_focus (widget);
5584 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5585 G_OBJECT_TYPE_NAME (widget));
5586 gtk_widget_error_bell (widget);
5591 static const cairo_user_data_key_t event_key;
5594 _gtk_cairo_get_event (cairo_t *cr)
5596 g_return_val_if_fail (cr != NULL, NULL);
5598 return cairo_get_user_data (cr, &event_key);
5602 gtk_cairo_set_event (cairo_t *cr,
5603 GdkEventExpose *event)
5605 cairo_set_user_data (cr, &event_key, event, NULL);
5609 * gtk_cairo_should_draw_window:
5610 * @cr: a cairo context
5611 * @window: the window to check
5613 * This function is supposed to be called in #GtkWidget::draw
5614 * implementations for widgets that support multiple windows.
5615 * @cr must be untransformed from invoking of the draw function.
5616 * This function will return %TRUE if the contents of the given
5617 * @window are supposed to be drawn and %FALSE otherwise. Note
5618 * that when the drawing was not initiated by the windowing
5619 * system this function will return %TRUE for all windows, so
5620 * you need to draw the bottommost window first. Also, do not
5621 * use "else if" statements to check which window should be drawn.
5623 * Returns: %TRUE if @window should be drawn
5628 gtk_cairo_should_draw_window (cairo_t *cr,
5631 GdkEventExpose *event;
5633 g_return_val_if_fail (cr != NULL, FALSE);
5634 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5636 event = _gtk_cairo_get_event (cr);
5638 return event == NULL ||
5639 event->window == window;
5642 /* code shared by gtk_container_propagate_draw() and
5646 _gtk_widget_draw_internal (GtkWidget *widget,
5648 gboolean clip_to_size)
5650 GtkStyleContext *context;
5652 if (!gtk_widget_is_drawable (widget))
5657 cairo_rectangle (cr,
5659 widget->priv->allocation.width,
5660 widget->priv->allocation.height);
5664 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5668 g_signal_emit (widget, widget_signals[DRAW],
5673 context = gtk_widget_get_style_context (widget);
5674 _gtk_style_context_coalesce_animation_areas (context, widget);
5679 * @widget: the widget to draw. It must be drawable (see
5680 * gtk_widget_is_drawable()) and a size must have been allocated.
5681 * @cr: a cairo context to draw to
5683 * Draws @widget to @cr. The top left corner of the widget will be
5684 * drawn to the currently set origin point of @cr.
5686 * You should pass a cairo context as @cr argument that is in an
5687 * original state. Otherwise the resulting drawing is undefined. For
5688 * example changing the operator using cairo_set_operator() or the
5689 * line width using cairo_set_line_width() might have unwanted side
5691 * You may however change the context's transform matrix - like with
5692 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5693 * region with cairo_clip() prior to calling this function. Also, it
5694 * is fine to modify the context with cairo_save() and
5695 * cairo_push_group() prior to calling this function.
5697 * <note><para>Special purpose widgets may contain special code for
5698 * rendering to the screen and might appear differently on screen
5699 * and when rendered using gtk_widget_draw().</para></note>
5704 gtk_widget_draw (GtkWidget *widget,
5707 GdkEventExpose *tmp_event;
5709 g_return_if_fail (GTK_IS_WIDGET (widget));
5710 g_return_if_fail (!widget->priv->alloc_needed);
5711 g_return_if_fail (cr != NULL);
5714 /* We have to reset the event here so that draw functions can call
5715 * gtk_widget_draw() on random other widgets and get the desired
5716 * effect: Drawing all contents, not just the current window.
5718 tmp_event = _gtk_cairo_get_event (cr);
5719 gtk_cairo_set_event (cr, NULL);
5721 _gtk_widget_draw_internal (widget, cr, TRUE);
5723 gtk_cairo_set_event (cr, tmp_event);
5728 gtk_widget_real_key_press_event (GtkWidget *widget,
5731 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5735 gtk_widget_real_key_release_event (GtkWidget *widget,
5738 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5742 gtk_widget_real_focus_in_event (GtkWidget *widget,
5743 GdkEventFocus *event)
5745 gtk_widget_queue_shallow_draw (widget);
5751 gtk_widget_real_focus_out_event (GtkWidget *widget,
5752 GdkEventFocus *event)
5754 gtk_widget_queue_shallow_draw (widget);
5759 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5760 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5764 * @widget: a #GtkWidget
5765 * @event: a #GdkEvent
5767 * Rarely-used function. This function is used to emit
5768 * the event signals on a widget (those signals should never
5769 * be emitted without using this function to do so).
5770 * If you want to synthesize an event though, don't use this function;
5771 * instead, use gtk_main_do_event() so the event will behave as if
5772 * it were in the event queue. Don't synthesize expose events; instead,
5773 * use gdk_window_invalidate_rect() to invalidate a region of the
5776 * Return value: return from the event signal emission (%TRUE if
5777 * the event was handled)
5780 gtk_widget_event (GtkWidget *widget,
5783 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5784 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5786 if (event->type == GDK_EXPOSE)
5788 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5789 "the same effect, call gdk_window_invalidate_rect/region(), "
5790 "followed by gdk_window_process_updates().");
5794 return gtk_widget_event_internal (widget, event);
5797 /* Returns TRUE if a translation should be done */
5799 _gtk_widget_get_translation_to_window (GtkWidget *widget,
5804 GdkWindow *w, *widget_window;
5806 if (!gtk_widget_get_has_window (widget))
5808 *x = -widget->priv->allocation.x;
5809 *y = -widget->priv->allocation.y;
5817 widget_window = gtk_widget_get_window (widget);
5819 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5822 gdk_window_get_position (w, &wx, &wy);
5839 * gtk_cairo_transform_to_window:
5840 * @cr: the cairo context to transform
5841 * @widget: the widget the context is currently centered for
5842 * @window: the window to transform the context to
5844 * Transforms the given cairo context @cr that from @widget-relative
5845 * coordinates to @window-relative coordinates.
5846 * If the @widget's window is not an ancestor of @window, no
5847 * modification will be applied.
5849 * This is the inverse to the transformation GTK applies when
5850 * preparing an expose event to be emitted with the #GtkWidget::draw
5851 * signal. It is intended to help porting multiwindow widgets from
5852 * GTK+ 2 to the rendering architecture of GTK+ 3.
5857 gtk_cairo_transform_to_window (cairo_t *cr,
5863 g_return_if_fail (cr != NULL);
5864 g_return_if_fail (GTK_IS_WIDGET (widget));
5865 g_return_if_fail (GDK_IS_WINDOW (window));
5867 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
5868 cairo_translate (cr, x, y);
5872 * gtk_widget_send_expose:
5873 * @widget: a #GtkWidget
5874 * @event: a expose #GdkEvent
5876 * Very rarely-used function. This function is used to emit
5877 * an expose event on a widget. This function is not normally used
5878 * directly. The only time it is used is when propagating an expose
5879 * event to a child %NO_WINDOW widget, and that is normally done
5880 * using gtk_container_propagate_draw().
5882 * If you want to force an area of a window to be redrawn,
5883 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5884 * To cause the redraw to be done immediately, follow that call
5885 * with a call to gdk_window_process_updates().
5887 * Return value: return from the event signal emission (%TRUE if
5888 * the event was handled)
5891 gtk_widget_send_expose (GtkWidget *widget,
5894 gboolean result = FALSE;
5899 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5900 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5901 g_return_val_if_fail (event != NULL, TRUE);
5902 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5904 cr = gdk_cairo_create (event->expose.window);
5905 gtk_cairo_set_event (cr, &event->expose);
5907 gdk_cairo_region (cr, event->expose.region);
5910 do_clip = _gtk_widget_get_translation_to_window (widget,
5911 event->expose.window,
5913 cairo_translate (cr, -x, -y);
5915 _gtk_widget_draw_internal (widget, cr, do_clip);
5917 /* unset here, so if someone keeps a reference to cr we
5918 * don't leak the window. */
5919 gtk_cairo_set_event (cr, NULL);
5926 event_window_is_still_viewable (GdkEvent *event)
5928 /* Check that we think the event's window is viewable before
5929 * delivering the event, to prevent suprises. We do this here
5930 * at the last moment, since the event may have been queued
5931 * up behind other events, held over a recursive main loop, etc.
5933 switch (event->type)
5936 case GDK_MOTION_NOTIFY:
5937 case GDK_BUTTON_PRESS:
5938 case GDK_2BUTTON_PRESS:
5939 case GDK_3BUTTON_PRESS:
5941 case GDK_ENTER_NOTIFY:
5942 case GDK_PROXIMITY_IN:
5944 return event->any.window && gdk_window_is_viewable (event->any.window);
5947 /* The following events are the second half of paired events;
5948 * we always deliver them to deal with widgets that clean up
5949 * on the second half.
5951 case GDK_BUTTON_RELEASE:
5952 case GDK_KEY_RELEASE:
5953 case GDK_LEAVE_NOTIFY:
5954 case GDK_PROXIMITY_OUT:
5958 /* Remaining events would make sense on an not-viewable window,
5959 * or don't have an associated window.
5966 gtk_widget_event_internal (GtkWidget *widget,
5969 gboolean return_val = FALSE;
5971 /* We check only once for is-still-visible; if someone
5972 * hides the window in on of the signals on the widget,
5973 * they are responsible for returning TRUE to terminate
5976 if (!event_window_is_still_viewable (event))
5979 g_object_ref (widget);
5981 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5982 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5987 switch (event->type)
5993 case GDK_BUTTON_PRESS:
5994 case GDK_2BUTTON_PRESS:
5995 case GDK_3BUTTON_PRESS:
5996 signal_num = BUTTON_PRESS_EVENT;
5999 signal_num = SCROLL_EVENT;
6001 case GDK_BUTTON_RELEASE:
6002 signal_num = BUTTON_RELEASE_EVENT;
6004 case GDK_MOTION_NOTIFY:
6005 signal_num = MOTION_NOTIFY_EVENT;
6008 signal_num = DELETE_EVENT;
6011 signal_num = DESTROY_EVENT;
6012 _gtk_tooltip_hide (widget);
6015 signal_num = KEY_PRESS_EVENT;
6017 case GDK_KEY_RELEASE:
6018 signal_num = KEY_RELEASE_EVENT;
6020 case GDK_ENTER_NOTIFY:
6021 signal_num = ENTER_NOTIFY_EVENT;
6023 case GDK_LEAVE_NOTIFY:
6024 signal_num = LEAVE_NOTIFY_EVENT;
6026 case GDK_FOCUS_CHANGE:
6027 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6028 if (event->focus_change.in)
6029 _gtk_tooltip_focus_in (widget);
6031 _gtk_tooltip_focus_out (widget);
6034 signal_num = CONFIGURE_EVENT;
6037 signal_num = MAP_EVENT;
6040 signal_num = UNMAP_EVENT;
6042 case GDK_WINDOW_STATE:
6043 signal_num = WINDOW_STATE_EVENT;
6045 case GDK_PROPERTY_NOTIFY:
6046 signal_num = PROPERTY_NOTIFY_EVENT;
6048 case GDK_SELECTION_CLEAR:
6049 signal_num = SELECTION_CLEAR_EVENT;
6051 case GDK_SELECTION_REQUEST:
6052 signal_num = SELECTION_REQUEST_EVENT;
6054 case GDK_SELECTION_NOTIFY:
6055 signal_num = SELECTION_NOTIFY_EVENT;
6057 case GDK_PROXIMITY_IN:
6058 signal_num = PROXIMITY_IN_EVENT;
6060 case GDK_PROXIMITY_OUT:
6061 signal_num = PROXIMITY_OUT_EVENT;
6063 case GDK_VISIBILITY_NOTIFY:
6064 signal_num = VISIBILITY_NOTIFY_EVENT;
6066 case GDK_GRAB_BROKEN:
6067 signal_num = GRAB_BROKEN_EVENT;
6070 signal_num = DAMAGE_EVENT;
6073 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6077 if (signal_num != -1)
6078 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6080 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6081 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6085 g_object_unref (widget);
6091 * gtk_widget_activate:
6092 * @widget: a #GtkWidget that's activatable
6094 * For widgets that can be "activated" (buttons, menu items, etc.)
6095 * this function activates them. Activation is what happens when you
6096 * press Enter on a widget during key navigation. If @widget isn't
6097 * activatable, the function returns %FALSE.
6099 * Return value: %TRUE if the widget was activatable
6102 gtk_widget_activate (GtkWidget *widget)
6104 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6106 if (WIDGET_CLASS (widget)->activate_signal)
6108 /* FIXME: we should eventually check the signals signature here */
6109 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6118 gtk_widget_reparent_subwindows (GtkWidget *widget,
6119 GdkWindow *new_window)
6121 GtkWidgetPrivate *priv = widget->priv;
6123 if (!gtk_widget_get_has_window (widget))
6125 GList *children = gdk_window_get_children (priv->window);
6128 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6130 GdkWindow *window = tmp_list->data;
6133 gdk_window_get_user_data (window, &child);
6134 while (child && child != widget)
6135 child = ((GtkWidget*) child)->priv->parent;
6138 gdk_window_reparent (window, new_window, 0, 0);
6141 g_list_free (children);
6146 GList *tmp_list, *children;
6148 parent = gdk_window_get_parent (priv->window);
6151 gdk_window_reparent (priv->window, new_window, 0, 0);
6154 children = gdk_window_get_children (parent);
6156 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6158 GdkWindow *window = tmp_list->data;
6161 gdk_window_get_user_data (window, &child);
6163 if (child == widget)
6164 gdk_window_reparent (window, new_window, 0, 0);
6167 g_list_free (children);
6173 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6174 gpointer client_data)
6176 GtkWidgetPrivate *priv = widget->priv;
6178 g_assert (client_data != NULL);
6180 if (!gtk_widget_get_has_window (widget))
6183 g_object_unref (priv->window);
6184 priv->window = (GdkWindow*) client_data;
6186 g_object_ref (priv->window);
6188 if (GTK_IS_CONTAINER (widget))
6189 gtk_container_forall (GTK_CONTAINER (widget),
6190 gtk_widget_reparent_fixup_child,
6196 * gtk_widget_reparent:
6197 * @widget: a #GtkWidget
6198 * @new_parent: a #GtkContainer to move the widget into
6200 * Moves a widget from one #GtkContainer to another, handling reference
6201 * count issues to avoid destroying the widget.
6204 gtk_widget_reparent (GtkWidget *widget,
6205 GtkWidget *new_parent)
6207 GtkWidgetPrivate *priv;
6209 g_return_if_fail (GTK_IS_WIDGET (widget));
6210 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6211 priv = widget->priv;
6212 g_return_if_fail (priv->parent != NULL);
6214 if (priv->parent != new_parent)
6216 /* First try to see if we can get away without unrealizing
6217 * the widget as we reparent it. if so we set a flag so
6218 * that gtk_widget_unparent doesn't unrealize widget
6220 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6221 priv->in_reparent = TRUE;
6223 g_object_ref (widget);
6224 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6225 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6226 g_object_unref (widget);
6228 if (priv->in_reparent)
6230 priv->in_reparent = FALSE;
6232 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6233 gtk_widget_reparent_fixup_child (widget,
6234 gtk_widget_get_parent_window (widget));
6237 g_object_notify (G_OBJECT (widget), "parent");
6242 * gtk_widget_intersect:
6243 * @widget: a #GtkWidget
6244 * @area: a rectangle
6245 * @intersection: rectangle to store intersection of @widget and @area
6247 * Computes the intersection of a @widget's area and @area, storing
6248 * the intersection in @intersection, and returns %TRUE if there was
6249 * an intersection. @intersection may be %NULL if you're only
6250 * interested in whether there was an intersection.
6252 * Return value: %TRUE if there was an intersection
6255 gtk_widget_intersect (GtkWidget *widget,
6256 const GdkRectangle *area,
6257 GdkRectangle *intersection)
6259 GtkWidgetPrivate *priv;
6264 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6265 g_return_val_if_fail (area != NULL, FALSE);
6267 priv = widget->priv;
6270 dest = intersection;
6274 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6276 if (return_val && intersection && gtk_widget_get_has_window (widget))
6278 intersection->x -= priv->allocation.x;
6279 intersection->y -= priv->allocation.y;
6286 * gtk_widget_region_intersect:
6287 * @widget: a #GtkWidget
6288 * @region: a #cairo_region_t, in the same coordinate system as
6289 * @widget->allocation. That is, relative to @widget->window
6290 * for %NO_WINDOW widgets; relative to the parent window
6291 * of @widget->window for widgets with their own window.
6292 * @returns: A newly allocated region holding the intersection of @widget
6293 * and @region. The coordinates of the return value are
6294 * relative to @widget->window for %NO_WINDOW widgets, and
6295 * relative to the parent window of @widget->window for
6296 * widgets with their own window.
6298 * Computes the intersection of a @widget's area and @region, returning
6299 * the intersection. The result may be empty, use cairo_region_is_empty() to
6303 gtk_widget_region_intersect (GtkWidget *widget,
6304 const cairo_region_t *region)
6307 cairo_region_t *dest;
6309 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6310 g_return_val_if_fail (region != NULL, NULL);
6312 gtk_widget_get_allocation (widget, &rect);
6314 dest = cairo_region_create_rectangle (&rect);
6316 cairo_region_intersect (dest, region);
6322 * _gtk_widget_grab_notify:
6323 * @widget: a #GtkWidget
6324 * @was_grabbed: whether a grab is now in effect
6326 * Emits the #GtkWidget::grab-notify signal on @widget.
6331 _gtk_widget_grab_notify (GtkWidget *widget,
6332 gboolean was_grabbed)
6334 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6338 * gtk_widget_grab_focus:
6339 * @widget: a #GtkWidget
6341 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6342 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6343 * something like #GtkFrame won't work.
6345 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6346 * gtk_widget_set_can_focus() to modify that flag.
6348 * The widget also needs to be realized and mapped. This is indicated by the
6349 * related signals. Grabbing the focus immediately after creating the widget
6350 * will likely fail and cause critical warnings.
6353 gtk_widget_grab_focus (GtkWidget *widget)
6355 g_return_if_fail (GTK_IS_WIDGET (widget));
6357 if (!gtk_widget_is_sensitive (widget))
6360 g_object_ref (widget);
6361 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6362 g_object_notify (G_OBJECT (widget), "has-focus");
6363 g_object_unref (widget);
6367 reset_focus_recurse (GtkWidget *widget,
6370 if (GTK_IS_CONTAINER (widget))
6372 GtkContainer *container;
6374 container = GTK_CONTAINER (widget);
6375 gtk_container_set_focus_child (container, NULL);
6377 gtk_container_foreach (container,
6378 reset_focus_recurse,
6384 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6386 if (gtk_widget_get_can_focus (focus_widget))
6388 GtkWidget *toplevel;
6391 /* clear the current focus setting, break if the current widget
6392 * is the focus widget's parent, since containers above that will
6393 * be set by the next loop.
6395 toplevel = gtk_widget_get_toplevel (focus_widget);
6396 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6398 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6400 if (widget == focus_widget)
6402 /* We call _gtk_window_internal_set_focus() here so that the
6403 * toplevel window can request the focus if necessary.
6404 * This is needed when the toplevel is a GtkPlug
6406 if (!gtk_widget_has_focus (widget))
6407 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6414 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
6416 widget = widget->priv->parent;
6417 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6421 else if (toplevel != focus_widget)
6423 /* gtk_widget_grab_focus() operates on a tree without window...
6424 * actually, this is very questionable behaviour.
6427 gtk_container_foreach (GTK_CONTAINER (toplevel),
6428 reset_focus_recurse,
6432 /* now propagate the new focus up the widget tree and finally
6433 * set it on the window
6435 widget = focus_widget;
6436 while (widget->priv->parent)
6438 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6439 widget = widget->priv->parent;
6441 if (GTK_IS_WINDOW (widget))
6442 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6447 gtk_widget_real_query_tooltip (GtkWidget *widget,
6450 gboolean keyboard_tip,
6451 GtkTooltip *tooltip)
6453 gchar *tooltip_markup;
6454 gboolean has_tooltip;
6456 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6457 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6459 if (has_tooltip && tooltip_markup)
6461 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6469 gtk_widget_real_style_updated (GtkWidget *widget)
6471 if (gtk_widget_get_realized (widget))
6473 /* Trigger ::style-set for old
6474 * widgets not listening to this
6476 g_signal_emit (widget,
6477 widget_signals[STYLE_SET],
6479 widget->priv->style);
6482 if (widget->priv->context)
6484 gtk_style_context_invalidate (widget->priv->context);
6486 if (gtk_widget_get_realized (widget) &&
6487 gtk_widget_get_has_window (widget))
6488 gtk_style_context_set_background (widget->priv->context,
6489 widget->priv->window);
6492 if (widget->priv->anchored)
6493 gtk_widget_queue_resize (widget);
6497 gtk_widget_real_show_help (GtkWidget *widget,
6498 GtkWidgetHelpType help_type)
6500 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6502 _gtk_tooltip_toggle_keyboard_mode (widget);
6511 gtk_widget_real_focus (GtkWidget *widget,
6512 GtkDirectionType direction)
6514 if (!gtk_widget_get_can_focus (widget))
6517 if (!gtk_widget_is_focus (widget))
6519 gtk_widget_grab_focus (widget);
6527 gtk_widget_real_move_focus (GtkWidget *widget,
6528 GtkDirectionType direction)
6530 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6532 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6534 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6540 gtk_widget_real_keynav_failed (GtkWidget *widget,
6541 GtkDirectionType direction)
6543 gboolean cursor_only;
6547 case GTK_DIR_TAB_FORWARD:
6548 case GTK_DIR_TAB_BACKWARD:
6555 g_object_get (gtk_widget_get_settings (widget),
6556 "gtk-keynav-cursor-only", &cursor_only,
6563 gtk_widget_error_bell (widget);
6569 * gtk_widget_set_can_focus:
6570 * @widget: a #GtkWidget
6571 * @can_focus: whether or not @widget can own the input focus.
6573 * Specifies whether @widget can own the input focus. See
6574 * gtk_widget_grab_focus() for actually setting the input focus on a
6580 gtk_widget_set_can_focus (GtkWidget *widget,
6583 g_return_if_fail (GTK_IS_WIDGET (widget));
6585 if (widget->priv->can_focus != can_focus)
6587 widget->priv->can_focus = can_focus;
6589 gtk_widget_queue_resize (widget);
6590 g_object_notify (G_OBJECT (widget), "can-focus");
6595 * gtk_widget_get_can_focus:
6596 * @widget: a #GtkWidget
6598 * Determines whether @widget can own the input focus. See
6599 * gtk_widget_set_can_focus().
6601 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6606 gtk_widget_get_can_focus (GtkWidget *widget)
6608 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6610 return widget->priv->can_focus;
6614 * gtk_widget_has_focus:
6615 * @widget: a #GtkWidget
6617 * Determines if the widget has the global input focus. See
6618 * gtk_widget_is_focus() for the difference between having the global
6619 * input focus, and only having the focus within a toplevel.
6621 * Return value: %TRUE if the widget has the global input focus.
6626 gtk_widget_has_focus (GtkWidget *widget)
6628 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6630 return widget->priv->has_focus;
6634 * gtk_widget_is_focus:
6635 * @widget: a #GtkWidget
6637 * Determines if the widget is the focus widget within its
6638 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6639 * necessarily set; %HAS_FOCUS will only be set if the
6640 * toplevel widget additionally has the global input focus.)
6642 * Return value: %TRUE if the widget is the focus widget.
6645 gtk_widget_is_focus (GtkWidget *widget)
6647 GtkWidget *toplevel;
6649 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6651 toplevel = gtk_widget_get_toplevel (widget);
6653 if (GTK_IS_WINDOW (toplevel))
6654 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6660 * gtk_widget_set_can_default:
6661 * @widget: a #GtkWidget
6662 * @can_default: whether or not @widget can be a default widget.
6664 * Specifies whether @widget can be a default widget. See
6665 * gtk_widget_grab_default() for details about the meaning of
6671 gtk_widget_set_can_default (GtkWidget *widget,
6672 gboolean can_default)
6674 g_return_if_fail (GTK_IS_WIDGET (widget));
6676 if (widget->priv->can_default != can_default)
6678 widget->priv->can_default = can_default;
6680 gtk_widget_queue_resize (widget);
6681 g_object_notify (G_OBJECT (widget), "can-default");
6686 * gtk_widget_get_can_default:
6687 * @widget: a #GtkWidget
6689 * Determines whether @widget can be a default widget. See
6690 * gtk_widget_set_can_default().
6692 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6697 gtk_widget_get_can_default (GtkWidget *widget)
6699 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6701 return widget->priv->can_default;
6705 * gtk_widget_has_default:
6706 * @widget: a #GtkWidget
6708 * Determines whether @widget is the current default widget within its
6709 * toplevel. See gtk_widget_set_can_default().
6711 * Return value: %TRUE if @widget is the current default widget within
6712 * its toplevel, %FALSE otherwise
6717 gtk_widget_has_default (GtkWidget *widget)
6719 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6721 return widget->priv->has_default;
6725 _gtk_widget_set_has_default (GtkWidget *widget,
6726 gboolean has_default)
6728 widget->priv->has_default = has_default;
6732 * gtk_widget_grab_default:
6733 * @widget: a #GtkWidget
6735 * Causes @widget to become the default widget. @widget must have the
6736 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6737 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6738 * %TRUE)</literal>. The default widget is activated when
6739 * the user presses Enter in a window. Default widgets must be
6740 * activatable, that is, gtk_widget_activate() should affect them. Note
6741 * that #GtkEntry widgets require the "activates-default" property
6742 * set to %TRUE before they activate the default widget when Enter
6743 * is pressed and the #GtkEntry is focused.
6746 gtk_widget_grab_default (GtkWidget *widget)
6750 g_return_if_fail (GTK_IS_WIDGET (widget));
6751 g_return_if_fail (gtk_widget_get_can_default (widget));
6753 window = gtk_widget_get_toplevel (widget);
6755 if (window && gtk_widget_is_toplevel (window))
6756 gtk_window_set_default (GTK_WINDOW (window), widget);
6758 g_warning (G_STRLOC ": widget not within a GtkWindow");
6762 * gtk_widget_set_receives_default:
6763 * @widget: a #GtkWidget
6764 * @receives_default: whether or not @widget can be a default widget.
6766 * Specifies whether @widget will be treated as the default widget
6767 * within its toplevel when it has the focus, even if another widget
6770 * See gtk_widget_grab_default() for details about the meaning of
6776 gtk_widget_set_receives_default (GtkWidget *widget,
6777 gboolean receives_default)
6779 g_return_if_fail (GTK_IS_WIDGET (widget));
6781 if (widget->priv->receives_default != receives_default)
6783 widget->priv->receives_default = receives_default;
6785 g_object_notify (G_OBJECT (widget), "receives-default");
6790 * gtk_widget_get_receives_default:
6791 * @widget: a #GtkWidget
6793 * Determines whether @widget is alyways treated as default widget
6794 * withing its toplevel when it has the focus, even if another widget
6797 * See gtk_widget_set_receives_default().
6799 * Return value: %TRUE if @widget acts as default widget when focussed,
6805 gtk_widget_get_receives_default (GtkWidget *widget)
6807 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6809 return widget->priv->receives_default;
6813 * gtk_widget_has_grab:
6814 * @widget: a #GtkWidget
6816 * Determines whether the widget is currently grabbing events, so it
6817 * is the only widget receiving input events (keyboard and mouse).
6819 * See also gtk_grab_add().
6821 * Return value: %TRUE if the widget is in the grab_widgets stack
6826 gtk_widget_has_grab (GtkWidget *widget)
6828 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6830 return widget->priv->has_grab;
6834 _gtk_widget_set_has_grab (GtkWidget *widget,
6837 widget->priv->has_grab = has_grab;
6841 * gtk_widget_device_is_shadowed:
6842 * @widget: a #GtkWidget
6843 * @device: a #GdkDevice
6845 * Returns %TRUE if @device has been shadowed by a GTK+
6846 * device grab on another widget, so it would stop sending
6847 * events to @widget. This may be used in the
6848 * #GtkWidget::grab-notify signal to check for specific
6849 * devices. See gtk_device_grab_add().
6851 * Returns: %TRUE if there is an ongoing grab on @device
6852 * by another #GtkWidget than @widget.
6857 gtk_widget_device_is_shadowed (GtkWidget *widget,
6860 GtkWindowGroup *group;
6861 GtkWidget *grab_widget, *toplevel;
6863 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6864 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6866 if (!gtk_widget_get_realized (widget))
6869 toplevel = gtk_widget_get_toplevel (widget);
6871 if (GTK_IS_WINDOW (toplevel))
6872 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6874 group = gtk_window_get_group (NULL);
6876 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6878 /* Widget not inside the hierarchy of grab_widget */
6880 widget != grab_widget &&
6881 !gtk_widget_is_ancestor (widget, grab_widget))
6884 grab_widget = gtk_window_group_get_current_grab (group);
6885 if (grab_widget && widget != grab_widget &&
6886 !gtk_widget_is_ancestor (widget, grab_widget))
6893 * gtk_widget_set_name:
6894 * @widget: a #GtkWidget
6895 * @name: name for the widget
6897 * Widgets can be named, which allows you to refer to them from a
6898 * CSS file. You can apply a style to widgets with a particular name
6899 * in the CSS file. See the documentation for the CSS syntax (on the
6900 * same page as the docs for #GtkStyleContext).
6902 * Note that the CSS syntax has certain special characters to delimit
6903 * and represent elements in a selector (period, #, >, *...),
6904 * so using these will make your widget impossible to match by name.
6905 * Any combination of alphanumeric symbols, dashes and underscores will
6909 gtk_widget_set_name (GtkWidget *widget,
6912 GtkWidgetPrivate *priv;
6915 g_return_if_fail (GTK_IS_WIDGET (widget));
6917 priv = widget->priv;
6919 new_name = g_strdup (name);
6920 g_free (priv->name);
6921 priv->name = new_name;
6927 pos = gtk_widget_path_length (priv->path) - 1;
6928 gtk_widget_path_iter_set_name (priv->path, pos,
6933 gtk_style_context_set_path (priv->context, priv->path);
6935 g_object_notify (G_OBJECT (widget), "name");
6939 * gtk_widget_get_name:
6940 * @widget: a #GtkWidget
6942 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6943 * significance of widget names.
6945 * Return value: name of the widget. This string is owned by GTK+ and
6946 * should not be modified or freed
6948 G_CONST_RETURN gchar*
6949 gtk_widget_get_name (GtkWidget *widget)
6951 GtkWidgetPrivate *priv;
6953 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6955 priv = widget->priv;
6959 return G_OBJECT_TYPE_NAME (widget);
6963 _gtk_widget_update_state_flags (GtkWidget *widget,
6964 GtkStateFlags flags,
6967 GtkWidgetPrivate *priv;
6969 priv = widget->priv;
6971 /* Handle insensitive first, since it is propagated
6972 * differently throughout the widget hierarchy.
6974 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_UNSET))
6975 gtk_widget_set_sensitive (widget, TRUE);
6976 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation != STATE_CHANGE_UNSET))
6977 gtk_widget_set_sensitive (widget, FALSE);
6978 else if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && !(flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_REPLACE))
6979 gtk_widget_set_sensitive (widget, TRUE);
6981 if (operation != STATE_CHANGE_REPLACE)
6982 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
6985 operation == STATE_CHANGE_REPLACE)
6990 data.operation = operation;
6991 data.use_forall = FALSE;
6994 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6996 data.parent_sensitive = TRUE;
6998 gtk_widget_propagate_state (widget, &data);
7000 gtk_widget_queue_resize (widget);
7005 * gtk_widget_set_state_flags:
7006 * @widget: a #GtkWidget
7007 * @flags: State flags to turn on
7008 * @clear: Whether to clear state before turning on @flags
7010 * This function is for use in widget implementations. Turns on flag
7011 * values in the current widget state (insensitive, prelighted, etc.).
7013 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7014 * will be propagated down to all non-internal children if @widget is a
7015 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7016 * down to all #GtkContainer children by different means than turning on the
7017 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7018 * gtk_widget_is_sensitive() will make use of these.
7023 gtk_widget_set_state_flags (GtkWidget *widget,
7024 GtkStateFlags flags,
7027 g_return_if_fail (GTK_IS_WIDGET (widget));
7029 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7030 (clear && widget->priv->state_flags == flags))
7034 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7036 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
7040 * gtk_widget_unset_state_flags:
7041 * @widget: a #GtkWidget
7042 * @flags: State flags to turn off
7044 * This function is for use in widget implementations. Turns off flag
7045 * values for the current widget state (insensitive, prelighted, etc.).
7046 * See gtk_widget_set_state_flags().
7051 gtk_widget_unset_state_flags (GtkWidget *widget,
7052 GtkStateFlags flags)
7054 g_return_if_fail (GTK_IS_WIDGET (widget));
7056 if ((widget->priv->state_flags & flags) == 0)
7059 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
7063 * gtk_widget_get_state_flags:
7064 * @widget: a #GtkWidget
7066 * Returns the widget state as a flag set. It is worth mentioning
7067 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7068 * returned, that is, also based on parent insensitivity, even if
7069 * @widget itself is sensitive.
7071 * Returns: The state flags for widget
7076 gtk_widget_get_state_flags (GtkWidget *widget)
7078 GtkStateFlags flags;
7080 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7082 flags = widget->priv->state_flags;
7084 if (!gtk_widget_is_sensitive (widget))
7085 flags |= GTK_STATE_FLAG_INSENSITIVE;
7087 if (gtk_widget_has_focus (widget))
7088 flags |= GTK_STATE_FLAG_FOCUSED;
7094 * gtk_widget_set_state:
7095 * @widget: a #GtkWidget
7096 * @state: new state for @widget
7098 * This function is for use in widget implementations. Sets the state
7099 * of a widget (insensitive, prelighted, etc.) Usually you should set
7100 * the state using wrapper functions such as gtk_widget_set_sensitive().
7102 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7105 gtk_widget_set_state (GtkWidget *widget,
7108 GtkStateFlags flags;
7110 if (state == gtk_widget_get_state (widget))
7115 case GTK_STATE_ACTIVE:
7116 flags = GTK_STATE_FLAG_ACTIVE;
7118 case GTK_STATE_PRELIGHT:
7119 flags = GTK_STATE_FLAG_PRELIGHT;
7121 case GTK_STATE_SELECTED:
7122 flags = GTK_STATE_FLAG_SELECTED;
7124 case GTK_STATE_INSENSITIVE:
7125 flags = GTK_STATE_FLAG_INSENSITIVE;
7127 case GTK_STATE_INCONSISTENT:
7128 flags = GTK_STATE_FLAG_INCONSISTENT;
7130 case GTK_STATE_FOCUSED:
7131 flags = GTK_STATE_FLAG_FOCUSED;
7133 case GTK_STATE_NORMAL:
7139 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7143 * gtk_widget_get_state:
7144 * @widget: a #GtkWidget
7146 * Returns the widget's state. See gtk_widget_set_state().
7148 * Returns: the state of @widget.
7152 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7155 gtk_widget_get_state (GtkWidget *widget)
7157 GtkStateFlags flags;
7159 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7161 flags = gtk_widget_get_state_flags (widget);
7163 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7164 return GTK_STATE_INSENSITIVE;
7165 else if (flags & GTK_STATE_FLAG_ACTIVE)
7166 return GTK_STATE_ACTIVE;
7167 else if (flags & GTK_STATE_FLAG_SELECTED)
7168 return GTK_STATE_SELECTED;
7169 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7170 return GTK_STATE_PRELIGHT;
7172 return GTK_STATE_NORMAL;
7176 * gtk_widget_set_visible:
7177 * @widget: a #GtkWidget
7178 * @visible: whether the widget should be shown or not
7180 * Sets the visibility state of @widget. Note that setting this to
7181 * %TRUE doesn't mean the widget is actually viewable, see
7182 * gtk_widget_get_visible().
7184 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7185 * but is nicer to use when the visibility of the widget depends on
7191 gtk_widget_set_visible (GtkWidget *widget,
7194 g_return_if_fail (GTK_IS_WIDGET (widget));
7196 if (visible != gtk_widget_get_visible (widget))
7199 gtk_widget_show (widget);
7201 gtk_widget_hide (widget);
7206 _gtk_widget_set_visible_flag (GtkWidget *widget,
7209 widget->priv->visible = visible;
7213 * gtk_widget_get_visible:
7214 * @widget: a #GtkWidget
7216 * Determines whether the widget is visible. Note that this doesn't
7217 * take into account whether the widget's parent is also visible
7218 * or the widget is obscured in any way.
7220 * See gtk_widget_set_visible().
7222 * Return value: %TRUE if the widget is visible
7227 gtk_widget_get_visible (GtkWidget *widget)
7229 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7231 return widget->priv->visible;
7235 * gtk_widget_set_has_window:
7236 * @widget: a #GtkWidget
7237 * @has_window: whether or not @widget has a window.
7239 * Specifies whether @widget has a #GdkWindow of its own. Note that
7240 * all realized widgets have a non-%NULL "window" pointer
7241 * (gtk_widget_get_window() never returns a %NULL window when a widget
7242 * is realized), but for many of them it's actually the #GdkWindow of
7243 * one of its parent widgets. Widgets that do not create a %window for
7244 * themselves in #GtkWidget::realize must announce this by
7245 * calling this function with @has_window = %FALSE.
7247 * This function should only be called by widget implementations,
7248 * and they should call it in their init() function.
7253 gtk_widget_set_has_window (GtkWidget *widget,
7254 gboolean has_window)
7256 g_return_if_fail (GTK_IS_WIDGET (widget));
7258 widget->priv->no_window = !has_window;
7262 * gtk_widget_get_has_window:
7263 * @widget: a #GtkWidget
7265 * Determines whether @widget has a #GdkWindow of its own. See
7266 * gtk_widget_set_has_window().
7268 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7273 gtk_widget_get_has_window (GtkWidget *widget)
7275 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7277 return ! widget->priv->no_window;
7281 * gtk_widget_is_toplevel:
7282 * @widget: a #GtkWidget
7284 * Determines whether @widget is a toplevel widget.
7286 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7287 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7290 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7295 gtk_widget_is_toplevel (GtkWidget *widget)
7297 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7299 return widget->priv->toplevel;
7303 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7304 gboolean is_toplevel)
7306 widget->priv->toplevel = is_toplevel;
7310 * gtk_widget_is_drawable:
7311 * @widget: a #GtkWidget
7313 * Determines whether @widget can be drawn to. A widget can be drawn
7314 * to if it is mapped and visible.
7316 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7321 gtk_widget_is_drawable (GtkWidget *widget)
7323 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7325 return (gtk_widget_get_visible (widget) &&
7326 gtk_widget_get_mapped (widget));
7330 * gtk_widget_get_realized:
7331 * @widget: a #GtkWidget
7333 * Determines whether @widget is realized.
7335 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7340 gtk_widget_get_realized (GtkWidget *widget)
7342 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7344 return widget->priv->realized;
7348 * gtk_widget_set_realized:
7349 * @widget: a #GtkWidget
7350 * @realized: %TRUE to mark the widget as realized
7352 * Marks the widget as being realized.
7354 * This function should only ever be called in a derived widget's
7355 * "realize" or "unrealize" implementation.
7360 gtk_widget_set_realized (GtkWidget *widget,
7363 g_return_if_fail (GTK_IS_WIDGET (widget));
7365 widget->priv->realized = realized;
7369 * gtk_widget_get_mapped:
7370 * @widget: a #GtkWidget
7372 * Whether the widget is mapped.
7374 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7379 gtk_widget_get_mapped (GtkWidget *widget)
7381 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7383 return widget->priv->mapped;
7387 * gtk_widget_set_mapped:
7388 * @widget: a #GtkWidget
7389 * @mapped: %TRUE to mark the widget as mapped
7391 * Marks the widget as being realized.
7393 * This function should only ever be called in a derived widget's
7394 * "map" or "unmap" implementation.
7399 gtk_widget_set_mapped (GtkWidget *widget,
7402 g_return_if_fail (GTK_IS_WIDGET (widget));
7404 widget->priv->mapped = mapped;
7408 * gtk_widget_set_app_paintable:
7409 * @widget: a #GtkWidget
7410 * @app_paintable: %TRUE if the application will paint on the widget
7412 * Sets whether the application intends to draw on the widget in
7413 * an #GtkWidget::draw handler.
7415 * This is a hint to the widget and does not affect the behavior of
7416 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7417 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7418 * the effect is to suppress default themed drawing of the widget's
7419 * background. (Children of the widget will still be drawn.) The application
7420 * is then entirely responsible for drawing the widget background.
7422 * Note that the background is still drawn when the widget is mapped.
7425 gtk_widget_set_app_paintable (GtkWidget *widget,
7426 gboolean app_paintable)
7428 g_return_if_fail (GTK_IS_WIDGET (widget));
7430 app_paintable = (app_paintable != FALSE);
7432 if (widget->priv->app_paintable != app_paintable)
7434 widget->priv->app_paintable = app_paintable;
7436 if (gtk_widget_is_drawable (widget))
7437 gtk_widget_queue_draw (widget);
7439 g_object_notify (G_OBJECT (widget), "app-paintable");
7444 * gtk_widget_get_app_paintable:
7445 * @widget: a #GtkWidget
7447 * Determines whether the application intends to draw on the widget in
7448 * an #GtkWidget::draw handler.
7450 * See gtk_widget_set_app_paintable()
7452 * Return value: %TRUE if the widget is app paintable
7457 gtk_widget_get_app_paintable (GtkWidget *widget)
7459 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7461 return widget->priv->app_paintable;
7465 * gtk_widget_set_double_buffered:
7466 * @widget: a #GtkWidget
7467 * @double_buffered: %TRUE to double-buffer a widget
7469 * Widgets are double buffered by default; you can use this function
7470 * to turn off the buffering. "Double buffered" simply means that
7471 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7472 * automatically around expose events sent to the
7473 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7474 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7475 * buffer to the screen. The result is that users see the window
7476 * update in one smooth step, and don't see individual graphics
7477 * primitives being rendered.
7479 * In very simple terms, double buffered widgets don't flicker,
7480 * so you would only use this function to turn off double buffering
7481 * if you had special needs and really knew what you were doing.
7483 * Note: if you turn off double-buffering, you have to handle
7484 * expose events, since even the clearing to the background color or
7485 * pixmap will not happen automatically (as it is done in
7486 * gdk_window_begin_paint()).
7489 gtk_widget_set_double_buffered (GtkWidget *widget,
7490 gboolean double_buffered)
7492 g_return_if_fail (GTK_IS_WIDGET (widget));
7494 double_buffered = (double_buffered != FALSE);
7496 if (widget->priv->double_buffered != double_buffered)
7498 widget->priv->double_buffered = double_buffered;
7500 g_object_notify (G_OBJECT (widget), "double-buffered");
7505 * gtk_widget_get_double_buffered:
7506 * @widget: a #GtkWidget
7508 * Determines whether the widget is double buffered.
7510 * See gtk_widget_set_double_buffered()
7512 * Return value: %TRUE if the widget is double buffered
7517 gtk_widget_get_double_buffered (GtkWidget *widget)
7519 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7521 return widget->priv->double_buffered;
7525 * gtk_widget_set_redraw_on_allocate:
7526 * @widget: a #GtkWidget
7527 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7528 * when it is allocated to a new size. Otherwise, only the
7529 * new portion of the widget will be redrawn.
7531 * Sets whether the entire widget is queued for drawing when its size
7532 * allocation changes. By default, this setting is %TRUE and
7533 * the entire widget is redrawn on every size change. If your widget
7534 * leaves the upper left unchanged when made bigger, turning this
7535 * setting off will improve performance.
7537 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7538 * off all allocation on resizing: the widget will not even redraw if
7539 * its position changes; this is to allow containers that don't draw
7540 * anything to avoid excess invalidations. If you set this flag on a
7541 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7542 * you are responsible for invalidating both the old and new allocation
7543 * of the widget when the widget is moved and responsible for invalidating
7544 * regions newly when the widget increases size.
7547 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7548 gboolean redraw_on_allocate)
7550 g_return_if_fail (GTK_IS_WIDGET (widget));
7552 widget->priv->redraw_on_alloc = redraw_on_allocate;
7556 * gtk_widget_set_sensitive:
7557 * @widget: a #GtkWidget
7558 * @sensitive: %TRUE to make the widget sensitive
7560 * Sets the sensitivity of a widget. A widget is sensitive if the user
7561 * can interact with it. Insensitive widgets are "grayed out" and the
7562 * user can't interact with them. Insensitive widgets are known as
7563 * "inactive", "disabled", or "ghosted" in some other toolkits.
7566 gtk_widget_set_sensitive (GtkWidget *widget,
7569 GtkWidgetPrivate *priv;
7572 g_return_if_fail (GTK_IS_WIDGET (widget));
7574 priv = widget->priv;
7576 sensitive = (sensitive != FALSE);
7578 if (widget->priv->sensitive == sensitive)
7581 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7585 widget->priv->sensitive = TRUE;
7586 data.operation = STATE_CHANGE_UNSET;
7590 widget->priv->sensitive = FALSE;
7591 data.operation = STATE_CHANGE_SET;
7594 data.use_forall = TRUE;
7597 data.parent_sensitive = gtk_widget_is_sensitive (priv->parent);
7599 data.parent_sensitive = TRUE;
7601 gtk_widget_propagate_state (widget, &data);
7603 if (gtk_widget_is_drawable (widget))
7604 gtk_widget_queue_draw (widget);
7606 g_object_notify (G_OBJECT (widget), "sensitive");
7610 * gtk_widget_get_sensitive:
7611 * @widget: a #GtkWidget
7613 * Returns the widget's sensitivity (in the sense of returning
7614 * the value that has been set using gtk_widget_set_sensitive()).
7616 * The effective sensitivity of a widget is however determined by both its
7617 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7619 * Returns: %TRUE if the widget is sensitive
7624 gtk_widget_get_sensitive (GtkWidget *widget)
7626 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7628 return widget->priv->sensitive;
7632 * gtk_widget_is_sensitive:
7633 * @widget: a #GtkWidget
7635 * Returns the widget's effective sensitivity, which means
7636 * it is sensitive itself and also its parent widget is sensntive
7638 * Returns: %TRUE if the widget is effectively sensitive
7643 gtk_widget_is_sensitive (GtkWidget *widget)
7645 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7647 return widget->priv->sensitive && widget->priv->parent_sensitive;
7651 _gtk_widget_update_path (GtkWidget *widget)
7653 if (widget->priv->path)
7655 gtk_widget_path_free (widget->priv->path);
7656 widget->priv->path = NULL;
7659 gtk_widget_get_path (widget);
7663 * gtk_widget_set_parent:
7664 * @widget: a #GtkWidget
7665 * @parent: parent container
7667 * This function is useful only when implementing subclasses of
7669 * Sets the container as the parent of @widget, and takes care of
7670 * some details such as updating the state and style of the child
7671 * to reflect its new location. The opposite function is
7672 * gtk_widget_unparent().
7675 gtk_widget_set_parent (GtkWidget *widget,
7678 GtkStateFlags parent_flags;
7679 GtkWidgetPrivate *priv;
7682 g_return_if_fail (GTK_IS_WIDGET (widget));
7683 g_return_if_fail (GTK_IS_WIDGET (parent));
7684 g_return_if_fail (widget != parent);
7686 priv = widget->priv;
7688 if (priv->parent != NULL)
7690 g_warning ("Can't set a parent on widget which has a parent\n");
7693 if (gtk_widget_is_toplevel (widget))
7695 g_warning ("Can't set a parent on a toplevel widget\n");
7699 /* keep this function in sync with gtk_menu_attach_to_widget()
7702 g_object_ref_sink (widget);
7704 gtk_widget_push_verify_invariants (widget);
7706 priv->parent = parent;
7708 parent_flags = gtk_widget_get_state_flags (parent);
7710 /* Merge both old state and current parent state,
7711 * We don't want the insensitive flag to propagate
7712 * to the new child though */
7713 data.flags = parent_flags & ~GTK_STATE_FLAG_INSENSITIVE;
7714 data.flags |= priv->state_flags;
7716 data.operation = STATE_CHANGE_REPLACE;
7717 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
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_rc_styles (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 if (widget->priv->context)
7765 _gtk_widget_update_path (widget);
7766 gtk_style_context_set_path (widget->priv->context, widget->priv->path);
7768 screen = gtk_widget_get_screen (widget);
7771 gtk_style_context_set_screen (widget->priv->context, screen);
7774 gtk_widget_pop_verify_invariants (widget);
7778 * gtk_widget_get_parent:
7779 * @widget: a #GtkWidget
7781 * Returns the parent container of @widget.
7783 * Return value: (transfer none): the parent container of @widget, or %NULL
7786 gtk_widget_get_parent (GtkWidget *widget)
7788 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7790 return widget->priv->parent;
7793 /*****************************************
7795 * see docs/styles.txt
7796 *****************************************/
7799 * gtk_widget_style_attach:
7800 * @widget: a #GtkWidget
7802 * This function attaches the widget's #GtkStyle to the widget's
7803 * #GdkWindow. It is a replacement for
7806 * widget->style = gtk_style_attach (widget->style, widget->window);
7809 * and should only ever be called in a derived widget's "realize"
7810 * implementation which does not chain up to its parent class'
7811 * "realize" implementation, because one of the parent classes
7812 * (finally #GtkWidget) would attach the style itself.
7816 * Deprecated: 3.0. This step is unnecessary with #GtkStyleContext.
7819 gtk_widget_style_attach (GtkWidget *widget)
7821 GtkWidgetPrivate *priv;
7823 g_return_if_fail (GTK_IS_WIDGET (widget));
7824 g_return_if_fail (gtk_widget_get_realized (widget));
7826 priv = widget->priv;
7828 priv->style = gtk_style_attach (priv->style, priv->window);
7832 * gtk_widget_has_rc_style:
7833 * @widget: a #GtkWidget
7835 * Determines if the widget style has been looked up through the rc mechanism.
7837 * Returns: %TRUE if the widget has been looked up through the rc
7838 * mechanism, %FALSE otherwise.
7842 * Deprecated:3.0: Use #GtkStyleContext instead
7845 gtk_widget_has_rc_style (GtkWidget *widget)
7847 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7849 return widget->priv->rc_style;
7853 * gtk_widget_set_style:
7854 * @widget: a #GtkWidget
7855 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect
7856 * of a previous call to gtk_widget_set_style() and go back to
7859 * Sets the #GtkStyle for a widget (@widget->style).
7861 * You probably don't want to use this function; it interacts
7862 * badly with themes, because themes work by replacing the #GtkStyle.
7863 * Instead, use gtk_widget_modify_style().
7865 * Deprecated:3.0: Use #GtkStyleContext instead
7868 gtk_widget_set_style (GtkWidget *widget,
7871 g_return_if_fail (GTK_IS_WIDGET (widget));
7875 * gtk_widget_ensure_style:
7876 * @widget: a #GtkWidget
7878 * Ensures that @widget has a style (@widget->style).
7880 * Not a very useful function; most of the time, if you
7881 * want the style, the widget is realized, and realized
7882 * widgets are guaranteed to have a style already.
7884 * Deprecated:3.0: Use #GtkStyleContext instead
7887 gtk_widget_ensure_style (GtkWidget *widget)
7889 g_return_if_fail (GTK_IS_WIDGET (widget));
7891 if (!widget->priv->style ||
7892 widget->priv->style == gtk_widget_get_default_style ())
7896 if (widget->priv->style)
7897 g_object_unref (widget->priv->style);
7899 style = g_object_new (GTK_TYPE_STYLE,
7900 "context", gtk_widget_get_style_context (widget),
7903 widget->priv->style = g_object_ref (style);
7905 g_signal_emit (widget,
7906 widget_signals[STYLE_SET],
7909 g_object_unref (style);
7914 * gtk_widget_get_style:
7915 * @widget: a #GtkWidget
7917 * Simply an accessor function that returns @widget->style.
7919 * Return value: (transfer none): the widget's #GtkStyle
7921 * Deprecated:3.0: Use #GtkStyleContext instead
7924 gtk_widget_get_style (GtkWidget *widget)
7926 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7928 return widget->priv->style;
7932 * gtk_widget_modify_style:
7933 * @widget: a #GtkWidget
7934 * @style: the #GtkRcStyle holding the style modifications
7936 * Modifies style values on the widget.
7938 * Modifications made using this technique take precedence over
7939 * style values set via an RC file, however, they will be overridden
7940 * if a style is explicitely set on the widget using gtk_widget_set_style().
7941 * The #GtkRcStyle structure is designed so each field can either be
7942 * set or unset, so it is possible, using this function, to modify some
7943 * style values and leave the others unchanged.
7945 * Note that modifications made with this function are not cumulative
7946 * with previous calls to gtk_widget_modify_style() or with such
7947 * functions as gtk_widget_modify_fg(). If you wish to retain
7948 * previous values, you must first call gtk_widget_get_modifier_style(),
7949 * make your modifications to the returned style, then call
7950 * gtk_widget_modify_style() with that style. On the other hand,
7951 * if you first call gtk_widget_modify_style(), subsequent calls
7952 * to such functions gtk_widget_modify_fg() will have a cumulative
7953 * effect with the initial modifications.
7955 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7958 gtk_widget_modify_style (GtkWidget *widget,
7961 g_return_if_fail (GTK_IS_WIDGET (widget));
7962 g_return_if_fail (GTK_IS_RC_STYLE (style));
7964 g_object_set_qdata_full (G_OBJECT (widget),
7966 gtk_rc_style_copy (style),
7967 (GDestroyNotify) g_object_unref);
7971 * gtk_widget_get_modifier_style:
7972 * @widget: a #GtkWidget
7974 * Returns the current modifier style for the widget. (As set by
7975 * gtk_widget_modify_style().) If no style has previously set, a new
7976 * #GtkRcStyle will be created with all values unset, and set as the
7977 * modifier style for the widget. If you make changes to this rc
7978 * style, you must call gtk_widget_modify_style(), passing in the
7979 * returned rc style, to make sure that your changes take effect.
7981 * Caution: passing the style back to gtk_widget_modify_style() will
7982 * normally end up destroying it, because gtk_widget_modify_style() copies
7983 * the passed-in style and sets the copy as the new modifier style,
7984 * thus dropping any reference to the old modifier style. Add a reference
7985 * to the modifier style if you want to keep it alive.
7987 * Return value: (transfer none): the modifier style for the widget.
7988 * This rc style is owned by the widget. If you want to keep a
7989 * pointer to value this around, you must add a refcount using
7992 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7995 gtk_widget_get_modifier_style (GtkWidget *widget)
7997 GtkRcStyle *rc_style;
7999 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8001 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
8005 rc_style = gtk_rc_style_new ();
8006 g_object_set_qdata_full (G_OBJECT (widget),
8009 (GDestroyNotify) g_object_unref);
8016 gtk_widget_modify_color_component (GtkWidget *widget,
8017 GtkRcFlags component,
8019 const GdkColor *color)
8021 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
8028 rc_style->fg[state] = *color;
8031 rc_style->bg[state] = *color;
8034 rc_style->text[state] = *color;
8037 rc_style->base[state] = *color;
8040 g_assert_not_reached();
8043 rc_style->color_flags[state] |= component;
8046 rc_style->color_flags[state] &= ~component;
8048 gtk_widget_modify_style (widget, rc_style);
8052 modifier_style_changed (GtkModifierStyle *style,
8055 GtkStyleContext *context;
8057 context = gtk_widget_get_style_context (widget);
8058 gtk_style_context_invalidate (context);
8061 static GtkModifierStyle *
8062 _gtk_widget_get_modifier_properties (GtkWidget *widget)
8064 GtkModifierStyle *style;
8066 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
8068 if (G_UNLIKELY (!style))
8070 GtkStyleContext *context;
8072 style = _gtk_modifier_style_new ();
8073 g_object_set_qdata_full (G_OBJECT (widget),
8074 quark_modifier_style,
8076 (GDestroyNotify) g_object_unref);
8078 g_signal_connect (style, "changed",
8079 G_CALLBACK (modifier_style_changed), widget);
8081 context = gtk_widget_get_style_context (widget);
8083 gtk_style_context_add_provider (context,
8084 GTK_STYLE_PROVIDER (style),
8085 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
8092 * gtk_widget_override_color:
8093 * @widget: a #GtkWidget
8094 * @state: the state for which to set the color
8095 * @color: the color to assign, or %NULL to undo the effect
8096 * of previous calls to gtk_widget_override_color()
8098 * Sets the color to use for a widget.
8100 * All other style values are left untouched.
8103 * This API is mostly meant as a quick way for applications to
8104 * change a widget appearance. If you are developing a widgets
8105 * library and intend this change to be themeable, it is better
8106 * done by setting meaningful CSS classes and regions in your
8107 * widget/container implementation through gtk_style_context_add_class()
8108 * and gtk_style_context_add_region().
8110 * This way, your widget library can install a #GtkCssProvider
8111 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
8112 * to provide a default styling for those widgets that need so, and
8113 * this theming may fully overridden by the user's theme.
8116 * Note that for complex widgets this may bring in undesired
8117 * results (such as uniform background color everywhere), in
8118 * these cases it is better to fully style such widgets through a
8119 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8126 gtk_widget_override_color (GtkWidget *widget,
8127 GtkStateFlags state,
8128 const GdkRGBA *color)
8130 GtkModifierStyle *style;
8132 g_return_if_fail (GTK_IS_WIDGET (widget));
8134 style = _gtk_widget_get_modifier_properties (widget);
8135 _gtk_modifier_style_set_color (style, state, color);
8139 * gtk_widget_override_background_color:
8140 * @widget: a #GtkWidget
8141 * @state: the state for which to set the background color
8142 * @color: the color to assign, or %NULL to undo the effect
8143 * of previous calls to gtk_widget_override_background_color()
8145 * Sets the background color to use for a widget.
8147 * All other style values are left untouched.
8148 * See gtk_widget_override_color().
8153 gtk_widget_override_background_color (GtkWidget *widget,
8154 GtkStateFlags state,
8155 const GdkRGBA *color)
8157 GtkModifierStyle *style;
8159 g_return_if_fail (GTK_IS_WIDGET (widget));
8161 style = _gtk_widget_get_modifier_properties (widget);
8162 _gtk_modifier_style_set_background_color (style, state, color);
8166 * gtk_widget_override_font:
8167 * @widget: a #GtkWidget
8168 * @font_desc: the font descriptiong to use, or %NULL to undo
8169 * the effect of previous calls to gtk_widget_override_font()
8171 * Sets the font to use for a widget. All other style values are
8172 * left untouched. See gtk_widget_override_color().
8177 gtk_widget_override_font (GtkWidget *widget,
8178 const PangoFontDescription *font_desc)
8180 GtkModifierStyle *style;
8182 g_return_if_fail (GTK_IS_WIDGET (widget));
8184 style = _gtk_widget_get_modifier_properties (widget);
8185 _gtk_modifier_style_set_font (style, font_desc);
8189 * gtk_widget_override_symbolic_color:
8190 * @widget: a #GtkWidget
8191 * @name: the name of the symbolic color to modify
8192 * @color: (allow-none): the color to assign (does not need
8193 * to be allocated), or %NULL to undo the effect of previous
8194 * calls to gtk_widget_override_symbolic_color()
8196 * Sets a symbolic color for a widget.
8198 * All other style values are left untouched.
8199 * See gtk_widget_override_color() for overriding the foreground
8200 * or background color.
8205 gtk_widget_override_symbolic_color (GtkWidget *widget,
8207 const GdkRGBA *color)
8209 GtkModifierStyle *style;
8211 g_return_if_fail (GTK_IS_WIDGET (widget));
8213 style = _gtk_widget_get_modifier_properties (widget);
8214 _gtk_modifier_style_map_color (style, name, color);
8218 * gtk_widget_override_cursor:
8219 * @widget: a #GtkWidget
8220 * @cursor: the color to use for primary cursor (does not need to be
8221 * allocated), or %NULL to undo the effect of previous calls to
8222 * of gtk_widget_override_cursor().
8223 * @secondary_cursor: the color to use for secondary cursor (does not
8224 * need to be allocated), or %NULL to undo the effect of previous
8225 * calls to of gtk_widget_override_cursor().
8227 * Sets the cursor color to use in a widget, overriding the
8228 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8229 * style properties. All other style values are left untouched.
8230 * See also gtk_widget_modify_style().
8232 * Note that the underlying properties have the #GdkColor type,
8233 * so the alpha value in @primary and @secondary will be ignored.
8238 gtk_widget_override_cursor (GtkWidget *widget,
8239 const GdkRGBA *cursor,
8240 const GdkRGBA *secondary_cursor)
8242 GtkModifierStyle *style;
8244 g_return_if_fail (GTK_IS_WIDGET (widget));
8246 style = _gtk_widget_get_modifier_properties (widget);
8247 _gtk_modifier_style_set_color_property (style,
8249 "cursor-color", cursor);
8250 _gtk_modifier_style_set_color_property (style,
8252 "secondary-cursor-color",
8257 * gtk_widget_modify_fg:
8258 * @widget: a #GtkWidget
8259 * @state: the state for which to set the foreground color
8260 * @color: (allow-none): the color to assign (does not need to be allocated),
8261 * or %NULL to undo the effect of previous calls to
8262 * of gtk_widget_modify_fg().
8264 * Sets the foreground color for a widget in a particular state.
8266 * All other style values are left untouched.
8267 * See also gtk_widget_modify_style().
8269 * Deprecated:3.0: Use gtk_widget_override_color() instead
8272 gtk_widget_modify_fg (GtkWidget *widget,
8274 const GdkColor *color)
8276 GtkStateFlags flags;
8279 g_return_if_fail (GTK_IS_WIDGET (widget));
8280 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8284 case GTK_STATE_ACTIVE:
8285 flags = GTK_STATE_FLAG_ACTIVE;
8287 case GTK_STATE_PRELIGHT:
8288 flags = GTK_STATE_FLAG_PRELIGHT;
8290 case GTK_STATE_SELECTED:
8291 flags = GTK_STATE_FLAG_SELECTED;
8293 case GTK_STATE_INSENSITIVE:
8294 flags = GTK_STATE_FLAG_INSENSITIVE;
8296 case GTK_STATE_NORMAL:
8303 rgba.red = color->red / 65535.;
8304 rgba.green = color->green / 65535.;
8305 rgba.blue = color->blue / 65535.;
8308 gtk_widget_override_color (widget, flags, &rgba);
8311 gtk_widget_override_color (widget, flags, NULL);
8315 * gtk_widget_modify_bg:
8316 * @widget: a #GtkWidget
8317 * @state: the state for which to set the background color
8318 * @color: (allow-none): the color to assign (does not need
8319 * to be allocated), or %NULL to undo the effect of previous
8320 * calls to of gtk_widget_modify_bg().
8322 * Sets the background color for a widget in a particular state.
8324 * All other style values are left untouched.
8325 * See also gtk_widget_modify_style().
8328 * Note that "no window" widgets (which have the %GTK_NO_WINDOW
8329 * flag set) draw on their parent container's window and thus may
8330 * not draw any background themselves. This is the case for e.g.
8333 * To modify the background of such widgets, you have to set the
8334 * background color on their parent; if you want to set the background
8335 * of a rectangular area around a label, try placing the label in
8336 * a #GtkEventBox widget and setting the background color on that.
8339 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8342 gtk_widget_modify_bg (GtkWidget *widget,
8344 const GdkColor *color)
8346 GtkStateFlags flags;
8349 g_return_if_fail (GTK_IS_WIDGET (widget));
8350 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8354 case GTK_STATE_ACTIVE:
8355 flags = GTK_STATE_FLAG_ACTIVE;
8357 case GTK_STATE_PRELIGHT:
8358 flags = GTK_STATE_FLAG_PRELIGHT;
8360 case GTK_STATE_SELECTED:
8361 flags = GTK_STATE_FLAG_SELECTED;
8363 case GTK_STATE_INSENSITIVE:
8364 flags = GTK_STATE_FLAG_INSENSITIVE;
8366 case GTK_STATE_NORMAL:
8373 rgba.red = color->red / 65535.;
8374 rgba.green = color->green / 65535.;
8375 rgba.blue = color->blue / 65535.;
8378 gtk_widget_override_background_color (widget, flags, &rgba);
8381 gtk_widget_override_background_color (widget, flags, NULL);
8385 * gtk_widget_modify_text:
8386 * @widget: a #GtkWidget
8387 * @state: the state for which to set the text color
8388 * @color: (allow-none): the color to assign (does not need to
8389 * be allocated), or %NULL to undo the effect of previous
8390 * calls to of gtk_widget_modify_text().
8392 * Sets the text color for a widget in a particular state.
8394 * All other style values are left untouched.
8395 * The text color is the foreground color used along with the
8396 * base color (see gtk_widget_modify_base()) for widgets such
8397 * as #GtkEntry and #GtkTextView.
8398 * See also gtk_widget_modify_style().
8400 * Deprecated:3.0: Use gtk_widget_override_color() instead
8403 gtk_widget_modify_text (GtkWidget *widget,
8405 const GdkColor *color)
8407 g_return_if_fail (GTK_IS_WIDGET (widget));
8408 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8410 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
8414 * gtk_widget_modify_base:
8415 * @widget: a #GtkWidget
8416 * @state: the state for which to set the base color
8417 * @color: (allow-none): the color to assign (does not need to
8418 * be allocated), or %NULL to undo the effect of previous
8419 * calls to of gtk_widget_modify_base().
8421 * Sets the base color for a widget in a particular state.
8422 * All other style values are left untouched. The base color
8423 * is the background color used along with the text color
8424 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
8425 * and #GtkTextView. See also gtk_widget_modify_style().
8428 * Note that "no window" widgets (which have the %GTK_NO_WINDOW
8429 * flag set) draw on their parent container's window and thus may
8430 * not draw any background themselves. This is the case for e.g.
8433 * To modify the background of such widgets, you have to set the
8434 * base color on their parent; if you want to set the background
8435 * of a rectangular area around a label, try placing the label in
8436 * a #GtkEventBox widget and setting the base color on that.
8439 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8442 gtk_widget_modify_base (GtkWidget *widget,
8444 const GdkColor *color)
8446 g_return_if_fail (GTK_IS_WIDGET (widget));
8447 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8449 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
8453 * gtk_widget_modify_cursor:
8454 * @widget: a #GtkWidget
8455 * @primary: the color to use for primary cursor (does not need to be
8456 * allocated), or %NULL to undo the effect of previous calls to
8457 * of gtk_widget_modify_cursor().
8458 * @secondary: the color to use for secondary cursor (does not need to be
8459 * allocated), or %NULL to undo the effect of previous calls to
8460 * of gtk_widget_modify_cursor().
8462 * Sets the cursor color to use in a widget, overriding the
8463 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8466 * All other style values are left untouched.
8467 * See also gtk_widget_modify_style().
8471 * Deprecated: 3.0. Use gtk_widget_override_cursor() instead.
8474 gtk_widget_modify_cursor (GtkWidget *widget,
8475 const GdkColor *primary,
8476 const GdkColor *secondary)
8478 GdkRGBA primary_rgba, secondary_rgba;
8480 g_return_if_fail (GTK_IS_WIDGET (widget));
8482 primary_rgba.red = primary->red / 65535.;
8483 primary_rgba.green = primary->green / 65535.;
8484 primary_rgba.blue = primary->blue / 65535.;
8485 primary_rgba.alpha = 1;
8487 secondary_rgba.red = secondary->red / 65535.;
8488 secondary_rgba.green = secondary->green / 65535.;
8489 secondary_rgba.blue = secondary->blue / 65535.;
8490 secondary_rgba.alpha = 1;
8492 gtk_widget_override_cursor (widget, &primary_rgba, &secondary_rgba);
8496 * gtk_widget_modify_font:
8497 * @widget: a #GtkWidget
8498 * @font_desc: (allow-none): the font description to use, or %NULL
8499 * to undo the effect of previous calls to gtk_widget_modify_font()
8501 * Sets the font to use for a widget.
8503 * All other style values are left untouched.
8504 * See also gtk_widget_modify_style().
8506 * Deprecated:3.0: Use gtk_widget_override_font() instead
8509 gtk_widget_modify_font (GtkWidget *widget,
8510 PangoFontDescription *font_desc)
8512 g_return_if_fail (GTK_IS_WIDGET (widget));
8514 gtk_widget_override_font (widget, font_desc);
8518 gtk_widget_real_direction_changed (GtkWidget *widget,
8519 GtkTextDirection previous_direction)
8521 gtk_widget_queue_resize (widget);
8525 gtk_widget_real_style_set (GtkWidget *widget,
8526 GtkStyle *previous_style)
8531 GtkWidget *previous_toplevel;
8532 GdkScreen *previous_screen;
8533 GdkScreen *new_screen;
8534 } HierarchyChangedInfo;
8537 do_screen_change (GtkWidget *widget,
8538 GdkScreen *old_screen,
8539 GdkScreen *new_screen)
8541 if (old_screen != new_screen)
8543 GtkStyleContext *context;
8547 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8549 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8552 _gtk_tooltip_hide (widget);
8554 context = gtk_widget_get_style_context (widget);
8555 gtk_style_context_set_screen (context, gtk_widget_get_screen (widget));
8557 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8562 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8563 gpointer client_data)
8565 GtkWidgetPrivate *priv = widget->priv;
8566 HierarchyChangedInfo *info = client_data;
8567 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8568 (priv->parent && priv->parent->priv->anchored);
8570 if (priv->anchored != new_anchored)
8572 g_object_ref (widget);
8574 priv->anchored = new_anchored;
8576 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8577 do_screen_change (widget, info->previous_screen, info->new_screen);
8579 if (GTK_IS_CONTAINER (widget))
8580 gtk_container_forall (GTK_CONTAINER (widget),
8581 gtk_widget_propagate_hierarchy_changed_recurse,
8584 g_object_unref (widget);
8589 * _gtk_widget_propagate_hierarchy_changed:
8590 * @widget: a #GtkWidget
8591 * @previous_toplevel: Previous toplevel
8593 * Propagates changes in the anchored state to a widget and all
8594 * children, unsetting or setting the %ANCHORED flag, and
8595 * emitting #GtkWidget::hierarchy-changed.
8598 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8599 GtkWidget *previous_toplevel)
8601 GtkWidgetPrivate *priv = widget->priv;
8602 HierarchyChangedInfo info;
8604 info.previous_toplevel = previous_toplevel;
8605 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8607 if (gtk_widget_is_toplevel (widget) ||
8608 (priv->parent && priv->parent->priv->anchored))
8609 info.new_screen = gtk_widget_get_screen (widget);
8611 info.new_screen = NULL;
8613 if (info.previous_screen)
8614 g_object_ref (info.previous_screen);
8615 if (previous_toplevel)
8616 g_object_ref (previous_toplevel);
8618 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8620 if (previous_toplevel)
8621 g_object_unref (previous_toplevel);
8622 if (info.previous_screen)
8623 g_object_unref (info.previous_screen);
8627 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8628 gpointer client_data)
8630 HierarchyChangedInfo *info = client_data;
8632 g_object_ref (widget);
8634 do_screen_change (widget, info->previous_screen, info->new_screen);
8636 if (GTK_IS_CONTAINER (widget))
8637 gtk_container_forall (GTK_CONTAINER (widget),
8638 gtk_widget_propagate_screen_changed_recurse,
8641 g_object_unref (widget);
8645 * gtk_widget_is_composited:
8646 * @widget: a #GtkWidget
8648 * Whether @widget can rely on having its alpha channel
8649 * drawn correctly. On X11 this function returns whether a
8650 * compositing manager is running for @widget's screen.
8652 * Please note that the semantics of this call will change
8653 * in the future if used on a widget that has a composited
8654 * window in its hierarchy (as set by gdk_window_set_composited()).
8656 * Return value: %TRUE if the widget can rely on its alpha
8657 * channel being drawn correctly.
8662 gtk_widget_is_composited (GtkWidget *widget)
8666 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8668 screen = gtk_widget_get_screen (widget);
8670 return gdk_screen_is_composited (screen);
8674 propagate_composited_changed (GtkWidget *widget,
8677 if (GTK_IS_CONTAINER (widget))
8679 gtk_container_forall (GTK_CONTAINER (widget),
8680 propagate_composited_changed,
8684 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8688 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8690 propagate_composited_changed (widget, NULL);
8694 * _gtk_widget_propagate_screen_changed:
8695 * @widget: a #GtkWidget
8696 * @previous_screen: Previous screen
8698 * Propagates changes in the screen for a widget to all
8699 * children, emitting #GtkWidget::screen-changed.
8702 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8703 GdkScreen *previous_screen)
8705 HierarchyChangedInfo info;
8707 info.previous_screen = previous_screen;
8708 info.new_screen = gtk_widget_get_screen (widget);
8710 if (previous_screen)
8711 g_object_ref (previous_screen);
8713 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8715 if (previous_screen)
8716 g_object_unref (previous_screen);
8720 reset_style_recurse (GtkWidget *widget, gpointer data)
8722 if (widget->priv->context)
8724 _gtk_widget_update_path (widget);
8725 gtk_style_context_set_path (widget->priv->context,
8726 widget->priv->path);
8729 if (GTK_IS_CONTAINER (widget))
8730 gtk_container_forall (GTK_CONTAINER (widget),
8731 reset_style_recurse,
8736 * gtk_widget_reset_style:
8737 * @widget: a #GtkWidget
8739 * Updates the style context of @widget and all descendents
8740 * by updating its widget path. #GtkContainer<!-- -->s may want
8741 * to use this on a child when reordering it in a way that a different
8742 * style might apply to it. See also gtk_container_get_path_for_child().
8747 gtk_widget_reset_style (GtkWidget *widget)
8749 g_return_if_fail (GTK_IS_WIDGET (widget));
8751 reset_style_recurse (widget, NULL);
8755 * gtk_widget_reset_rc_styles:
8756 * @widget: a #GtkWidget.
8758 * Reset the styles of @widget and all descendents, so when
8759 * they are looked up again, they get the correct values
8760 * for the currently loaded RC file settings.
8762 * This function is not useful for applications.
8764 * Deprecated:3.0: Use #GtkStyleContext instead, and gtk_widget_reset_style()
8767 gtk_widget_reset_rc_styles (GtkWidget *widget)
8769 g_return_if_fail (GTK_IS_WIDGET (widget));
8771 reset_style_recurse (widget, NULL);
8775 * gtk_widget_get_default_style:
8777 * Returns the default style used by all widgets initially.
8779 * Returns: (transfer none): the default style. This #GtkStyle
8780 * object is owned by GTK+ and should not be modified or freed.
8782 * Deprecated:3.0: Use #GtkStyleContext instead, and
8783 * gtk_css_provider_get_default() to obtain a #GtkStyleProvider
8784 * with the default widget style information.
8787 gtk_widget_get_default_style (void)
8789 if (!gtk_default_style)
8791 gtk_default_style = gtk_style_new ();
8792 g_object_ref (gtk_default_style);
8795 return gtk_default_style;
8798 #ifdef G_ENABLE_DEBUG
8800 /* Verify invariants, see docs/widget_system.txt for notes on much of
8801 * this. Invariants may be temporarily broken while we're in the
8802 * process of updating state, of course, so you can only
8803 * verify_invariants() after a given operation is complete.
8804 * Use push/pop_verify_invariants to help with that.
8807 gtk_widget_verify_invariants (GtkWidget *widget)
8811 if (widget->priv->verifying_invariants_count > 0)
8814 parent = widget->priv->parent;
8816 if (widget->priv->mapped)
8818 /* Mapped implies ... */
8820 if (!widget->priv->realized)
8821 g_warning ("%s %p is mapped but not realized",
8822 G_OBJECT_TYPE_NAME (widget), widget);
8824 if (!widget->priv->visible)
8825 g_warning ("%s %p is mapped but not visible",
8826 G_OBJECT_TYPE_NAME (widget), widget);
8828 if (!widget->priv->toplevel)
8830 if (!widget->priv->child_visible)
8831 g_warning ("%s %p is mapped but not child_visible",
8832 G_OBJECT_TYPE_NAME (widget), widget);
8837 /* Not mapped implies... */
8840 /* This check makes sense for normal toplevels, but for
8841 * something like a toplevel that is embedded within a clutter
8842 * state, mapping may depend on external factors.
8844 if (widget->priv->toplevel)
8846 if (widget->priv->visible)
8847 g_warning ("%s %p toplevel is visible but not mapped",
8848 G_OBJECT_TYPE_NAME (widget), widget);
8853 /* Parent related checks aren't possible if parent has
8854 * verifying_invariants_count > 0 because parent needs to recurse
8855 * children first before the invariants will hold.
8857 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8860 parent->priv->realized)
8862 /* Parent realized implies... */
8865 /* This is in widget_system.txt but appears to fail
8866 * because there's no gtk_container_realize() that
8867 * realizes all children... instead we just lazily
8868 * wait for map to fix things up.
8870 if (!widget->priv->realized)
8871 g_warning ("%s %p is realized but child %s %p is not realized",
8872 G_OBJECT_TYPE_NAME (parent), parent,
8873 G_OBJECT_TYPE_NAME (widget), widget);
8876 else if (!widget->priv->toplevel)
8878 /* No parent or parent not realized on non-toplevel implies... */
8880 if (widget->priv->realized && !widget->priv->in_reparent)
8881 g_warning ("%s %p is not realized but child %s %p is realized",
8882 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8883 G_OBJECT_TYPE_NAME (widget), widget);
8887 parent->priv->mapped &&
8888 widget->priv->visible &&
8889 widget->priv->child_visible)
8891 /* Parent mapped and we are visible implies... */
8893 if (!widget->priv->mapped)
8894 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8895 G_OBJECT_TYPE_NAME (parent), parent,
8896 G_OBJECT_TYPE_NAME (widget), widget);
8898 else if (!widget->priv->toplevel)
8900 /* No parent or parent not mapped on non-toplevel implies... */
8902 if (widget->priv->mapped && !widget->priv->in_reparent)
8903 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8904 G_OBJECT_TYPE_NAME (widget), widget,
8905 widget->priv->visible,
8906 widget->priv->child_visible,
8907 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8908 parent ? parent->priv->mapped : FALSE);
8912 if (!widget->priv->realized)
8914 /* Not realized implies... */
8917 /* widget_system.txt says these hold, but they don't. */
8918 if (widget->priv->resize_pending)
8919 g_warning ("%s %p resize pending but not realized",
8920 G_OBJECT_TYPE_NAME (widget), widget);
8922 if (widget->priv->alloc_needed)
8923 g_warning ("%s %p alloc needed but not realized",
8924 G_OBJECT_TYPE_NAME (widget), widget);
8926 if (widget->priv->width_request_needed)
8927 g_warning ("%s %p width request needed but not realized",
8928 G_OBJECT_TYPE_NAME (widget), widget);
8930 if (widget->priv->height_request_needed)
8931 g_warning ("%s %p height request needed but not realized",
8932 G_OBJECT_TYPE_NAME (widget), widget);
8937 /* The point of this push/pop is that invariants may not hold while
8938 * we're busy making changes. So we only check at the outermost call
8939 * on the call stack, after we finish updating everything.
8942 gtk_widget_push_verify_invariants (GtkWidget *widget)
8944 widget->priv->verifying_invariants_count += 1;
8948 gtk_widget_verify_child_invariants (GtkWidget *widget,
8949 gpointer client_data)
8951 /* We don't recurse further; this is a one-level check. */
8952 gtk_widget_verify_invariants (widget);
8956 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8958 g_assert (widget->priv->verifying_invariants_count > 0);
8960 widget->priv->verifying_invariants_count -= 1;
8962 if (widget->priv->verifying_invariants_count == 0)
8964 gtk_widget_verify_invariants (widget);
8966 if (GTK_IS_CONTAINER (widget))
8968 /* Check one level of children, because our
8969 * push_verify_invariants() will have prevented some of the
8970 * checks. This does not recurse because if recursion is
8971 * needed, it will happen naturally as each child has a
8972 * push/pop on that child. For example if we're recursively
8973 * mapping children, we'll push/pop on each child as we map
8976 gtk_container_forall (GTK_CONTAINER (widget),
8977 gtk_widget_verify_child_invariants,
8982 #endif /* G_ENABLE_DEBUG */
8984 static PangoContext *
8985 gtk_widget_peek_pango_context (GtkWidget *widget)
8987 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8991 * gtk_widget_get_pango_context:
8992 * @widget: a #GtkWidget
8994 * Gets a #PangoContext with the appropriate font map, font description,
8995 * and base direction for this widget. Unlike the context returned
8996 * by gtk_widget_create_pango_context(), this context is owned by
8997 * the widget (it can be used until the screen for the widget changes
8998 * or the widget is removed from its toplevel), and will be updated to
8999 * match any changes to the widget's attributes.
9001 * If you create and keep a #PangoLayout using this context, you must
9002 * deal with changes to the context by calling pango_layout_context_changed()
9003 * on the layout in response to the #GtkWidget::style-updated and
9004 * #GtkWidget::direction-changed signals for the widget.
9006 * Return value: (transfer none): the #PangoContext for the widget.
9009 gtk_widget_get_pango_context (GtkWidget *widget)
9011 PangoContext *context;
9013 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9015 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
9018 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
9019 g_object_set_qdata_full (G_OBJECT (widget),
9020 quark_pango_context,
9029 update_pango_context (GtkWidget *widget,
9030 PangoContext *context)
9032 PangoFontDescription *font_desc;
9033 GtkStyleContext *style_context;
9035 style_context = gtk_widget_get_style_context (widget);
9037 gtk_style_context_get (style_context,
9038 gtk_widget_get_state_flags (widget),
9042 pango_context_set_font_description (context, font_desc);
9043 pango_context_set_base_dir (context,
9044 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
9045 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
9047 pango_font_description_free (font_desc);
9051 gtk_widget_update_pango_context (GtkWidget *widget)
9053 PangoContext *context = gtk_widget_peek_pango_context (widget);
9059 update_pango_context (widget, context);
9061 screen = gtk_widget_get_screen_unchecked (widget);
9064 pango_cairo_context_set_resolution (context,
9065 gdk_screen_get_resolution (screen));
9066 pango_cairo_context_set_font_options (context,
9067 gdk_screen_get_font_options (screen));
9073 * gtk_widget_create_pango_context:
9074 * @widget: a #GtkWidget
9076 * Creates a new #PangoContext with the appropriate font map,
9077 * font description, and base direction for drawing text for
9078 * this widget. See also gtk_widget_get_pango_context().
9080 * Return value: (transfer full): the new #PangoContext
9083 gtk_widget_create_pango_context (GtkWidget *widget)
9086 PangoContext *context;
9088 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9090 screen = gtk_widget_get_screen_unchecked (widget);
9093 GTK_NOTE (MULTIHEAD,
9094 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
9096 screen = gdk_screen_get_default ();
9099 context = gdk_pango_context_get_for_screen (screen);
9101 update_pango_context (widget, context);
9102 pango_context_set_language (context, gtk_get_default_language ());
9108 * gtk_widget_create_pango_layout:
9109 * @widget: a #GtkWidget
9110 * @text: text to set on the layout (can be %NULL)
9112 * Creates a new #PangoLayout with the appropriate font map,
9113 * font description, and base direction for drawing text for
9116 * If you keep a #PangoLayout created in this way around, in order to
9117 * notify the layout of changes to the base direction or font of this
9118 * widget, you must call pango_layout_context_changed() in response to
9119 * the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
9122 * Return value: (transfer full): the new #PangoLayout
9125 gtk_widget_create_pango_layout (GtkWidget *widget,
9128 PangoLayout *layout;
9129 PangoContext *context;
9131 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9133 context = gtk_widget_get_pango_context (widget);
9134 layout = pango_layout_new (context);
9137 pango_layout_set_text (layout, text, -1);
9143 * gtk_widget_render_icon_pixbuf:
9144 * @widget: a #GtkWidget
9145 * @stock_id: a stock ID
9146 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
9147 * render at the size of the source and don't scale (if there are
9148 * multiple source sizes, GTK+ picks one of the available sizes).
9150 * A convenience function that uses the theme engine and style
9151 * settings for @widget to look up @stock_id and render it to
9152 * a pixbuf. @stock_id should be a stock icon ID such as
9153 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
9154 * such as #GTK_ICON_SIZE_MENU.
9156 * The pixels in the returned #GdkPixbuf are shared with the rest of
9157 * the application and should not be modified. The pixbuf should be freed
9158 * after use with g_object_unref().
9160 * Return value: (transfer full): a new pixbuf, or %NULL if the
9161 * stock ID wasn't known
9166 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
9167 const gchar *stock_id,
9170 GtkStyleContext *context;
9171 GtkIconSet *icon_set;
9173 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9174 g_return_val_if_fail (stock_id != NULL, NULL);
9175 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
9177 context = gtk_widget_get_style_context (widget);
9178 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
9180 if (icon_set == NULL)
9183 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
9187 * gtk_widget_render_icon:
9188 * @widget: a #GtkWidget
9189 * @stock_id: a stock ID
9190 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
9191 * render at the size of the source and don't scale (if there are
9192 * multiple source sizes, GTK+ picks one of the available sizes).
9193 * @detail: (allow-none): render detail to pass to theme engine
9195 * A convenience function that uses the theme settings for @widget
9196 * to look up @stock_id and render it to a pixbuf. @stock_id should
9197 * be a stock icon ID such as #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size
9198 * should be a size such as #GTK_ICON_SIZE_MENU. @detail should be a
9199 * string that identifies the widget or code doing the rendering, so
9200 * that theme engines can special-case rendering for that widget or
9203 * The pixels in the returned #GdkPixbuf are shared with the rest of
9204 * the application and should not be modified. The pixbuf should be
9205 * freed after use with g_object_unref().
9207 * Return value: (transfer full): a new pixbuf, or %NULL if the
9208 * stock ID wasn't known
9210 * Deprecated: 3.0: Use gtk_widget_render_icon_pixbuf() instead.
9213 gtk_widget_render_icon (GtkWidget *widget,
9214 const gchar *stock_id,
9216 const gchar *detail)
9218 return gtk_widget_render_icon_pixbuf (widget, stock_id, size);
9222 * gtk_widget_set_parent_window:
9223 * @widget: a #GtkWidget.
9224 * @parent_window: the new parent window.
9226 * Sets a non default parent window for @widget.
9228 * For GtkWindow classes, setting a @parent_window effects whether
9229 * the window is a toplevel window or can be embedded into other
9233 * For GtkWindow classes, this needs to be called before the
9234 * window is realized.
9239 gtk_widget_set_parent_window (GtkWidget *widget,
9240 GdkWindow *parent_window)
9242 GdkWindow *old_parent_window;
9244 g_return_if_fail (GTK_IS_WIDGET (widget));
9246 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
9247 quark_parent_window);
9249 if (parent_window != old_parent_window)
9253 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
9255 if (old_parent_window)
9256 g_object_unref (old_parent_window);
9258 g_object_ref (parent_window);
9260 /* Unset toplevel flag when adding a parent window to a widget,
9261 * this is the primary entry point to allow toplevels to be
9264 #ifdef GDK_WINDOWING_X11
9265 is_plug = GTK_IS_PLUG (widget);
9269 if (GTK_IS_WINDOW (widget) && !is_plug)
9270 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
9275 * gtk_widget_get_parent_window:
9276 * @widget: a #GtkWidget.
9278 * Gets @widget's parent window.
9280 * Returns: (transfer none): the parent window of @widget.
9283 gtk_widget_get_parent_window (GtkWidget *widget)
9285 GtkWidgetPrivate *priv;
9286 GdkWindow *parent_window;
9288 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9290 priv = widget->priv;
9292 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
9294 return (parent_window != NULL) ? parent_window :
9295 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
9300 * gtk_widget_set_child_visible:
9301 * @widget: a #GtkWidget
9302 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
9304 * Sets whether @widget should be mapped along with its when its parent
9305 * is mapped and @widget has been shown with gtk_widget_show().
9307 * The child visibility can be set for widget before it is added to
9308 * a container with gtk_widget_set_parent(), to avoid mapping
9309 * children unnecessary before immediately unmapping them. However
9310 * it will be reset to its default state of %TRUE when the widget
9311 * is removed from a container.
9313 * Note that changing the child visibility of a widget does not
9314 * queue a resize on the widget. Most of the time, the size of
9315 * a widget is computed from all visible children, whether or
9316 * not they are mapped. If this is not the case, the container
9317 * can queue a resize itself.
9319 * This function is only useful for container implementations and
9320 * never should be called by an application.
9323 gtk_widget_set_child_visible (GtkWidget *widget,
9324 gboolean is_visible)
9326 GtkWidgetPrivate *priv;
9328 g_return_if_fail (GTK_IS_WIDGET (widget));
9329 g_return_if_fail (!gtk_widget_is_toplevel (widget));
9331 priv = widget->priv;
9333 g_object_ref (widget);
9334 gtk_widget_verify_invariants (widget);
9337 priv->child_visible = TRUE;
9340 GtkWidget *toplevel;
9342 priv->child_visible = FALSE;
9344 toplevel = gtk_widget_get_toplevel (widget);
9345 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
9346 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
9349 if (priv->parent && gtk_widget_get_realized (priv->parent))
9351 if (gtk_widget_get_mapped (priv->parent) &&
9352 priv->child_visible &&
9353 gtk_widget_get_visible (widget))
9354 gtk_widget_map (widget);
9356 gtk_widget_unmap (widget);
9359 gtk_widget_verify_invariants (widget);
9360 g_object_unref (widget);
9364 * gtk_widget_get_child_visible:
9365 * @widget: a #GtkWidget
9367 * Gets the value set with gtk_widget_set_child_visible().
9368 * If you feel a need to use this function, your code probably
9369 * needs reorganization.
9371 * This function is only useful for container implementations and
9372 * never should be called by an application.
9374 * Return value: %TRUE if the widget is mapped with the parent.
9377 gtk_widget_get_child_visible (GtkWidget *widget)
9379 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9381 return widget->priv->child_visible;
9385 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9387 GtkWidget *toplevel;
9389 toplevel = gtk_widget_get_toplevel (widget);
9391 if (gtk_widget_is_toplevel (toplevel))
9393 if (GTK_IS_WINDOW (toplevel))
9394 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9395 else if (GTK_IS_INVISIBLE (toplevel))
9396 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9403 * gtk_widget_get_screen:
9404 * @widget: a #GtkWidget
9406 * Get the #GdkScreen from the toplevel window associated with
9407 * this widget. This function can only be called after the widget
9408 * has been added to a widget hierarchy with a #GtkWindow
9411 * In general, you should only create screen specific
9412 * resources when a widget has been realized, and you should
9413 * free those resources when the widget is unrealized.
9415 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9420 gtk_widget_get_screen (GtkWidget *widget)
9424 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9426 screen = gtk_widget_get_screen_unchecked (widget);
9433 g_warning (G_STRLOC ": Can't get associated screen"
9434 " for a widget unless it is inside a toplevel GtkWindow\n"
9435 " widget type is %s associated top level type is %s",
9436 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9437 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9439 return gdk_screen_get_default ();
9444 * gtk_widget_has_screen:
9445 * @widget: a #GtkWidget
9447 * Checks whether there is a #GdkScreen is associated with
9448 * this widget. All toplevel widgets have an associated
9449 * screen, and all widgets added into a hierarchy with a toplevel
9450 * window at the top.
9452 * Return value: %TRUE if there is a #GdkScreen associcated
9458 gtk_widget_has_screen (GtkWidget *widget)
9460 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9462 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9466 * gtk_widget_get_display:
9467 * @widget: a #GtkWidget
9469 * Get the #GdkDisplay for the toplevel window associated with
9470 * this widget. This function can only be called after the widget
9471 * has been added to a widget hierarchy with a #GtkWindow at the top.
9473 * In general, you should only create display specific
9474 * resources when a widget has been realized, and you should
9475 * free those resources when the widget is unrealized.
9477 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9482 gtk_widget_get_display (GtkWidget *widget)
9484 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9486 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9490 * gtk_widget_get_root_window:
9491 * @widget: a #GtkWidget
9493 * Get the root window where this widget is located. This function can
9494 * only be called after the widget has been added to a widget
9495 * hierarchy with #GtkWindow at the top.
9497 * The root window is useful for such purposes as creating a popup
9498 * #GdkWindow associated with the window. In general, you should only
9499 * create display specific resources when a widget has been realized,
9500 * and you should free those resources when the widget is unrealized.
9502 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9507 gtk_widget_get_root_window (GtkWidget *widget)
9509 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9511 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9515 * gtk_widget_child_focus:
9516 * @widget: a #GtkWidget
9517 * @direction: direction of focus movement
9519 * This function is used by custom widget implementations; if you're
9520 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9521 * to a particular widget, and gtk_container_set_focus_chain() to
9522 * change the focus tab order. So you may want to investigate those
9523 * functions instead.
9525 * gtk_widget_child_focus() is called by containers as the user moves
9526 * around the window using keyboard shortcuts. @direction indicates
9527 * what kind of motion is taking place (up, down, left, right, tab
9528 * forward, tab backward). gtk_widget_child_focus() emits the
9529 * #GtkWidget::focus signal; widgets override the default handler
9530 * for this signal in order to implement appropriate focus behavior.
9532 * The default ::focus handler for a widget should return %TRUE if
9533 * moving in @direction left the focus on a focusable location inside
9534 * that widget, and %FALSE if moving in @direction moved the focus
9535 * outside the widget. If returning %TRUE, widgets normally
9536 * call gtk_widget_grab_focus() to place the focus accordingly;
9537 * if returning %FALSE, they don't modify the current focus location.
9539 * Return value: %TRUE if focus ended up inside @widget
9542 gtk_widget_child_focus (GtkWidget *widget,
9543 GtkDirectionType direction)
9545 gboolean return_val;
9547 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9549 if (!gtk_widget_get_visible (widget) ||
9550 !gtk_widget_is_sensitive (widget))
9553 /* child widgets must set CAN_FOCUS, containers
9554 * don't have to though.
9556 if (!GTK_IS_CONTAINER (widget) &&
9557 !gtk_widget_get_can_focus (widget))
9560 g_signal_emit (widget,
9561 widget_signals[FOCUS],
9563 direction, &return_val);
9569 * gtk_widget_keynav_failed:
9570 * @widget: a #GtkWidget
9571 * @direction: direction of focus movement
9573 * This function should be called whenever keyboard navigation within
9574 * a single widget hits a boundary. The function emits the
9575 * #GtkWidget::keynav-failed signal on the widget and its return
9576 * value should be interpreted in a way similar to the return value of
9577 * gtk_widget_child_focus():
9579 * When %TRUE is returned, stay in the widget, the failed keyboard
9580 * navigation is Ok and/or there is nowhere we can/should move the
9583 * When %FALSE is returned, the caller should continue with keyboard
9584 * navigation outside the widget, e.g. by calling
9585 * gtk_widget_child_focus() on the widget's toplevel.
9587 * The default ::keynav-failed handler returns %TRUE for
9588 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9589 * values of #GtkDirectionType, it looks at the
9590 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9591 * if the setting is %TRUE. This way the entire user interface
9592 * becomes cursor-navigatable on input devices such as mobile phones
9593 * which only have cursor keys but no tab key.
9595 * Whenever the default handler returns %TRUE, it also calls
9596 * gtk_widget_error_bell() to notify the user of the failed keyboard
9599 * A use case for providing an own implementation of ::keynav-failed
9600 * (either by connecting to it or by overriding it) would be a row of
9601 * #GtkEntry widgets where the user should be able to navigate the
9602 * entire row with the cursor keys, as e.g. known from user interfaces
9603 * that require entering license keys.
9605 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9606 * if the emitting widget should try to handle the keyboard
9607 * navigation attempt in its parent container(s).
9612 gtk_widget_keynav_failed (GtkWidget *widget,
9613 GtkDirectionType direction)
9615 gboolean return_val;
9617 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9619 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9620 direction, &return_val);
9626 * gtk_widget_error_bell:
9627 * @widget: a #GtkWidget
9629 * Notifies the user about an input-related error on this widget.
9630 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9631 * gdk_window_beep(), otherwise it does nothing.
9633 * Note that the effect of gdk_window_beep() can be configured in many
9634 * ways, depending on the windowing backend and the desktop environment
9635 * or window manager that is used.
9640 gtk_widget_error_bell (GtkWidget *widget)
9642 GtkWidgetPrivate *priv;
9643 GtkSettings* settings;
9646 g_return_if_fail (GTK_IS_WIDGET (widget));
9648 priv = widget->priv;
9650 settings = gtk_widget_get_settings (widget);
9654 g_object_get (settings,
9655 "gtk-error-bell", &beep,
9658 if (beep && priv->window)
9659 gdk_window_beep (priv->window);
9663 gtk_widget_set_usize_internal (GtkWidget *widget,
9666 GtkQueueResizeFlags flags)
9668 GtkWidgetAuxInfo *aux_info;
9669 gboolean changed = FALSE;
9671 g_object_freeze_notify (G_OBJECT (widget));
9673 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
9675 if (width > -2 && aux_info->width != width)
9677 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9678 g_object_notify (G_OBJECT (widget), "width-request");
9679 aux_info->width = width;
9682 if (height > -2 && aux_info->height != height)
9684 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9685 g_object_notify (G_OBJECT (widget), "height-request");
9686 aux_info->height = height;
9690 if (gtk_widget_get_visible (widget) && changed)
9692 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9693 gtk_widget_queue_resize (widget);
9695 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9698 g_object_thaw_notify (G_OBJECT (widget));
9702 * gtk_widget_set_size_request:
9703 * @widget: a #GtkWidget
9704 * @width: width @widget should request, or -1 to unset
9705 * @height: height @widget should request, or -1 to unset
9707 * Sets the minimum size of a widget; that is, the widget's size
9708 * request will be @width by @height. You can use this function to
9709 * force a widget to be either larger or smaller than it normally
9712 * In most cases, gtk_window_set_default_size() is a better choice for
9713 * toplevel windows than this function; setting the default size will
9714 * still allow users to shrink the window. Setting the size request
9715 * will force them to leave the window at least as large as the size
9716 * request. When dealing with window sizes,
9717 * gtk_window_set_geometry_hints() can be a useful function as well.
9719 * Note the inherent danger of setting any fixed size - themes,
9720 * translations into other languages, different fonts, and user action
9721 * can all change the appropriate size for a given widget. So, it's
9722 * basically impossible to hardcode a size that will always be
9725 * The size request of a widget is the smallest size a widget can
9726 * accept while still functioning well and drawing itself correctly.
9727 * However in some strange cases a widget may be allocated less than
9728 * its requested size, and in many cases a widget may be allocated more
9729 * space than it requested.
9731 * If the size request in a given direction is -1 (unset), then
9732 * the "natural" size request of the widget will be used instead.
9734 * Widgets can't actually be allocated a size less than 1 by 1, but
9735 * you can pass 0,0 to this function to mean "as small as possible."
9737 * The size request set here does not include any margin from the
9738 * #GtkWidget properties margin-left, margin-right, margin-top, and
9739 * margin-bottom, but it does include pretty much all other padding
9740 * or border properties set by any subclass of #GtkWidget.
9743 gtk_widget_set_size_request (GtkWidget *widget,
9747 g_return_if_fail (GTK_IS_WIDGET (widget));
9748 g_return_if_fail (width >= -1);
9749 g_return_if_fail (height >= -1);
9756 gtk_widget_set_usize_internal (widget, width, height, 0);
9761 * gtk_widget_get_size_request:
9762 * @widget: a #GtkWidget
9763 * @width: (out) (allow-none): return location for width, or %NULL
9764 * @height: (out) (allow-none): return location for height, or %NULL
9766 * Gets the size request that was explicitly set for the widget using
9767 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9768 * @height indicates that that dimension has not been set explicitly
9769 * and the natural requisition of the widget will be used intead. See
9770 * gtk_widget_set_size_request(). To get the size a widget will
9771 * actually request, call gtk_widget_get_preferred_size() instead of
9775 gtk_widget_get_size_request (GtkWidget *widget,
9779 const GtkWidgetAuxInfo *aux_info;
9781 g_return_if_fail (GTK_IS_WIDGET (widget));
9783 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9786 *width = aux_info->width;
9789 *height = aux_info->height;
9793 * _gtk_widget_override_size_request:
9794 * @widget: a #GtkWidget
9795 * @width: new forced minimum width
9796 * @height: new forced minimum height
9797 * @old_width: location to store previous forced minimum width
9798 * @old_width: location to store previous forced minumum height
9800 * Temporarily establishes a forced minimum size for a widget; this
9801 * is used by GtkWindow when calculating the size to add to the
9802 * window's geometry widget. Cached sizes for the widget and its
9803 * parents are invalidated, so that subsequent calls to the size
9804 * negotiation machinery produce the overriden result, but the
9805 * widget is not queued for relayout or redraw. The old size must
9806 * be restored with _gtk_widget_restore_size_request() or things
9810 _gtk_widget_override_size_request (GtkWidget *widget,
9816 gtk_widget_get_size_request (widget, old_width, old_height);
9817 gtk_widget_set_usize_internal (widget, width, height,
9818 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9822 * _gtk_widget_restore_size_request:
9823 * @widget: a #GtkWidget
9824 * @old_width: saved forced minimum size
9825 * @old_height: saved forced minimum size
9827 * Undoes the operation of_gtk_widget_override_size_request().
9830 _gtk_widget_restore_size_request (GtkWidget *widget,
9834 gtk_widget_set_usize_internal (widget, old_width, old_height,
9835 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9839 * gtk_widget_set_events:
9840 * @widget: a #GtkWidget
9841 * @events: event mask
9843 * Sets the event mask (see #GdkEventMask) for a widget. The event
9844 * mask determines which events a widget will receive. Keep in mind
9845 * that different widgets have different default event masks, and by
9846 * changing the event mask you may disrupt a widget's functionality,
9847 * so be careful. This function must be called while a widget is
9848 * unrealized. Consider gtk_widget_add_events() for widgets that are
9849 * already realized, or if you want to preserve the existing event
9850 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9851 * to get events on those widgets, place them inside a #GtkEventBox
9852 * and receive events on the event box.
9855 gtk_widget_set_events (GtkWidget *widget,
9858 g_return_if_fail (GTK_IS_WIDGET (widget));
9859 g_return_if_fail (!gtk_widget_get_realized (widget));
9861 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9862 GINT_TO_POINTER (events));
9863 g_object_notify (G_OBJECT (widget), "events");
9867 * gtk_widget_set_device_events:
9868 * @widget: a #GtkWidget
9869 * @device: a #GdkDevice
9870 * @events: event mask
9872 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9873 * mask determines which events a widget will receive from @device. Keep
9874 * in mind that different widgets have different default event masks, and by
9875 * changing the event mask you may disrupt a widget's functionality,
9876 * so be careful. This function must be called while a widget is
9877 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9878 * already realized, or if you want to preserve the existing event
9879 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9880 * to get events on those widgets, place them inside a #GtkEventBox
9881 * and receive events on the event box.
9886 gtk_widget_set_device_events (GtkWidget *widget,
9888 GdkEventMask events)
9890 GHashTable *device_events;
9892 g_return_if_fail (GTK_IS_WIDGET (widget));
9893 g_return_if_fail (GDK_IS_DEVICE (device));
9894 g_return_if_fail (!gtk_widget_get_realized (widget));
9896 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9898 if (G_UNLIKELY (!device_events))
9900 device_events = g_hash_table_new (NULL, NULL);
9901 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9902 (GDestroyNotify) g_hash_table_unref);
9905 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9909 * gtk_widget_set_device_enabled:
9910 * @widget: a #GtkWidget
9911 * @device: a #GdkDevice
9912 * @enabled: whether to enable the device
9914 * Enables or disables a #GdkDevice to interact with @widget
9915 * and all its children.
9917 * It does so by descending through the #GdkWindow hierarchy
9918 * and enabling the same mask that is has for core events
9919 * (i.e. the one that gdk_window_get_events() returns).
9924 gtk_widget_set_device_enabled (GtkWidget *widget,
9928 GList *enabled_devices;
9930 g_return_if_fail (GTK_IS_WIDGET (widget));
9931 g_return_if_fail (GDK_IS_DEVICE (device));
9933 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9934 enabled_devices = g_list_append (enabled_devices, device);
9936 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9937 enabled_devices, (GDestroyNotify) g_list_free);;
9939 if (gtk_widget_get_realized (widget))
9940 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9944 * gtk_widget_get_device_enabled:
9945 * @widget: a #GtkWidget
9946 * @device: a #GdkDevice
9948 * Returns whether @device can interact with @widget and its
9949 * children. See gtk_widget_set_device_enabled().
9951 * Return value: %TRUE is @device is enabled for @widget
9956 gtk_widget_get_device_enabled (GtkWidget *widget,
9959 GList *enabled_devices;
9961 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9962 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9964 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9966 return g_list_find (enabled_devices, device) != NULL;
9970 gtk_widget_add_events_internal_list (GtkWidget *widget,
9977 for (l = window_list; l != NULL; l = l->next)
9979 GdkWindow *window = l->data;
9982 gdk_window_get_user_data (window, &user_data);
9983 if (user_data == widget)
9988 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9990 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9992 children = gdk_window_get_children (window);
9993 gtk_widget_add_events_internal_list (widget, device, events, children);
9994 g_list_free (children);
10000 gtk_widget_add_events_internal (GtkWidget *widget,
10004 GtkWidgetPrivate *priv = widget->priv;
10005 GList *window_list;
10007 if (!gtk_widget_get_has_window (widget))
10008 window_list = gdk_window_get_children (priv->window);
10010 window_list = g_list_prepend (NULL, priv->window);
10012 gtk_widget_add_events_internal_list (widget, device, events, window_list);
10014 g_list_free (window_list);
10018 * gtk_widget_add_events:
10019 * @widget: a #GtkWidget
10020 * @events: an event mask, see #GdkEventMask
10022 * Adds the events in the bitfield @events to the event mask for
10023 * @widget. See gtk_widget_set_events() for details.
10026 gtk_widget_add_events (GtkWidget *widget,
10031 g_return_if_fail (GTK_IS_WIDGET (widget));
10033 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10034 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
10035 GINT_TO_POINTER (old_events | events));
10037 if (gtk_widget_get_realized (widget))
10039 gtk_widget_add_events_internal (widget, NULL, events);
10040 gtk_widget_update_devices_mask (widget, FALSE);
10043 g_object_notify (G_OBJECT (widget), "events");
10047 * gtk_widget_add_device_events:
10048 * @widget: a #GtkWidget
10049 * @device: a #GdkDevice
10050 * @events: an event mask, see #GdkEventMask
10052 * Adds the device events in the bitfield @events to the event mask for
10053 * @widget. See gtk_widget_set_device_events() for details.
10058 gtk_widget_add_device_events (GtkWidget *widget,
10060 GdkEventMask events)
10062 GdkEventMask old_events;
10063 GHashTable *device_events;
10065 g_return_if_fail (GTK_IS_WIDGET (widget));
10066 g_return_if_fail (GDK_IS_DEVICE (device));
10068 old_events = gtk_widget_get_device_events (widget, device);
10070 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10072 if (G_UNLIKELY (!device_events))
10074 device_events = g_hash_table_new (NULL, NULL);
10075 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
10076 (GDestroyNotify) g_hash_table_unref);
10079 g_hash_table_insert (device_events, device,
10080 GUINT_TO_POINTER (old_events | events));
10082 if (gtk_widget_get_realized (widget))
10083 gtk_widget_add_events_internal (widget, device, events);
10085 g_object_notify (G_OBJECT (widget), "events");
10089 * gtk_widget_get_toplevel:
10090 * @widget: a #GtkWidget
10092 * This function returns the topmost widget in the container hierarchy
10093 * @widget is a part of. If @widget has no parent widgets, it will be
10094 * returned as the topmost widget. No reference will be added to the
10095 * returned widget; it should not be unreferenced.
10097 * Note the difference in behavior vs. gtk_widget_get_ancestor();
10098 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
10100 * %NULL if @widget wasn't inside a toplevel window, and if the
10101 * window was inside a #GtkWindow-derived widget which was in turn
10102 * inside the toplevel #GtkWindow. While the second case may
10103 * seem unlikely, it actually happens when a #GtkPlug is embedded
10104 * inside a #GtkSocket within the same application.
10106 * To reliably find the toplevel #GtkWindow, use
10107 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
10108 * is set on the result.
10110 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
10111 * if (gtk_widget_is_toplevel (toplevel))
10113 * /* Perform action on toplevel. */
10117 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
10118 * if there's no ancestor.
10121 gtk_widget_get_toplevel (GtkWidget *widget)
10123 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10125 while (widget->priv->parent)
10126 widget = widget->priv->parent;
10132 * gtk_widget_get_ancestor:
10133 * @widget: a #GtkWidget
10134 * @widget_type: ancestor type
10136 * Gets the first ancestor of @widget with type @widget_type. For example,
10137 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
10138 * the first #GtkBox that's an ancestor of @widget. No reference will be
10139 * added to the returned widget; it should not be unreferenced. See note
10140 * about checking for a toplevel #GtkWindow in the docs for
10141 * gtk_widget_get_toplevel().
10143 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
10144 * considers @widget to be an ancestor of itself.
10146 * Return value: (transfer none): the ancestor widget, or %NULL if not found
10149 gtk_widget_get_ancestor (GtkWidget *widget,
10152 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10154 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
10155 widget = widget->priv->parent;
10157 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
10164 * gtk_widget_set_visual:
10165 * @widget: a #GtkWidget
10166 * @visual: visual to be used or %NULL to unset a previous one
10168 * Sets the visual that should be used for by widget and its children for
10169 * creating #GdkWindows. The visual must be on the same #GdkScreen as
10170 * returned by gdk_widget_get_screen(), so handling the
10171 * #GtkWidget::screen-changed signal is necessary.
10173 * Setting a new @visual will not cause @widget to recreate its windows,
10174 * so you should call this function before @widget is realized.
10177 gtk_widget_set_visual (GtkWidget *widget,
10180 g_return_if_fail (GTK_IS_WIDGET (widget));
10181 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
10184 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
10187 g_object_set_qdata_full (G_OBJECT (widget),
10189 g_object_ref (visual),
10194 * gtk_widget_get_visual:
10195 * @widget: a #GtkWidget
10197 * Gets the visual that will be used to render @widget.
10199 * Return value: (transfer none): the visual for @widget
10202 gtk_widget_get_visual (GtkWidget *widget)
10208 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10210 if (gtk_widget_get_has_window (widget) &&
10211 widget->priv->window)
10212 return gdk_window_get_visual (widget->priv->window);
10214 screen = gtk_widget_get_screen (widget);
10216 for (w = widget; w != NULL; w = w->priv->parent)
10218 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
10221 if (gdk_visual_get_screen (visual) == screen)
10224 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
10225 gtk_widget_get_name (widget));
10229 return gdk_screen_get_system_visual (screen);
10233 * gtk_widget_get_settings:
10234 * @widget: a #GtkWidget
10236 * Gets the settings object holding the settings used for this widget.
10238 * Note that this function can only be called when the #GtkWidget
10239 * is attached to a toplevel, since the settings object is specific
10240 * to a particular #GdkScreen.
10242 * Return value: (transfer none): the relevant #GtkSettings object
10245 gtk_widget_get_settings (GtkWidget *widget)
10247 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10249 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
10253 * gtk_widget_get_events:
10254 * @widget: a #GtkWidget
10256 * Returns the event mask for the widget (a bitfield containing flags
10257 * from the #GdkEventMask enumeration). These are the events that the widget
10260 * Return value: event mask for @widget
10263 gtk_widget_get_events (GtkWidget *widget)
10265 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10267 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10271 * gtk_widget_get_device_events:
10272 * @widget: a #GtkWidget
10273 * @device: a #GdkDevice
10275 * Returns the events mask for the widget corresponding to an specific device. These
10276 * are the events that the widget will receive when @device operates on it.
10278 * Returns: device event mask for @widget
10283 gtk_widget_get_device_events (GtkWidget *widget,
10286 GHashTable *device_events;
10288 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10289 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
10291 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10293 if (!device_events)
10296 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
10300 * gtk_widget_get_pointer:
10301 * @widget: a #GtkWidget
10302 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
10303 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
10305 * Obtains the location of the mouse pointer in widget coordinates.
10306 * Widget coordinates are a bit odd; for historical reasons, they are
10307 * defined as @widget->window coordinates for widgets that are not
10308 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
10309 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
10312 gtk_widget_get_pointer (GtkWidget *widget,
10316 GtkWidgetPrivate *priv;
10318 g_return_if_fail (GTK_IS_WIDGET (widget));
10320 priv = widget->priv;
10327 if (gtk_widget_get_realized (widget))
10329 gdk_window_get_pointer (priv->window, x, y, NULL);
10331 if (!gtk_widget_get_has_window (widget))
10334 *x -= priv->allocation.x;
10336 *y -= priv->allocation.y;
10342 * gtk_widget_is_ancestor:
10343 * @widget: a #GtkWidget
10344 * @ancestor: another #GtkWidget
10346 * Determines whether @widget is somewhere inside @ancestor, possibly with
10347 * intermediate containers.
10349 * Return value: %TRUE if @ancestor contains @widget as a child,
10350 * grandchild, great grandchild, etc.
10353 gtk_widget_is_ancestor (GtkWidget *widget,
10354 GtkWidget *ancestor)
10356 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10357 g_return_val_if_fail (ancestor != NULL, FALSE);
10361 if (widget->priv->parent == ancestor)
10363 widget = widget->priv->parent;
10369 static GQuark quark_composite_name = 0;
10372 * gtk_widget_set_composite_name:
10373 * @widget: a #GtkWidget.
10374 * @name: the name to set
10376 * Sets a widgets composite name. The widget must be
10377 * a composite child of its parent; see gtk_widget_push_composite_child().
10380 gtk_widget_set_composite_name (GtkWidget *widget,
10383 g_return_if_fail (GTK_IS_WIDGET (widget));
10384 g_return_if_fail (widget->priv->composite_child);
10385 g_return_if_fail (name != NULL);
10387 if (!quark_composite_name)
10388 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10390 g_object_set_qdata_full (G_OBJECT (widget),
10391 quark_composite_name,
10397 * gtk_widget_get_composite_name:
10398 * @widget: a #GtkWidget
10400 * Obtains the composite name of a widget.
10402 * Returns: the composite name of @widget, or %NULL if @widget is not
10403 * a composite child. The string should be freed when it is no
10407 gtk_widget_get_composite_name (GtkWidget *widget)
10409 GtkWidgetPrivate *priv;
10411 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10413 priv = widget->priv;
10415 if (widget->priv->composite_child && priv->parent)
10416 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10423 * gtk_widget_push_composite_child:
10425 * Makes all newly-created widgets as composite children until
10426 * the corresponding gtk_widget_pop_composite_child() call.
10428 * A composite child is a child that's an implementation detail of the
10429 * container it's inside and should not be visible to people using the
10430 * container. Composite children aren't treated differently by GTK (but
10431 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10432 * builders might want to treat them in a different way.
10434 * Here is a simple example:
10436 * gtk_widget_push_composite_child ();
10437 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10438 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10439 * gtk_widget_pop_composite_child ();
10440 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10441 * GTK_WIDGET (scrolled_window));
10442 * g_object_ref (scrolled_window->hscrollbar);
10446 gtk_widget_push_composite_child (void)
10448 composite_child_stack++;
10452 * gtk_widget_pop_composite_child:
10454 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10457 gtk_widget_pop_composite_child (void)
10459 if (composite_child_stack)
10460 composite_child_stack--;
10464 gtk_widget_emit_direction_changed (GtkWidget *widget,
10465 GtkTextDirection old_dir)
10467 gtk_widget_update_pango_context (widget);
10469 if (widget->priv->context)
10470 gtk_style_context_set_direction (widget->priv->context,
10471 gtk_widget_get_direction (widget));
10473 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10477 * gtk_widget_set_direction:
10478 * @widget: a #GtkWidget
10479 * @dir: the new direction
10481 * Sets the reading direction on a particular widget. This direction
10482 * controls the primary direction for widgets containing text,
10483 * and also the direction in which the children of a container are
10484 * packed. The ability to set the direction is present in order
10485 * so that correct localization into languages with right-to-left
10486 * reading directions can be done. Generally, applications will
10487 * let the default reading direction present, except for containers
10488 * where the containers are arranged in an order that is explicitely
10489 * visual rather than logical (such as buttons for text justification).
10491 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10492 * set by gtk_widget_set_default_direction() will be used.
10495 gtk_widget_set_direction (GtkWidget *widget,
10496 GtkTextDirection dir)
10498 GtkTextDirection old_dir;
10500 g_return_if_fail (GTK_IS_WIDGET (widget));
10501 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10503 old_dir = gtk_widget_get_direction (widget);
10505 widget->priv->direction = dir;
10507 if (old_dir != gtk_widget_get_direction (widget))
10508 gtk_widget_emit_direction_changed (widget, old_dir);
10512 * gtk_widget_get_direction:
10513 * @widget: a #GtkWidget
10515 * Gets the reading direction for a particular widget. See
10516 * gtk_widget_set_direction().
10518 * Return value: the reading direction for the widget.
10521 gtk_widget_get_direction (GtkWidget *widget)
10523 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10525 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10526 return gtk_default_direction;
10528 return widget->priv->direction;
10532 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10534 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10536 g_object_ref (widget);
10538 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10539 gtk_widget_emit_direction_changed (widget, old_dir);
10541 if (GTK_IS_CONTAINER (widget))
10542 gtk_container_forall (GTK_CONTAINER (widget),
10543 gtk_widget_set_default_direction_recurse,
10546 g_object_unref (widget);
10550 * gtk_widget_set_default_direction:
10551 * @dir: the new default direction. This cannot be
10552 * %GTK_TEXT_DIR_NONE.
10554 * Sets the default reading direction for widgets where the
10555 * direction has not been explicitly set by gtk_widget_set_direction().
10558 gtk_widget_set_default_direction (GtkTextDirection dir)
10560 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10562 if (dir != gtk_default_direction)
10564 GList *toplevels, *tmp_list;
10565 GtkTextDirection old_dir = gtk_default_direction;
10567 gtk_default_direction = dir;
10569 tmp_list = toplevels = gtk_window_list_toplevels ();
10570 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10574 gtk_widget_set_default_direction_recurse (tmp_list->data,
10575 GUINT_TO_POINTER (old_dir));
10576 g_object_unref (tmp_list->data);
10577 tmp_list = tmp_list->next;
10580 g_list_free (toplevels);
10585 * gtk_widget_get_default_direction:
10587 * Obtains the current default reading direction. See
10588 * gtk_widget_set_default_direction().
10590 * Return value: the current default direction.
10593 gtk_widget_get_default_direction (void)
10595 return gtk_default_direction;
10599 gtk_widget_dispose (GObject *object)
10601 GtkWidget *widget = GTK_WIDGET (object);
10602 GtkWidgetPrivate *priv = widget->priv;
10605 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10606 else if (gtk_widget_get_visible (widget))
10607 gtk_widget_hide (widget);
10609 priv->visible = FALSE;
10610 if (gtk_widget_get_realized (widget))
10611 gtk_widget_unrealize (widget);
10613 if (!priv->in_destruction)
10615 priv->in_destruction = TRUE;
10616 g_signal_emit (object, widget_signals[DESTROY], 0);
10617 priv->in_destruction = FALSE;
10620 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10624 gtk_widget_real_destroy (GtkWidget *object)
10626 /* gtk_object_destroy() will already hold a refcount on object */
10627 GtkWidget *widget = GTK_WIDGET (object);
10628 GtkWidgetPrivate *priv = widget->priv;
10630 /* wipe accelerator closures (keep order) */
10631 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10632 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10634 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10635 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10637 gtk_grab_remove (widget);
10639 g_object_unref (priv->style);
10640 priv->style = gtk_widget_get_default_style ();
10641 g_object_ref (priv->style);
10645 gtk_widget_finalize (GObject *object)
10647 GtkWidget *widget = GTK_WIDGET (object);
10648 GtkWidgetPrivate *priv = widget->priv;
10649 GtkWidgetAuxInfo *aux_info;
10650 GtkAccessible *accessible;
10652 gtk_grab_remove (widget);
10654 g_object_unref (priv->style);
10655 priv->style = NULL;
10657 g_free (priv->name);
10659 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
10661 gtk_widget_aux_info_destroy (aux_info);
10663 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10665 g_object_unref (accessible);
10668 gtk_widget_path_free (priv->path);
10671 g_object_unref (priv->context);
10673 if (g_object_is_floating (object))
10674 g_warning ("A floating object was finalized. This means that someone\n"
10675 "called g_object_unref() on an object that had only a floating\n"
10676 "reference; the initial floating reference is not owned by anyone\n"
10677 "and must be removed with g_object_ref_sink().");
10679 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10682 /*****************************************
10683 * gtk_widget_real_map:
10688 *****************************************/
10691 gtk_widget_real_map (GtkWidget *widget)
10693 GtkWidgetPrivate *priv = widget->priv;
10695 g_assert (gtk_widget_get_realized (widget));
10697 if (!gtk_widget_get_mapped (widget))
10699 gtk_widget_set_mapped (widget, TRUE);
10701 if (gtk_widget_get_has_window (widget))
10702 gdk_window_show (priv->window);
10706 /*****************************************
10707 * gtk_widget_real_unmap:
10712 *****************************************/
10715 gtk_widget_real_unmap (GtkWidget *widget)
10717 GtkWidgetPrivate *priv = widget->priv;
10719 if (gtk_widget_get_mapped (widget))
10721 gtk_widget_set_mapped (widget, FALSE);
10723 if (gtk_widget_get_has_window (widget))
10724 gdk_window_hide (priv->window);
10728 /*****************************************
10729 * gtk_widget_real_realize:
10734 *****************************************/
10737 gtk_widget_real_realize (GtkWidget *widget)
10739 GtkWidgetPrivate *priv = widget->priv;
10741 g_assert (!gtk_widget_get_has_window (widget));
10743 gtk_widget_set_realized (widget, TRUE);
10746 priv->window = gtk_widget_get_parent_window (widget);
10747 g_object_ref (priv->window);
10749 priv->style = gtk_style_attach (priv->style, priv->window);
10752 /*****************************************
10753 * gtk_widget_real_unrealize:
10758 *****************************************/
10761 gtk_widget_real_unrealize (GtkWidget *widget)
10763 GtkWidgetPrivate *priv = widget->priv;
10765 g_assert (!widget->priv->mapped);
10767 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10770 /* We must do unrealize child widget BEFORE container widget.
10771 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10772 * So, unrealizing container widget bofore its children causes the problem
10773 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10776 if (GTK_IS_CONTAINER (widget))
10777 gtk_container_forall (GTK_CONTAINER (widget),
10778 (GtkCallback) gtk_widget_unrealize,
10781 gtk_style_detach (priv->style);
10782 if (gtk_widget_get_has_window (widget))
10784 gdk_window_set_user_data (priv->window, NULL);
10785 gdk_window_destroy (priv->window);
10786 priv->window = NULL;
10790 g_object_unref (priv->window);
10791 priv->window = NULL;
10794 gtk_selection_remove_all (widget);
10796 gtk_widget_set_realized (widget, FALSE);
10800 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10801 GtkOrientation orientation,
10802 gint *minimum_size,
10803 gint *natural_size)
10805 const GtkWidgetAuxInfo *aux_info;
10807 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10809 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10810 aux_info->width > 0)
10812 *minimum_size = MAX (*minimum_size, aux_info->width);
10814 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10815 aux_info->height > 0)
10817 *minimum_size = MAX (*minimum_size, aux_info->height);
10820 /* Fix it if set_size_request made natural size smaller than min size.
10821 * This would also silently fix broken widgets, but we warn about them
10822 * in gtksizerequest.c when calling their size request vfuncs.
10824 *natural_size = MAX (*natural_size, *minimum_size);
10826 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10828 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10829 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10833 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10834 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10839 * _gtk_widget_peek_request_cache:
10841 * Returns the address of the widget's request cache (strictly for
10842 * internal use in gtksizerequest.c)
10844 * Return value: the address of @widget's size request cache.
10847 _gtk_widget_peek_request_cache (GtkWidget *widget)
10849 /* Don't bother slowing things down with the return_if_fail guards here */
10850 return &widget->priv->requests;
10854 * _gtk_widget_set_device_window:
10855 * @widget: a #GtkWidget
10856 * @device: a #GdkDevice
10857 * @window: the new device window
10859 * Sets pointer window for @widget and @device.
10860 * Does not ref @window.
10863 _gtk_widget_set_device_window (GtkWidget *widget,
10867 GHashTable *device_window;
10869 g_return_if_fail (GTK_IS_WIDGET (widget));
10870 g_return_if_fail (GDK_IS_DEVICE (device));
10871 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10873 if (!gtk_widget_get_mapped (widget))
10876 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10878 if (!device_window && window)
10880 device_window = g_hash_table_new (NULL, NULL);
10881 g_object_set_qdata_full (G_OBJECT (widget),
10882 quark_pointer_window,
10884 (GDestroyNotify) g_hash_table_destroy);
10888 g_hash_table_insert (device_window, device, window);
10889 else if (device_window)
10891 g_hash_table_remove (device_window, device);
10893 if (g_hash_table_size (device_window) == 0)
10894 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10899 * _gtk_widget_get_device_window:
10900 * @widget: a #GtkWidget
10901 * @device: a #GdkDevice
10903 * Return value: the device window set on @widget, or %NULL
10906 _gtk_widget_get_device_window (GtkWidget *widget,
10909 GHashTable *device_window;
10911 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10912 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10914 if (!gtk_widget_get_mapped (widget))
10917 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10919 if (!device_window)
10922 return g_hash_table_lookup (device_window, device);
10926 * _gtk_widget_list_devices:
10927 * @widget: a #GtkWidget
10929 * Returns the list of #GdkDevices that is currently on top
10930 * of any window belonging to @widget.
10931 * Free the list with g_list_free(), the elements are owned
10932 * by GTK+ and must not be freed.
10935 _gtk_widget_list_devices (GtkWidget *widget)
10937 GHashTableIter iter;
10938 GHashTable *device_window;
10939 GList *devices = NULL;
10940 gpointer key, value;
10942 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10944 if (!gtk_widget_get_mapped (widget))
10947 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10949 if (G_UNLIKELY (!device_window))
10952 g_hash_table_iter_init (&iter, device_window);
10954 while (g_hash_table_iter_next (&iter, &key, &value))
10955 devices = g_list_prepend (devices, key);
10961 synth_crossing (GtkWidget *widget,
10965 GdkCrossingMode mode,
10966 GdkNotifyType detail)
10970 event = gdk_event_new (type);
10972 event->crossing.window = g_object_ref (window);
10973 event->crossing.send_event = TRUE;
10974 event->crossing.subwindow = g_object_ref (window);
10975 event->crossing.time = GDK_CURRENT_TIME;
10976 event->crossing.x = event->crossing.y = 0;
10977 event->crossing.x_root = event->crossing.y_root = 0;
10978 event->crossing.mode = mode;
10979 event->crossing.detail = detail;
10980 event->crossing.focus = FALSE;
10981 event->crossing.state = 0;
10982 gdk_event_set_device (event, device);
10985 widget = gtk_get_event_widget (event);
10988 gtk_widget_event_internal (widget, event);
10990 gdk_event_free (event);
10994 * _gtk_widget_synthesize_crossing:
10995 * @from: the #GtkWidget the virtual pointer is leaving.
10996 * @to: the #GtkWidget the virtual pointer is moving to.
10997 * @mode: the #GdkCrossingMode to place on the synthesized events.
10999 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
11001 * The real pointer window is the window that most recently received an enter notify
11002 * event. Windows that don't select for crossing events can't become the real
11003 * poiner window. The real pointer widget that owns the real pointer window. The
11004 * effective pointer window is the same as the real pointer window unless the real
11005 * pointer widget is either insensitive or there is a grab on a widget that is not
11006 * an ancestor of the real pointer widget (in which case the effective pointer
11007 * window should be the root window).
11009 * When the effective pointer window is the same as the real poiner window, we
11010 * receive crossing events from the windowing system. When the effective pointer
11011 * window changes to become different from the real pointer window we synthesize
11012 * crossing events, attempting to follow X protocol rules:
11014 * When the root window becomes the effective pointer window:
11015 * - leave notify on real pointer window, detail Ancestor
11016 * - leave notify on all of its ancestors, detail Virtual
11017 * - enter notify on root window, detail Inferior
11019 * When the root window ceases to be the effective pointer window:
11020 * - leave notify on root window, detail Inferior
11021 * - enter notify on all ancestors of real pointer window, detail Virtual
11022 * - enter notify on real pointer window, detail Ancestor
11025 _gtk_widget_synthesize_crossing (GtkWidget *from,
11028 GdkCrossingMode mode)
11030 GdkWindow *from_window = NULL, *to_window = NULL;
11032 g_return_if_fail (from != NULL || to != NULL);
11036 from_window = _gtk_widget_get_device_window (from, device);
11039 from_window = from->priv->window;
11044 to_window = _gtk_widget_get_device_window (to, device);
11047 to_window = to->priv->window;
11050 if (from_window == NULL && to_window == NULL)
11052 else if (from_window != NULL && to_window == NULL)
11054 GList *from_ancestors = NULL, *list;
11055 GdkWindow *from_ancestor = from_window;
11057 while (from_ancestor != NULL)
11059 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
11060 if (from_ancestor == NULL)
11062 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
11065 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11066 device, mode, GDK_NOTIFY_ANCESTOR);
11067 for (list = g_list_last (from_ancestors); list; list = list->prev)
11069 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11070 device, mode, GDK_NOTIFY_VIRTUAL);
11073 /* XXX: enter/inferior on root window? */
11075 g_list_free (from_ancestors);
11077 else if (from_window == NULL && to_window != NULL)
11079 GList *to_ancestors = NULL, *list;
11080 GdkWindow *to_ancestor = to_window;
11082 while (to_ancestor != NULL)
11084 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
11085 if (to_ancestor == NULL)
11087 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
11090 /* XXX: leave/inferior on root window? */
11092 for (list = to_ancestors; list; list = list->next)
11094 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11095 device, mode, GDK_NOTIFY_VIRTUAL);
11097 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11098 device, mode, GDK_NOTIFY_ANCESTOR);
11100 g_list_free (to_ancestors);
11102 else if (from_window == to_window)
11106 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
11107 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
11109 while (from_ancestor != NULL || to_ancestor != NULL)
11111 if (from_ancestor != NULL)
11113 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
11114 if (from_ancestor == to_window)
11117 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
11119 if (to_ancestor != NULL)
11121 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
11122 if (to_ancestor == from_window)
11125 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
11128 if (to_ancestor == from_window)
11130 if (mode != GDK_CROSSING_GTK_UNGRAB)
11131 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11132 device, mode, GDK_NOTIFY_INFERIOR);
11133 for (list = to_ancestors; list; list = list->next)
11134 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11135 device, mode, GDK_NOTIFY_VIRTUAL);
11136 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11137 device, mode, GDK_NOTIFY_ANCESTOR);
11139 else if (from_ancestor == to_window)
11141 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11142 device, mode, GDK_NOTIFY_ANCESTOR);
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_VIRTUAL);
11148 if (mode != GDK_CROSSING_GTK_GRAB)
11149 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11150 device, mode, GDK_NOTIFY_INFERIOR);
11154 while (from_ancestors != NULL && to_ancestors != NULL
11155 && from_ancestors->data == to_ancestors->data)
11157 from_ancestors = g_list_delete_link (from_ancestors,
11159 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
11162 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11163 device, mode, GDK_NOTIFY_NONLINEAR);
11165 for (list = g_list_last (from_ancestors); list; list = list->prev)
11167 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11168 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11170 for (list = to_ancestors; list; list = list->next)
11172 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11173 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11175 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11176 device, mode, GDK_NOTIFY_NONLINEAR);
11178 g_list_free (from_ancestors);
11179 g_list_free (to_ancestors);
11184 gtk_widget_propagate_state (GtkWidget *widget,
11185 GtkStateData *data)
11187 GtkWidgetPrivate *priv = widget->priv;
11188 GtkStateFlags new_flags, old_flags = priv->state_flags;
11189 GtkStateType old_state;
11191 old_state = gtk_widget_get_state (widget);
11193 if (!priv->parent_sensitive)
11194 old_flags |= GTK_STATE_FLAG_INSENSITIVE;
11196 priv->parent_sensitive = data->parent_sensitive;
11198 switch (data->operation)
11200 case STATE_CHANGE_REPLACE:
11201 priv->state_flags = data->flags;
11203 case STATE_CHANGE_SET:
11204 priv->state_flags |= data->flags;
11206 case STATE_CHANGE_UNSET:
11207 priv->state_flags &= ~(data->flags);
11211 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
11215 window = gtk_widget_get_toplevel (widget);
11217 if (window && gtk_widget_is_toplevel (window))
11218 gtk_window_set_focus (GTK_WINDOW (window), NULL);
11221 new_flags = gtk_widget_get_state_flags (widget);
11223 if (old_flags != new_flags)
11225 g_object_ref (widget);
11227 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
11228 gtk_grab_remove (widget);
11230 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
11231 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
11233 if (!priv->shadowed)
11235 GList *event_windows = NULL;
11236 GList *devices, *d;
11238 devices = _gtk_widget_list_devices (widget);
11240 for (d = devices; d; d = d->next)
11246 window = _gtk_widget_get_device_window (widget, device);
11248 /* Do not propagate more than once to the
11249 * same window if non-multidevice aware.
11251 if (!gdk_window_get_support_multidevice (window) &&
11252 g_list_find (event_windows, window))
11255 if (!gtk_widget_is_sensitive (widget))
11256 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
11257 GDK_CROSSING_STATE_CHANGED);
11258 else if (old_flags & GTK_STATE_FLAG_INSENSITIVE)
11259 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
11260 GDK_CROSSING_STATE_CHANGED);
11262 event_windows = g_list_prepend (event_windows, window);
11265 g_list_free (event_windows);
11266 g_list_free (devices);
11269 if (GTK_IS_CONTAINER (widget))
11271 data->parent_sensitive = gtk_widget_is_sensitive (widget);
11273 /* Do not propagate focused state further */
11274 data->flags &= ~GTK_STATE_FLAG_FOCUSED;
11276 if (data->use_forall)
11277 gtk_container_forall (GTK_CONTAINER (widget),
11278 (GtkCallback) gtk_widget_propagate_state,
11281 gtk_container_foreach (GTK_CONTAINER (widget),
11282 (GtkCallback) gtk_widget_propagate_state,
11286 /* Trigger state change transitions for the widget */
11287 if (priv->context &&
11288 gtk_widget_get_mapped (widget))
11290 gint diff, flag = 1;
11292 diff = old_flags ^ new_flags;
11296 if ((diff & flag) != 0)
11300 target = ((new_flags & flag) != 0);
11301 _gtk_widget_notify_state_change (widget, flag, target);
11310 g_object_unref (widget);
11314 static const GtkWidgetAuxInfo default_aux_info = {
11322 * _gtk_widget_get_aux_info:
11323 * @widget: a #GtkWidget
11324 * @create: if %TRUE, create the structure if it doesn't exist
11326 * Get the #GtkWidgetAuxInfo structure for the widget.
11328 * Return value: the #GtkAuxInfo structure for the widget, or
11329 * %NULL if @create is %FALSE and one doesn't already exist.
11332 _gtk_widget_get_aux_info (GtkWidget *widget,
11335 GtkWidgetAuxInfo *aux_info;
11337 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
11338 if (!aux_info && create)
11340 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
11342 *aux_info = default_aux_info;
11344 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
11350 static const GtkWidgetAuxInfo*
11351 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11353 GtkWidgetAuxInfo *aux_info;
11355 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
11356 if (aux_info == NULL)
11358 return &default_aux_info;
11366 /*****************************************
11367 * gtk_widget_aux_info_destroy:
11372 *****************************************/
11375 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11377 g_slice_free (GtkWidgetAuxInfo, aux_info);
11381 * gtk_widget_shape_combine_region:
11382 * @widget: a #GtkWidget
11383 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11385 * Sets a shape for this widget's GDK window. This allows for
11386 * transparent windows etc., see gdk_window_shape_combine_region()
11387 * for more information.
11392 gtk_widget_shape_combine_region (GtkWidget *widget,
11393 cairo_region_t *region)
11395 GtkWidgetPrivate *priv;
11397 g_return_if_fail (GTK_IS_WIDGET (widget));
11398 /* set_shape doesn't work on widgets without gdk window */
11399 g_return_if_fail (gtk_widget_get_has_window (widget));
11401 priv = widget->priv;
11403 if (region == NULL)
11405 priv->has_shape_mask = FALSE;
11408 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11410 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11414 priv->has_shape_mask = TRUE;
11416 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11417 cairo_region_copy (region),
11418 (GDestroyNotify) cairo_region_destroy);
11420 /* set shape if widget has a gdk window already.
11421 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11424 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11429 * gtk_widget_input_shape_combine_region:
11430 * @widget: a #GtkWidget
11431 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11433 * Sets an input shape for this widget's GDK window. This allows for
11434 * windows which react to mouse click in a nonrectangular region, see
11435 * gdk_window_input_shape_combine_region() for more information.
11440 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11441 cairo_region_t *region)
11443 GtkWidgetPrivate *priv;
11445 g_return_if_fail (GTK_IS_WIDGET (widget));
11446 /* set_shape doesn't work on widgets without gdk window */
11447 g_return_if_fail (gtk_widget_get_has_window (widget));
11449 priv = widget->priv;
11451 if (region == NULL)
11454 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11456 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11460 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11461 cairo_region_copy (region),
11462 (GDestroyNotify) cairo_region_destroy);
11464 /* set shape if widget has a gdk window already.
11465 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11468 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11473 /* style properties
11477 * gtk_widget_class_install_style_property_parser: (skip)
11478 * @klass: a #GtkWidgetClass
11479 * @pspec: the #GParamSpec for the style property
11480 * @parser: the parser for the style property
11482 * Installs a style property on a widget class.
11485 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11487 GtkRcPropertyParser parser)
11489 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11490 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11491 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11492 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11494 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11496 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11497 G_OBJECT_CLASS_NAME (klass),
11502 g_param_spec_ref_sink (pspec);
11503 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11504 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11508 * gtk_widget_class_install_style_property:
11509 * @klass: a #GtkWidgetClass
11510 * @pspec: the #GParamSpec for the property
11512 * Installs a style property on a widget class. The parser for the
11513 * style property is determined by the value type of @pspec.
11516 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11519 GtkRcPropertyParser parser;
11521 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11522 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11524 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11526 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11530 * gtk_widget_class_find_style_property:
11531 * @klass: a #GtkWidgetClass
11532 * @property_name: the name of the style property to find
11533 * @returns: (transfer none): the #GParamSpec of the style property or
11534 * %NULL if @class has no style property with that name.
11536 * Finds a style property of a widget class by name.
11541 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11542 const gchar *property_name)
11544 g_return_val_if_fail (property_name != NULL, NULL);
11546 return g_param_spec_pool_lookup (style_property_spec_pool,
11548 G_OBJECT_CLASS_TYPE (klass),
11553 * gtk_widget_class_list_style_properties:
11554 * @klass: a #GtkWidgetClass
11555 * @n_properties: location to return the number of style properties found
11556 * @returns: (array length=n_properties) (transfer container): an
11557 * newly allocated array of #GParamSpec*. The array must be
11558 * freed with g_free().
11560 * Returns all style properties of a widget class.
11565 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11566 guint *n_properties)
11568 GParamSpec **pspecs;
11571 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11572 G_OBJECT_CLASS_TYPE (klass),
11581 * gtk_widget_style_get_property:
11582 * @widget: a #GtkWidget
11583 * @property_name: the name of a style property
11584 * @value: location to return the property value
11586 * Gets the value of a style property of @widget.
11589 gtk_widget_style_get_property (GtkWidget *widget,
11590 const gchar *property_name,
11595 g_return_if_fail (GTK_IS_WIDGET (widget));
11596 g_return_if_fail (property_name != NULL);
11597 g_return_if_fail (G_IS_VALUE (value));
11599 g_object_ref (widget);
11600 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11602 G_OBJECT_TYPE (widget),
11605 g_warning ("%s: widget class `%s' has no property named `%s'",
11607 G_OBJECT_TYPE_NAME (widget),
11611 GtkStyleContext *context;
11612 const GValue *peek_value;
11613 GtkStateFlags state;
11615 context = gtk_widget_get_style_context (widget);
11616 state = gtk_widget_get_state_flags (widget);
11618 peek_value = _gtk_style_context_peek_style_property (context,
11619 G_OBJECT_TYPE (widget),
11622 /* auto-conversion of the caller's value type
11624 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11625 g_value_copy (peek_value, value);
11626 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11627 g_value_transform (peek_value, value);
11629 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11631 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11632 G_VALUE_TYPE_NAME (value));
11634 g_object_unref (widget);
11638 * gtk_widget_style_get_valist:
11639 * @widget: a #GtkWidget
11640 * @first_property_name: the name of the first property to get
11641 * @var_args: a <type>va_list</type> of pairs of property names and
11642 * locations to return the property values, starting with the location
11643 * for @first_property_name.
11645 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11649 gtk_widget_style_get_valist (GtkWidget *widget,
11650 const gchar *first_property_name,
11653 GtkStyleContext *context;
11654 GtkStateFlags state;
11657 g_return_if_fail (GTK_IS_WIDGET (widget));
11659 g_object_ref (widget);
11660 context = gtk_widget_get_style_context (widget);
11661 state = gtk_widget_get_state_flags (widget);
11663 name = first_property_name;
11666 const GValue *peek_value;
11670 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11672 G_OBJECT_TYPE (widget),
11676 g_warning ("%s: widget class `%s' has no property named `%s'",
11678 G_OBJECT_TYPE_NAME (widget),
11682 /* style pspecs are always readable so we can spare that check here */
11684 peek_value = _gtk_style_context_peek_style_property (context,
11685 G_OBJECT_TYPE (widget),
11688 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11691 g_warning ("%s: %s", G_STRLOC, error);
11696 name = va_arg (var_args, gchar*);
11699 g_object_unref (widget);
11703 * gtk_widget_style_get:
11704 * @widget: a #GtkWidget
11705 * @first_property_name: the name of the first property to get
11706 * @Varargs: pairs of property names and locations to
11707 * return the property values, starting with the location for
11708 * @first_property_name, terminated by %NULL.
11710 * Gets the values of a multiple style properties of @widget.
11713 gtk_widget_style_get (GtkWidget *widget,
11714 const gchar *first_property_name,
11719 g_return_if_fail (GTK_IS_WIDGET (widget));
11721 va_start (var_args, first_property_name);
11722 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11728 * @widget: a #GtkWidget
11729 * @path_length: (out) (allow-none): location to store length of the path,
11731 * @path: (out) (allow-none): location to store allocated path string,
11733 * @path_reversed: (out) (allow-none): location to store allocated reverse
11734 * path string, or %NULL
11736 * Obtains the full path to @widget. The path is simply the name of a
11737 * widget and all its parents in the container hierarchy, separated by
11738 * periods. The name of a widget comes from
11739 * gtk_widget_get_name(). Paths are used to apply styles to a widget
11740 * in gtkrc configuration files. Widget names are the type of the
11741 * widget by default (e.g. "GtkButton") or can be set to an
11742 * application-specific value with gtk_widget_set_name(). By setting
11743 * the name of a widget, you allow users or theme authors to apply
11744 * styles to that specific widget in their gtkrc
11745 * file. @path_reversed_p fills in the path in reverse order,
11746 * i.e. starting with @widget's name instead of starting with the name
11747 * of @widget's outermost ancestor.
11749 * Deprecated:3.0: Use gtk_widget_get_path() instead
11752 gtk_widget_path (GtkWidget *widget,
11753 guint *path_length,
11755 gchar **path_reversed)
11757 static gchar *rev_path = NULL;
11758 static guint tmp_path_len = 0;
11761 g_return_if_fail (GTK_IS_WIDGET (widget));
11766 const gchar *string;
11771 string = gtk_widget_get_name (widget);
11772 l = strlen (string);
11773 while (tmp_path_len <= len + l + 1)
11775 tmp_path_len += INIT_PATH_SIZE;
11776 rev_path = g_realloc (rev_path, tmp_path_len);
11778 s = string + l - 1;
11779 d = rev_path + len;
11780 while (s >= string)
11784 widget = widget->priv->parent;
11787 rev_path[len++] = '.';
11789 rev_path[len++] = 0;
11794 *path_length = len - 1;
11796 *path_reversed = g_strdup (rev_path);
11799 *path = g_strdup (rev_path);
11800 g_strreverse (*path);
11805 * gtk_widget_class_path:
11806 * @widget: a #GtkWidget
11807 * @path_length: (out) (allow-none): location to store the length of the
11808 * class path, or %NULL
11809 * @path: (out) (allow-none): location to store the class path as an
11810 * allocated string, or %NULL
11811 * @path_reversed: (out) (allow-none): location to store the reverse
11812 * class path as an allocated string, or %NULL
11814 * Same as gtk_widget_path(), but always uses the name of a widget's type,
11815 * never uses a custom name set with gtk_widget_set_name().
11817 * Deprecated:3.0: Use gtk_widget_get_path() instead
11820 gtk_widget_class_path (GtkWidget *widget,
11821 guint *path_length,
11823 gchar **path_reversed)
11825 static gchar *rev_path = NULL;
11826 static guint tmp_path_len = 0;
11829 g_return_if_fail (GTK_IS_WIDGET (widget));
11834 const gchar *string;
11839 string = g_type_name (G_OBJECT_TYPE (widget));
11840 l = strlen (string);
11841 while (tmp_path_len <= len + l + 1)
11843 tmp_path_len += INIT_PATH_SIZE;
11844 rev_path = g_realloc (rev_path, tmp_path_len);
11846 s = string + l - 1;
11847 d = rev_path + len;
11848 while (s >= string)
11852 widget = widget->priv->parent;
11855 rev_path[len++] = '.';
11857 rev_path[len++] = 0;
11862 *path_length = len - 1;
11864 *path_reversed = g_strdup (rev_path);
11867 *path = g_strdup (rev_path);
11868 g_strreverse (*path);
11873 * gtk_requisition_new:
11875 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11877 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11878 * be freed with gtk_requisition_free().
11883 gtk_requisition_new (void)
11885 return g_slice_new0 (GtkRequisition);
11889 * gtk_requisition_copy:
11890 * @requisition: a #GtkRequisition
11892 * Copies a #GtkRequisition.
11894 * Returns: a copy of @requisition
11897 gtk_requisition_copy (const GtkRequisition *requisition)
11899 return g_slice_dup (GtkRequisition, requisition);
11903 * gtk_requisition_free:
11904 * @requisition: a #GtkRequisition
11906 * Frees a #GtkRequisition.
11909 gtk_requisition_free (GtkRequisition *requisition)
11911 g_slice_free (GtkRequisition, requisition);
11914 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11915 gtk_requisition_copy,
11916 gtk_requisition_free)
11919 * gtk_widget_get_accessible:
11920 * @widget: a #GtkWidget
11922 * Returns the accessible object that describes the widget to an
11923 * assistive technology.
11925 * If no accessibility library is loaded (i.e. no ATK implementation library is
11926 * loaded via <envar>GTK_MODULES</envar> or via another application library,
11927 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
11928 * if no class-specific #AtkObject implementation is available for the widget
11929 * instance in question, it will inherit an #AtkObject implementation from the
11930 * first ancestor class for which such an implementation is defined.
11932 * The documentation of the
11933 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
11934 * library contains more information about accessible objects and their uses.
11936 * Returns: (transfer none): the #AtkObject associated with @widget
11939 gtk_widget_get_accessible (GtkWidget *widget)
11941 GtkWidgetClass *klass;
11943 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11945 klass = GTK_WIDGET_GET_CLASS (widget);
11947 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11949 return klass->get_accessible (widget);
11953 gtk_widget_real_get_accessible (GtkWidget *widget)
11955 AtkObject* accessible;
11957 accessible = g_object_get_qdata (G_OBJECT (widget),
11958 quark_accessible_object);
11961 AtkObjectFactory *factory;
11962 AtkRegistry *default_registry;
11964 default_registry = atk_get_default_registry ();
11965 factory = atk_registry_get_factory (default_registry,
11966 G_TYPE_FROM_INSTANCE (widget));
11968 atk_object_factory_create_accessible (factory,
11969 G_OBJECT (widget));
11970 g_object_set_qdata (G_OBJECT (widget),
11971 quark_accessible_object,
11978 * Initialize a AtkImplementorIface instance's virtual pointers as
11979 * appropriate to this implementor's class (GtkWidget).
11982 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11984 iface->ref_accessible = gtk_widget_ref_accessible;
11988 gtk_widget_ref_accessible (AtkImplementor *implementor)
11990 AtkObject *accessible;
11992 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11994 g_object_ref (accessible);
11999 * Expand flag management
12003 gtk_widget_update_computed_expand (GtkWidget *widget)
12005 GtkWidgetPrivate *priv;
12007 priv = widget->priv;
12009 if (priv->need_compute_expand)
12013 if (priv->hexpand_set)
12018 if (priv->vexpand_set)
12023 /* we don't need to use compute_expand if both expands are
12024 * forced by the app
12026 if (!(priv->hexpand_set && priv->vexpand_set))
12028 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
12032 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
12033 priv->hexpand_set ? &ignored : &h,
12034 priv->vexpand_set ? &ignored : &v);
12038 priv->need_compute_expand = FALSE;
12039 priv->computed_hexpand = h != FALSE;
12040 priv->computed_vexpand = v != FALSE;
12045 * gtk_widget_queue_compute_expand:
12046 * @widget: a #GtkWidget
12048 * Mark @widget as needing to recompute its expand flags. Call
12049 * this function when setting legacy expand child properties
12050 * on the child of a container.
12052 * See gtk_widget_compute_expand().
12055 gtk_widget_queue_compute_expand (GtkWidget *widget)
12058 gboolean changed_anything;
12060 if (widget->priv->need_compute_expand)
12063 changed_anything = FALSE;
12065 while (parent != NULL)
12067 if (!parent->priv->need_compute_expand)
12069 parent->priv->need_compute_expand = TRUE;
12070 changed_anything = TRUE;
12073 /* Note: if we had an invariant that "if a child needs to
12074 * compute expand, its parents also do" then we could stop going
12075 * up when we got to a parent that already needed to
12076 * compute. However, in general we compute expand lazily (as
12077 * soon as we see something in a subtree that is expand, we know
12078 * we're expanding) and so this invariant does not hold and we
12079 * have to always walk all the way up in case some ancestor
12080 * is not currently need_compute_expand.
12083 parent = parent->priv->parent;
12086 /* recomputing expand always requires
12087 * a relayout as well
12089 if (changed_anything)
12090 gtk_widget_queue_resize (widget);
12094 * gtk_widget_compute_expand:
12095 * @widget: the widget
12096 * @orientation: expand direction
12098 * Computes whether a container should give this widget extra space
12099 * when possible. Containers should check this, rather than
12100 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
12102 * This function already checks whether the widget is visible, so
12103 * visibility does not need to be checked separately. Non-visible
12104 * widgets are not expanded.
12106 * The computed expand value uses either the expand setting explicitly
12107 * set on the widget itself, or, if none has been explicitly set,
12108 * the widget may expand if some of its children do.
12110 * Return value: whether widget tree rooted here should be expanded
12113 gtk_widget_compute_expand (GtkWidget *widget,
12114 GtkOrientation orientation)
12116 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12118 /* We never make a widget expand if not even showing. */
12119 if (!gtk_widget_get_visible (widget))
12122 gtk_widget_update_computed_expand (widget);
12124 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12126 return widget->priv->computed_hexpand;
12130 return widget->priv->computed_vexpand;
12135 gtk_widget_set_expand (GtkWidget *widget,
12136 GtkOrientation orientation,
12139 const char *expand_prop;
12140 const char *expand_set_prop;
12142 GtkWidgetPrivate *priv;
12144 g_return_if_fail (GTK_IS_WIDGET (widget));
12146 priv = widget->priv;
12148 expand = expand != FALSE;
12150 was_both = priv->hexpand && priv->vexpand;
12152 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12154 if (priv->hexpand_set &&
12155 priv->hexpand == expand)
12158 priv->hexpand_set = TRUE;
12159 priv->hexpand = expand;
12161 expand_prop = "hexpand";
12162 expand_set_prop = "hexpand-set";
12166 if (priv->vexpand_set &&
12167 priv->vexpand == expand)
12170 priv->vexpand_set = TRUE;
12171 priv->vexpand = expand;
12173 expand_prop = "vexpand";
12174 expand_set_prop = "vexpand-set";
12177 gtk_widget_queue_compute_expand (widget);
12179 g_object_freeze_notify (G_OBJECT (widget));
12180 g_object_notify (G_OBJECT (widget), expand_prop);
12181 g_object_notify (G_OBJECT (widget), expand_set_prop);
12182 if (was_both != (priv->hexpand && priv->vexpand))
12183 g_object_notify (G_OBJECT (widget), "expand");
12184 g_object_thaw_notify (G_OBJECT (widget));
12188 gtk_widget_set_expand_set (GtkWidget *widget,
12189 GtkOrientation orientation,
12192 GtkWidgetPrivate *priv;
12195 priv = widget->priv;
12197 set = set != FALSE;
12199 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12201 if (set == priv->hexpand_set)
12204 priv->hexpand_set = set;
12205 prop = "hexpand-set";
12209 if (set == priv->vexpand_set)
12212 priv->vexpand_set = set;
12213 prop = "vexpand-set";
12216 gtk_widget_queue_compute_expand (widget);
12218 g_object_notify (G_OBJECT (widget), prop);
12222 * gtk_widget_get_hexpand:
12223 * @widget: the widget
12225 * Gets whether the widget would like any available extra horizontal
12226 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12227 * generally receive the extra space. For example, a list or
12228 * scrollable area or document in your window would often be set to
12231 * Containers should use gtk_widget_compute_expand() rather than
12232 * this function, to see whether a widget, or any of its children,
12233 * has the expand flag set. If any child of a widget wants to
12234 * expand, the parent may ask to expand also.
12236 * This function only looks at the widget's own hexpand flag, rather
12237 * than computing whether the entire widget tree rooted at this widget
12240 * Return value: whether hexpand flag is set
12243 gtk_widget_get_hexpand (GtkWidget *widget)
12245 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12247 return widget->priv->hexpand;
12251 * gtk_widget_set_hexpand:
12252 * @widget: the widget
12253 * @expand: whether to expand
12255 * Sets whether the widget would like any available extra horizontal
12256 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12257 * generally receive the extra space. For example, a list or
12258 * scrollable area or document in your window would often be set to
12261 * Call this function to set the expand flag if you would like your
12262 * widget to become larger horizontally when the window has extra
12265 * By default, widgets automatically expand if any of their children
12266 * want to expand. (To see if a widget will automatically expand given
12267 * its current children and state, call gtk_widget_compute_expand(). A
12268 * container can decide how the expandability of children affects the
12269 * expansion of the container by overriding the compute_expand virtual
12270 * method on #GtkWidget.).
12272 * Setting hexpand explicitly with this function will override the
12273 * automatic expand behavior.
12275 * This function forces the widget to expand or not to expand,
12276 * regardless of children. The override occurs because
12277 * gtk_widget_set_hexpand() sets the hexpand-set property (see
12278 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
12279 * value to be used, rather than looking at children and widget state.
12282 gtk_widget_set_hexpand (GtkWidget *widget,
12285 g_return_if_fail (GTK_IS_WIDGET (widget));
12287 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
12291 * gtk_widget_get_hexpand_set:
12292 * @widget: the widget
12294 * Gets whether gtk_widget_set_hexpand() has been used to
12295 * explicitly set the expand flag on this widget.
12297 * If hexpand is set, then it overrides any computed
12298 * expand value based on child widgets. If hexpand is not
12299 * set, then the expand value depends on whether any
12300 * children of the widget would like to expand.
12302 * There are few reasons to use this function, but it's here
12303 * for completeness and consistency.
12305 * Return value: whether hexpand has been explicitly set
12308 gtk_widget_get_hexpand_set (GtkWidget *widget)
12310 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12312 return widget->priv->hexpand_set;
12316 * gtk_widget_set_hexpand_set:
12317 * @widget: the widget
12318 * @set: value for hexpand-set property
12320 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
12323 * The hexpand-set property will be set automatically when you call
12324 * gtk_widget_set_hexpand() to set hexpand, so the most likely
12325 * reason to use this function would be to unset an explicit expand
12328 * If hexpand is set, then it overrides any computed
12329 * expand value based on child widgets. If hexpand is not
12330 * set, then the expand value depends on whether any
12331 * children of the widget would like to expand.
12333 * There are few reasons to use this function, but it's here
12334 * for completeness and consistency.
12337 gtk_widget_set_hexpand_set (GtkWidget *widget,
12340 g_return_if_fail (GTK_IS_WIDGET (widget));
12342 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
12347 * gtk_widget_get_vexpand:
12348 * @widget: the widget
12350 * Gets whether the widget would like any available extra vertical
12353 * See gtk_widget_get_hexpand() for more detail.
12355 * Return value: whether vexpand flag is set
12358 gtk_widget_get_vexpand (GtkWidget *widget)
12360 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12362 return widget->priv->vexpand;
12366 * gtk_widget_set_vexpand:
12367 * @widget: the widget
12368 * @expand: whether to expand
12370 * Sets whether the widget would like any available extra vertical
12373 * See gtk_widget_set_hexpand() for more detail.
12376 gtk_widget_set_vexpand (GtkWidget *widget,
12379 g_return_if_fail (GTK_IS_WIDGET (widget));
12381 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12385 * gtk_widget_get_vexpand_set:
12386 * @widget: the widget
12388 * Gets whether gtk_widget_set_vexpand() has been used to
12389 * explicitly set the expand flag on this widget.
12391 * See gtk_widget_get_hexpand_set() for more detail.
12393 * Return value: whether vexpand has been explicitly set
12396 gtk_widget_get_vexpand_set (GtkWidget *widget)
12398 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12400 return widget->priv->vexpand_set;
12404 * gtk_widget_set_vexpand_set:
12405 * @widget: the widget
12406 * @set: value for vexpand-set property
12408 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12411 * See gtk_widget_set_hexpand_set() for more detail.
12414 gtk_widget_set_vexpand_set (GtkWidget *widget,
12417 g_return_if_fail (GTK_IS_WIDGET (widget));
12419 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12423 * GtkBuildable implementation
12425 static GQuark quark_builder_has_default = 0;
12426 static GQuark quark_builder_has_focus = 0;
12427 static GQuark quark_builder_atk_relations = 0;
12428 static GQuark quark_builder_set_name = 0;
12431 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12433 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12434 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12435 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12436 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12438 iface->set_name = gtk_widget_buildable_set_name;
12439 iface->get_name = gtk_widget_buildable_get_name;
12440 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12441 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12442 iface->parser_finished = gtk_widget_buildable_parser_finished;
12443 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12444 iface->custom_finished = gtk_widget_buildable_custom_finished;
12448 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12451 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12452 g_strdup (name), g_free);
12455 static const gchar *
12456 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12458 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12462 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12463 GtkBuilder *builder,
12464 const gchar *childname)
12466 if (strcmp (childname, "accessible") == 0)
12467 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12473 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12474 GtkBuilder *builder,
12476 const GValue *value)
12478 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12479 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12480 GINT_TO_POINTER (TRUE));
12481 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12482 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12483 GINT_TO_POINTER (TRUE));
12485 g_object_set_property (G_OBJECT (buildable), name, value);
12490 gchar *action_name;
12491 GString *description;
12493 gboolean translatable;
12503 free_action (AtkActionData *data, gpointer user_data)
12505 g_free (data->action_name);
12506 g_string_free (data->description, TRUE);
12507 g_free (data->context);
12508 g_slice_free (AtkActionData, data);
12512 free_relation (AtkRelationData *data, gpointer user_data)
12514 g_free (data->target);
12515 g_free (data->type);
12516 g_slice_free (AtkRelationData, data);
12520 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12521 GtkBuilder *builder)
12523 GSList *atk_relations;
12525 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12526 gtk_widget_grab_default (GTK_WIDGET (buildable));
12527 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12528 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12530 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12531 quark_builder_atk_relations);
12534 AtkObject *accessible;
12535 AtkRelationSet *relation_set;
12538 AtkRelationType relation_type;
12539 AtkObject *target_accessible;
12541 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12542 relation_set = atk_object_ref_relation_set (accessible);
12544 for (l = atk_relations; l; l = l->next)
12546 AtkRelationData *relation = (AtkRelationData*)l->data;
12548 target = gtk_builder_get_object (builder, relation->target);
12551 g_warning ("Target object %s in <relation> does not exist",
12555 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12556 g_assert (target_accessible != NULL);
12558 relation_type = atk_relation_type_for_name (relation->type);
12559 if (relation_type == ATK_RELATION_NULL)
12561 g_warning ("<relation> type %s not found",
12565 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12566 target_accessible);
12568 g_object_unref (relation_set);
12570 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
12571 g_slist_free (atk_relations);
12572 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12581 } AccessibilitySubParserData;
12584 accessibility_start_element (GMarkupParseContext *context,
12585 const gchar *element_name,
12586 const gchar **names,
12587 const gchar **values,
12588 gpointer user_data,
12591 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12593 gint line_number, char_number;
12595 if (strcmp (element_name, "relation") == 0)
12597 gchar *target = NULL;
12598 gchar *type = NULL;
12599 AtkRelationData *relation;
12601 for (i = 0; names[i]; i++)
12603 if (strcmp (names[i], "target") == 0)
12604 target = g_strdup (values[i]);
12605 else if (strcmp (names[i], "type") == 0)
12606 type = g_strdup (values[i]);
12609 g_markup_parse_context_get_position (context,
12612 g_set_error (error,
12614 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12615 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12617 line_number, char_number, names[i], "relation");
12624 if (!target || !type)
12626 g_markup_parse_context_get_position (context,
12629 g_set_error (error,
12631 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12632 "%s:%d:%d <%s> requires attribute \"%s\"",
12634 line_number, char_number, "relation",
12635 type ? "target" : "type");
12641 relation = g_slice_new (AtkRelationData);
12642 relation->target = target;
12643 relation->type = type;
12645 data->relations = g_slist_prepend (data->relations, relation);
12647 else if (strcmp (element_name, "action") == 0)
12649 const gchar *action_name = NULL;
12650 const gchar *description = NULL;
12651 const gchar *msg_context = NULL;
12652 gboolean translatable = FALSE;
12653 AtkActionData *action;
12655 for (i = 0; names[i]; i++)
12657 if (strcmp (names[i], "action_name") == 0)
12658 action_name = values[i];
12659 else if (strcmp (names[i], "description") == 0)
12660 description = values[i];
12661 else if (strcmp (names[i], "translatable") == 0)
12663 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12666 else if (strcmp (names[i], "comments") == 0)
12668 /* do nothing, comments are for translators */
12670 else if (strcmp (names[i], "context") == 0)
12671 msg_context = values[i];
12674 g_markup_parse_context_get_position (context,
12677 g_set_error (error,
12679 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12680 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12682 line_number, char_number, names[i], "action");
12689 g_markup_parse_context_get_position (context,
12692 g_set_error (error,
12694 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12695 "%s:%d:%d <%s> requires attribute \"%s\"",
12697 line_number, char_number, "action",
12702 action = g_slice_new (AtkActionData);
12703 action->action_name = g_strdup (action_name);
12704 action->description = g_string_new (description);
12705 action->context = g_strdup (msg_context);
12706 action->translatable = translatable;
12708 data->actions = g_slist_prepend (data->actions, action);
12710 else if (strcmp (element_name, "accessibility") == 0)
12713 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12717 accessibility_text (GMarkupParseContext *context,
12720 gpointer user_data,
12723 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12725 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12727 AtkActionData *action = data->actions->data;
12729 g_string_append_len (action->description, text, text_len);
12733 static const GMarkupParser accessibility_parser =
12735 accessibility_start_element,
12737 accessibility_text,
12746 } AccelGroupParserData;
12749 accel_group_start_element (GMarkupParseContext *context,
12750 const gchar *element_name,
12751 const gchar **names,
12752 const gchar **values,
12753 gpointer user_data,
12758 guint modifiers = 0;
12759 gchar *signal = NULL;
12760 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12762 for (i = 0; names[i]; i++)
12764 if (strcmp (names[i], "key") == 0)
12765 key = gdk_keyval_from_name (values[i]);
12766 else if (strcmp (names[i], "modifiers") == 0)
12768 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12774 else if (strcmp (names[i], "signal") == 0)
12775 signal = g_strdup (values[i]);
12778 if (key == 0 || signal == NULL)
12780 g_warning ("<accelerator> requires key and signal attributes");
12783 parser_data->key = key;
12784 parser_data->modifiers = modifiers;
12785 parser_data->signal = signal;
12788 static const GMarkupParser accel_group_parser =
12790 accel_group_start_element,
12799 style_start_element (GMarkupParseContext *context,
12800 const gchar *element_name,
12801 const gchar **names,
12802 const gchar **values,
12803 gpointer user_data,
12806 StyleParserData *style_data = (StyleParserData *)user_data;
12809 if (strcmp (element_name, "class") == 0)
12811 if (g_markup_collect_attributes (element_name,
12815 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12816 G_MARKUP_COLLECT_INVALID))
12818 style_data->classes = g_slist_append (style_data->classes, class_name);
12821 else if (strcmp (element_name, "style") == 0)
12824 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12827 static const GMarkupParser style_parser =
12829 style_start_element,
12833 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12834 GtkBuilder *builder,
12836 const gchar *tagname,
12837 GMarkupParser *parser,
12840 g_assert (buildable);
12842 if (strcmp (tagname, "accelerator") == 0)
12844 AccelGroupParserData *parser_data;
12846 parser_data = g_slice_new0 (AccelGroupParserData);
12847 parser_data->object = g_object_ref (buildable);
12848 *parser = accel_group_parser;
12849 *data = parser_data;
12852 if (strcmp (tagname, "accessibility") == 0)
12854 AccessibilitySubParserData *parser_data;
12856 parser_data = g_slice_new0 (AccessibilitySubParserData);
12857 *parser = accessibility_parser;
12858 *data = parser_data;
12861 if (strcmp (tagname, "style") == 0)
12863 StyleParserData *parser_data;
12865 parser_data = g_slice_new0 (StyleParserData);
12866 *parser = style_parser;
12867 *data = parser_data;
12875 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12876 GtkWidget *toplevel,
12877 gpointer user_data)
12879 AccelGroupParserData *accel_data;
12880 GSList *accel_groups;
12881 GtkAccelGroup *accel_group;
12883 g_return_if_fail (GTK_IS_WIDGET (widget));
12884 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12885 g_return_if_fail (user_data != NULL);
12887 accel_data = (AccelGroupParserData*)user_data;
12888 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12889 if (g_slist_length (accel_groups) == 0)
12891 accel_group = gtk_accel_group_new ();
12892 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12896 g_assert (g_slist_length (accel_groups) == 1);
12897 accel_group = g_slist_nth_data (accel_groups, 0);
12900 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12901 accel_data->signal,
12904 accel_data->modifiers,
12905 GTK_ACCEL_VISIBLE);
12907 g_object_unref (accel_data->object);
12908 g_free (accel_data->signal);
12909 g_slice_free (AccelGroupParserData, accel_data);
12913 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12914 GtkBuilder *builder,
12916 const gchar *tagname,
12917 gpointer user_data)
12919 if (strcmp (tagname, "accelerator") == 0)
12921 AccelGroupParserData *accel_data;
12922 GtkWidget *toplevel;
12924 accel_data = (AccelGroupParserData*)user_data;
12925 g_assert (accel_data->object);
12927 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12929 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12931 else if (strcmp (tagname, "accessibility") == 0)
12933 AccessibilitySubParserData *a11y_data;
12935 a11y_data = (AccessibilitySubParserData*)user_data;
12937 if (a11y_data->actions)
12939 AtkObject *accessible;
12944 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12946 if (ATK_IS_ACTION (accessible))
12948 action = ATK_ACTION (accessible);
12949 n_actions = atk_action_get_n_actions (action);
12951 for (l = a11y_data->actions; l; l = l->next)
12953 AtkActionData *action_data = (AtkActionData*)l->data;
12955 for (i = 0; i < n_actions; i++)
12956 if (strcmp (atk_action_get_name (action, i),
12957 action_data->action_name) == 0)
12962 gchar *description;
12964 if (action_data->translatable && action_data->description->len)
12965 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12966 action_data->context,
12967 action_data->description->str);
12969 description = action_data->description->str;
12971 atk_action_set_description (action, i, description);
12976 g_warning ("accessibility action on a widget that does not implement AtkAction");
12978 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
12979 g_slist_free (a11y_data->actions);
12982 if (a11y_data->relations)
12983 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12984 a11y_data->relations);
12986 g_slice_free (AccessibilitySubParserData, a11y_data);
12988 else if (strcmp (tagname, "style") == 0)
12990 StyleParserData *style_data = (StyleParserData *)user_data;
12991 GtkStyleContext *context;
12994 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
12996 for (l = style_data->classes; l; l = l->next)
12997 gtk_style_context_add_class (context, (const gchar *)l->data);
12999 g_slist_free_full (style_data->classes, g_free);
13000 g_slice_free (StyleParserData, style_data);
13004 static GtkSizeRequestMode
13005 gtk_widget_real_get_request_mode (GtkWidget *widget)
13007 /* By default widgets are height-for-width. */
13008 return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
13012 gtk_widget_real_get_width (GtkWidget *widget,
13013 gint *minimum_size,
13014 gint *natural_size)
13024 gtk_widget_real_get_height (GtkWidget *widget,
13025 gint *minimum_size,
13026 gint *natural_size)
13036 gtk_widget_real_get_height_for_width (GtkWidget *widget,
13038 gint *minimum_height,
13039 gint *natural_height)
13041 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
13045 gtk_widget_real_get_width_for_height (GtkWidget *widget,
13047 gint *minimum_width,
13048 gint *natural_width)
13050 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
13054 * gtk_widget_get_halign:
13055 * @widget: a #GtkWidget
13057 * Gets the value of the #GtkWidget:halign property.
13059 * Returns: the horizontal alignment of @widget
13062 gtk_widget_get_halign (GtkWidget *widget)
13064 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
13065 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
13069 * gtk_widget_set_halign:
13070 * @widget: a #GtkWidget
13071 * @align: the horizontal alignment
13073 * Sets the horizontal alignment of @widget.
13074 * See the #GtkWidget:halign property.
13077 gtk_widget_set_halign (GtkWidget *widget,
13080 GtkWidgetAuxInfo *aux_info;
13082 g_return_if_fail (GTK_IS_WIDGET (widget));
13084 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
13086 if (aux_info->halign == align)
13089 aux_info->halign = align;
13090 gtk_widget_queue_resize (widget);
13091 g_object_notify (G_OBJECT (widget), "halign");
13095 * gtk_widget_get_valign:
13096 * @widget: a #GtkWidget
13098 * Gets the value of the #GtkWidget:valign property.
13100 * Returns: the vertical alignment of @widget
13103 gtk_widget_get_valign (GtkWidget *widget)
13105 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
13106 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
13110 * gtk_widget_set_valign:
13111 * @widget: a #GtkWidget
13112 * @align: the vertical alignment
13114 * Sets the vertical alignment of @widget.
13115 * See the #GtkWidget:valign property.
13118 gtk_widget_set_valign (GtkWidget *widget,
13121 GtkWidgetAuxInfo *aux_info;
13123 g_return_if_fail (GTK_IS_WIDGET (widget));
13125 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
13127 if (aux_info->valign == align)
13130 aux_info->valign = align;
13131 gtk_widget_queue_resize (widget);
13132 g_object_notify (G_OBJECT (widget), "valign");
13136 * gtk_widget_get_margin_left:
13137 * @widget: a #GtkWidget
13139 * Gets the value of the #GtkWidget:margin-left property.
13141 * Returns: The left margin of @widget
13144 gtk_widget_get_margin_left (GtkWidget *widget)
13146 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13148 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
13152 * gtk_widget_set_margin_left:
13153 * @widget: a #GtkWidget
13154 * @margin: the left margin
13156 * Sets the left margin of @widget.
13157 * See the #GtkWidget:margin-left property.
13160 gtk_widget_set_margin_left (GtkWidget *widget,
13163 GtkWidgetAuxInfo *aux_info;
13165 g_return_if_fail (GTK_IS_WIDGET (widget));
13166 g_return_if_fail (margin <= G_MAXINT16);
13168 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
13170 if (aux_info->margin.left == margin)
13173 aux_info->margin.left = margin;
13174 gtk_widget_queue_resize (widget);
13175 g_object_notify (G_OBJECT (widget), "margin-left");
13179 * gtk_widget_get_margin_right:
13180 * @widget: a #GtkWidget
13182 * Gets the value of the #GtkWidget:margin-right property.
13184 * Returns: The left margin of @widget
13187 gtk_widget_get_margin_right (GtkWidget *widget)
13189 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13191 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
13195 * gtk_widget_set_margin_right:
13196 * @widget: a #GtkWidget
13197 * @margin: the right margin
13199 * Sets the right margin of @widget.
13200 * See the #GtkWidget:margin-right property.
13203 gtk_widget_set_margin_right (GtkWidget *widget,
13206 GtkWidgetAuxInfo *aux_info;
13208 g_return_if_fail (GTK_IS_WIDGET (widget));
13209 g_return_if_fail (margin <= G_MAXINT16);
13211 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
13213 if (aux_info->margin.right == margin)
13216 aux_info->margin.right = margin;
13217 gtk_widget_queue_resize (widget);
13218 g_object_notify (G_OBJECT (widget), "margin-right");
13222 * gtk_widget_get_margin_top:
13223 * @widget: a #GtkWidget
13225 * Gets the value of the #GtkWidget:margin-top property.
13227 * Returns: The top margin of @widget
13230 gtk_widget_get_margin_top (GtkWidget *widget)
13232 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13234 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
13238 * gtk_widget_set_margin_top:
13239 * @widget: a #GtkWidget
13240 * @margin: the top margin
13242 * Sets the top margin of @widget.
13243 * See the #GtkWidget:margin-top property.
13246 gtk_widget_set_margin_top (GtkWidget *widget,
13249 GtkWidgetAuxInfo *aux_info;
13251 g_return_if_fail (GTK_IS_WIDGET (widget));
13252 g_return_if_fail (margin <= G_MAXINT16);
13254 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
13256 if (aux_info->margin.top == margin)
13259 aux_info->margin.top = margin;
13260 gtk_widget_queue_resize (widget);
13261 g_object_notify (G_OBJECT (widget), "margin-top");
13265 * gtk_widget_get_margin_bottom:
13266 * @widget: a #GtkWidget
13268 * Gets the value of the #GtkWidget:margin-bottom property.
13270 * Returns: The bottom margin of @widget
13273 gtk_widget_get_margin_bottom (GtkWidget *widget)
13275 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13277 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
13281 * gtk_widget_set_margin_bottom:
13282 * @widget: a #GtkWidget
13283 * @margin: the bottom margin
13285 * Sets the bottom margin of @widget.
13286 * See the #GtkWidget:margin-bottom property.
13289 gtk_widget_set_margin_bottom (GtkWidget *widget,
13292 GtkWidgetAuxInfo *aux_info;
13294 g_return_if_fail (GTK_IS_WIDGET (widget));
13295 g_return_if_fail (margin <= G_MAXINT16);
13297 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
13299 if (aux_info->margin.bottom == margin)
13302 aux_info->margin.bottom = margin;
13303 gtk_widget_queue_resize (widget);
13304 g_object_notify (G_OBJECT (widget), "margin-bottom");
13308 * gtk_widget_get_clipboard:
13309 * @widget: a #GtkWidget
13310 * @selection: a #GdkAtom which identifies the clipboard
13311 * to use. %GDK_SELECTION_CLIPBOARD gives the
13312 * default clipboard. Another common value
13313 * is %GDK_SELECTION_PRIMARY, which gives
13314 * the primary X selection.
13316 * Returns the clipboard object for the given selection to
13317 * be used with @widget. @widget must have a #GdkDisplay
13318 * associated with it, so must be attached to a toplevel
13321 * Return value: (transfer none): the appropriate clipboard object. If no
13322 * clipboard already exists, a new one will
13323 * be created. Once a clipboard object has
13324 * been created, it is persistent for all time.
13329 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
13331 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13332 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
13334 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
13339 * gtk_widget_list_mnemonic_labels:
13340 * @widget: a #GtkWidget
13342 * Returns a newly allocated list of the widgets, normally labels, for
13343 * which this widget is the target of a mnemonic (see for example,
13344 * gtk_label_set_mnemonic_widget()).
13346 * The widgets in the list are not individually referenced. If you
13347 * want to iterate through the list and perform actions involving
13348 * callbacks that might destroy the widgets, you
13349 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
13350 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
13351 * widgets afterwards.
13353 * Return value: (element-type GtkWidget) (transfer container): the list of
13354 * mnemonic labels; free this list
13355 * with g_list_free() when you are done with it.
13360 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
13362 GList *list = NULL;
13365 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13367 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13368 list = g_list_prepend (list, l->data);
13374 * gtk_widget_add_mnemonic_label:
13375 * @widget: a #GtkWidget
13376 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13378 * Adds a widget to the list of mnemonic labels for
13379 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13380 * list of mnemonic labels for the widget is cleared when the
13381 * widget is destroyed, so the caller must make sure to update
13382 * its internal state at this point as well, by using a connection
13383 * to the #GtkWidget::destroy signal or a weak notifier.
13388 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13391 GSList *old_list, *new_list;
13393 g_return_if_fail (GTK_IS_WIDGET (widget));
13394 g_return_if_fail (GTK_IS_WIDGET (label));
13396 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13397 new_list = g_slist_prepend (old_list, label);
13399 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13400 new_list, (GDestroyNotify) g_slist_free);
13404 * gtk_widget_remove_mnemonic_label:
13405 * @widget: a #GtkWidget
13406 * @label: a #GtkWidget that was previously set as a mnemnic label for
13407 * @widget with gtk_widget_add_mnemonic_label().
13409 * Removes a widget from the list of mnemonic labels for
13410 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13411 * must have previously been added to the list with
13412 * gtk_widget_add_mnemonic_label().
13417 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13420 GSList *old_list, *new_list;
13422 g_return_if_fail (GTK_IS_WIDGET (widget));
13423 g_return_if_fail (GTK_IS_WIDGET (label));
13425 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13426 new_list = g_slist_remove (old_list, label);
13429 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13430 new_list, (GDestroyNotify) g_slist_free);
13434 * gtk_widget_get_no_show_all:
13435 * @widget: a #GtkWidget
13437 * Returns the current value of the #GtkWidget:no-show-all property,
13438 * which determines whether calls to gtk_widget_show_all()
13439 * will affect this widget.
13441 * Return value: the current value of the "no-show-all" property.
13446 gtk_widget_get_no_show_all (GtkWidget *widget)
13448 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13450 return widget->priv->no_show_all;
13454 * gtk_widget_set_no_show_all:
13455 * @widget: a #GtkWidget
13456 * @no_show_all: the new value for the "no-show-all" property
13458 * Sets the #GtkWidget:no-show-all property, which determines whether
13459 * calls to gtk_widget_show_all() will affect this widget.
13461 * This is mostly for use in constructing widget hierarchies with externally
13462 * controlled visibility, see #GtkUIManager.
13467 gtk_widget_set_no_show_all (GtkWidget *widget,
13468 gboolean no_show_all)
13470 g_return_if_fail (GTK_IS_WIDGET (widget));
13472 no_show_all = (no_show_all != FALSE);
13474 if (widget->priv->no_show_all != no_show_all)
13476 widget->priv->no_show_all = no_show_all;
13478 g_object_notify (G_OBJECT (widget), "no-show-all");
13484 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13485 gboolean has_tooltip,
13488 GtkWidgetPrivate *priv = widget->priv;
13489 gboolean priv_has_tooltip;
13491 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13492 quark_has_tooltip));
13494 if (priv_has_tooltip != has_tooltip || force)
13496 priv_has_tooltip = has_tooltip;
13498 if (priv_has_tooltip)
13500 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13501 gdk_window_set_events (priv->window,
13502 gdk_window_get_events (priv->window) |
13503 GDK_LEAVE_NOTIFY_MASK |
13504 GDK_POINTER_MOTION_MASK |
13505 GDK_POINTER_MOTION_HINT_MASK);
13507 if (gtk_widget_get_has_window (widget))
13508 gtk_widget_add_events (widget,
13509 GDK_LEAVE_NOTIFY_MASK |
13510 GDK_POINTER_MOTION_MASK |
13511 GDK_POINTER_MOTION_HINT_MASK);
13514 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13515 GUINT_TO_POINTER (priv_has_tooltip));
13520 * gtk_widget_set_tooltip_window:
13521 * @widget: a #GtkWidget
13522 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13524 * Replaces the default, usually yellow, window used for displaying
13525 * tooltips with @custom_window. GTK+ will take care of showing and
13526 * hiding @custom_window at the right moment, to behave likewise as
13527 * the default tooltip window. If @custom_window is %NULL, the default
13528 * tooltip window will be used.
13530 * If the custom window should have the default theming it needs to
13531 * have the name "gtk-tooltip", see gtk_widget_set_name().
13536 gtk_widget_set_tooltip_window (GtkWidget *widget,
13537 GtkWindow *custom_window)
13539 gboolean has_tooltip;
13540 gchar *tooltip_markup;
13542 g_return_if_fail (GTK_IS_WIDGET (widget));
13543 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13545 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13548 g_object_ref (custom_window);
13550 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13551 custom_window, g_object_unref);
13553 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13554 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13556 if (has_tooltip && gtk_widget_get_visible (widget))
13557 gtk_widget_queue_tooltip_query (widget);
13561 * gtk_widget_get_tooltip_window:
13562 * @widget: a #GtkWidget
13564 * Returns the #GtkWindow of the current tooltip. This can be the
13565 * GtkWindow created by default, or the custom tooltip window set
13566 * using gtk_widget_set_tooltip_window().
13568 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13573 gtk_widget_get_tooltip_window (GtkWidget *widget)
13575 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13577 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13581 * gtk_widget_trigger_tooltip_query:
13582 * @widget: a #GtkWidget
13584 * Triggers a tooltip query on the display where the toplevel of @widget
13585 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13591 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13593 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13596 static guint tooltip_query_id;
13597 static GSList *tooltip_query_displays;
13600 tooltip_query_idle (gpointer data)
13602 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13603 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13604 g_slist_free (tooltip_query_displays);
13606 tooltip_query_displays = NULL;
13607 tooltip_query_id = 0;
13613 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13615 GdkDisplay *display;
13617 display = gtk_widget_get_display (widget);
13619 if (!g_slist_find (tooltip_query_displays, display))
13620 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13622 if (tooltip_query_id == 0)
13623 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13627 * gtk_widget_set_tooltip_text:
13628 * @widget: a #GtkWidget
13629 * @text: the contents of the tooltip for @widget
13631 * Sets @text as the contents of the tooltip. This function will take
13632 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13633 * handler for the #GtkWidget::query-tooltip signal.
13635 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13640 gtk_widget_set_tooltip_text (GtkWidget *widget,
13643 g_return_if_fail (GTK_IS_WIDGET (widget));
13645 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13649 * gtk_widget_get_tooltip_text:
13650 * @widget: a #GtkWidget
13652 * Gets the contents of the tooltip for @widget.
13654 * Return value: the tooltip text, or %NULL. You should free the
13655 * returned string with g_free() when done.
13660 gtk_widget_get_tooltip_text (GtkWidget *widget)
13662 gchar *text = NULL;
13664 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13666 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13672 * gtk_widget_set_tooltip_markup:
13673 * @widget: a #GtkWidget
13674 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13676 * Sets @markup as the contents of the tooltip, which is marked up with
13677 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13679 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13680 * and of the default handler for the #GtkWidget::query-tooltip signal.
13682 * See also the #GtkWidget:tooltip-markup property and
13683 * gtk_tooltip_set_markup().
13688 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13689 const gchar *markup)
13691 g_return_if_fail (GTK_IS_WIDGET (widget));
13693 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13697 * gtk_widget_get_tooltip_markup:
13698 * @widget: a #GtkWidget
13700 * Gets the contents of the tooltip for @widget.
13702 * Return value: the tooltip text, or %NULL. You should free the
13703 * returned string with g_free() when done.
13708 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13710 gchar *text = NULL;
13712 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13714 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13720 * gtk_widget_set_has_tooltip:
13721 * @widget: a #GtkWidget
13722 * @has_tooltip: whether or not @widget has a tooltip.
13724 * Sets the has-tooltip property on @widget to @has_tooltip. See
13725 * #GtkWidget:has-tooltip for more information.
13730 gtk_widget_set_has_tooltip (GtkWidget *widget,
13731 gboolean has_tooltip)
13733 g_return_if_fail (GTK_IS_WIDGET (widget));
13735 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13739 * gtk_widget_get_has_tooltip:
13740 * @widget: a #GtkWidget
13742 * Returns the current value of the has-tooltip property. See
13743 * #GtkWidget:has-tooltip for more information.
13745 * Return value: current value of has-tooltip on @widget.
13750 gtk_widget_get_has_tooltip (GtkWidget *widget)
13752 gboolean has_tooltip = FALSE;
13754 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13756 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13758 return has_tooltip;
13762 * gtk_widget_get_allocation:
13763 * @widget: a #GtkWidget
13764 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13766 * Retrieves the widget's allocation.
13768 * Note, when implementing a #GtkContainer: a widget's allocation will
13769 * be its "adjusted" allocation, that is, the widget's parent
13770 * container typically calls gtk_widget_size_allocate() with an
13771 * allocation, and that allocation is then adjusted (to handle margin
13772 * and alignment for example) before assignment to the widget.
13773 * gtk_widget_get_allocation() returns the adjusted allocation that
13774 * was actually assigned to the widget. The adjusted allocation is
13775 * guaranteed to be completely contained within the
13776 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13777 * is guaranteed that its children stay inside the assigned bounds,
13778 * but not that they have exactly the bounds the container assigned.
13779 * There is no way to get the original allocation assigned by
13780 * gtk_widget_size_allocate(), since it isn't stored; if a container
13781 * implementation needs that information it will have to track it itself.
13786 gtk_widget_get_allocation (GtkWidget *widget,
13787 GtkAllocation *allocation)
13789 GtkWidgetPrivate *priv;
13791 g_return_if_fail (GTK_IS_WIDGET (widget));
13792 g_return_if_fail (allocation != NULL);
13794 priv = widget->priv;
13796 *allocation = priv->allocation;
13800 * gtk_widget_set_allocation:
13801 * @widget: a #GtkWidget
13802 * @allocation: a pointer to a #GtkAllocation to copy from
13804 * Sets the widget's allocation. This should not be used
13805 * directly, but from within a widget's size_allocate method.
13807 * The allocation set should be the "adjusted" or actual
13808 * allocation. If you're implementing a #GtkContainer, you want to use
13809 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13810 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13811 * allocation inside gtk_widget_size_allocate() to create an adjusted
13817 gtk_widget_set_allocation (GtkWidget *widget,
13818 const GtkAllocation *allocation)
13820 GtkWidgetPrivate *priv;
13822 g_return_if_fail (GTK_IS_WIDGET (widget));
13823 g_return_if_fail (allocation != NULL);
13825 priv = widget->priv;
13827 priv->allocation = *allocation;
13831 * gtk_widget_get_allocated_width:
13832 * @widget: the widget to query
13834 * Returns the width that has currently been allocated to @widget.
13835 * This function is intended to be used when implementing handlers
13836 * for the #GtkWidget::draw function.
13838 * Returns: the width of the @widget
13841 gtk_widget_get_allocated_width (GtkWidget *widget)
13843 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13845 return widget->priv->allocation.width;
13849 * gtk_widget_get_allocated_height:
13850 * @widget: the widget to query
13852 * Returns the height that has currently been allocated to @widget.
13853 * This function is intended to be used when implementing handlers
13854 * for the #GtkWidget::draw function.
13856 * Returns: the height of the @widget
13859 gtk_widget_get_allocated_height (GtkWidget *widget)
13861 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13863 return widget->priv->allocation.height;
13867 * gtk_widget_get_requisition:
13868 * @widget: a #GtkWidget
13869 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13871 * Retrieves the widget's requisition.
13873 * This function should only be used by widget implementations in
13874 * order to figure whether the widget's requisition has actually
13875 * changed after some internal state change (so that they can call
13876 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13878 * Normally, gtk_widget_size_request() should be used.
13882 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13883 * removed, If you need to cache sizes across requests and allocations,
13884 * add an explicit cache to the widget in question instead.
13887 gtk_widget_get_requisition (GtkWidget *widget,
13888 GtkRequisition *requisition)
13890 g_return_if_fail (GTK_IS_WIDGET (widget));
13891 g_return_if_fail (requisition != NULL);
13893 gtk_widget_get_preferred_size (widget, requisition, NULL);
13897 * gtk_widget_set_window:
13898 * @widget: a #GtkWidget
13899 * @window: a #GdkWindow
13901 * Sets a widget's window. This function should only be used in a
13902 * widget's #GtkWidget::realize implementation. The %window passed is
13903 * usually either new window created with gdk_window_new(), or the
13904 * window of its parent widget as returned by
13905 * gtk_widget_get_parent_window().
13907 * Widgets must indicate whether they will create their own #GdkWindow
13908 * by calling gtk_widget_set_has_window(). This is usually done in the
13909 * widget's init() function.
13911 * <note><para>This function does not add any reference to @window.</para></note>
13916 gtk_widget_set_window (GtkWidget *widget,
13919 GtkWidgetPrivate *priv;
13921 g_return_if_fail (GTK_IS_WIDGET (widget));
13922 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13924 priv = widget->priv;
13926 if (priv->window != window)
13928 priv->window = window;
13929 g_object_notify (G_OBJECT (widget), "window");
13934 * gtk_widget_get_window:
13935 * @widget: a #GtkWidget
13937 * Returns the widget's window if it is realized, %NULL otherwise
13939 * Return value: (transfer none): @widget's window.
13944 gtk_widget_get_window (GtkWidget *widget)
13946 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13948 return widget->priv->window;
13952 * gtk_widget_get_support_multidevice:
13953 * @widget: a #GtkWidget
13955 * Returns %TRUE if @widget is multiple pointer aware. See
13956 * gtk_widget_set_support_multidevice() for more information.
13958 * Returns: %TRUE if @widget is multidevice aware.
13961 gtk_widget_get_support_multidevice (GtkWidget *widget)
13963 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13965 return widget->priv->multidevice;
13969 * gtk_widget_set_support_multidevice:
13970 * @widget: a #GtkWidget
13971 * @support_multidevice: %TRUE to support input from multiple devices.
13973 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13974 * @widget will start receiving multiple, per device enter/leave events. Note
13975 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13976 * gdk_window_set_support_multidevice() will have to be called manually on them.
13981 gtk_widget_set_support_multidevice (GtkWidget *widget,
13982 gboolean support_multidevice)
13984 GtkWidgetPrivate *priv;
13986 g_return_if_fail (GTK_IS_WIDGET (widget));
13988 priv = widget->priv;
13989 priv->multidevice = (support_multidevice == TRUE);
13991 if (gtk_widget_get_realized (widget))
13992 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13996 _gtk_widget_set_has_focus (GtkWidget *widget,
13997 gboolean has_focus)
13999 widget->priv->has_focus = has_focus;
14002 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
14004 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
14008 * gtk_widget_send_focus_change:
14009 * @widget: a #GtkWidget
14010 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
14012 * Sends the focus change @event to @widget
14014 * This function is not meant to be used by applications. The only time it
14015 * should be used is when it is necessary for a #GtkWidget to assign focus
14016 * to a widget that is semantically owned by the first widget even though
14017 * it's not a direct child - for instance, a search entry in a floating
14018 * window similar to the quick search in #GtkTreeView.
14020 * An example of its usage is:
14023 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
14025 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
14026 * fevent->focus_change.in = TRUE;
14027 * fevent->focus_change.window = gtk_widget_get_window (widget);
14028 * if (fevent->focus_change.window != NULL)
14029 * g_object_ref (fevent->focus_change.window);
14031 * gtk_widget_send_focus_change (widget, fevent);
14033 * gdk_event_free (event);
14036 * Return value: the return value from the event signal emission: %TRUE
14037 * if the event was handled, and %FALSE otherwise
14042 gtk_widget_send_focus_change (GtkWidget *widget,
14047 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
14048 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
14050 g_object_ref (widget);
14052 _gtk_widget_set_has_focus (widget, event->focus_change.in);
14054 res = gtk_widget_event (widget, event);
14056 g_object_notify (G_OBJECT (widget), "has-focus");
14058 g_object_unref (widget);
14064 * gtk_widget_in_destruction:
14065 * @widget: a #GtkWidget
14067 * Returns whether the widget is currently being destroyed.
14068 * This information can sometimes be used to avoid doing
14069 * unnecessary work.
14071 * Returns: %TRUE if @widget is being destroyed
14074 gtk_widget_in_destruction (GtkWidget *widget)
14076 return widget->priv->in_destruction;
14080 _gtk_widget_get_resize_pending (GtkWidget *widget)
14082 return widget->priv->resize_pending;
14086 _gtk_widget_set_resize_pending (GtkWidget *widget,
14087 gboolean resize_pending)
14089 widget->priv->resize_pending = resize_pending;
14093 _gtk_widget_get_in_reparent (GtkWidget *widget)
14095 return widget->priv->in_reparent;
14099 _gtk_widget_set_in_reparent (GtkWidget *widget,
14100 gboolean in_reparent)
14102 widget->priv->in_reparent = in_reparent;
14106 _gtk_widget_get_anchored (GtkWidget *widget)
14108 return widget->priv->anchored;
14112 _gtk_widget_set_anchored (GtkWidget *widget,
14115 widget->priv->anchored = anchored;
14119 _gtk_widget_get_shadowed (GtkWidget *widget)
14121 return widget->priv->shadowed;
14125 _gtk_widget_set_shadowed (GtkWidget *widget,
14128 widget->priv->shadowed = shadowed;
14132 _gtk_widget_get_alloc_needed (GtkWidget *widget)
14134 return widget->priv->alloc_needed;
14138 _gtk_widget_set_alloc_needed (GtkWidget *widget,
14139 gboolean alloc_needed)
14141 widget->priv->alloc_needed = alloc_needed;
14145 _gtk_widget_get_width_request_needed (GtkWidget *widget)
14147 return widget->priv->width_request_needed;
14151 _gtk_widget_set_width_request_needed (GtkWidget *widget,
14152 gboolean width_request_needed)
14154 widget->priv->width_request_needed = width_request_needed;
14158 _gtk_widget_get_height_request_needed (GtkWidget *widget)
14160 return widget->priv->height_request_needed;
14164 _gtk_widget_set_height_request_needed (GtkWidget *widget,
14165 gboolean height_request_needed)
14167 widget->priv->height_request_needed = height_request_needed;
14171 _gtk_widget_get_sizegroup_visited (GtkWidget *widget)
14173 return widget->priv->sizegroup_visited;
14177 _gtk_widget_set_sizegroup_visited (GtkWidget *widget,
14180 widget->priv->sizegroup_visited = visited;
14184 _gtk_widget_get_sizegroup_bumping (GtkWidget *widget)
14186 return widget->priv->sizegroup_bumping;
14190 _gtk_widget_set_sizegroup_bumping (GtkWidget *widget,
14193 widget->priv->sizegroup_bumping = bumping;
14197 _gtk_widget_add_sizegroup (GtkWidget *widget,
14202 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14203 groups = g_slist_prepend (groups, group);
14204 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14206 widget->priv->have_size_groups = TRUE;
14210 _gtk_widget_remove_sizegroup (GtkWidget *widget,
14215 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14216 groups = g_slist_remove (groups, group);
14217 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14219 widget->priv->have_size_groups = groups != NULL;
14223 _gtk_widget_get_sizegroups (GtkWidget *widget)
14225 if (widget->priv->have_size_groups)
14226 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14232 * gtk_widget_get_path:
14233 * @widget: a #GtkWidget
14235 * Returns the #GtkWidgetPath representing @widget, if the widget
14236 * is not connected to a toplevel widget, a partial path will be
14239 * Returns: (transfer none): The #GtkWidgetPath representing @widget
14242 gtk_widget_get_path (GtkWidget *widget)
14244 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14246 /* As strange as it may seem, this may happen on object construction.
14247 * init() implementations of parent types may eventually call this function,
14248 * each with its corresponding GType, which could leave a child
14249 * implementation with a wrong widget type in the widget path
14251 if (widget->priv->path &&
14252 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (widget->priv->path))
14254 gtk_widget_path_free (widget->priv->path);
14255 widget->priv->path = NULL;
14258 if (!widget->priv->path)
14263 parent = widget->priv->parent;
14266 widget->priv->path = gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
14269 /* Widget is either toplevel or unparented, treat both
14270 * as toplevels style wise, since there are situations
14271 * where style properties might be retrieved on that
14274 widget->priv->path = gtk_widget_path_new ();
14277 pos = gtk_widget_path_append_type (widget->priv->path, G_OBJECT_TYPE (widget));
14279 if (widget->priv->name)
14280 gtk_widget_path_iter_set_name (widget->priv->path, pos, widget->priv->name);
14282 if (widget->priv->context)
14284 GList *classes, *l;
14286 /* Also add any persistent classes in
14287 * the style context the widget path
14289 classes = gtk_style_context_list_classes (widget->priv->context);
14291 for (l = classes; l; l = l->next)
14292 gtk_widget_path_iter_add_class (widget->priv->path, pos, l->data);
14294 gtk_style_context_set_path (widget->priv->context,
14295 widget->priv->path);
14297 g_list_free (classes);
14301 return widget->priv->path;
14305 style_context_changed (GtkStyleContext *context,
14306 gpointer user_data)
14308 GtkWidget *widget = user_data;
14310 gtk_widget_update_pango_context (widget);
14312 if (gtk_widget_get_realized (widget))
14313 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
14316 /* Compress all style updates so it
14317 * is only emitted once pre-realize.
14319 widget->priv->style_update_pending = TRUE;
14322 if (widget->priv->anchored)
14323 gtk_widget_queue_resize (widget);
14327 * gtk_widget_get_style_context:
14328 * @widget: a #GtkWidget
14330 * Returns the style context associated to @widget.
14332 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
14333 * must not be freed.
14336 gtk_widget_get_style_context (GtkWidget *widget)
14338 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14340 if (G_UNLIKELY (!widget->priv->context))
14344 widget->priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
14345 "direction", gtk_widget_get_direction (widget),
14348 g_signal_connect (widget->priv->context, "changed",
14349 G_CALLBACK (style_context_changed), widget);
14351 screen = gtk_widget_get_screen (widget);
14354 gtk_style_context_set_screen (widget->priv->context, screen);
14356 _gtk_widget_update_path (widget);
14357 gtk_style_context_set_path (widget->priv->context,
14358 widget->priv->path);
14362 /* Force widget path regeneration if needed, the
14363 * context will be updated within this function.
14365 gtk_widget_get_path (widget);
14368 return widget->priv->context;