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 const 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;
6923 gtk_widget_reset_style (widget);
6925 g_object_notify (G_OBJECT (widget), "name");
6929 * gtk_widget_get_name:
6930 * @widget: a #GtkWidget
6932 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6933 * significance of widget names.
6935 * Return value: name of the widget. This string is owned by GTK+ and
6936 * should not be modified or freed
6938 G_CONST_RETURN gchar*
6939 gtk_widget_get_name (GtkWidget *widget)
6941 GtkWidgetPrivate *priv;
6943 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6945 priv = widget->priv;
6949 return G_OBJECT_TYPE_NAME (widget);
6953 _gtk_widget_update_state_flags (GtkWidget *widget,
6954 GtkStateFlags flags,
6957 GtkWidgetPrivate *priv;
6959 priv = widget->priv;
6961 /* Handle insensitive first, since it is propagated
6962 * differently throughout the widget hierarchy.
6964 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_UNSET))
6965 gtk_widget_set_sensitive (widget, TRUE);
6966 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation != STATE_CHANGE_UNSET))
6967 gtk_widget_set_sensitive (widget, FALSE);
6968 else if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && !(flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_REPLACE))
6969 gtk_widget_set_sensitive (widget, TRUE);
6971 if (operation != STATE_CHANGE_REPLACE)
6972 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
6975 operation == STATE_CHANGE_REPLACE)
6980 data.operation = operation;
6981 data.use_forall = FALSE;
6984 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6986 data.parent_sensitive = TRUE;
6988 gtk_widget_propagate_state (widget, &data);
6990 gtk_widget_queue_resize (widget);
6995 * gtk_widget_set_state_flags:
6996 * @widget: a #GtkWidget
6997 * @flags: State flags to turn on
6998 * @clear: Whether to clear state before turning on @flags
7000 * This function is for use in widget implementations. Turns on flag
7001 * values in the current widget state (insensitive, prelighted, etc.).
7003 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7004 * will be propagated down to all non-internal children if @widget is a
7005 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7006 * down to all #GtkContainer children by different means than turning on the
7007 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7008 * gtk_widget_is_sensitive() will make use of these.
7013 gtk_widget_set_state_flags (GtkWidget *widget,
7014 GtkStateFlags flags,
7017 g_return_if_fail (GTK_IS_WIDGET (widget));
7019 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7020 (clear && widget->priv->state_flags == flags))
7024 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7026 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
7030 * gtk_widget_unset_state_flags:
7031 * @widget: a #GtkWidget
7032 * @flags: State flags to turn off
7034 * This function is for use in widget implementations. Turns off flag
7035 * values for the current widget state (insensitive, prelighted, etc.).
7036 * See gtk_widget_set_state_flags().
7041 gtk_widget_unset_state_flags (GtkWidget *widget,
7042 GtkStateFlags flags)
7044 g_return_if_fail (GTK_IS_WIDGET (widget));
7046 if ((widget->priv->state_flags & flags) == 0)
7049 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
7053 * gtk_widget_get_state_flags:
7054 * @widget: a #GtkWidget
7056 * Returns the widget state as a flag set. It is worth mentioning
7057 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7058 * returned, that is, also based on parent insensitivity, even if
7059 * @widget itself is sensitive.
7061 * Returns: The state flags for widget
7066 gtk_widget_get_state_flags (GtkWidget *widget)
7068 GtkStateFlags flags;
7070 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7072 flags = widget->priv->state_flags;
7074 if (!gtk_widget_is_sensitive (widget))
7075 flags |= GTK_STATE_FLAG_INSENSITIVE;
7077 if (gtk_widget_has_focus (widget))
7078 flags |= GTK_STATE_FLAG_FOCUSED;
7084 * gtk_widget_set_state:
7085 * @widget: a #GtkWidget
7086 * @state: new state for @widget
7088 * This function is for use in widget implementations. Sets the state
7089 * of a widget (insensitive, prelighted, etc.) Usually you should set
7090 * the state using wrapper functions such as gtk_widget_set_sensitive().
7092 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7095 gtk_widget_set_state (GtkWidget *widget,
7098 GtkStateFlags flags;
7100 if (state == gtk_widget_get_state (widget))
7105 case GTK_STATE_ACTIVE:
7106 flags = GTK_STATE_FLAG_ACTIVE;
7108 case GTK_STATE_PRELIGHT:
7109 flags = GTK_STATE_FLAG_PRELIGHT;
7111 case GTK_STATE_SELECTED:
7112 flags = GTK_STATE_FLAG_SELECTED;
7114 case GTK_STATE_INSENSITIVE:
7115 flags = GTK_STATE_FLAG_INSENSITIVE;
7117 case GTK_STATE_INCONSISTENT:
7118 flags = GTK_STATE_FLAG_INCONSISTENT;
7120 case GTK_STATE_FOCUSED:
7121 flags = GTK_STATE_FLAG_FOCUSED;
7123 case GTK_STATE_NORMAL:
7129 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7133 * gtk_widget_get_state:
7134 * @widget: a #GtkWidget
7136 * Returns the widget's state. See gtk_widget_set_state().
7138 * Returns: the state of @widget.
7142 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7145 gtk_widget_get_state (GtkWidget *widget)
7147 GtkStateFlags flags;
7149 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7151 flags = gtk_widget_get_state_flags (widget);
7153 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7154 return GTK_STATE_INSENSITIVE;
7155 else if (flags & GTK_STATE_FLAG_ACTIVE)
7156 return GTK_STATE_ACTIVE;
7157 else if (flags & GTK_STATE_FLAG_SELECTED)
7158 return GTK_STATE_SELECTED;
7159 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7160 return GTK_STATE_PRELIGHT;
7162 return GTK_STATE_NORMAL;
7166 * gtk_widget_set_visible:
7167 * @widget: a #GtkWidget
7168 * @visible: whether the widget should be shown or not
7170 * Sets the visibility state of @widget. Note that setting this to
7171 * %TRUE doesn't mean the widget is actually viewable, see
7172 * gtk_widget_get_visible().
7174 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7175 * but is nicer to use when the visibility of the widget depends on
7181 gtk_widget_set_visible (GtkWidget *widget,
7184 g_return_if_fail (GTK_IS_WIDGET (widget));
7186 if (visible != gtk_widget_get_visible (widget))
7189 gtk_widget_show (widget);
7191 gtk_widget_hide (widget);
7196 _gtk_widget_set_visible_flag (GtkWidget *widget,
7199 widget->priv->visible = visible;
7203 * gtk_widget_get_visible:
7204 * @widget: a #GtkWidget
7206 * Determines whether the widget is visible. Note that this doesn't
7207 * take into account whether the widget's parent is also visible
7208 * or the widget is obscured in any way.
7210 * See gtk_widget_set_visible().
7212 * Return value: %TRUE if the widget is visible
7217 gtk_widget_get_visible (GtkWidget *widget)
7219 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7221 return widget->priv->visible;
7225 * gtk_widget_set_has_window:
7226 * @widget: a #GtkWidget
7227 * @has_window: whether or not @widget has a window.
7229 * Specifies whether @widget has a #GdkWindow of its own. Note that
7230 * all realized widgets have a non-%NULL "window" pointer
7231 * (gtk_widget_get_window() never returns a %NULL window when a widget
7232 * is realized), but for many of them it's actually the #GdkWindow of
7233 * one of its parent widgets. Widgets that do not create a %window for
7234 * themselves in #GtkWidget::realize must announce this by
7235 * calling this function with @has_window = %FALSE.
7237 * This function should only be called by widget implementations,
7238 * and they should call it in their init() function.
7243 gtk_widget_set_has_window (GtkWidget *widget,
7244 gboolean has_window)
7246 g_return_if_fail (GTK_IS_WIDGET (widget));
7248 widget->priv->no_window = !has_window;
7252 * gtk_widget_get_has_window:
7253 * @widget: a #GtkWidget
7255 * Determines whether @widget has a #GdkWindow of its own. See
7256 * gtk_widget_set_has_window().
7258 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7263 gtk_widget_get_has_window (GtkWidget *widget)
7265 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7267 return ! widget->priv->no_window;
7271 * gtk_widget_is_toplevel:
7272 * @widget: a #GtkWidget
7274 * Determines whether @widget is a toplevel widget.
7276 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7277 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7280 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7285 gtk_widget_is_toplevel (GtkWidget *widget)
7287 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7289 return widget->priv->toplevel;
7293 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7294 gboolean is_toplevel)
7296 widget->priv->toplevel = is_toplevel;
7300 * gtk_widget_is_drawable:
7301 * @widget: a #GtkWidget
7303 * Determines whether @widget can be drawn to. A widget can be drawn
7304 * to if it is mapped and visible.
7306 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7311 gtk_widget_is_drawable (GtkWidget *widget)
7313 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7315 return (gtk_widget_get_visible (widget) &&
7316 gtk_widget_get_mapped (widget));
7320 * gtk_widget_get_realized:
7321 * @widget: a #GtkWidget
7323 * Determines whether @widget is realized.
7325 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7330 gtk_widget_get_realized (GtkWidget *widget)
7332 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7334 return widget->priv->realized;
7338 * gtk_widget_set_realized:
7339 * @widget: a #GtkWidget
7340 * @realized: %TRUE to mark the widget as realized
7342 * Marks the widget as being realized.
7344 * This function should only ever be called in a derived widget's
7345 * "realize" or "unrealize" implementation.
7350 gtk_widget_set_realized (GtkWidget *widget,
7353 g_return_if_fail (GTK_IS_WIDGET (widget));
7355 widget->priv->realized = realized;
7359 * gtk_widget_get_mapped:
7360 * @widget: a #GtkWidget
7362 * Whether the widget is mapped.
7364 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7369 gtk_widget_get_mapped (GtkWidget *widget)
7371 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7373 return widget->priv->mapped;
7377 * gtk_widget_set_mapped:
7378 * @widget: a #GtkWidget
7379 * @mapped: %TRUE to mark the widget as mapped
7381 * Marks the widget as being realized.
7383 * This function should only ever be called in a derived widget's
7384 * "map" or "unmap" implementation.
7389 gtk_widget_set_mapped (GtkWidget *widget,
7392 g_return_if_fail (GTK_IS_WIDGET (widget));
7394 widget->priv->mapped = mapped;
7398 * gtk_widget_set_app_paintable:
7399 * @widget: a #GtkWidget
7400 * @app_paintable: %TRUE if the application will paint on the widget
7402 * Sets whether the application intends to draw on the widget in
7403 * an #GtkWidget::draw handler.
7405 * This is a hint to the widget and does not affect the behavior of
7406 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7407 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7408 * the effect is to suppress default themed drawing of the widget's
7409 * background. (Children of the widget will still be drawn.) The application
7410 * is then entirely responsible for drawing the widget background.
7412 * Note that the background is still drawn when the widget is mapped.
7415 gtk_widget_set_app_paintable (GtkWidget *widget,
7416 gboolean app_paintable)
7418 g_return_if_fail (GTK_IS_WIDGET (widget));
7420 app_paintable = (app_paintable != FALSE);
7422 if (widget->priv->app_paintable != app_paintable)
7424 widget->priv->app_paintable = app_paintable;
7426 if (gtk_widget_is_drawable (widget))
7427 gtk_widget_queue_draw (widget);
7429 g_object_notify (G_OBJECT (widget), "app-paintable");
7434 * gtk_widget_get_app_paintable:
7435 * @widget: a #GtkWidget
7437 * Determines whether the application intends to draw on the widget in
7438 * an #GtkWidget::draw handler.
7440 * See gtk_widget_set_app_paintable()
7442 * Return value: %TRUE if the widget is app paintable
7447 gtk_widget_get_app_paintable (GtkWidget *widget)
7449 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7451 return widget->priv->app_paintable;
7455 * gtk_widget_set_double_buffered:
7456 * @widget: a #GtkWidget
7457 * @double_buffered: %TRUE to double-buffer a widget
7459 * Widgets are double buffered by default; you can use this function
7460 * to turn off the buffering. "Double buffered" simply means that
7461 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7462 * automatically around expose events sent to the
7463 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7464 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7465 * buffer to the screen. The result is that users see the window
7466 * update in one smooth step, and don't see individual graphics
7467 * primitives being rendered.
7469 * In very simple terms, double buffered widgets don't flicker,
7470 * so you would only use this function to turn off double buffering
7471 * if you had special needs and really knew what you were doing.
7473 * Note: if you turn off double-buffering, you have to handle
7474 * expose events, since even the clearing to the background color or
7475 * pixmap will not happen automatically (as it is done in
7476 * gdk_window_begin_paint()).
7479 gtk_widget_set_double_buffered (GtkWidget *widget,
7480 gboolean double_buffered)
7482 g_return_if_fail (GTK_IS_WIDGET (widget));
7484 double_buffered = (double_buffered != FALSE);
7486 if (widget->priv->double_buffered != double_buffered)
7488 widget->priv->double_buffered = double_buffered;
7490 g_object_notify (G_OBJECT (widget), "double-buffered");
7495 * gtk_widget_get_double_buffered:
7496 * @widget: a #GtkWidget
7498 * Determines whether the widget is double buffered.
7500 * See gtk_widget_set_double_buffered()
7502 * Return value: %TRUE if the widget is double buffered
7507 gtk_widget_get_double_buffered (GtkWidget *widget)
7509 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7511 return widget->priv->double_buffered;
7515 * gtk_widget_set_redraw_on_allocate:
7516 * @widget: a #GtkWidget
7517 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7518 * when it is allocated to a new size. Otherwise, only the
7519 * new portion of the widget will be redrawn.
7521 * Sets whether the entire widget is queued for drawing when its size
7522 * allocation changes. By default, this setting is %TRUE and
7523 * the entire widget is redrawn on every size change. If your widget
7524 * leaves the upper left unchanged when made bigger, turning this
7525 * setting off will improve performance.
7527 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7528 * off all allocation on resizing: the widget will not even redraw if
7529 * its position changes; this is to allow containers that don't draw
7530 * anything to avoid excess invalidations. If you set this flag on a
7531 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7532 * you are responsible for invalidating both the old and new allocation
7533 * of the widget when the widget is moved and responsible for invalidating
7534 * regions newly when the widget increases size.
7537 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7538 gboolean redraw_on_allocate)
7540 g_return_if_fail (GTK_IS_WIDGET (widget));
7542 widget->priv->redraw_on_alloc = redraw_on_allocate;
7546 * gtk_widget_set_sensitive:
7547 * @widget: a #GtkWidget
7548 * @sensitive: %TRUE to make the widget sensitive
7550 * Sets the sensitivity of a widget. A widget is sensitive if the user
7551 * can interact with it. Insensitive widgets are "grayed out" and the
7552 * user can't interact with them. Insensitive widgets are known as
7553 * "inactive", "disabled", or "ghosted" in some other toolkits.
7556 gtk_widget_set_sensitive (GtkWidget *widget,
7559 GtkWidgetPrivate *priv;
7562 g_return_if_fail (GTK_IS_WIDGET (widget));
7564 priv = widget->priv;
7566 sensitive = (sensitive != FALSE);
7568 if (widget->priv->sensitive == sensitive)
7571 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7575 widget->priv->sensitive = TRUE;
7576 data.operation = STATE_CHANGE_UNSET;
7580 widget->priv->sensitive = FALSE;
7581 data.operation = STATE_CHANGE_SET;
7584 data.use_forall = TRUE;
7587 data.parent_sensitive = gtk_widget_is_sensitive (priv->parent);
7589 data.parent_sensitive = TRUE;
7591 gtk_widget_propagate_state (widget, &data);
7593 gtk_widget_queue_resize (widget);
7595 g_object_notify (G_OBJECT (widget), "sensitive");
7599 * gtk_widget_get_sensitive:
7600 * @widget: a #GtkWidget
7602 * Returns the widget's sensitivity (in the sense of returning
7603 * the value that has been set using gtk_widget_set_sensitive()).
7605 * The effective sensitivity of a widget is however determined by both its
7606 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7608 * Returns: %TRUE if the widget is sensitive
7613 gtk_widget_get_sensitive (GtkWidget *widget)
7615 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7617 return widget->priv->sensitive;
7621 * gtk_widget_is_sensitive:
7622 * @widget: a #GtkWidget
7624 * Returns the widget's effective sensitivity, which means
7625 * it is sensitive itself and also its parent widget is sensitive
7627 * Returns: %TRUE if the widget is effectively sensitive
7632 gtk_widget_is_sensitive (GtkWidget *widget)
7634 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7636 return widget->priv->sensitive && widget->priv->parent_sensitive;
7640 _gtk_widget_update_path (GtkWidget *widget)
7642 if (widget->priv->path)
7644 gtk_widget_path_free (widget->priv->path);
7645 widget->priv->path = NULL;
7648 gtk_widget_get_path (widget);
7652 * gtk_widget_set_parent:
7653 * @widget: a #GtkWidget
7654 * @parent: parent container
7656 * This function is useful only when implementing subclasses of
7658 * Sets the container as the parent of @widget, and takes care of
7659 * some details such as updating the state and style of the child
7660 * to reflect its new location. The opposite function is
7661 * gtk_widget_unparent().
7664 gtk_widget_set_parent (GtkWidget *widget,
7667 GtkStateFlags parent_flags;
7668 GtkWidgetPrivate *priv;
7671 g_return_if_fail (GTK_IS_WIDGET (widget));
7672 g_return_if_fail (GTK_IS_WIDGET (parent));
7673 g_return_if_fail (widget != parent);
7675 priv = widget->priv;
7677 if (priv->parent != NULL)
7679 g_warning ("Can't set a parent on widget which has a parent\n");
7682 if (gtk_widget_is_toplevel (widget))
7684 g_warning ("Can't set a parent on a toplevel widget\n");
7688 /* keep this function in sync with gtk_menu_attach_to_widget()
7691 g_object_ref_sink (widget);
7693 gtk_widget_push_verify_invariants (widget);
7695 priv->parent = parent;
7697 parent_flags = gtk_widget_get_state_flags (parent);
7699 /* Merge both old state and current parent state,
7700 * We don't want the insensitive flag to propagate
7701 * to the new child though */
7702 data.flags = parent_flags & ~GTK_STATE_FLAG_INSENSITIVE;
7703 data.flags |= priv->state_flags;
7705 data.operation = STATE_CHANGE_REPLACE;
7706 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
7707 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7708 gtk_widget_propagate_state (widget, &data);
7710 gtk_widget_reset_rc_styles (widget);
7712 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7713 if (priv->parent->priv->anchored)
7714 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7715 g_object_notify (G_OBJECT (widget), "parent");
7717 /* Enforce realized/mapped invariants
7719 if (gtk_widget_get_realized (priv->parent))
7720 gtk_widget_realize (widget);
7722 if (gtk_widget_get_visible (priv->parent) &&
7723 gtk_widget_get_visible (widget))
7725 if (gtk_widget_get_child_visible (widget) &&
7726 gtk_widget_get_mapped (priv->parent))
7727 gtk_widget_map (widget);
7729 gtk_widget_queue_resize (widget);
7732 /* child may cause parent's expand to change, if the child is
7733 * expanded. If child is not expanded, then it can't modify the
7734 * parent's expand. If the child becomes expanded later then it will
7735 * queue compute_expand then. This optimization plus defaulting
7736 * newly-constructed widgets to need_compute_expand=FALSE should
7737 * mean that initially building a widget tree doesn't have to keep
7738 * walking up setting need_compute_expand on parents over and over.
7740 * We can't change a parent to need to expand unless we're visible.
7742 if (gtk_widget_get_visible (widget) &&
7743 (priv->need_compute_expand ||
7744 priv->computed_hexpand ||
7745 priv->computed_vexpand))
7747 gtk_widget_queue_compute_expand (parent);
7750 if (widget->priv->context)
7754 _gtk_widget_update_path (widget);
7755 gtk_style_context_set_path (widget->priv->context, widget->priv->path);
7757 screen = gtk_widget_get_screen (widget);
7760 gtk_style_context_set_screen (widget->priv->context, screen);
7763 gtk_widget_pop_verify_invariants (widget);
7767 * gtk_widget_get_parent:
7768 * @widget: a #GtkWidget
7770 * Returns the parent container of @widget.
7772 * Return value: (transfer none): the parent container of @widget, or %NULL
7775 gtk_widget_get_parent (GtkWidget *widget)
7777 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7779 return widget->priv->parent;
7782 /*****************************************
7784 * see docs/styles.txt
7785 *****************************************/
7788 * gtk_widget_style_attach:
7789 * @widget: a #GtkWidget
7791 * This function attaches the widget's #GtkStyle to the widget's
7792 * #GdkWindow. It is a replacement for
7795 * widget->style = gtk_style_attach (widget->style, widget->window);
7798 * and should only ever be called in a derived widget's "realize"
7799 * implementation which does not chain up to its parent class'
7800 * "realize" implementation, because one of the parent classes
7801 * (finally #GtkWidget) would attach the style itself.
7805 * Deprecated: 3.0. This step is unnecessary with #GtkStyleContext.
7808 gtk_widget_style_attach (GtkWidget *widget)
7810 GtkWidgetPrivate *priv;
7812 g_return_if_fail (GTK_IS_WIDGET (widget));
7813 g_return_if_fail (gtk_widget_get_realized (widget));
7815 priv = widget->priv;
7817 priv->style = gtk_style_attach (priv->style, priv->window);
7821 * gtk_widget_has_rc_style:
7822 * @widget: a #GtkWidget
7824 * Determines if the widget style has been looked up through the rc mechanism.
7826 * Returns: %TRUE if the widget has been looked up through the rc
7827 * mechanism, %FALSE otherwise.
7831 * Deprecated:3.0: Use #GtkStyleContext instead
7834 gtk_widget_has_rc_style (GtkWidget *widget)
7836 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7838 return widget->priv->rc_style;
7842 * gtk_widget_set_style:
7843 * @widget: a #GtkWidget
7844 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect
7845 * of a previous call to gtk_widget_set_style() and go back to
7848 * Used to set the #GtkStyle for a widget (@widget->style). Since
7849 * GTK 3, this function does nothing, the passed in style is ignored.
7851 * Deprecated:3.0: Use #GtkStyleContext instead
7854 gtk_widget_set_style (GtkWidget *widget,
7857 g_return_if_fail (GTK_IS_WIDGET (widget));
7861 * gtk_widget_ensure_style:
7862 * @widget: a #GtkWidget
7864 * Ensures that @widget has a style (@widget->style).
7866 * Not a very useful function; most of the time, if you
7867 * want the style, the widget is realized, and realized
7868 * widgets are guaranteed to have a style already.
7870 * Deprecated:3.0: Use #GtkStyleContext instead
7873 gtk_widget_ensure_style (GtkWidget *widget)
7875 GtkWidgetPrivate *priv;
7877 g_return_if_fail (GTK_IS_WIDGET (widget));
7879 priv = widget->priv;
7881 if (priv->style == gtk_widget_get_default_style ())
7885 g_object_unref (priv->style);
7887 style = g_object_new (GTK_TYPE_STYLE,
7888 "context", gtk_widget_get_style_context (widget),
7891 priv->style = g_object_ref (style);
7893 g_signal_emit (widget,
7894 widget_signals[STYLE_SET],
7897 g_object_unref (style);
7902 * gtk_widget_get_style:
7903 * @widget: a #GtkWidget
7905 * Simply an accessor function that returns @widget->style.
7907 * Return value: (transfer none): the widget's #GtkStyle
7909 * Deprecated:3.0: Use #GtkStyleContext instead
7912 gtk_widget_get_style (GtkWidget *widget)
7914 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7916 return widget->priv->style;
7920 * gtk_widget_modify_style:
7921 * @widget: a #GtkWidget
7922 * @style: the #GtkRcStyle holding the style modifications
7924 * Modifies style values on the widget.
7926 * Modifications made using this technique take precedence over
7927 * style values set via an RC file, however, they will be overridden
7928 * if a style is explicitely set on the widget using gtk_widget_set_style().
7929 * The #GtkRcStyle structure is designed so each field can either be
7930 * set or unset, so it is possible, using this function, to modify some
7931 * style values and leave the others unchanged.
7933 * Note that modifications made with this function are not cumulative
7934 * with previous calls to gtk_widget_modify_style() or with such
7935 * functions as gtk_widget_modify_fg(). If you wish to retain
7936 * previous values, you must first call gtk_widget_get_modifier_style(),
7937 * make your modifications to the returned style, then call
7938 * gtk_widget_modify_style() with that style. On the other hand,
7939 * if you first call gtk_widget_modify_style(), subsequent calls
7940 * to such functions gtk_widget_modify_fg() will have a cumulative
7941 * effect with the initial modifications.
7943 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7946 gtk_widget_modify_style (GtkWidget *widget,
7949 g_return_if_fail (GTK_IS_WIDGET (widget));
7950 g_return_if_fail (GTK_IS_RC_STYLE (style));
7952 g_object_set_qdata_full (G_OBJECT (widget),
7954 gtk_rc_style_copy (style),
7955 (GDestroyNotify) g_object_unref);
7959 * gtk_widget_get_modifier_style:
7960 * @widget: a #GtkWidget
7962 * Returns the current modifier style for the widget. (As set by
7963 * gtk_widget_modify_style().) If no style has previously set, a new
7964 * #GtkRcStyle will be created with all values unset, and set as the
7965 * modifier style for the widget. If you make changes to this rc
7966 * style, you must call gtk_widget_modify_style(), passing in the
7967 * returned rc style, to make sure that your changes take effect.
7969 * Caution: passing the style back to gtk_widget_modify_style() will
7970 * normally end up destroying it, because gtk_widget_modify_style() copies
7971 * the passed-in style and sets the copy as the new modifier style,
7972 * thus dropping any reference to the old modifier style. Add a reference
7973 * to the modifier style if you want to keep it alive.
7975 * Return value: (transfer none): the modifier style for the widget.
7976 * This rc style is owned by the widget. If you want to keep a
7977 * pointer to value this around, you must add a refcount using
7980 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7983 gtk_widget_get_modifier_style (GtkWidget *widget)
7985 GtkRcStyle *rc_style;
7987 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7989 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7993 rc_style = gtk_rc_style_new ();
7994 g_object_set_qdata_full (G_OBJECT (widget),
7997 (GDestroyNotify) g_object_unref);
8004 gtk_widget_modify_color_component (GtkWidget *widget,
8005 GtkRcFlags component,
8007 const GdkColor *color)
8009 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
8016 rc_style->fg[state] = *color;
8019 rc_style->bg[state] = *color;
8022 rc_style->text[state] = *color;
8025 rc_style->base[state] = *color;
8028 g_assert_not_reached();
8031 rc_style->color_flags[state] |= component;
8034 rc_style->color_flags[state] &= ~component;
8036 gtk_widget_modify_style (widget, rc_style);
8040 modifier_style_changed (GtkModifierStyle *style,
8043 GtkStyleContext *context;
8045 context = gtk_widget_get_style_context (widget);
8046 gtk_style_context_invalidate (context);
8049 static GtkModifierStyle *
8050 _gtk_widget_get_modifier_properties (GtkWidget *widget)
8052 GtkModifierStyle *style;
8054 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
8056 if (G_UNLIKELY (!style))
8058 GtkStyleContext *context;
8060 style = _gtk_modifier_style_new ();
8061 g_object_set_qdata_full (G_OBJECT (widget),
8062 quark_modifier_style,
8064 (GDestroyNotify) g_object_unref);
8066 g_signal_connect (style, "changed",
8067 G_CALLBACK (modifier_style_changed), widget);
8069 context = gtk_widget_get_style_context (widget);
8071 gtk_style_context_add_provider (context,
8072 GTK_STYLE_PROVIDER (style),
8073 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
8080 * gtk_widget_override_color:
8081 * @widget: a #GtkWidget
8082 * @state: the state for which to set the color
8083 * @color: the color to assign, or %NULL to undo the effect
8084 * of previous calls to gtk_widget_override_color()
8086 * Sets the color to use for a widget.
8088 * All other style values are left untouched.
8091 * This API is mostly meant as a quick way for applications to
8092 * change a widget appearance. If you are developing a widgets
8093 * library and intend this change to be themeable, it is better
8094 * done by setting meaningful CSS classes and regions in your
8095 * widget/container implementation through gtk_style_context_add_class()
8096 * and gtk_style_context_add_region().
8098 * This way, your widget library can install a #GtkCssProvider
8099 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
8100 * to provide a default styling for those widgets that need so, and
8101 * this theming may fully overridden by the user's theme.
8104 * Note that for complex widgets this may bring in undesired
8105 * results (such as uniform background color everywhere), in
8106 * these cases it is better to fully style such widgets through a
8107 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8114 gtk_widget_override_color (GtkWidget *widget,
8115 GtkStateFlags state,
8116 const GdkRGBA *color)
8118 GtkModifierStyle *style;
8120 g_return_if_fail (GTK_IS_WIDGET (widget));
8122 style = _gtk_widget_get_modifier_properties (widget);
8123 _gtk_modifier_style_set_color (style, state, color);
8127 * gtk_widget_override_background_color:
8128 * @widget: a #GtkWidget
8129 * @state: the state for which to set the background color
8130 * @color: the color to assign, or %NULL to undo the effect
8131 * of previous calls to gtk_widget_override_background_color()
8133 * Sets the background color to use for a widget.
8135 * All other style values are left untouched.
8136 * See gtk_widget_override_color().
8141 gtk_widget_override_background_color (GtkWidget *widget,
8142 GtkStateFlags state,
8143 const GdkRGBA *color)
8145 GtkModifierStyle *style;
8147 g_return_if_fail (GTK_IS_WIDGET (widget));
8149 style = _gtk_widget_get_modifier_properties (widget);
8150 _gtk_modifier_style_set_background_color (style, state, color);
8154 * gtk_widget_override_font:
8155 * @widget: a #GtkWidget
8156 * @font_desc: the font descriptiong to use, or %NULL to undo
8157 * the effect of previous calls to gtk_widget_override_font()
8159 * Sets the font to use for a widget. All other style values are
8160 * left untouched. See gtk_widget_override_color().
8165 gtk_widget_override_font (GtkWidget *widget,
8166 const PangoFontDescription *font_desc)
8168 GtkModifierStyle *style;
8170 g_return_if_fail (GTK_IS_WIDGET (widget));
8172 style = _gtk_widget_get_modifier_properties (widget);
8173 _gtk_modifier_style_set_font (style, font_desc);
8177 * gtk_widget_override_symbolic_color:
8178 * @widget: a #GtkWidget
8179 * @name: the name of the symbolic color to modify
8180 * @color: (allow-none): the color to assign (does not need
8181 * to be allocated), or %NULL to undo the effect of previous
8182 * calls to gtk_widget_override_symbolic_color()
8184 * Sets a symbolic color for a widget.
8186 * All other style values are left untouched.
8187 * See gtk_widget_override_color() for overriding the foreground
8188 * or background color.
8193 gtk_widget_override_symbolic_color (GtkWidget *widget,
8195 const GdkRGBA *color)
8197 GtkModifierStyle *style;
8199 g_return_if_fail (GTK_IS_WIDGET (widget));
8201 style = _gtk_widget_get_modifier_properties (widget);
8202 _gtk_modifier_style_map_color (style, name, color);
8206 * gtk_widget_override_cursor:
8207 * @widget: a #GtkWidget
8208 * @cursor: the color to use for primary cursor (does not need to be
8209 * allocated), or %NULL to undo the effect of previous calls to
8210 * of gtk_widget_override_cursor().
8211 * @secondary_cursor: the color to use for secondary cursor (does not
8212 * need to be allocated), or %NULL to undo the effect of previous
8213 * calls to of gtk_widget_override_cursor().
8215 * Sets the cursor color to use in a widget, overriding the
8216 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8217 * style properties. All other style values are left untouched.
8218 * See also gtk_widget_modify_style().
8220 * Note that the underlying properties have the #GdkColor type,
8221 * so the alpha value in @primary and @secondary will be ignored.
8226 gtk_widget_override_cursor (GtkWidget *widget,
8227 const GdkRGBA *cursor,
8228 const GdkRGBA *secondary_cursor)
8230 GtkModifierStyle *style;
8232 g_return_if_fail (GTK_IS_WIDGET (widget));
8234 style = _gtk_widget_get_modifier_properties (widget);
8235 _gtk_modifier_style_set_color_property (style,
8237 "cursor-color", cursor);
8238 _gtk_modifier_style_set_color_property (style,
8240 "secondary-cursor-color",
8245 * gtk_widget_modify_fg:
8246 * @widget: a #GtkWidget
8247 * @state: the state for which to set the foreground color
8248 * @color: (allow-none): the color to assign (does not need to be allocated),
8249 * or %NULL to undo the effect of previous calls to
8250 * of gtk_widget_modify_fg().
8252 * Sets the foreground color for a widget in a particular state.
8254 * All other style values are left untouched.
8255 * See also gtk_widget_modify_style().
8257 * Deprecated:3.0: Use gtk_widget_override_color() instead
8260 gtk_widget_modify_fg (GtkWidget *widget,
8262 const GdkColor *color)
8264 GtkStateFlags flags;
8267 g_return_if_fail (GTK_IS_WIDGET (widget));
8268 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8272 case GTK_STATE_ACTIVE:
8273 flags = GTK_STATE_FLAG_ACTIVE;
8275 case GTK_STATE_PRELIGHT:
8276 flags = GTK_STATE_FLAG_PRELIGHT;
8278 case GTK_STATE_SELECTED:
8279 flags = GTK_STATE_FLAG_SELECTED;
8281 case GTK_STATE_INSENSITIVE:
8282 flags = GTK_STATE_FLAG_INSENSITIVE;
8284 case GTK_STATE_NORMAL:
8291 rgba.red = color->red / 65535.;
8292 rgba.green = color->green / 65535.;
8293 rgba.blue = color->blue / 65535.;
8296 gtk_widget_override_color (widget, flags, &rgba);
8299 gtk_widget_override_color (widget, flags, NULL);
8303 * gtk_widget_modify_bg:
8304 * @widget: a #GtkWidget
8305 * @state: the state for which to set the background color
8306 * @color: (allow-none): the color to assign (does not need
8307 * to be allocated), or %NULL to undo the effect of previous
8308 * calls to of gtk_widget_modify_bg().
8310 * Sets the background color for a widget in a particular state.
8312 * All other style values are left untouched.
8313 * See also gtk_widget_modify_style().
8316 * Note that "no window" widgets (which have the %GTK_NO_WINDOW
8317 * flag set) draw on their parent container's window and thus may
8318 * not draw any background themselves. This is the case for e.g.
8321 * To modify the background of such widgets, you have to set the
8322 * background color on their parent; if you want to set the background
8323 * of a rectangular area around a label, try placing the label in
8324 * a #GtkEventBox widget and setting the background color on that.
8327 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8330 gtk_widget_modify_bg (GtkWidget *widget,
8332 const GdkColor *color)
8334 GtkStateFlags flags;
8337 g_return_if_fail (GTK_IS_WIDGET (widget));
8338 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8342 case GTK_STATE_ACTIVE:
8343 flags = GTK_STATE_FLAG_ACTIVE;
8345 case GTK_STATE_PRELIGHT:
8346 flags = GTK_STATE_FLAG_PRELIGHT;
8348 case GTK_STATE_SELECTED:
8349 flags = GTK_STATE_FLAG_SELECTED;
8351 case GTK_STATE_INSENSITIVE:
8352 flags = GTK_STATE_FLAG_INSENSITIVE;
8354 case GTK_STATE_NORMAL:
8361 rgba.red = color->red / 65535.;
8362 rgba.green = color->green / 65535.;
8363 rgba.blue = color->blue / 65535.;
8366 gtk_widget_override_background_color (widget, flags, &rgba);
8369 gtk_widget_override_background_color (widget, flags, NULL);
8373 * gtk_widget_modify_text:
8374 * @widget: a #GtkWidget
8375 * @state: the state for which to set the text color
8376 * @color: (allow-none): the color to assign (does not need to
8377 * be allocated), or %NULL to undo the effect of previous
8378 * calls to of gtk_widget_modify_text().
8380 * Sets the text color for a widget in a particular state.
8382 * All other style values are left untouched.
8383 * The text color is the foreground color used along with the
8384 * base color (see gtk_widget_modify_base()) for widgets such
8385 * as #GtkEntry and #GtkTextView.
8386 * See also gtk_widget_modify_style().
8388 * Deprecated:3.0: Use gtk_widget_override_color() instead
8391 gtk_widget_modify_text (GtkWidget *widget,
8393 const GdkColor *color)
8395 g_return_if_fail (GTK_IS_WIDGET (widget));
8396 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8398 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
8402 * gtk_widget_modify_base:
8403 * @widget: a #GtkWidget
8404 * @state: the state for which to set the base color
8405 * @color: (allow-none): the color to assign (does not need to
8406 * be allocated), or %NULL to undo the effect of previous
8407 * calls to of gtk_widget_modify_base().
8409 * Sets the base color for a widget in a particular state.
8410 * All other style values are left untouched. The base color
8411 * is the background color used along with the text color
8412 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
8413 * and #GtkTextView. See also gtk_widget_modify_style().
8416 * Note that "no window" widgets (which have the %GTK_NO_WINDOW
8417 * flag set) draw on their parent container's window and thus may
8418 * not draw any background themselves. This is the case for e.g.
8421 * To modify the background of such widgets, you have to set the
8422 * base color on their parent; if you want to set the background
8423 * of a rectangular area around a label, try placing the label in
8424 * a #GtkEventBox widget and setting the base color on that.
8427 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8430 gtk_widget_modify_base (GtkWidget *widget,
8432 const GdkColor *color)
8434 g_return_if_fail (GTK_IS_WIDGET (widget));
8435 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8437 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
8441 * gtk_widget_modify_cursor:
8442 * @widget: a #GtkWidget
8443 * @primary: the color to use for primary cursor (does not need to be
8444 * allocated), or %NULL to undo the effect of previous calls to
8445 * of gtk_widget_modify_cursor().
8446 * @secondary: the color to use for secondary cursor (does not need to be
8447 * allocated), or %NULL to undo the effect of previous calls to
8448 * of gtk_widget_modify_cursor().
8450 * Sets the cursor color to use in a widget, overriding the
8451 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8454 * All other style values are left untouched.
8455 * See also gtk_widget_modify_style().
8459 * Deprecated: 3.0. Use gtk_widget_override_cursor() instead.
8462 gtk_widget_modify_cursor (GtkWidget *widget,
8463 const GdkColor *primary,
8464 const GdkColor *secondary)
8466 GdkRGBA primary_rgba, secondary_rgba;
8468 g_return_if_fail (GTK_IS_WIDGET (widget));
8470 primary_rgba.red = primary->red / 65535.;
8471 primary_rgba.green = primary->green / 65535.;
8472 primary_rgba.blue = primary->blue / 65535.;
8473 primary_rgba.alpha = 1;
8475 secondary_rgba.red = secondary->red / 65535.;
8476 secondary_rgba.green = secondary->green / 65535.;
8477 secondary_rgba.blue = secondary->blue / 65535.;
8478 secondary_rgba.alpha = 1;
8480 gtk_widget_override_cursor (widget, &primary_rgba, &secondary_rgba);
8484 * gtk_widget_modify_font:
8485 * @widget: a #GtkWidget
8486 * @font_desc: (allow-none): the font description to use, or %NULL
8487 * to undo the effect of previous calls to gtk_widget_modify_font()
8489 * Sets the font to use for a widget.
8491 * All other style values are left untouched.
8492 * See also gtk_widget_modify_style().
8494 * Deprecated:3.0: Use gtk_widget_override_font() instead
8497 gtk_widget_modify_font (GtkWidget *widget,
8498 PangoFontDescription *font_desc)
8500 g_return_if_fail (GTK_IS_WIDGET (widget));
8502 gtk_widget_override_font (widget, font_desc);
8506 gtk_widget_real_direction_changed (GtkWidget *widget,
8507 GtkTextDirection previous_direction)
8509 gtk_widget_queue_resize (widget);
8513 gtk_widget_real_style_set (GtkWidget *widget,
8514 GtkStyle *previous_style)
8519 GtkWidget *previous_toplevel;
8520 GdkScreen *previous_screen;
8521 GdkScreen *new_screen;
8522 } HierarchyChangedInfo;
8525 do_screen_change (GtkWidget *widget,
8526 GdkScreen *old_screen,
8527 GdkScreen *new_screen)
8529 if (old_screen != new_screen)
8531 GtkWidgetPrivate *priv = widget->priv;
8535 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8537 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8540 _gtk_tooltip_hide (widget);
8542 if (new_screen && priv->context)
8543 gtk_style_context_set_screen (priv->context, new_screen);
8545 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8550 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8551 gpointer client_data)
8553 GtkWidgetPrivate *priv = widget->priv;
8554 HierarchyChangedInfo *info = client_data;
8555 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8556 (priv->parent && priv->parent->priv->anchored);
8558 if (priv->anchored != new_anchored)
8560 g_object_ref (widget);
8562 priv->anchored = new_anchored;
8564 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8565 do_screen_change (widget, info->previous_screen, info->new_screen);
8567 if (GTK_IS_CONTAINER (widget))
8568 gtk_container_forall (GTK_CONTAINER (widget),
8569 gtk_widget_propagate_hierarchy_changed_recurse,
8572 g_object_unref (widget);
8577 * _gtk_widget_propagate_hierarchy_changed:
8578 * @widget: a #GtkWidget
8579 * @previous_toplevel: Previous toplevel
8581 * Propagates changes in the anchored state to a widget and all
8582 * children, unsetting or setting the %ANCHORED flag, and
8583 * emitting #GtkWidget::hierarchy-changed.
8586 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8587 GtkWidget *previous_toplevel)
8589 GtkWidgetPrivate *priv = widget->priv;
8590 HierarchyChangedInfo info;
8592 info.previous_toplevel = previous_toplevel;
8593 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8595 if (gtk_widget_is_toplevel (widget) ||
8596 (priv->parent && priv->parent->priv->anchored))
8597 info.new_screen = gtk_widget_get_screen (widget);
8599 info.new_screen = NULL;
8601 if (info.previous_screen)
8602 g_object_ref (info.previous_screen);
8603 if (previous_toplevel)
8604 g_object_ref (previous_toplevel);
8606 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8608 if (previous_toplevel)
8609 g_object_unref (previous_toplevel);
8610 if (info.previous_screen)
8611 g_object_unref (info.previous_screen);
8615 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8616 gpointer client_data)
8618 HierarchyChangedInfo *info = client_data;
8620 g_object_ref (widget);
8622 do_screen_change (widget, info->previous_screen, info->new_screen);
8624 if (GTK_IS_CONTAINER (widget))
8625 gtk_container_forall (GTK_CONTAINER (widget),
8626 gtk_widget_propagate_screen_changed_recurse,
8629 g_object_unref (widget);
8633 * gtk_widget_is_composited:
8634 * @widget: a #GtkWidget
8636 * Whether @widget can rely on having its alpha channel
8637 * drawn correctly. On X11 this function returns whether a
8638 * compositing manager is running for @widget's screen.
8640 * Please note that the semantics of this call will change
8641 * in the future if used on a widget that has a composited
8642 * window in its hierarchy (as set by gdk_window_set_composited()).
8644 * Return value: %TRUE if the widget can rely on its alpha
8645 * channel being drawn correctly.
8650 gtk_widget_is_composited (GtkWidget *widget)
8654 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8656 screen = gtk_widget_get_screen (widget);
8658 return gdk_screen_is_composited (screen);
8662 propagate_composited_changed (GtkWidget *widget,
8665 if (GTK_IS_CONTAINER (widget))
8667 gtk_container_forall (GTK_CONTAINER (widget),
8668 propagate_composited_changed,
8672 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8676 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8678 propagate_composited_changed (widget, NULL);
8682 * _gtk_widget_propagate_screen_changed:
8683 * @widget: a #GtkWidget
8684 * @previous_screen: Previous screen
8686 * Propagates changes in the screen for a widget to all
8687 * children, emitting #GtkWidget::screen-changed.
8690 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8691 GdkScreen *previous_screen)
8693 HierarchyChangedInfo info;
8695 info.previous_screen = previous_screen;
8696 info.new_screen = gtk_widget_get_screen (widget);
8698 if (previous_screen)
8699 g_object_ref (previous_screen);
8701 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8703 if (previous_screen)
8704 g_object_unref (previous_screen);
8708 reset_style_recurse (GtkWidget *widget, gpointer data)
8710 if (widget->priv->context)
8712 _gtk_widget_update_path (widget);
8713 gtk_style_context_set_path (widget->priv->context,
8714 widget->priv->path);
8717 if (GTK_IS_CONTAINER (widget))
8718 gtk_container_forall (GTK_CONTAINER (widget),
8719 reset_style_recurse,
8724 * gtk_widget_reset_style:
8725 * @widget: a #GtkWidget
8727 * Updates the style context of @widget and all descendents
8728 * by updating its widget path. #GtkContainer<!-- -->s may want
8729 * to use this on a child when reordering it in a way that a different
8730 * style might apply to it. See also gtk_container_get_path_for_child().
8735 gtk_widget_reset_style (GtkWidget *widget)
8737 g_return_if_fail (GTK_IS_WIDGET (widget));
8739 reset_style_recurse (widget, NULL);
8743 * gtk_widget_reset_rc_styles:
8744 * @widget: a #GtkWidget.
8746 * Reset the styles of @widget and all descendents, so when
8747 * they are looked up again, they get the correct values
8748 * for the currently loaded RC file settings.
8750 * This function is not useful for applications.
8752 * Deprecated:3.0: Use #GtkStyleContext instead, and gtk_widget_reset_style()
8755 gtk_widget_reset_rc_styles (GtkWidget *widget)
8757 g_return_if_fail (GTK_IS_WIDGET (widget));
8759 reset_style_recurse (widget, NULL);
8763 * gtk_widget_get_default_style:
8765 * Returns the default style used by all widgets initially.
8767 * Returns: (transfer none): the default style. This #GtkStyle
8768 * object is owned by GTK+ and should not be modified or freed.
8770 * Deprecated:3.0: Use #GtkStyleContext instead, and
8771 * gtk_css_provider_get_default() to obtain a #GtkStyleProvider
8772 * with the default widget style information.
8775 gtk_widget_get_default_style (void)
8777 if (!gtk_default_style)
8779 gtk_default_style = gtk_style_new ();
8780 g_object_ref (gtk_default_style);
8783 return gtk_default_style;
8786 #ifdef G_ENABLE_DEBUG
8788 /* Verify invariants, see docs/widget_system.txt for notes on much of
8789 * this. Invariants may be temporarily broken while we're in the
8790 * process of updating state, of course, so you can only
8791 * verify_invariants() after a given operation is complete.
8792 * Use push/pop_verify_invariants to help with that.
8795 gtk_widget_verify_invariants (GtkWidget *widget)
8799 if (widget->priv->verifying_invariants_count > 0)
8802 parent = widget->priv->parent;
8804 if (widget->priv->mapped)
8806 /* Mapped implies ... */
8808 if (!widget->priv->realized)
8809 g_warning ("%s %p is mapped but not realized",
8810 G_OBJECT_TYPE_NAME (widget), widget);
8812 if (!widget->priv->visible)
8813 g_warning ("%s %p is mapped but not visible",
8814 G_OBJECT_TYPE_NAME (widget), widget);
8816 if (!widget->priv->toplevel)
8818 if (!widget->priv->child_visible)
8819 g_warning ("%s %p is mapped but not child_visible",
8820 G_OBJECT_TYPE_NAME (widget), widget);
8825 /* Not mapped implies... */
8828 /* This check makes sense for normal toplevels, but for
8829 * something like a toplevel that is embedded within a clutter
8830 * state, mapping may depend on external factors.
8832 if (widget->priv->toplevel)
8834 if (widget->priv->visible)
8835 g_warning ("%s %p toplevel is visible but not mapped",
8836 G_OBJECT_TYPE_NAME (widget), widget);
8841 /* Parent related checks aren't possible if parent has
8842 * verifying_invariants_count > 0 because parent needs to recurse
8843 * children first before the invariants will hold.
8845 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8848 parent->priv->realized)
8850 /* Parent realized implies... */
8853 /* This is in widget_system.txt but appears to fail
8854 * because there's no gtk_container_realize() that
8855 * realizes all children... instead we just lazily
8856 * wait for map to fix things up.
8858 if (!widget->priv->realized)
8859 g_warning ("%s %p is realized but child %s %p is not realized",
8860 G_OBJECT_TYPE_NAME (parent), parent,
8861 G_OBJECT_TYPE_NAME (widget), widget);
8864 else if (!widget->priv->toplevel)
8866 /* No parent or parent not realized on non-toplevel implies... */
8868 if (widget->priv->realized && !widget->priv->in_reparent)
8869 g_warning ("%s %p is not realized but child %s %p is realized",
8870 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8871 G_OBJECT_TYPE_NAME (widget), widget);
8875 parent->priv->mapped &&
8876 widget->priv->visible &&
8877 widget->priv->child_visible)
8879 /* Parent mapped and we are visible implies... */
8881 if (!widget->priv->mapped)
8882 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8883 G_OBJECT_TYPE_NAME (parent), parent,
8884 G_OBJECT_TYPE_NAME (widget), widget);
8886 else if (!widget->priv->toplevel)
8888 /* No parent or parent not mapped on non-toplevel implies... */
8890 if (widget->priv->mapped && !widget->priv->in_reparent)
8891 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8892 G_OBJECT_TYPE_NAME (widget), widget,
8893 widget->priv->visible,
8894 widget->priv->child_visible,
8895 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8896 parent ? parent->priv->mapped : FALSE);
8900 if (!widget->priv->realized)
8902 /* Not realized implies... */
8905 /* widget_system.txt says these hold, but they don't. */
8906 if (widget->priv->resize_pending)
8907 g_warning ("%s %p resize pending but not realized",
8908 G_OBJECT_TYPE_NAME (widget), widget);
8910 if (widget->priv->alloc_needed)
8911 g_warning ("%s %p alloc needed but not realized",
8912 G_OBJECT_TYPE_NAME (widget), widget);
8914 if (widget->priv->width_request_needed)
8915 g_warning ("%s %p width request needed but not realized",
8916 G_OBJECT_TYPE_NAME (widget), widget);
8918 if (widget->priv->height_request_needed)
8919 g_warning ("%s %p height request needed but not realized",
8920 G_OBJECT_TYPE_NAME (widget), widget);
8925 /* The point of this push/pop is that invariants may not hold while
8926 * we're busy making changes. So we only check at the outermost call
8927 * on the call stack, after we finish updating everything.
8930 gtk_widget_push_verify_invariants (GtkWidget *widget)
8932 widget->priv->verifying_invariants_count += 1;
8936 gtk_widget_verify_child_invariants (GtkWidget *widget,
8937 gpointer client_data)
8939 /* We don't recurse further; this is a one-level check. */
8940 gtk_widget_verify_invariants (widget);
8944 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8946 g_assert (widget->priv->verifying_invariants_count > 0);
8948 widget->priv->verifying_invariants_count -= 1;
8950 if (widget->priv->verifying_invariants_count == 0)
8952 gtk_widget_verify_invariants (widget);
8954 if (GTK_IS_CONTAINER (widget))
8956 /* Check one level of children, because our
8957 * push_verify_invariants() will have prevented some of the
8958 * checks. This does not recurse because if recursion is
8959 * needed, it will happen naturally as each child has a
8960 * push/pop on that child. For example if we're recursively
8961 * mapping children, we'll push/pop on each child as we map
8964 gtk_container_forall (GTK_CONTAINER (widget),
8965 gtk_widget_verify_child_invariants,
8970 #endif /* G_ENABLE_DEBUG */
8972 static PangoContext *
8973 gtk_widget_peek_pango_context (GtkWidget *widget)
8975 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8979 * gtk_widget_get_pango_context:
8980 * @widget: a #GtkWidget
8982 * Gets a #PangoContext with the appropriate font map, font description,
8983 * and base direction for this widget. Unlike the context returned
8984 * by gtk_widget_create_pango_context(), this context is owned by
8985 * the widget (it can be used until the screen for the widget changes
8986 * or the widget is removed from its toplevel), and will be updated to
8987 * match any changes to the widget's attributes.
8989 * If you create and keep a #PangoLayout using this context, you must
8990 * deal with changes to the context by calling pango_layout_context_changed()
8991 * on the layout in response to the #GtkWidget::style-updated and
8992 * #GtkWidget::direction-changed signals for the widget.
8994 * Return value: (transfer none): the #PangoContext for the widget.
8997 gtk_widget_get_pango_context (GtkWidget *widget)
8999 PangoContext *context;
9001 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9003 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
9006 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
9007 g_object_set_qdata_full (G_OBJECT (widget),
9008 quark_pango_context,
9017 update_pango_context (GtkWidget *widget,
9018 PangoContext *context)
9020 PangoFontDescription *font_desc;
9021 GtkStyleContext *style_context;
9023 style_context = gtk_widget_get_style_context (widget);
9025 gtk_style_context_get (style_context,
9026 gtk_widget_get_state_flags (widget),
9030 pango_context_set_font_description (context, font_desc);
9031 pango_context_set_base_dir (context,
9032 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
9033 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
9035 pango_font_description_free (font_desc);
9039 gtk_widget_update_pango_context (GtkWidget *widget)
9041 PangoContext *context = gtk_widget_peek_pango_context (widget);
9047 update_pango_context (widget, context);
9049 screen = gtk_widget_get_screen_unchecked (widget);
9052 pango_cairo_context_set_resolution (context,
9053 gdk_screen_get_resolution (screen));
9054 pango_cairo_context_set_font_options (context,
9055 gdk_screen_get_font_options (screen));
9061 * gtk_widget_create_pango_context:
9062 * @widget: a #GtkWidget
9064 * Creates a new #PangoContext with the appropriate font map,
9065 * font description, and base direction for drawing text for
9066 * this widget. See also gtk_widget_get_pango_context().
9068 * Return value: (transfer full): the new #PangoContext
9071 gtk_widget_create_pango_context (GtkWidget *widget)
9074 PangoContext *context;
9076 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9078 screen = gtk_widget_get_screen_unchecked (widget);
9081 GTK_NOTE (MULTIHEAD,
9082 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
9084 screen = gdk_screen_get_default ();
9087 context = gdk_pango_context_get_for_screen (screen);
9089 update_pango_context (widget, context);
9090 pango_context_set_language (context, gtk_get_default_language ());
9096 * gtk_widget_create_pango_layout:
9097 * @widget: a #GtkWidget
9098 * @text: text to set on the layout (can be %NULL)
9100 * Creates a new #PangoLayout with the appropriate font map,
9101 * font description, and base direction for drawing text for
9104 * If you keep a #PangoLayout created in this way around, in order to
9105 * notify the layout of changes to the base direction or font of this
9106 * widget, you must call pango_layout_context_changed() in response to
9107 * the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
9110 * Return value: (transfer full): the new #PangoLayout
9113 gtk_widget_create_pango_layout (GtkWidget *widget,
9116 PangoLayout *layout;
9117 PangoContext *context;
9119 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9121 context = gtk_widget_get_pango_context (widget);
9122 layout = pango_layout_new (context);
9125 pango_layout_set_text (layout, text, -1);
9131 * gtk_widget_render_icon_pixbuf:
9132 * @widget: a #GtkWidget
9133 * @stock_id: a stock ID
9134 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
9135 * render at the size of the source and don't scale (if there are
9136 * multiple source sizes, GTK+ picks one of the available sizes).
9138 * A convenience function that uses the theme engine and style
9139 * settings for @widget to look up @stock_id and render it to
9140 * a pixbuf. @stock_id should be a stock icon ID such as
9141 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
9142 * such as #GTK_ICON_SIZE_MENU.
9144 * The pixels in the returned #GdkPixbuf are shared with the rest of
9145 * the application and should not be modified. The pixbuf should be freed
9146 * after use with g_object_unref().
9148 * Return value: (transfer full): a new pixbuf, or %NULL if the
9149 * stock ID wasn't known
9154 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
9155 const gchar *stock_id,
9158 GtkStyleContext *context;
9159 GtkIconSet *icon_set;
9161 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9162 g_return_val_if_fail (stock_id != NULL, NULL);
9163 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
9165 context = gtk_widget_get_style_context (widget);
9166 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
9168 if (icon_set == NULL)
9171 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
9175 * gtk_widget_render_icon:
9176 * @widget: a #GtkWidget
9177 * @stock_id: a stock ID
9178 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
9179 * render at the size of the source and don't scale (if there are
9180 * multiple source sizes, GTK+ picks one of the available sizes).
9181 * @detail: (allow-none): render detail to pass to theme engine
9183 * A convenience function that uses the theme settings for @widget
9184 * to look up @stock_id and render it to a pixbuf. @stock_id should
9185 * be a stock icon ID such as #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size
9186 * should be a size such as #GTK_ICON_SIZE_MENU. @detail should be a
9187 * string that identifies the widget or code doing the rendering, so
9188 * that theme engines can special-case rendering for that widget or
9191 * The pixels in the returned #GdkPixbuf are shared with the rest of
9192 * the application and should not be modified. The pixbuf should be
9193 * freed after use with g_object_unref().
9195 * Return value: (transfer full): a new pixbuf, or %NULL if the
9196 * stock ID wasn't known
9198 * Deprecated: 3.0: Use gtk_widget_render_icon_pixbuf() instead.
9201 gtk_widget_render_icon (GtkWidget *widget,
9202 const gchar *stock_id,
9204 const gchar *detail)
9206 return gtk_widget_render_icon_pixbuf (widget, stock_id, size);
9210 * gtk_widget_set_parent_window:
9211 * @widget: a #GtkWidget.
9212 * @parent_window: the new parent window.
9214 * Sets a non default parent window for @widget.
9216 * For GtkWindow classes, setting a @parent_window effects whether
9217 * the window is a toplevel window or can be embedded into other
9221 * For GtkWindow classes, this needs to be called before the
9222 * window is realized.
9227 gtk_widget_set_parent_window (GtkWidget *widget,
9228 GdkWindow *parent_window)
9230 GdkWindow *old_parent_window;
9232 g_return_if_fail (GTK_IS_WIDGET (widget));
9234 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
9235 quark_parent_window);
9237 if (parent_window != old_parent_window)
9241 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
9243 if (old_parent_window)
9244 g_object_unref (old_parent_window);
9246 g_object_ref (parent_window);
9248 /* Unset toplevel flag when adding a parent window to a widget,
9249 * this is the primary entry point to allow toplevels to be
9252 #ifdef GDK_WINDOWING_X11
9253 is_plug = GTK_IS_PLUG (widget);
9257 if (GTK_IS_WINDOW (widget) && !is_plug)
9258 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
9263 * gtk_widget_get_parent_window:
9264 * @widget: a #GtkWidget.
9266 * Gets @widget's parent window.
9268 * Returns: (transfer none): the parent window of @widget.
9271 gtk_widget_get_parent_window (GtkWidget *widget)
9273 GtkWidgetPrivate *priv;
9274 GdkWindow *parent_window;
9276 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9278 priv = widget->priv;
9280 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
9282 return (parent_window != NULL) ? parent_window :
9283 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
9288 * gtk_widget_set_child_visible:
9289 * @widget: a #GtkWidget
9290 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
9292 * Sets whether @widget should be mapped along with its when its parent
9293 * is mapped and @widget has been shown with gtk_widget_show().
9295 * The child visibility can be set for widget before it is added to
9296 * a container with gtk_widget_set_parent(), to avoid mapping
9297 * children unnecessary before immediately unmapping them. However
9298 * it will be reset to its default state of %TRUE when the widget
9299 * is removed from a container.
9301 * Note that changing the child visibility of a widget does not
9302 * queue a resize on the widget. Most of the time, the size of
9303 * a widget is computed from all visible children, whether or
9304 * not they are mapped. If this is not the case, the container
9305 * can queue a resize itself.
9307 * This function is only useful for container implementations and
9308 * never should be called by an application.
9311 gtk_widget_set_child_visible (GtkWidget *widget,
9312 gboolean is_visible)
9314 GtkWidgetPrivate *priv;
9316 g_return_if_fail (GTK_IS_WIDGET (widget));
9317 g_return_if_fail (!gtk_widget_is_toplevel (widget));
9319 priv = widget->priv;
9321 g_object_ref (widget);
9322 gtk_widget_verify_invariants (widget);
9325 priv->child_visible = TRUE;
9328 GtkWidget *toplevel;
9330 priv->child_visible = FALSE;
9332 toplevel = gtk_widget_get_toplevel (widget);
9333 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
9334 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
9337 if (priv->parent && gtk_widget_get_realized (priv->parent))
9339 if (gtk_widget_get_mapped (priv->parent) &&
9340 priv->child_visible &&
9341 gtk_widget_get_visible (widget))
9342 gtk_widget_map (widget);
9344 gtk_widget_unmap (widget);
9347 gtk_widget_verify_invariants (widget);
9348 g_object_unref (widget);
9352 * gtk_widget_get_child_visible:
9353 * @widget: a #GtkWidget
9355 * Gets the value set with gtk_widget_set_child_visible().
9356 * If you feel a need to use this function, your code probably
9357 * needs reorganization.
9359 * This function is only useful for container implementations and
9360 * never should be called by an application.
9362 * Return value: %TRUE if the widget is mapped with the parent.
9365 gtk_widget_get_child_visible (GtkWidget *widget)
9367 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9369 return widget->priv->child_visible;
9373 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9375 GtkWidget *toplevel;
9377 toplevel = gtk_widget_get_toplevel (widget);
9379 if (gtk_widget_is_toplevel (toplevel))
9381 if (GTK_IS_WINDOW (toplevel))
9382 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9383 else if (GTK_IS_INVISIBLE (toplevel))
9384 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9391 * gtk_widget_get_screen:
9392 * @widget: a #GtkWidget
9394 * Get the #GdkScreen from the toplevel window associated with
9395 * this widget. This function can only be called after the widget
9396 * has been added to a widget hierarchy with a #GtkWindow
9399 * In general, you should only create screen specific
9400 * resources when a widget has been realized, and you should
9401 * free those resources when the widget is unrealized.
9403 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9408 gtk_widget_get_screen (GtkWidget *widget)
9412 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9414 screen = gtk_widget_get_screen_unchecked (widget);
9421 g_warning (G_STRLOC ": Can't get associated screen"
9422 " for a widget unless it is inside a toplevel GtkWindow\n"
9423 " widget type is %s associated top level type is %s",
9424 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9425 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9427 return gdk_screen_get_default ();
9432 * gtk_widget_has_screen:
9433 * @widget: a #GtkWidget
9435 * Checks whether there is a #GdkScreen is associated with
9436 * this widget. All toplevel widgets have an associated
9437 * screen, and all widgets added into a hierarchy with a toplevel
9438 * window at the top.
9440 * Return value: %TRUE if there is a #GdkScreen associcated
9446 gtk_widget_has_screen (GtkWidget *widget)
9448 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9450 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9454 * gtk_widget_get_display:
9455 * @widget: a #GtkWidget
9457 * Get the #GdkDisplay for the toplevel window associated with
9458 * this widget. This function can only be called after the widget
9459 * has been added to a widget hierarchy with a #GtkWindow at the top.
9461 * In general, you should only create display specific
9462 * resources when a widget has been realized, and you should
9463 * free those resources when the widget is unrealized.
9465 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9470 gtk_widget_get_display (GtkWidget *widget)
9472 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9474 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9478 * gtk_widget_get_root_window:
9479 * @widget: a #GtkWidget
9481 * Get the root window where this widget is located. This function can
9482 * only be called after the widget has been added to a widget
9483 * hierarchy with #GtkWindow at the top.
9485 * The root window is useful for such purposes as creating a popup
9486 * #GdkWindow associated with the window. In general, you should only
9487 * create display specific resources when a widget has been realized,
9488 * and you should free those resources when the widget is unrealized.
9490 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9495 gtk_widget_get_root_window (GtkWidget *widget)
9497 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9499 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9503 * gtk_widget_child_focus:
9504 * @widget: a #GtkWidget
9505 * @direction: direction of focus movement
9507 * This function is used by custom widget implementations; if you're
9508 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9509 * to a particular widget, and gtk_container_set_focus_chain() to
9510 * change the focus tab order. So you may want to investigate those
9511 * functions instead.
9513 * gtk_widget_child_focus() is called by containers as the user moves
9514 * around the window using keyboard shortcuts. @direction indicates
9515 * what kind of motion is taking place (up, down, left, right, tab
9516 * forward, tab backward). gtk_widget_child_focus() emits the
9517 * #GtkWidget::focus signal; widgets override the default handler
9518 * for this signal in order to implement appropriate focus behavior.
9520 * The default ::focus handler for a widget should return %TRUE if
9521 * moving in @direction left the focus on a focusable location inside
9522 * that widget, and %FALSE if moving in @direction moved the focus
9523 * outside the widget. If returning %TRUE, widgets normally
9524 * call gtk_widget_grab_focus() to place the focus accordingly;
9525 * if returning %FALSE, they don't modify the current focus location.
9527 * Return value: %TRUE if focus ended up inside @widget
9530 gtk_widget_child_focus (GtkWidget *widget,
9531 GtkDirectionType direction)
9533 gboolean return_val;
9535 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9537 if (!gtk_widget_get_visible (widget) ||
9538 !gtk_widget_is_sensitive (widget))
9541 /* child widgets must set CAN_FOCUS, containers
9542 * don't have to though.
9544 if (!GTK_IS_CONTAINER (widget) &&
9545 !gtk_widget_get_can_focus (widget))
9548 g_signal_emit (widget,
9549 widget_signals[FOCUS],
9551 direction, &return_val);
9557 * gtk_widget_keynav_failed:
9558 * @widget: a #GtkWidget
9559 * @direction: direction of focus movement
9561 * This function should be called whenever keyboard navigation within
9562 * a single widget hits a boundary. The function emits the
9563 * #GtkWidget::keynav-failed signal on the widget and its return
9564 * value should be interpreted in a way similar to the return value of
9565 * gtk_widget_child_focus():
9567 * When %TRUE is returned, stay in the widget, the failed keyboard
9568 * navigation is Ok and/or there is nowhere we can/should move the
9571 * When %FALSE is returned, the caller should continue with keyboard
9572 * navigation outside the widget, e.g. by calling
9573 * gtk_widget_child_focus() on the widget's toplevel.
9575 * The default ::keynav-failed handler returns %TRUE for
9576 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9577 * values of #GtkDirectionType, it looks at the
9578 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9579 * if the setting is %TRUE. This way the entire user interface
9580 * becomes cursor-navigatable on input devices such as mobile phones
9581 * which only have cursor keys but no tab key.
9583 * Whenever the default handler returns %TRUE, it also calls
9584 * gtk_widget_error_bell() to notify the user of the failed keyboard
9587 * A use case for providing an own implementation of ::keynav-failed
9588 * (either by connecting to it or by overriding it) would be a row of
9589 * #GtkEntry widgets where the user should be able to navigate the
9590 * entire row with the cursor keys, as e.g. known from user interfaces
9591 * that require entering license keys.
9593 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9594 * if the emitting widget should try to handle the keyboard
9595 * navigation attempt in its parent container(s).
9600 gtk_widget_keynav_failed (GtkWidget *widget,
9601 GtkDirectionType direction)
9603 gboolean return_val;
9605 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9607 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9608 direction, &return_val);
9614 * gtk_widget_error_bell:
9615 * @widget: a #GtkWidget
9617 * Notifies the user about an input-related error on this widget.
9618 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9619 * gdk_window_beep(), otherwise it does nothing.
9621 * Note that the effect of gdk_window_beep() can be configured in many
9622 * ways, depending on the windowing backend and the desktop environment
9623 * or window manager that is used.
9628 gtk_widget_error_bell (GtkWidget *widget)
9630 GtkWidgetPrivate *priv;
9631 GtkSettings* settings;
9634 g_return_if_fail (GTK_IS_WIDGET (widget));
9636 priv = widget->priv;
9638 settings = gtk_widget_get_settings (widget);
9642 g_object_get (settings,
9643 "gtk-error-bell", &beep,
9646 if (beep && priv->window)
9647 gdk_window_beep (priv->window);
9651 gtk_widget_set_usize_internal (GtkWidget *widget,
9654 GtkQueueResizeFlags flags)
9656 GtkWidgetAuxInfo *aux_info;
9657 gboolean changed = FALSE;
9659 g_object_freeze_notify (G_OBJECT (widget));
9661 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
9663 if (width > -2 && aux_info->width != width)
9665 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9666 g_object_notify (G_OBJECT (widget), "width-request");
9667 aux_info->width = width;
9670 if (height > -2 && aux_info->height != height)
9672 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9673 g_object_notify (G_OBJECT (widget), "height-request");
9674 aux_info->height = height;
9678 if (gtk_widget_get_visible (widget) && changed)
9680 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9681 gtk_widget_queue_resize (widget);
9683 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9686 g_object_thaw_notify (G_OBJECT (widget));
9690 * gtk_widget_set_size_request:
9691 * @widget: a #GtkWidget
9692 * @width: width @widget should request, or -1 to unset
9693 * @height: height @widget should request, or -1 to unset
9695 * Sets the minimum size of a widget; that is, the widget's size
9696 * request will be @width by @height. You can use this function to
9697 * force a widget to be either larger or smaller than it normally
9700 * In most cases, gtk_window_set_default_size() is a better choice for
9701 * toplevel windows than this function; setting the default size will
9702 * still allow users to shrink the window. Setting the size request
9703 * will force them to leave the window at least as large as the size
9704 * request. When dealing with window sizes,
9705 * gtk_window_set_geometry_hints() can be a useful function as well.
9707 * Note the inherent danger of setting any fixed size - themes,
9708 * translations into other languages, different fonts, and user action
9709 * can all change the appropriate size for a given widget. So, it's
9710 * basically impossible to hardcode a size that will always be
9713 * The size request of a widget is the smallest size a widget can
9714 * accept while still functioning well and drawing itself correctly.
9715 * However in some strange cases a widget may be allocated less than
9716 * its requested size, and in many cases a widget may be allocated more
9717 * space than it requested.
9719 * If the size request in a given direction is -1 (unset), then
9720 * the "natural" size request of the widget will be used instead.
9722 * Widgets can't actually be allocated a size less than 1 by 1, but
9723 * you can pass 0,0 to this function to mean "as small as possible."
9725 * The size request set here does not include any margin from the
9726 * #GtkWidget properties margin-left, margin-right, margin-top, and
9727 * margin-bottom, but it does include pretty much all other padding
9728 * or border properties set by any subclass of #GtkWidget.
9731 gtk_widget_set_size_request (GtkWidget *widget,
9735 g_return_if_fail (GTK_IS_WIDGET (widget));
9736 g_return_if_fail (width >= -1);
9737 g_return_if_fail (height >= -1);
9744 gtk_widget_set_usize_internal (widget, width, height, 0);
9749 * gtk_widget_get_size_request:
9750 * @widget: a #GtkWidget
9751 * @width: (out) (allow-none): return location for width, or %NULL
9752 * @height: (out) (allow-none): return location for height, or %NULL
9754 * Gets the size request that was explicitly set for the widget using
9755 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9756 * @height indicates that that dimension has not been set explicitly
9757 * and the natural requisition of the widget will be used intead. See
9758 * gtk_widget_set_size_request(). To get the size a widget will
9759 * actually request, call gtk_widget_get_preferred_size() instead of
9763 gtk_widget_get_size_request (GtkWidget *widget,
9767 const GtkWidgetAuxInfo *aux_info;
9769 g_return_if_fail (GTK_IS_WIDGET (widget));
9771 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9774 *width = aux_info->width;
9777 *height = aux_info->height;
9781 * _gtk_widget_override_size_request:
9782 * @widget: a #GtkWidget
9783 * @width: new forced minimum width
9784 * @height: new forced minimum height
9785 * @old_width: location to store previous forced minimum width
9786 * @old_width: location to store previous forced minumum height
9788 * Temporarily establishes a forced minimum size for a widget; this
9789 * is used by GtkWindow when calculating the size to add to the
9790 * window's geometry widget. Cached sizes for the widget and its
9791 * parents are invalidated, so that subsequent calls to the size
9792 * negotiation machinery produce the overriden result, but the
9793 * widget is not queued for relayout or redraw. The old size must
9794 * be restored with _gtk_widget_restore_size_request() or things
9798 _gtk_widget_override_size_request (GtkWidget *widget,
9804 gtk_widget_get_size_request (widget, old_width, old_height);
9805 gtk_widget_set_usize_internal (widget, width, height,
9806 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9810 * _gtk_widget_restore_size_request:
9811 * @widget: a #GtkWidget
9812 * @old_width: saved forced minimum size
9813 * @old_height: saved forced minimum size
9815 * Undoes the operation of_gtk_widget_override_size_request().
9818 _gtk_widget_restore_size_request (GtkWidget *widget,
9822 gtk_widget_set_usize_internal (widget, old_width, old_height,
9823 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9827 * gtk_widget_set_events:
9828 * @widget: a #GtkWidget
9829 * @events: event mask
9831 * Sets the event mask (see #GdkEventMask) for a widget. The event
9832 * mask determines which events a widget will receive. Keep in mind
9833 * that different widgets have different default event masks, and by
9834 * changing the event mask you may disrupt a widget's functionality,
9835 * so be careful. This function must be called while a widget is
9836 * unrealized. Consider gtk_widget_add_events() for widgets that are
9837 * already realized, or if you want to preserve the existing event
9838 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9839 * to get events on those widgets, place them inside a #GtkEventBox
9840 * and receive events on the event box.
9843 gtk_widget_set_events (GtkWidget *widget,
9846 g_return_if_fail (GTK_IS_WIDGET (widget));
9847 g_return_if_fail (!gtk_widget_get_realized (widget));
9849 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9850 GINT_TO_POINTER (events));
9851 g_object_notify (G_OBJECT (widget), "events");
9855 * gtk_widget_set_device_events:
9856 * @widget: a #GtkWidget
9857 * @device: a #GdkDevice
9858 * @events: event mask
9860 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9861 * mask determines which events a widget will receive from @device. Keep
9862 * in mind that different widgets have different default event masks, and by
9863 * changing the event mask you may disrupt a widget's functionality,
9864 * so be careful. This function must be called while a widget is
9865 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9866 * already realized, or if you want to preserve the existing event
9867 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9868 * to get events on those widgets, place them inside a #GtkEventBox
9869 * and receive events on the event box.
9874 gtk_widget_set_device_events (GtkWidget *widget,
9876 GdkEventMask events)
9878 GHashTable *device_events;
9880 g_return_if_fail (GTK_IS_WIDGET (widget));
9881 g_return_if_fail (GDK_IS_DEVICE (device));
9882 g_return_if_fail (!gtk_widget_get_realized (widget));
9884 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9886 if (G_UNLIKELY (!device_events))
9888 device_events = g_hash_table_new (NULL, NULL);
9889 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9890 (GDestroyNotify) g_hash_table_unref);
9893 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9897 * gtk_widget_set_device_enabled:
9898 * @widget: a #GtkWidget
9899 * @device: a #GdkDevice
9900 * @enabled: whether to enable the device
9902 * Enables or disables a #GdkDevice to interact with @widget
9903 * and all its children.
9905 * It does so by descending through the #GdkWindow hierarchy
9906 * and enabling the same mask that is has for core events
9907 * (i.e. the one that gdk_window_get_events() returns).
9912 gtk_widget_set_device_enabled (GtkWidget *widget,
9916 GList *enabled_devices;
9918 g_return_if_fail (GTK_IS_WIDGET (widget));
9919 g_return_if_fail (GDK_IS_DEVICE (device));
9921 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9922 enabled_devices = g_list_append (enabled_devices, device);
9924 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9925 enabled_devices, (GDestroyNotify) g_list_free);;
9927 if (gtk_widget_get_realized (widget))
9928 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9932 * gtk_widget_get_device_enabled:
9933 * @widget: a #GtkWidget
9934 * @device: a #GdkDevice
9936 * Returns whether @device can interact with @widget and its
9937 * children. See gtk_widget_set_device_enabled().
9939 * Return value: %TRUE is @device is enabled for @widget
9944 gtk_widget_get_device_enabled (GtkWidget *widget,
9947 GList *enabled_devices;
9949 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9950 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9952 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9954 return g_list_find (enabled_devices, device) != NULL;
9958 gtk_widget_add_events_internal_list (GtkWidget *widget,
9965 for (l = window_list; l != NULL; l = l->next)
9967 GdkWindow *window = l->data;
9970 gdk_window_get_user_data (window, &user_data);
9971 if (user_data == widget)
9976 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9978 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9980 children = gdk_window_get_children (window);
9981 gtk_widget_add_events_internal_list (widget, device, events, children);
9982 g_list_free (children);
9988 gtk_widget_add_events_internal (GtkWidget *widget,
9992 GtkWidgetPrivate *priv = widget->priv;
9995 if (!gtk_widget_get_has_window (widget))
9996 window_list = gdk_window_get_children (priv->window);
9998 window_list = g_list_prepend (NULL, priv->window);
10000 gtk_widget_add_events_internal_list (widget, device, events, window_list);
10002 g_list_free (window_list);
10006 * gtk_widget_add_events:
10007 * @widget: a #GtkWidget
10008 * @events: an event mask, see #GdkEventMask
10010 * Adds the events in the bitfield @events to the event mask for
10011 * @widget. See gtk_widget_set_events() for details.
10014 gtk_widget_add_events (GtkWidget *widget,
10019 g_return_if_fail (GTK_IS_WIDGET (widget));
10021 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10022 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
10023 GINT_TO_POINTER (old_events | events));
10025 if (gtk_widget_get_realized (widget))
10027 gtk_widget_add_events_internal (widget, NULL, events);
10028 gtk_widget_update_devices_mask (widget, FALSE);
10031 g_object_notify (G_OBJECT (widget), "events");
10035 * gtk_widget_add_device_events:
10036 * @widget: a #GtkWidget
10037 * @device: a #GdkDevice
10038 * @events: an event mask, see #GdkEventMask
10040 * Adds the device events in the bitfield @events to the event mask for
10041 * @widget. See gtk_widget_set_device_events() for details.
10046 gtk_widget_add_device_events (GtkWidget *widget,
10048 GdkEventMask events)
10050 GdkEventMask old_events;
10051 GHashTable *device_events;
10053 g_return_if_fail (GTK_IS_WIDGET (widget));
10054 g_return_if_fail (GDK_IS_DEVICE (device));
10056 old_events = gtk_widget_get_device_events (widget, device);
10058 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10060 if (G_UNLIKELY (!device_events))
10062 device_events = g_hash_table_new (NULL, NULL);
10063 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
10064 (GDestroyNotify) g_hash_table_unref);
10067 g_hash_table_insert (device_events, device,
10068 GUINT_TO_POINTER (old_events | events));
10070 if (gtk_widget_get_realized (widget))
10071 gtk_widget_add_events_internal (widget, device, events);
10073 g_object_notify (G_OBJECT (widget), "events");
10077 * gtk_widget_get_toplevel:
10078 * @widget: a #GtkWidget
10080 * This function returns the topmost widget in the container hierarchy
10081 * @widget is a part of. If @widget has no parent widgets, it will be
10082 * returned as the topmost widget. No reference will be added to the
10083 * returned widget; it should not be unreferenced.
10085 * Note the difference in behavior vs. gtk_widget_get_ancestor();
10086 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
10088 * %NULL if @widget wasn't inside a toplevel window, and if the
10089 * window was inside a #GtkWindow-derived widget which was in turn
10090 * inside the toplevel #GtkWindow. While the second case may
10091 * seem unlikely, it actually happens when a #GtkPlug is embedded
10092 * inside a #GtkSocket within the same application.
10094 * To reliably find the toplevel #GtkWindow, use
10095 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
10096 * is set on the result.
10098 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
10099 * if (gtk_widget_is_toplevel (toplevel))
10101 * /* Perform action on toplevel. */
10105 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
10106 * if there's no ancestor.
10109 gtk_widget_get_toplevel (GtkWidget *widget)
10111 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10113 while (widget->priv->parent)
10114 widget = widget->priv->parent;
10120 * gtk_widget_get_ancestor:
10121 * @widget: a #GtkWidget
10122 * @widget_type: ancestor type
10124 * Gets the first ancestor of @widget with type @widget_type. For example,
10125 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
10126 * the first #GtkBox that's an ancestor of @widget. No reference will be
10127 * added to the returned widget; it should not be unreferenced. See note
10128 * about checking for a toplevel #GtkWindow in the docs for
10129 * gtk_widget_get_toplevel().
10131 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
10132 * considers @widget to be an ancestor of itself.
10134 * Return value: (transfer none): the ancestor widget, or %NULL if not found
10137 gtk_widget_get_ancestor (GtkWidget *widget,
10140 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10142 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
10143 widget = widget->priv->parent;
10145 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
10152 * gtk_widget_set_visual:
10153 * @widget: a #GtkWidget
10154 * @visual: visual to be used or %NULL to unset a previous one
10156 * Sets the visual that should be used for by widget and its children for
10157 * creating #GdkWindows. The visual must be on the same #GdkScreen as
10158 * returned by gdk_widget_get_screen(), so handling the
10159 * #GtkWidget::screen-changed signal is necessary.
10161 * Setting a new @visual will not cause @widget to recreate its windows,
10162 * so you should call this function before @widget is realized.
10165 gtk_widget_set_visual (GtkWidget *widget,
10168 g_return_if_fail (GTK_IS_WIDGET (widget));
10169 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
10172 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
10175 g_object_set_qdata_full (G_OBJECT (widget),
10177 g_object_ref (visual),
10182 * gtk_widget_get_visual:
10183 * @widget: a #GtkWidget
10185 * Gets the visual that will be used to render @widget.
10187 * Return value: (transfer none): the visual for @widget
10190 gtk_widget_get_visual (GtkWidget *widget)
10196 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10198 if (gtk_widget_get_has_window (widget) &&
10199 widget->priv->window)
10200 return gdk_window_get_visual (widget->priv->window);
10202 screen = gtk_widget_get_screen (widget);
10204 for (w = widget; w != NULL; w = w->priv->parent)
10206 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
10209 if (gdk_visual_get_screen (visual) == screen)
10212 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
10213 gtk_widget_get_name (widget));
10217 return gdk_screen_get_system_visual (screen);
10221 * gtk_widget_get_settings:
10222 * @widget: a #GtkWidget
10224 * Gets the settings object holding the settings used for this widget.
10226 * Note that this function can only be called when the #GtkWidget
10227 * is attached to a toplevel, since the settings object is specific
10228 * to a particular #GdkScreen.
10230 * Return value: (transfer none): the relevant #GtkSettings object
10233 gtk_widget_get_settings (GtkWidget *widget)
10235 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10237 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
10241 * gtk_widget_get_events:
10242 * @widget: a #GtkWidget
10244 * Returns the event mask for the widget (a bitfield containing flags
10245 * from the #GdkEventMask enumeration). These are the events that the widget
10248 * Return value: event mask for @widget
10251 gtk_widget_get_events (GtkWidget *widget)
10253 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10255 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10259 * gtk_widget_get_device_events:
10260 * @widget: a #GtkWidget
10261 * @device: a #GdkDevice
10263 * Returns the events mask for the widget corresponding to an specific device. These
10264 * are the events that the widget will receive when @device operates on it.
10266 * Returns: device event mask for @widget
10271 gtk_widget_get_device_events (GtkWidget *widget,
10274 GHashTable *device_events;
10276 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10277 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
10279 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10281 if (!device_events)
10284 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
10288 * gtk_widget_get_pointer:
10289 * @widget: a #GtkWidget
10290 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
10291 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
10293 * Obtains the location of the mouse pointer in widget coordinates.
10294 * Widget coordinates are a bit odd; for historical reasons, they are
10295 * defined as @widget->window coordinates for widgets that are not
10296 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
10297 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
10300 gtk_widget_get_pointer (GtkWidget *widget,
10304 GtkWidgetPrivate *priv;
10306 g_return_if_fail (GTK_IS_WIDGET (widget));
10308 priv = widget->priv;
10315 if (gtk_widget_get_realized (widget))
10317 gdk_window_get_pointer (priv->window, x, y, NULL);
10319 if (!gtk_widget_get_has_window (widget))
10322 *x -= priv->allocation.x;
10324 *y -= priv->allocation.y;
10330 * gtk_widget_is_ancestor:
10331 * @widget: a #GtkWidget
10332 * @ancestor: another #GtkWidget
10334 * Determines whether @widget is somewhere inside @ancestor, possibly with
10335 * intermediate containers.
10337 * Return value: %TRUE if @ancestor contains @widget as a child,
10338 * grandchild, great grandchild, etc.
10341 gtk_widget_is_ancestor (GtkWidget *widget,
10342 GtkWidget *ancestor)
10344 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10345 g_return_val_if_fail (ancestor != NULL, FALSE);
10349 if (widget->priv->parent == ancestor)
10351 widget = widget->priv->parent;
10357 static GQuark quark_composite_name = 0;
10360 * gtk_widget_set_composite_name:
10361 * @widget: a #GtkWidget.
10362 * @name: the name to set
10364 * Sets a widgets composite name. The widget must be
10365 * a composite child of its parent; see gtk_widget_push_composite_child().
10368 gtk_widget_set_composite_name (GtkWidget *widget,
10371 g_return_if_fail (GTK_IS_WIDGET (widget));
10372 g_return_if_fail (widget->priv->composite_child);
10373 g_return_if_fail (name != NULL);
10375 if (!quark_composite_name)
10376 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10378 g_object_set_qdata_full (G_OBJECT (widget),
10379 quark_composite_name,
10385 * gtk_widget_get_composite_name:
10386 * @widget: a #GtkWidget
10388 * Obtains the composite name of a widget.
10390 * Returns: the composite name of @widget, or %NULL if @widget is not
10391 * a composite child. The string should be freed when it is no
10395 gtk_widget_get_composite_name (GtkWidget *widget)
10397 GtkWidgetPrivate *priv;
10399 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10401 priv = widget->priv;
10403 if (widget->priv->composite_child && priv->parent)
10404 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10411 * gtk_widget_push_composite_child:
10413 * Makes all newly-created widgets as composite children until
10414 * the corresponding gtk_widget_pop_composite_child() call.
10416 * A composite child is a child that's an implementation detail of the
10417 * container it's inside and should not be visible to people using the
10418 * container. Composite children aren't treated differently by GTK (but
10419 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10420 * builders might want to treat them in a different way.
10422 * Here is a simple example:
10424 * gtk_widget_push_composite_child ();
10425 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10426 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10427 * gtk_widget_pop_composite_child ();
10428 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10429 * GTK_WIDGET (scrolled_window));
10430 * g_object_ref (scrolled_window->hscrollbar);
10434 gtk_widget_push_composite_child (void)
10436 composite_child_stack++;
10440 * gtk_widget_pop_composite_child:
10442 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10445 gtk_widget_pop_composite_child (void)
10447 if (composite_child_stack)
10448 composite_child_stack--;
10452 gtk_widget_emit_direction_changed (GtkWidget *widget,
10453 GtkTextDirection old_dir)
10455 gtk_widget_update_pango_context (widget);
10457 if (widget->priv->context)
10458 gtk_style_context_set_direction (widget->priv->context,
10459 gtk_widget_get_direction (widget));
10461 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10465 * gtk_widget_set_direction:
10466 * @widget: a #GtkWidget
10467 * @dir: the new direction
10469 * Sets the reading direction on a particular widget. This direction
10470 * controls the primary direction for widgets containing text,
10471 * and also the direction in which the children of a container are
10472 * packed. The ability to set the direction is present in order
10473 * so that correct localization into languages with right-to-left
10474 * reading directions can be done. Generally, applications will
10475 * let the default reading direction present, except for containers
10476 * where the containers are arranged in an order that is explicitely
10477 * visual rather than logical (such as buttons for text justification).
10479 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10480 * set by gtk_widget_set_default_direction() will be used.
10483 gtk_widget_set_direction (GtkWidget *widget,
10484 GtkTextDirection dir)
10486 GtkTextDirection old_dir;
10488 g_return_if_fail (GTK_IS_WIDGET (widget));
10489 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10491 old_dir = gtk_widget_get_direction (widget);
10493 widget->priv->direction = dir;
10495 if (old_dir != gtk_widget_get_direction (widget))
10496 gtk_widget_emit_direction_changed (widget, old_dir);
10500 * gtk_widget_get_direction:
10501 * @widget: a #GtkWidget
10503 * Gets the reading direction for a particular widget. See
10504 * gtk_widget_set_direction().
10506 * Return value: the reading direction for the widget.
10509 gtk_widget_get_direction (GtkWidget *widget)
10511 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10513 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10514 return gtk_default_direction;
10516 return widget->priv->direction;
10520 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10522 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10524 g_object_ref (widget);
10526 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10527 gtk_widget_emit_direction_changed (widget, old_dir);
10529 if (GTK_IS_CONTAINER (widget))
10530 gtk_container_forall (GTK_CONTAINER (widget),
10531 gtk_widget_set_default_direction_recurse,
10534 g_object_unref (widget);
10538 * gtk_widget_set_default_direction:
10539 * @dir: the new default direction. This cannot be
10540 * %GTK_TEXT_DIR_NONE.
10542 * Sets the default reading direction for widgets where the
10543 * direction has not been explicitly set by gtk_widget_set_direction().
10546 gtk_widget_set_default_direction (GtkTextDirection dir)
10548 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10550 if (dir != gtk_default_direction)
10552 GList *toplevels, *tmp_list;
10553 GtkTextDirection old_dir = gtk_default_direction;
10555 gtk_default_direction = dir;
10557 tmp_list = toplevels = gtk_window_list_toplevels ();
10558 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10562 gtk_widget_set_default_direction_recurse (tmp_list->data,
10563 GUINT_TO_POINTER (old_dir));
10564 g_object_unref (tmp_list->data);
10565 tmp_list = tmp_list->next;
10568 g_list_free (toplevels);
10573 * gtk_widget_get_default_direction:
10575 * Obtains the current default reading direction. See
10576 * gtk_widget_set_default_direction().
10578 * Return value: the current default direction.
10581 gtk_widget_get_default_direction (void)
10583 return gtk_default_direction;
10587 gtk_widget_dispose (GObject *object)
10589 GtkWidget *widget = GTK_WIDGET (object);
10590 GtkWidgetPrivate *priv = widget->priv;
10593 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10594 else if (gtk_widget_get_visible (widget))
10595 gtk_widget_hide (widget);
10597 priv->visible = FALSE;
10598 if (gtk_widget_get_realized (widget))
10599 gtk_widget_unrealize (widget);
10601 if (!priv->in_destruction)
10603 priv->in_destruction = TRUE;
10604 g_signal_emit (object, widget_signals[DESTROY], 0);
10605 priv->in_destruction = FALSE;
10608 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10612 gtk_widget_real_destroy (GtkWidget *object)
10614 /* gtk_object_destroy() will already hold a refcount on object */
10615 GtkWidget *widget = GTK_WIDGET (object);
10616 GtkWidgetPrivate *priv = widget->priv;
10618 /* wipe accelerator closures (keep order) */
10619 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10620 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10622 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10623 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10625 gtk_grab_remove (widget);
10627 g_object_unref (priv->style);
10628 priv->style = gtk_widget_get_default_style ();
10629 g_object_ref (priv->style);
10633 gtk_widget_finalize (GObject *object)
10635 GtkWidget *widget = GTK_WIDGET (object);
10636 GtkWidgetPrivate *priv = widget->priv;
10637 GtkWidgetAuxInfo *aux_info;
10638 GtkAccessible *accessible;
10640 gtk_grab_remove (widget);
10642 g_object_unref (priv->style);
10643 priv->style = NULL;
10645 g_free (priv->name);
10647 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
10649 gtk_widget_aux_info_destroy (aux_info);
10651 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10653 g_object_unref (accessible);
10656 gtk_widget_path_free (priv->path);
10659 g_object_unref (priv->context);
10661 _gtk_widget_free_cached_sizes (widget);
10663 if (g_object_is_floating (object))
10664 g_warning ("A floating object was finalized. This means that someone\n"
10665 "called g_object_unref() on an object that had only a floating\n"
10666 "reference; the initial floating reference is not owned by anyone\n"
10667 "and must be removed with g_object_ref_sink().");
10669 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10672 /*****************************************
10673 * gtk_widget_real_map:
10678 *****************************************/
10681 gtk_widget_real_map (GtkWidget *widget)
10683 GtkWidgetPrivate *priv = widget->priv;
10685 g_assert (gtk_widget_get_realized (widget));
10687 if (!gtk_widget_get_mapped (widget))
10689 gtk_widget_set_mapped (widget, TRUE);
10691 if (gtk_widget_get_has_window (widget))
10692 gdk_window_show (priv->window);
10696 /*****************************************
10697 * gtk_widget_real_unmap:
10702 *****************************************/
10705 gtk_widget_real_unmap (GtkWidget *widget)
10707 GtkWidgetPrivate *priv = widget->priv;
10709 if (gtk_widget_get_mapped (widget))
10711 gtk_widget_set_mapped (widget, FALSE);
10713 if (gtk_widget_get_has_window (widget))
10714 gdk_window_hide (priv->window);
10718 /*****************************************
10719 * gtk_widget_real_realize:
10724 *****************************************/
10727 gtk_widget_real_realize (GtkWidget *widget)
10729 GtkWidgetPrivate *priv = widget->priv;
10731 g_assert (!gtk_widget_get_has_window (widget));
10733 gtk_widget_set_realized (widget, TRUE);
10736 priv->window = gtk_widget_get_parent_window (widget);
10737 g_object_ref (priv->window);
10739 priv->style = gtk_style_attach (priv->style, priv->window);
10742 /*****************************************
10743 * gtk_widget_real_unrealize:
10748 *****************************************/
10751 gtk_widget_real_unrealize (GtkWidget *widget)
10753 GtkWidgetPrivate *priv = widget->priv;
10755 g_assert (!widget->priv->mapped);
10757 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10760 /* We must do unrealize child widget BEFORE container widget.
10761 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10762 * So, unrealizing container widget bofore its children causes the problem
10763 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10766 if (GTK_IS_CONTAINER (widget))
10767 gtk_container_forall (GTK_CONTAINER (widget),
10768 (GtkCallback) gtk_widget_unrealize,
10771 gtk_style_detach (priv->style);
10772 if (gtk_widget_get_has_window (widget))
10774 gdk_window_set_user_data (priv->window, NULL);
10775 gdk_window_destroy (priv->window);
10776 priv->window = NULL;
10780 g_object_unref (priv->window);
10781 priv->window = NULL;
10784 gtk_selection_remove_all (widget);
10786 gtk_widget_set_realized (widget, FALSE);
10790 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10791 GtkOrientation orientation,
10792 gint *minimum_size,
10793 gint *natural_size)
10795 const GtkWidgetAuxInfo *aux_info;
10797 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10799 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10800 aux_info->width > 0)
10802 *minimum_size = MAX (*minimum_size, aux_info->width);
10804 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10805 aux_info->height > 0)
10807 *minimum_size = MAX (*minimum_size, aux_info->height);
10810 /* Fix it if set_size_request made natural size smaller than min size.
10811 * This would also silently fix broken widgets, but we warn about them
10812 * in gtksizerequest.c when calling their size request vfuncs.
10814 *natural_size = MAX (*natural_size, *minimum_size);
10816 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10818 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10819 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10823 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10824 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10829 * _gtk_widget_peek_request_cache:
10831 * Returns the address of the widget's request cache (strictly for
10832 * internal use in gtksizerequest.c)
10834 * Return value: the address of @widget's size request cache.
10837 _gtk_widget_peek_request_cache (GtkWidget *widget)
10839 /* Don't bother slowing things down with the return_if_fail guards here */
10840 return &widget->priv->requests;
10844 * _gtk_widget_set_device_window:
10845 * @widget: a #GtkWidget
10846 * @device: a #GdkDevice
10847 * @window: the new device window
10849 * Sets pointer window for @widget and @device.
10850 * Does not ref @window.
10853 _gtk_widget_set_device_window (GtkWidget *widget,
10857 GHashTable *device_window;
10859 g_return_if_fail (GTK_IS_WIDGET (widget));
10860 g_return_if_fail (GDK_IS_DEVICE (device));
10861 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10863 if (!gtk_widget_get_mapped (widget))
10866 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10868 if (!device_window && window)
10870 device_window = g_hash_table_new (NULL, NULL);
10871 g_object_set_qdata_full (G_OBJECT (widget),
10872 quark_pointer_window,
10874 (GDestroyNotify) g_hash_table_destroy);
10878 g_hash_table_insert (device_window, device, window);
10879 else if (device_window)
10881 g_hash_table_remove (device_window, device);
10883 if (g_hash_table_size (device_window) == 0)
10884 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10889 * _gtk_widget_get_device_window:
10890 * @widget: a #GtkWidget
10891 * @device: a #GdkDevice
10893 * Return value: the device window set on @widget, or %NULL
10896 _gtk_widget_get_device_window (GtkWidget *widget,
10899 GHashTable *device_window;
10901 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10902 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10904 if (!gtk_widget_get_mapped (widget))
10907 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10909 if (!device_window)
10912 return g_hash_table_lookup (device_window, device);
10916 * _gtk_widget_list_devices:
10917 * @widget: a #GtkWidget
10919 * Returns the list of #GdkDevices that is currently on top
10920 * of any window belonging to @widget.
10921 * Free the list with g_list_free(), the elements are owned
10922 * by GTK+ and must not be freed.
10925 _gtk_widget_list_devices (GtkWidget *widget)
10927 GHashTableIter iter;
10928 GHashTable *device_window;
10929 GList *devices = NULL;
10930 gpointer key, value;
10932 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10934 if (!gtk_widget_get_mapped (widget))
10937 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10939 if (G_UNLIKELY (!device_window))
10942 g_hash_table_iter_init (&iter, device_window);
10944 while (g_hash_table_iter_next (&iter, &key, &value))
10945 devices = g_list_prepend (devices, key);
10951 synth_crossing (GtkWidget *widget,
10955 GdkCrossingMode mode,
10956 GdkNotifyType detail)
10960 event = gdk_event_new (type);
10962 event->crossing.window = g_object_ref (window);
10963 event->crossing.send_event = TRUE;
10964 event->crossing.subwindow = g_object_ref (window);
10965 event->crossing.time = GDK_CURRENT_TIME;
10966 event->crossing.x = event->crossing.y = 0;
10967 event->crossing.x_root = event->crossing.y_root = 0;
10968 event->crossing.mode = mode;
10969 event->crossing.detail = detail;
10970 event->crossing.focus = FALSE;
10971 event->crossing.state = 0;
10972 gdk_event_set_device (event, device);
10975 widget = gtk_get_event_widget (event);
10978 gtk_widget_event_internal (widget, event);
10980 gdk_event_free (event);
10984 * _gtk_widget_synthesize_crossing:
10985 * @from: the #GtkWidget the virtual pointer is leaving.
10986 * @to: the #GtkWidget the virtual pointer is moving to.
10987 * @mode: the #GdkCrossingMode to place on the synthesized events.
10989 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10991 * The real pointer window is the window that most recently received an enter notify
10992 * event. Windows that don't select for crossing events can't become the real
10993 * poiner window. The real pointer widget that owns the real pointer window. The
10994 * effective pointer window is the same as the real pointer window unless the real
10995 * pointer widget is either insensitive or there is a grab on a widget that is not
10996 * an ancestor of the real pointer widget (in which case the effective pointer
10997 * window should be the root window).
10999 * When the effective pointer window is the same as the real poiner window, we
11000 * receive crossing events from the windowing system. When the effective pointer
11001 * window changes to become different from the real pointer window we synthesize
11002 * crossing events, attempting to follow X protocol rules:
11004 * When the root window becomes the effective pointer window:
11005 * - leave notify on real pointer window, detail Ancestor
11006 * - leave notify on all of its ancestors, detail Virtual
11007 * - enter notify on root window, detail Inferior
11009 * When the root window ceases to be the effective pointer window:
11010 * - leave notify on root window, detail Inferior
11011 * - enter notify on all ancestors of real pointer window, detail Virtual
11012 * - enter notify on real pointer window, detail Ancestor
11015 _gtk_widget_synthesize_crossing (GtkWidget *from,
11018 GdkCrossingMode mode)
11020 GdkWindow *from_window = NULL, *to_window = NULL;
11022 g_return_if_fail (from != NULL || to != NULL);
11026 from_window = _gtk_widget_get_device_window (from, device);
11029 from_window = from->priv->window;
11034 to_window = _gtk_widget_get_device_window (to, device);
11037 to_window = to->priv->window;
11040 if (from_window == NULL && to_window == NULL)
11042 else if (from_window != NULL && to_window == NULL)
11044 GList *from_ancestors = NULL, *list;
11045 GdkWindow *from_ancestor = from_window;
11047 while (from_ancestor != NULL)
11049 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
11050 if (from_ancestor == NULL)
11052 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
11055 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11056 device, mode, GDK_NOTIFY_ANCESTOR);
11057 for (list = g_list_last (from_ancestors); list; list = list->prev)
11059 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11060 device, mode, GDK_NOTIFY_VIRTUAL);
11063 /* XXX: enter/inferior on root window? */
11065 g_list_free (from_ancestors);
11067 else if (from_window == NULL && to_window != NULL)
11069 GList *to_ancestors = NULL, *list;
11070 GdkWindow *to_ancestor = to_window;
11072 while (to_ancestor != NULL)
11074 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
11075 if (to_ancestor == NULL)
11077 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
11080 /* XXX: leave/inferior on root window? */
11082 for (list = to_ancestors; list; list = list->next)
11084 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11085 device, mode, GDK_NOTIFY_VIRTUAL);
11087 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11088 device, mode, GDK_NOTIFY_ANCESTOR);
11090 g_list_free (to_ancestors);
11092 else if (from_window == to_window)
11096 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
11097 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
11099 while (from_ancestor != NULL || to_ancestor != NULL)
11101 if (from_ancestor != NULL)
11103 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
11104 if (from_ancestor == to_window)
11107 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
11109 if (to_ancestor != NULL)
11111 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
11112 if (to_ancestor == from_window)
11115 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
11118 if (to_ancestor == from_window)
11120 if (mode != GDK_CROSSING_GTK_UNGRAB)
11121 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11122 device, mode, GDK_NOTIFY_INFERIOR);
11123 for (list = to_ancestors; list; list = list->next)
11124 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11125 device, mode, GDK_NOTIFY_VIRTUAL);
11126 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11127 device, mode, GDK_NOTIFY_ANCESTOR);
11129 else if (from_ancestor == to_window)
11131 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11132 device, mode, GDK_NOTIFY_ANCESTOR);
11133 for (list = g_list_last (from_ancestors); list; list = list->prev)
11135 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11136 device, mode, GDK_NOTIFY_VIRTUAL);
11138 if (mode != GDK_CROSSING_GTK_GRAB)
11139 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11140 device, mode, GDK_NOTIFY_INFERIOR);
11144 while (from_ancestors != NULL && to_ancestors != NULL
11145 && from_ancestors->data == to_ancestors->data)
11147 from_ancestors = g_list_delete_link (from_ancestors,
11149 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
11152 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11153 device, mode, GDK_NOTIFY_NONLINEAR);
11155 for (list = g_list_last (from_ancestors); list; list = list->prev)
11157 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11158 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11160 for (list = to_ancestors; list; list = list->next)
11162 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11163 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11165 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11166 device, mode, GDK_NOTIFY_NONLINEAR);
11168 g_list_free (from_ancestors);
11169 g_list_free (to_ancestors);
11174 gtk_widget_propagate_state (GtkWidget *widget,
11175 GtkStateData *data)
11177 GtkWidgetPrivate *priv = widget->priv;
11178 GtkStateFlags new_flags, old_flags = priv->state_flags;
11179 GtkStateType old_state;
11181 old_state = gtk_widget_get_state (widget);
11183 if (!priv->parent_sensitive)
11184 old_flags |= GTK_STATE_FLAG_INSENSITIVE;
11186 priv->parent_sensitive = data->parent_sensitive;
11188 switch (data->operation)
11190 case STATE_CHANGE_REPLACE:
11191 priv->state_flags = data->flags;
11193 case STATE_CHANGE_SET:
11194 priv->state_flags |= data->flags;
11196 case STATE_CHANGE_UNSET:
11197 priv->state_flags &= ~(data->flags);
11201 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
11205 window = gtk_widget_get_toplevel (widget);
11207 if (window && gtk_widget_is_toplevel (window))
11208 gtk_window_set_focus (GTK_WINDOW (window), NULL);
11211 new_flags = gtk_widget_get_state_flags (widget);
11213 if (old_flags != new_flags)
11215 g_object_ref (widget);
11217 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
11218 gtk_grab_remove (widget);
11220 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
11221 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
11223 if (!priv->shadowed)
11225 GList *event_windows = NULL;
11226 GList *devices, *d;
11228 devices = _gtk_widget_list_devices (widget);
11230 for (d = devices; d; d = d->next)
11236 window = _gtk_widget_get_device_window (widget, device);
11238 /* Do not propagate more than once to the
11239 * same window if non-multidevice aware.
11241 if (!gdk_window_get_support_multidevice (window) &&
11242 g_list_find (event_windows, window))
11245 if (!gtk_widget_is_sensitive (widget))
11246 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
11247 GDK_CROSSING_STATE_CHANGED);
11248 else if (old_flags & GTK_STATE_FLAG_INSENSITIVE)
11249 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
11250 GDK_CROSSING_STATE_CHANGED);
11252 event_windows = g_list_prepend (event_windows, window);
11255 g_list_free (event_windows);
11256 g_list_free (devices);
11259 if (GTK_IS_CONTAINER (widget))
11261 GtkStateData child_data = *data;
11263 child_data.parent_sensitive = gtk_widget_is_sensitive (widget);
11265 /* Do not propagate focused state further */
11266 child_data.flags &= ~GTK_STATE_FLAG_FOCUSED;
11268 if (child_data.use_forall)
11269 gtk_container_forall (GTK_CONTAINER (widget),
11270 (GtkCallback) gtk_widget_propagate_state,
11273 gtk_container_foreach (GTK_CONTAINER (widget),
11274 (GtkCallback) gtk_widget_propagate_state,
11278 /* Trigger state change transitions for the widget */
11279 if (priv->context &&
11280 gtk_widget_get_mapped (widget))
11282 gint diff, flag = 1;
11284 diff = old_flags ^ new_flags;
11288 if ((diff & flag) != 0)
11292 target = ((new_flags & flag) != 0);
11293 _gtk_widget_notify_state_change (widget, flag, target);
11302 g_object_unref (widget);
11306 static const GtkWidgetAuxInfo default_aux_info = {
11314 * _gtk_widget_get_aux_info:
11315 * @widget: a #GtkWidget
11316 * @create: if %TRUE, create the structure if it doesn't exist
11318 * Get the #GtkWidgetAuxInfo structure for the widget.
11320 * Return value: the #GtkAuxInfo structure for the widget, or
11321 * %NULL if @create is %FALSE and one doesn't already exist.
11324 _gtk_widget_get_aux_info (GtkWidget *widget,
11327 GtkWidgetAuxInfo *aux_info;
11329 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
11330 if (!aux_info && create)
11332 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
11334 *aux_info = default_aux_info;
11336 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
11342 static const GtkWidgetAuxInfo*
11343 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11345 GtkWidgetAuxInfo *aux_info;
11347 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
11348 if (aux_info == NULL)
11350 return &default_aux_info;
11358 /*****************************************
11359 * gtk_widget_aux_info_destroy:
11364 *****************************************/
11367 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11369 g_slice_free (GtkWidgetAuxInfo, aux_info);
11373 * gtk_widget_shape_combine_region:
11374 * @widget: a #GtkWidget
11375 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11377 * Sets a shape for this widget's GDK window. This allows for
11378 * transparent windows etc., see gdk_window_shape_combine_region()
11379 * for more information.
11384 gtk_widget_shape_combine_region (GtkWidget *widget,
11385 cairo_region_t *region)
11387 GtkWidgetPrivate *priv;
11389 g_return_if_fail (GTK_IS_WIDGET (widget));
11390 /* set_shape doesn't work on widgets without gdk window */
11391 g_return_if_fail (gtk_widget_get_has_window (widget));
11393 priv = widget->priv;
11395 if (region == NULL)
11397 priv->has_shape_mask = FALSE;
11400 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11402 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11406 priv->has_shape_mask = TRUE;
11408 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11409 cairo_region_copy (region),
11410 (GDestroyNotify) cairo_region_destroy);
11412 /* set shape if widget has a gdk window already.
11413 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11416 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11421 * gtk_widget_input_shape_combine_region:
11422 * @widget: a #GtkWidget
11423 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11425 * Sets an input shape for this widget's GDK window. This allows for
11426 * windows which react to mouse click in a nonrectangular region, see
11427 * gdk_window_input_shape_combine_region() for more information.
11432 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11433 cairo_region_t *region)
11435 GtkWidgetPrivate *priv;
11437 g_return_if_fail (GTK_IS_WIDGET (widget));
11438 /* set_shape doesn't work on widgets without gdk window */
11439 g_return_if_fail (gtk_widget_get_has_window (widget));
11441 priv = widget->priv;
11443 if (region == NULL)
11446 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11448 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11452 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11453 cairo_region_copy (region),
11454 (GDestroyNotify) cairo_region_destroy);
11456 /* set shape if widget has a gdk window already.
11457 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11460 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11465 /* style properties
11469 * gtk_widget_class_install_style_property_parser: (skip)
11470 * @klass: a #GtkWidgetClass
11471 * @pspec: the #GParamSpec for the style property
11472 * @parser: the parser for the style property
11474 * Installs a style property on a widget class.
11477 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11479 GtkRcPropertyParser parser)
11481 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11482 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11483 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11484 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11486 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11488 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11489 G_OBJECT_CLASS_NAME (klass),
11494 g_param_spec_ref_sink (pspec);
11495 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11496 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11500 * gtk_widget_class_install_style_property:
11501 * @klass: a #GtkWidgetClass
11502 * @pspec: the #GParamSpec for the property
11504 * Installs a style property on a widget class. The parser for the
11505 * style property is determined by the value type of @pspec.
11508 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11511 GtkRcPropertyParser parser;
11513 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11514 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11516 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11518 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11522 * gtk_widget_class_find_style_property:
11523 * @klass: a #GtkWidgetClass
11524 * @property_name: the name of the style property to find
11525 * @returns: (transfer none): the #GParamSpec of the style property or
11526 * %NULL if @class has no style property with that name.
11528 * Finds a style property of a widget class by name.
11533 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11534 const gchar *property_name)
11536 g_return_val_if_fail (property_name != NULL, NULL);
11538 return g_param_spec_pool_lookup (style_property_spec_pool,
11540 G_OBJECT_CLASS_TYPE (klass),
11545 * gtk_widget_class_list_style_properties:
11546 * @klass: a #GtkWidgetClass
11547 * @n_properties: location to return the number of style properties found
11548 * @returns: (array length=n_properties) (transfer container): an
11549 * newly allocated array of #GParamSpec*. The array must be
11550 * freed with g_free().
11552 * Returns all style properties of a widget class.
11557 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11558 guint *n_properties)
11560 GParamSpec **pspecs;
11563 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11564 G_OBJECT_CLASS_TYPE (klass),
11573 * gtk_widget_style_get_property:
11574 * @widget: a #GtkWidget
11575 * @property_name: the name of a style property
11576 * @value: location to return the property value
11578 * Gets the value of a style property of @widget.
11581 gtk_widget_style_get_property (GtkWidget *widget,
11582 const gchar *property_name,
11587 g_return_if_fail (GTK_IS_WIDGET (widget));
11588 g_return_if_fail (property_name != NULL);
11589 g_return_if_fail (G_IS_VALUE (value));
11591 g_object_ref (widget);
11592 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11594 G_OBJECT_TYPE (widget),
11597 g_warning ("%s: widget class `%s' has no property named `%s'",
11599 G_OBJECT_TYPE_NAME (widget),
11603 GtkStyleContext *context;
11604 const GValue *peek_value;
11605 GtkStateFlags state;
11607 context = gtk_widget_get_style_context (widget);
11608 state = gtk_widget_get_state_flags (widget);
11610 peek_value = _gtk_style_context_peek_style_property (context,
11611 G_OBJECT_TYPE (widget),
11614 /* auto-conversion of the caller's value type
11616 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11617 g_value_copy (peek_value, value);
11618 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11619 g_value_transform (peek_value, value);
11621 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11623 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11624 G_VALUE_TYPE_NAME (value));
11626 g_object_unref (widget);
11630 * gtk_widget_style_get_valist:
11631 * @widget: a #GtkWidget
11632 * @first_property_name: the name of the first property to get
11633 * @var_args: a <type>va_list</type> of pairs of property names and
11634 * locations to return the property values, starting with the location
11635 * for @first_property_name.
11637 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11641 gtk_widget_style_get_valist (GtkWidget *widget,
11642 const gchar *first_property_name,
11645 GtkStyleContext *context;
11646 GtkStateFlags state;
11649 g_return_if_fail (GTK_IS_WIDGET (widget));
11651 g_object_ref (widget);
11652 context = gtk_widget_get_style_context (widget);
11653 state = gtk_widget_get_state_flags (widget);
11655 name = first_property_name;
11658 const GValue *peek_value;
11662 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11664 G_OBJECT_TYPE (widget),
11668 g_warning ("%s: widget class `%s' has no property named `%s'",
11670 G_OBJECT_TYPE_NAME (widget),
11674 /* style pspecs are always readable so we can spare that check here */
11676 peek_value = _gtk_style_context_peek_style_property (context,
11677 G_OBJECT_TYPE (widget),
11680 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11683 g_warning ("%s: %s", G_STRLOC, error);
11688 name = va_arg (var_args, gchar*);
11691 g_object_unref (widget);
11695 * gtk_widget_style_get:
11696 * @widget: a #GtkWidget
11697 * @first_property_name: the name of the first property to get
11698 * @Varargs: pairs of property names and locations to
11699 * return the property values, starting with the location for
11700 * @first_property_name, terminated by %NULL.
11702 * Gets the values of a multiple style properties of @widget.
11705 gtk_widget_style_get (GtkWidget *widget,
11706 const gchar *first_property_name,
11711 g_return_if_fail (GTK_IS_WIDGET (widget));
11713 va_start (var_args, first_property_name);
11714 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11720 * @widget: a #GtkWidget
11721 * @path_length: (out) (allow-none): location to store length of the path,
11723 * @path: (out) (allow-none): location to store allocated path string,
11725 * @path_reversed: (out) (allow-none): location to store allocated reverse
11726 * path string, or %NULL
11728 * Obtains the full path to @widget. The path is simply the name of a
11729 * widget and all its parents in the container hierarchy, separated by
11730 * periods. The name of a widget comes from
11731 * gtk_widget_get_name(). Paths are used to apply styles to a widget
11732 * in gtkrc configuration files. Widget names are the type of the
11733 * widget by default (e.g. "GtkButton") or can be set to an
11734 * application-specific value with gtk_widget_set_name(). By setting
11735 * the name of a widget, you allow users or theme authors to apply
11736 * styles to that specific widget in their gtkrc
11737 * file. @path_reversed_p fills in the path in reverse order,
11738 * i.e. starting with @widget's name instead of starting with the name
11739 * of @widget's outermost ancestor.
11741 * Deprecated:3.0: Use gtk_widget_get_path() instead
11744 gtk_widget_path (GtkWidget *widget,
11745 guint *path_length,
11747 gchar **path_reversed)
11749 static gchar *rev_path = NULL;
11750 static guint tmp_path_len = 0;
11753 g_return_if_fail (GTK_IS_WIDGET (widget));
11758 const gchar *string;
11763 string = gtk_widget_get_name (widget);
11764 l = strlen (string);
11765 while (tmp_path_len <= len + l + 1)
11767 tmp_path_len += INIT_PATH_SIZE;
11768 rev_path = g_realloc (rev_path, tmp_path_len);
11770 s = string + l - 1;
11771 d = rev_path + len;
11772 while (s >= string)
11776 widget = widget->priv->parent;
11779 rev_path[len++] = '.';
11781 rev_path[len++] = 0;
11786 *path_length = len - 1;
11788 *path_reversed = g_strdup (rev_path);
11791 *path = g_strdup (rev_path);
11792 g_strreverse (*path);
11797 * gtk_widget_class_path:
11798 * @widget: a #GtkWidget
11799 * @path_length: (out) (allow-none): location to store the length of the
11800 * class path, or %NULL
11801 * @path: (out) (allow-none): location to store the class path as an
11802 * allocated string, or %NULL
11803 * @path_reversed: (out) (allow-none): location to store the reverse
11804 * class path as an allocated string, or %NULL
11806 * Same as gtk_widget_path(), but always uses the name of a widget's type,
11807 * never uses a custom name set with gtk_widget_set_name().
11809 * Deprecated:3.0: Use gtk_widget_get_path() instead
11812 gtk_widget_class_path (GtkWidget *widget,
11813 guint *path_length,
11815 gchar **path_reversed)
11817 static gchar *rev_path = NULL;
11818 static guint tmp_path_len = 0;
11821 g_return_if_fail (GTK_IS_WIDGET (widget));
11826 const gchar *string;
11831 string = g_type_name (G_OBJECT_TYPE (widget));
11832 l = strlen (string);
11833 while (tmp_path_len <= len + l + 1)
11835 tmp_path_len += INIT_PATH_SIZE;
11836 rev_path = g_realloc (rev_path, tmp_path_len);
11838 s = string + l - 1;
11839 d = rev_path + len;
11840 while (s >= string)
11844 widget = widget->priv->parent;
11847 rev_path[len++] = '.';
11849 rev_path[len++] = 0;
11854 *path_length = len - 1;
11856 *path_reversed = g_strdup (rev_path);
11859 *path = g_strdup (rev_path);
11860 g_strreverse (*path);
11865 * gtk_requisition_new:
11867 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11869 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11870 * be freed with gtk_requisition_free().
11875 gtk_requisition_new (void)
11877 return g_slice_new0 (GtkRequisition);
11881 * gtk_requisition_copy:
11882 * @requisition: a #GtkRequisition
11884 * Copies a #GtkRequisition.
11886 * Returns: a copy of @requisition
11889 gtk_requisition_copy (const GtkRequisition *requisition)
11891 return g_slice_dup (GtkRequisition, requisition);
11895 * gtk_requisition_free:
11896 * @requisition: a #GtkRequisition
11898 * Frees a #GtkRequisition.
11901 gtk_requisition_free (GtkRequisition *requisition)
11903 g_slice_free (GtkRequisition, requisition);
11906 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11907 gtk_requisition_copy,
11908 gtk_requisition_free)
11911 * gtk_widget_get_accessible:
11912 * @widget: a #GtkWidget
11914 * Returns the accessible object that describes the widget to an
11915 * assistive technology.
11917 * If no accessibility library is loaded (i.e. no ATK implementation library is
11918 * loaded via <envar>GTK_MODULES</envar> or via another application library,
11919 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
11920 * if no class-specific #AtkObject implementation is available for the widget
11921 * instance in question, it will inherit an #AtkObject implementation from the
11922 * first ancestor class for which such an implementation is defined.
11924 * The documentation of the
11925 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
11926 * library contains more information about accessible objects and their uses.
11928 * Returns: (transfer none): the #AtkObject associated with @widget
11931 gtk_widget_get_accessible (GtkWidget *widget)
11933 GtkWidgetClass *klass;
11935 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11937 klass = GTK_WIDGET_GET_CLASS (widget);
11939 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11941 return klass->get_accessible (widget);
11945 gtk_widget_real_get_accessible (GtkWidget *widget)
11947 AtkObject* accessible;
11949 accessible = g_object_get_qdata (G_OBJECT (widget),
11950 quark_accessible_object);
11953 AtkObjectFactory *factory;
11954 AtkRegistry *default_registry;
11956 default_registry = atk_get_default_registry ();
11957 factory = atk_registry_get_factory (default_registry,
11958 G_TYPE_FROM_INSTANCE (widget));
11960 atk_object_factory_create_accessible (factory,
11961 G_OBJECT (widget));
11962 g_object_set_qdata (G_OBJECT (widget),
11963 quark_accessible_object,
11970 * Initialize a AtkImplementorIface instance's virtual pointers as
11971 * appropriate to this implementor's class (GtkWidget).
11974 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11976 iface->ref_accessible = gtk_widget_ref_accessible;
11980 gtk_widget_ref_accessible (AtkImplementor *implementor)
11982 AtkObject *accessible;
11984 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11986 g_object_ref (accessible);
11991 * Expand flag management
11995 gtk_widget_update_computed_expand (GtkWidget *widget)
11997 GtkWidgetPrivate *priv;
11999 priv = widget->priv;
12001 if (priv->need_compute_expand)
12005 if (priv->hexpand_set)
12010 if (priv->vexpand_set)
12015 /* we don't need to use compute_expand if both expands are
12016 * forced by the app
12018 if (!(priv->hexpand_set && priv->vexpand_set))
12020 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
12024 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
12025 priv->hexpand_set ? &ignored : &h,
12026 priv->vexpand_set ? &ignored : &v);
12030 priv->need_compute_expand = FALSE;
12031 priv->computed_hexpand = h != FALSE;
12032 priv->computed_vexpand = v != FALSE;
12037 * gtk_widget_queue_compute_expand:
12038 * @widget: a #GtkWidget
12040 * Mark @widget as needing to recompute its expand flags. Call
12041 * this function when setting legacy expand child properties
12042 * on the child of a container.
12044 * See gtk_widget_compute_expand().
12047 gtk_widget_queue_compute_expand (GtkWidget *widget)
12050 gboolean changed_anything;
12052 if (widget->priv->need_compute_expand)
12055 changed_anything = FALSE;
12057 while (parent != NULL)
12059 if (!parent->priv->need_compute_expand)
12061 parent->priv->need_compute_expand = TRUE;
12062 changed_anything = TRUE;
12065 /* Note: if we had an invariant that "if a child needs to
12066 * compute expand, its parents also do" then we could stop going
12067 * up when we got to a parent that already needed to
12068 * compute. However, in general we compute expand lazily (as
12069 * soon as we see something in a subtree that is expand, we know
12070 * we're expanding) and so this invariant does not hold and we
12071 * have to always walk all the way up in case some ancestor
12072 * is not currently need_compute_expand.
12075 parent = parent->priv->parent;
12078 /* recomputing expand always requires
12079 * a relayout as well
12081 if (changed_anything)
12082 gtk_widget_queue_resize (widget);
12086 * gtk_widget_compute_expand:
12087 * @widget: the widget
12088 * @orientation: expand direction
12090 * Computes whether a container should give this widget extra space
12091 * when possible. Containers should check this, rather than
12092 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
12094 * This function already checks whether the widget is visible, so
12095 * visibility does not need to be checked separately. Non-visible
12096 * widgets are not expanded.
12098 * The computed expand value uses either the expand setting explicitly
12099 * set on the widget itself, or, if none has been explicitly set,
12100 * the widget may expand if some of its children do.
12102 * Return value: whether widget tree rooted here should be expanded
12105 gtk_widget_compute_expand (GtkWidget *widget,
12106 GtkOrientation orientation)
12108 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12110 /* We never make a widget expand if not even showing. */
12111 if (!gtk_widget_get_visible (widget))
12114 gtk_widget_update_computed_expand (widget);
12116 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12118 return widget->priv->computed_hexpand;
12122 return widget->priv->computed_vexpand;
12127 gtk_widget_set_expand (GtkWidget *widget,
12128 GtkOrientation orientation,
12131 const char *expand_prop;
12132 const char *expand_set_prop;
12134 GtkWidgetPrivate *priv;
12136 g_return_if_fail (GTK_IS_WIDGET (widget));
12138 priv = widget->priv;
12140 expand = expand != FALSE;
12142 was_both = priv->hexpand && priv->vexpand;
12144 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12146 if (priv->hexpand_set &&
12147 priv->hexpand == expand)
12150 priv->hexpand_set = TRUE;
12151 priv->hexpand = expand;
12153 expand_prop = "hexpand";
12154 expand_set_prop = "hexpand-set";
12158 if (priv->vexpand_set &&
12159 priv->vexpand == expand)
12162 priv->vexpand_set = TRUE;
12163 priv->vexpand = expand;
12165 expand_prop = "vexpand";
12166 expand_set_prop = "vexpand-set";
12169 gtk_widget_queue_compute_expand (widget);
12171 g_object_freeze_notify (G_OBJECT (widget));
12172 g_object_notify (G_OBJECT (widget), expand_prop);
12173 g_object_notify (G_OBJECT (widget), expand_set_prop);
12174 if (was_both != (priv->hexpand && priv->vexpand))
12175 g_object_notify (G_OBJECT (widget), "expand");
12176 g_object_thaw_notify (G_OBJECT (widget));
12180 gtk_widget_set_expand_set (GtkWidget *widget,
12181 GtkOrientation orientation,
12184 GtkWidgetPrivate *priv;
12187 priv = widget->priv;
12189 set = set != FALSE;
12191 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12193 if (set == priv->hexpand_set)
12196 priv->hexpand_set = set;
12197 prop = "hexpand-set";
12201 if (set == priv->vexpand_set)
12204 priv->vexpand_set = set;
12205 prop = "vexpand-set";
12208 gtk_widget_queue_compute_expand (widget);
12210 g_object_notify (G_OBJECT (widget), prop);
12214 * gtk_widget_get_hexpand:
12215 * @widget: the widget
12217 * Gets whether the widget would like any available extra horizontal
12218 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12219 * generally receive the extra space. For example, a list or
12220 * scrollable area or document in your window would often be set to
12223 * Containers should use gtk_widget_compute_expand() rather than
12224 * this function, to see whether a widget, or any of its children,
12225 * has the expand flag set. If any child of a widget wants to
12226 * expand, the parent may ask to expand also.
12228 * This function only looks at the widget's own hexpand flag, rather
12229 * than computing whether the entire widget tree rooted at this widget
12232 * Return value: whether hexpand flag is set
12235 gtk_widget_get_hexpand (GtkWidget *widget)
12237 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12239 return widget->priv->hexpand;
12243 * gtk_widget_set_hexpand:
12244 * @widget: the widget
12245 * @expand: whether to expand
12247 * Sets whether the widget would like any available extra horizontal
12248 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12249 * generally receive the extra space. For example, a list or
12250 * scrollable area or document in your window would often be set to
12253 * Call this function to set the expand flag if you would like your
12254 * widget to become larger horizontally when the window has extra
12257 * By default, widgets automatically expand if any of their children
12258 * want to expand. (To see if a widget will automatically expand given
12259 * its current children and state, call gtk_widget_compute_expand(). A
12260 * container can decide how the expandability of children affects the
12261 * expansion of the container by overriding the compute_expand virtual
12262 * method on #GtkWidget.).
12264 * Setting hexpand explicitly with this function will override the
12265 * automatic expand behavior.
12267 * This function forces the widget to expand or not to expand,
12268 * regardless of children. The override occurs because
12269 * gtk_widget_set_hexpand() sets the hexpand-set property (see
12270 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
12271 * value to be used, rather than looking at children and widget state.
12274 gtk_widget_set_hexpand (GtkWidget *widget,
12277 g_return_if_fail (GTK_IS_WIDGET (widget));
12279 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
12283 * gtk_widget_get_hexpand_set:
12284 * @widget: the widget
12286 * Gets whether gtk_widget_set_hexpand() has been used to
12287 * explicitly set the expand flag on this widget.
12289 * If hexpand is set, then it overrides any computed
12290 * expand value based on child widgets. If hexpand is not
12291 * set, then the expand value depends on whether any
12292 * children of the widget would like to expand.
12294 * There are few reasons to use this function, but it's here
12295 * for completeness and consistency.
12297 * Return value: whether hexpand has been explicitly set
12300 gtk_widget_get_hexpand_set (GtkWidget *widget)
12302 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12304 return widget->priv->hexpand_set;
12308 * gtk_widget_set_hexpand_set:
12309 * @widget: the widget
12310 * @set: value for hexpand-set property
12312 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
12315 * The hexpand-set property will be set automatically when you call
12316 * gtk_widget_set_hexpand() to set hexpand, so the most likely
12317 * reason to use this function would be to unset an explicit expand
12320 * If hexpand is set, then it overrides any computed
12321 * expand value based on child widgets. If hexpand is not
12322 * set, then the expand value depends on whether any
12323 * children of the widget would like to expand.
12325 * There are few reasons to use this function, but it's here
12326 * for completeness and consistency.
12329 gtk_widget_set_hexpand_set (GtkWidget *widget,
12332 g_return_if_fail (GTK_IS_WIDGET (widget));
12334 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
12339 * gtk_widget_get_vexpand:
12340 * @widget: the widget
12342 * Gets whether the widget would like any available extra vertical
12345 * See gtk_widget_get_hexpand() for more detail.
12347 * Return value: whether vexpand flag is set
12350 gtk_widget_get_vexpand (GtkWidget *widget)
12352 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12354 return widget->priv->vexpand;
12358 * gtk_widget_set_vexpand:
12359 * @widget: the widget
12360 * @expand: whether to expand
12362 * Sets whether the widget would like any available extra vertical
12365 * See gtk_widget_set_hexpand() for more detail.
12368 gtk_widget_set_vexpand (GtkWidget *widget,
12371 g_return_if_fail (GTK_IS_WIDGET (widget));
12373 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12377 * gtk_widget_get_vexpand_set:
12378 * @widget: the widget
12380 * Gets whether gtk_widget_set_vexpand() has been used to
12381 * explicitly set the expand flag on this widget.
12383 * See gtk_widget_get_hexpand_set() for more detail.
12385 * Return value: whether vexpand has been explicitly set
12388 gtk_widget_get_vexpand_set (GtkWidget *widget)
12390 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12392 return widget->priv->vexpand_set;
12396 * gtk_widget_set_vexpand_set:
12397 * @widget: the widget
12398 * @set: value for vexpand-set property
12400 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12403 * See gtk_widget_set_hexpand_set() for more detail.
12406 gtk_widget_set_vexpand_set (GtkWidget *widget,
12409 g_return_if_fail (GTK_IS_WIDGET (widget));
12411 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12415 * GtkBuildable implementation
12417 static GQuark quark_builder_has_default = 0;
12418 static GQuark quark_builder_has_focus = 0;
12419 static GQuark quark_builder_atk_relations = 0;
12420 static GQuark quark_builder_set_name = 0;
12423 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12425 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12426 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12427 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12428 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12430 iface->set_name = gtk_widget_buildable_set_name;
12431 iface->get_name = gtk_widget_buildable_get_name;
12432 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12433 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12434 iface->parser_finished = gtk_widget_buildable_parser_finished;
12435 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12436 iface->custom_finished = gtk_widget_buildable_custom_finished;
12440 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12443 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12444 g_strdup (name), g_free);
12447 static const gchar *
12448 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12450 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12454 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12455 GtkBuilder *builder,
12456 const gchar *childname)
12458 if (strcmp (childname, "accessible") == 0)
12459 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12465 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12466 GtkBuilder *builder,
12468 const GValue *value)
12470 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12471 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12472 GINT_TO_POINTER (TRUE));
12473 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12474 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12475 GINT_TO_POINTER (TRUE));
12477 g_object_set_property (G_OBJECT (buildable), name, value);
12482 gchar *action_name;
12483 GString *description;
12485 gboolean translatable;
12495 free_action (AtkActionData *data, gpointer user_data)
12497 g_free (data->action_name);
12498 g_string_free (data->description, TRUE);
12499 g_free (data->context);
12500 g_slice_free (AtkActionData, data);
12504 free_relation (AtkRelationData *data, gpointer user_data)
12506 g_free (data->target);
12507 g_free (data->type);
12508 g_slice_free (AtkRelationData, data);
12512 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12513 GtkBuilder *builder)
12515 GSList *atk_relations;
12517 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12518 gtk_widget_grab_default (GTK_WIDGET (buildable));
12519 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12520 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12522 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12523 quark_builder_atk_relations);
12526 AtkObject *accessible;
12527 AtkRelationSet *relation_set;
12530 AtkRelationType relation_type;
12531 AtkObject *target_accessible;
12533 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12534 relation_set = atk_object_ref_relation_set (accessible);
12536 for (l = atk_relations; l; l = l->next)
12538 AtkRelationData *relation = (AtkRelationData*)l->data;
12540 target = gtk_builder_get_object (builder, relation->target);
12543 g_warning ("Target object %s in <relation> does not exist",
12547 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12548 g_assert (target_accessible != NULL);
12550 relation_type = atk_relation_type_for_name (relation->type);
12551 if (relation_type == ATK_RELATION_NULL)
12553 g_warning ("<relation> type %s not found",
12557 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12558 target_accessible);
12560 g_object_unref (relation_set);
12562 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
12563 g_slist_free (atk_relations);
12564 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12573 } AccessibilitySubParserData;
12576 accessibility_start_element (GMarkupParseContext *context,
12577 const gchar *element_name,
12578 const gchar **names,
12579 const gchar **values,
12580 gpointer user_data,
12583 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12585 gint line_number, char_number;
12587 if (strcmp (element_name, "relation") == 0)
12589 gchar *target = NULL;
12590 gchar *type = NULL;
12591 AtkRelationData *relation;
12593 for (i = 0; names[i]; i++)
12595 if (strcmp (names[i], "target") == 0)
12596 target = g_strdup (values[i]);
12597 else if (strcmp (names[i], "type") == 0)
12598 type = g_strdup (values[i]);
12601 g_markup_parse_context_get_position (context,
12604 g_set_error (error,
12606 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12607 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12609 line_number, char_number, names[i], "relation");
12616 if (!target || !type)
12618 g_markup_parse_context_get_position (context,
12621 g_set_error (error,
12623 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12624 "%s:%d:%d <%s> requires attribute \"%s\"",
12626 line_number, char_number, "relation",
12627 type ? "target" : "type");
12633 relation = g_slice_new (AtkRelationData);
12634 relation->target = target;
12635 relation->type = type;
12637 data->relations = g_slist_prepend (data->relations, relation);
12639 else if (strcmp (element_name, "action") == 0)
12641 const gchar *action_name = NULL;
12642 const gchar *description = NULL;
12643 const gchar *msg_context = NULL;
12644 gboolean translatable = FALSE;
12645 AtkActionData *action;
12647 for (i = 0; names[i]; i++)
12649 if (strcmp (names[i], "action_name") == 0)
12650 action_name = values[i];
12651 else if (strcmp (names[i], "description") == 0)
12652 description = values[i];
12653 else if (strcmp (names[i], "translatable") == 0)
12655 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12658 else if (strcmp (names[i], "comments") == 0)
12660 /* do nothing, comments are for translators */
12662 else if (strcmp (names[i], "context") == 0)
12663 msg_context = values[i];
12666 g_markup_parse_context_get_position (context,
12669 g_set_error (error,
12671 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12672 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12674 line_number, char_number, names[i], "action");
12681 g_markup_parse_context_get_position (context,
12684 g_set_error (error,
12686 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12687 "%s:%d:%d <%s> requires attribute \"%s\"",
12689 line_number, char_number, "action",
12694 action = g_slice_new (AtkActionData);
12695 action->action_name = g_strdup (action_name);
12696 action->description = g_string_new (description);
12697 action->context = g_strdup (msg_context);
12698 action->translatable = translatable;
12700 data->actions = g_slist_prepend (data->actions, action);
12702 else if (strcmp (element_name, "accessibility") == 0)
12705 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12709 accessibility_text (GMarkupParseContext *context,
12712 gpointer user_data,
12715 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12717 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12719 AtkActionData *action = data->actions->data;
12721 g_string_append_len (action->description, text, text_len);
12725 static const GMarkupParser accessibility_parser =
12727 accessibility_start_element,
12729 accessibility_text,
12738 } AccelGroupParserData;
12741 accel_group_start_element (GMarkupParseContext *context,
12742 const gchar *element_name,
12743 const gchar **names,
12744 const gchar **values,
12745 gpointer user_data,
12750 guint modifiers = 0;
12751 gchar *signal = NULL;
12752 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12754 for (i = 0; names[i]; i++)
12756 if (strcmp (names[i], "key") == 0)
12757 key = gdk_keyval_from_name (values[i]);
12758 else if (strcmp (names[i], "modifiers") == 0)
12760 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12766 else if (strcmp (names[i], "signal") == 0)
12767 signal = g_strdup (values[i]);
12770 if (key == 0 || signal == NULL)
12772 g_warning ("<accelerator> requires key and signal attributes");
12775 parser_data->key = key;
12776 parser_data->modifiers = modifiers;
12777 parser_data->signal = signal;
12780 static const GMarkupParser accel_group_parser =
12782 accel_group_start_element,
12791 style_start_element (GMarkupParseContext *context,
12792 const gchar *element_name,
12793 const gchar **names,
12794 const gchar **values,
12795 gpointer user_data,
12798 StyleParserData *style_data = (StyleParserData *)user_data;
12801 if (strcmp (element_name, "class") == 0)
12803 if (g_markup_collect_attributes (element_name,
12807 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12808 G_MARKUP_COLLECT_INVALID))
12810 style_data->classes = g_slist_append (style_data->classes, class_name);
12813 else if (strcmp (element_name, "style") == 0)
12816 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12819 static const GMarkupParser style_parser =
12821 style_start_element,
12825 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12826 GtkBuilder *builder,
12828 const gchar *tagname,
12829 GMarkupParser *parser,
12832 g_assert (buildable);
12834 if (strcmp (tagname, "accelerator") == 0)
12836 AccelGroupParserData *parser_data;
12838 parser_data = g_slice_new0 (AccelGroupParserData);
12839 parser_data->object = g_object_ref (buildable);
12840 *parser = accel_group_parser;
12841 *data = parser_data;
12844 if (strcmp (tagname, "accessibility") == 0)
12846 AccessibilitySubParserData *parser_data;
12848 parser_data = g_slice_new0 (AccessibilitySubParserData);
12849 *parser = accessibility_parser;
12850 *data = parser_data;
12853 if (strcmp (tagname, "style") == 0)
12855 StyleParserData *parser_data;
12857 parser_data = g_slice_new0 (StyleParserData);
12858 *parser = style_parser;
12859 *data = parser_data;
12867 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12868 GtkWidget *toplevel,
12869 gpointer user_data)
12871 AccelGroupParserData *accel_data;
12872 GSList *accel_groups;
12873 GtkAccelGroup *accel_group;
12875 g_return_if_fail (GTK_IS_WIDGET (widget));
12876 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12877 g_return_if_fail (user_data != NULL);
12879 accel_data = (AccelGroupParserData*)user_data;
12880 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12881 if (g_slist_length (accel_groups) == 0)
12883 accel_group = gtk_accel_group_new ();
12884 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12888 g_assert (g_slist_length (accel_groups) == 1);
12889 accel_group = g_slist_nth_data (accel_groups, 0);
12892 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12893 accel_data->signal,
12896 accel_data->modifiers,
12897 GTK_ACCEL_VISIBLE);
12899 g_object_unref (accel_data->object);
12900 g_free (accel_data->signal);
12901 g_slice_free (AccelGroupParserData, accel_data);
12905 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12906 GtkBuilder *builder,
12908 const gchar *tagname,
12909 gpointer user_data)
12911 if (strcmp (tagname, "accelerator") == 0)
12913 AccelGroupParserData *accel_data;
12914 GtkWidget *toplevel;
12916 accel_data = (AccelGroupParserData*)user_data;
12917 g_assert (accel_data->object);
12919 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12921 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12923 else if (strcmp (tagname, "accessibility") == 0)
12925 AccessibilitySubParserData *a11y_data;
12927 a11y_data = (AccessibilitySubParserData*)user_data;
12929 if (a11y_data->actions)
12931 AtkObject *accessible;
12936 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12938 if (ATK_IS_ACTION (accessible))
12940 action = ATK_ACTION (accessible);
12941 n_actions = atk_action_get_n_actions (action);
12943 for (l = a11y_data->actions; l; l = l->next)
12945 AtkActionData *action_data = (AtkActionData*)l->data;
12947 for (i = 0; i < n_actions; i++)
12948 if (strcmp (atk_action_get_name (action, i),
12949 action_data->action_name) == 0)
12954 gchar *description;
12956 if (action_data->translatable && action_data->description->len)
12957 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12958 action_data->context,
12959 action_data->description->str);
12961 description = action_data->description->str;
12963 atk_action_set_description (action, i, description);
12968 g_warning ("accessibility action on a widget that does not implement AtkAction");
12970 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
12971 g_slist_free (a11y_data->actions);
12974 if (a11y_data->relations)
12975 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12976 a11y_data->relations);
12978 g_slice_free (AccessibilitySubParserData, a11y_data);
12980 else if (strcmp (tagname, "style") == 0)
12982 StyleParserData *style_data = (StyleParserData *)user_data;
12983 GtkStyleContext *context;
12986 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
12988 for (l = style_data->classes; l; l = l->next)
12989 gtk_style_context_add_class (context, (const gchar *)l->data);
12991 gtk_widget_reset_style (GTK_WIDGET (buildable));
12993 g_slist_free_full (style_data->classes, g_free);
12994 g_slice_free (StyleParserData, style_data);
12998 static GtkSizeRequestMode
12999 gtk_widget_real_get_request_mode (GtkWidget *widget)
13001 /* By default widgets dont trade size at all. */
13002 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
13006 gtk_widget_real_get_width (GtkWidget *widget,
13007 gint *minimum_size,
13008 gint *natural_size)
13018 gtk_widget_real_get_height (GtkWidget *widget,
13019 gint *minimum_size,
13020 gint *natural_size)
13030 gtk_widget_real_get_height_for_width (GtkWidget *widget,
13032 gint *minimum_height,
13033 gint *natural_height)
13035 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
13039 gtk_widget_real_get_width_for_height (GtkWidget *widget,
13041 gint *minimum_width,
13042 gint *natural_width)
13044 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
13048 * gtk_widget_get_halign:
13049 * @widget: a #GtkWidget
13051 * Gets the value of the #GtkWidget:halign property.
13053 * Returns: the horizontal alignment of @widget
13056 gtk_widget_get_halign (GtkWidget *widget)
13058 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
13059 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
13063 * gtk_widget_set_halign:
13064 * @widget: a #GtkWidget
13065 * @align: the horizontal alignment
13067 * Sets the horizontal alignment of @widget.
13068 * See the #GtkWidget:halign property.
13071 gtk_widget_set_halign (GtkWidget *widget,
13074 GtkWidgetAuxInfo *aux_info;
13076 g_return_if_fail (GTK_IS_WIDGET (widget));
13078 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
13080 if (aux_info->halign == align)
13083 aux_info->halign = align;
13084 gtk_widget_queue_resize (widget);
13085 g_object_notify (G_OBJECT (widget), "halign");
13089 * gtk_widget_get_valign:
13090 * @widget: a #GtkWidget
13092 * Gets the value of the #GtkWidget:valign property.
13094 * Returns: the vertical alignment of @widget
13097 gtk_widget_get_valign (GtkWidget *widget)
13099 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
13100 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
13104 * gtk_widget_set_valign:
13105 * @widget: a #GtkWidget
13106 * @align: the vertical alignment
13108 * Sets the vertical alignment of @widget.
13109 * See the #GtkWidget:valign property.
13112 gtk_widget_set_valign (GtkWidget *widget,
13115 GtkWidgetAuxInfo *aux_info;
13117 g_return_if_fail (GTK_IS_WIDGET (widget));
13119 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
13121 if (aux_info->valign == align)
13124 aux_info->valign = align;
13125 gtk_widget_queue_resize (widget);
13126 g_object_notify (G_OBJECT (widget), "valign");
13130 * gtk_widget_get_margin_left:
13131 * @widget: a #GtkWidget
13133 * Gets the value of the #GtkWidget:margin-left property.
13135 * Returns: The left margin of @widget
13138 gtk_widget_get_margin_left (GtkWidget *widget)
13140 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13142 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
13146 * gtk_widget_set_margin_left:
13147 * @widget: a #GtkWidget
13148 * @margin: the left margin
13150 * Sets the left margin of @widget.
13151 * See the #GtkWidget:margin-left property.
13154 gtk_widget_set_margin_left (GtkWidget *widget,
13157 GtkWidgetAuxInfo *aux_info;
13159 g_return_if_fail (GTK_IS_WIDGET (widget));
13160 g_return_if_fail (margin <= G_MAXINT16);
13162 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
13164 if (aux_info->margin.left == margin)
13167 aux_info->margin.left = margin;
13168 gtk_widget_queue_resize (widget);
13169 g_object_notify (G_OBJECT (widget), "margin-left");
13173 * gtk_widget_get_margin_right:
13174 * @widget: a #GtkWidget
13176 * Gets the value of the #GtkWidget:margin-right property.
13178 * Returns: The left margin of @widget
13181 gtk_widget_get_margin_right (GtkWidget *widget)
13183 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13185 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
13189 * gtk_widget_set_margin_right:
13190 * @widget: a #GtkWidget
13191 * @margin: the right margin
13193 * Sets the right margin of @widget.
13194 * See the #GtkWidget:margin-right property.
13197 gtk_widget_set_margin_right (GtkWidget *widget,
13200 GtkWidgetAuxInfo *aux_info;
13202 g_return_if_fail (GTK_IS_WIDGET (widget));
13203 g_return_if_fail (margin <= G_MAXINT16);
13205 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
13207 if (aux_info->margin.right == margin)
13210 aux_info->margin.right = margin;
13211 gtk_widget_queue_resize (widget);
13212 g_object_notify (G_OBJECT (widget), "margin-right");
13216 * gtk_widget_get_margin_top:
13217 * @widget: a #GtkWidget
13219 * Gets the value of the #GtkWidget:margin-top property.
13221 * Returns: The top margin of @widget
13224 gtk_widget_get_margin_top (GtkWidget *widget)
13226 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13228 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
13232 * gtk_widget_set_margin_top:
13233 * @widget: a #GtkWidget
13234 * @margin: the top margin
13236 * Sets the top margin of @widget.
13237 * See the #GtkWidget:margin-top property.
13240 gtk_widget_set_margin_top (GtkWidget *widget,
13243 GtkWidgetAuxInfo *aux_info;
13245 g_return_if_fail (GTK_IS_WIDGET (widget));
13246 g_return_if_fail (margin <= G_MAXINT16);
13248 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
13250 if (aux_info->margin.top == margin)
13253 aux_info->margin.top = margin;
13254 gtk_widget_queue_resize (widget);
13255 g_object_notify (G_OBJECT (widget), "margin-top");
13259 * gtk_widget_get_margin_bottom:
13260 * @widget: a #GtkWidget
13262 * Gets the value of the #GtkWidget:margin-bottom property.
13264 * Returns: The bottom margin of @widget
13267 gtk_widget_get_margin_bottom (GtkWidget *widget)
13269 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13271 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
13275 * gtk_widget_set_margin_bottom:
13276 * @widget: a #GtkWidget
13277 * @margin: the bottom margin
13279 * Sets the bottom margin of @widget.
13280 * See the #GtkWidget:margin-bottom property.
13283 gtk_widget_set_margin_bottom (GtkWidget *widget,
13286 GtkWidgetAuxInfo *aux_info;
13288 g_return_if_fail (GTK_IS_WIDGET (widget));
13289 g_return_if_fail (margin <= G_MAXINT16);
13291 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
13293 if (aux_info->margin.bottom == margin)
13296 aux_info->margin.bottom = margin;
13297 gtk_widget_queue_resize (widget);
13298 g_object_notify (G_OBJECT (widget), "margin-bottom");
13302 * gtk_widget_get_clipboard:
13303 * @widget: a #GtkWidget
13304 * @selection: a #GdkAtom which identifies the clipboard
13305 * to use. %GDK_SELECTION_CLIPBOARD gives the
13306 * default clipboard. Another common value
13307 * is %GDK_SELECTION_PRIMARY, which gives
13308 * the primary X selection.
13310 * Returns the clipboard object for the given selection to
13311 * be used with @widget. @widget must have a #GdkDisplay
13312 * associated with it, so must be attached to a toplevel
13315 * Return value: (transfer none): the appropriate clipboard object. If no
13316 * clipboard already exists, a new one will
13317 * be created. Once a clipboard object has
13318 * been created, it is persistent for all time.
13323 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
13325 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13326 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
13328 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
13333 * gtk_widget_list_mnemonic_labels:
13334 * @widget: a #GtkWidget
13336 * Returns a newly allocated list of the widgets, normally labels, for
13337 * which this widget is the target of a mnemonic (see for example,
13338 * gtk_label_set_mnemonic_widget()).
13340 * The widgets in the list are not individually referenced. If you
13341 * want to iterate through the list and perform actions involving
13342 * callbacks that might destroy the widgets, you
13343 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
13344 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
13345 * widgets afterwards.
13347 * Return value: (element-type GtkWidget) (transfer container): the list of
13348 * mnemonic labels; free this list
13349 * with g_list_free() when you are done with it.
13354 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
13356 GList *list = NULL;
13359 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13361 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13362 list = g_list_prepend (list, l->data);
13368 * gtk_widget_add_mnemonic_label:
13369 * @widget: a #GtkWidget
13370 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13372 * Adds a widget to the list of mnemonic labels for
13373 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13374 * list of mnemonic labels for the widget is cleared when the
13375 * widget is destroyed, so the caller must make sure to update
13376 * its internal state at this point as well, by using a connection
13377 * to the #GtkWidget::destroy signal or a weak notifier.
13382 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13385 GSList *old_list, *new_list;
13387 g_return_if_fail (GTK_IS_WIDGET (widget));
13388 g_return_if_fail (GTK_IS_WIDGET (label));
13390 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13391 new_list = g_slist_prepend (old_list, label);
13393 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13394 new_list, (GDestroyNotify) g_slist_free);
13398 * gtk_widget_remove_mnemonic_label:
13399 * @widget: a #GtkWidget
13400 * @label: a #GtkWidget that was previously set as a mnemnic label for
13401 * @widget with gtk_widget_add_mnemonic_label().
13403 * Removes a widget from the list of mnemonic labels for
13404 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13405 * must have previously been added to the list with
13406 * gtk_widget_add_mnemonic_label().
13411 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13414 GSList *old_list, *new_list;
13416 g_return_if_fail (GTK_IS_WIDGET (widget));
13417 g_return_if_fail (GTK_IS_WIDGET (label));
13419 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13420 new_list = g_slist_remove (old_list, label);
13423 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13424 new_list, (GDestroyNotify) g_slist_free);
13428 * gtk_widget_get_no_show_all:
13429 * @widget: a #GtkWidget
13431 * Returns the current value of the #GtkWidget:no-show-all property,
13432 * which determines whether calls to gtk_widget_show_all()
13433 * will affect this widget.
13435 * Return value: the current value of the "no-show-all" property.
13440 gtk_widget_get_no_show_all (GtkWidget *widget)
13442 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13444 return widget->priv->no_show_all;
13448 * gtk_widget_set_no_show_all:
13449 * @widget: a #GtkWidget
13450 * @no_show_all: the new value for the "no-show-all" property
13452 * Sets the #GtkWidget:no-show-all property, which determines whether
13453 * calls to gtk_widget_show_all() will affect this widget.
13455 * This is mostly for use in constructing widget hierarchies with externally
13456 * controlled visibility, see #GtkUIManager.
13461 gtk_widget_set_no_show_all (GtkWidget *widget,
13462 gboolean no_show_all)
13464 g_return_if_fail (GTK_IS_WIDGET (widget));
13466 no_show_all = (no_show_all != FALSE);
13468 if (widget->priv->no_show_all != no_show_all)
13470 widget->priv->no_show_all = no_show_all;
13472 g_object_notify (G_OBJECT (widget), "no-show-all");
13478 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13479 gboolean has_tooltip,
13482 GtkWidgetPrivate *priv = widget->priv;
13483 gboolean priv_has_tooltip;
13485 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13486 quark_has_tooltip));
13488 if (priv_has_tooltip != has_tooltip || force)
13490 priv_has_tooltip = has_tooltip;
13492 if (priv_has_tooltip)
13494 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13495 gdk_window_set_events (priv->window,
13496 gdk_window_get_events (priv->window) |
13497 GDK_LEAVE_NOTIFY_MASK |
13498 GDK_POINTER_MOTION_MASK |
13499 GDK_POINTER_MOTION_HINT_MASK);
13501 if (gtk_widget_get_has_window (widget))
13502 gtk_widget_add_events (widget,
13503 GDK_LEAVE_NOTIFY_MASK |
13504 GDK_POINTER_MOTION_MASK |
13505 GDK_POINTER_MOTION_HINT_MASK);
13508 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13509 GUINT_TO_POINTER (priv_has_tooltip));
13514 * gtk_widget_set_tooltip_window:
13515 * @widget: a #GtkWidget
13516 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13518 * Replaces the default, usually yellow, window used for displaying
13519 * tooltips with @custom_window. GTK+ will take care of showing and
13520 * hiding @custom_window at the right moment, to behave likewise as
13521 * the default tooltip window. If @custom_window is %NULL, the default
13522 * tooltip window will be used.
13524 * If the custom window should have the default theming it needs to
13525 * have the name "gtk-tooltip", see gtk_widget_set_name().
13530 gtk_widget_set_tooltip_window (GtkWidget *widget,
13531 GtkWindow *custom_window)
13533 gboolean has_tooltip;
13534 gchar *tooltip_markup;
13536 g_return_if_fail (GTK_IS_WIDGET (widget));
13537 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13539 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13542 g_object_ref (custom_window);
13544 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13545 custom_window, g_object_unref);
13547 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13548 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13550 if (has_tooltip && gtk_widget_get_visible (widget))
13551 gtk_widget_queue_tooltip_query (widget);
13555 * gtk_widget_get_tooltip_window:
13556 * @widget: a #GtkWidget
13558 * Returns the #GtkWindow of the current tooltip. This can be the
13559 * GtkWindow created by default, or the custom tooltip window set
13560 * using gtk_widget_set_tooltip_window().
13562 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13567 gtk_widget_get_tooltip_window (GtkWidget *widget)
13569 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13571 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13575 * gtk_widget_trigger_tooltip_query:
13576 * @widget: a #GtkWidget
13578 * Triggers a tooltip query on the display where the toplevel of @widget
13579 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13585 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13587 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13590 static guint tooltip_query_id;
13591 static GSList *tooltip_query_displays;
13594 tooltip_query_idle (gpointer data)
13596 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13597 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13598 g_slist_free (tooltip_query_displays);
13600 tooltip_query_displays = NULL;
13601 tooltip_query_id = 0;
13607 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13609 GdkDisplay *display;
13611 display = gtk_widget_get_display (widget);
13613 if (!g_slist_find (tooltip_query_displays, display))
13614 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13616 if (tooltip_query_id == 0)
13617 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13621 * gtk_widget_set_tooltip_text:
13622 * @widget: a #GtkWidget
13623 * @text: the contents of the tooltip for @widget
13625 * Sets @text as the contents of the tooltip. This function will take
13626 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13627 * handler for the #GtkWidget::query-tooltip signal.
13629 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13634 gtk_widget_set_tooltip_text (GtkWidget *widget,
13637 g_return_if_fail (GTK_IS_WIDGET (widget));
13639 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13643 * gtk_widget_get_tooltip_text:
13644 * @widget: a #GtkWidget
13646 * Gets the contents of the tooltip for @widget.
13648 * Return value: the tooltip text, or %NULL. You should free the
13649 * returned string with g_free() when done.
13654 gtk_widget_get_tooltip_text (GtkWidget *widget)
13656 gchar *text = NULL;
13658 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13660 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13666 * gtk_widget_set_tooltip_markup:
13667 * @widget: a #GtkWidget
13668 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13670 * Sets @markup as the contents of the tooltip, which is marked up with
13671 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13673 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13674 * and of the default handler for the #GtkWidget::query-tooltip signal.
13676 * See also the #GtkWidget:tooltip-markup property and
13677 * gtk_tooltip_set_markup().
13682 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13683 const gchar *markup)
13685 g_return_if_fail (GTK_IS_WIDGET (widget));
13687 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13691 * gtk_widget_get_tooltip_markup:
13692 * @widget: a #GtkWidget
13694 * Gets the contents of the tooltip for @widget.
13696 * Return value: the tooltip text, or %NULL. You should free the
13697 * returned string with g_free() when done.
13702 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13704 gchar *text = NULL;
13706 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13708 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13714 * gtk_widget_set_has_tooltip:
13715 * @widget: a #GtkWidget
13716 * @has_tooltip: whether or not @widget has a tooltip.
13718 * Sets the has-tooltip property on @widget to @has_tooltip. See
13719 * #GtkWidget:has-tooltip for more information.
13724 gtk_widget_set_has_tooltip (GtkWidget *widget,
13725 gboolean has_tooltip)
13727 g_return_if_fail (GTK_IS_WIDGET (widget));
13729 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13733 * gtk_widget_get_has_tooltip:
13734 * @widget: a #GtkWidget
13736 * Returns the current value of the has-tooltip property. See
13737 * #GtkWidget:has-tooltip for more information.
13739 * Return value: current value of has-tooltip on @widget.
13744 gtk_widget_get_has_tooltip (GtkWidget *widget)
13746 gboolean has_tooltip = FALSE;
13748 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13750 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13752 return has_tooltip;
13756 * gtk_widget_get_allocation:
13757 * @widget: a #GtkWidget
13758 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13760 * Retrieves the widget's allocation.
13762 * Note, when implementing a #GtkContainer: a widget's allocation will
13763 * be its "adjusted" allocation, that is, the widget's parent
13764 * container typically calls gtk_widget_size_allocate() with an
13765 * allocation, and that allocation is then adjusted (to handle margin
13766 * and alignment for example) before assignment to the widget.
13767 * gtk_widget_get_allocation() returns the adjusted allocation that
13768 * was actually assigned to the widget. The adjusted allocation is
13769 * guaranteed to be completely contained within the
13770 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13771 * is guaranteed that its children stay inside the assigned bounds,
13772 * but not that they have exactly the bounds the container assigned.
13773 * There is no way to get the original allocation assigned by
13774 * gtk_widget_size_allocate(), since it isn't stored; if a container
13775 * implementation needs that information it will have to track it itself.
13780 gtk_widget_get_allocation (GtkWidget *widget,
13781 GtkAllocation *allocation)
13783 GtkWidgetPrivate *priv;
13785 g_return_if_fail (GTK_IS_WIDGET (widget));
13786 g_return_if_fail (allocation != NULL);
13788 priv = widget->priv;
13790 *allocation = priv->allocation;
13794 * gtk_widget_set_allocation:
13795 * @widget: a #GtkWidget
13796 * @allocation: a pointer to a #GtkAllocation to copy from
13798 * Sets the widget's allocation. This should not be used
13799 * directly, but from within a widget's size_allocate method.
13801 * The allocation set should be the "adjusted" or actual
13802 * allocation. If you're implementing a #GtkContainer, you want to use
13803 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13804 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13805 * allocation inside gtk_widget_size_allocate() to create an adjusted
13811 gtk_widget_set_allocation (GtkWidget *widget,
13812 const GtkAllocation *allocation)
13814 GtkWidgetPrivate *priv;
13816 g_return_if_fail (GTK_IS_WIDGET (widget));
13817 g_return_if_fail (allocation != NULL);
13819 priv = widget->priv;
13821 priv->allocation = *allocation;
13825 * gtk_widget_get_allocated_width:
13826 * @widget: the widget to query
13828 * Returns the width that has currently been allocated to @widget.
13829 * This function is intended to be used when implementing handlers
13830 * for the #GtkWidget::draw function.
13832 * Returns: the width of the @widget
13835 gtk_widget_get_allocated_width (GtkWidget *widget)
13837 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13839 return widget->priv->allocation.width;
13843 * gtk_widget_get_allocated_height:
13844 * @widget: the widget to query
13846 * Returns the height that has currently been allocated to @widget.
13847 * This function is intended to be used when implementing handlers
13848 * for the #GtkWidget::draw function.
13850 * Returns: the height of the @widget
13853 gtk_widget_get_allocated_height (GtkWidget *widget)
13855 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13857 return widget->priv->allocation.height;
13861 * gtk_widget_get_requisition:
13862 * @widget: a #GtkWidget
13863 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13865 * Retrieves the widget's requisition.
13867 * This function should only be used by widget implementations in
13868 * order to figure whether the widget's requisition has actually
13869 * changed after some internal state change (so that they can call
13870 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13872 * Normally, gtk_widget_size_request() should be used.
13876 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13877 * removed, If you need to cache sizes across requests and allocations,
13878 * add an explicit cache to the widget in question instead.
13881 gtk_widget_get_requisition (GtkWidget *widget,
13882 GtkRequisition *requisition)
13884 g_return_if_fail (GTK_IS_WIDGET (widget));
13885 g_return_if_fail (requisition != NULL);
13887 gtk_widget_get_preferred_size (widget, requisition, NULL);
13891 * gtk_widget_set_window:
13892 * @widget: a #GtkWidget
13893 * @window: a #GdkWindow
13895 * Sets a widget's window. This function should only be used in a
13896 * widget's #GtkWidget::realize implementation. The %window passed is
13897 * usually either new window created with gdk_window_new(), or the
13898 * window of its parent widget as returned by
13899 * gtk_widget_get_parent_window().
13901 * Widgets must indicate whether they will create their own #GdkWindow
13902 * by calling gtk_widget_set_has_window(). This is usually done in the
13903 * widget's init() function.
13905 * <note><para>This function does not add any reference to @window.</para></note>
13910 gtk_widget_set_window (GtkWidget *widget,
13913 GtkWidgetPrivate *priv;
13915 g_return_if_fail (GTK_IS_WIDGET (widget));
13916 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13918 priv = widget->priv;
13920 if (priv->window != window)
13922 priv->window = window;
13923 g_object_notify (G_OBJECT (widget), "window");
13928 * gtk_widget_get_window:
13929 * @widget: a #GtkWidget
13931 * Returns the widget's window if it is realized, %NULL otherwise
13933 * Return value: (transfer none): @widget's window.
13938 gtk_widget_get_window (GtkWidget *widget)
13940 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13942 return widget->priv->window;
13946 * gtk_widget_get_support_multidevice:
13947 * @widget: a #GtkWidget
13949 * Returns %TRUE if @widget is multiple pointer aware. See
13950 * gtk_widget_set_support_multidevice() for more information.
13952 * Returns: %TRUE if @widget is multidevice aware.
13955 gtk_widget_get_support_multidevice (GtkWidget *widget)
13957 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13959 return widget->priv->multidevice;
13963 * gtk_widget_set_support_multidevice:
13964 * @widget: a #GtkWidget
13965 * @support_multidevice: %TRUE to support input from multiple devices.
13967 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13968 * @widget will start receiving multiple, per device enter/leave events. Note
13969 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13970 * gdk_window_set_support_multidevice() will have to be called manually on them.
13975 gtk_widget_set_support_multidevice (GtkWidget *widget,
13976 gboolean support_multidevice)
13978 GtkWidgetPrivate *priv;
13980 g_return_if_fail (GTK_IS_WIDGET (widget));
13982 priv = widget->priv;
13983 priv->multidevice = (support_multidevice == TRUE);
13985 if (gtk_widget_get_realized (widget))
13986 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13990 _gtk_widget_set_has_focus (GtkWidget *widget,
13991 gboolean has_focus)
13993 widget->priv->has_focus = has_focus;
13996 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
13998 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
14002 * gtk_widget_send_focus_change:
14003 * @widget: a #GtkWidget
14004 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
14006 * Sends the focus change @event to @widget
14008 * This function is not meant to be used by applications. The only time it
14009 * should be used is when it is necessary for a #GtkWidget to assign focus
14010 * to a widget that is semantically owned by the first widget even though
14011 * it's not a direct child - for instance, a search entry in a floating
14012 * window similar to the quick search in #GtkTreeView.
14014 * An example of its usage is:
14017 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
14019 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
14020 * fevent->focus_change.in = TRUE;
14021 * fevent->focus_change.window = gtk_widget_get_window (widget);
14022 * if (fevent->focus_change.window != NULL)
14023 * g_object_ref (fevent->focus_change.window);
14025 * gtk_widget_send_focus_change (widget, fevent);
14027 * gdk_event_free (event);
14030 * Return value: the return value from the event signal emission: %TRUE
14031 * if the event was handled, and %FALSE otherwise
14036 gtk_widget_send_focus_change (GtkWidget *widget,
14041 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
14042 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
14044 g_object_ref (widget);
14046 _gtk_widget_set_has_focus (widget, event->focus_change.in);
14048 res = gtk_widget_event (widget, event);
14050 g_object_notify (G_OBJECT (widget), "has-focus");
14052 g_object_unref (widget);
14058 * gtk_widget_in_destruction:
14059 * @widget: a #GtkWidget
14061 * Returns whether the widget is currently being destroyed.
14062 * This information can sometimes be used to avoid doing
14063 * unnecessary work.
14065 * Returns: %TRUE if @widget is being destroyed
14068 gtk_widget_in_destruction (GtkWidget *widget)
14070 return widget->priv->in_destruction;
14074 _gtk_widget_get_resize_pending (GtkWidget *widget)
14076 return widget->priv->resize_pending;
14080 _gtk_widget_set_resize_pending (GtkWidget *widget,
14081 gboolean resize_pending)
14083 widget->priv->resize_pending = resize_pending;
14087 _gtk_widget_get_in_reparent (GtkWidget *widget)
14089 return widget->priv->in_reparent;
14093 _gtk_widget_set_in_reparent (GtkWidget *widget,
14094 gboolean in_reparent)
14096 widget->priv->in_reparent = in_reparent;
14100 _gtk_widget_get_anchored (GtkWidget *widget)
14102 return widget->priv->anchored;
14106 _gtk_widget_set_anchored (GtkWidget *widget,
14109 widget->priv->anchored = anchored;
14113 _gtk_widget_get_shadowed (GtkWidget *widget)
14115 return widget->priv->shadowed;
14119 _gtk_widget_set_shadowed (GtkWidget *widget,
14122 widget->priv->shadowed = shadowed;
14126 _gtk_widget_get_alloc_needed (GtkWidget *widget)
14128 return widget->priv->alloc_needed;
14132 _gtk_widget_set_alloc_needed (GtkWidget *widget,
14133 gboolean alloc_needed)
14135 widget->priv->alloc_needed = alloc_needed;
14139 _gtk_widget_get_width_request_needed (GtkWidget *widget)
14141 return widget->priv->width_request_needed;
14145 _gtk_widget_set_width_request_needed (GtkWidget *widget,
14146 gboolean width_request_needed)
14148 widget->priv->width_request_needed = width_request_needed;
14152 _gtk_widget_get_height_request_needed (GtkWidget *widget)
14154 return widget->priv->height_request_needed;
14158 _gtk_widget_set_height_request_needed (GtkWidget *widget,
14159 gboolean height_request_needed)
14161 widget->priv->height_request_needed = height_request_needed;
14165 _gtk_widget_get_sizegroup_visited (GtkWidget *widget)
14167 return widget->priv->sizegroup_visited;
14171 _gtk_widget_set_sizegroup_visited (GtkWidget *widget,
14174 widget->priv->sizegroup_visited = visited;
14178 _gtk_widget_get_sizegroup_bumping (GtkWidget *widget)
14180 return widget->priv->sizegroup_bumping;
14184 _gtk_widget_set_sizegroup_bumping (GtkWidget *widget,
14187 widget->priv->sizegroup_bumping = bumping;
14191 _gtk_widget_add_sizegroup (GtkWidget *widget,
14196 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14197 groups = g_slist_prepend (groups, group);
14198 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14200 widget->priv->have_size_groups = TRUE;
14204 _gtk_widget_remove_sizegroup (GtkWidget *widget,
14209 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14210 groups = g_slist_remove (groups, group);
14211 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14213 widget->priv->have_size_groups = groups != NULL;
14217 _gtk_widget_get_sizegroups (GtkWidget *widget)
14219 if (widget->priv->have_size_groups)
14220 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14226 * gtk_widget_get_path:
14227 * @widget: a #GtkWidget
14229 * Returns the #GtkWidgetPath representing @widget, if the widget
14230 * is not connected to a toplevel widget, a partial path will be
14233 * Returns: (transfer none): The #GtkWidgetPath representing @widget
14236 gtk_widget_get_path (GtkWidget *widget)
14238 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14240 /* As strange as it may seem, this may happen on object construction.
14241 * init() implementations of parent types may eventually call this function,
14242 * each with its corresponding GType, which could leave a child
14243 * implementation with a wrong widget type in the widget path
14245 if (widget->priv->path &&
14246 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (widget->priv->path))
14248 gtk_widget_path_free (widget->priv->path);
14249 widget->priv->path = NULL;
14252 if (!widget->priv->path)
14257 parent = widget->priv->parent;
14260 widget->priv->path = gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
14263 /* Widget is either toplevel or unparented, treat both
14264 * as toplevels style wise, since there are situations
14265 * where style properties might be retrieved on that
14268 widget->priv->path = gtk_widget_path_new ();
14271 pos = gtk_widget_path_append_type (widget->priv->path, G_OBJECT_TYPE (widget));
14273 if (widget->priv->name)
14274 gtk_widget_path_iter_set_name (widget->priv->path, pos, widget->priv->name);
14276 if (widget->priv->context)
14278 GList *classes, *l;
14280 /* Also add any persistent classes in
14281 * the style context the widget path
14283 classes = gtk_style_context_list_classes (widget->priv->context);
14285 for (l = classes; l; l = l->next)
14286 gtk_widget_path_iter_add_class (widget->priv->path, pos, l->data);
14288 gtk_style_context_set_path (widget->priv->context,
14289 widget->priv->path);
14291 g_list_free (classes);
14295 return widget->priv->path;
14299 style_context_changed (GtkStyleContext *context,
14300 gpointer user_data)
14302 GtkWidget *widget = user_data;
14304 gtk_widget_update_pango_context (widget);
14306 if (gtk_widget_get_realized (widget))
14307 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
14310 /* Compress all style updates so it
14311 * is only emitted once pre-realize.
14313 widget->priv->style_update_pending = TRUE;
14316 if (widget->priv->anchored)
14317 gtk_widget_queue_resize (widget);
14321 * gtk_widget_get_style_context:
14322 * @widget: a #GtkWidget
14324 * Returns the style context associated to @widget.
14326 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
14327 * must not be freed.
14330 gtk_widget_get_style_context (GtkWidget *widget)
14332 GtkWidgetPrivate *priv;
14333 GtkWidgetPath *path;
14335 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14337 priv = widget->priv;
14339 /* updates style context if it exists already */
14340 path = gtk_widget_get_path (widget);
14342 if (G_UNLIKELY (priv->context == NULL))
14346 priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
14347 "direction", gtk_widget_get_direction (widget),
14350 g_signal_connect (widget->priv->context, "changed",
14351 G_CALLBACK (style_context_changed), widget);
14353 screen = gtk_widget_get_screen (widget);
14356 gtk_style_context_set_screen (priv->context, screen);
14358 gtk_style_context_set_path (priv->context, path);
14361 return widget->priv->context;