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 "gtkaccelmapprivate.h"
39 #include "gtkclipboard.h"
40 #include "gtkiconfactory.h"
42 #include "gtkmarshalers.h"
43 #include "gtkselectionprivate.h"
44 #include "gtksettingsprivate.h"
45 #include "gtksizegroup-private.h"
46 #include "gtkwidget.h"
47 #include "gtkwidgetprivate.h"
48 #include "gtkwindowprivate.h"
49 #include "gtkcontainerprivate.h"
50 #include "gtkbindings.h"
51 #include "gtkprivate.h"
52 #include "gtkaccessible.h"
53 #include "gtktooltip.h"
54 #include "gtkinvisible.h"
55 #include "gtkbuildable.h"
56 #include "gtkbuilderprivate.h"
57 #include "gtksizerequest.h"
58 #include "gtkstylecontextprivate.h"
59 #include "gtksymboliccolor.h"
60 #include "gtkcssprovider.h"
61 #include "gtkanimationdescription.h"
62 #include "gtkmodifierstyle.h"
63 #include "gtkversion.h"
66 #include "gtktypebuiltins.h"
67 #include "a11y/gtkwidgetaccessible.h"
71 * @Short_description: Base class for all widgets
74 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
75 * widget lifecycle, states and style.
77 * <refsect2 id="geometry-management">
78 * <title>Height-for-width Geometry Management</title>
80 * GTK+ uses a height-for-width (and width-for-height) geometry management
81 * system. Height-for-width means that a widget can change how much
82 * vertical space it needs, depending on the amount of horizontal space
83 * that it is given (and similar for width-for-height). The most common
84 * example is a label that reflows to fill up the available width, wraps
85 * to fewer lines, and therefore needs less height.
87 * Height-for-width geometry management is implemented in GTK+ by way
88 * of five virtual methods:
90 * <listitem>#GtkWidgetClass.get_request_mode()</listitem>
91 * <listitem>#GtkWidgetClass.get_preferred_width()</listitem>
92 * <listitem>#GtkWidgetClass.get_preferred_height()</listitem>
93 * <listitem>#GtkWidgetClass.get_preferred_height_for_width()</listitem>
94 * <listitem>#GtkWidgetClass.get_preferred_width_for_height()</listitem>
97 * There are some important things to keep in mind when implementing
98 * height-for-width and when using it in container implementations.
100 * The geometry management system will query a widget hierarchy in
101 * only one orientation at a time. When widgets are initially queried
102 * for their minimum sizes it is generally done in two initial passes
103 * in the #GtkSizeRequestMode chosen by the toplevel.
105 * For example, when queried in the normal
106 * %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode:
107 * First, the default minimum and natural width for each widget
108 * in the interface will be computed using gtk_widget_get_preferred_width().
109 * Because the preferred widths for each container depend on the preferred
110 * widths of their children, this information propagates up the hierarchy,
111 * and finally a minimum and natural width is determined for the entire
112 * toplevel. Next, the toplevel will use the minimum width to query for the
113 * minimum height contextual to that width using
114 * gtk_widget_get_preferred_height_for_width(), which will also be a highly
115 * recursive operation. The minimum height for the minimum width is normally
116 * used to set the minimum size constraint on the toplevel
117 * (unless gtk_window_set_geometry_hints() is explicitly used instead).
119 * After the toplevel window has initially requested its size in both
120 * dimensions it can go on to allocate itself a reasonable size (or a size
121 * previously specified with gtk_window_set_default_size()). During the
122 * recursive allocation process it's important to note that request cycles
123 * will be recursively executed while container widgets allocate their children.
124 * Each container widget, once allocated a size, will go on to first share the
125 * space in one orientation among its children and then request each child's
126 * height for its target allocated width or its width for allocated height,
127 * depending. In this way a #GtkWidget will typically be requested its size
128 * a number of times before actually being allocated a size. The size a
129 * widget is finally allocated can of course differ from the size it has
130 * requested. For this reason, #GtkWidget caches a small number of results
131 * to avoid re-querying for the same sizes in one allocation cycle.
133 * See <link linkend="container-geometry-management">GtkContainer's
134 * geometry management section</link>
135 * to learn more about how height-for-width allocations are performed
136 * by container widgets.
138 * If a widget does move content around to intelligently use up the
139 * allocated size then it must support the request in both
140 * #GtkSizeRequestModes even if the widget in question only
141 * trades sizes in a single orientation.
143 * For instance, a #GtkLabel that does height-for-width word wrapping
144 * will not expect to have #GtkWidgetClass.get_preferred_height() called
145 * because that call is specific to a width-for-height request. In this
146 * case the label must return the height required for its own minimum
147 * possible width. By following this rule any widget that handles
148 * height-for-width or width-for-height requests will always be allocated
149 * at least enough space to fit its own content.
151 * Here are some examples of how a %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH widget
152 * generally deals with width-for-height requests, for #GtkWidgetClass.get_preferred_height()
154 * <programlisting><![CDATA[
156 * foo_widget_get_preferred_height (GtkWidget *widget, gint *min_height, gint *nat_height)
158 * if (i_am_in_height_for_width_mode)
162 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
163 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width,
164 * min_height, nat_height);
168 * ... some widgets do both. For instance, if a GtkLabel is rotated to 90 degrees
169 * it will return the minimum and natural height for the rotated label here.
172 * ]]></programlisting>
174 * And in #GtkWidgetClass.get_preferred_width_for_height() it will simply return
175 * the minimum and natural width:
177 * <programlisting><![CDATA[
179 * foo_widget_get_preferred_width_for_height (GtkWidget *widget, gint for_height,
180 * gint *min_width, gint *nat_width)
182 * if (i_am_in_height_for_width_mode)
184 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, min_width, nat_width);
188 * ... again if a widget is sometimes operating in width-for-height mode
189 * (like a rotated GtkLabel) it can go ahead and do its real width for
190 * height calculation here.
193 * ]]></programlisting>
195 * Often a widget needs to get its own request during size request or
196 * allocation. For example, when computing height it may need to also
197 * compute width. Or when deciding how to use an allocation, the widget
198 * may need to know its natural size. In these cases, the widget should
199 * be careful to call its virtual methods directly, like this:
201 * <title>Widget calling its own size request method.</title>
203 * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget),
208 * It will not work to use the wrapper functions, such as
209 * gtk_widget_get_preferred_width() inside your own size request
210 * implementation. These return a request adjusted by #GtkSizeGroup
211 * and by the #GtkWidgetClass.adjust_size_request() virtual method. If a
212 * widget used the wrappers inside its virtual method implementations,
213 * then the adjustments (such as widget margins) would be applied
214 * twice. GTK+ therefore does not allow this and will warn if you try
217 * Of course if you are getting the size request for
218 * <emphasis>another</emphasis> widget, such as a child of a
219 * container, you <emphasis>must</emphasis> use the wrapper APIs.
220 * Otherwise, you would not properly consider widget margins,
221 * #GtkSizeGroup, and so forth.
224 * <refsect2 id="style-properties">
225 * <title>Style Properties</title>
227 * <structname>GtkWidget</structname> introduces <firstterm>style
228 * properties</firstterm> - these are basically object properties that are stored
229 * not on the object, but in the style object associated to the widget. Style
230 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
231 * This mechanism is used for configuring such things as the location of the
232 * scrollbar arrows through the theme, giving theme authors more control over the
233 * look of applications without the need to write a theme engine in C.
236 * Use gtk_widget_class_install_style_property() to install style properties for
237 * a widget class, gtk_widget_class_find_style_property() or
238 * gtk_widget_class_list_style_properties() to get information about existing
239 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
240 * gtk_widget_style_get_valist() to obtain the value of a style property.
243 * <refsect2 id="GtkWidget-BUILDER-UI">
244 * <title>GtkWidget as GtkBuildable</title>
246 * The GtkWidget implementation of the GtkBuildable interface supports a
247 * custom <accelerator> element, which has attributes named key,
248 * modifiers and signal and allows to specify accelerators.
251 * <title>A UI definition fragment specifying an accelerator</title>
252 * <programlisting><![CDATA[
253 * <object class="GtkButton">
254 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
256 * ]]></programlisting>
259 * In addition to accelerators, <structname>GtkWidget</structname> also support a
260 * custom <accessible> element, which supports actions and relations.
261 * Properties on the accessible implementation of an object can be set by accessing the
262 * internal child "accessible" of a <structname>GtkWidget</structname>.
265 * <title>A UI definition fragment specifying an accessible</title>
266 * <programlisting><![CDATA[
267 * <object class="GtkButton" id="label1"/>
268 * <property name="label">I am a Label for a Button</property>
270 * <object class="GtkButton" id="button1">
272 * <action action_name="click" translatable="yes">Click the button.</action>
273 * <relation target="label1" type="labelled-by"/>
275 * <child internal-child="accessible">
276 * <object class="AtkObject" id="a11y-button1">
277 * <property name="AtkObject::name">Clickable Button</property>
281 * ]]></programlisting>
284 * Finally, GtkWidget allows style information such as style classes to
285 * be associated with widgets, using the custom <style> element:
287 * <title>A UI definition fragment specifying an style class</title>
288 * <programlisting><![CDATA[
289 * <object class="GtkButton" id="button1">
291 * <class name="my-special-button-class"/>
292 * <class name="dark-button"/>
295 * ]]></programlisting>
301 /* Add flags here that should not be propagated to children. By default,
302 * all flags will be set on children (think prelight or active), but we
303 * might want to not do this for some.
305 #define GTK_STATE_FLAGS_DONT_PROPAGATE (GTK_STATE_FLAG_FOCUSED)
306 #define GTK_STATE_FLAGS_DO_PROPAGATE (~GTK_STATE_FLAGS_DONT_PROPAGATE)
308 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
310 #define GTK_STATE_FLAGS_BITS 7
312 struct _GtkWidgetPrivate
314 /* The state of the widget. Needs to be able to hold all GtkStateFlags bits
315 * (defined in "gtkenums.h").
317 guint state_flags : GTK_STATE_FLAGS_BITS;
321 guint in_destruction : 1;
324 guint composite_child : 1;
332 guint can_default : 1;
333 guint has_default : 1;
334 guint receives_default : 1;
337 guint style_update_pending : 1;
338 guint app_paintable : 1;
339 guint double_buffered : 1;
340 guint redraw_on_alloc : 1;
341 guint no_show_all : 1;
342 guint child_visible : 1;
343 guint multidevice : 1;
344 guint has_shape_mask : 1;
345 guint in_reparent : 1;
347 /* Queue-resize related flags */
348 guint resize_pending : 1;
349 guint alloc_needed : 1;
350 guint width_request_needed : 1;
351 guint height_request_needed : 1;
353 /* Expand-related flags */
354 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
355 guint computed_hexpand : 1; /* computed results (composite of child flags) */
356 guint computed_vexpand : 1;
357 guint hexpand : 1; /* application-forced expand */
359 guint hexpand_set : 1; /* whether to use application-forced */
360 guint vexpand_set : 1; /* instead of computing from children */
362 /* SizeGroup related flags */
363 guint sizegroup_visited : 1;
364 guint sizegroup_bumping : 1;
365 guint have_size_groups : 1;
367 /* The widget's name. If the widget does not have a name
368 * (the name is NULL), then its name (as returned by
369 * "gtk_widget_get_name") is its class's name.
370 * Among other things, the widget name is used to determine
371 * the style to use for a widget.
375 /* The list of attached windows to this widget.
376 * We keep a list in order to call reset_style to all of them,
378 GList *attached_windows;
380 /* The style for the widget. The style contains the
381 * colors the widget should be drawn in for each state
382 * along with graphics contexts used to draw with and
383 * the font to use for text.
386 GtkStyleContext *context;
388 /* Widget's path for styling */
391 /* The widget's allocated size */
392 GtkAllocation allocation;
394 /* The widget's requested sizes */
395 SizeRequestCache requests;
397 /* The widget's window or its parent window if it does
398 * not have a window. (Which will be indicated by the
399 * GTK_NO_WINDOW flag being set).
403 /* The widget's parent */
406 #ifdef G_ENABLE_DEBUG
407 /* Number of gtk_widget_push_verify_invariants () */
408 guint verifying_invariants_count;
409 #endif /* G_ENABLE_DEBUG */
412 struct _GtkWidgetClassPrivate
414 GType accessible_type;
415 AtkRole accessible_role;
444 BUTTON_RELEASE_EVENT,
458 PROPERTY_NOTIFY_EVENT,
459 SELECTION_CLEAR_EVENT,
460 SELECTION_REQUEST_EVENT,
461 SELECTION_NOTIFY_EVENT,
466 VISIBILITY_NOTIFY_EVENT,
480 ACCEL_CLOSURES_CHANGED,
504 PROP_RECEIVES_DEFAULT,
505 PROP_COMPOSITE_CHILD,
513 PROP_DOUBLE_BUFFERED,
528 typedef struct _GtkStateData GtkStateData;
531 STATE_CHANGE_REPLACE,
538 guint flags : GTK_STATE_FLAGS_BITS;
542 /* --- prototypes --- */
543 static void gtk_widget_base_class_init (gpointer g_class);
544 static void gtk_widget_class_init (GtkWidgetClass *klass);
545 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
546 static void gtk_widget_init (GtkWidget *widget);
547 static void gtk_widget_set_property (GObject *object,
551 static void gtk_widget_get_property (GObject *object,
555 static void gtk_widget_dispose (GObject *object);
556 static void gtk_widget_real_destroy (GtkWidget *object);
557 static void gtk_widget_finalize (GObject *object);
558 static void gtk_widget_real_show (GtkWidget *widget);
559 static void gtk_widget_real_hide (GtkWidget *widget);
560 static void gtk_widget_real_map (GtkWidget *widget);
561 static void gtk_widget_real_unmap (GtkWidget *widget);
562 static void gtk_widget_real_realize (GtkWidget *widget);
563 static void gtk_widget_real_unrealize (GtkWidget *widget);
564 static void gtk_widget_real_size_allocate (GtkWidget *widget,
565 GtkAllocation *allocation);
566 static void gtk_widget_real_style_set (GtkWidget *widget,
567 GtkStyle *previous_style);
568 static void gtk_widget_real_direction_changed(GtkWidget *widget,
569 GtkTextDirection previous_direction);
571 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
572 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
575 gboolean keyboard_tip,
576 GtkTooltip *tooltip);
577 static void gtk_widget_real_style_updated (GtkWidget *widget);
578 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
579 GtkWidgetHelpType help_type);
581 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
583 GParamSpec **pspecs);
584 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
586 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
588 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
589 GdkEventFocus *event);
590 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
591 GdkEventFocus *event);
592 static gboolean gtk_widget_real_focus (GtkWidget *widget,
593 GtkDirectionType direction);
594 static void gtk_widget_real_move_focus (GtkWidget *widget,
595 GtkDirectionType direction);
596 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
597 GtkDirectionType direction);
598 #ifdef G_ENABLE_DEBUG
599 static void gtk_widget_verify_invariants (GtkWidget *widget);
600 static void gtk_widget_push_verify_invariants (GtkWidget *widget);
601 static void gtk_widget_pop_verify_invariants (GtkWidget *widget);
603 #define gtk_widget_verify_invariants(widget)
604 #define gtk_widget_push_verify_invariants(widget)
605 #define gtk_widget_pop_verify_invariants(widget)
607 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
608 static void gtk_widget_update_pango_context (GtkWidget *widget);
609 static void gtk_widget_propagate_state (GtkWidget *widget,
612 static gint gtk_widget_event_internal (GtkWidget *widget,
614 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
615 gboolean group_cycling);
616 static void gtk_widget_real_get_width (GtkWidget *widget,
619 static void gtk_widget_real_get_height (GtkWidget *widget,
622 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
624 gint *minimum_height,
625 gint *natural_height);
626 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
629 gint *natural_width);
630 static void gtk_widget_real_state_flags_changed (GtkWidget *widget,
631 GtkStateFlags old_state);
632 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
633 static GtkWidgetAuxInfo* gtk_widget_get_aux_info (GtkWidget *widget,
635 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
636 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
637 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
638 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
639 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
640 cairo_region_t *region);
641 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
642 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
643 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
646 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
647 gboolean has_tooltip,
649 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
650 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
652 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
653 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
655 const gchar *childname);
656 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
659 const GValue *value);
660 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
663 const gchar *tagname,
664 GMarkupParser *parser,
666 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
669 const gchar *tagname,
671 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
672 GtkBuilder *builder);
674 static GtkSizeRequestMode gtk_widget_real_get_request_mode (GtkWidget *widget);
675 static void gtk_widget_real_get_width (GtkWidget *widget,
678 static void gtk_widget_real_get_height (GtkWidget *widget,
682 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
685 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
686 GtkOrientation orientation,
689 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
690 GtkOrientation orientation,
694 gint *allocated_size);
696 static void gtk_widget_set_usize_internal (GtkWidget *widget,
699 GtkQueueResizeFlags flags);
701 static void gtk_widget_add_events_internal (GtkWidget *widget,
704 static void gtk_widget_set_device_enabled_internal (GtkWidget *widget,
709 /* --- variables --- */
710 static gpointer gtk_widget_parent_class = NULL;
711 static guint widget_signals[LAST_SIGNAL] = { 0 };
712 static guint composite_child_stack = 0;
713 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
714 static GParamSpecPool *style_property_spec_pool = NULL;
716 static GQuark quark_property_parser = 0;
717 static GQuark quark_aux_info = 0;
718 static GQuark quark_accel_path = 0;
719 static GQuark quark_accel_closures = 0;
720 static GQuark quark_event_mask = 0;
721 static GQuark quark_device_event_mask = 0;
722 static GQuark quark_parent_window = 0;
723 static GQuark quark_pointer_window = 0;
724 static GQuark quark_shape_info = 0;
725 static GQuark quark_input_shape_info = 0;
726 static GQuark quark_pango_context = 0;
727 static GQuark quark_accessible_object = 0;
728 static GQuark quark_mnemonic_labels = 0;
729 static GQuark quark_tooltip_markup = 0;
730 static GQuark quark_has_tooltip = 0;
731 static GQuark quark_tooltip_window = 0;
732 static GQuark quark_visual = 0;
733 static GQuark quark_modifier_style = 0;
734 static GQuark quark_enabled_devices = 0;
735 static GQuark quark_size_groups = 0;
736 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
737 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
739 /* --- functions --- */
741 gtk_widget_get_type (void)
743 static GType widget_type = 0;
745 if (G_UNLIKELY (widget_type == 0))
747 const GTypeInfo widget_info =
749 sizeof (GtkWidgetClass),
750 gtk_widget_base_class_init,
751 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
752 (GClassInitFunc) gtk_widget_class_init,
753 NULL, /* class_finalize */
754 NULL, /* class_init */
757 (GInstanceInitFunc) gtk_widget_init,
758 NULL, /* value_table */
761 const GInterfaceInfo accessibility_info =
763 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
764 (GInterfaceFinalizeFunc) NULL,
765 NULL /* interface data */
768 const GInterfaceInfo buildable_info =
770 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
771 (GInterfaceFinalizeFunc) NULL,
772 NULL /* interface data */
775 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
776 &widget_info, G_TYPE_FLAG_ABSTRACT);
778 g_type_add_class_private (widget_type, sizeof (GtkWidgetClassPrivate));
780 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
781 &accessibility_info) ;
782 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
790 gtk_widget_base_class_init (gpointer g_class)
792 GtkWidgetClass *klass = g_class;
794 klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
798 child_property_notify_dispatcher (GObject *object,
802 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
805 /* We guard against the draw signal callbacks modifying the state of the
806 * cairo context by surounding it with save/restore.
807 * Maybe we should also cairo_new_path() just to be sure?
810 gtk_widget_draw_marshaller (GClosure *closure,
811 GValue *return_value,
812 guint n_param_values,
813 const GValue *param_values,
814 gpointer invocation_hint,
815 gpointer marshal_data)
817 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
821 _gtk_marshal_BOOLEAN__BOXED (closure,
832 gtk_widget_class_init (GtkWidgetClass *klass)
834 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
835 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
836 GtkBindingSet *binding_set;
838 gtk_widget_parent_class = g_type_class_peek_parent (klass);
840 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
841 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
842 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
843 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
844 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
845 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
846 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
847 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
848 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
849 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
850 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
851 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
852 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
853 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
854 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
855 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
856 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
857 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
858 quark_enabled_devices = g_quark_from_static_string ("gtk-widget-enabled-devices");
859 quark_size_groups = g_quark_from_static_string ("gtk-widget-size-groups");
861 style_property_spec_pool = g_param_spec_pool_new (FALSE);
862 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
863 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
864 cpn_context.dispatcher = child_property_notify_dispatcher;
865 _gtk_widget_child_property_notify_context = &cpn_context;
867 gobject_class->dispose = gtk_widget_dispose;
868 gobject_class->finalize = gtk_widget_finalize;
869 gobject_class->set_property = gtk_widget_set_property;
870 gobject_class->get_property = gtk_widget_get_property;
872 klass->destroy = gtk_widget_real_destroy;
874 klass->activate_signal = 0;
875 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
876 klass->show = gtk_widget_real_show;
877 klass->show_all = gtk_widget_show;
878 klass->hide = gtk_widget_real_hide;
879 klass->map = gtk_widget_real_map;
880 klass->unmap = gtk_widget_real_unmap;
881 klass->realize = gtk_widget_real_realize;
882 klass->unrealize = gtk_widget_real_unrealize;
883 klass->size_allocate = gtk_widget_real_size_allocate;
884 klass->get_request_mode = gtk_widget_real_get_request_mode;
885 klass->get_preferred_width = gtk_widget_real_get_width;
886 klass->get_preferred_height = gtk_widget_real_get_height;
887 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
888 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
889 klass->state_changed = NULL;
890 klass->state_flags_changed = gtk_widget_real_state_flags_changed;
891 klass->parent_set = NULL;
892 klass->hierarchy_changed = NULL;
893 klass->style_set = gtk_widget_real_style_set;
894 klass->direction_changed = gtk_widget_real_direction_changed;
895 klass->grab_notify = NULL;
896 klass->child_notify = NULL;
898 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
899 klass->grab_focus = gtk_widget_real_grab_focus;
900 klass->focus = gtk_widget_real_focus;
901 klass->move_focus = gtk_widget_real_move_focus;
902 klass->keynav_failed = gtk_widget_real_keynav_failed;
904 klass->button_press_event = NULL;
905 klass->button_release_event = NULL;
906 klass->motion_notify_event = NULL;
907 klass->delete_event = NULL;
908 klass->destroy_event = NULL;
909 klass->key_press_event = gtk_widget_real_key_press_event;
910 klass->key_release_event = gtk_widget_real_key_release_event;
911 klass->enter_notify_event = NULL;
912 klass->leave_notify_event = NULL;
913 klass->configure_event = NULL;
914 klass->focus_in_event = gtk_widget_real_focus_in_event;
915 klass->focus_out_event = gtk_widget_real_focus_out_event;
916 klass->map_event = NULL;
917 klass->unmap_event = NULL;
918 klass->window_state_event = NULL;
919 klass->property_notify_event = _gtk_selection_property_notify;
920 klass->selection_clear_event = _gtk_selection_clear;
921 klass->selection_request_event = _gtk_selection_request;
922 klass->selection_notify_event = _gtk_selection_notify;
923 klass->selection_received = NULL;
924 klass->proximity_in_event = NULL;
925 klass->proximity_out_event = NULL;
926 klass->drag_begin = NULL;
927 klass->drag_end = NULL;
928 klass->drag_data_delete = NULL;
929 klass->drag_leave = NULL;
930 klass->drag_motion = NULL;
931 klass->drag_drop = NULL;
932 klass->drag_data_received = NULL;
933 klass->screen_changed = NULL;
934 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
935 klass->grab_broken_event = NULL;
936 klass->query_tooltip = gtk_widget_real_query_tooltip;
937 klass->style_updated = gtk_widget_real_style_updated;
939 klass->show_help = gtk_widget_real_show_help;
941 /* Accessibility support */
942 klass->priv->accessible_type = GTK_TYPE_ACCESSIBLE;
943 klass->priv->accessible_role = ATK_ROLE_INVALID;
944 klass->get_accessible = gtk_widget_real_get_accessible;
946 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
947 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
949 g_object_class_install_property (gobject_class,
951 g_param_spec_string ("name",
953 P_("The name of the widget"),
955 GTK_PARAM_READWRITE));
956 g_object_class_install_property (gobject_class,
958 g_param_spec_object ("parent",
960 P_("The parent widget of this widget. Must be a Container widget"),
962 GTK_PARAM_READWRITE));
964 g_object_class_install_property (gobject_class,
966 g_param_spec_int ("width-request",
968 P_("Override for width request of the widget, or -1 if natural request should be used"),
972 GTK_PARAM_READWRITE));
973 g_object_class_install_property (gobject_class,
975 g_param_spec_int ("height-request",
976 P_("Height request"),
977 P_("Override for height request of the widget, or -1 if natural request should be used"),
981 GTK_PARAM_READWRITE));
982 g_object_class_install_property (gobject_class,
984 g_param_spec_boolean ("visible",
986 P_("Whether the widget is visible"),
988 GTK_PARAM_READWRITE));
989 g_object_class_install_property (gobject_class,
991 g_param_spec_boolean ("sensitive",
993 P_("Whether the widget responds to input"),
995 GTK_PARAM_READWRITE));
996 g_object_class_install_property (gobject_class,
998 g_param_spec_boolean ("app-paintable",
999 P_("Application paintable"),
1000 P_("Whether the application will paint directly on the widget"),
1002 GTK_PARAM_READWRITE));
1003 g_object_class_install_property (gobject_class,
1005 g_param_spec_boolean ("can-focus",
1007 P_("Whether the widget can accept the input focus"),
1009 GTK_PARAM_READWRITE));
1010 g_object_class_install_property (gobject_class,
1012 g_param_spec_boolean ("has-focus",
1014 P_("Whether the widget has the input focus"),
1016 GTK_PARAM_READWRITE));
1017 g_object_class_install_property (gobject_class,
1019 g_param_spec_boolean ("is-focus",
1021 P_("Whether the widget is the focus widget within the toplevel"),
1023 GTK_PARAM_READWRITE));
1024 g_object_class_install_property (gobject_class,
1026 g_param_spec_boolean ("can-default",
1028 P_("Whether the widget can be the default widget"),
1030 GTK_PARAM_READWRITE));
1031 g_object_class_install_property (gobject_class,
1033 g_param_spec_boolean ("has-default",
1035 P_("Whether the widget is the default widget"),
1037 GTK_PARAM_READWRITE));
1038 g_object_class_install_property (gobject_class,
1039 PROP_RECEIVES_DEFAULT,
1040 g_param_spec_boolean ("receives-default",
1041 P_("Receives default"),
1042 P_("If TRUE, the widget will receive the default action when it is focused"),
1044 GTK_PARAM_READWRITE));
1045 g_object_class_install_property (gobject_class,
1046 PROP_COMPOSITE_CHILD,
1047 g_param_spec_boolean ("composite-child",
1048 P_("Composite child"),
1049 P_("Whether the widget is part of a composite widget"),
1051 GTK_PARAM_READABLE));
1052 g_object_class_install_property (gobject_class,
1054 g_param_spec_object ("style",
1056 P_("The style of the widget, which contains information about how it will look (colors etc)"),
1058 GTK_PARAM_READWRITE));
1059 g_object_class_install_property (gobject_class,
1061 g_param_spec_flags ("events",
1063 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1064 GDK_TYPE_EVENT_MASK,
1066 GTK_PARAM_READWRITE));
1067 g_object_class_install_property (gobject_class,
1069 g_param_spec_boolean ("no-show-all",
1071 P_("Whether gtk_widget_show_all() should not affect this widget"),
1073 GTK_PARAM_READWRITE));
1076 * GtkWidget:has-tooltip:
1078 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1079 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1080 * the widget will be queried using #GtkWidget::query-tooltip to determine
1081 * whether it will provide a tooltip or not.
1083 * Note that setting this property to %TRUE for the first time will change
1084 * the event masks of the GdkWindows of this widget to include leave-notify
1085 * and motion-notify events. This cannot and will not be undone when the
1086 * property is set to %FALSE again.
1090 g_object_class_install_property (gobject_class,
1092 g_param_spec_boolean ("has-tooltip",
1094 P_("Whether this widget has a tooltip"),
1096 GTK_PARAM_READWRITE));
1098 * GtkWidget:tooltip-text:
1100 * Sets the text of tooltip to be the given string.
1102 * Also see gtk_tooltip_set_text().
1104 * This is a convenience property which will take care of getting the
1105 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1106 * will automatically be set to %TRUE and there will be taken care of
1107 * #GtkWidget::query-tooltip in the default signal handler.
1111 g_object_class_install_property (gobject_class,
1113 g_param_spec_string ("tooltip-text",
1115 P_("The contents of the tooltip for this widget"),
1117 GTK_PARAM_READWRITE));
1119 * GtkWidget:tooltip-markup:
1121 * Sets the text of tooltip to be the given string, which is marked up
1122 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1123 * Also see gtk_tooltip_set_markup().
1125 * This is a convenience property which will take care of getting the
1126 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1127 * will automatically be set to %TRUE and there will be taken care of
1128 * #GtkWidget::query-tooltip in the default signal handler.
1132 g_object_class_install_property (gobject_class,
1133 PROP_TOOLTIP_MARKUP,
1134 g_param_spec_string ("tooltip-markup",
1135 P_("Tooltip markup"),
1136 P_("The contents of the tooltip for this widget"),
1138 GTK_PARAM_READWRITE));
1143 * The widget's window if it is realized, %NULL otherwise.
1147 g_object_class_install_property (gobject_class,
1149 g_param_spec_object ("window",
1151 P_("The widget's window if it is realized"),
1153 GTK_PARAM_READABLE));
1156 * GtkWidget:double-buffered
1158 * Whether the widget is double buffered.
1162 g_object_class_install_property (gobject_class,
1163 PROP_DOUBLE_BUFFERED,
1164 g_param_spec_boolean ("double-buffered",
1165 P_("Double Buffered"),
1166 P_("Whether the widget is double buffered"),
1168 GTK_PARAM_READWRITE));
1173 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1177 g_object_class_install_property (gobject_class,
1179 g_param_spec_enum ("halign",
1180 P_("Horizontal Alignment"),
1181 P_("How to position in extra horizontal space"),
1184 GTK_PARAM_READWRITE));
1189 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1193 g_object_class_install_property (gobject_class,
1195 g_param_spec_enum ("valign",
1196 P_("Vertical Alignment"),
1197 P_("How to position in extra vertical space"),
1200 GTK_PARAM_READWRITE));
1203 * GtkWidget:margin-left
1205 * Margin on left side of widget.
1207 * This property adds margin outside of the widget's normal size
1208 * request, the margin will be added in addition to the size from
1209 * gtk_widget_set_size_request() for example.
1213 g_object_class_install_property (gobject_class,
1215 g_param_spec_int ("margin-left",
1216 P_("Margin on Left"),
1217 P_("Pixels of extra space on the left side"),
1221 GTK_PARAM_READWRITE));
1224 * GtkWidget:margin-right
1226 * Margin on right side of widget.
1228 * This property adds margin outside of the widget's normal size
1229 * request, the margin will be added in addition to the size from
1230 * gtk_widget_set_size_request() for example.
1234 g_object_class_install_property (gobject_class,
1236 g_param_spec_int ("margin-right",
1237 P_("Margin on Right"),
1238 P_("Pixels of extra space on the right side"),
1242 GTK_PARAM_READWRITE));
1245 * GtkWidget:margin-top
1247 * Margin on top side of widget.
1249 * This property adds margin outside of the widget's normal size
1250 * request, the margin will be added in addition to the size from
1251 * gtk_widget_set_size_request() for example.
1255 g_object_class_install_property (gobject_class,
1257 g_param_spec_int ("margin-top",
1258 P_("Margin on Top"),
1259 P_("Pixels of extra space on the top side"),
1263 GTK_PARAM_READWRITE));
1266 * GtkWidget:margin-bottom
1268 * Margin on bottom side of widget.
1270 * This property adds margin outside of the widget's normal size
1271 * request, the margin will be added in addition to the size from
1272 * gtk_widget_set_size_request() for example.
1276 g_object_class_install_property (gobject_class,
1278 g_param_spec_int ("margin-bottom",
1279 P_("Margin on Bottom"),
1280 P_("Pixels of extra space on the bottom side"),
1284 GTK_PARAM_READWRITE));
1289 * Sets all four sides' margin at once. If read, returns max
1290 * margin on any side.
1294 g_object_class_install_property (gobject_class,
1296 g_param_spec_int ("margin",
1298 P_("Pixels of extra space on all four sides"),
1302 GTK_PARAM_READWRITE));
1305 * GtkWidget::destroy:
1306 * @object: the object which received the signal
1308 * Signals that all holders of a reference to the widget should release
1309 * the reference that they hold. May result in finalization of the widget
1310 * if all references are released.
1312 widget_signals[DESTROY] =
1313 g_signal_new (I_("destroy"),
1314 G_TYPE_FROM_CLASS (gobject_class),
1315 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1316 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1318 _gtk_marshal_VOID__VOID,
1324 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1328 g_object_class_install_property (gobject_class,
1330 g_param_spec_boolean ("hexpand",
1331 P_("Horizontal Expand"),
1332 P_("Whether widget wants more horizontal space"),
1334 GTK_PARAM_READWRITE));
1337 * GtkWidget:hexpand-set
1339 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1343 g_object_class_install_property (gobject_class,
1345 g_param_spec_boolean ("hexpand-set",
1346 P_("Horizontal Expand Set"),
1347 P_("Whether to use the hexpand property"),
1349 GTK_PARAM_READWRITE));
1354 * Whether to expand vertically. See gtk_widget_set_vexpand().
1358 g_object_class_install_property (gobject_class,
1360 g_param_spec_boolean ("vexpand",
1361 P_("Vertical Expand"),
1362 P_("Whether widget wants more vertical space"),
1364 GTK_PARAM_READWRITE));
1367 * GtkWidget:vexpand-set
1369 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1373 g_object_class_install_property (gobject_class,
1375 g_param_spec_boolean ("vexpand-set",
1376 P_("Vertical Expand Set"),
1377 P_("Whether to use the vexpand property"),
1379 GTK_PARAM_READWRITE));
1384 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1388 g_object_class_install_property (gobject_class,
1390 g_param_spec_boolean ("expand",
1392 P_("Whether widget wants to expand in both directions"),
1394 GTK_PARAM_READWRITE));
1398 * @widget: the object which received the signal.
1400 widget_signals[SHOW] =
1401 g_signal_new (I_("show"),
1402 G_TYPE_FROM_CLASS (gobject_class),
1404 G_STRUCT_OFFSET (GtkWidgetClass, show),
1406 _gtk_marshal_VOID__VOID,
1411 * @widget: the object which received the signal.
1413 widget_signals[HIDE] =
1414 g_signal_new (I_("hide"),
1415 G_TYPE_FROM_CLASS (gobject_class),
1417 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1419 _gtk_marshal_VOID__VOID,
1424 * @widget: the object which received the signal.
1426 widget_signals[MAP] =
1427 g_signal_new (I_("map"),
1428 G_TYPE_FROM_CLASS (gobject_class),
1430 G_STRUCT_OFFSET (GtkWidgetClass, map),
1432 _gtk_marshal_VOID__VOID,
1437 * @widget: the object which received the signal.
1439 widget_signals[UNMAP] =
1440 g_signal_new (I_("unmap"),
1441 G_TYPE_FROM_CLASS (gobject_class),
1443 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1445 _gtk_marshal_VOID__VOID,
1449 * GtkWidget::realize:
1450 * @widget: the object which received the signal.
1452 widget_signals[REALIZE] =
1453 g_signal_new (I_("realize"),
1454 G_TYPE_FROM_CLASS (gobject_class),
1456 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1458 _gtk_marshal_VOID__VOID,
1462 * GtkWidget::unrealize:
1463 * @widget: the object which received the signal.
1465 widget_signals[UNREALIZE] =
1466 g_signal_new (I_("unrealize"),
1467 G_TYPE_FROM_CLASS (gobject_class),
1469 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1471 _gtk_marshal_VOID__VOID,
1475 * GtkWidget::size-allocate:
1476 * @widget: the object which received the signal.
1479 widget_signals[SIZE_ALLOCATE] =
1480 g_signal_new (I_("size-allocate"),
1481 G_TYPE_FROM_CLASS (gobject_class),
1483 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1485 _gtk_marshal_VOID__BOXED,
1487 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1490 * GtkWidget::state-changed:
1491 * @widget: the object which received the signal.
1492 * @state: the previous state
1494 * The ::state-changed signal is emitted when the widget state changes.
1495 * See gtk_widget_get_state().
1497 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1499 widget_signals[STATE_CHANGED] =
1500 g_signal_new (I_("state-changed"),
1501 G_TYPE_FROM_CLASS (gobject_class),
1503 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1505 _gtk_marshal_VOID__ENUM,
1507 GTK_TYPE_STATE_TYPE);
1510 * GtkWidget::state-flags-changed:
1511 * @widget: the object which received the signal.
1512 * @flags: The previous state flags.
1514 * The ::state-flags-changed signal is emitted when the widget state
1515 * changes, see gtk_widget_get_state_flags().
1519 widget_signals[STATE_FLAGS_CHANGED] =
1520 g_signal_new (I_("state-flags-changed"),
1521 G_TYPE_FROM_CLASS (gobject_class),
1523 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1525 _gtk_marshal_VOID__FLAGS,
1527 GTK_TYPE_STATE_FLAGS);
1530 * GtkWidget::parent-set:
1531 * @widget: the object on which the signal is emitted
1532 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1533 * just got its initial parent.
1535 * The ::parent-set signal is emitted when a new parent
1536 * has been set on a widget.
1538 widget_signals[PARENT_SET] =
1539 g_signal_new (I_("parent-set"),
1540 G_TYPE_FROM_CLASS (gobject_class),
1542 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1544 _gtk_marshal_VOID__OBJECT,
1549 * GtkWidget::hierarchy-changed:
1550 * @widget: the object on which the signal is emitted
1551 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1552 * if the widget was previously unanchored
1554 * The ::hierarchy-changed signal is emitted when the
1555 * anchored state of a widget changes. A widget is
1556 * <firstterm>anchored</firstterm> when its toplevel
1557 * ancestor is a #GtkWindow. This signal is emitted when
1558 * a widget changes from un-anchored to anchored or vice-versa.
1560 widget_signals[HIERARCHY_CHANGED] =
1561 g_signal_new (I_("hierarchy-changed"),
1562 G_TYPE_FROM_CLASS (gobject_class),
1564 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1566 _gtk_marshal_VOID__OBJECT,
1571 * GtkWidget::style-set:
1572 * @widget: the object on which the signal is emitted
1573 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1574 * just got its initial style
1576 * The ::style-set signal is emitted when a new style has been set
1577 * on a widget. Note that style-modifying functions like
1578 * gtk_widget_modify_base() also cause this signal to be emitted.
1580 * Note that this signal is emitted for changes to the deprecated
1581 * #GtkStyle. To track changes to the #GtkStyleContext associated
1582 * with a widget, use the #GtkWidget::style-updated signal.
1584 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1586 widget_signals[STYLE_SET] =
1587 g_signal_new (I_("style-set"),
1588 G_TYPE_FROM_CLASS (gobject_class),
1590 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1592 _gtk_marshal_VOID__OBJECT,
1597 * GtkWidget::style-updated:
1598 * @widget: the object on which the signal is emitted
1600 * The ::style-updated signal is emitted when the #GtkStyleContext
1601 * of a widget is changed. Note that style-modifying functions like
1602 * gtk_widget_override_color() also cause this signal to be emitted.
1606 widget_signals[STYLE_UPDATED] =
1607 g_signal_new (I_("style-updated"),
1608 G_TYPE_FROM_CLASS (gobject_class),
1610 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1612 g_cclosure_marshal_VOID__VOID,
1616 * GtkWidget::direction-changed:
1617 * @widget: the object on which the signal is emitted
1618 * @previous_direction: the previous text direction of @widget
1620 * The ::direction-changed signal is emitted when the text direction
1621 * of a widget changes.
1623 widget_signals[DIRECTION_CHANGED] =
1624 g_signal_new (I_("direction-changed"),
1625 G_TYPE_FROM_CLASS (gobject_class),
1627 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1629 _gtk_marshal_VOID__ENUM,
1631 GTK_TYPE_TEXT_DIRECTION);
1634 * GtkWidget::grab-notify:
1635 * @widget: the object which received the signal
1636 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1637 * if it becomes unshadowed
1639 * The ::grab-notify signal is emitted when a widget becomes
1640 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1641 * another widget, or when it becomes unshadowed due to a grab
1644 * A widget is shadowed by a gtk_grab_add() when the topmost
1645 * grab widget in the grab stack of its window group is not
1648 widget_signals[GRAB_NOTIFY] =
1649 g_signal_new (I_("grab-notify"),
1650 G_TYPE_FROM_CLASS (gobject_class),
1652 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1654 _gtk_marshal_VOID__BOOLEAN,
1659 * GtkWidget::child-notify:
1660 * @widget: the object which received the signal
1661 * @pspec: the #GParamSpec of the changed child property
1663 * The ::child-notify signal is emitted for each
1664 * <link linkend="child-properties">child property</link> that has
1665 * changed on an object. The signal's detail holds the property name.
1667 widget_signals[CHILD_NOTIFY] =
1668 g_signal_new (I_("child-notify"),
1669 G_TYPE_FROM_CLASS (gobject_class),
1670 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1671 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1673 g_cclosure_marshal_VOID__PARAM,
1679 * @widget: the object which received the signal
1680 * @cr: the cairo context to draw to
1682 * This signal is emitted when a widget is supposed to render itself.
1683 * The @widget's top left corner must be painted at the origin of
1684 * the passed in context and be sized to the values returned by
1685 * gtk_widget_get_allocated_width() and
1686 * gtk_widget_get_allocated_height().
1688 * Signal handlers connected to this signal can modify the cairo
1689 * context passed as @cr in any way they like and don't need to
1690 * restore it. The signal emission takes care of calling cairo_save()
1691 * before and cairo_restore() after invoking the handler.
1695 widget_signals[DRAW] =
1696 g_signal_new (I_("draw"),
1697 G_TYPE_FROM_CLASS (gobject_class),
1699 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1700 _gtk_boolean_handled_accumulator, NULL,
1701 gtk_widget_draw_marshaller,
1703 CAIRO_GOBJECT_TYPE_CONTEXT);
1706 * GtkWidget::mnemonic-activate:
1707 * @widget: the object which received the signal.
1710 widget_signals[MNEMONIC_ACTIVATE] =
1711 g_signal_new (I_("mnemonic-activate"),
1712 G_TYPE_FROM_CLASS (gobject_class),
1714 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1715 _gtk_boolean_handled_accumulator, NULL,
1716 _gtk_marshal_BOOLEAN__BOOLEAN,
1721 * GtkWidget::grab-focus:
1722 * @widget: the object which received the signal.
1724 widget_signals[GRAB_FOCUS] =
1725 g_signal_new (I_("grab-focus"),
1726 G_TYPE_FROM_CLASS (gobject_class),
1727 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1728 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1730 _gtk_marshal_VOID__VOID,
1735 * @widget: the object which received the signal.
1738 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1740 widget_signals[FOCUS] =
1741 g_signal_new (I_("focus"),
1742 G_TYPE_FROM_CLASS (klass),
1744 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1745 _gtk_boolean_handled_accumulator, NULL,
1746 _gtk_marshal_BOOLEAN__ENUM,
1748 GTK_TYPE_DIRECTION_TYPE);
1751 * GtkWidget::move-focus:
1752 * @widget: the object which received the signal.
1755 widget_signals[MOVE_FOCUS] =
1756 g_signal_new (I_("move-focus"),
1757 G_TYPE_FROM_CLASS (klass),
1758 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1759 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1761 _gtk_marshal_VOID__ENUM,
1764 GTK_TYPE_DIRECTION_TYPE);
1767 * GtkWidget::keynav-failed:
1768 * @widget: the object which received the signal
1769 * @direction: the direction of movement
1771 * Gets emitted if keyboard navigation fails.
1772 * See gtk_widget_keynav_failed() for details.
1774 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1775 * if the emitting widget should try to handle the keyboard
1776 * navigation attempt in its parent container(s).
1780 widget_signals[KEYNAV_FAILED] =
1781 g_signal_new (I_("keynav-failed"),
1782 G_TYPE_FROM_CLASS (klass),
1784 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1785 _gtk_boolean_handled_accumulator, NULL,
1786 _gtk_marshal_BOOLEAN__ENUM,
1788 GTK_TYPE_DIRECTION_TYPE);
1792 * @widget: the object which received the signal.
1793 * @event: the #GdkEvent which triggered this signal
1795 * The GTK+ main loop will emit three signals for each GDK event delivered
1796 * to a widget: one generic ::event signal, another, more specific,
1797 * signal that matches the type of event delivered (e.g.
1798 * #GtkWidget::key-press-event) and finally a generic
1799 * #GtkWidget::event-after signal.
1801 * Returns: %TRUE to stop other handlers from being invoked for the event
1802 * and to cancel the emission of the second specific ::event signal.
1803 * %FALSE to propagate the event further and to allow the emission of
1804 * the second signal. The ::event-after signal is emitted regardless of
1807 widget_signals[EVENT] =
1808 g_signal_new (I_("event"),
1809 G_TYPE_FROM_CLASS (klass),
1811 G_STRUCT_OFFSET (GtkWidgetClass, event),
1812 _gtk_boolean_handled_accumulator, NULL,
1813 _gtk_marshal_BOOLEAN__BOXED,
1815 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1818 * GtkWidget::event-after:
1819 * @widget: the object which received the signal.
1820 * @event: the #GdkEvent which triggered this signal
1822 * After the emission of the #GtkWidget::event signal and (optionally)
1823 * the second more specific signal, ::event-after will be emitted
1824 * regardless of the previous two signals handlers return values.
1827 widget_signals[EVENT_AFTER] =
1828 g_signal_new (I_("event-after"),
1829 G_TYPE_FROM_CLASS (klass),
1833 _gtk_marshal_VOID__BOXED,
1835 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1838 * GtkWidget::button-press-event:
1839 * @widget: the object which received the signal.
1840 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1843 * The ::button-press-event signal will be emitted when a button
1844 * (typically from a mouse) is pressed.
1846 * To receive this signal, the #GdkWindow associated to the
1847 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1849 * This signal will be sent to the grab widget if there is one.
1851 * Returns: %TRUE to stop other handlers from being invoked for the event.
1852 * %FALSE to propagate the event further.
1854 widget_signals[BUTTON_PRESS_EVENT] =
1855 g_signal_new (I_("button-press-event"),
1856 G_TYPE_FROM_CLASS (klass),
1858 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1859 _gtk_boolean_handled_accumulator, NULL,
1860 _gtk_marshal_BOOLEAN__BOXED,
1862 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1865 * GtkWidget::button-release-event:
1866 * @widget: the object which received the signal.
1867 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1870 * The ::button-release-event signal will be emitted when a button
1871 * (typically from a mouse) is released.
1873 * To receive this signal, the #GdkWindow associated to the
1874 * widget needs to enable the #GDK_BUTTON_RELEASE_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[BUTTON_RELEASE_EVENT] =
1882 g_signal_new (I_("button-release-event"),
1883 G_TYPE_FROM_CLASS (klass),
1885 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1886 _gtk_boolean_handled_accumulator, NULL,
1887 _gtk_marshal_BOOLEAN__BOXED,
1889 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1892 * GtkWidget::scroll-event:
1893 * @widget: the object which received the signal.
1894 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1897 * The ::scroll-event signal is emitted when a button in the 4 to 7
1898 * range is pressed. Wheel mice are usually configured to generate
1899 * button press events for buttons 4 and 5 when the wheel is turned.
1901 * To receive this signal, the #GdkWindow associated to the widget needs
1902 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1904 * This signal will be sent to the grab widget if there is one.
1906 * Returns: %TRUE to stop other handlers from being invoked for the event.
1907 * %FALSE to propagate the event further.
1909 widget_signals[SCROLL_EVENT] =
1910 g_signal_new (I_("scroll-event"),
1911 G_TYPE_FROM_CLASS (klass),
1913 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1914 _gtk_boolean_handled_accumulator, NULL,
1915 _gtk_marshal_BOOLEAN__BOXED,
1917 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1920 * GtkWidget::motion-notify-event:
1921 * @widget: the object which received the signal.
1922 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1925 * The ::motion-notify-event signal is emitted when the pointer moves
1926 * over the widget's #GdkWindow.
1928 * To receive this signal, the #GdkWindow associated to the widget
1929 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1931 * This signal will be sent to the grab widget if there is one.
1933 * Returns: %TRUE to stop other handlers from being invoked for the event.
1934 * %FALSE to propagate the event further.
1936 widget_signals[MOTION_NOTIFY_EVENT] =
1937 g_signal_new (I_("motion-notify-event"),
1938 G_TYPE_FROM_CLASS (klass),
1940 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1941 _gtk_boolean_handled_accumulator, NULL,
1942 _gtk_marshal_BOOLEAN__BOXED,
1944 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1947 * GtkWidget::composited-changed:
1948 * @widget: the object on which the signal is emitted
1950 * The ::composited-changed signal is emitted when the composited
1951 * status of @widget<!-- -->s screen changes.
1952 * See gdk_screen_is_composited().
1954 widget_signals[COMPOSITED_CHANGED] =
1955 g_signal_new (I_("composited-changed"),
1956 G_TYPE_FROM_CLASS (klass),
1957 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1958 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1960 _gtk_marshal_VOID__VOID,
1964 * GtkWidget::delete-event:
1965 * @widget: the object which received the signal
1966 * @event: the event which triggered this signal
1968 * The ::delete-event signal is emitted if a user requests that
1969 * a toplevel window is closed. The default handler for this signal
1970 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1971 * this signal will cause the window to be hidden instead, so that
1972 * it can later be shown again without reconstructing it.
1974 * Returns: %TRUE to stop other handlers from being invoked for the event.
1975 * %FALSE to propagate the event further.
1977 widget_signals[DELETE_EVENT] =
1978 g_signal_new (I_("delete-event"),
1979 G_TYPE_FROM_CLASS (klass),
1981 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1982 _gtk_boolean_handled_accumulator, NULL,
1983 _gtk_marshal_BOOLEAN__BOXED,
1985 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1988 * GtkWidget::destroy-event:
1989 * @widget: the object which received the signal.
1990 * @event: the event which triggered this signal
1992 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1993 * You rarely get this signal, because most widgets disconnect themselves
1994 * from their window before they destroy it, so no widget owns the
1995 * window at destroy time.
1997 * To receive this signal, the #GdkWindow associated to the widget needs
1998 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1999 * automatically for all new windows.
2001 * Returns: %TRUE to stop other handlers from being invoked for the event.
2002 * %FALSE to propagate the event further.
2004 widget_signals[DESTROY_EVENT] =
2005 g_signal_new (I_("destroy-event"),
2006 G_TYPE_FROM_CLASS (klass),
2008 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
2009 _gtk_boolean_handled_accumulator, NULL,
2010 _gtk_marshal_BOOLEAN__BOXED,
2012 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2015 * GtkWidget::key-press-event:
2016 * @widget: the object which received the signal
2017 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2019 * The ::key-press-event signal is emitted when a key is pressed. The signal
2020 * emission will reoccur at the key-repeat rate when the key is kept pressed.
2022 * To receive this signal, the #GdkWindow associated to the widget needs
2023 * to enable the #GDK_KEY_PRESS_MASK mask.
2025 * This signal will be sent to the grab widget if there is one.
2027 * Returns: %TRUE to stop other handlers from being invoked for the event.
2028 * %FALSE to propagate the event further.
2030 widget_signals[KEY_PRESS_EVENT] =
2031 g_signal_new (I_("key-press-event"),
2032 G_TYPE_FROM_CLASS (klass),
2034 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
2035 _gtk_boolean_handled_accumulator, NULL,
2036 _gtk_marshal_BOOLEAN__BOXED,
2038 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2041 * GtkWidget::key-release-event:
2042 * @widget: the object which received the signal
2043 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2045 * The ::key-release-event signal is emitted when a key is released.
2047 * To receive this signal, the #GdkWindow associated to the widget needs
2048 * to enable the #GDK_KEY_RELEASE_MASK mask.
2050 * This signal will be sent to the grab widget if there is one.
2052 * Returns: %TRUE to stop other handlers from being invoked for the event.
2053 * %FALSE to propagate the event further.
2055 widget_signals[KEY_RELEASE_EVENT] =
2056 g_signal_new (I_("key-release-event"),
2057 G_TYPE_FROM_CLASS (klass),
2059 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2060 _gtk_boolean_handled_accumulator, NULL,
2061 _gtk_marshal_BOOLEAN__BOXED,
2063 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2066 * GtkWidget::enter-notify-event:
2067 * @widget: the object which received the signal
2068 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2071 * The ::enter-notify-event will be emitted when the pointer enters
2072 * the @widget's window.
2074 * To receive this signal, the #GdkWindow associated to the widget needs
2075 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2077 * This signal will be sent to the grab widget if there is one.
2079 * Returns: %TRUE to stop other handlers from being invoked for the event.
2080 * %FALSE to propagate the event further.
2082 widget_signals[ENTER_NOTIFY_EVENT] =
2083 g_signal_new (I_("enter-notify-event"),
2084 G_TYPE_FROM_CLASS (klass),
2086 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2087 _gtk_boolean_handled_accumulator, NULL,
2088 _gtk_marshal_BOOLEAN__BOXED,
2090 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2093 * GtkWidget::leave-notify-event:
2094 * @widget: the object which received the signal
2095 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2098 * The ::leave-notify-event will be emitted when the pointer leaves
2099 * the @widget's window.
2101 * To receive this signal, the #GdkWindow associated to the widget needs
2102 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2104 * This signal will be sent to the grab widget if there is one.
2106 * Returns: %TRUE to stop other handlers from being invoked for the event.
2107 * %FALSE to propagate the event further.
2109 widget_signals[LEAVE_NOTIFY_EVENT] =
2110 g_signal_new (I_("leave-notify-event"),
2111 G_TYPE_FROM_CLASS (klass),
2113 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2114 _gtk_boolean_handled_accumulator, NULL,
2115 _gtk_marshal_BOOLEAN__BOXED,
2117 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2120 * GtkWidget::configure-event:
2121 * @widget: the object which received the signal
2122 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2125 * The ::configure-event signal will be emitted when the size, position or
2126 * stacking of the @widget's window has changed.
2128 * To receive this signal, the #GdkWindow associated to the widget needs
2129 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2130 * automatically for all new windows.
2132 * Returns: %TRUE to stop other handlers from being invoked for the event.
2133 * %FALSE to propagate the event further.
2135 widget_signals[CONFIGURE_EVENT] =
2136 g_signal_new (I_("configure-event"),
2137 G_TYPE_FROM_CLASS (klass),
2139 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2140 _gtk_boolean_handled_accumulator, NULL,
2141 _gtk_marshal_BOOLEAN__BOXED,
2143 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2146 * GtkWidget::focus-in-event:
2147 * @widget: the object which received the signal
2148 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2151 * The ::focus-in-event signal will be emitted when the keyboard focus
2152 * enters the @widget's window.
2154 * To receive this signal, the #GdkWindow associated to the widget needs
2155 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2157 * Returns: %TRUE to stop other handlers from being invoked for the event.
2158 * %FALSE to propagate the event further.
2160 widget_signals[FOCUS_IN_EVENT] =
2161 g_signal_new (I_("focus-in-event"),
2162 G_TYPE_FROM_CLASS (klass),
2164 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2165 _gtk_boolean_handled_accumulator, NULL,
2166 _gtk_marshal_BOOLEAN__BOXED,
2168 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2171 * GtkWidget::focus-out-event:
2172 * @widget: the object which received the signal
2173 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2176 * The ::focus-out-event signal will be emitted when the keyboard focus
2177 * leaves the @widget's window.
2179 * To receive this signal, the #GdkWindow associated to the widget needs
2180 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2182 * Returns: %TRUE to stop other handlers from being invoked for the event.
2183 * %FALSE to propagate the event further.
2185 widget_signals[FOCUS_OUT_EVENT] =
2186 g_signal_new (I_("focus-out-event"),
2187 G_TYPE_FROM_CLASS (klass),
2189 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2190 _gtk_boolean_handled_accumulator, NULL,
2191 _gtk_marshal_BOOLEAN__BOXED,
2193 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2196 * GtkWidget::map-event:
2197 * @widget: the object which received the signal
2198 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2200 * The ::map-event signal will be emitted when the @widget's window is
2201 * mapped. A window is mapped when it becomes visible on the screen.
2203 * To receive this signal, the #GdkWindow associated to the widget needs
2204 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2205 * automatically for all new windows.
2207 * Returns: %TRUE to stop other handlers from being invoked for the event.
2208 * %FALSE to propagate the event further.
2210 widget_signals[MAP_EVENT] =
2211 g_signal_new (I_("map-event"),
2212 G_TYPE_FROM_CLASS (klass),
2214 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2215 _gtk_boolean_handled_accumulator, NULL,
2216 _gtk_marshal_BOOLEAN__BOXED,
2218 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2221 * GtkWidget::unmap-event:
2222 * @widget: the object which received the signal
2223 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2225 * The ::unmap-event signal will be emitted when the @widget's window is
2226 * unmapped. A window is unmapped when it becomes invisible on the screen.
2228 * To receive this signal, the #GdkWindow associated to the widget needs
2229 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2230 * automatically for all new windows.
2232 * Returns: %TRUE to stop other handlers from being invoked for the event.
2233 * %FALSE to propagate the event further.
2235 widget_signals[UNMAP_EVENT] =
2236 g_signal_new (I_("unmap-event"),
2237 G_TYPE_FROM_CLASS (klass),
2239 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2240 _gtk_boolean_handled_accumulator, NULL,
2241 _gtk_marshal_BOOLEAN__BOXED,
2243 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2246 * GtkWidget::property-notify-event:
2247 * @widget: the object which received the signal
2248 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2251 * The ::property-notify-event signal will be emitted when a property on
2252 * the @widget's window has been changed or deleted.
2254 * To receive this signal, the #GdkWindow associated to the widget needs
2255 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2257 * Returns: %TRUE to stop other handlers from being invoked for the event.
2258 * %FALSE to propagate the event further.
2260 widget_signals[PROPERTY_NOTIFY_EVENT] =
2261 g_signal_new (I_("property-notify-event"),
2262 G_TYPE_FROM_CLASS (klass),
2264 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2265 _gtk_boolean_handled_accumulator, NULL,
2266 _gtk_marshal_BOOLEAN__BOXED,
2268 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2271 * GtkWidget::selection-clear-event:
2272 * @widget: the object which received the signal
2273 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2276 * The ::selection-clear-event signal will be emitted when the
2277 * the @widget's window has lost ownership of a selection.
2279 * Returns: %TRUE to stop other handlers from being invoked for the event.
2280 * %FALSE to propagate the event further.
2282 widget_signals[SELECTION_CLEAR_EVENT] =
2283 g_signal_new (I_("selection-clear-event"),
2284 G_TYPE_FROM_CLASS (klass),
2286 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2287 _gtk_boolean_handled_accumulator, NULL,
2288 _gtk_marshal_BOOLEAN__BOXED,
2290 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2293 * GtkWidget::selection-request-event:
2294 * @widget: the object which received the signal
2295 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2298 * The ::selection-request-event signal will be emitted when
2299 * another client requests ownership of the selection owned by
2300 * the @widget's window.
2302 * Returns: %TRUE to stop other handlers from being invoked for the event.
2303 * %FALSE to propagate the event further.
2305 widget_signals[SELECTION_REQUEST_EVENT] =
2306 g_signal_new (I_("selection-request-event"),
2307 G_TYPE_FROM_CLASS (klass),
2309 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2310 _gtk_boolean_handled_accumulator, NULL,
2311 _gtk_marshal_BOOLEAN__BOXED,
2313 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2316 * GtkWidget::selection-notify-event:
2317 * @widget: the object which received the signal.
2318 * @event: (type Gdk.EventSelection):
2320 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2322 widget_signals[SELECTION_NOTIFY_EVENT] =
2323 g_signal_new (I_("selection-notify-event"),
2324 G_TYPE_FROM_CLASS (klass),
2326 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2327 _gtk_boolean_handled_accumulator, NULL,
2328 _gtk_marshal_BOOLEAN__BOXED,
2330 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2333 * GtkWidget::selection-received:
2334 * @widget: the object which received the signal.
2338 widget_signals[SELECTION_RECEIVED] =
2339 g_signal_new (I_("selection-received"),
2340 G_TYPE_FROM_CLASS (klass),
2342 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2344 _gtk_marshal_VOID__BOXED_UINT,
2346 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2350 * GtkWidget::selection-get:
2351 * @widget: the object which received the signal.
2356 widget_signals[SELECTION_GET] =
2357 g_signal_new (I_("selection-get"),
2358 G_TYPE_FROM_CLASS (klass),
2360 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2362 _gtk_marshal_VOID__BOXED_UINT_UINT,
2364 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2369 * GtkWidget::proximity-in-event:
2370 * @widget: the object which received the signal
2371 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2374 * To receive this signal the #GdkWindow associated to the widget needs
2375 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2377 * This signal will be sent to the grab widget if there is one.
2379 * Returns: %TRUE to stop other handlers from being invoked for the event.
2380 * %FALSE to propagate the event further.
2382 widget_signals[PROXIMITY_IN_EVENT] =
2383 g_signal_new (I_("proximity-in-event"),
2384 G_TYPE_FROM_CLASS (klass),
2386 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2387 _gtk_boolean_handled_accumulator, NULL,
2388 _gtk_marshal_BOOLEAN__BOXED,
2390 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2393 * GtkWidget::proximity-out-event:
2394 * @widget: the object which received the signal
2395 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2398 * To receive this signal the #GdkWindow associated to the widget needs
2399 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2401 * This signal will be sent to the grab widget if there is one.
2403 * Returns: %TRUE to stop other handlers from being invoked for the event.
2404 * %FALSE to propagate the event further.
2406 widget_signals[PROXIMITY_OUT_EVENT] =
2407 g_signal_new (I_("proximity-out-event"),
2408 G_TYPE_FROM_CLASS (klass),
2410 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2411 _gtk_boolean_handled_accumulator, NULL,
2412 _gtk_marshal_BOOLEAN__BOXED,
2414 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2417 * GtkWidget::drag-leave:
2418 * @widget: the object which received the signal.
2419 * @drag_context: the drag context
2420 * @time: the timestamp of the motion event
2422 * The ::drag-leave signal is emitted on the drop site when the cursor
2423 * leaves the widget. A typical reason to connect to this signal is to
2424 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2425 * with gtk_drag_unhighlight()
2427 widget_signals[DRAG_LEAVE] =
2428 g_signal_new (I_("drag-leave"),
2429 G_TYPE_FROM_CLASS (klass),
2431 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2433 _gtk_marshal_VOID__OBJECT_UINT,
2435 GDK_TYPE_DRAG_CONTEXT,
2439 * GtkWidget::drag-begin:
2440 * @widget: the object which received the signal
2441 * @drag_context: the drag context
2443 * The ::drag-begin signal is emitted on the drag source when a drag is
2444 * started. A typical reason to connect to this signal is to set up a
2445 * custom drag icon with gtk_drag_source_set_icon().
2447 * Note that some widgets set up a drag icon in the default handler of
2448 * this signal, so you may have to use g_signal_connect_after() to
2449 * override what the default handler did.
2451 widget_signals[DRAG_BEGIN] =
2452 g_signal_new (I_("drag-begin"),
2453 G_TYPE_FROM_CLASS (klass),
2455 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2457 _gtk_marshal_VOID__OBJECT,
2459 GDK_TYPE_DRAG_CONTEXT);
2462 * GtkWidget::drag-end:
2463 * @widget: the object which received the signal
2464 * @drag_context: the drag context
2466 * The ::drag-end signal is emitted on the drag source when a drag is
2467 * finished. A typical reason to connect to this signal is to undo
2468 * things done in #GtkWidget::drag-begin.
2470 widget_signals[DRAG_END] =
2471 g_signal_new (I_("drag-end"),
2472 G_TYPE_FROM_CLASS (klass),
2474 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2476 _gtk_marshal_VOID__OBJECT,
2478 GDK_TYPE_DRAG_CONTEXT);
2481 * GtkWidget::drag-data-delete:
2482 * @widget: the object which received the signal
2483 * @drag_context: the drag context
2485 * The ::drag-data-delete signal is emitted on the drag source when a drag
2486 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2487 * handler is responsible for deleting the data that has been dropped. What
2488 * "delete" means depends on the context of the drag operation.
2490 widget_signals[DRAG_DATA_DELETE] =
2491 g_signal_new (I_("drag-data-delete"),
2492 G_TYPE_FROM_CLASS (klass),
2494 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2496 _gtk_marshal_VOID__OBJECT,
2498 GDK_TYPE_DRAG_CONTEXT);
2501 * GtkWidget::drag-failed:
2502 * @widget: the object which received the signal
2503 * @drag_context: the drag context
2504 * @result: the result of the drag operation
2506 * The ::drag-failed signal is emitted on the drag source when a drag has
2507 * failed. The signal handler may hook custom code to handle a failed DND
2508 * operation based on the type of error, it returns %TRUE is the failure has
2509 * been already handled (not showing the default "drag operation failed"
2510 * animation), otherwise it returns %FALSE.
2512 * Return value: %TRUE if the failed drag operation has been already handled.
2516 widget_signals[DRAG_FAILED] =
2517 g_signal_new (I_("drag-failed"),
2518 G_TYPE_FROM_CLASS (klass),
2520 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2521 _gtk_boolean_handled_accumulator, NULL,
2522 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2524 GDK_TYPE_DRAG_CONTEXT,
2525 GTK_TYPE_DRAG_RESULT);
2528 * GtkWidget::drag-motion:
2529 * @widget: the object which received the signal
2530 * @drag_context: the drag context
2531 * @x: the x coordinate of the current cursor position
2532 * @y: the y coordinate of the current cursor position
2533 * @time: the timestamp of the motion event
2535 * The drag-motion signal is emitted on the drop site when the user
2536 * moves the cursor over the widget during a drag. The signal handler
2537 * must determine whether the cursor position is in a drop zone or not.
2538 * If it is not in a drop zone, it returns %FALSE and no further processing
2539 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2540 * handler is responsible for providing the necessary information for
2541 * displaying feedback to the user, by calling gdk_drag_status().
2543 * If the decision whether the drop will be accepted or rejected can't be
2544 * made based solely on the cursor position and the type of the data, the
2545 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2546 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2547 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2548 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2549 * when using the drag-motion signal that way.
2551 * Also note that there is no drag-enter signal. The drag receiver has to
2552 * keep track of whether he has received any drag-motion signals since the
2553 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2554 * an "enter" signal. Upon an "enter", the handler will typically highlight
2555 * the drop site with gtk_drag_highlight().
2558 * drag_motion (GtkWidget *widget,
2559 * GdkDragContext *context,
2566 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2568 * if (!private_data->drag_highlight)
2570 * private_data->drag_highlight = 1;
2571 * gtk_drag_highlight (widget);
2574 * target = gtk_drag_dest_find_target (widget, context, NULL);
2575 * if (target == GDK_NONE)
2576 * gdk_drag_status (context, 0, time);
2579 * private_data->pending_status = context->suggested_action;
2580 * gtk_drag_get_data (widget, context, target, time);
2587 * drag_data_received (GtkWidget *widget,
2588 * GdkDragContext *context,
2591 * GtkSelectionData *selection_data,
2595 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2597 * if (private_data->suggested_action)
2599 * private_data->suggested_action = 0;
2601 * /* We are getting this data due to a request in drag_motion,
2602 * * rather than due to a request in drag_drop, so we are just
2603 * * supposed to call gdk_drag_status (), not actually paste in
2606 * str = gtk_selection_data_get_text (selection_data);
2607 * if (!data_is_acceptable (str))
2608 * gdk_drag_status (context, 0, time);
2610 * gdk_drag_status (context, private_data->suggested_action, time);
2614 * /* accept the drop */
2619 * Returns: whether the cursor position is in a drop zone
2621 widget_signals[DRAG_MOTION] =
2622 g_signal_new (I_("drag-motion"),
2623 G_TYPE_FROM_CLASS (klass),
2625 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2626 _gtk_boolean_handled_accumulator, NULL,
2627 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2629 GDK_TYPE_DRAG_CONTEXT,
2635 * GtkWidget::drag-drop:
2636 * @widget: the object which received the signal
2637 * @drag_context: the drag context
2638 * @x: the x coordinate of the current cursor position
2639 * @y: the y coordinate of the current cursor position
2640 * @time: the timestamp of the motion event
2642 * The ::drag-drop signal is emitted on the drop site when the user drops
2643 * the data onto the widget. The signal handler must determine whether
2644 * the cursor position is in a drop zone or not. If it is not in a drop
2645 * zone, it returns %FALSE and no further processing is necessary.
2646 * Otherwise, the handler returns %TRUE. In this case, the handler must
2647 * ensure that gtk_drag_finish() is called to let the source know that
2648 * the drop is done. The call to gtk_drag_finish() can be done either
2649 * directly or in a #GtkWidget::drag-data-received handler which gets
2650 * triggered by calling gtk_drag_get_data() to receive the data for one
2651 * or more of the supported targets.
2653 * Returns: whether the cursor position is in a drop zone
2655 widget_signals[DRAG_DROP] =
2656 g_signal_new (I_("drag-drop"),
2657 G_TYPE_FROM_CLASS (klass),
2659 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2660 _gtk_boolean_handled_accumulator, NULL,
2661 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2663 GDK_TYPE_DRAG_CONTEXT,
2669 * GtkWidget::drag-data-get:
2670 * @widget: the object which received the signal
2671 * @drag_context: the drag context
2672 * @data: the #GtkSelectionData to be filled with the dragged data
2673 * @info: the info that has been registered with the target in the
2675 * @time: the timestamp at which the data was requested
2677 * The ::drag-data-get signal is emitted on the drag source when the drop
2678 * site requests the data which is dragged. It is the responsibility of
2679 * the signal handler to fill @data with the data in the format which
2680 * is indicated by @info. See gtk_selection_data_set() and
2681 * gtk_selection_data_set_text().
2683 widget_signals[DRAG_DATA_GET] =
2684 g_signal_new (I_("drag-data-get"),
2685 G_TYPE_FROM_CLASS (klass),
2687 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2689 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2691 GDK_TYPE_DRAG_CONTEXT,
2692 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2697 * GtkWidget::drag-data-received:
2698 * @widget: the object which received the signal
2699 * @drag_context: the drag context
2700 * @x: where the drop happened
2701 * @y: where the drop happened
2702 * @data: the received data
2703 * @info: the info that has been registered with the target in the
2705 * @time: the timestamp at which the data was received
2707 * The ::drag-data-received signal is emitted on the drop site when the
2708 * dragged data has been received. If the data was received in order to
2709 * determine whether the drop will be accepted, the handler is expected
2710 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2711 * If the data was received in response to a #GtkWidget::drag-drop signal
2712 * (and this is the last target to be received), the handler for this
2713 * signal is expected to process the received data and then call
2714 * gtk_drag_finish(), setting the @success parameter depending on whether
2715 * the data was processed successfully.
2717 * The handler may inspect and modify @drag_context->action before calling
2718 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2719 * following example:
2722 * drag_data_received (GtkWidget *widget,
2723 * GdkDragContext *drag_context,
2726 * GtkSelectionData *data,
2730 * if ((data->length >= 0) && (data->format == 8))
2732 * if (drag_context->action == GDK_ACTION_ASK)
2734 * GtkWidget *dialog;
2737 * dialog = gtk_message_dialog_new (NULL,
2738 * GTK_DIALOG_MODAL |
2739 * GTK_DIALOG_DESTROY_WITH_PARENT,
2741 * GTK_BUTTONS_YES_NO,
2742 * "Move the data ?\n");
2743 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2744 * gtk_widget_destroy (dialog);
2746 * if (response == GTK_RESPONSE_YES)
2747 * drag_context->action = GDK_ACTION_MOVE;
2749 * drag_context->action = GDK_ACTION_COPY;
2752 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2756 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2760 widget_signals[DRAG_DATA_RECEIVED] =
2761 g_signal_new (I_("drag-data-received"),
2762 G_TYPE_FROM_CLASS (klass),
2764 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2766 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2768 GDK_TYPE_DRAG_CONTEXT,
2771 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2776 * GtkWidget::visibility-notify-event:
2777 * @widget: the object which received the signal
2778 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2779 * triggered this signal.
2781 * The ::visibility-notify-event will be emitted when the @widget's window
2782 * is obscured or unobscured.
2784 * To receive this signal the #GdkWindow associated to the widget needs
2785 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2787 * Returns: %TRUE to stop other handlers from being invoked for the event.
2788 * %FALSE to propagate the event further.
2790 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2791 g_signal_new (I_("visibility-notify-event"),
2792 G_TYPE_FROM_CLASS (klass),
2794 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2795 _gtk_boolean_handled_accumulator, NULL,
2796 _gtk_marshal_BOOLEAN__BOXED,
2798 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2801 * GtkWidget::window-state-event:
2802 * @widget: the object which received the signal
2803 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2804 * triggered this signal.
2806 * The ::window-state-event will be emitted when the state of the
2807 * toplevel window associated to the @widget changes.
2809 * To receive this signal the #GdkWindow associated to the widget
2810 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2811 * this mask automatically for all new windows.
2813 * Returns: %TRUE to stop other handlers from being invoked for the
2814 * event. %FALSE to propagate the event further.
2816 widget_signals[WINDOW_STATE_EVENT] =
2817 g_signal_new (I_("window-state-event"),
2818 G_TYPE_FROM_CLASS (klass),
2820 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2821 _gtk_boolean_handled_accumulator, NULL,
2822 _gtk_marshal_BOOLEAN__BOXED,
2824 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2827 * GtkWidget::damage-event:
2828 * @widget: the object which received the signal
2829 * @event: (type Gdk.EventExpose): the #GdkEventExpose event
2831 * Emitted when a redirected window belonging to @widget gets drawn into.
2832 * The region/area members of the event shows what area of the redirected
2833 * drawable was drawn into.
2835 * Returns: %TRUE to stop other handlers from being invoked for the event.
2836 * %FALSE to propagate the event further.
2840 widget_signals[DAMAGE_EVENT] =
2841 g_signal_new (I_("damage-event"),
2842 G_TYPE_FROM_CLASS (klass),
2844 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2845 _gtk_boolean_handled_accumulator, NULL,
2846 _gtk_marshal_BOOLEAN__BOXED,
2848 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2851 * GtkWidget::grab-broken-event:
2852 * @widget: the object which received the signal
2853 * @event: (type Gdk.EventGrabBroken): the #GdkEventGrabBroken event
2855 * Emitted when a pointer or keyboard grab on a window belonging
2856 * to @widget gets broken.
2858 * On X11, this happens when the grab window becomes unviewable
2859 * (i.e. it or one of its ancestors is unmapped), or if the same
2860 * application grabs the pointer or keyboard again.
2862 * Returns: %TRUE to stop other handlers from being invoked for
2863 * the event. %FALSE to propagate the event further.
2867 widget_signals[GRAB_BROKEN_EVENT] =
2868 g_signal_new (I_("grab-broken-event"),
2869 G_TYPE_FROM_CLASS (klass),
2871 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2872 _gtk_boolean_handled_accumulator, NULL,
2873 _gtk_marshal_BOOLEAN__BOXED,
2875 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2878 * GtkWidget::query-tooltip:
2879 * @widget: the object which received the signal
2880 * @x: the x coordinate of the cursor position where the request has
2881 * been emitted, relative to @widget's left side
2882 * @y: the y coordinate of the cursor position where the request has
2883 * been emitted, relative to @widget's top
2884 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2885 * @tooltip: a #GtkTooltip
2887 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2888 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2889 * focus in keyboard mode.
2891 * Using the given coordinates, the signal handler should determine
2892 * whether a tooltip should be shown for @widget. If this is the case
2893 * %TRUE should be returned, %FALSE otherwise. Note that if
2894 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2895 * should not be used.
2897 * The signal handler is free to manipulate @tooltip with the therefore
2898 * destined function calls.
2900 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2904 widget_signals[QUERY_TOOLTIP] =
2905 g_signal_new (I_("query-tooltip"),
2906 G_TYPE_FROM_CLASS (klass),
2908 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2909 _gtk_boolean_handled_accumulator, NULL,
2910 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2918 * GtkWidget::popup-menu
2919 * @widget: the object which received the signal
2921 * This signal gets emitted whenever a widget should pop up a context
2922 * menu. This usually happens through the standard key binding mechanism;
2923 * by pressing a certain key while a widget is focused, the user can cause
2924 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2925 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2926 * for an example of how to use this signal.
2928 * Returns: %TRUE if a menu was activated
2930 widget_signals[POPUP_MENU] =
2931 g_signal_new (I_("popup-menu"),
2932 G_TYPE_FROM_CLASS (klass),
2933 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2934 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2935 _gtk_boolean_handled_accumulator, NULL,
2936 _gtk_marshal_BOOLEAN__VOID,
2940 * GtkWidget::show-help:
2941 * @widget: the object which received the signal.
2944 widget_signals[SHOW_HELP] =
2945 g_signal_new (I_("show-help"),
2946 G_TYPE_FROM_CLASS (klass),
2947 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2948 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2949 _gtk_boolean_handled_accumulator, NULL,
2950 _gtk_marshal_BOOLEAN__ENUM,
2952 GTK_TYPE_WIDGET_HELP_TYPE);
2955 * GtkWidget::accel-closures-changed:
2956 * @widget: the object which received the signal.
2958 widget_signals[ACCEL_CLOSURES_CHANGED] =
2959 g_signal_new (I_("accel-closures-changed"),
2960 G_TYPE_FROM_CLASS (klass),
2964 _gtk_marshal_VOID__VOID,
2968 * GtkWidget::screen-changed:
2969 * @widget: the object on which the signal is emitted
2970 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2971 * widget was not associated with a screen before
2973 * The ::screen-changed signal gets emitted when the
2974 * screen of a widget has changed.
2976 widget_signals[SCREEN_CHANGED] =
2977 g_signal_new (I_("screen-changed"),
2978 G_TYPE_FROM_CLASS (klass),
2980 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2982 _gtk_marshal_VOID__OBJECT,
2987 * GtkWidget::can-activate-accel:
2988 * @widget: the object which received the signal
2989 * @signal_id: the ID of a signal installed on @widget
2991 * Determines whether an accelerator that activates the signal
2992 * identified by @signal_id can currently be activated.
2993 * This signal is present to allow applications and derived
2994 * widgets to override the default #GtkWidget handling
2995 * for determining whether an accelerator can be activated.
2997 * Returns: %TRUE if the signal can be activated.
2999 widget_signals[CAN_ACTIVATE_ACCEL] =
3000 g_signal_new (I_("can-activate-accel"),
3001 G_TYPE_FROM_CLASS (klass),
3003 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
3004 _gtk_boolean_handled_accumulator, NULL,
3005 _gtk_marshal_BOOLEAN__UINT,
3006 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
3008 binding_set = gtk_binding_set_by_class (klass);
3009 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
3011 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
3014 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
3016 GTK_TYPE_WIDGET_HELP_TYPE,
3017 GTK_WIDGET_HELP_TOOLTIP);
3018 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
3020 GTK_TYPE_WIDGET_HELP_TYPE,
3021 GTK_WIDGET_HELP_TOOLTIP);
3022 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
3024 GTK_TYPE_WIDGET_HELP_TYPE,
3025 GTK_WIDGET_HELP_WHATS_THIS);
3026 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
3028 GTK_TYPE_WIDGET_HELP_TYPE,
3029 GTK_WIDGET_HELP_WHATS_THIS);
3031 gtk_widget_class_install_style_property (klass,
3032 g_param_spec_boolean ("interior-focus",
3033 P_("Interior Focus"),
3034 P_("Whether to draw the focus indicator inside widgets"),
3036 GTK_PARAM_READABLE));
3038 gtk_widget_class_install_style_property (klass,
3039 g_param_spec_int ("focus-line-width",
3040 P_("Focus linewidth"),
3041 P_("Width, in pixels, of the focus indicator line"),
3043 GTK_PARAM_READABLE));
3045 gtk_widget_class_install_style_property (klass,
3046 g_param_spec_string ("focus-line-pattern",
3047 P_("Focus line dash pattern"),
3048 P_("Dash pattern used to draw the focus indicator"),
3050 GTK_PARAM_READABLE));
3051 gtk_widget_class_install_style_property (klass,
3052 g_param_spec_int ("focus-padding",
3053 P_("Focus padding"),
3054 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3056 GTK_PARAM_READABLE));
3057 gtk_widget_class_install_style_property (klass,
3058 g_param_spec_boxed ("cursor-color",
3060 P_("Color with which to draw insertion cursor"),
3062 GTK_PARAM_READABLE));
3063 gtk_widget_class_install_style_property (klass,
3064 g_param_spec_boxed ("secondary-cursor-color",
3065 P_("Secondary cursor color"),
3066 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3068 GTK_PARAM_READABLE));
3069 gtk_widget_class_install_style_property (klass,
3070 g_param_spec_float ("cursor-aspect-ratio",
3071 P_("Cursor line aspect ratio"),
3072 P_("Aspect ratio with which to draw insertion cursor"),
3074 GTK_PARAM_READABLE));
3076 gtk_widget_class_install_style_property (klass,
3077 g_param_spec_boolean ("window-dragging",
3078 P_("Window dragging"),
3079 P_("Whether windows can be dragged by clicking on empty areas"),
3081 GTK_PARAM_READABLE));
3084 * GtkWidget:link-color:
3086 * The "link-color" style property defines the color of unvisited links.
3090 gtk_widget_class_install_style_property (klass,
3091 g_param_spec_boxed ("link-color",
3092 P_("Unvisited Link Color"),
3093 P_("Color of unvisited links"),
3095 GTK_PARAM_READABLE));
3098 * GtkWidget:visited-link-color:
3100 * The "visited-link-color" style property defines the color of visited links.
3104 gtk_widget_class_install_style_property (klass,
3105 g_param_spec_boxed ("visited-link-color",
3106 P_("Visited Link Color"),
3107 P_("Color of visited links"),
3109 GTK_PARAM_READABLE));
3112 * GtkWidget:wide-separators:
3114 * The "wide-separators" style property defines whether separators have
3115 * configurable width and should be drawn using a box instead of a line.
3119 gtk_widget_class_install_style_property (klass,
3120 g_param_spec_boolean ("wide-separators",
3121 P_("Wide Separators"),
3122 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3124 GTK_PARAM_READABLE));
3127 * GtkWidget:separator-width:
3129 * The "separator-width" style property defines the width of separators.
3130 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3134 gtk_widget_class_install_style_property (klass,
3135 g_param_spec_int ("separator-width",
3136 P_("Separator Width"),
3137 P_("The width of separators if wide-separators is TRUE"),
3139 GTK_PARAM_READABLE));
3142 * GtkWidget:separator-height:
3144 * The "separator-height" style property defines the height of separators.
3145 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3149 gtk_widget_class_install_style_property (klass,
3150 g_param_spec_int ("separator-height",
3151 P_("Separator Height"),
3152 P_("The height of separators if \"wide-separators\" is TRUE"),
3154 GTK_PARAM_READABLE));
3157 * GtkWidget:scroll-arrow-hlength:
3159 * The "scroll-arrow-hlength" style property defines the length of
3160 * horizontal scroll arrows.
3164 gtk_widget_class_install_style_property (klass,
3165 g_param_spec_int ("scroll-arrow-hlength",
3166 P_("Horizontal Scroll Arrow Length"),
3167 P_("The length of horizontal scroll arrows"),
3169 GTK_PARAM_READABLE));
3172 * GtkWidget:scroll-arrow-vlength:
3174 * The "scroll-arrow-vlength" style property defines the length of
3175 * vertical scroll arrows.
3179 gtk_widget_class_install_style_property (klass,
3180 g_param_spec_int ("scroll-arrow-vlength",
3181 P_("Vertical Scroll Arrow Length"),
3182 P_("The length of vertical scroll arrows"),
3184 GTK_PARAM_READABLE));
3186 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3188 gtk_widget_class_set_accessible_type (klass, GTK_TYPE_WIDGET_ACCESSIBLE);
3192 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3196 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3197 for (node = list; node; node = node->next)
3199 GParamSpec *pspec = node->data;
3201 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3202 g_param_spec_unref (pspec);
3208 gtk_widget_set_property (GObject *object,
3210 const GValue *value,
3213 GtkWidget *widget = GTK_WIDGET (object);
3218 gchar *tooltip_markup;
3219 const gchar *tooltip_text;
3220 GtkWindow *tooltip_window;
3223 gtk_widget_set_name (widget, g_value_get_string (value));
3226 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3228 case PROP_WIDTH_REQUEST:
3229 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3231 case PROP_HEIGHT_REQUEST:
3232 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3235 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3237 case PROP_SENSITIVE:
3238 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3240 case PROP_APP_PAINTABLE:
3241 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3243 case PROP_CAN_FOCUS:
3244 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3246 case PROP_HAS_FOCUS:
3247 if (g_value_get_boolean (value))
3248 gtk_widget_grab_focus (widget);
3251 if (g_value_get_boolean (value))
3252 gtk_widget_grab_focus (widget);
3254 case PROP_CAN_DEFAULT:
3255 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3257 case PROP_HAS_DEFAULT:
3258 if (g_value_get_boolean (value))
3259 gtk_widget_grab_default (widget);
3261 case PROP_RECEIVES_DEFAULT:
3262 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3265 gtk_widget_set_style (widget, g_value_get_object (value));
3268 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3269 gtk_widget_set_events (widget, g_value_get_flags (value));
3271 case PROP_NO_SHOW_ALL:
3272 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3274 case PROP_HAS_TOOLTIP:
3275 gtk_widget_real_set_has_tooltip (widget,
3276 g_value_get_boolean (value), FALSE);
3278 case PROP_TOOLTIP_MARKUP:
3279 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3280 tooltip_markup = g_value_dup_string (value);
3282 /* Treat an empty string as a NULL string,
3283 * because an empty string would be useless for a tooltip:
3285 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3287 g_free (tooltip_markup);
3288 tooltip_markup = NULL;
3291 g_object_set_qdata_full (object, quark_tooltip_markup,
3292 tooltip_markup, g_free);
3294 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3295 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3296 if (gtk_widget_get_visible (widget))
3297 gtk_widget_queue_tooltip_query (widget);
3299 case PROP_TOOLTIP_TEXT:
3300 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3302 tooltip_text = g_value_get_string (value);
3304 /* Treat an empty string as a NULL string,
3305 * because an empty string would be useless for a tooltip:
3307 if (tooltip_text && (strlen (tooltip_text) == 0))
3308 tooltip_text = NULL;
3310 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3312 g_object_set_qdata_full (object, quark_tooltip_markup,
3313 tooltip_markup, g_free);
3315 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3316 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3317 if (gtk_widget_get_visible (widget))
3318 gtk_widget_queue_tooltip_query (widget);
3320 case PROP_DOUBLE_BUFFERED:
3321 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3324 gtk_widget_set_halign (widget, g_value_get_enum (value));
3327 gtk_widget_set_valign (widget, g_value_get_enum (value));
3329 case PROP_MARGIN_LEFT:
3330 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3332 case PROP_MARGIN_RIGHT:
3333 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3335 case PROP_MARGIN_TOP:
3336 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3338 case PROP_MARGIN_BOTTOM:
3339 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3342 g_object_freeze_notify (G_OBJECT (widget));
3343 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3344 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3345 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3346 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3347 g_object_thaw_notify (G_OBJECT (widget));
3350 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3352 case PROP_HEXPAND_SET:
3353 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3356 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3358 case PROP_VEXPAND_SET:
3359 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3362 g_object_freeze_notify (G_OBJECT (widget));
3363 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3364 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3365 g_object_thaw_notify (G_OBJECT (widget));
3368 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3374 gtk_widget_get_property (GObject *object,
3379 GtkWidget *widget = GTK_WIDGET (object);
3380 GtkWidgetPrivate *priv = widget->priv;
3388 g_value_set_string (value, priv->name);
3390 g_value_set_static_string (value, "");
3393 g_value_set_object (value, priv->parent);
3395 case PROP_WIDTH_REQUEST:
3398 gtk_widget_get_size_request (widget, &w, NULL);
3399 g_value_set_int (value, w);
3402 case PROP_HEIGHT_REQUEST:
3405 gtk_widget_get_size_request (widget, NULL, &h);
3406 g_value_set_int (value, h);
3410 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3412 case PROP_SENSITIVE:
3413 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3415 case PROP_APP_PAINTABLE:
3416 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3418 case PROP_CAN_FOCUS:
3419 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3421 case PROP_HAS_FOCUS:
3422 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3425 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3427 case PROP_CAN_DEFAULT:
3428 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3430 case PROP_HAS_DEFAULT:
3431 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3433 case PROP_RECEIVES_DEFAULT:
3434 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3436 case PROP_COMPOSITE_CHILD:
3437 g_value_set_boolean (value, widget->priv->composite_child);
3440 g_value_set_object (value, gtk_widget_get_style (widget));
3443 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3444 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3446 case PROP_NO_SHOW_ALL:
3447 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3449 case PROP_HAS_TOOLTIP:
3450 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3452 case PROP_TOOLTIP_TEXT:
3454 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3457 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3458 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3460 g_value_take_string (value, text);
3463 case PROP_TOOLTIP_MARKUP:
3464 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3467 g_value_set_object (value, gtk_widget_get_window (widget));
3469 case PROP_DOUBLE_BUFFERED:
3470 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3473 g_value_set_enum (value, gtk_widget_get_halign (widget));
3476 g_value_set_enum (value, gtk_widget_get_valign (widget));
3478 case PROP_MARGIN_LEFT:
3479 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3481 case PROP_MARGIN_RIGHT:
3482 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3484 case PROP_MARGIN_TOP:
3485 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3487 case PROP_MARGIN_BOTTOM:
3488 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3492 GtkWidgetAuxInfo *aux_info = gtk_widget_get_aux_info (widget, FALSE);
3493 if (aux_info == NULL)
3495 g_value_set_int (value, 0);
3499 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3500 aux_info->margin.right),
3501 MAX (aux_info->margin.top,
3502 aux_info->margin.bottom)));
3507 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3509 case PROP_HEXPAND_SET:
3510 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3513 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3515 case PROP_VEXPAND_SET:
3516 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3519 g_value_set_boolean (value,
3520 gtk_widget_get_hexpand (widget) &&
3521 gtk_widget_get_vexpand (widget));
3524 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3530 gtk_widget_init (GtkWidget *widget)
3532 GtkWidgetPrivate *priv;
3534 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3537 priv = widget->priv;
3539 priv->child_visible = TRUE;
3541 priv->allocation.x = -1;
3542 priv->allocation.y = -1;
3543 priv->allocation.width = 1;
3544 priv->allocation.height = 1;
3545 priv->window = NULL;
3546 priv->parent = NULL;
3548 priv->sensitive = TRUE;
3549 priv->composite_child = composite_child_stack != 0;
3550 priv->double_buffered = TRUE;
3551 priv->redraw_on_alloc = TRUE;
3552 priv->width_request_needed = TRUE;
3553 priv->height_request_needed = TRUE;
3554 priv->alloc_needed = TRUE;
3556 /* this will be set to TRUE if the widget gets a child or if the
3557 * expand flag is set on the widget, but until one of those happen
3558 * we know the expand is already properly FALSE.
3560 * We really want to default FALSE here to avoid computing expand
3561 * all over the place while initially building a widget tree.
3563 priv->need_compute_expand = FALSE;
3565 priv->style = gtk_widget_get_default_style ();
3566 g_object_ref (priv->style);
3571 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3573 GParamSpec **pspecs)
3575 GtkWidgetPrivate *priv = widget->priv;
3576 GtkWidget *container = priv->parent;
3579 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3580 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3584 * gtk_widget_freeze_child_notify:
3585 * @widget: a #GtkWidget
3587 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3588 * signals are queued until gtk_widget_thaw_child_notify() is called
3591 * This is the analogue of g_object_freeze_notify() for child properties.
3594 gtk_widget_freeze_child_notify (GtkWidget *widget)
3596 g_return_if_fail (GTK_IS_WIDGET (widget));
3598 if (!G_OBJECT (widget)->ref_count)
3601 g_object_ref (widget);
3602 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3603 g_object_unref (widget);
3607 * gtk_widget_child_notify:
3608 * @widget: a #GtkWidget
3609 * @child_property: the name of a child property installed on the
3610 * class of @widget<!-- -->'s parent
3612 * Emits a #GtkWidget::child-notify signal for the
3613 * <link linkend="child-properties">child property</link> @child_property
3616 * This is the analogue of g_object_notify() for child properties.
3618 * Also see gtk_container_child_notify().
3621 gtk_widget_child_notify (GtkWidget *widget,
3622 const gchar *child_property)
3624 if (widget->priv->parent == NULL)
3627 gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
3631 * gtk_widget_thaw_child_notify:
3632 * @widget: a #GtkWidget
3634 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3635 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3639 gtk_widget_thaw_child_notify (GtkWidget *widget)
3641 GObjectNotifyQueue *nqueue;
3643 g_return_if_fail (GTK_IS_WIDGET (widget));
3645 if (!G_OBJECT (widget)->ref_count)
3648 g_object_ref (widget);
3649 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3650 if (!nqueue || !nqueue->freeze_count)
3651 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3652 G_OBJECT_TYPE_NAME (widget), widget);
3654 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3655 g_object_unref (widget);
3661 * @type: type ID of the widget to create
3662 * @first_property_name: name of first property to set
3663 * @...: value of first property, followed by more properties,
3666 * This is a convenience function for creating a widget and setting
3667 * its properties in one go. For example you might write:
3668 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3669 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3670 * g_object_new(), but returns a widget so you don't have to
3671 * cast the object yourself.
3673 * Return value: a new #GtkWidget of type @widget_type
3676 gtk_widget_new (GType type,
3677 const gchar *first_property_name,
3683 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3685 va_start (var_args, first_property_name);
3686 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3693 gtk_widget_queue_draw_child (GtkWidget *widget)
3695 GtkWidgetPrivate *priv = widget->priv;
3698 parent = priv->parent;
3699 if (parent && gtk_widget_is_drawable (parent))
3700 gtk_widget_queue_draw_area (parent,
3703 priv->allocation.width,
3704 priv->allocation.height);
3708 * gtk_widget_unparent:
3709 * @widget: a #GtkWidget
3711 * This function is only for use in widget implementations.
3712 * Should be called by implementations of the remove method
3713 * on #GtkContainer, to dissociate a child from the container.
3716 gtk_widget_unparent (GtkWidget *widget)
3718 GtkWidgetPrivate *priv;
3719 GObjectNotifyQueue *nqueue;
3720 GtkWidget *toplevel;
3721 GtkWidget *old_parent;
3723 g_return_if_fail (GTK_IS_WIDGET (widget));
3725 priv = widget->priv;
3727 if (priv->parent == NULL)
3730 /* keep this function in sync with gtk_menu_detach() */
3732 gtk_widget_push_verify_invariants (widget);
3734 g_object_freeze_notify (G_OBJECT (widget));
3735 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3737 toplevel = gtk_widget_get_toplevel (widget);
3738 if (gtk_widget_is_toplevel (toplevel))
3739 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3741 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3742 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3744 gtk_widget_queue_draw_child (widget);
3746 /* Reset the width and height here, to force reallocation if we
3747 * get added back to a new parent. This won't work if our new
3748 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3749 * (would 0x0 be OK here?)
3751 priv->allocation.width = 1;
3752 priv->allocation.height = 1;
3754 if (gtk_widget_get_realized (widget))
3756 if (priv->in_reparent)
3757 gtk_widget_unmap (widget);
3759 gtk_widget_unrealize (widget);
3762 /* If we are unanchoring the child, we save around the toplevel
3763 * to emit hierarchy changed
3765 if (priv->parent->priv->anchored)
3766 g_object_ref (toplevel);
3770 /* Removing a widget from a container restores the child visible
3771 * flag to the default state, so it doesn't affect the child
3772 * in the next parent.
3774 priv->child_visible = TRUE;
3776 old_parent = priv->parent;
3777 priv->parent = NULL;
3779 /* parent may no longer expand if the removed
3780 * child was expand=TRUE and could therefore
3783 if (gtk_widget_get_visible (widget) &&
3784 (priv->need_compute_expand ||
3785 priv->computed_hexpand ||
3786 priv->computed_vexpand))
3788 gtk_widget_queue_compute_expand (old_parent);
3791 /* Unset BACKDROP since we are no longer inside a toplevel window */
3792 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_BACKDROP);
3794 gtk_style_context_set_parent (priv->context, NULL);
3796 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3799 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3800 g_object_unref (toplevel);
3803 /* Now that the parent pointer is nullified and the hierarchy-changed
3804 * already passed, go ahead and unset the parent window, if we are unparenting
3805 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
3806 * will fire again for the new subhierarchy.
3808 gtk_widget_set_parent_window (widget, NULL);
3810 g_object_notify (G_OBJECT (widget), "parent");
3811 g_object_thaw_notify (G_OBJECT (widget));
3813 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3814 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3816 gtk_widget_pop_verify_invariants (widget);
3817 g_object_unref (widget);
3821 * gtk_widget_destroy:
3822 * @widget: a #GtkWidget
3824 * Destroys a widget.
3827 * destroyed, it will break any references it holds to other objects.
3828 * If the widget is inside a container, the widget will be removed
3829 * from the container. If the widget is a toplevel (derived from
3830 * #GtkWindow), it will be removed from the list of toplevels, and the
3831 * reference GTK+ holds to it will be removed. Removing a
3832 * widget from its container or the list of toplevels results in the
3833 * widget being finalized, unless you've added additional references
3834 * to the widget with g_object_ref().
3836 * In most cases, only toplevel widgets (windows) require explicit
3837 * destruction, because when you destroy a toplevel its children will
3838 * be destroyed as well.
3841 gtk_widget_destroy (GtkWidget *widget)
3843 g_return_if_fail (GTK_IS_WIDGET (widget));
3845 if (!widget->priv->in_destruction)
3846 g_object_run_dispose (G_OBJECT (widget));
3850 * gtk_widget_destroyed:
3851 * @widget: a #GtkWidget
3852 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3854 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3855 * %NULL. It's intended to be used as a callback connected to the
3856 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3857 * as a signal handler, and pass the address of your widget variable
3858 * as user data. Then when the widget is destroyed, the variable will
3859 * be set to %NULL. Useful for example to avoid multiple copies
3860 * of the same dialog.
3863 gtk_widget_destroyed (GtkWidget *widget,
3864 GtkWidget **widget_pointer)
3866 /* Don't make any assumptions about the
3868 * Even check widget_pointer.
3871 *widget_pointer = NULL;
3876 * @widget: a #GtkWidget
3878 * Flags a widget to be displayed. Any widget that isn't shown will
3879 * not appear on the screen. If you want to show all the widgets in a
3880 * container, it's easier to call gtk_widget_show_all() on the
3881 * container, instead of individually showing the widgets.
3883 * Remember that you have to show the containers containing a widget,
3884 * in addition to the widget itself, before it will appear onscreen.
3886 * When a toplevel container is shown, it is immediately realized and
3887 * mapped; other shown widgets are realized and mapped when their
3888 * toplevel container is realized and mapped.
3891 gtk_widget_show (GtkWidget *widget)
3893 g_return_if_fail (GTK_IS_WIDGET (widget));
3895 if (!gtk_widget_get_visible (widget))
3897 g_object_ref (widget);
3898 gtk_widget_push_verify_invariants (widget);
3900 if (!gtk_widget_is_toplevel (widget))
3901 gtk_widget_queue_resize (widget);
3903 /* see comment in set_parent() for why this should and can be
3906 if (widget->priv->need_compute_expand ||
3907 widget->priv->computed_hexpand ||
3908 widget->priv->computed_vexpand)
3910 if (widget->priv->parent != NULL)
3911 gtk_widget_queue_compute_expand (widget->priv->parent);
3914 g_signal_emit (widget, widget_signals[SHOW], 0);
3915 g_object_notify (G_OBJECT (widget), "visible");
3917 gtk_widget_pop_verify_invariants (widget);
3918 g_object_unref (widget);
3923 gtk_widget_real_show (GtkWidget *widget)
3925 GtkWidgetPrivate *priv = widget->priv;
3927 if (!gtk_widget_get_visible (widget))
3929 priv->visible = TRUE;
3932 gtk_widget_get_mapped (priv->parent) &&
3933 gtk_widget_get_child_visible (widget) &&
3934 !gtk_widget_get_mapped (widget))
3935 gtk_widget_map (widget);
3940 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3943 g_signal_handlers_disconnect_by_func (widget,
3944 gtk_widget_show_map_callback,
3949 * gtk_widget_show_now:
3950 * @widget: a #GtkWidget
3952 * Shows a widget. If the widget is an unmapped toplevel widget
3953 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3954 * loop and wait for the window to actually be mapped. Be careful;
3955 * because the main loop is running, anything can happen during
3959 gtk_widget_show_now (GtkWidget *widget)
3963 g_return_if_fail (GTK_IS_WIDGET (widget));
3965 /* make sure we will get event */
3966 if (!gtk_widget_get_mapped (widget) &&
3967 gtk_widget_is_toplevel (widget))
3969 gtk_widget_show (widget);
3971 g_signal_connect (widget, "map-event",
3972 G_CALLBACK (gtk_widget_show_map_callback),
3976 gtk_main_iteration ();
3979 gtk_widget_show (widget);
3984 * @widget: a #GtkWidget
3986 * Reverses the effects of gtk_widget_show(), causing the widget to be
3987 * hidden (invisible to the user).
3990 gtk_widget_hide (GtkWidget *widget)
3992 g_return_if_fail (GTK_IS_WIDGET (widget));
3994 if (gtk_widget_get_visible (widget))
3996 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3998 g_object_ref (widget);
3999 gtk_widget_push_verify_invariants (widget);
4001 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
4002 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
4004 /* a parent may now be expand=FALSE since we're hidden. */
4005 if (widget->priv->need_compute_expand ||
4006 widget->priv->computed_hexpand ||
4007 widget->priv->computed_vexpand)
4009 gtk_widget_queue_compute_expand (widget);
4012 g_signal_emit (widget, widget_signals[HIDE], 0);
4013 if (!gtk_widget_is_toplevel (widget))
4014 gtk_widget_queue_resize (widget);
4015 g_object_notify (G_OBJECT (widget), "visible");
4017 gtk_widget_pop_verify_invariants (widget);
4018 g_object_unref (widget);
4023 gtk_widget_real_hide (GtkWidget *widget)
4025 if (gtk_widget_get_visible (widget))
4027 widget->priv->visible = FALSE;
4029 if (gtk_widget_get_mapped (widget))
4030 gtk_widget_unmap (widget);
4035 * gtk_widget_hide_on_delete:
4036 * @widget: a #GtkWidget
4038 * Utility function; intended to be connected to the #GtkWidget::delete-event
4039 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4040 * argument, then returns %TRUE. If connected to ::delete-event, the
4041 * result is that clicking the close button for a window (on the
4042 * window frame, top right corner usually) will hide but not destroy
4043 * the window. By default, GTK+ destroys windows when ::delete-event
4046 * Return value: %TRUE
4049 gtk_widget_hide_on_delete (GtkWidget *widget)
4051 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4053 gtk_widget_hide (widget);
4059 * gtk_widget_show_all:
4060 * @widget: a #GtkWidget
4062 * Recursively shows a widget, and any child widgets (if the widget is
4066 gtk_widget_show_all (GtkWidget *widget)
4068 GtkWidgetClass *class;
4070 g_return_if_fail (GTK_IS_WIDGET (widget));
4072 if (gtk_widget_get_no_show_all (widget))
4075 class = GTK_WIDGET_GET_CLASS (widget);
4077 if (class->show_all)
4078 class->show_all (widget);
4082 _gtk_widget_notify_state_change (GtkWidget *widget,
4090 case GTK_STATE_FLAG_ACTIVE:
4091 state = GTK_STATE_ACTIVE;
4093 case GTK_STATE_FLAG_PRELIGHT:
4094 state = GTK_STATE_PRELIGHT;
4096 case GTK_STATE_FLAG_SELECTED:
4097 state = GTK_STATE_SELECTED;
4099 case GTK_STATE_FLAG_INSENSITIVE:
4100 state = GTK_STATE_INSENSITIVE;
4102 case GTK_STATE_FLAG_INCONSISTENT:
4103 state = GTK_STATE_INCONSISTENT;
4105 case GTK_STATE_FLAG_FOCUSED:
4106 state = GTK_STATE_FOCUSED;
4112 gtk_style_context_notify_state_change (widget->priv->context,
4113 gtk_widget_get_window (widget),
4114 NULL, state, target);
4117 /* Initializes state transitions for those states that
4118 * were enabled before mapping and have a looping animation.
4121 _gtk_widget_start_state_transitions (GtkWidget *widget)
4123 GtkStateFlags state, flag;
4125 if (!widget->priv->context)
4128 state = gtk_widget_get_state_flags (widget);
4129 flag = GTK_STATE_FLAG_FOCUSED;
4133 GtkAnimationDescription *animation_desc;
4135 if ((state & flag) == 0)
4141 gtk_style_context_get (widget->priv->context, state,
4142 "transition", &animation_desc,
4147 if (_gtk_animation_description_get_loop (animation_desc))
4148 _gtk_widget_notify_state_change (widget, flag, TRUE);
4150 _gtk_animation_description_unref (animation_desc);
4159 * @widget: a #GtkWidget
4161 * This function is only for use in widget implementations. Causes
4162 * a widget to be mapped if it isn't already.
4165 gtk_widget_map (GtkWidget *widget)
4167 GtkWidgetPrivate *priv;
4169 g_return_if_fail (GTK_IS_WIDGET (widget));
4170 g_return_if_fail (gtk_widget_get_visible (widget));
4171 g_return_if_fail (gtk_widget_get_child_visible (widget));
4173 priv = widget->priv;
4175 if (!gtk_widget_get_mapped (widget))
4177 gtk_widget_push_verify_invariants (widget);
4179 if (!gtk_widget_get_realized (widget))
4180 gtk_widget_realize (widget);
4182 g_signal_emit (widget, widget_signals[MAP], 0);
4184 if (!gtk_widget_get_has_window (widget))
4185 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4187 gtk_widget_pop_verify_invariants (widget);
4189 _gtk_widget_start_state_transitions (widget);
4195 * @widget: a #GtkWidget
4197 * This function is only for use in widget implementations. Causes
4198 * a widget to be unmapped if it's currently mapped.
4201 gtk_widget_unmap (GtkWidget *widget)
4203 GtkWidgetPrivate *priv;
4205 g_return_if_fail (GTK_IS_WIDGET (widget));
4207 priv = widget->priv;
4209 if (gtk_widget_get_mapped (widget))
4211 gtk_widget_push_verify_invariants (widget);
4213 if (!gtk_widget_get_has_window (widget))
4214 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4215 _gtk_tooltip_hide (widget);
4216 g_signal_emit (widget, widget_signals[UNMAP], 0);
4218 gtk_widget_pop_verify_invariants (widget);
4221 gtk_style_context_cancel_animations (priv->context, NULL);
4223 /* Unset pointer/window info */
4224 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4229 _gtk_widget_enable_device_events (GtkWidget *widget)
4231 GHashTable *device_events;
4232 GHashTableIter iter;
4233 gpointer key, value;
4235 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4240 g_hash_table_iter_init (&iter, device_events);
4242 while (g_hash_table_iter_next (&iter, &key, &value))
4245 GdkEventMask event_mask;
4248 event_mask = GPOINTER_TO_UINT (value);
4249 gtk_widget_add_events_internal (widget, device, event_mask);
4254 get_widget_windows (GtkWidget *widget)
4256 GList *window_list, *last, *l, *children, *ret;
4258 if (gtk_widget_get_has_window (widget))
4259 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4261 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4263 last = g_list_last (window_list);
4266 for (l = window_list; l; l = l->next)
4268 GtkWidget *window_widget = NULL;
4270 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4272 if (widget != window_widget)
4275 ret = g_list_prepend (ret, l->data);
4276 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4280 last = g_list_concat (last, children);
4281 last = g_list_last (last);
4285 g_list_free (window_list);
4291 device_enable_foreach (GtkWidget *widget,
4294 GdkDevice *device = user_data;
4295 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4299 device_disable_foreach (GtkWidget *widget,
4302 GdkDevice *device = user_data;
4303 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4307 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4312 GList *window_list, *l;
4314 window_list = get_widget_windows (widget);
4316 for (l = window_list; l; l = l->next)
4318 GdkEventMask events = 0;
4324 events = gdk_window_get_events (window);
4326 gdk_window_set_device_events (window, device, events);
4329 if (recurse && GTK_IS_CONTAINER (widget))
4332 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4334 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4337 g_list_free (window_list);
4341 gtk_widget_update_devices_mask (GtkWidget *widget,
4344 GList *enabled_devices, *l;
4346 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4348 for (l = enabled_devices; l; l = l->next)
4349 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4353 * gtk_widget_realize:
4354 * @widget: a #GtkWidget
4356 * Creates the GDK (windowing system) resources associated with a
4357 * widget. For example, @widget->window will be created when a widget
4358 * is realized. Normally realization happens implicitly; if you show
4359 * a widget and all its parent containers, then the widget will be
4360 * realized and mapped automatically.
4362 * Realizing a widget requires all
4363 * the widget's parent widgets to be realized; calling
4364 * gtk_widget_realize() realizes the widget's parents in addition to
4365 * @widget itself. If a widget is not yet inside a toplevel window
4366 * when you realize it, bad things will happen.
4368 * This function is primarily used in widget implementations, and
4369 * isn't very useful otherwise. Many times when you think you might
4370 * need it, a better approach is to connect to a signal that will be
4371 * called after the widget is realized automatically, such as
4372 * #GtkWidget::draw. Or simply g_signal_connect () to the
4373 * #GtkWidget::realize signal.
4376 gtk_widget_realize (GtkWidget *widget)
4378 GtkWidgetPrivate *priv;
4379 cairo_region_t *region;
4381 g_return_if_fail (GTK_IS_WIDGET (widget));
4382 g_return_if_fail (widget->priv->anchored ||
4383 GTK_IS_INVISIBLE (widget));
4385 priv = widget->priv;
4387 if (!gtk_widget_get_realized (widget))
4389 gtk_widget_push_verify_invariants (widget);
4392 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4393 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4396 if (priv->parent == NULL &&
4397 !gtk_widget_is_toplevel (widget))
4398 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4399 "inside a toplevel window is not going to work very well. "
4400 "Widgets must be inside a toplevel container before realizing them.");
4402 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4403 gtk_widget_realize (priv->parent);
4405 gtk_widget_ensure_style (widget);
4407 if (priv->style_update_pending)
4408 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4410 g_signal_emit (widget, widget_signals[REALIZE], 0);
4412 gtk_widget_real_set_has_tooltip (widget,
4413 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4416 if (priv->has_shape_mask)
4418 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4419 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4422 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4424 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4426 if (priv->multidevice)
4427 gdk_window_set_support_multidevice (priv->window, TRUE);
4429 _gtk_widget_enable_device_events (widget);
4430 gtk_widget_update_devices_mask (widget, TRUE);
4432 gtk_widget_pop_verify_invariants (widget);
4437 * gtk_widget_unrealize:
4438 * @widget: a #GtkWidget
4440 * This function is only useful in widget implementations.
4441 * Causes a widget to be unrealized (frees all GDK resources
4442 * associated with the widget, such as @widget->window).
4445 gtk_widget_unrealize (GtkWidget *widget)
4447 g_return_if_fail (GTK_IS_WIDGET (widget));
4449 gtk_widget_push_verify_invariants (widget);
4451 if (widget->priv->has_shape_mask)
4452 gtk_widget_shape_combine_region (widget, NULL);
4454 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4455 gtk_widget_input_shape_combine_region (widget, NULL);
4457 if (gtk_widget_get_realized (widget))
4459 g_object_ref (widget);
4461 if (widget->priv->mapped)
4462 gtk_widget_unmap (widget);
4464 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4465 g_assert (!widget->priv->mapped);
4466 gtk_widget_set_realized (widget, FALSE);
4468 g_object_unref (widget);
4471 gtk_widget_pop_verify_invariants (widget);
4474 /*****************************************
4476 *****************************************/
4479 * gtk_widget_queue_draw_region:
4480 * @widget: a #GtkWidget
4481 * @region: region to draw
4483 * Invalidates the rectangular area of @widget defined by @region by
4484 * calling gdk_window_invalidate_region() on the widget's window and
4485 * all its child windows. Once the main loop becomes idle (after the
4486 * current batch of events has been processed, roughly), the window
4487 * will receive expose events for the union of all regions that have
4490 * Normally you would only use this function in widget
4491 * implementations. You might also use it to schedule a redraw of a
4492 * #GtkDrawingArea or some portion thereof.
4497 gtk_widget_queue_draw_region (GtkWidget *widget,
4498 const cairo_region_t *region)
4500 GtkWidgetPrivate *priv;
4503 g_return_if_fail (GTK_IS_WIDGET (widget));
4505 priv = widget->priv;
4507 if (!gtk_widget_get_realized (widget))
4510 /* Just return if the widget or one of its ancestors isn't mapped */
4511 for (w = widget; w != NULL; w = w->priv->parent)
4512 if (!gtk_widget_get_mapped (w))
4515 gdk_window_invalidate_region (priv->window, region, TRUE);
4519 * gtk_widget_queue_draw_area:
4520 * @widget: a #GtkWidget
4521 * @x: x coordinate of upper-left corner of rectangle to redraw
4522 * @y: y coordinate of upper-left corner of rectangle to redraw
4523 * @width: width of region to draw
4524 * @height: height of region to draw
4526 * Convenience function that calls gtk_widget_queue_draw_region() on
4527 * the region created from the given coordinates.
4529 * The region here is specified in widget coordinates.
4530 * Widget coordinates are a bit odd; for historical reasons, they are
4531 * defined as @widget->window coordinates for widgets that are not
4532 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4533 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4536 gtk_widget_queue_draw_area (GtkWidget *widget,
4543 cairo_region_t *region;
4545 g_return_if_fail (GTK_IS_WIDGET (widget));
4550 rect.height = height;
4552 region = cairo_region_create_rectangle (&rect);
4553 gtk_widget_queue_draw_region (widget, region);
4554 cairo_region_destroy (region);
4558 * gtk_widget_queue_draw:
4559 * @widget: a #GtkWidget
4561 * Equivalent to calling gtk_widget_queue_draw_area() for the
4562 * entire area of a widget.
4565 gtk_widget_queue_draw (GtkWidget *widget)
4569 g_return_if_fail (GTK_IS_WIDGET (widget));
4571 gtk_widget_get_allocation (widget, &rect);
4573 if (!gtk_widget_get_has_window (widget))
4574 gtk_widget_queue_draw_area (widget,
4575 rect.x, rect.y, rect.width, rect.height);
4577 gtk_widget_queue_draw_area (widget,
4578 0, 0, rect.width, rect.height);
4582 * gtk_widget_queue_resize:
4583 * @widget: a #GtkWidget
4585 * This function is only for use in widget implementations.
4586 * Flags a widget to have its size renegotiated; should
4587 * be called when a widget for some reason has a new size request.
4588 * For example, when you change the text in a #GtkLabel, #GtkLabel
4589 * queues a resize to ensure there's enough space for the new text.
4591 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4592 * from inside its implementation of the GtkWidgetClass::size_allocate
4593 * virtual method. Calls to gtk_widget_queue_resize() from inside
4594 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4597 gtk_widget_queue_resize (GtkWidget *widget)
4599 g_return_if_fail (GTK_IS_WIDGET (widget));
4601 if (gtk_widget_get_realized (widget))
4602 gtk_widget_queue_shallow_draw (widget);
4604 _gtk_size_group_queue_resize (widget, 0);
4608 * gtk_widget_queue_resize_no_redraw:
4609 * @widget: a #GtkWidget
4611 * This function works like gtk_widget_queue_resize(),
4612 * except that the widget is not invalidated.
4617 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4619 g_return_if_fail (GTK_IS_WIDGET (widget));
4621 _gtk_size_group_queue_resize (widget, 0);
4625 * gtk_widget_size_request:
4626 * @widget: a #GtkWidget
4627 * @requisition: (out): a #GtkRequisition to be filled in
4629 * This function is typically used when implementing a #GtkContainer
4630 * subclass. Obtains the preferred size of a widget. The container
4631 * uses this information to arrange its child widgets and decide what
4632 * size allocations to give them with gtk_widget_size_allocate().
4634 * You can also call this function from an application, with some
4635 * caveats. Most notably, getting a size request requires the widget
4636 * to be associated with a screen, because font information may be
4637 * needed. Multihead-aware applications should keep this in mind.
4639 * Also remember that the size request is not necessarily the size
4640 * a widget will actually be allocated.
4642 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4645 gtk_widget_size_request (GtkWidget *widget,
4646 GtkRequisition *requisition)
4648 g_return_if_fail (GTK_IS_WIDGET (widget));
4650 gtk_widget_get_preferred_size (widget, requisition, NULL);
4654 * gtk_widget_get_child_requisition:
4655 * @widget: a #GtkWidget
4656 * @requisition: (out): a #GtkRequisition to be filled in
4658 * This function is only for use in widget implementations. Obtains
4659 * @widget->requisition, unless someone has forced a particular
4660 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4661 * in which case it returns that geometry instead of the widget's
4664 * This function differs from gtk_widget_size_request() in that
4665 * it retrieves the last size request value from @widget->requisition,
4666 * while gtk_widget_size_request() actually calls the "size_request" method
4667 * on @widget to compute the size request and fill in @widget->requisition,
4668 * and only then returns @widget->requisition.
4670 * Because this function does not call the "size_request" method, it
4671 * can only be used when you know that @widget->requisition is
4672 * up-to-date, that is, gtk_widget_size_request() has been called
4673 * since the last time a resize was queued. In general, only container
4674 * implementations have this information; applications should use
4675 * gtk_widget_size_request().
4678 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4681 gtk_widget_get_child_requisition (GtkWidget *widget,
4682 GtkRequisition *requisition)
4684 gtk_widget_get_preferred_size (widget, requisition, NULL);
4688 invalidate_predicate (GdkWindow *window,
4693 gdk_window_get_user_data (window, &user_data);
4695 return (user_data == data);
4698 /* Invalidate @region in widget->window and all children
4699 * of widget->window owned by widget. @region is in the
4700 * same coordinates as widget->allocation and will be
4701 * modified by this call.
4704 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4705 cairo_region_t *region)
4707 GtkWidgetPrivate *priv = widget->priv;
4709 if (!gtk_widget_get_realized (widget))
4712 if (gtk_widget_get_has_window (widget) && priv->parent)
4716 gdk_window_get_position (priv->window, &x, &y);
4717 cairo_region_translate (region, -x, -y);
4720 gdk_window_invalidate_maybe_recurse (priv->window, region,
4721 invalidate_predicate, widget);
4725 * gtk_widget_queue_shallow_draw:
4726 * @widget: a #GtkWidget
4728 * Like gtk_widget_queue_draw(), but only windows owned
4729 * by @widget are invalidated.
4732 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4735 cairo_region_t *region;
4737 if (!gtk_widget_get_realized (widget))
4740 gtk_widget_get_allocation (widget, &rect);
4742 region = cairo_region_create_rectangle (&rect);
4743 gtk_widget_invalidate_widget_windows (widget, region);
4744 cairo_region_destroy (region);
4748 * gtk_widget_size_allocate:
4749 * @widget: a #GtkWidget
4750 * @allocation: position and size to be allocated to @widget
4752 * This function is only used by #GtkContainer subclasses, to assign a size
4753 * and position to their child widgets.
4755 * In this function, the allocation may be adjusted. It will be forced
4756 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4757 * method on the child will be used to adjust the allocation. Standard
4758 * adjustments include removing the widget's margins, and applying the
4759 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4762 gtk_widget_size_allocate (GtkWidget *widget,
4763 GtkAllocation *allocation)
4765 GtkWidgetPrivate *priv;
4766 GdkRectangle real_allocation;
4767 GdkRectangle old_allocation;
4768 GdkRectangle adjusted_allocation;
4769 gboolean alloc_needed;
4770 gboolean size_changed;
4771 gboolean position_changed;
4772 gint natural_width, natural_height, dummy;
4773 gint min_width, min_height;
4775 priv = widget->priv;
4777 g_return_if_fail (GTK_IS_WIDGET (widget));
4779 gtk_widget_push_verify_invariants (widget);
4781 #ifdef G_ENABLE_DEBUG
4782 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4793 parent = gtk_widget_get_parent (parent);
4796 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4797 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4798 2 * depth, " ", name,
4799 allocation->width, allocation->height);
4801 #endif /* G_ENABLE_DEBUG */
4803 alloc_needed = priv->alloc_needed;
4804 if (!priv->width_request_needed && !priv->height_request_needed)
4805 /* Preserve request/allocate ordering */
4806 priv->alloc_needed = FALSE;
4808 old_allocation = priv->allocation;
4809 real_allocation = *allocation;
4811 adjusted_allocation = real_allocation;
4812 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4814 /* Go ahead and request the height for allocated width, note that the internals
4815 * of get_height_for_width will internally limit the for_size to natural size
4816 * when aligning implicitly.
4818 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4819 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
4823 /* Go ahead and request the width for allocated height, note that the internals
4824 * of get_width_for_height will internally limit the for_size to natural size
4825 * when aligning implicitly.
4827 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4828 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
4831 #ifdef G_ENABLE_DEBUG
4832 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4834 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
4835 !GTK_IS_SCROLLABLE (widget))
4836 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
4837 "Allocation is %dx%d, but minimum required size is %dx%d.",
4838 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
4839 G_OBJECT_TYPE_NAME (widget), widget,
4840 real_allocation.width, real_allocation.height,
4841 min_width, min_height);
4844 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4845 * allocated sizes and possibly limit them to the natural sizes */
4846 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4847 GTK_ORIENTATION_HORIZONTAL,
4850 &adjusted_allocation.x,
4851 &adjusted_allocation.width);
4852 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4853 GTK_ORIENTATION_VERTICAL,
4856 &adjusted_allocation.y,
4857 &adjusted_allocation.height);
4859 if (adjusted_allocation.x < real_allocation.x ||
4860 adjusted_allocation.y < real_allocation.y ||
4861 (adjusted_allocation.x + adjusted_allocation.width) >
4862 (real_allocation.x + real_allocation.width) ||
4863 (adjusted_allocation.y + adjusted_allocation.height >
4864 real_allocation.y + real_allocation.height))
4866 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",
4867 G_OBJECT_TYPE_NAME (widget), widget,
4868 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4869 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4870 adjusted_allocation = real_allocation; /* veto it */
4874 real_allocation = adjusted_allocation;
4877 if (real_allocation.width < 0 || real_allocation.height < 0)
4879 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4880 real_allocation.width,
4881 real_allocation.height);
4884 real_allocation.width = MAX (real_allocation.width, 1);
4885 real_allocation.height = MAX (real_allocation.height, 1);
4887 size_changed = (old_allocation.width != real_allocation.width ||
4888 old_allocation.height != real_allocation.height);
4889 position_changed = (old_allocation.x != real_allocation.x ||
4890 old_allocation.y != real_allocation.y);
4892 if (!alloc_needed && !size_changed && !position_changed)
4895 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4897 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4898 priv->width_request_needed = FALSE;
4899 priv->height_request_needed = FALSE;
4900 priv->alloc_needed = FALSE;
4902 if (gtk_widget_get_mapped (widget))
4904 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4906 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4908 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4909 cairo_region_union_rectangle (invalidate, &old_allocation);
4911 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4912 cairo_region_destroy (invalidate);
4917 if (priv->redraw_on_alloc)
4919 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4921 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4922 cairo_region_union_rectangle (invalidate, &old_allocation);
4924 gtk_widget_invalidate_widget_windows (widget, invalidate);
4925 cairo_region_destroy (invalidate);
4929 if (size_changed || position_changed)
4931 GtkStyleContext *context;
4933 context = gtk_widget_get_style_context (widget);
4934 _gtk_style_context_invalidate_animation_areas (context);
4938 if ((size_changed || position_changed) && priv->parent &&
4939 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4941 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4942 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4943 cairo_region_destroy (invalidate);
4947 gtk_widget_pop_verify_invariants (widget);
4951 * gtk_widget_common_ancestor:
4952 * @widget_a: a #GtkWidget
4953 * @widget_b: a #GtkWidget
4955 * Find the common ancestor of @widget_a and @widget_b that
4956 * is closest to the two widgets.
4958 * Return value: the closest common ancestor of @widget_a and
4959 * @widget_b or %NULL if @widget_a and @widget_b do not
4960 * share a common ancestor.
4963 gtk_widget_common_ancestor (GtkWidget *widget_a,
4964 GtkWidget *widget_b)
4966 GtkWidget *parent_a;
4967 GtkWidget *parent_b;
4971 parent_a = widget_a;
4972 while (parent_a->priv->parent)
4974 parent_a = parent_a->priv->parent;
4978 parent_b = widget_b;
4979 while (parent_b->priv->parent)
4981 parent_b = parent_b->priv->parent;
4985 if (parent_a != parent_b)
4988 while (depth_a > depth_b)
4990 widget_a = widget_a->priv->parent;
4994 while (depth_b > depth_a)
4996 widget_b = widget_b->priv->parent;
5000 while (widget_a != widget_b)
5002 widget_a = widget_a->priv->parent;
5003 widget_b = widget_b->priv->parent;
5010 * gtk_widget_translate_coordinates:
5011 * @src_widget: a #GtkWidget
5012 * @dest_widget: a #GtkWidget
5013 * @src_x: X position relative to @src_widget
5014 * @src_y: Y position relative to @src_widget
5015 * @dest_x: (out): location to store X position relative to @dest_widget
5016 * @dest_y: (out): location to store Y position relative to @dest_widget
5018 * Translate coordinates relative to @src_widget's allocation to coordinates
5019 * relative to @dest_widget's allocations. In order to perform this
5020 * operation, both widgets must be realized, and must share a common
5023 * Return value: %FALSE if either widget was not realized, or there
5024 * was no common ancestor. In this case, nothing is stored in
5025 * *@dest_x and *@dest_y. Otherwise %TRUE.
5028 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5029 GtkWidget *dest_widget,
5035 GtkWidgetPrivate *src_priv = src_widget->priv;
5036 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5037 GtkWidget *ancestor;
5039 GList *dest_list = NULL;
5041 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5042 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5044 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5045 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5048 /* Translate from allocation relative to window relative */
5049 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5052 gdk_window_get_position (src_priv->window, &wx, &wy);
5054 src_x -= wx - src_priv->allocation.x;
5055 src_y -= wy - src_priv->allocation.y;
5059 src_x += src_priv->allocation.x;
5060 src_y += src_priv->allocation.y;
5063 /* Translate to the common ancestor */
5064 window = src_priv->window;
5065 while (window != ancestor->priv->window)
5069 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5074 window = gdk_window_get_effective_parent (window);
5076 if (!window) /* Handle GtkHandleBox */
5081 window = dest_priv->window;
5082 while (window != ancestor->priv->window)
5084 dest_list = g_list_prepend (dest_list, window);
5086 window = gdk_window_get_effective_parent (window);
5088 if (!window) /* Handle GtkHandleBox */
5090 g_list_free (dest_list);
5099 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5104 dest_list = g_list_remove (dest_list, dest_list->data);
5107 /* Translate from window relative to allocation relative */
5108 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5111 gdk_window_get_position (dest_priv->window, &wx, &wy);
5113 src_x += wx - dest_priv->allocation.x;
5114 src_y += wy - dest_priv->allocation.y;
5118 src_x -= dest_priv->allocation.x;
5119 src_y -= dest_priv->allocation.y;
5131 gtk_widget_real_size_allocate (GtkWidget *widget,
5132 GtkAllocation *allocation)
5134 GtkWidgetPrivate *priv = widget->priv;
5136 priv->allocation = *allocation;
5138 if (gtk_widget_get_realized (widget) &&
5139 gtk_widget_get_has_window (widget))
5141 gdk_window_move_resize (priv->window,
5142 allocation->x, allocation->y,
5143 allocation->width, allocation->height);
5147 /* translate initial/final into start/end */
5149 effective_align (GtkAlign align,
5150 GtkTextDirection direction)
5154 case GTK_ALIGN_START:
5155 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5157 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5164 adjust_for_align (GtkAlign align,
5166 gint *allocated_pos,
5167 gint *allocated_size)
5171 case GTK_ALIGN_FILL:
5172 /* change nothing */
5174 case GTK_ALIGN_START:
5175 /* keep *allocated_pos where it is */
5176 *allocated_size = MIN (*allocated_size, *natural_size);
5179 if (*allocated_size > *natural_size)
5181 *allocated_pos += (*allocated_size - *natural_size);
5182 *allocated_size = *natural_size;
5185 case GTK_ALIGN_CENTER:
5186 if (*allocated_size > *natural_size)
5188 *allocated_pos += (*allocated_size - *natural_size) / 2;
5189 *allocated_size = MIN (*allocated_size, *natural_size);
5196 adjust_for_margin(gint start_margin,
5200 gint *allocated_pos,
5201 gint *allocated_size)
5203 *minimum_size -= (start_margin + end_margin);
5204 *natural_size -= (start_margin + end_margin);
5205 *allocated_pos += start_margin;
5206 *allocated_size -= (start_margin + end_margin);
5210 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5211 GtkOrientation orientation,
5214 gint *allocated_pos,
5215 gint *allocated_size)
5217 const GtkWidgetAuxInfo *aux_info;
5219 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5221 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5223 adjust_for_margin (aux_info->margin.left,
5224 aux_info->margin.right,
5225 minimum_size, natural_size,
5226 allocated_pos, allocated_size);
5227 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5228 natural_size, allocated_pos, allocated_size);
5232 adjust_for_margin (aux_info->margin.top,
5233 aux_info->margin.bottom,
5234 minimum_size, natural_size,
5235 allocated_pos, allocated_size);
5236 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5237 natural_size, allocated_pos, allocated_size);
5242 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5245 GtkWidgetPrivate *priv = widget->priv;
5247 /* widgets must be onscreen for accels to take effect */
5248 return gtk_widget_is_sensitive (widget) &&
5249 gtk_widget_is_drawable (widget) &&
5250 gdk_window_is_viewable (priv->window);
5254 * gtk_widget_can_activate_accel:
5255 * @widget: a #GtkWidget
5256 * @signal_id: the ID of a signal installed on @widget
5258 * Determines whether an accelerator that activates the signal
5259 * identified by @signal_id can currently be activated.
5260 * This is done by emitting the #GtkWidget::can-activate-accel
5261 * signal on @widget; if the signal isn't overridden by a
5262 * handler or in a derived widget, then the default check is
5263 * that the widget must be sensitive, and the widget and all
5264 * its ancestors mapped.
5266 * Return value: %TRUE if the accelerator can be activated.
5271 gtk_widget_can_activate_accel (GtkWidget *widget,
5274 gboolean can_activate = FALSE;
5275 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5276 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5277 return can_activate;
5286 closure_accel_activate (GClosure *closure,
5287 GValue *return_value,
5288 guint n_param_values,
5289 const GValue *param_values,
5290 gpointer invocation_hint,
5291 gpointer marshal_data)
5293 AccelClosure *aclosure = (AccelClosure*) closure;
5294 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5297 g_signal_emit (closure->data, aclosure->signal_id, 0);
5299 /* whether accelerator was handled */
5300 g_value_set_boolean (return_value, can_activate);
5304 closures_destroy (gpointer data)
5306 GSList *slist, *closures = data;
5308 for (slist = closures; slist; slist = slist->next)
5310 g_closure_invalidate (slist->data);
5311 g_closure_unref (slist->data);
5313 g_slist_free (closures);
5317 widget_new_accel_closure (GtkWidget *widget,
5320 AccelClosure *aclosure;
5321 GClosure *closure = NULL;
5322 GSList *slist, *closures;
5324 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5325 for (slist = closures; slist; slist = slist->next)
5326 if (!gtk_accel_group_from_accel_closure (slist->data))
5328 /* reuse this closure */
5329 closure = slist->data;
5334 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5335 closures = g_slist_prepend (closures, g_closure_ref (closure));
5336 g_closure_sink (closure);
5337 g_closure_set_marshal (closure, closure_accel_activate);
5339 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5341 aclosure = (AccelClosure*) closure;
5342 g_assert (closure->data == widget);
5343 g_assert (closure->marshal == closure_accel_activate);
5344 aclosure->signal_id = signal_id;
5350 * gtk_widget_add_accelerator
5351 * @widget: widget to install an accelerator on
5352 * @accel_signal: widget signal to emit on accelerator activation
5353 * @accel_group: accel group for this widget, added to its toplevel
5354 * @accel_key: GDK keyval of the accelerator
5355 * @accel_mods: modifier key combination of the accelerator
5356 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5358 * Installs an accelerator for this @widget in @accel_group that causes
5359 * @accel_signal to be emitted if the accelerator is activated.
5360 * The @accel_group needs to be added to the widget's toplevel via
5361 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5362 * Accelerators added through this function are not user changeable during
5363 * runtime. If you want to support accelerators that can be changed by the
5364 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5365 * gtk_menu_item_set_accel_path() instead.
5368 gtk_widget_add_accelerator (GtkWidget *widget,
5369 const gchar *accel_signal,
5370 GtkAccelGroup *accel_group,
5372 GdkModifierType accel_mods,
5373 GtkAccelFlags accel_flags)
5378 g_return_if_fail (GTK_IS_WIDGET (widget));
5379 g_return_if_fail (accel_signal != NULL);
5380 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5382 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5383 if (!query.signal_id ||
5384 !(query.signal_flags & G_SIGNAL_ACTION) ||
5385 query.return_type != G_TYPE_NONE ||
5388 /* hmm, should be elaborate enough */
5389 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5390 G_OBJECT_TYPE_NAME (widget), accel_signal);
5394 closure = widget_new_accel_closure (widget, query.signal_id);
5396 g_object_ref (widget);
5398 /* install the accelerator. since we don't map this onto an accel_path,
5399 * the accelerator will automatically be locked.
5401 gtk_accel_group_connect (accel_group,
5404 accel_flags | GTK_ACCEL_LOCKED,
5407 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5409 g_object_unref (widget);
5413 * gtk_widget_remove_accelerator:
5414 * @widget: widget to install an accelerator on
5415 * @accel_group: accel group for this widget
5416 * @accel_key: GDK keyval of the accelerator
5417 * @accel_mods: modifier key combination of the accelerator
5419 * Removes an accelerator from @widget, previously installed with
5420 * gtk_widget_add_accelerator().
5422 * Returns: whether an accelerator was installed and could be removed
5425 gtk_widget_remove_accelerator (GtkWidget *widget,
5426 GtkAccelGroup *accel_group,
5428 GdkModifierType accel_mods)
5430 GtkAccelGroupEntry *ag_entry;
5431 GList *slist, *clist;
5434 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5435 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5437 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5438 clist = gtk_widget_list_accel_closures (widget);
5439 for (slist = clist; slist; slist = slist->next)
5443 for (i = 0; i < n; i++)
5444 if (slist->data == (gpointer) ag_entry[i].closure)
5446 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5448 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5450 g_list_free (clist);
5455 g_list_free (clist);
5457 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5458 accel_key, accel_mods, accel_group,
5459 G_OBJECT_TYPE_NAME (widget), widget);
5465 * gtk_widget_list_accel_closures:
5466 * @widget: widget to list accelerator closures for
5468 * Lists the closures used by @widget for accelerator group connections
5469 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5470 * The closures can be used to monitor accelerator changes on @widget,
5471 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5472 * #GtkAccelGroup of a closure which can be found out with
5473 * gtk_accel_group_from_accel_closure().
5475 * Return value: (transfer container) (element-type GClosure):
5476 * a newly allocated #GList of closures
5479 gtk_widget_list_accel_closures (GtkWidget *widget)
5482 GList *clist = NULL;
5484 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5486 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5487 if (gtk_accel_group_from_accel_closure (slist->data))
5488 clist = g_list_prepend (clist, slist->data);
5494 GtkAccelGroup *accel_group;
5499 destroy_accel_path (gpointer data)
5501 AccelPath *apath = data;
5503 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5505 /* closures_destroy takes care of unrefing the closure */
5506 g_object_unref (apath->accel_group);
5508 g_slice_free (AccelPath, apath);
5513 * gtk_widget_set_accel_path:
5514 * @widget: a #GtkWidget
5515 * @accel_path: (allow-none): path used to look up the accelerator
5516 * @accel_group: (allow-none): a #GtkAccelGroup.
5518 * Given an accelerator group, @accel_group, and an accelerator path,
5519 * @accel_path, sets up an accelerator in @accel_group so whenever the
5520 * key binding that is defined for @accel_path is pressed, @widget
5521 * will be activated. This removes any accelerators (for any
5522 * accelerator group) installed by previous calls to
5523 * gtk_widget_set_accel_path(). Associating accelerators with
5524 * paths allows them to be modified by the user and the modifications
5525 * to be saved for future use. (See gtk_accel_map_save().)
5527 * This function is a low level function that would most likely
5528 * be used by a menu creation system like #GtkUIManager. If you
5529 * use #GtkUIManager, setting up accelerator paths will be done
5532 * Even when you you aren't using #GtkUIManager, if you only want to
5533 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5534 * provides a somewhat more convenient interface.
5536 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5537 * pass a static string, you can save some memory by interning it first with
5538 * g_intern_static_string().
5541 gtk_widget_set_accel_path (GtkWidget *widget,
5542 const gchar *accel_path,
5543 GtkAccelGroup *accel_group)
5547 g_return_if_fail (GTK_IS_WIDGET (widget));
5548 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5552 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5553 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5555 gtk_accel_map_add_entry (accel_path, 0, 0);
5556 apath = g_slice_new (AccelPath);
5557 apath->accel_group = g_object_ref (accel_group);
5558 apath->path_quark = g_quark_from_string (accel_path);
5559 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5564 /* also removes possible old settings */
5565 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5568 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5570 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5574 _gtk_widget_get_accel_path (GtkWidget *widget,
5579 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5581 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5583 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5584 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5588 * gtk_widget_mnemonic_activate:
5589 * @widget: a #GtkWidget
5590 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5592 * Emits the #GtkWidget::mnemonic-activate signal.
5594 * The default handler for this signal activates the @widget if
5595 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5598 * Returns: %TRUE if the signal has been handled
5601 gtk_widget_mnemonic_activate (GtkWidget *widget,
5602 gboolean group_cycling)
5606 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5608 group_cycling = group_cycling != FALSE;
5609 if (!gtk_widget_is_sensitive (widget))
5612 g_signal_emit (widget,
5613 widget_signals[MNEMONIC_ACTIVATE],
5621 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5622 gboolean group_cycling)
5624 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5625 gtk_widget_activate (widget);
5626 else if (gtk_widget_get_can_focus (widget))
5627 gtk_widget_grab_focus (widget);
5630 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5631 G_OBJECT_TYPE_NAME (widget));
5632 gtk_widget_error_bell (widget);
5637 static const cairo_user_data_key_t event_key;
5640 _gtk_cairo_get_event (cairo_t *cr)
5642 g_return_val_if_fail (cr != NULL, NULL);
5644 return cairo_get_user_data (cr, &event_key);
5648 gtk_cairo_set_event (cairo_t *cr,
5649 GdkEventExpose *event)
5651 cairo_set_user_data (cr, &event_key, event, NULL);
5655 * gtk_cairo_should_draw_window:
5656 * @cr: a cairo context
5657 * @window: the window to check. @window may not be an input-only
5660 * This function is supposed to be called in #GtkWidget::draw
5661 * implementations for widgets that support multiple windows.
5662 * @cr must be untransformed from invoking of the draw function.
5663 * This function will return %TRUE if the contents of the given
5664 * @window are supposed to be drawn and %FALSE otherwise. Note
5665 * that when the drawing was not initiated by the windowing
5666 * system this function will return %TRUE for all windows, so
5667 * you need to draw the bottommost window first. Also, do not
5668 * use "else if" statements to check which window should be drawn.
5670 * Returns: %TRUE if @window should be drawn
5675 gtk_cairo_should_draw_window (cairo_t *cr,
5678 GdkEventExpose *event;
5680 g_return_val_if_fail (cr != NULL, FALSE);
5681 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5683 event = _gtk_cairo_get_event (cr);
5685 return event == NULL ||
5686 event->window == window;
5690 gtk_widget_get_clip_draw (GtkWidget *widget)
5692 /* labels are not clipped, because clipping them would cause
5693 * mnemonics to not appear on characters that go beyond the
5695 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
5697 if (GTK_IS_LABEL (widget))
5703 /* code shared by gtk_container_propagate_draw() and
5707 _gtk_widget_draw_internal (GtkWidget *widget,
5709 gboolean clip_to_size)
5711 GtkStyleContext *context;
5713 if (!gtk_widget_is_drawable (widget))
5716 clip_to_size &= gtk_widget_get_clip_draw (widget);
5720 cairo_rectangle (cr,
5722 widget->priv->allocation.width,
5723 widget->priv->allocation.height);
5727 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5731 g_signal_emit (widget, widget_signals[DRAW],
5735 if (cairo_status (cr) &&
5736 _gtk_cairo_get_event (cr))
5738 /* We check the event so we only warn about internal GTK calls.
5739 * Errors might come from PDF streams having write failures and
5740 * we don't want to spam stderr in that case.
5741 * We do want to catch errors from
5743 g_warning ("drawing failure for widget `%s': %s",
5744 G_OBJECT_TYPE_NAME (widget),
5745 cairo_status_to_string (cairo_status (cr)));
5749 context = gtk_widget_get_style_context (widget);
5750 _gtk_style_context_coalesce_animation_areas (context, widget);
5755 * @widget: the widget to draw. It must be drawable (see
5756 * gtk_widget_is_drawable()) and a size must have been allocated.
5757 * @cr: a cairo context to draw to
5759 * Draws @widget to @cr. The top left corner of the widget will be
5760 * drawn to the currently set origin point of @cr.
5762 * You should pass a cairo context as @cr argument that is in an
5763 * original state. Otherwise the resulting drawing is undefined. For
5764 * example changing the operator using cairo_set_operator() or the
5765 * line width using cairo_set_line_width() might have unwanted side
5767 * You may however change the context's transform matrix - like with
5768 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5769 * region with cairo_clip() prior to calling this function. Also, it
5770 * is fine to modify the context with cairo_save() and
5771 * cairo_push_group() prior to calling this function.
5773 * <note><para>Special purpose widgets may contain special code for
5774 * rendering to the screen and might appear differently on screen
5775 * and when rendered using gtk_widget_draw().</para></note>
5780 gtk_widget_draw (GtkWidget *widget,
5783 GdkEventExpose *tmp_event;
5785 g_return_if_fail (GTK_IS_WIDGET (widget));
5786 g_return_if_fail (!widget->priv->alloc_needed);
5787 g_return_if_fail (cr != NULL);
5790 /* We have to reset the event here so that draw functions can call
5791 * gtk_widget_draw() on random other widgets and get the desired
5792 * effect: Drawing all contents, not just the current window.
5794 tmp_event = _gtk_cairo_get_event (cr);
5795 gtk_cairo_set_event (cr, NULL);
5797 _gtk_widget_draw_internal (widget, cr, TRUE);
5799 gtk_cairo_set_event (cr, tmp_event);
5804 gtk_widget_real_key_press_event (GtkWidget *widget,
5807 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5811 gtk_widget_real_key_release_event (GtkWidget *widget,
5814 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5818 gtk_widget_real_focus_in_event (GtkWidget *widget,
5819 GdkEventFocus *event)
5821 gtk_widget_queue_shallow_draw (widget);
5827 gtk_widget_real_focus_out_event (GtkWidget *widget,
5828 GdkEventFocus *event)
5830 gtk_widget_queue_shallow_draw (widget);
5835 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5836 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5840 * @widget: a #GtkWidget
5841 * @event: a #GdkEvent
5843 * Rarely-used function. This function is used to emit
5844 * the event signals on a widget (those signals should never
5845 * be emitted without using this function to do so).
5846 * If you want to synthesize an event though, don't use this function;
5847 * instead, use gtk_main_do_event() so the event will behave as if
5848 * it were in the event queue. Don't synthesize expose events; instead,
5849 * use gdk_window_invalidate_rect() to invalidate a region of the
5852 * Return value: return from the event signal emission (%TRUE if
5853 * the event was handled)
5856 gtk_widget_event (GtkWidget *widget,
5859 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5860 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5862 if (event->type == GDK_EXPOSE)
5864 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5865 "the same effect, call gdk_window_invalidate_rect/region(), "
5866 "followed by gdk_window_process_updates().");
5870 return gtk_widget_event_internal (widget, event);
5873 /* Returns TRUE if a translation should be done */
5875 _gtk_widget_get_translation_to_window (GtkWidget *widget,
5880 GdkWindow *w, *widget_window;
5882 if (!gtk_widget_get_has_window (widget))
5884 *x = -widget->priv->allocation.x;
5885 *y = -widget->priv->allocation.y;
5893 widget_window = gtk_widget_get_window (widget);
5895 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5898 gdk_window_get_position (w, &wx, &wy);
5915 * gtk_cairo_transform_to_window:
5916 * @cr: the cairo context to transform
5917 * @widget: the widget the context is currently centered for
5918 * @window: the window to transform the context to
5920 * Transforms the given cairo context @cr that from @widget-relative
5921 * coordinates to @window-relative coordinates.
5922 * If the @widget's window is not an ancestor of @window, no
5923 * modification will be applied.
5925 * This is the inverse to the transformation GTK applies when
5926 * preparing an expose event to be emitted with the #GtkWidget::draw
5927 * signal. It is intended to help porting multiwindow widgets from
5928 * GTK+ 2 to the rendering architecture of GTK+ 3.
5933 gtk_cairo_transform_to_window (cairo_t *cr,
5939 g_return_if_fail (cr != NULL);
5940 g_return_if_fail (GTK_IS_WIDGET (widget));
5941 g_return_if_fail (GDK_IS_WINDOW (window));
5943 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
5944 cairo_translate (cr, x, y);
5948 * gtk_widget_send_expose:
5949 * @widget: a #GtkWidget
5950 * @event: a expose #GdkEvent
5952 * Very rarely-used function. This function is used to emit
5953 * an expose event on a widget. This function is not normally used
5954 * directly. The only time it is used is when propagating an expose
5955 * event to a child %NO_WINDOW widget, and that is normally done
5956 * using gtk_container_propagate_draw().
5958 * If you want to force an area of a window to be redrawn,
5959 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5960 * To cause the redraw to be done immediately, follow that call
5961 * with a call to gdk_window_process_updates().
5963 * Return value: return from the event signal emission (%TRUE if
5964 * the event was handled)
5967 gtk_widget_send_expose (GtkWidget *widget,
5970 gboolean result = FALSE;
5975 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5976 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5977 g_return_val_if_fail (event != NULL, TRUE);
5978 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5980 cr = gdk_cairo_create (event->expose.window);
5981 gtk_cairo_set_event (cr, &event->expose);
5983 gdk_cairo_region (cr, event->expose.region);
5986 do_clip = _gtk_widget_get_translation_to_window (widget,
5987 event->expose.window,
5989 cairo_translate (cr, -x, -y);
5991 _gtk_widget_draw_internal (widget, cr, do_clip);
5993 /* unset here, so if someone keeps a reference to cr we
5994 * don't leak the window. */
5995 gtk_cairo_set_event (cr, NULL);
6002 event_window_is_still_viewable (GdkEvent *event)
6004 /* Check that we think the event's window is viewable before
6005 * delivering the event, to prevent suprises. We do this here
6006 * at the last moment, since the event may have been queued
6007 * up behind other events, held over a recursive main loop, etc.
6009 switch (event->type)
6012 case GDK_MOTION_NOTIFY:
6013 case GDK_BUTTON_PRESS:
6014 case GDK_2BUTTON_PRESS:
6015 case GDK_3BUTTON_PRESS:
6017 case GDK_ENTER_NOTIFY:
6018 case GDK_PROXIMITY_IN:
6020 return event->any.window && gdk_window_is_viewable (event->any.window);
6023 /* The following events are the second half of paired events;
6024 * we always deliver them to deal with widgets that clean up
6025 * on the second half.
6027 case GDK_BUTTON_RELEASE:
6028 case GDK_KEY_RELEASE:
6029 case GDK_LEAVE_NOTIFY:
6030 case GDK_PROXIMITY_OUT:
6034 /* Remaining events would make sense on an not-viewable window,
6035 * or don't have an associated window.
6042 gtk_widget_event_internal (GtkWidget *widget,
6045 gboolean return_val = FALSE;
6047 /* We check only once for is-still-visible; if someone
6048 * hides the window in on of the signals on the widget,
6049 * they are responsible for returning TRUE to terminate
6052 if (!event_window_is_still_viewable (event))
6055 g_object_ref (widget);
6057 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6058 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6063 switch (event->type)
6069 case GDK_BUTTON_PRESS:
6070 case GDK_2BUTTON_PRESS:
6071 case GDK_3BUTTON_PRESS:
6072 signal_num = BUTTON_PRESS_EVENT;
6075 signal_num = SCROLL_EVENT;
6077 case GDK_BUTTON_RELEASE:
6078 signal_num = BUTTON_RELEASE_EVENT;
6080 case GDK_MOTION_NOTIFY:
6081 signal_num = MOTION_NOTIFY_EVENT;
6084 signal_num = DELETE_EVENT;
6087 signal_num = DESTROY_EVENT;
6088 _gtk_tooltip_hide (widget);
6091 signal_num = KEY_PRESS_EVENT;
6093 case GDK_KEY_RELEASE:
6094 signal_num = KEY_RELEASE_EVENT;
6096 case GDK_ENTER_NOTIFY:
6097 signal_num = ENTER_NOTIFY_EVENT;
6099 case GDK_LEAVE_NOTIFY:
6100 signal_num = LEAVE_NOTIFY_EVENT;
6102 case GDK_FOCUS_CHANGE:
6103 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6104 if (event->focus_change.in)
6105 _gtk_tooltip_focus_in (widget);
6107 _gtk_tooltip_focus_out (widget);
6110 signal_num = CONFIGURE_EVENT;
6113 signal_num = MAP_EVENT;
6116 signal_num = UNMAP_EVENT;
6118 case GDK_WINDOW_STATE:
6119 signal_num = WINDOW_STATE_EVENT;
6121 case GDK_PROPERTY_NOTIFY:
6122 signal_num = PROPERTY_NOTIFY_EVENT;
6124 case GDK_SELECTION_CLEAR:
6125 signal_num = SELECTION_CLEAR_EVENT;
6127 case GDK_SELECTION_REQUEST:
6128 signal_num = SELECTION_REQUEST_EVENT;
6130 case GDK_SELECTION_NOTIFY:
6131 signal_num = SELECTION_NOTIFY_EVENT;
6133 case GDK_PROXIMITY_IN:
6134 signal_num = PROXIMITY_IN_EVENT;
6136 case GDK_PROXIMITY_OUT:
6137 signal_num = PROXIMITY_OUT_EVENT;
6139 case GDK_VISIBILITY_NOTIFY:
6140 signal_num = VISIBILITY_NOTIFY_EVENT;
6142 case GDK_GRAB_BROKEN:
6143 signal_num = GRAB_BROKEN_EVENT;
6146 signal_num = DAMAGE_EVENT;
6149 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6153 if (signal_num != -1)
6154 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6156 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6157 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6161 g_object_unref (widget);
6167 * gtk_widget_activate:
6168 * @widget: a #GtkWidget that's activatable
6170 * For widgets that can be "activated" (buttons, menu items, etc.)
6171 * this function activates them. Activation is what happens when you
6172 * press Enter on a widget during key navigation. If @widget isn't
6173 * activatable, the function returns %FALSE.
6175 * Return value: %TRUE if the widget was activatable
6178 gtk_widget_activate (GtkWidget *widget)
6180 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6182 if (WIDGET_CLASS (widget)->activate_signal)
6184 /* FIXME: we should eventually check the signals signature here */
6185 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6194 gtk_widget_reparent_subwindows (GtkWidget *widget,
6195 GdkWindow *new_window)
6197 GtkWidgetPrivate *priv = widget->priv;
6199 if (!gtk_widget_get_has_window (widget))
6201 GList *children = gdk_window_get_children (priv->window);
6204 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6206 GdkWindow *window = tmp_list->data;
6209 gdk_window_get_user_data (window, &child);
6210 while (child && child != widget)
6211 child = ((GtkWidget*) child)->priv->parent;
6214 gdk_window_reparent (window, new_window, 0, 0);
6217 g_list_free (children);
6222 GList *tmp_list, *children;
6224 parent = gdk_window_get_parent (priv->window);
6227 gdk_window_reparent (priv->window, new_window, 0, 0);
6230 children = gdk_window_get_children (parent);
6232 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6234 GdkWindow *window = tmp_list->data;
6237 gdk_window_get_user_data (window, &child);
6239 if (child == widget)
6240 gdk_window_reparent (window, new_window, 0, 0);
6243 g_list_free (children);
6249 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6250 gpointer client_data)
6252 GtkWidgetPrivate *priv = widget->priv;
6254 g_assert (client_data != NULL);
6256 if (!gtk_widget_get_has_window (widget))
6259 g_object_unref (priv->window);
6260 priv->window = (GdkWindow*) client_data;
6262 g_object_ref (priv->window);
6264 if (GTK_IS_CONTAINER (widget))
6265 gtk_container_forall (GTK_CONTAINER (widget),
6266 gtk_widget_reparent_fixup_child,
6272 * gtk_widget_reparent:
6273 * @widget: a #GtkWidget
6274 * @new_parent: a #GtkContainer to move the widget into
6276 * Moves a widget from one #GtkContainer to another, handling reference
6277 * count issues to avoid destroying the widget.
6280 gtk_widget_reparent (GtkWidget *widget,
6281 GtkWidget *new_parent)
6283 GtkWidgetPrivate *priv;
6285 g_return_if_fail (GTK_IS_WIDGET (widget));
6286 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6287 priv = widget->priv;
6288 g_return_if_fail (priv->parent != NULL);
6290 if (priv->parent != new_parent)
6292 /* First try to see if we can get away without unrealizing
6293 * the widget as we reparent it. if so we set a flag so
6294 * that gtk_widget_unparent doesn't unrealize widget
6296 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6297 priv->in_reparent = TRUE;
6299 g_object_ref (widget);
6300 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6301 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6302 g_object_unref (widget);
6304 if (priv->in_reparent)
6306 priv->in_reparent = FALSE;
6308 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6309 gtk_widget_reparent_fixup_child (widget,
6310 gtk_widget_get_parent_window (widget));
6313 g_object_notify (G_OBJECT (widget), "parent");
6318 * gtk_widget_intersect:
6319 * @widget: a #GtkWidget
6320 * @area: a rectangle
6321 * @intersection: rectangle to store intersection of @widget and @area
6323 * Computes the intersection of a @widget's area and @area, storing
6324 * the intersection in @intersection, and returns %TRUE if there was
6325 * an intersection. @intersection may be %NULL if you're only
6326 * interested in whether there was an intersection.
6328 * Return value: %TRUE if there was an intersection
6331 gtk_widget_intersect (GtkWidget *widget,
6332 const GdkRectangle *area,
6333 GdkRectangle *intersection)
6335 GtkWidgetPrivate *priv;
6340 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6341 g_return_val_if_fail (area != NULL, FALSE);
6343 priv = widget->priv;
6346 dest = intersection;
6350 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6352 if (return_val && intersection && gtk_widget_get_has_window (widget))
6354 intersection->x -= priv->allocation.x;
6355 intersection->y -= priv->allocation.y;
6362 * gtk_widget_region_intersect:
6363 * @widget: a #GtkWidget
6364 * @region: a #cairo_region_t, in the same coordinate system as
6365 * @widget->allocation. That is, relative to @widget->window
6366 * for %NO_WINDOW widgets; relative to the parent window
6367 * of @widget->window for widgets with their own window.
6369 * Computes the intersection of a @widget's area and @region, returning
6370 * the intersection. The result may be empty, use cairo_region_is_empty() to
6373 * Returns: A newly allocated region holding the intersection of @widget
6374 * and @region. The coordinates of the return value are relative to
6375 * @widget->window for %NO_WINDOW widgets, and relative to the parent
6376 * window of @widget->window for widgets with their own window.
6379 gtk_widget_region_intersect (GtkWidget *widget,
6380 const cairo_region_t *region)
6383 cairo_region_t *dest;
6385 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6386 g_return_val_if_fail (region != NULL, NULL);
6388 gtk_widget_get_allocation (widget, &rect);
6390 dest = cairo_region_create_rectangle (&rect);
6392 cairo_region_intersect (dest, region);
6398 * _gtk_widget_grab_notify:
6399 * @widget: a #GtkWidget
6400 * @was_grabbed: whether a grab is now in effect
6402 * Emits the #GtkWidget::grab-notify signal on @widget.
6407 _gtk_widget_grab_notify (GtkWidget *widget,
6408 gboolean was_grabbed)
6410 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6414 * gtk_widget_grab_focus:
6415 * @widget: a #GtkWidget
6417 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6418 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6419 * something like #GtkFrame won't work.
6421 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6422 * gtk_widget_set_can_focus() to modify that flag.
6424 * The widget also needs to be realized and mapped. This is indicated by the
6425 * related signals. Grabbing the focus immediately after creating the widget
6426 * will likely fail and cause critical warnings.
6429 gtk_widget_grab_focus (GtkWidget *widget)
6431 g_return_if_fail (GTK_IS_WIDGET (widget));
6433 if (!gtk_widget_is_sensitive (widget))
6436 g_object_ref (widget);
6437 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6438 g_object_notify (G_OBJECT (widget), "has-focus");
6439 g_object_unref (widget);
6443 reset_focus_recurse (GtkWidget *widget,
6446 if (GTK_IS_CONTAINER (widget))
6448 GtkContainer *container;
6450 container = GTK_CONTAINER (widget);
6451 gtk_container_set_focus_child (container, NULL);
6453 gtk_container_foreach (container,
6454 reset_focus_recurse,
6460 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6462 if (gtk_widget_get_can_focus (focus_widget))
6464 GtkWidget *toplevel;
6467 /* clear the current focus setting, break if the current widget
6468 * is the focus widget's parent, since containers above that will
6469 * be set by the next loop.
6471 toplevel = gtk_widget_get_toplevel (focus_widget);
6472 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6474 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6476 if (widget == focus_widget)
6478 /* We call _gtk_window_internal_set_focus() here so that the
6479 * toplevel window can request the focus if necessary.
6480 * This is needed when the toplevel is a GtkPlug
6482 if (!gtk_widget_has_focus (widget))
6483 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6490 GtkWidget *common_ancestor = gtk_widget_common_ancestor (widget, focus_widget);
6492 if (widget != common_ancestor)
6494 while (widget->priv->parent && widget->priv->parent != common_ancestor)
6496 widget = widget->priv->parent;
6497 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6502 else if (toplevel != focus_widget)
6504 /* gtk_widget_grab_focus() operates on a tree without window...
6505 * actually, this is very questionable behaviour.
6508 gtk_container_foreach (GTK_CONTAINER (toplevel),
6509 reset_focus_recurse,
6513 /* now propagate the new focus up the widget tree and finally
6514 * set it on the window
6516 widget = focus_widget;
6517 while (widget->priv->parent)
6519 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6520 widget = widget->priv->parent;
6522 if (GTK_IS_WINDOW (widget))
6523 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6528 gtk_widget_real_query_tooltip (GtkWidget *widget,
6531 gboolean keyboard_tip,
6532 GtkTooltip *tooltip)
6534 gchar *tooltip_markup;
6535 gboolean has_tooltip;
6537 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6538 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6540 if (has_tooltip && tooltip_markup)
6542 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6550 gtk_widget_real_state_flags_changed (GtkWidget *widget,
6551 GtkStateFlags old_state)
6553 gtk_widget_update_pango_context (widget);
6557 gtk_widget_real_style_updated (GtkWidget *widget)
6559 GtkWidgetPrivate *priv = widget->priv;
6561 gtk_widget_update_pango_context (widget);
6563 if (priv->style != NULL &&
6564 priv->style != gtk_widget_get_default_style ())
6566 /* Trigger ::style-set for old
6567 * widgets not listening to this
6569 g_signal_emit (widget,
6570 widget_signals[STYLE_SET],
6572 widget->priv->style);
6575 if (widget->priv->context)
6577 if (gtk_widget_get_realized (widget) &&
6578 gtk_widget_get_has_window (widget))
6579 gtk_style_context_set_background (widget->priv->context,
6580 widget->priv->window);
6583 if (widget->priv->anchored)
6584 gtk_widget_queue_resize (widget);
6588 gtk_widget_real_show_help (GtkWidget *widget,
6589 GtkWidgetHelpType help_type)
6591 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6593 _gtk_tooltip_toggle_keyboard_mode (widget);
6602 gtk_widget_real_focus (GtkWidget *widget,
6603 GtkDirectionType direction)
6605 if (!gtk_widget_get_can_focus (widget))
6608 if (!gtk_widget_is_focus (widget))
6610 gtk_widget_grab_focus (widget);
6618 gtk_widget_real_move_focus (GtkWidget *widget,
6619 GtkDirectionType direction)
6621 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6623 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6625 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6631 gtk_widget_real_keynav_failed (GtkWidget *widget,
6632 GtkDirectionType direction)
6634 gboolean cursor_only;
6638 case GTK_DIR_TAB_FORWARD:
6639 case GTK_DIR_TAB_BACKWARD:
6646 g_object_get (gtk_widget_get_settings (widget),
6647 "gtk-keynav-cursor-only", &cursor_only,
6654 gtk_widget_error_bell (widget);
6660 * gtk_widget_set_can_focus:
6661 * @widget: a #GtkWidget
6662 * @can_focus: whether or not @widget can own the input focus.
6664 * Specifies whether @widget can own the input focus. See
6665 * gtk_widget_grab_focus() for actually setting the input focus on a
6671 gtk_widget_set_can_focus (GtkWidget *widget,
6674 g_return_if_fail (GTK_IS_WIDGET (widget));
6676 if (widget->priv->can_focus != can_focus)
6678 widget->priv->can_focus = can_focus;
6680 gtk_widget_queue_resize (widget);
6681 g_object_notify (G_OBJECT (widget), "can-focus");
6686 * gtk_widget_get_can_focus:
6687 * @widget: a #GtkWidget
6689 * Determines whether @widget can own the input focus. See
6690 * gtk_widget_set_can_focus().
6692 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6697 gtk_widget_get_can_focus (GtkWidget *widget)
6699 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6701 return widget->priv->can_focus;
6705 * gtk_widget_has_focus:
6706 * @widget: a #GtkWidget
6708 * Determines if the widget has the global input focus. See
6709 * gtk_widget_is_focus() for the difference between having the global
6710 * input focus, and only having the focus within a toplevel.
6712 * Return value: %TRUE if the widget has the global input focus.
6717 gtk_widget_has_focus (GtkWidget *widget)
6719 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6721 return widget->priv->has_focus;
6725 * gtk_widget_has_visible_focus:
6726 * @widget: a #GtkWidget
6728 * Determines if the widget should show a visible indication that
6729 * it has the global input focus. This is a convenience function for
6730 * use in ::draw handlers that takes into account whether focus
6731 * indication should currently be shown in the toplevel window of
6732 * @widget. See gtk_window_get_focus_visible() for more information
6733 * about focus indication.
6735 * To find out if the widget has the global input focus, use
6736 * gtk_widget_has_focus().
6738 * Return value: %TRUE if the widget should display a 'focus rectangle'
6743 gtk_widget_has_visible_focus (GtkWidget *widget)
6745 gboolean draw_focus;
6747 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6749 if (widget->priv->has_focus)
6751 GtkWidget *toplevel;
6753 toplevel = gtk_widget_get_toplevel (widget);
6755 if (GTK_IS_WINDOW (toplevel))
6756 draw_focus = gtk_window_get_focus_visible (GTK_WINDOW (toplevel));
6767 * gtk_widget_is_focus:
6768 * @widget: a #GtkWidget
6770 * Determines if the widget is the focus widget within its
6771 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6772 * necessarily set; %HAS_FOCUS will only be set if the
6773 * toplevel widget additionally has the global input focus.)
6775 * Return value: %TRUE if the widget is the focus widget.
6778 gtk_widget_is_focus (GtkWidget *widget)
6780 GtkWidget *toplevel;
6782 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6784 toplevel = gtk_widget_get_toplevel (widget);
6786 if (GTK_IS_WINDOW (toplevel))
6787 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6793 * gtk_widget_set_can_default:
6794 * @widget: a #GtkWidget
6795 * @can_default: whether or not @widget can be a default widget.
6797 * Specifies whether @widget can be a default widget. See
6798 * gtk_widget_grab_default() for details about the meaning of
6804 gtk_widget_set_can_default (GtkWidget *widget,
6805 gboolean can_default)
6807 g_return_if_fail (GTK_IS_WIDGET (widget));
6809 if (widget->priv->can_default != can_default)
6811 widget->priv->can_default = can_default;
6813 gtk_widget_queue_resize (widget);
6814 g_object_notify (G_OBJECT (widget), "can-default");
6819 * gtk_widget_get_can_default:
6820 * @widget: a #GtkWidget
6822 * Determines whether @widget can be a default widget. See
6823 * gtk_widget_set_can_default().
6825 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6830 gtk_widget_get_can_default (GtkWidget *widget)
6832 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6834 return widget->priv->can_default;
6838 * gtk_widget_has_default:
6839 * @widget: a #GtkWidget
6841 * Determines whether @widget is the current default widget within its
6842 * toplevel. See gtk_widget_set_can_default().
6844 * Return value: %TRUE if @widget is the current default widget within
6845 * its toplevel, %FALSE otherwise
6850 gtk_widget_has_default (GtkWidget *widget)
6852 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6854 return widget->priv->has_default;
6858 _gtk_widget_set_has_default (GtkWidget *widget,
6859 gboolean has_default)
6861 widget->priv->has_default = has_default;
6865 * gtk_widget_grab_default:
6866 * @widget: a #GtkWidget
6868 * Causes @widget to become the default widget. @widget must have the
6869 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6870 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6871 * %TRUE)</literal>. The default widget is activated when
6872 * the user presses Enter in a window. Default widgets must be
6873 * activatable, that is, gtk_widget_activate() should affect them. Note
6874 * that #GtkEntry widgets require the "activates-default" property
6875 * set to %TRUE before they activate the default widget when Enter
6876 * is pressed and the #GtkEntry is focused.
6879 gtk_widget_grab_default (GtkWidget *widget)
6883 g_return_if_fail (GTK_IS_WIDGET (widget));
6884 g_return_if_fail (gtk_widget_get_can_default (widget));
6886 window = gtk_widget_get_toplevel (widget);
6888 if (window && gtk_widget_is_toplevel (window))
6889 gtk_window_set_default (GTK_WINDOW (window), widget);
6891 g_warning (G_STRLOC ": widget not within a GtkWindow");
6895 * gtk_widget_set_receives_default:
6896 * @widget: a #GtkWidget
6897 * @receives_default: whether or not @widget can be a default widget.
6899 * Specifies whether @widget will be treated as the default widget
6900 * within its toplevel when it has the focus, even if another widget
6903 * See gtk_widget_grab_default() for details about the meaning of
6909 gtk_widget_set_receives_default (GtkWidget *widget,
6910 gboolean receives_default)
6912 g_return_if_fail (GTK_IS_WIDGET (widget));
6914 if (widget->priv->receives_default != receives_default)
6916 widget->priv->receives_default = receives_default;
6918 g_object_notify (G_OBJECT (widget), "receives-default");
6923 * gtk_widget_get_receives_default:
6924 * @widget: a #GtkWidget
6926 * Determines whether @widget is alyways treated as default widget
6927 * withing its toplevel when it has the focus, even if another widget
6930 * See gtk_widget_set_receives_default().
6932 * Return value: %TRUE if @widget acts as default widget when focussed,
6938 gtk_widget_get_receives_default (GtkWidget *widget)
6940 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6942 return widget->priv->receives_default;
6946 * gtk_widget_has_grab:
6947 * @widget: a #GtkWidget
6949 * Determines whether the widget is currently grabbing events, so it
6950 * is the only widget receiving input events (keyboard and mouse).
6952 * See also gtk_grab_add().
6954 * Return value: %TRUE if the widget is in the grab_widgets stack
6959 gtk_widget_has_grab (GtkWidget *widget)
6961 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6963 return widget->priv->has_grab;
6967 _gtk_widget_set_has_grab (GtkWidget *widget,
6970 widget->priv->has_grab = has_grab;
6974 * gtk_widget_device_is_shadowed:
6975 * @widget: a #GtkWidget
6976 * @device: a #GdkDevice
6978 * Returns %TRUE if @device has been shadowed by a GTK+
6979 * device grab on another widget, so it would stop sending
6980 * events to @widget. This may be used in the
6981 * #GtkWidget::grab-notify signal to check for specific
6982 * devices. See gtk_device_grab_add().
6984 * Returns: %TRUE if there is an ongoing grab on @device
6985 * by another #GtkWidget than @widget.
6990 gtk_widget_device_is_shadowed (GtkWidget *widget,
6993 GtkWindowGroup *group;
6994 GtkWidget *grab_widget, *toplevel;
6996 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6997 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6999 if (!gtk_widget_get_realized (widget))
7002 toplevel = gtk_widget_get_toplevel (widget);
7004 if (GTK_IS_WINDOW (toplevel))
7005 group = gtk_window_get_group (GTK_WINDOW (toplevel));
7007 group = gtk_window_get_group (NULL);
7009 grab_widget = gtk_window_group_get_current_device_grab (group, device);
7011 /* Widget not inside the hierarchy of grab_widget */
7013 widget != grab_widget &&
7014 !gtk_widget_is_ancestor (widget, grab_widget))
7017 grab_widget = gtk_window_group_get_current_grab (group);
7018 if (grab_widget && widget != grab_widget &&
7019 !gtk_widget_is_ancestor (widget, grab_widget))
7026 * gtk_widget_set_name:
7027 * @widget: a #GtkWidget
7028 * @name: name for the widget
7030 * Widgets can be named, which allows you to refer to them from a
7031 * CSS file. You can apply a style to widgets with a particular name
7032 * in the CSS file. See the documentation for the CSS syntax (on the
7033 * same page as the docs for #GtkStyleContext).
7035 * Note that the CSS syntax has certain special characters to delimit
7036 * and represent elements in a selector (period, #, >, *...),
7037 * so using these will make your widget impossible to match by name.
7038 * Any combination of alphanumeric symbols, dashes and underscores will
7042 gtk_widget_set_name (GtkWidget *widget,
7045 GtkWidgetPrivate *priv;
7048 g_return_if_fail (GTK_IS_WIDGET (widget));
7050 priv = widget->priv;
7052 new_name = g_strdup (name);
7053 g_free (priv->name);
7054 priv->name = new_name;
7056 gtk_widget_reset_style (widget);
7058 g_object_notify (G_OBJECT (widget), "name");
7062 * gtk_widget_get_name:
7063 * @widget: a #GtkWidget
7065 * Retrieves the name of a widget. See gtk_widget_set_name() for the
7066 * significance of widget names.
7068 * Return value: name of the widget. This string is owned by GTK+ and
7069 * should not be modified or freed
7072 gtk_widget_get_name (GtkWidget *widget)
7074 GtkWidgetPrivate *priv;
7076 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7078 priv = widget->priv;
7082 return G_OBJECT_TYPE_NAME (widget);
7086 _gtk_widget_update_state_flags (GtkWidget *widget,
7087 GtkStateFlags flags,
7090 GtkWidgetPrivate *priv;
7092 priv = widget->priv;
7094 /* Handle insensitive first, since it is propagated
7095 * differently throughout the widget hierarchy.
7097 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_UNSET))
7098 gtk_widget_set_sensitive (widget, TRUE);
7099 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation != STATE_CHANGE_UNSET))
7100 gtk_widget_set_sensitive (widget, FALSE);
7101 else if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && !(flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_REPLACE))
7102 gtk_widget_set_sensitive (widget, TRUE);
7104 if (operation != STATE_CHANGE_REPLACE)
7105 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
7108 operation == STATE_CHANGE_REPLACE)
7113 data.operation = operation;
7115 gtk_widget_propagate_state (widget, &data);
7117 gtk_widget_queue_resize (widget);
7122 * gtk_widget_set_state_flags:
7123 * @widget: a #GtkWidget
7124 * @flags: State flags to turn on
7125 * @clear: Whether to clear state before turning on @flags
7127 * This function is for use in widget implementations. Turns on flag
7128 * values in the current widget state (insensitive, prelighted, etc.).
7130 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7131 * will be propagated down to all non-internal children if @widget is a
7132 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7133 * down to all #GtkContainer children by different means than turning on the
7134 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7135 * gtk_widget_is_sensitive() will make use of these.
7140 gtk_widget_set_state_flags (GtkWidget *widget,
7141 GtkStateFlags flags,
7144 g_return_if_fail (GTK_IS_WIDGET (widget));
7146 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7147 (clear && widget->priv->state_flags == flags))
7151 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7153 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
7157 * gtk_widget_unset_state_flags:
7158 * @widget: a #GtkWidget
7159 * @flags: State flags to turn off
7161 * This function is for use in widget implementations. Turns off flag
7162 * values for the current widget state (insensitive, prelighted, etc.).
7163 * See gtk_widget_set_state_flags().
7168 gtk_widget_unset_state_flags (GtkWidget *widget,
7169 GtkStateFlags flags)
7171 g_return_if_fail (GTK_IS_WIDGET (widget));
7173 if ((widget->priv->state_flags & flags) == 0)
7176 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
7180 * gtk_widget_get_state_flags:
7181 * @widget: a #GtkWidget
7183 * Returns the widget state as a flag set. It is worth mentioning
7184 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7185 * returned, that is, also based on parent insensitivity, even if
7186 * @widget itself is sensitive.
7188 * Returns: The state flags for widget
7193 gtk_widget_get_state_flags (GtkWidget *widget)
7195 GtkStateFlags flags;
7197 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7199 flags = widget->priv->state_flags;
7201 if (gtk_widget_has_focus (widget))
7202 flags |= GTK_STATE_FLAG_FOCUSED;
7208 * gtk_widget_set_state:
7209 * @widget: a #GtkWidget
7210 * @state: new state for @widget
7212 * This function is for use in widget implementations. Sets the state
7213 * of a widget (insensitive, prelighted, etc.) Usually you should set
7214 * the state using wrapper functions such as gtk_widget_set_sensitive().
7216 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7219 gtk_widget_set_state (GtkWidget *widget,
7222 GtkStateFlags flags;
7224 if (state == gtk_widget_get_state (widget))
7229 case GTK_STATE_ACTIVE:
7230 flags = GTK_STATE_FLAG_ACTIVE;
7232 case GTK_STATE_PRELIGHT:
7233 flags = GTK_STATE_FLAG_PRELIGHT;
7235 case GTK_STATE_SELECTED:
7236 flags = GTK_STATE_FLAG_SELECTED;
7238 case GTK_STATE_INSENSITIVE:
7239 flags = GTK_STATE_FLAG_INSENSITIVE;
7241 case GTK_STATE_INCONSISTENT:
7242 flags = GTK_STATE_FLAG_INCONSISTENT;
7244 case GTK_STATE_FOCUSED:
7245 flags = GTK_STATE_FLAG_FOCUSED;
7247 case GTK_STATE_NORMAL:
7253 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7257 * gtk_widget_get_state:
7258 * @widget: a #GtkWidget
7260 * Returns the widget's state. See gtk_widget_set_state().
7262 * Returns: the state of @widget.
7266 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7269 gtk_widget_get_state (GtkWidget *widget)
7271 GtkStateFlags flags;
7273 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7275 flags = gtk_widget_get_state_flags (widget);
7277 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7278 return GTK_STATE_INSENSITIVE;
7279 else if (flags & GTK_STATE_FLAG_ACTIVE)
7280 return GTK_STATE_ACTIVE;
7281 else if (flags & GTK_STATE_FLAG_SELECTED)
7282 return GTK_STATE_SELECTED;
7283 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7284 return GTK_STATE_PRELIGHT;
7286 return GTK_STATE_NORMAL;
7290 * gtk_widget_set_visible:
7291 * @widget: a #GtkWidget
7292 * @visible: whether the widget should be shown or not
7294 * Sets the visibility state of @widget. Note that setting this to
7295 * %TRUE doesn't mean the widget is actually viewable, see
7296 * gtk_widget_get_visible().
7298 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7299 * but is nicer to use when the visibility of the widget depends on
7305 gtk_widget_set_visible (GtkWidget *widget,
7308 g_return_if_fail (GTK_IS_WIDGET (widget));
7310 if (visible != gtk_widget_get_visible (widget))
7313 gtk_widget_show (widget);
7315 gtk_widget_hide (widget);
7320 _gtk_widget_set_visible_flag (GtkWidget *widget,
7323 widget->priv->visible = visible;
7327 * gtk_widget_get_visible:
7328 * @widget: a #GtkWidget
7330 * Determines whether the widget is visible. Note that this doesn't
7331 * take into account whether the widget's parent is also visible
7332 * or the widget is obscured in any way.
7334 * See gtk_widget_set_visible().
7336 * Return value: %TRUE if the widget is visible
7341 gtk_widget_get_visible (GtkWidget *widget)
7343 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7345 return widget->priv->visible;
7349 * gtk_widget_set_has_window:
7350 * @widget: a #GtkWidget
7351 * @has_window: whether or not @widget has a window.
7353 * Specifies whether @widget has a #GdkWindow of its own. Note that
7354 * all realized widgets have a non-%NULL "window" pointer
7355 * (gtk_widget_get_window() never returns a %NULL window when a widget
7356 * is realized), but for many of them it's actually the #GdkWindow of
7357 * one of its parent widgets. Widgets that do not create a %window for
7358 * themselves in #GtkWidget::realize must announce this by
7359 * calling this function with @has_window = %FALSE.
7361 * This function should only be called by widget implementations,
7362 * and they should call it in their init() function.
7367 gtk_widget_set_has_window (GtkWidget *widget,
7368 gboolean has_window)
7370 g_return_if_fail (GTK_IS_WIDGET (widget));
7372 widget->priv->no_window = !has_window;
7376 * gtk_widget_get_has_window:
7377 * @widget: a #GtkWidget
7379 * Determines whether @widget has a #GdkWindow of its own. See
7380 * gtk_widget_set_has_window().
7382 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7387 gtk_widget_get_has_window (GtkWidget *widget)
7389 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7391 return ! widget->priv->no_window;
7395 * gtk_widget_is_toplevel:
7396 * @widget: a #GtkWidget
7398 * Determines whether @widget is a toplevel widget.
7400 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7401 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7404 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7409 gtk_widget_is_toplevel (GtkWidget *widget)
7411 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7413 return widget->priv->toplevel;
7417 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7418 gboolean is_toplevel)
7420 widget->priv->toplevel = is_toplevel;
7424 * gtk_widget_is_drawable:
7425 * @widget: a #GtkWidget
7427 * Determines whether @widget can be drawn to. A widget can be drawn
7428 * to if it is mapped and visible.
7430 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7435 gtk_widget_is_drawable (GtkWidget *widget)
7437 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7439 return (gtk_widget_get_visible (widget) &&
7440 gtk_widget_get_mapped (widget));
7444 * gtk_widget_get_realized:
7445 * @widget: a #GtkWidget
7447 * Determines whether @widget is realized.
7449 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7454 gtk_widget_get_realized (GtkWidget *widget)
7456 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7458 return widget->priv->realized;
7462 * gtk_widget_set_realized:
7463 * @widget: a #GtkWidget
7464 * @realized: %TRUE to mark the widget as realized
7466 * Marks the widget as being realized.
7468 * This function should only ever be called in a derived widget's
7469 * "realize" or "unrealize" implementation.
7474 gtk_widget_set_realized (GtkWidget *widget,
7477 g_return_if_fail (GTK_IS_WIDGET (widget));
7479 widget->priv->realized = realized;
7483 * gtk_widget_get_mapped:
7484 * @widget: a #GtkWidget
7486 * Whether the widget is mapped.
7488 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7493 gtk_widget_get_mapped (GtkWidget *widget)
7495 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7497 return widget->priv->mapped;
7501 * gtk_widget_set_mapped:
7502 * @widget: a #GtkWidget
7503 * @mapped: %TRUE to mark the widget as mapped
7505 * Marks the widget as being realized.
7507 * This function should only ever be called in a derived widget's
7508 * "map" or "unmap" implementation.
7513 gtk_widget_set_mapped (GtkWidget *widget,
7516 g_return_if_fail (GTK_IS_WIDGET (widget));
7518 widget->priv->mapped = mapped;
7522 * gtk_widget_set_app_paintable:
7523 * @widget: a #GtkWidget
7524 * @app_paintable: %TRUE if the application will paint on the widget
7526 * Sets whether the application intends to draw on the widget in
7527 * an #GtkWidget::draw handler.
7529 * This is a hint to the widget and does not affect the behavior of
7530 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7531 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7532 * the effect is to suppress default themed drawing of the widget's
7533 * background. (Children of the widget will still be drawn.) The application
7534 * is then entirely responsible for drawing the widget background.
7536 * Note that the background is still drawn when the widget is mapped.
7539 gtk_widget_set_app_paintable (GtkWidget *widget,
7540 gboolean app_paintable)
7542 g_return_if_fail (GTK_IS_WIDGET (widget));
7544 app_paintable = (app_paintable != FALSE);
7546 if (widget->priv->app_paintable != app_paintable)
7548 widget->priv->app_paintable = app_paintable;
7550 if (gtk_widget_is_drawable (widget))
7551 gtk_widget_queue_draw (widget);
7553 g_object_notify (G_OBJECT (widget), "app-paintable");
7558 * gtk_widget_get_app_paintable:
7559 * @widget: a #GtkWidget
7561 * Determines whether the application intends to draw on the widget in
7562 * an #GtkWidget::draw handler.
7564 * See gtk_widget_set_app_paintable()
7566 * Return value: %TRUE if the widget is app paintable
7571 gtk_widget_get_app_paintable (GtkWidget *widget)
7573 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7575 return widget->priv->app_paintable;
7579 * gtk_widget_set_double_buffered:
7580 * @widget: a #GtkWidget
7581 * @double_buffered: %TRUE to double-buffer a widget
7583 * Widgets are double buffered by default; you can use this function
7584 * to turn off the buffering. "Double buffered" simply means that
7585 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7586 * automatically around expose events sent to the
7587 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7588 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7589 * buffer to the screen. The result is that users see the window
7590 * update in one smooth step, and don't see individual graphics
7591 * primitives being rendered.
7593 * In very simple terms, double buffered widgets don't flicker,
7594 * so you would only use this function to turn off double buffering
7595 * if you had special needs and really knew what you were doing.
7597 * Note: if you turn off double-buffering, you have to handle
7598 * expose events, since even the clearing to the background color or
7599 * pixmap will not happen automatically (as it is done in
7600 * gdk_window_begin_paint()).
7603 gtk_widget_set_double_buffered (GtkWidget *widget,
7604 gboolean double_buffered)
7606 g_return_if_fail (GTK_IS_WIDGET (widget));
7608 double_buffered = (double_buffered != FALSE);
7610 if (widget->priv->double_buffered != double_buffered)
7612 widget->priv->double_buffered = double_buffered;
7614 g_object_notify (G_OBJECT (widget), "double-buffered");
7619 * gtk_widget_get_double_buffered:
7620 * @widget: a #GtkWidget
7622 * Determines whether the widget is double buffered.
7624 * See gtk_widget_set_double_buffered()
7626 * Return value: %TRUE if the widget is double buffered
7631 gtk_widget_get_double_buffered (GtkWidget *widget)
7633 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7635 return widget->priv->double_buffered;
7639 * gtk_widget_set_redraw_on_allocate:
7640 * @widget: a #GtkWidget
7641 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7642 * when it is allocated to a new size. Otherwise, only the
7643 * new portion of the widget will be redrawn.
7645 * Sets whether the entire widget is queued for drawing when its size
7646 * allocation changes. By default, this setting is %TRUE and
7647 * the entire widget is redrawn on every size change. If your widget
7648 * leaves the upper left unchanged when made bigger, turning this
7649 * setting off will improve performance.
7651 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7652 * off all allocation on resizing: the widget will not even redraw if
7653 * its position changes; this is to allow containers that don't draw
7654 * anything to avoid excess invalidations. If you set this flag on a
7655 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7656 * you are responsible for invalidating both the old and new allocation
7657 * of the widget when the widget is moved and responsible for invalidating
7658 * regions newly when the widget increases size.
7661 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7662 gboolean redraw_on_allocate)
7664 g_return_if_fail (GTK_IS_WIDGET (widget));
7666 widget->priv->redraw_on_alloc = redraw_on_allocate;
7670 * gtk_widget_set_sensitive:
7671 * @widget: a #GtkWidget
7672 * @sensitive: %TRUE to make the widget sensitive
7674 * Sets the sensitivity of a widget. A widget is sensitive if the user
7675 * can interact with it. Insensitive widgets are "grayed out" and the
7676 * user can't interact with them. Insensitive widgets are known as
7677 * "inactive", "disabled", or "ghosted" in some other toolkits.
7680 gtk_widget_set_sensitive (GtkWidget *widget,
7683 GtkWidgetPrivate *priv;
7685 g_return_if_fail (GTK_IS_WIDGET (widget));
7687 priv = widget->priv;
7689 sensitive = (sensitive != FALSE);
7691 if (priv->sensitive == sensitive)
7694 priv->sensitive = sensitive;
7696 if (priv->parent == NULL
7697 || gtk_widget_is_sensitive (priv->parent))
7701 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7704 data.operation = STATE_CHANGE_UNSET;
7706 data.operation = STATE_CHANGE_SET;
7708 gtk_widget_propagate_state (widget, &data);
7710 gtk_widget_queue_resize (widget);
7713 g_object_notify (G_OBJECT (widget), "sensitive");
7717 * gtk_widget_get_sensitive:
7718 * @widget: a #GtkWidget
7720 * Returns the widget's sensitivity (in the sense of returning
7721 * the value that has been set using gtk_widget_set_sensitive()).
7723 * The effective sensitivity of a widget is however determined by both its
7724 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7726 * Returns: %TRUE if the widget is sensitive
7731 gtk_widget_get_sensitive (GtkWidget *widget)
7733 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7735 return widget->priv->sensitive;
7739 * gtk_widget_is_sensitive:
7740 * @widget: a #GtkWidget
7742 * Returns the widget's effective sensitivity, which means
7743 * it is sensitive itself and also its parent widget is sensitive
7745 * Returns: %TRUE if the widget is effectively sensitive
7750 gtk_widget_is_sensitive (GtkWidget *widget)
7752 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7754 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
7758 _gtk_widget_update_path (GtkWidget *widget)
7760 if (widget->priv->path)
7762 gtk_widget_path_free (widget->priv->path);
7763 widget->priv->path = NULL;
7766 gtk_widget_get_path (widget);
7770 * gtk_widget_set_parent:
7771 * @widget: a #GtkWidget
7772 * @parent: parent container
7774 * This function is useful only when implementing subclasses of
7776 * Sets the container as the parent of @widget, and takes care of
7777 * some details such as updating the state and style of the child
7778 * to reflect its new location. The opposite function is
7779 * gtk_widget_unparent().
7782 gtk_widget_set_parent (GtkWidget *widget,
7785 GtkStateFlags parent_flags;
7786 GtkWidgetPrivate *priv;
7789 g_return_if_fail (GTK_IS_WIDGET (widget));
7790 g_return_if_fail (GTK_IS_WIDGET (parent));
7791 g_return_if_fail (widget != parent);
7793 priv = widget->priv;
7795 if (priv->parent != NULL)
7797 g_warning ("Can't set a parent on widget which has a parent\n");
7800 if (gtk_widget_is_toplevel (widget))
7802 g_warning ("Can't set a parent on a toplevel widget\n");
7806 /* keep this function in sync with gtk_menu_attach_to_widget()
7809 g_object_ref_sink (widget);
7811 gtk_widget_push_verify_invariants (widget);
7813 priv->parent = parent;
7815 parent_flags = gtk_widget_get_state_flags (parent);
7817 /* Merge both old state and current parent state,
7818 * making sure to only propagate the right states */
7819 data.flags = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
7820 data.flags |= priv->state_flags;
7822 data.operation = STATE_CHANGE_REPLACE;
7823 gtk_widget_propagate_state (widget, &data);
7826 gtk_style_context_set_parent (priv->context,
7827 gtk_widget_get_style_context (parent));
7828 gtk_widget_reset_style (widget);
7830 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7831 if (priv->parent->priv->anchored)
7832 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7833 g_object_notify (G_OBJECT (widget), "parent");
7835 /* Enforce realized/mapped invariants
7837 if (gtk_widget_get_realized (priv->parent))
7838 gtk_widget_realize (widget);
7840 if (gtk_widget_get_visible (priv->parent) &&
7841 gtk_widget_get_visible (widget))
7843 if (gtk_widget_get_child_visible (widget) &&
7844 gtk_widget_get_mapped (priv->parent))
7845 gtk_widget_map (widget);
7847 gtk_widget_queue_resize (widget);
7850 /* child may cause parent's expand to change, if the child is
7851 * expanded. If child is not expanded, then it can't modify the
7852 * parent's expand. If the child becomes expanded later then it will
7853 * queue compute_expand then. This optimization plus defaulting
7854 * newly-constructed widgets to need_compute_expand=FALSE should
7855 * mean that initially building a widget tree doesn't have to keep
7856 * walking up setting need_compute_expand on parents over and over.
7858 * We can't change a parent to need to expand unless we're visible.
7860 if (gtk_widget_get_visible (widget) &&
7861 (priv->need_compute_expand ||
7862 priv->computed_hexpand ||
7863 priv->computed_vexpand))
7865 gtk_widget_queue_compute_expand (parent);
7868 gtk_widget_pop_verify_invariants (widget);
7872 * gtk_widget_get_parent:
7873 * @widget: a #GtkWidget
7875 * Returns the parent container of @widget.
7877 * Return value: (transfer none): the parent container of @widget, or %NULL
7880 gtk_widget_get_parent (GtkWidget *widget)
7882 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7884 return widget->priv->parent;
7888 modifier_style_changed (GtkModifierStyle *style,
7891 GtkStyleContext *context;
7893 context = gtk_widget_get_style_context (widget);
7894 gtk_style_context_invalidate (context);
7897 static GtkModifierStyle *
7898 _gtk_widget_get_modifier_properties (GtkWidget *widget)
7900 GtkModifierStyle *style;
7902 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
7904 if (G_UNLIKELY (!style))
7906 GtkStyleContext *context;
7908 style = _gtk_modifier_style_new ();
7909 g_object_set_qdata_full (G_OBJECT (widget),
7910 quark_modifier_style,
7912 (GDestroyNotify) g_object_unref);
7914 g_signal_connect (style, "changed",
7915 G_CALLBACK (modifier_style_changed), widget);
7917 context = gtk_widget_get_style_context (widget);
7919 gtk_style_context_add_provider (context,
7920 GTK_STYLE_PROVIDER (style),
7921 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
7928 * gtk_widget_override_color:
7929 * @widget: a #GtkWidget
7930 * @state: the state for which to set the color
7931 * @color: (allow-none): the color to assign, or %NULL to undo the effect
7932 * of previous calls to gtk_widget_override_color()
7934 * Sets the color to use for a widget.
7936 * All other style values are left untouched.
7939 * This API is mostly meant as a quick way for applications to
7940 * change a widget appearance. If you are developing a widgets
7941 * library and intend this change to be themeable, it is better
7942 * done by setting meaningful CSS classes and regions in your
7943 * widget/container implementation through gtk_style_context_add_class()
7944 * and gtk_style_context_add_region().
7946 * This way, your widget library can install a #GtkCssProvider
7947 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
7948 * to provide a default styling for those widgets that need so, and
7949 * this theming may fully overridden by the user's theme.
7952 * Note that for complex widgets this may bring in undesired
7953 * results (such as uniform background color everywhere), in
7954 * these cases it is better to fully style such widgets through a
7955 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
7962 gtk_widget_override_color (GtkWidget *widget,
7963 GtkStateFlags state,
7964 const GdkRGBA *color)
7966 GtkModifierStyle *style;
7968 g_return_if_fail (GTK_IS_WIDGET (widget));
7970 style = _gtk_widget_get_modifier_properties (widget);
7971 _gtk_modifier_style_set_color (style, state, color);
7975 * gtk_widget_override_background_color:
7976 * @widget: a #GtkWidget
7977 * @state: the state for which to set the background color
7978 * @color: (allow-none): the color to assign, or %NULL to undo the effect
7979 * of previous calls to gtk_widget_override_background_color()
7981 * Sets the background color to use for a widget.
7983 * All other style values are left untouched.
7984 * See gtk_widget_override_color().
7989 gtk_widget_override_background_color (GtkWidget *widget,
7990 GtkStateFlags state,
7991 const GdkRGBA *color)
7993 GtkModifierStyle *style;
7995 g_return_if_fail (GTK_IS_WIDGET (widget));
7997 style = _gtk_widget_get_modifier_properties (widget);
7998 _gtk_modifier_style_set_background_color (style, state, color);
8002 * gtk_widget_override_font:
8003 * @widget: a #GtkWidget
8004 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
8005 * the effect of previous calls to gtk_widget_override_font()
8007 * Sets the font to use for a widget. All other style values are
8008 * left untouched. See gtk_widget_override_color().
8013 gtk_widget_override_font (GtkWidget *widget,
8014 const PangoFontDescription *font_desc)
8016 GtkModifierStyle *style;
8018 g_return_if_fail (GTK_IS_WIDGET (widget));
8020 style = _gtk_widget_get_modifier_properties (widget);
8021 _gtk_modifier_style_set_font (style, font_desc);
8025 * gtk_widget_override_symbolic_color:
8026 * @widget: a #GtkWidget
8027 * @name: the name of the symbolic color to modify
8028 * @color: (allow-none): the color to assign (does not need
8029 * to be allocated), or %NULL to undo the effect of previous
8030 * calls to gtk_widget_override_symbolic_color()
8032 * Sets a symbolic color for a widget.
8034 * All other style values are left untouched.
8035 * See gtk_widget_override_color() for overriding the foreground
8036 * or background color.
8041 gtk_widget_override_symbolic_color (GtkWidget *widget,
8043 const GdkRGBA *color)
8045 GtkModifierStyle *style;
8047 g_return_if_fail (GTK_IS_WIDGET (widget));
8049 style = _gtk_widget_get_modifier_properties (widget);
8050 _gtk_modifier_style_map_color (style, name, color);
8054 * gtk_widget_override_cursor:
8055 * @widget: a #GtkWidget
8056 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8057 * allocated), or %NULL to undo the effect of previous calls to
8058 * of gtk_widget_override_cursor().
8059 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8060 * need to be allocated), or %NULL to undo the effect of previous
8061 * calls to of gtk_widget_override_cursor().
8063 * Sets the cursor color to use in a widget, overriding the
8064 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8065 * style properties. All other style values are left untouched.
8066 * See also gtk_widget_modify_style().
8068 * Note that the underlying properties have the #GdkColor type,
8069 * so the alpha value in @primary and @secondary will be ignored.
8074 gtk_widget_override_cursor (GtkWidget *widget,
8075 const GdkRGBA *cursor,
8076 const GdkRGBA *secondary_cursor)
8078 GtkModifierStyle *style;
8080 g_return_if_fail (GTK_IS_WIDGET (widget));
8082 style = _gtk_widget_get_modifier_properties (widget);
8083 _gtk_modifier_style_set_color_property (style,
8085 "cursor-color", cursor);
8086 _gtk_modifier_style_set_color_property (style,
8088 "secondary-cursor-color",
8093 gtk_widget_real_direction_changed (GtkWidget *widget,
8094 GtkTextDirection previous_direction)
8096 gtk_widget_queue_resize (widget);
8100 gtk_widget_real_style_set (GtkWidget *widget,
8101 GtkStyle *previous_style)
8106 GtkWidget *previous_toplevel;
8107 GdkScreen *previous_screen;
8108 GdkScreen *new_screen;
8109 } HierarchyChangedInfo;
8112 do_screen_change (GtkWidget *widget,
8113 GdkScreen *old_screen,
8114 GdkScreen *new_screen)
8116 if (old_screen != new_screen)
8118 GtkWidgetPrivate *priv = widget->priv;
8122 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8124 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8127 _gtk_tooltip_hide (widget);
8129 if (new_screen && priv->context)
8130 gtk_style_context_set_screen (priv->context, new_screen);
8132 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8137 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8138 gpointer client_data)
8140 GtkWidgetPrivate *priv = widget->priv;
8141 HierarchyChangedInfo *info = client_data;
8142 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8143 (priv->parent && priv->parent->priv->anchored);
8145 if (priv->anchored != new_anchored)
8147 g_object_ref (widget);
8149 priv->anchored = new_anchored;
8151 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8152 do_screen_change (widget, info->previous_screen, info->new_screen);
8154 if (GTK_IS_CONTAINER (widget))
8155 gtk_container_forall (GTK_CONTAINER (widget),
8156 gtk_widget_propagate_hierarchy_changed_recurse,
8159 g_object_unref (widget);
8164 * _gtk_widget_propagate_hierarchy_changed:
8165 * @widget: a #GtkWidget
8166 * @previous_toplevel: Previous toplevel
8168 * Propagates changes in the anchored state to a widget and all
8169 * children, unsetting or setting the %ANCHORED flag, and
8170 * emitting #GtkWidget::hierarchy-changed.
8173 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8174 GtkWidget *previous_toplevel)
8176 GtkWidgetPrivate *priv = widget->priv;
8177 HierarchyChangedInfo info;
8179 info.previous_toplevel = previous_toplevel;
8180 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8182 if (gtk_widget_is_toplevel (widget) ||
8183 (priv->parent && priv->parent->priv->anchored))
8184 info.new_screen = gtk_widget_get_screen (widget);
8186 info.new_screen = NULL;
8188 if (info.previous_screen)
8189 g_object_ref (info.previous_screen);
8190 if (previous_toplevel)
8191 g_object_ref (previous_toplevel);
8193 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8195 if (previous_toplevel)
8196 g_object_unref (previous_toplevel);
8197 if (info.previous_screen)
8198 g_object_unref (info.previous_screen);
8202 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8203 gpointer client_data)
8205 HierarchyChangedInfo *info = client_data;
8207 g_object_ref (widget);
8209 do_screen_change (widget, info->previous_screen, info->new_screen);
8211 if (GTK_IS_CONTAINER (widget))
8212 gtk_container_forall (GTK_CONTAINER (widget),
8213 gtk_widget_propagate_screen_changed_recurse,
8216 g_object_unref (widget);
8220 * gtk_widget_is_composited:
8221 * @widget: a #GtkWidget
8223 * Whether @widget can rely on having its alpha channel
8224 * drawn correctly. On X11 this function returns whether a
8225 * compositing manager is running for @widget's screen.
8227 * Please note that the semantics of this call will change
8228 * in the future if used on a widget that has a composited
8229 * window in its hierarchy (as set by gdk_window_set_composited()).
8231 * Return value: %TRUE if the widget can rely on its alpha
8232 * channel being drawn correctly.
8237 gtk_widget_is_composited (GtkWidget *widget)
8241 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8243 screen = gtk_widget_get_screen (widget);
8245 return gdk_screen_is_composited (screen);
8249 propagate_composited_changed (GtkWidget *widget,
8252 if (GTK_IS_CONTAINER (widget))
8254 gtk_container_forall (GTK_CONTAINER (widget),
8255 propagate_composited_changed,
8259 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8263 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8265 propagate_composited_changed (widget, NULL);
8269 * _gtk_widget_propagate_screen_changed:
8270 * @widget: a #GtkWidget
8271 * @previous_screen: Previous screen
8273 * Propagates changes in the screen for a widget to all
8274 * children, emitting #GtkWidget::screen-changed.
8277 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8278 GdkScreen *previous_screen)
8280 HierarchyChangedInfo info;
8282 info.previous_screen = previous_screen;
8283 info.new_screen = gtk_widget_get_screen (widget);
8285 if (previous_screen)
8286 g_object_ref (previous_screen);
8288 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8290 if (previous_screen)
8291 g_object_unref (previous_screen);
8295 reset_style_recurse (GtkWidget *widget, gpointer data)
8297 _gtk_widget_update_path (widget);
8299 if (GTK_IS_CONTAINER (widget))
8300 gtk_container_forall (GTK_CONTAINER (widget),
8301 reset_style_recurse,
8306 * gtk_widget_reset_style:
8307 * @widget: a #GtkWidget
8309 * Updates the style context of @widget and all descendents
8310 * by updating its widget path. #GtkContainer<!-- -->s may want
8311 * to use this on a child when reordering it in a way that a different
8312 * style might apply to it. See also gtk_container_get_path_for_child().
8317 gtk_widget_reset_style (GtkWidget *widget)
8319 g_return_if_fail (GTK_IS_WIDGET (widget));
8321 reset_style_recurse (widget, NULL);
8323 g_list_foreach (widget->priv->attached_windows,
8324 (GFunc) reset_style_recurse, NULL);
8327 #ifdef G_ENABLE_DEBUG
8329 /* Verify invariants, see docs/widget_system.txt for notes on much of
8330 * this. Invariants may be temporarily broken while we're in the
8331 * process of updating state, of course, so you can only
8332 * verify_invariants() after a given operation is complete.
8333 * Use push/pop_verify_invariants to help with that.
8336 gtk_widget_verify_invariants (GtkWidget *widget)
8340 if (widget->priv->verifying_invariants_count > 0)
8343 parent = widget->priv->parent;
8345 if (widget->priv->mapped)
8347 /* Mapped implies ... */
8349 if (!widget->priv->realized)
8350 g_warning ("%s %p is mapped but not realized",
8351 G_OBJECT_TYPE_NAME (widget), widget);
8353 if (!widget->priv->visible)
8354 g_warning ("%s %p is mapped but not visible",
8355 G_OBJECT_TYPE_NAME (widget), widget);
8357 if (!widget->priv->toplevel)
8359 if (!widget->priv->child_visible)
8360 g_warning ("%s %p is mapped but not child_visible",
8361 G_OBJECT_TYPE_NAME (widget), widget);
8366 /* Not mapped implies... */
8369 /* This check makes sense for normal toplevels, but for
8370 * something like a toplevel that is embedded within a clutter
8371 * state, mapping may depend on external factors.
8373 if (widget->priv->toplevel)
8375 if (widget->priv->visible)
8376 g_warning ("%s %p toplevel is visible but not mapped",
8377 G_OBJECT_TYPE_NAME (widget), widget);
8382 /* Parent related checks aren't possible if parent has
8383 * verifying_invariants_count > 0 because parent needs to recurse
8384 * children first before the invariants will hold.
8386 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8389 parent->priv->realized)
8391 /* Parent realized implies... */
8394 /* This is in widget_system.txt but appears to fail
8395 * because there's no gtk_container_realize() that
8396 * realizes all children... instead we just lazily
8397 * wait for map to fix things up.
8399 if (!widget->priv->realized)
8400 g_warning ("%s %p is realized but child %s %p is not realized",
8401 G_OBJECT_TYPE_NAME (parent), parent,
8402 G_OBJECT_TYPE_NAME (widget), widget);
8405 else if (!widget->priv->toplevel)
8407 /* No parent or parent not realized on non-toplevel implies... */
8409 if (widget->priv->realized && !widget->priv->in_reparent)
8410 g_warning ("%s %p is not realized but child %s %p is realized",
8411 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8412 G_OBJECT_TYPE_NAME (widget), widget);
8416 parent->priv->mapped &&
8417 widget->priv->visible &&
8418 widget->priv->child_visible)
8420 /* Parent mapped and we are visible implies... */
8422 if (!widget->priv->mapped)
8423 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8424 G_OBJECT_TYPE_NAME (parent), parent,
8425 G_OBJECT_TYPE_NAME (widget), widget);
8427 else if (!widget->priv->toplevel)
8429 /* No parent or parent not mapped on non-toplevel implies... */
8431 if (widget->priv->mapped && !widget->priv->in_reparent)
8432 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8433 G_OBJECT_TYPE_NAME (widget), widget,
8434 widget->priv->visible,
8435 widget->priv->child_visible,
8436 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8437 parent ? parent->priv->mapped : FALSE);
8441 if (!widget->priv->realized)
8443 /* Not realized implies... */
8446 /* widget_system.txt says these hold, but they don't. */
8447 if (widget->priv->resize_pending)
8448 g_warning ("%s %p resize pending but not realized",
8449 G_OBJECT_TYPE_NAME (widget), widget);
8451 if (widget->priv->alloc_needed)
8452 g_warning ("%s %p alloc needed but not realized",
8453 G_OBJECT_TYPE_NAME (widget), widget);
8455 if (widget->priv->width_request_needed)
8456 g_warning ("%s %p width request needed but not realized",
8457 G_OBJECT_TYPE_NAME (widget), widget);
8459 if (widget->priv->height_request_needed)
8460 g_warning ("%s %p height request needed but not realized",
8461 G_OBJECT_TYPE_NAME (widget), widget);
8466 /* The point of this push/pop is that invariants may not hold while
8467 * we're busy making changes. So we only check at the outermost call
8468 * on the call stack, after we finish updating everything.
8471 gtk_widget_push_verify_invariants (GtkWidget *widget)
8473 widget->priv->verifying_invariants_count += 1;
8477 gtk_widget_verify_child_invariants (GtkWidget *widget,
8478 gpointer client_data)
8480 /* We don't recurse further; this is a one-level check. */
8481 gtk_widget_verify_invariants (widget);
8485 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8487 g_assert (widget->priv->verifying_invariants_count > 0);
8489 widget->priv->verifying_invariants_count -= 1;
8491 if (widget->priv->verifying_invariants_count == 0)
8493 gtk_widget_verify_invariants (widget);
8495 if (GTK_IS_CONTAINER (widget))
8497 /* Check one level of children, because our
8498 * push_verify_invariants() will have prevented some of the
8499 * checks. This does not recurse because if recursion is
8500 * needed, it will happen naturally as each child has a
8501 * push/pop on that child. For example if we're recursively
8502 * mapping children, we'll push/pop on each child as we map
8505 gtk_container_forall (GTK_CONTAINER (widget),
8506 gtk_widget_verify_child_invariants,
8511 #endif /* G_ENABLE_DEBUG */
8513 static PangoContext *
8514 gtk_widget_peek_pango_context (GtkWidget *widget)
8516 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8520 * gtk_widget_get_pango_context:
8521 * @widget: a #GtkWidget
8523 * Gets a #PangoContext with the appropriate font map, font description,
8524 * and base direction for this widget. Unlike the context returned
8525 * by gtk_widget_create_pango_context(), this context is owned by
8526 * the widget (it can be used until the screen for the widget changes
8527 * or the widget is removed from its toplevel), and will be updated to
8528 * match any changes to the widget's attributes.
8530 * If you create and keep a #PangoLayout using this context, you must
8531 * deal with changes to the context by calling pango_layout_context_changed()
8532 * on the layout in response to the #GtkWidget::style-updated and
8533 * #GtkWidget::direction-changed signals for the widget.
8535 * Return value: (transfer none): the #PangoContext for the widget.
8538 gtk_widget_get_pango_context (GtkWidget *widget)
8540 PangoContext *context;
8542 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8544 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8547 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8548 g_object_set_qdata_full (G_OBJECT (widget),
8549 quark_pango_context,
8558 update_pango_context (GtkWidget *widget,
8559 PangoContext *context)
8561 const PangoFontDescription *font_desc;
8562 GtkStyleContext *style_context;
8564 style_context = gtk_widget_get_style_context (widget);
8566 font_desc = gtk_style_context_get_font (style_context,
8567 gtk_widget_get_state_flags (widget));
8569 pango_context_set_font_description (context, font_desc);
8570 pango_context_set_base_dir (context,
8571 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8572 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8576 gtk_widget_update_pango_context (GtkWidget *widget)
8578 PangoContext *context = gtk_widget_peek_pango_context (widget);
8584 update_pango_context (widget, context);
8586 screen = gtk_widget_get_screen_unchecked (widget);
8589 pango_cairo_context_set_resolution (context,
8590 gdk_screen_get_resolution (screen));
8591 pango_cairo_context_set_font_options (context,
8592 gdk_screen_get_font_options (screen));
8598 * gtk_widget_create_pango_context:
8599 * @widget: a #GtkWidget
8601 * Creates a new #PangoContext with the appropriate font map,
8602 * font description, and base direction for drawing text for
8603 * this widget. See also gtk_widget_get_pango_context().
8605 * Return value: (transfer full): the new #PangoContext
8608 gtk_widget_create_pango_context (GtkWidget *widget)
8611 PangoContext *context;
8613 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8615 screen = gtk_widget_get_screen_unchecked (widget);
8618 GTK_NOTE (MULTIHEAD,
8619 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8621 screen = gdk_screen_get_default ();
8624 context = gdk_pango_context_get_for_screen (screen);
8626 update_pango_context (widget, context);
8627 pango_context_set_language (context, gtk_get_default_language ());
8633 * gtk_widget_create_pango_layout:
8634 * @widget: a #GtkWidget
8635 * @text: text to set on the layout (can be %NULL)
8637 * Creates a new #PangoLayout with the appropriate font map,
8638 * font description, and base direction for drawing text for
8641 * If you keep a #PangoLayout created in this way around, in order to
8642 * notify the layout of changes to the base direction or font of this
8643 * widget, you must call pango_layout_context_changed() in response to
8644 * the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
8647 * Return value: (transfer full): the new #PangoLayout
8650 gtk_widget_create_pango_layout (GtkWidget *widget,
8653 PangoLayout *layout;
8654 PangoContext *context;
8656 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8658 context = gtk_widget_get_pango_context (widget);
8659 layout = pango_layout_new (context);
8662 pango_layout_set_text (layout, text, -1);
8668 * gtk_widget_render_icon_pixbuf:
8669 * @widget: a #GtkWidget
8670 * @stock_id: a stock ID
8671 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8672 * render at the size of the source and don't scale (if there are
8673 * multiple source sizes, GTK+ picks one of the available sizes).
8675 * A convenience function that uses the theme engine and style
8676 * settings for @widget to look up @stock_id and render it to
8677 * a pixbuf. @stock_id should be a stock icon ID such as
8678 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8679 * such as #GTK_ICON_SIZE_MENU.
8681 * The pixels in the returned #GdkPixbuf are shared with the rest of
8682 * the application and should not be modified. The pixbuf should be freed
8683 * after use with g_object_unref().
8685 * Return value: (transfer full): a new pixbuf, or %NULL if the
8686 * stock ID wasn't known
8691 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
8692 const gchar *stock_id,
8695 GtkStyleContext *context;
8696 GtkIconSet *icon_set;
8698 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8699 g_return_val_if_fail (stock_id != NULL, NULL);
8700 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8702 context = gtk_widget_get_style_context (widget);
8703 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
8705 if (icon_set == NULL)
8708 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
8712 * gtk_widget_set_parent_window:
8713 * @widget: a #GtkWidget.
8714 * @parent_window: the new parent window.
8716 * Sets a non default parent window for @widget.
8718 * For GtkWindow classes, setting a @parent_window effects whether
8719 * the window is a toplevel window or can be embedded into other
8723 * For GtkWindow classes, this needs to be called before the
8724 * window is realized.
8729 gtk_widget_set_parent_window (GtkWidget *widget,
8730 GdkWindow *parent_window)
8732 GdkWindow *old_parent_window;
8734 g_return_if_fail (GTK_IS_WIDGET (widget));
8736 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8737 quark_parent_window);
8739 if (parent_window != old_parent_window)
8743 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8745 if (old_parent_window)
8746 g_object_unref (old_parent_window);
8748 g_object_ref (parent_window);
8750 /* Unset toplevel flag when adding a parent window to a widget,
8751 * this is the primary entry point to allow toplevels to be
8754 #ifdef GDK_WINDOWING_X11
8755 is_plug = GTK_IS_PLUG (widget);
8759 if (GTK_IS_WINDOW (widget) && !is_plug)
8760 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
8765 * gtk_widget_get_parent_window:
8766 * @widget: a #GtkWidget.
8768 * Gets @widget's parent window.
8770 * Returns: (transfer none): the parent window of @widget.
8773 gtk_widget_get_parent_window (GtkWidget *widget)
8775 GtkWidgetPrivate *priv;
8776 GdkWindow *parent_window;
8778 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8780 priv = widget->priv;
8782 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8784 return (parent_window != NULL) ? parent_window :
8785 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8790 * gtk_widget_set_child_visible:
8791 * @widget: a #GtkWidget
8792 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8794 * Sets whether @widget should be mapped along with its when its parent
8795 * is mapped and @widget has been shown with gtk_widget_show().
8797 * The child visibility can be set for widget before it is added to
8798 * a container with gtk_widget_set_parent(), to avoid mapping
8799 * children unnecessary before immediately unmapping them. However
8800 * it will be reset to its default state of %TRUE when the widget
8801 * is removed from a container.
8803 * Note that changing the child visibility of a widget does not
8804 * queue a resize on the widget. Most of the time, the size of
8805 * a widget is computed from all visible children, whether or
8806 * not they are mapped. If this is not the case, the container
8807 * can queue a resize itself.
8809 * This function is only useful for container implementations and
8810 * never should be called by an application.
8813 gtk_widget_set_child_visible (GtkWidget *widget,
8814 gboolean is_visible)
8816 GtkWidgetPrivate *priv;
8818 g_return_if_fail (GTK_IS_WIDGET (widget));
8819 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8821 priv = widget->priv;
8823 g_object_ref (widget);
8824 gtk_widget_verify_invariants (widget);
8827 priv->child_visible = TRUE;
8830 GtkWidget *toplevel;
8832 priv->child_visible = FALSE;
8834 toplevel = gtk_widget_get_toplevel (widget);
8835 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8836 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8839 if (priv->parent && gtk_widget_get_realized (priv->parent))
8841 if (gtk_widget_get_mapped (priv->parent) &&
8842 priv->child_visible &&
8843 gtk_widget_get_visible (widget))
8844 gtk_widget_map (widget);
8846 gtk_widget_unmap (widget);
8849 gtk_widget_verify_invariants (widget);
8850 g_object_unref (widget);
8854 * gtk_widget_get_child_visible:
8855 * @widget: a #GtkWidget
8857 * Gets the value set with gtk_widget_set_child_visible().
8858 * If you feel a need to use this function, your code probably
8859 * needs reorganization.
8861 * This function is only useful for container implementations and
8862 * never should be called by an application.
8864 * Return value: %TRUE if the widget is mapped with the parent.
8867 gtk_widget_get_child_visible (GtkWidget *widget)
8869 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8871 return widget->priv->child_visible;
8875 gtk_widget_get_screen_unchecked (GtkWidget *widget)
8877 GtkWidget *toplevel;
8879 toplevel = gtk_widget_get_toplevel (widget);
8881 if (gtk_widget_is_toplevel (toplevel))
8883 if (GTK_IS_WINDOW (toplevel))
8884 return gtk_window_get_screen (GTK_WINDOW (toplevel));
8885 else if (GTK_IS_INVISIBLE (toplevel))
8886 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
8893 * gtk_widget_get_screen:
8894 * @widget: a #GtkWidget
8896 * Get the #GdkScreen from the toplevel window associated with
8897 * this widget. This function can only be called after the widget
8898 * has been added to a widget hierarchy with a #GtkWindow
8901 * In general, you should only create screen specific
8902 * resources when a widget has been realized, and you should
8903 * free those resources when the widget is unrealized.
8905 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
8910 gtk_widget_get_screen (GtkWidget *widget)
8914 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8916 screen = gtk_widget_get_screen_unchecked (widget);
8923 g_warning (G_STRLOC ": Can't get associated screen"
8924 " for a widget unless it is inside a toplevel GtkWindow\n"
8925 " widget type is %s associated top level type is %s",
8926 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
8927 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
8929 return gdk_screen_get_default ();
8934 * gtk_widget_has_screen:
8935 * @widget: a #GtkWidget
8937 * Checks whether there is a #GdkScreen is associated with
8938 * this widget. All toplevel widgets have an associated
8939 * screen, and all widgets added into a hierarchy with a toplevel
8940 * window at the top.
8942 * Return value: %TRUE if there is a #GdkScreen associcated
8948 gtk_widget_has_screen (GtkWidget *widget)
8950 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8952 return (gtk_widget_get_screen_unchecked (widget) != NULL);
8956 * gtk_widget_get_display:
8957 * @widget: a #GtkWidget
8959 * Get the #GdkDisplay for the toplevel window associated with
8960 * this widget. This function can only be called after the widget
8961 * has been added to a widget hierarchy with a #GtkWindow at the top.
8963 * In general, you should only create display specific
8964 * resources when a widget has been realized, and you should
8965 * free those resources when the widget is unrealized.
8967 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
8972 gtk_widget_get_display (GtkWidget *widget)
8974 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8976 return gdk_screen_get_display (gtk_widget_get_screen (widget));
8980 * gtk_widget_get_root_window:
8981 * @widget: a #GtkWidget
8983 * Get the root window where this widget is located. This function can
8984 * only be called after the widget has been added to a widget
8985 * hierarchy with #GtkWindow at the top.
8987 * The root window is useful for such purposes as creating a popup
8988 * #GdkWindow associated with the window. In general, you should only
8989 * create display specific resources when a widget has been realized,
8990 * and you should free those resources when the widget is unrealized.
8992 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
8997 gtk_widget_get_root_window (GtkWidget *widget)
8999 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9001 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9005 * gtk_widget_child_focus:
9006 * @widget: a #GtkWidget
9007 * @direction: direction of focus movement
9009 * This function is used by custom widget implementations; if you're
9010 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9011 * to a particular widget, and gtk_container_set_focus_chain() to
9012 * change the focus tab order. So you may want to investigate those
9013 * functions instead.
9015 * gtk_widget_child_focus() is called by containers as the user moves
9016 * around the window using keyboard shortcuts. @direction indicates
9017 * what kind of motion is taking place (up, down, left, right, tab
9018 * forward, tab backward). gtk_widget_child_focus() emits the
9019 * #GtkWidget::focus signal; widgets override the default handler
9020 * for this signal in order to implement appropriate focus behavior.
9022 * The default ::focus handler for a widget should return %TRUE if
9023 * moving in @direction left the focus on a focusable location inside
9024 * that widget, and %FALSE if moving in @direction moved the focus
9025 * outside the widget. If returning %TRUE, widgets normally
9026 * call gtk_widget_grab_focus() to place the focus accordingly;
9027 * if returning %FALSE, they don't modify the current focus location.
9029 * Return value: %TRUE if focus ended up inside @widget
9032 gtk_widget_child_focus (GtkWidget *widget,
9033 GtkDirectionType direction)
9035 gboolean return_val;
9037 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9039 if (!gtk_widget_get_visible (widget) ||
9040 !gtk_widget_is_sensitive (widget))
9043 /* child widgets must set CAN_FOCUS, containers
9044 * don't have to though.
9046 if (!GTK_IS_CONTAINER (widget) &&
9047 !gtk_widget_get_can_focus (widget))
9050 g_signal_emit (widget,
9051 widget_signals[FOCUS],
9053 direction, &return_val);
9059 * gtk_widget_keynav_failed:
9060 * @widget: a #GtkWidget
9061 * @direction: direction of focus movement
9063 * This function should be called whenever keyboard navigation within
9064 * a single widget hits a boundary. The function emits the
9065 * #GtkWidget::keynav-failed signal on the widget and its return
9066 * value should be interpreted in a way similar to the return value of
9067 * gtk_widget_child_focus():
9069 * When %TRUE is returned, stay in the widget, the failed keyboard
9070 * navigation is Ok and/or there is nowhere we can/should move the
9073 * When %FALSE is returned, the caller should continue with keyboard
9074 * navigation outside the widget, e.g. by calling
9075 * gtk_widget_child_focus() on the widget's toplevel.
9077 * The default ::keynav-failed handler returns %TRUE for
9078 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9079 * values of #GtkDirectionType, it looks at the
9080 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9081 * if the setting is %TRUE. This way the entire user interface
9082 * becomes cursor-navigatable on input devices such as mobile phones
9083 * which only have cursor keys but no tab key.
9085 * Whenever the default handler returns %TRUE, it also calls
9086 * gtk_widget_error_bell() to notify the user of the failed keyboard
9089 * A use case for providing an own implementation of ::keynav-failed
9090 * (either by connecting to it or by overriding it) would be a row of
9091 * #GtkEntry widgets where the user should be able to navigate the
9092 * entire row with the cursor keys, as e.g. known from user interfaces
9093 * that require entering license keys.
9095 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9096 * if the emitting widget should try to handle the keyboard
9097 * navigation attempt in its parent container(s).
9102 gtk_widget_keynav_failed (GtkWidget *widget,
9103 GtkDirectionType direction)
9105 gboolean return_val;
9107 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9109 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9110 direction, &return_val);
9116 * gtk_widget_error_bell:
9117 * @widget: a #GtkWidget
9119 * Notifies the user about an input-related error on this widget.
9120 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9121 * gdk_window_beep(), otherwise it does nothing.
9123 * Note that the effect of gdk_window_beep() can be configured in many
9124 * ways, depending on the windowing backend and the desktop environment
9125 * or window manager that is used.
9130 gtk_widget_error_bell (GtkWidget *widget)
9132 GtkWidgetPrivate *priv;
9133 GtkSettings* settings;
9136 g_return_if_fail (GTK_IS_WIDGET (widget));
9138 priv = widget->priv;
9140 settings = gtk_widget_get_settings (widget);
9144 g_object_get (settings,
9145 "gtk-error-bell", &beep,
9148 if (beep && priv->window)
9149 gdk_window_beep (priv->window);
9153 gtk_widget_set_usize_internal (GtkWidget *widget,
9156 GtkQueueResizeFlags flags)
9158 GtkWidgetAuxInfo *aux_info;
9159 gboolean changed = FALSE;
9161 g_object_freeze_notify (G_OBJECT (widget));
9163 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9165 if (width > -2 && aux_info->width != width)
9167 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9168 g_object_notify (G_OBJECT (widget), "width-request");
9169 aux_info->width = width;
9172 if (height > -2 && aux_info->height != height)
9174 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9175 g_object_notify (G_OBJECT (widget), "height-request");
9176 aux_info->height = height;
9180 if (gtk_widget_get_visible (widget) && changed)
9182 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9183 gtk_widget_queue_resize (widget);
9185 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9188 g_object_thaw_notify (G_OBJECT (widget));
9192 * gtk_widget_set_size_request:
9193 * @widget: a #GtkWidget
9194 * @width: width @widget should request, or -1 to unset
9195 * @height: height @widget should request, or -1 to unset
9197 * Sets the minimum size of a widget; that is, the widget's size
9198 * request will be @width by @height. You can use this function to
9199 * force a widget to be either larger or smaller than it normally
9202 * In most cases, gtk_window_set_default_size() is a better choice for
9203 * toplevel windows than this function; setting the default size will
9204 * still allow users to shrink the window. Setting the size request
9205 * will force them to leave the window at least as large as the size
9206 * request. When dealing with window sizes,
9207 * gtk_window_set_geometry_hints() can be a useful function as well.
9209 * Note the inherent danger of setting any fixed size - themes,
9210 * translations into other languages, different fonts, and user action
9211 * can all change the appropriate size for a given widget. So, it's
9212 * basically impossible to hardcode a size that will always be
9215 * The size request of a widget is the smallest size a widget can
9216 * accept while still functioning well and drawing itself correctly.
9217 * However in some strange cases a widget may be allocated less than
9218 * its requested size, and in many cases a widget may be allocated more
9219 * space than it requested.
9221 * If the size request in a given direction is -1 (unset), then
9222 * the "natural" size request of the widget will be used instead.
9224 * Widgets can't actually be allocated a size less than 1 by 1, but
9225 * you can pass 0,0 to this function to mean "as small as possible."
9227 * The size request set here does not include any margin from the
9228 * #GtkWidget properties margin-left, margin-right, margin-top, and
9229 * margin-bottom, but it does include pretty much all other padding
9230 * or border properties set by any subclass of #GtkWidget.
9233 gtk_widget_set_size_request (GtkWidget *widget,
9237 g_return_if_fail (GTK_IS_WIDGET (widget));
9238 g_return_if_fail (width >= -1);
9239 g_return_if_fail (height >= -1);
9246 gtk_widget_set_usize_internal (widget, width, height, 0);
9251 * gtk_widget_get_size_request:
9252 * @widget: a #GtkWidget
9253 * @width: (out) (allow-none): return location for width, or %NULL
9254 * @height: (out) (allow-none): return location for height, or %NULL
9256 * Gets the size request that was explicitly set for the widget using
9257 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9258 * @height indicates that that dimension has not been set explicitly
9259 * and the natural requisition of the widget will be used intead. See
9260 * gtk_widget_set_size_request(). To get the size a widget will
9261 * actually request, call gtk_widget_get_preferred_size() instead of
9265 gtk_widget_get_size_request (GtkWidget *widget,
9269 const GtkWidgetAuxInfo *aux_info;
9271 g_return_if_fail (GTK_IS_WIDGET (widget));
9273 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9276 *width = aux_info->width;
9279 *height = aux_info->height;
9283 * _gtk_widget_override_size_request:
9284 * @widget: a #GtkWidget
9285 * @width: new forced minimum width
9286 * @height: new forced minimum height
9287 * @old_width: location to store previous forced minimum width
9288 * @old_width: location to store previous forced minumum height
9290 * Temporarily establishes a forced minimum size for a widget; this
9291 * is used by GtkWindow when calculating the size to add to the
9292 * window's geometry widget. Cached sizes for the widget and its
9293 * parents are invalidated, so that subsequent calls to the size
9294 * negotiation machinery produce the overriden result, but the
9295 * widget is not queued for relayout or redraw. The old size must
9296 * be restored with _gtk_widget_restore_size_request() or things
9300 _gtk_widget_override_size_request (GtkWidget *widget,
9306 gtk_widget_get_size_request (widget, old_width, old_height);
9307 gtk_widget_set_usize_internal (widget, width, height,
9308 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9312 * _gtk_widget_restore_size_request:
9313 * @widget: a #GtkWidget
9314 * @old_width: saved forced minimum size
9315 * @old_height: saved forced minimum size
9317 * Undoes the operation of_gtk_widget_override_size_request().
9320 _gtk_widget_restore_size_request (GtkWidget *widget,
9324 gtk_widget_set_usize_internal (widget, old_width, old_height,
9325 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9329 * gtk_widget_set_events:
9330 * @widget: a #GtkWidget
9331 * @events: event mask
9333 * Sets the event mask (see #GdkEventMask) for a widget. The event
9334 * mask determines which events a widget will receive. Keep in mind
9335 * that different widgets have different default event masks, and by
9336 * changing the event mask you may disrupt a widget's functionality,
9337 * so be careful. This function must be called while a widget is
9338 * unrealized. Consider gtk_widget_add_events() for widgets that are
9339 * already realized, or if you want to preserve the existing event
9340 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9341 * to get events on those widgets, place them inside a #GtkEventBox
9342 * and receive events on the event box.
9345 gtk_widget_set_events (GtkWidget *widget,
9348 g_return_if_fail (GTK_IS_WIDGET (widget));
9349 g_return_if_fail (!gtk_widget_get_realized (widget));
9351 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9352 GINT_TO_POINTER (events));
9353 g_object_notify (G_OBJECT (widget), "events");
9357 * gtk_widget_set_device_events:
9358 * @widget: a #GtkWidget
9359 * @device: a #GdkDevice
9360 * @events: event mask
9362 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9363 * mask determines which events a widget will receive from @device. Keep
9364 * in mind that different widgets have different default event masks, and by
9365 * changing the event mask you may disrupt a widget's functionality,
9366 * so be careful. This function must be called while a widget is
9367 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9368 * already realized, or if you want to preserve the existing event
9369 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9370 * to get events on those widgets, place them inside a #GtkEventBox
9371 * and receive events on the event box.
9376 gtk_widget_set_device_events (GtkWidget *widget,
9378 GdkEventMask events)
9380 GHashTable *device_events;
9382 g_return_if_fail (GTK_IS_WIDGET (widget));
9383 g_return_if_fail (GDK_IS_DEVICE (device));
9384 g_return_if_fail (!gtk_widget_get_realized (widget));
9386 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9388 if (G_UNLIKELY (!device_events))
9390 device_events = g_hash_table_new (NULL, NULL);
9391 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9392 (GDestroyNotify) g_hash_table_unref);
9395 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9399 * gtk_widget_set_device_enabled:
9400 * @widget: a #GtkWidget
9401 * @device: a #GdkDevice
9402 * @enabled: whether to enable the device
9404 * Enables or disables a #GdkDevice to interact with @widget
9405 * and all its children.
9407 * It does so by descending through the #GdkWindow hierarchy
9408 * and enabling the same mask that is has for core events
9409 * (i.e. the one that gdk_window_get_events() returns).
9414 gtk_widget_set_device_enabled (GtkWidget *widget,
9418 GList *enabled_devices;
9420 g_return_if_fail (GTK_IS_WIDGET (widget));
9421 g_return_if_fail (GDK_IS_DEVICE (device));
9423 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9424 enabled_devices = g_list_append (enabled_devices, device);
9426 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9427 enabled_devices, (GDestroyNotify) g_list_free);;
9429 if (gtk_widget_get_realized (widget))
9430 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9434 * gtk_widget_get_device_enabled:
9435 * @widget: a #GtkWidget
9436 * @device: a #GdkDevice
9438 * Returns whether @device can interact with @widget and its
9439 * children. See gtk_widget_set_device_enabled().
9441 * Return value: %TRUE is @device is enabled for @widget
9446 gtk_widget_get_device_enabled (GtkWidget *widget,
9449 GList *enabled_devices;
9451 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9452 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9454 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9456 return g_list_find (enabled_devices, device) != NULL;
9460 gtk_widget_add_events_internal_list (GtkWidget *widget,
9467 for (l = window_list; l != NULL; l = l->next)
9469 GdkWindow *window = l->data;
9472 gdk_window_get_user_data (window, &user_data);
9473 if (user_data == widget)
9478 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9480 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9482 children = gdk_window_get_children (window);
9483 gtk_widget_add_events_internal_list (widget, device, events, children);
9484 g_list_free (children);
9490 gtk_widget_add_events_internal (GtkWidget *widget,
9494 GtkWidgetPrivate *priv = widget->priv;
9497 if (!gtk_widget_get_has_window (widget))
9498 window_list = gdk_window_get_children (priv->window);
9500 window_list = g_list_prepend (NULL, priv->window);
9502 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9504 g_list_free (window_list);
9508 * gtk_widget_add_events:
9509 * @widget: a #GtkWidget
9510 * @events: an event mask, see #GdkEventMask
9512 * Adds the events in the bitfield @events to the event mask for
9513 * @widget. See gtk_widget_set_events() for details.
9516 gtk_widget_add_events (GtkWidget *widget,
9521 g_return_if_fail (GTK_IS_WIDGET (widget));
9523 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9524 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9525 GINT_TO_POINTER (old_events | events));
9527 if (gtk_widget_get_realized (widget))
9529 gtk_widget_add_events_internal (widget, NULL, events);
9530 gtk_widget_update_devices_mask (widget, FALSE);
9533 g_object_notify (G_OBJECT (widget), "events");
9537 * gtk_widget_add_device_events:
9538 * @widget: a #GtkWidget
9539 * @device: a #GdkDevice
9540 * @events: an event mask, see #GdkEventMask
9542 * Adds the device events in the bitfield @events to the event mask for
9543 * @widget. See gtk_widget_set_device_events() for details.
9548 gtk_widget_add_device_events (GtkWidget *widget,
9550 GdkEventMask events)
9552 GdkEventMask old_events;
9553 GHashTable *device_events;
9555 g_return_if_fail (GTK_IS_WIDGET (widget));
9556 g_return_if_fail (GDK_IS_DEVICE (device));
9558 old_events = gtk_widget_get_device_events (widget, device);
9560 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9562 if (G_UNLIKELY (!device_events))
9564 device_events = g_hash_table_new (NULL, NULL);
9565 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9566 (GDestroyNotify) g_hash_table_unref);
9569 g_hash_table_insert (device_events, device,
9570 GUINT_TO_POINTER (old_events | events));
9572 if (gtk_widget_get_realized (widget))
9573 gtk_widget_add_events_internal (widget, device, events);
9575 g_object_notify (G_OBJECT (widget), "events");
9579 * gtk_widget_get_toplevel:
9580 * @widget: a #GtkWidget
9582 * This function returns the topmost widget in the container hierarchy
9583 * @widget is a part of. If @widget has no parent widgets, it will be
9584 * returned as the topmost widget. No reference will be added to the
9585 * returned widget; it should not be unreferenced.
9587 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9588 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9590 * %NULL if @widget wasn't inside a toplevel window, and if the
9591 * window was inside a #GtkWindow-derived widget which was in turn
9592 * inside the toplevel #GtkWindow. While the second case may
9593 * seem unlikely, it actually happens when a #GtkPlug is embedded
9594 * inside a #GtkSocket within the same application.
9596 * To reliably find the toplevel #GtkWindow, use
9597 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9598 * is set on the result.
9600 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9601 * if (gtk_widget_is_toplevel (toplevel))
9603 * /* Perform action on toplevel. */
9607 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9608 * if there's no ancestor.
9611 gtk_widget_get_toplevel (GtkWidget *widget)
9613 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9615 while (widget->priv->parent)
9616 widget = widget->priv->parent;
9622 * gtk_widget_get_ancestor:
9623 * @widget: a #GtkWidget
9624 * @widget_type: ancestor type
9626 * Gets the first ancestor of @widget with type @widget_type. For example,
9627 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9628 * the first #GtkBox that's an ancestor of @widget. No reference will be
9629 * added to the returned widget; it should not be unreferenced. See note
9630 * about checking for a toplevel #GtkWindow in the docs for
9631 * gtk_widget_get_toplevel().
9633 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9634 * considers @widget to be an ancestor of itself.
9636 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9639 gtk_widget_get_ancestor (GtkWidget *widget,
9642 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9644 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9645 widget = widget->priv->parent;
9647 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9654 * gtk_widget_set_visual:
9655 * @widget: a #GtkWidget
9656 * @visual: visual to be used or %NULL to unset a previous one
9658 * Sets the visual that should be used for by widget and its children for
9659 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9660 * returned by gdk_widget_get_screen(), so handling the
9661 * #GtkWidget::screen-changed signal is necessary.
9663 * Setting a new @visual will not cause @widget to recreate its windows,
9664 * so you should call this function before @widget is realized.
9667 gtk_widget_set_visual (GtkWidget *widget,
9670 g_return_if_fail (GTK_IS_WIDGET (widget));
9671 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9674 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9677 g_object_set_qdata_full (G_OBJECT (widget),
9679 g_object_ref (visual),
9684 * gtk_widget_get_visual:
9685 * @widget: a #GtkWidget
9687 * Gets the visual that will be used to render @widget.
9689 * Return value: (transfer none): the visual for @widget
9692 gtk_widget_get_visual (GtkWidget *widget)
9698 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9700 if (gtk_widget_get_has_window (widget) &&
9701 widget->priv->window)
9702 return gdk_window_get_visual (widget->priv->window);
9704 screen = gtk_widget_get_screen (widget);
9706 for (w = widget; w != NULL; w = w->priv->parent)
9708 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9711 if (gdk_visual_get_screen (visual) == screen)
9714 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9715 gtk_widget_get_name (widget));
9719 return gdk_screen_get_system_visual (screen);
9723 * gtk_widget_get_settings:
9724 * @widget: a #GtkWidget
9726 * Gets the settings object holding the settings used for this widget.
9728 * Note that this function can only be called when the #GtkWidget
9729 * is attached to a toplevel, since the settings object is specific
9730 * to a particular #GdkScreen.
9732 * Return value: (transfer none): the relevant #GtkSettings object
9735 gtk_widget_get_settings (GtkWidget *widget)
9737 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9739 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9743 * gtk_widget_get_events:
9744 * @widget: a #GtkWidget
9746 * Returns the event mask for the widget (a bitfield containing flags
9747 * from the #GdkEventMask enumeration). These are the events that the widget
9750 * Return value: event mask for @widget
9753 gtk_widget_get_events (GtkWidget *widget)
9755 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9757 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9761 * gtk_widget_get_device_events:
9762 * @widget: a #GtkWidget
9763 * @device: a #GdkDevice
9765 * Returns the events mask for the widget corresponding to an specific device. These
9766 * are the events that the widget will receive when @device operates on it.
9768 * Returns: device event mask for @widget
9773 gtk_widget_get_device_events (GtkWidget *widget,
9776 GHashTable *device_events;
9778 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9779 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9781 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9786 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9790 * gtk_widget_get_pointer:
9791 * @widget: a #GtkWidget
9792 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9793 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9795 * Obtains the location of the mouse pointer in widget coordinates.
9796 * Widget coordinates are a bit odd; for historical reasons, they are
9797 * defined as @widget->window coordinates for widgets that are not
9798 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9799 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9801 * Deprecated: 3.4: Use gdk_window_get_device_position() instead.
9804 gtk_widget_get_pointer (GtkWidget *widget,
9808 GtkWidgetPrivate *priv;
9810 g_return_if_fail (GTK_IS_WIDGET (widget));
9812 priv = widget->priv;
9819 if (gtk_widget_get_realized (widget))
9821 gdk_window_get_device_position (priv->window,
9822 gdk_device_manager_get_client_pointer (
9823 gdk_display_get_device_manager (
9824 gtk_widget_get_display (widget))),
9827 if (!gtk_widget_get_has_window (widget))
9830 *x -= priv->allocation.x;
9832 *y -= priv->allocation.y;
9838 * gtk_widget_is_ancestor:
9839 * @widget: a #GtkWidget
9840 * @ancestor: another #GtkWidget
9842 * Determines whether @widget is somewhere inside @ancestor, possibly with
9843 * intermediate containers.
9845 * Return value: %TRUE if @ancestor contains @widget as a child,
9846 * grandchild, great grandchild, etc.
9849 gtk_widget_is_ancestor (GtkWidget *widget,
9850 GtkWidget *ancestor)
9852 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9853 g_return_val_if_fail (ancestor != NULL, FALSE);
9857 if (widget->priv->parent == ancestor)
9859 widget = widget->priv->parent;
9865 static GQuark quark_composite_name = 0;
9868 * gtk_widget_set_composite_name:
9869 * @widget: a #GtkWidget.
9870 * @name: the name to set
9872 * Sets a widgets composite name. The widget must be
9873 * a composite child of its parent; see gtk_widget_push_composite_child().
9876 gtk_widget_set_composite_name (GtkWidget *widget,
9879 g_return_if_fail (GTK_IS_WIDGET (widget));
9880 g_return_if_fail (widget->priv->composite_child);
9881 g_return_if_fail (name != NULL);
9883 if (!quark_composite_name)
9884 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
9886 g_object_set_qdata_full (G_OBJECT (widget),
9887 quark_composite_name,
9893 * gtk_widget_get_composite_name:
9894 * @widget: a #GtkWidget
9896 * Obtains the composite name of a widget.
9898 * Returns: the composite name of @widget, or %NULL if @widget is not
9899 * a composite child. The string should be freed when it is no
9903 gtk_widget_get_composite_name (GtkWidget *widget)
9905 GtkWidgetPrivate *priv;
9907 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9909 priv = widget->priv;
9911 if (widget->priv->composite_child && priv->parent)
9912 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
9919 * gtk_widget_push_composite_child:
9921 * Makes all newly-created widgets as composite children until
9922 * the corresponding gtk_widget_pop_composite_child() call.
9924 * A composite child is a child that's an implementation detail of the
9925 * container it's inside and should not be visible to people using the
9926 * container. Composite children aren't treated differently by GTK (but
9927 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
9928 * builders might want to treat them in a different way.
9930 * Here is a simple example:
9932 * gtk_widget_push_composite_child ();
9933 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
9934 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
9935 * gtk_widget_pop_composite_child ();
9936 * gtk_widget_set_parent (scrolled_window->hscrollbar,
9937 * GTK_WIDGET (scrolled_window));
9938 * g_object_ref (scrolled_window->hscrollbar);
9942 gtk_widget_push_composite_child (void)
9944 composite_child_stack++;
9948 * gtk_widget_pop_composite_child:
9950 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
9953 gtk_widget_pop_composite_child (void)
9955 if (composite_child_stack)
9956 composite_child_stack--;
9960 gtk_widget_emit_direction_changed (GtkWidget *widget,
9961 GtkTextDirection old_dir)
9963 gtk_widget_update_pango_context (widget);
9965 if (widget->priv->context)
9966 gtk_style_context_set_direction (widget->priv->context,
9967 gtk_widget_get_direction (widget));
9969 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
9973 * gtk_widget_set_direction:
9974 * @widget: a #GtkWidget
9975 * @dir: the new direction
9977 * Sets the reading direction on a particular widget. This direction
9978 * controls the primary direction for widgets containing text,
9979 * and also the direction in which the children of a container are
9980 * packed. The ability to set the direction is present in order
9981 * so that correct localization into languages with right-to-left
9982 * reading directions can be done. Generally, applications will
9983 * let the default reading direction present, except for containers
9984 * where the containers are arranged in an order that is explicitely
9985 * visual rather than logical (such as buttons for text justification).
9987 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
9988 * set by gtk_widget_set_default_direction() will be used.
9991 gtk_widget_set_direction (GtkWidget *widget,
9992 GtkTextDirection dir)
9994 GtkTextDirection old_dir;
9996 g_return_if_fail (GTK_IS_WIDGET (widget));
9997 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
9999 old_dir = gtk_widget_get_direction (widget);
10001 widget->priv->direction = dir;
10003 if (old_dir != gtk_widget_get_direction (widget))
10004 gtk_widget_emit_direction_changed (widget, old_dir);
10008 * gtk_widget_get_direction:
10009 * @widget: a #GtkWidget
10011 * Gets the reading direction for a particular widget. See
10012 * gtk_widget_set_direction().
10014 * Return value: the reading direction for the widget.
10017 gtk_widget_get_direction (GtkWidget *widget)
10019 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10021 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10022 return gtk_default_direction;
10024 return widget->priv->direction;
10028 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10030 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10032 g_object_ref (widget);
10034 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10035 gtk_widget_emit_direction_changed (widget, old_dir);
10037 if (GTK_IS_CONTAINER (widget))
10038 gtk_container_forall (GTK_CONTAINER (widget),
10039 gtk_widget_set_default_direction_recurse,
10042 g_object_unref (widget);
10046 * gtk_widget_set_default_direction:
10047 * @dir: the new default direction. This cannot be
10048 * %GTK_TEXT_DIR_NONE.
10050 * Sets the default reading direction for widgets where the
10051 * direction has not been explicitly set by gtk_widget_set_direction().
10054 gtk_widget_set_default_direction (GtkTextDirection dir)
10056 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10058 if (dir != gtk_default_direction)
10060 GList *toplevels, *tmp_list;
10061 GtkTextDirection old_dir = gtk_default_direction;
10063 gtk_default_direction = dir;
10065 tmp_list = toplevels = gtk_window_list_toplevels ();
10066 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10070 gtk_widget_set_default_direction_recurse (tmp_list->data,
10071 GUINT_TO_POINTER (old_dir));
10072 g_object_unref (tmp_list->data);
10073 tmp_list = tmp_list->next;
10076 g_list_free (toplevels);
10081 * gtk_widget_get_default_direction:
10083 * Obtains the current default reading direction. See
10084 * gtk_widget_set_default_direction().
10086 * Return value: the current default direction.
10089 gtk_widget_get_default_direction (void)
10091 return gtk_default_direction;
10095 gtk_widget_dispose (GObject *object)
10097 GtkWidget *widget = GTK_WIDGET (object);
10098 GtkWidgetPrivate *priv = widget->priv;
10101 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10102 else if (gtk_widget_get_visible (widget))
10103 gtk_widget_hide (widget);
10105 priv->visible = FALSE;
10106 if (gtk_widget_get_realized (widget))
10107 gtk_widget_unrealize (widget);
10109 if (!priv->in_destruction)
10111 priv->in_destruction = TRUE;
10112 g_signal_emit (object, widget_signals[DESTROY], 0);
10113 priv->in_destruction = FALSE;
10116 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10120 gtk_widget_real_destroy (GtkWidget *object)
10122 /* gtk_object_destroy() will already hold a refcount on object */
10123 GtkWidget *widget = GTK_WIDGET (object);
10124 GtkWidgetPrivate *priv = widget->priv;
10126 if (GTK_WIDGET_GET_CLASS (widget)->priv->accessible_type != GTK_TYPE_ACCESSIBLE)
10128 GtkAccessible *accessible = g_object_steal_qdata (G_OBJECT (widget), quark_accessible_object);
10132 gtk_accessible_set_widget (accessible, NULL);
10133 g_object_unref (accessible);
10137 /* wipe accelerator closures (keep order) */
10138 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10139 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10141 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10142 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10144 gtk_grab_remove (widget);
10147 g_object_unref (priv->style);
10148 priv->style = gtk_widget_get_default_style ();
10149 g_object_ref (priv->style);
10153 gtk_widget_finalize (GObject *object)
10155 GtkWidget *widget = GTK_WIDGET (object);
10156 GtkWidgetPrivate *priv = widget->priv;
10157 GtkWidgetAuxInfo *aux_info;
10158 GtkAccessible *accessible;
10160 gtk_grab_remove (widget);
10162 g_object_unref (priv->style);
10163 priv->style = NULL;
10165 g_free (priv->name);
10167 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10169 gtk_widget_aux_info_destroy (aux_info);
10171 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10173 g_object_unref (accessible);
10176 gtk_widget_path_free (priv->path);
10179 g_object_unref (priv->context);
10181 _gtk_widget_free_cached_sizes (widget);
10183 if (g_object_is_floating (object))
10184 g_warning ("A floating object was finalized. This means that someone\n"
10185 "called g_object_unref() on an object that had only a floating\n"
10186 "reference; the initial floating reference is not owned by anyone\n"
10187 "and must be removed with g_object_ref_sink().");
10189 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10192 /*****************************************
10193 * gtk_widget_real_map:
10198 *****************************************/
10201 gtk_widget_real_map (GtkWidget *widget)
10203 GtkWidgetPrivate *priv = widget->priv;
10205 g_assert (gtk_widget_get_realized (widget));
10207 if (!gtk_widget_get_mapped (widget))
10209 gtk_widget_set_mapped (widget, TRUE);
10211 if (gtk_widget_get_has_window (widget))
10212 gdk_window_show (priv->window);
10216 /*****************************************
10217 * gtk_widget_real_unmap:
10222 *****************************************/
10225 gtk_widget_real_unmap (GtkWidget *widget)
10227 GtkWidgetPrivate *priv = widget->priv;
10229 if (gtk_widget_get_mapped (widget))
10231 gtk_widget_set_mapped (widget, FALSE);
10233 if (gtk_widget_get_has_window (widget))
10234 gdk_window_hide (priv->window);
10238 /*****************************************
10239 * gtk_widget_real_realize:
10244 *****************************************/
10247 gtk_widget_real_realize (GtkWidget *widget)
10249 GtkWidgetPrivate *priv = widget->priv;
10251 g_assert (!gtk_widget_get_has_window (widget));
10253 gtk_widget_set_realized (widget, TRUE);
10256 priv->window = gtk_widget_get_parent_window (widget);
10257 g_object_ref (priv->window);
10261 /*****************************************
10262 * gtk_widget_real_unrealize:
10267 *****************************************/
10270 gtk_widget_real_unrealize (GtkWidget *widget)
10272 GtkWidgetPrivate *priv = widget->priv;
10274 g_assert (!widget->priv->mapped);
10276 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10279 /* We must do unrealize child widget BEFORE container widget.
10280 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10281 * So, unrealizing container widget bofore its children causes the problem
10282 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10285 if (GTK_IS_CONTAINER (widget))
10286 gtk_container_forall (GTK_CONTAINER (widget),
10287 (GtkCallback) gtk_widget_unrealize,
10290 if (gtk_widget_get_has_window (widget))
10292 gdk_window_set_user_data (priv->window, NULL);
10293 gdk_window_destroy (priv->window);
10294 priv->window = NULL;
10298 g_object_unref (priv->window);
10299 priv->window = NULL;
10302 gtk_selection_remove_all (widget);
10304 gtk_widget_set_realized (widget, FALSE);
10308 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10309 GtkOrientation orientation,
10310 gint *minimum_size,
10311 gint *natural_size)
10313 const GtkWidgetAuxInfo *aux_info;
10315 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10317 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10318 aux_info->width > 0)
10320 *minimum_size = MAX (*minimum_size, aux_info->width);
10322 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10323 aux_info->height > 0)
10325 *minimum_size = MAX (*minimum_size, aux_info->height);
10328 /* Fix it if set_size_request made natural size smaller than min size.
10329 * This would also silently fix broken widgets, but we warn about them
10330 * in gtksizerequest.c when calling their size request vfuncs.
10332 *natural_size = MAX (*natural_size, *minimum_size);
10334 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10336 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10337 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10341 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10342 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10347 * _gtk_widget_peek_request_cache:
10349 * Returns the address of the widget's request cache (strictly for
10350 * internal use in gtksizerequest.c)
10352 * Return value: the address of @widget's size request cache.
10355 _gtk_widget_peek_request_cache (GtkWidget *widget)
10357 /* Don't bother slowing things down with the return_if_fail guards here */
10358 return &widget->priv->requests;
10362 * _gtk_widget_set_device_window:
10363 * @widget: a #GtkWidget
10364 * @device: a #GdkDevice
10365 * @window: the new device window
10367 * Sets pointer window for @widget and @device.
10368 * Does not ref @window.
10371 _gtk_widget_set_device_window (GtkWidget *widget,
10375 GHashTable *device_window;
10377 g_return_if_fail (GTK_IS_WIDGET (widget));
10378 g_return_if_fail (GDK_IS_DEVICE (device));
10379 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10381 if (!gtk_widget_get_mapped (widget))
10384 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10386 if (!device_window && window)
10388 device_window = g_hash_table_new (NULL, NULL);
10389 g_object_set_qdata_full (G_OBJECT (widget),
10390 quark_pointer_window,
10392 (GDestroyNotify) g_hash_table_destroy);
10396 g_hash_table_insert (device_window, device, window);
10397 else if (device_window)
10399 g_hash_table_remove (device_window, device);
10401 if (g_hash_table_size (device_window) == 0)
10402 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10407 * _gtk_widget_get_device_window:
10408 * @widget: a #GtkWidget
10409 * @device: a #GdkDevice
10411 * Return value: the device window set on @widget, or %NULL
10414 _gtk_widget_get_device_window (GtkWidget *widget,
10417 GHashTable *device_window;
10419 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10420 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10422 if (!gtk_widget_get_mapped (widget))
10425 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10427 if (!device_window)
10430 return g_hash_table_lookup (device_window, device);
10434 * _gtk_widget_list_devices:
10435 * @widget: a #GtkWidget
10437 * Returns the list of #GdkDevices that is currently on top
10438 * of any window belonging to @widget.
10439 * Free the list with g_list_free(), the elements are owned
10440 * by GTK+ and must not be freed.
10443 _gtk_widget_list_devices (GtkWidget *widget)
10445 GHashTableIter iter;
10446 GHashTable *device_window;
10447 GList *devices = NULL;
10448 gpointer key, value;
10450 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10452 if (!gtk_widget_get_mapped (widget))
10455 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10457 if (G_UNLIKELY (!device_window))
10460 g_hash_table_iter_init (&iter, device_window);
10462 while (g_hash_table_iter_next (&iter, &key, &value))
10463 devices = g_list_prepend (devices, key);
10469 synth_crossing (GtkWidget *widget,
10473 GdkCrossingMode mode,
10474 GdkNotifyType detail)
10478 event = gdk_event_new (type);
10480 event->crossing.window = g_object_ref (window);
10481 event->crossing.send_event = TRUE;
10482 event->crossing.subwindow = g_object_ref (window);
10483 event->crossing.time = GDK_CURRENT_TIME;
10484 event->crossing.x = event->crossing.y = 0;
10485 event->crossing.x_root = event->crossing.y_root = 0;
10486 event->crossing.mode = mode;
10487 event->crossing.detail = detail;
10488 event->crossing.focus = FALSE;
10489 event->crossing.state = 0;
10490 gdk_event_set_device (event, device);
10493 widget = gtk_get_event_widget (event);
10496 gtk_widget_event_internal (widget, event);
10498 gdk_event_free (event);
10502 * _gtk_widget_synthesize_crossing:
10503 * @from: the #GtkWidget the virtual pointer is leaving.
10504 * @to: the #GtkWidget the virtual pointer is moving to.
10505 * @mode: the #GdkCrossingMode to place on the synthesized events.
10507 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10509 * The real pointer window is the window that most recently received an enter notify
10510 * event. Windows that don't select for crossing events can't become the real
10511 * poiner window. The real pointer widget that owns the real pointer window. The
10512 * effective pointer window is the same as the real pointer window unless the real
10513 * pointer widget is either insensitive or there is a grab on a widget that is not
10514 * an ancestor of the real pointer widget (in which case the effective pointer
10515 * window should be the root window).
10517 * When the effective pointer window is the same as the real poiner window, we
10518 * receive crossing events from the windowing system. When the effective pointer
10519 * window changes to become different from the real pointer window we synthesize
10520 * crossing events, attempting to follow X protocol rules:
10522 * When the root window becomes the effective pointer window:
10523 * - leave notify on real pointer window, detail Ancestor
10524 * - leave notify on all of its ancestors, detail Virtual
10525 * - enter notify on root window, detail Inferior
10527 * When the root window ceases to be the effective pointer window:
10528 * - leave notify on root window, detail Inferior
10529 * - enter notify on all ancestors of real pointer window, detail Virtual
10530 * - enter notify on real pointer window, detail Ancestor
10533 _gtk_widget_synthesize_crossing (GtkWidget *from,
10536 GdkCrossingMode mode)
10538 GdkWindow *from_window = NULL, *to_window = NULL;
10540 g_return_if_fail (from != NULL || to != NULL);
10544 from_window = _gtk_widget_get_device_window (from, device);
10547 from_window = from->priv->window;
10552 to_window = _gtk_widget_get_device_window (to, device);
10555 to_window = to->priv->window;
10558 if (from_window == NULL && to_window == NULL)
10560 else if (from_window != NULL && to_window == NULL)
10562 GList *from_ancestors = NULL, *list;
10563 GdkWindow *from_ancestor = from_window;
10565 while (from_ancestor != NULL)
10567 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10568 if (from_ancestor == NULL)
10570 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10573 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10574 device, mode, GDK_NOTIFY_ANCESTOR);
10575 for (list = g_list_last (from_ancestors); list; list = list->prev)
10577 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10578 device, mode, GDK_NOTIFY_VIRTUAL);
10581 /* XXX: enter/inferior on root window? */
10583 g_list_free (from_ancestors);
10585 else if (from_window == NULL && to_window != NULL)
10587 GList *to_ancestors = NULL, *list;
10588 GdkWindow *to_ancestor = to_window;
10590 while (to_ancestor != NULL)
10592 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10593 if (to_ancestor == NULL)
10595 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10598 /* XXX: leave/inferior on root window? */
10600 for (list = to_ancestors; list; list = list->next)
10602 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10603 device, mode, GDK_NOTIFY_VIRTUAL);
10605 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10606 device, mode, GDK_NOTIFY_ANCESTOR);
10608 g_list_free (to_ancestors);
10610 else if (from_window == to_window)
10614 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10615 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10617 while (from_ancestor != NULL || to_ancestor != NULL)
10619 if (from_ancestor != NULL)
10621 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10622 if (from_ancestor == to_window)
10625 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10627 if (to_ancestor != NULL)
10629 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10630 if (to_ancestor == from_window)
10633 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10636 if (to_ancestor == from_window)
10638 if (mode != GDK_CROSSING_GTK_UNGRAB)
10639 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10640 device, mode, GDK_NOTIFY_INFERIOR);
10641 for (list = to_ancestors; list; list = list->next)
10642 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10643 device, mode, GDK_NOTIFY_VIRTUAL);
10644 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10645 device, mode, GDK_NOTIFY_ANCESTOR);
10647 else if (from_ancestor == to_window)
10649 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10650 device, mode, GDK_NOTIFY_ANCESTOR);
10651 for (list = g_list_last (from_ancestors); list; list = list->prev)
10653 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10654 device, mode, GDK_NOTIFY_VIRTUAL);
10656 if (mode != GDK_CROSSING_GTK_GRAB)
10657 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10658 device, mode, GDK_NOTIFY_INFERIOR);
10662 while (from_ancestors != NULL && to_ancestors != NULL
10663 && from_ancestors->data == to_ancestors->data)
10665 from_ancestors = g_list_delete_link (from_ancestors,
10667 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10670 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10671 device, mode, GDK_NOTIFY_NONLINEAR);
10673 for (list = g_list_last (from_ancestors); list; list = list->prev)
10675 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10676 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10678 for (list = to_ancestors; list; list = list->next)
10680 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10681 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10683 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10684 device, mode, GDK_NOTIFY_NONLINEAR);
10686 g_list_free (from_ancestors);
10687 g_list_free (to_ancestors);
10692 gtk_widget_propagate_state (GtkWidget *widget,
10693 GtkStateData *data)
10695 GtkWidgetPrivate *priv = widget->priv;
10696 GtkStateFlags new_flags, old_flags = priv->state_flags;
10697 GtkStateType old_state;
10699 old_state = gtk_widget_get_state (widget);
10701 switch (data->operation)
10703 case STATE_CHANGE_REPLACE:
10704 priv->state_flags = data->flags;
10706 case STATE_CHANGE_SET:
10707 priv->state_flags |= data->flags;
10709 case STATE_CHANGE_UNSET:
10710 priv->state_flags &= ~(data->flags);
10714 /* make insensitivity unoverridable */
10715 if (!priv->sensitive)
10716 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
10718 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10722 window = gtk_widget_get_toplevel (widget);
10724 if (window && gtk_widget_is_toplevel (window))
10725 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10728 new_flags = priv->state_flags;
10730 if (old_flags != new_flags)
10732 g_object_ref (widget);
10734 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10735 gtk_grab_remove (widget);
10737 gtk_style_context_set_state (gtk_widget_get_style_context (widget), new_flags);
10739 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10740 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
10742 if (!priv->shadowed &&
10743 (new_flags & GTK_STATE_FLAG_INSENSITIVE) != (old_flags & GTK_STATE_FLAG_INSENSITIVE))
10745 GList *event_windows = NULL;
10746 GList *devices, *d;
10748 devices = _gtk_widget_list_devices (widget);
10750 for (d = devices; d; d = d->next)
10756 window = _gtk_widget_get_device_window (widget, device);
10758 /* Do not propagate more than once to the
10759 * same window if non-multidevice aware.
10761 if (!gdk_window_get_support_multidevice (window) &&
10762 g_list_find (event_windows, window))
10765 if (!gtk_widget_is_sensitive (widget))
10766 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10767 GDK_CROSSING_STATE_CHANGED);
10769 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10770 GDK_CROSSING_STATE_CHANGED);
10772 event_windows = g_list_prepend (event_windows, window);
10775 g_list_free (event_windows);
10776 g_list_free (devices);
10779 if (GTK_IS_CONTAINER (widget))
10781 GtkStateData child_data = *data;
10783 /* Make sure to only propate the right states further */
10784 child_data.flags &= GTK_STATE_FLAGS_DO_PROPAGATE;
10786 gtk_container_forall (GTK_CONTAINER (widget),
10787 (GtkCallback) gtk_widget_propagate_state,
10791 /* Trigger state change transitions for the widget */
10792 if (priv->context &&
10793 gtk_widget_get_mapped (widget))
10795 gint diff, flag = 1;
10797 diff = old_flags ^ new_flags;
10801 if ((diff & flag) != 0)
10805 target = ((new_flags & flag) != 0);
10806 _gtk_widget_notify_state_change (widget, flag, target);
10815 g_object_unref (widget);
10819 static const GtkWidgetAuxInfo default_aux_info = {
10827 * gtk_widget_get_aux_info:
10828 * @widget: a #GtkWidget
10829 * @create: if %TRUE, create the structure if it doesn't exist
10831 * Get the #GtkWidgetAuxInfo structure for the widget.
10833 * Return value: the #GtkAuxInfo structure for the widget, or
10834 * %NULL if @create is %FALSE and one doesn't already exist.
10836 static GtkWidgetAuxInfo *
10837 gtk_widget_get_aux_info (GtkWidget *widget,
10840 GtkWidgetAuxInfo *aux_info;
10842 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
10843 if (!aux_info && create)
10845 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
10847 *aux_info = default_aux_info;
10849 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
10855 static const GtkWidgetAuxInfo*
10856 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
10858 GtkWidgetAuxInfo *aux_info;
10860 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10861 if (aux_info == NULL)
10863 return &default_aux_info;
10871 /*****************************************
10872 * gtk_widget_aux_info_destroy:
10877 *****************************************/
10880 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
10882 g_slice_free (GtkWidgetAuxInfo, aux_info);
10886 * gtk_widget_shape_combine_region:
10887 * @widget: a #GtkWidget
10888 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10890 * Sets a shape for this widget's GDK window. This allows for
10891 * transparent windows etc., see gdk_window_shape_combine_region()
10892 * for more information.
10897 gtk_widget_shape_combine_region (GtkWidget *widget,
10898 cairo_region_t *region)
10900 GtkWidgetPrivate *priv;
10902 g_return_if_fail (GTK_IS_WIDGET (widget));
10903 /* set_shape doesn't work on widgets without gdk window */
10904 g_return_if_fail (gtk_widget_get_has_window (widget));
10906 priv = widget->priv;
10908 if (region == NULL)
10910 priv->has_shape_mask = FALSE;
10913 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
10915 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
10919 priv->has_shape_mask = TRUE;
10921 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
10922 cairo_region_copy (region),
10923 (GDestroyNotify) cairo_region_destroy);
10925 /* set shape if widget has a gdk window already.
10926 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10929 gdk_window_shape_combine_region (priv->window, region, 0, 0);
10934 * gtk_widget_input_shape_combine_region:
10935 * @widget: a #GtkWidget
10936 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10938 * Sets an input shape for this widget's GDK window. This allows for
10939 * windows which react to mouse click in a nonrectangular region, see
10940 * gdk_window_input_shape_combine_region() for more information.
10945 gtk_widget_input_shape_combine_region (GtkWidget *widget,
10946 cairo_region_t *region)
10948 GtkWidgetPrivate *priv;
10950 g_return_if_fail (GTK_IS_WIDGET (widget));
10951 /* set_shape doesn't work on widgets without gdk window */
10952 g_return_if_fail (gtk_widget_get_has_window (widget));
10954 priv = widget->priv;
10956 if (region == NULL)
10959 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
10961 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
10965 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
10966 cairo_region_copy (region),
10967 (GDestroyNotify) cairo_region_destroy);
10969 /* set shape if widget has a gdk window already.
10970 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10973 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
10978 /* style properties
10982 * gtk_widget_class_install_style_property_parser: (skip)
10983 * @klass: a #GtkWidgetClass
10984 * @pspec: the #GParamSpec for the style property
10985 * @parser: the parser for the style property
10987 * Installs a style property on a widget class.
10990 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
10992 GtkRcPropertyParser parser)
10994 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10995 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10996 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
10997 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
10999 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11001 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11002 G_OBJECT_CLASS_NAME (klass),
11007 g_param_spec_ref_sink (pspec);
11008 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11009 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11013 * gtk_widget_class_install_style_property:
11014 * @klass: a #GtkWidgetClass
11015 * @pspec: the #GParamSpec for the property
11017 * Installs a style property on a widget class. The parser for the
11018 * style property is determined by the value type of @pspec.
11021 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11024 GtkRcPropertyParser parser;
11026 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11027 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11029 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11031 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11035 * gtk_widget_class_find_style_property:
11036 * @klass: a #GtkWidgetClass
11037 * @property_name: the name of the style property to find
11039 * Finds a style property of a widget class by name.
11041 * Returns: (transfer none): the #GParamSpec of the style property or
11042 * %NULL if @class has no style property with that name.
11047 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11048 const gchar *property_name)
11050 g_return_val_if_fail (property_name != NULL, NULL);
11052 return g_param_spec_pool_lookup (style_property_spec_pool,
11054 G_OBJECT_CLASS_TYPE (klass),
11059 * gtk_widget_class_list_style_properties:
11060 * @klass: a #GtkWidgetClass
11061 * @n_properties: location to return the number of style properties found
11063 * Returns all style properties of a widget class.
11065 * Returns: (array length=n_properties) (transfer container): a
11066 * newly allocated array of #GParamSpec*. The array must be
11067 * freed with g_free().
11072 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11073 guint *n_properties)
11075 GParamSpec **pspecs;
11078 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11079 G_OBJECT_CLASS_TYPE (klass),
11088 * gtk_widget_style_get_property:
11089 * @widget: a #GtkWidget
11090 * @property_name: the name of a style property
11091 * @value: location to return the property value
11093 * Gets the value of a style property of @widget.
11096 gtk_widget_style_get_property (GtkWidget *widget,
11097 const gchar *property_name,
11102 g_return_if_fail (GTK_IS_WIDGET (widget));
11103 g_return_if_fail (property_name != NULL);
11104 g_return_if_fail (G_IS_VALUE (value));
11106 g_object_ref (widget);
11107 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11109 G_OBJECT_TYPE (widget),
11112 g_warning ("%s: widget class `%s' has no property named `%s'",
11114 G_OBJECT_TYPE_NAME (widget),
11118 GtkStyleContext *context;
11119 const GValue *peek_value;
11120 GtkStateFlags state;
11122 context = gtk_widget_get_style_context (widget);
11123 state = gtk_widget_get_state_flags (widget);
11125 peek_value = _gtk_style_context_peek_style_property (context,
11126 G_OBJECT_TYPE (widget),
11129 /* auto-conversion of the caller's value type
11131 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11132 g_value_copy (peek_value, value);
11133 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11134 g_value_transform (peek_value, value);
11136 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11138 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11139 G_VALUE_TYPE_NAME (value));
11141 g_object_unref (widget);
11145 * gtk_widget_style_get_valist:
11146 * @widget: a #GtkWidget
11147 * @first_property_name: the name of the first property to get
11148 * @var_args: a <type>va_list</type> of pairs of property names and
11149 * locations to return the property values, starting with the location
11150 * for @first_property_name.
11152 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11156 gtk_widget_style_get_valist (GtkWidget *widget,
11157 const gchar *first_property_name,
11160 GtkStyleContext *context;
11161 GtkStateFlags state;
11164 g_return_if_fail (GTK_IS_WIDGET (widget));
11166 g_object_ref (widget);
11167 context = gtk_widget_get_style_context (widget);
11168 state = gtk_widget_get_state_flags (widget);
11170 name = first_property_name;
11173 const GValue *peek_value;
11177 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11179 G_OBJECT_TYPE (widget),
11183 g_warning ("%s: widget class `%s' has no property named `%s'",
11185 G_OBJECT_TYPE_NAME (widget),
11189 /* style pspecs are always readable so we can spare that check here */
11191 peek_value = _gtk_style_context_peek_style_property (context,
11192 G_OBJECT_TYPE (widget),
11195 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11198 g_warning ("%s: %s", G_STRLOC, error);
11203 name = va_arg (var_args, gchar*);
11206 g_object_unref (widget);
11210 * gtk_widget_style_get:
11211 * @widget: a #GtkWidget
11212 * @first_property_name: the name of the first property to get
11213 * @...: pairs of property names and locations to return the
11214 * property values, starting with the location for
11215 * @first_property_name, terminated by %NULL.
11217 * Gets the values of a multiple style properties of @widget.
11220 gtk_widget_style_get (GtkWidget *widget,
11221 const gchar *first_property_name,
11226 g_return_if_fail (GTK_IS_WIDGET (widget));
11228 va_start (var_args, first_property_name);
11229 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11234 * gtk_requisition_new:
11236 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11238 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11239 * be freed with gtk_requisition_free().
11244 gtk_requisition_new (void)
11246 return g_slice_new0 (GtkRequisition);
11250 * gtk_requisition_copy:
11251 * @requisition: a #GtkRequisition
11253 * Copies a #GtkRequisition.
11255 * Returns: a copy of @requisition
11258 gtk_requisition_copy (const GtkRequisition *requisition)
11260 return g_slice_dup (GtkRequisition, requisition);
11264 * gtk_requisition_free:
11265 * @requisition: a #GtkRequisition
11267 * Frees a #GtkRequisition.
11270 gtk_requisition_free (GtkRequisition *requisition)
11272 g_slice_free (GtkRequisition, requisition);
11275 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11276 gtk_requisition_copy,
11277 gtk_requisition_free)
11280 * gtk_widget_class_set_accessible_type:
11281 * @widget_class: class to set the accessible type for
11282 * @type: The object type that implements the accessible for @widget_class
11284 * Sets the type to be used for creating accessibles for widgets of
11285 * @widget_class. The given @type must be a subtype of the type used for
11286 * accessibles of the parent class.
11288 * This function should only be called from class init functions of widgets.
11293 gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class,
11296 GtkWidgetClassPrivate *priv;
11298 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11299 g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type));
11301 priv = widget_class->priv;
11303 priv->accessible_type = type;
11304 /* reset this - honoring the type's role is better. */
11305 priv->accessible_role = ATK_ROLE_INVALID;
11309 * gtk_widget_class_set_accessible_role:
11310 * @widget_class: class to set the accessible role for
11311 * @role: The role to use for accessibles created for @widget_class
11313 * Sets the default #AtkRole to be set on accessibles created for
11314 * widgets of @widget_class. Accessibles may decide to not honor this
11315 * setting if their role reporting is more refined. Calls to
11316 * gtk_widget_class_set_accessible_type() will reset this value.
11318 * In cases where you want more fine-grained control over the role of
11319 * accessibles created for @widget_class, you should provide your own
11320 * accessible type and use gtk_widget_class_set_accessible_type()
11323 * If @role is #ATK_ROLE_INVALID, the default role will not be changed
11324 * and the accessible's default role will be used instead.
11326 * This function should only be called from class init functions of widgets.
11331 gtk_widget_class_set_accessible_role (GtkWidgetClass *widget_class,
11334 GtkWidgetClassPrivate *priv;
11336 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11338 priv = widget_class->priv;
11340 priv->accessible_role = role;
11344 * _gtk_widget_peek_accessible:
11345 * @widget: a #GtkWidget
11347 * Gets the accessible for @widget, if it has been created yet.
11348 * Otherwise, this function returns %NULL. If the @widget's implementation
11349 * does not use the default way to create accessibles, %NULL will always be
11352 * Returns: the accessible for @widget or %NULL if none has been
11356 _gtk_widget_peek_accessible (GtkWidget *widget)
11358 return g_object_get_qdata (G_OBJECT (widget),
11359 quark_accessible_object);
11363 * gtk_widget_get_accessible:
11364 * @widget: a #GtkWidget
11366 * Returns the accessible object that describes the widget to an
11367 * assistive technology.
11369 * If accessibility support is not available, this #AtkObject
11370 * instance may be a no-op. Likewise, if no class-specific #AtkObject
11371 * implementation is available for the widget instance in question,
11372 * it will inherit an #AtkObject implementation from the first ancestor
11373 * class for which such an implementation is defined.
11375 * The documentation of the
11376 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
11377 * library contains more information about accessible objects and their uses.
11379 * Returns: (transfer none): the #AtkObject associated with @widget
11382 gtk_widget_get_accessible (GtkWidget *widget)
11384 GtkWidgetClass *klass;
11386 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11388 klass = GTK_WIDGET_GET_CLASS (widget);
11390 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11392 return klass->get_accessible (widget);
11396 gtk_widget_real_get_accessible (GtkWidget *widget)
11398 AtkObject* accessible;
11400 accessible = g_object_get_qdata (G_OBJECT (widget),
11401 quark_accessible_object);
11404 GtkWidgetClass *widget_class;
11405 GtkWidgetClassPrivate *priv;
11406 AtkObjectFactory *factory;
11407 AtkRegistry *default_registry;
11409 widget_class = GTK_WIDGET_GET_CLASS (widget);
11410 priv = widget_class->priv;
11412 if (priv->accessible_type == GTK_TYPE_ACCESSIBLE)
11414 default_registry = atk_get_default_registry ();
11415 factory = atk_registry_get_factory (default_registry,
11416 G_TYPE_FROM_INSTANCE (widget));
11418 atk_object_factory_create_accessible (factory,
11419 G_OBJECT (widget));
11421 if (priv->accessible_role != ATK_ROLE_INVALID)
11422 atk_object_set_role (accessible, priv->accessible_role);
11424 g_object_set_qdata (G_OBJECT (widget),
11425 quark_accessible_object,
11430 accessible = g_object_new (priv->accessible_type,
11433 if (priv->accessible_role != ATK_ROLE_INVALID)
11434 atk_object_set_role (accessible, priv->accessible_role);
11436 g_object_set_qdata (G_OBJECT (widget),
11437 quark_accessible_object,
11440 atk_object_initialize (accessible, widget);
11442 /* Set the role again, since we don't want a role set
11443 * in some parent initialize() function to override
11446 if (priv->accessible_role != ATK_ROLE_INVALID)
11447 atk_object_set_role (accessible, priv->accessible_role);
11454 * Initialize a AtkImplementorIface instance's virtual pointers as
11455 * appropriate to this implementor's class (GtkWidget).
11458 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11460 iface->ref_accessible = gtk_widget_ref_accessible;
11464 gtk_widget_ref_accessible (AtkImplementor *implementor)
11466 AtkObject *accessible;
11468 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11470 g_object_ref (accessible);
11475 * Expand flag management
11479 gtk_widget_update_computed_expand (GtkWidget *widget)
11481 GtkWidgetPrivate *priv;
11483 priv = widget->priv;
11485 if (priv->need_compute_expand)
11489 if (priv->hexpand_set)
11494 if (priv->vexpand_set)
11499 /* we don't need to use compute_expand if both expands are
11500 * forced by the app
11502 if (!(priv->hexpand_set && priv->vexpand_set))
11504 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11508 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11509 priv->hexpand_set ? &ignored : &h,
11510 priv->vexpand_set ? &ignored : &v);
11514 priv->need_compute_expand = FALSE;
11515 priv->computed_hexpand = h != FALSE;
11516 priv->computed_vexpand = v != FALSE;
11521 * gtk_widget_queue_compute_expand:
11522 * @widget: a #GtkWidget
11524 * Mark @widget as needing to recompute its expand flags. Call
11525 * this function when setting legacy expand child properties
11526 * on the child of a container.
11528 * See gtk_widget_compute_expand().
11531 gtk_widget_queue_compute_expand (GtkWidget *widget)
11534 gboolean changed_anything;
11536 if (widget->priv->need_compute_expand)
11539 changed_anything = FALSE;
11541 while (parent != NULL)
11543 if (!parent->priv->need_compute_expand)
11545 parent->priv->need_compute_expand = TRUE;
11546 changed_anything = TRUE;
11549 /* Note: if we had an invariant that "if a child needs to
11550 * compute expand, its parents also do" then we could stop going
11551 * up when we got to a parent that already needed to
11552 * compute. However, in general we compute expand lazily (as
11553 * soon as we see something in a subtree that is expand, we know
11554 * we're expanding) and so this invariant does not hold and we
11555 * have to always walk all the way up in case some ancestor
11556 * is not currently need_compute_expand.
11559 parent = parent->priv->parent;
11562 /* recomputing expand always requires
11563 * a relayout as well
11565 if (changed_anything)
11566 gtk_widget_queue_resize (widget);
11570 * gtk_widget_compute_expand:
11571 * @widget: the widget
11572 * @orientation: expand direction
11574 * Computes whether a container should give this widget extra space
11575 * when possible. Containers should check this, rather than
11576 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11578 * This function already checks whether the widget is visible, so
11579 * visibility does not need to be checked separately. Non-visible
11580 * widgets are not expanded.
11582 * The computed expand value uses either the expand setting explicitly
11583 * set on the widget itself, or, if none has been explicitly set,
11584 * the widget may expand if some of its children do.
11586 * Return value: whether widget tree rooted here should be expanded
11589 gtk_widget_compute_expand (GtkWidget *widget,
11590 GtkOrientation orientation)
11592 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11594 /* We never make a widget expand if not even showing. */
11595 if (!gtk_widget_get_visible (widget))
11598 gtk_widget_update_computed_expand (widget);
11600 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11602 return widget->priv->computed_hexpand;
11606 return widget->priv->computed_vexpand;
11611 gtk_widget_set_expand (GtkWidget *widget,
11612 GtkOrientation orientation,
11615 const char *expand_prop;
11616 const char *expand_set_prop;
11618 GtkWidgetPrivate *priv;
11620 g_return_if_fail (GTK_IS_WIDGET (widget));
11622 priv = widget->priv;
11624 expand = expand != FALSE;
11626 was_both = priv->hexpand && priv->vexpand;
11628 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11630 if (priv->hexpand_set &&
11631 priv->hexpand == expand)
11634 priv->hexpand_set = TRUE;
11635 priv->hexpand = expand;
11637 expand_prop = "hexpand";
11638 expand_set_prop = "hexpand-set";
11642 if (priv->vexpand_set &&
11643 priv->vexpand == expand)
11646 priv->vexpand_set = TRUE;
11647 priv->vexpand = expand;
11649 expand_prop = "vexpand";
11650 expand_set_prop = "vexpand-set";
11653 gtk_widget_queue_compute_expand (widget);
11655 g_object_freeze_notify (G_OBJECT (widget));
11656 g_object_notify (G_OBJECT (widget), expand_prop);
11657 g_object_notify (G_OBJECT (widget), expand_set_prop);
11658 if (was_both != (priv->hexpand && priv->vexpand))
11659 g_object_notify (G_OBJECT (widget), "expand");
11660 g_object_thaw_notify (G_OBJECT (widget));
11664 gtk_widget_set_expand_set (GtkWidget *widget,
11665 GtkOrientation orientation,
11668 GtkWidgetPrivate *priv;
11671 priv = widget->priv;
11673 set = set != FALSE;
11675 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11677 if (set == priv->hexpand_set)
11680 priv->hexpand_set = set;
11681 prop = "hexpand-set";
11685 if (set == priv->vexpand_set)
11688 priv->vexpand_set = set;
11689 prop = "vexpand-set";
11692 gtk_widget_queue_compute_expand (widget);
11694 g_object_notify (G_OBJECT (widget), prop);
11698 * gtk_widget_get_hexpand:
11699 * @widget: the widget
11701 * Gets whether the widget would like any available extra horizontal
11702 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11703 * generally receive the extra space. For example, a list or
11704 * scrollable area or document in your window would often be set to
11707 * Containers should use gtk_widget_compute_expand() rather than
11708 * this function, to see whether a widget, or any of its children,
11709 * has the expand flag set. If any child of a widget wants to
11710 * expand, the parent may ask to expand also.
11712 * This function only looks at the widget's own hexpand flag, rather
11713 * than computing whether the entire widget tree rooted at this widget
11716 * Return value: whether hexpand flag is set
11719 gtk_widget_get_hexpand (GtkWidget *widget)
11721 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11723 return widget->priv->hexpand;
11727 * gtk_widget_set_hexpand:
11728 * @widget: the widget
11729 * @expand: whether to expand
11731 * Sets whether the widget would like any available extra horizontal
11732 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11733 * generally receive the extra space. For example, a list or
11734 * scrollable area or document in your window would often be set to
11737 * Call this function to set the expand flag if you would like your
11738 * widget to become larger horizontally when the window has extra
11741 * By default, widgets automatically expand if any of their children
11742 * want to expand. (To see if a widget will automatically expand given
11743 * its current children and state, call gtk_widget_compute_expand(). A
11744 * container can decide how the expandability of children affects the
11745 * expansion of the container by overriding the compute_expand virtual
11746 * method on #GtkWidget.).
11748 * Setting hexpand explicitly with this function will override the
11749 * automatic expand behavior.
11751 * This function forces the widget to expand or not to expand,
11752 * regardless of children. The override occurs because
11753 * gtk_widget_set_hexpand() sets the hexpand-set property (see
11754 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
11755 * value to be used, rather than looking at children and widget state.
11758 gtk_widget_set_hexpand (GtkWidget *widget,
11761 g_return_if_fail (GTK_IS_WIDGET (widget));
11763 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
11767 * gtk_widget_get_hexpand_set:
11768 * @widget: the widget
11770 * Gets whether gtk_widget_set_hexpand() has been used to
11771 * explicitly set the expand flag on this widget.
11773 * If hexpand is set, then it overrides any computed
11774 * expand value based on child widgets. If hexpand is not
11775 * set, then the expand value depends on whether any
11776 * children of the widget would like to expand.
11778 * There are few reasons to use this function, but it's here
11779 * for completeness and consistency.
11781 * Return value: whether hexpand has been explicitly set
11784 gtk_widget_get_hexpand_set (GtkWidget *widget)
11786 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11788 return widget->priv->hexpand_set;
11792 * gtk_widget_set_hexpand_set:
11793 * @widget: the widget
11794 * @set: value for hexpand-set property
11796 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
11799 * The hexpand-set property will be set automatically when you call
11800 * gtk_widget_set_hexpand() to set hexpand, so the most likely
11801 * reason to use this function would be to unset an explicit expand
11804 * If hexpand is set, then it overrides any computed
11805 * expand value based on child widgets. If hexpand is not
11806 * set, then the expand value depends on whether any
11807 * children of the widget would like to expand.
11809 * There are few reasons to use this function, but it's here
11810 * for completeness and consistency.
11813 gtk_widget_set_hexpand_set (GtkWidget *widget,
11816 g_return_if_fail (GTK_IS_WIDGET (widget));
11818 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
11823 * gtk_widget_get_vexpand:
11824 * @widget: the widget
11826 * Gets whether the widget would like any available extra vertical
11829 * See gtk_widget_get_hexpand() for more detail.
11831 * Return value: whether vexpand flag is set
11834 gtk_widget_get_vexpand (GtkWidget *widget)
11836 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11838 return widget->priv->vexpand;
11842 * gtk_widget_set_vexpand:
11843 * @widget: the widget
11844 * @expand: whether to expand
11846 * Sets whether the widget would like any available extra vertical
11849 * See gtk_widget_set_hexpand() for more detail.
11852 gtk_widget_set_vexpand (GtkWidget *widget,
11855 g_return_if_fail (GTK_IS_WIDGET (widget));
11857 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
11861 * gtk_widget_get_vexpand_set:
11862 * @widget: the widget
11864 * Gets whether gtk_widget_set_vexpand() has been used to
11865 * explicitly set the expand flag on this widget.
11867 * See gtk_widget_get_hexpand_set() for more detail.
11869 * Return value: whether vexpand has been explicitly set
11872 gtk_widget_get_vexpand_set (GtkWidget *widget)
11874 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11876 return widget->priv->vexpand_set;
11880 * gtk_widget_set_vexpand_set:
11881 * @widget: the widget
11882 * @set: value for vexpand-set property
11884 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
11887 * See gtk_widget_set_hexpand_set() for more detail.
11890 gtk_widget_set_vexpand_set (GtkWidget *widget,
11893 g_return_if_fail (GTK_IS_WIDGET (widget));
11895 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
11899 * GtkBuildable implementation
11901 static GQuark quark_builder_has_default = 0;
11902 static GQuark quark_builder_has_focus = 0;
11903 static GQuark quark_builder_atk_relations = 0;
11904 static GQuark quark_builder_set_name = 0;
11907 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
11909 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
11910 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
11911 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
11912 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
11914 iface->set_name = gtk_widget_buildable_set_name;
11915 iface->get_name = gtk_widget_buildable_get_name;
11916 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
11917 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
11918 iface->parser_finished = gtk_widget_buildable_parser_finished;
11919 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
11920 iface->custom_finished = gtk_widget_buildable_custom_finished;
11924 gtk_widget_buildable_set_name (GtkBuildable *buildable,
11927 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
11928 g_strdup (name), g_free);
11931 static const gchar *
11932 gtk_widget_buildable_get_name (GtkBuildable *buildable)
11934 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
11938 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
11939 GtkBuilder *builder,
11940 const gchar *childname)
11942 if (strcmp (childname, "accessible") == 0)
11943 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
11949 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
11950 GtkBuilder *builder,
11952 const GValue *value)
11954 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
11955 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
11956 GINT_TO_POINTER (TRUE));
11957 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
11958 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
11959 GINT_TO_POINTER (TRUE));
11961 g_object_set_property (G_OBJECT (buildable), name, value);
11966 gchar *action_name;
11967 GString *description;
11969 gboolean translatable;
11979 free_action (AtkActionData *data, gpointer user_data)
11981 g_free (data->action_name);
11982 g_string_free (data->description, TRUE);
11983 g_free (data->context);
11984 g_slice_free (AtkActionData, data);
11988 free_relation (AtkRelationData *data, gpointer user_data)
11990 g_free (data->target);
11991 g_free (data->type);
11992 g_slice_free (AtkRelationData, data);
11996 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
11997 GtkBuilder *builder)
11999 GSList *atk_relations;
12001 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12002 gtk_widget_grab_default (GTK_WIDGET (buildable));
12003 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12004 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12006 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12007 quark_builder_atk_relations);
12010 AtkObject *accessible;
12011 AtkRelationSet *relation_set;
12014 AtkRelationType relation_type;
12015 AtkObject *target_accessible;
12017 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12018 relation_set = atk_object_ref_relation_set (accessible);
12020 for (l = atk_relations; l; l = l->next)
12022 AtkRelationData *relation = (AtkRelationData*)l->data;
12024 target = gtk_builder_get_object (builder, relation->target);
12027 g_warning ("Target object %s in <relation> does not exist",
12031 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12032 g_assert (target_accessible != NULL);
12034 relation_type = atk_relation_type_for_name (relation->type);
12035 if (relation_type == ATK_RELATION_NULL)
12037 g_warning ("<relation> type %s not found",
12041 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12042 target_accessible);
12044 g_object_unref (relation_set);
12046 g_slist_free_full (atk_relations, (GDestroyNotify) free_relation);
12047 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12056 } AccessibilitySubParserData;
12059 accessibility_start_element (GMarkupParseContext *context,
12060 const gchar *element_name,
12061 const gchar **names,
12062 const gchar **values,
12063 gpointer user_data,
12066 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12068 gint line_number, char_number;
12070 if (strcmp (element_name, "relation") == 0)
12072 gchar *target = NULL;
12073 gchar *type = NULL;
12074 AtkRelationData *relation;
12076 for (i = 0; names[i]; i++)
12078 if (strcmp (names[i], "target") == 0)
12079 target = g_strdup (values[i]);
12080 else if (strcmp (names[i], "type") == 0)
12081 type = g_strdup (values[i]);
12084 g_markup_parse_context_get_position (context,
12087 g_set_error (error,
12089 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12090 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12092 line_number, char_number, names[i], "relation");
12099 if (!target || !type)
12101 g_markup_parse_context_get_position (context,
12104 g_set_error (error,
12106 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12107 "%s:%d:%d <%s> requires attribute \"%s\"",
12109 line_number, char_number, "relation",
12110 type ? "target" : "type");
12116 relation = g_slice_new (AtkRelationData);
12117 relation->target = target;
12118 relation->type = type;
12120 data->relations = g_slist_prepend (data->relations, relation);
12122 else if (strcmp (element_name, "action") == 0)
12124 const gchar *action_name = NULL;
12125 const gchar *description = NULL;
12126 const gchar *msg_context = NULL;
12127 gboolean translatable = FALSE;
12128 AtkActionData *action;
12130 for (i = 0; names[i]; i++)
12132 if (strcmp (names[i], "action_name") == 0)
12133 action_name = values[i];
12134 else if (strcmp (names[i], "description") == 0)
12135 description = values[i];
12136 else if (strcmp (names[i], "translatable") == 0)
12138 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12141 else if (strcmp (names[i], "comments") == 0)
12143 /* do nothing, comments are for translators */
12145 else if (strcmp (names[i], "context") == 0)
12146 msg_context = values[i];
12149 g_markup_parse_context_get_position (context,
12152 g_set_error (error,
12154 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12155 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12157 line_number, char_number, names[i], "action");
12164 g_markup_parse_context_get_position (context,
12167 g_set_error (error,
12169 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12170 "%s:%d:%d <%s> requires attribute \"%s\"",
12172 line_number, char_number, "action",
12177 action = g_slice_new (AtkActionData);
12178 action->action_name = g_strdup (action_name);
12179 action->description = g_string_new (description);
12180 action->context = g_strdup (msg_context);
12181 action->translatable = translatable;
12183 data->actions = g_slist_prepend (data->actions, action);
12185 else if (strcmp (element_name, "accessibility") == 0)
12188 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12192 accessibility_text (GMarkupParseContext *context,
12195 gpointer user_data,
12198 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12200 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12202 AtkActionData *action = data->actions->data;
12204 g_string_append_len (action->description, text, text_len);
12208 static const GMarkupParser accessibility_parser =
12210 accessibility_start_element,
12212 accessibility_text,
12221 } AccelGroupParserData;
12224 accel_group_start_element (GMarkupParseContext *context,
12225 const gchar *element_name,
12226 const gchar **names,
12227 const gchar **values,
12228 gpointer user_data,
12233 guint modifiers = 0;
12234 gchar *signal = NULL;
12235 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12237 for (i = 0; names[i]; i++)
12239 if (strcmp (names[i], "key") == 0)
12240 key = gdk_keyval_from_name (values[i]);
12241 else if (strcmp (names[i], "modifiers") == 0)
12243 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12249 else if (strcmp (names[i], "signal") == 0)
12250 signal = g_strdup (values[i]);
12253 if (key == 0 || signal == NULL)
12255 g_warning ("<accelerator> requires key and signal attributes");
12258 parser_data->key = key;
12259 parser_data->modifiers = modifiers;
12260 parser_data->signal = signal;
12263 static const GMarkupParser accel_group_parser =
12265 accel_group_start_element,
12274 style_start_element (GMarkupParseContext *context,
12275 const gchar *element_name,
12276 const gchar **names,
12277 const gchar **values,
12278 gpointer user_data,
12281 StyleParserData *style_data = (StyleParserData *)user_data;
12284 if (strcmp (element_name, "class") == 0)
12286 if (g_markup_collect_attributes (element_name,
12290 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12291 G_MARKUP_COLLECT_INVALID))
12293 style_data->classes = g_slist_append (style_data->classes, class_name);
12296 else if (strcmp (element_name, "style") == 0)
12299 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12302 static const GMarkupParser style_parser =
12304 style_start_element,
12308 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12309 GtkBuilder *builder,
12311 const gchar *tagname,
12312 GMarkupParser *parser,
12315 g_assert (buildable);
12317 if (strcmp (tagname, "accelerator") == 0)
12319 AccelGroupParserData *parser_data;
12321 parser_data = g_slice_new0 (AccelGroupParserData);
12322 parser_data->object = g_object_ref (buildable);
12323 *parser = accel_group_parser;
12324 *data = parser_data;
12327 if (strcmp (tagname, "accessibility") == 0)
12329 AccessibilitySubParserData *parser_data;
12331 parser_data = g_slice_new0 (AccessibilitySubParserData);
12332 *parser = accessibility_parser;
12333 *data = parser_data;
12336 if (strcmp (tagname, "style") == 0)
12338 StyleParserData *parser_data;
12340 parser_data = g_slice_new0 (StyleParserData);
12341 *parser = style_parser;
12342 *data = parser_data;
12350 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12351 GtkWidget *toplevel,
12352 gpointer user_data)
12354 AccelGroupParserData *accel_data;
12355 GSList *accel_groups;
12356 GtkAccelGroup *accel_group;
12358 g_return_if_fail (GTK_IS_WIDGET (widget));
12359 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12360 g_return_if_fail (user_data != NULL);
12362 accel_data = (AccelGroupParserData*)user_data;
12363 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12364 if (g_slist_length (accel_groups) == 0)
12366 accel_group = gtk_accel_group_new ();
12367 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12371 g_assert (g_slist_length (accel_groups) == 1);
12372 accel_group = g_slist_nth_data (accel_groups, 0);
12375 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12376 accel_data->signal,
12379 accel_data->modifiers,
12380 GTK_ACCEL_VISIBLE);
12382 g_object_unref (accel_data->object);
12383 g_free (accel_data->signal);
12384 g_slice_free (AccelGroupParserData, accel_data);
12388 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12389 GtkBuilder *builder,
12391 const gchar *tagname,
12392 gpointer user_data)
12394 if (strcmp (tagname, "accelerator") == 0)
12396 AccelGroupParserData *accel_data;
12397 GtkWidget *toplevel;
12399 accel_data = (AccelGroupParserData*)user_data;
12400 g_assert (accel_data->object);
12402 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12404 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12406 else if (strcmp (tagname, "accessibility") == 0)
12408 AccessibilitySubParserData *a11y_data;
12410 a11y_data = (AccessibilitySubParserData*)user_data;
12412 if (a11y_data->actions)
12414 AtkObject *accessible;
12419 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12421 if (ATK_IS_ACTION (accessible))
12423 action = ATK_ACTION (accessible);
12424 n_actions = atk_action_get_n_actions (action);
12426 for (l = a11y_data->actions; l; l = l->next)
12428 AtkActionData *action_data = (AtkActionData*)l->data;
12430 for (i = 0; i < n_actions; i++)
12431 if (strcmp (atk_action_get_name (action, i),
12432 action_data->action_name) == 0)
12437 gchar *description;
12439 if (action_data->translatable && action_data->description->len)
12440 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12441 action_data->context,
12442 action_data->description->str);
12444 description = action_data->description->str;
12446 atk_action_set_description (action, i, description);
12451 g_warning ("accessibility action on a widget that does not implement AtkAction");
12453 g_slist_free_full (a11y_data->actions, (GDestroyNotify) free_action);
12456 if (a11y_data->relations)
12457 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12458 a11y_data->relations);
12460 g_slice_free (AccessibilitySubParserData, a11y_data);
12462 else if (strcmp (tagname, "style") == 0)
12464 StyleParserData *style_data = (StyleParserData *)user_data;
12465 GtkStyleContext *context;
12468 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
12470 for (l = style_data->classes; l; l = l->next)
12471 gtk_style_context_add_class (context, (const gchar *)l->data);
12473 gtk_widget_reset_style (GTK_WIDGET (buildable));
12475 g_slist_free_full (style_data->classes, g_free);
12476 g_slice_free (StyleParserData, style_data);
12480 static GtkSizeRequestMode
12481 gtk_widget_real_get_request_mode (GtkWidget *widget)
12483 /* By default widgets dont trade size at all. */
12484 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
12488 gtk_widget_real_get_width (GtkWidget *widget,
12489 gint *minimum_size,
12490 gint *natural_size)
12500 gtk_widget_real_get_height (GtkWidget *widget,
12501 gint *minimum_size,
12502 gint *natural_size)
12512 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12514 gint *minimum_height,
12515 gint *natural_height)
12517 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12521 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12523 gint *minimum_width,
12524 gint *natural_width)
12526 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12530 * gtk_widget_get_halign:
12531 * @widget: a #GtkWidget
12533 * Gets the value of the #GtkWidget:halign property.
12535 * Returns: the horizontal alignment of @widget
12538 gtk_widget_get_halign (GtkWidget *widget)
12540 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12541 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12545 * gtk_widget_set_halign:
12546 * @widget: a #GtkWidget
12547 * @align: the horizontal alignment
12549 * Sets the horizontal alignment of @widget.
12550 * See the #GtkWidget:halign property.
12553 gtk_widget_set_halign (GtkWidget *widget,
12556 GtkWidgetAuxInfo *aux_info;
12558 g_return_if_fail (GTK_IS_WIDGET (widget));
12560 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12562 if (aux_info->halign == align)
12565 aux_info->halign = align;
12566 gtk_widget_queue_resize (widget);
12567 g_object_notify (G_OBJECT (widget), "halign");
12571 * gtk_widget_get_valign:
12572 * @widget: a #GtkWidget
12574 * Gets the value of the #GtkWidget:valign property.
12576 * Returns: the vertical alignment of @widget
12579 gtk_widget_get_valign (GtkWidget *widget)
12581 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12582 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12586 * gtk_widget_set_valign:
12587 * @widget: a #GtkWidget
12588 * @align: the vertical alignment
12590 * Sets the vertical alignment of @widget.
12591 * See the #GtkWidget:valign property.
12594 gtk_widget_set_valign (GtkWidget *widget,
12597 GtkWidgetAuxInfo *aux_info;
12599 g_return_if_fail (GTK_IS_WIDGET (widget));
12601 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12603 if (aux_info->valign == align)
12606 aux_info->valign = align;
12607 gtk_widget_queue_resize (widget);
12608 g_object_notify (G_OBJECT (widget), "valign");
12612 * gtk_widget_get_margin_left:
12613 * @widget: a #GtkWidget
12615 * Gets the value of the #GtkWidget:margin-left property.
12617 * Returns: The left margin of @widget
12622 gtk_widget_get_margin_left (GtkWidget *widget)
12624 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12626 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12630 * gtk_widget_set_margin_left:
12631 * @widget: a #GtkWidget
12632 * @margin: the left margin
12634 * Sets the left margin of @widget.
12635 * See the #GtkWidget:margin-left property.
12640 gtk_widget_set_margin_left (GtkWidget *widget,
12643 GtkWidgetAuxInfo *aux_info;
12645 g_return_if_fail (GTK_IS_WIDGET (widget));
12646 g_return_if_fail (margin <= G_MAXINT16);
12648 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12650 if (aux_info->margin.left == margin)
12653 aux_info->margin.left = margin;
12654 gtk_widget_queue_resize (widget);
12655 g_object_notify (G_OBJECT (widget), "margin-left");
12659 * gtk_widget_get_margin_right:
12660 * @widget: a #GtkWidget
12662 * Gets the value of the #GtkWidget:margin-right property.
12664 * Returns: The right margin of @widget
12669 gtk_widget_get_margin_right (GtkWidget *widget)
12671 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12673 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12677 * gtk_widget_set_margin_right:
12678 * @widget: a #GtkWidget
12679 * @margin: the right margin
12681 * Sets the right margin of @widget.
12682 * See the #GtkWidget:margin-right property.
12687 gtk_widget_set_margin_right (GtkWidget *widget,
12690 GtkWidgetAuxInfo *aux_info;
12692 g_return_if_fail (GTK_IS_WIDGET (widget));
12693 g_return_if_fail (margin <= G_MAXINT16);
12695 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12697 if (aux_info->margin.right == margin)
12700 aux_info->margin.right = margin;
12701 gtk_widget_queue_resize (widget);
12702 g_object_notify (G_OBJECT (widget), "margin-right");
12706 * gtk_widget_get_margin_top:
12707 * @widget: a #GtkWidget
12709 * Gets the value of the #GtkWidget:margin-top property.
12711 * Returns: The top margin of @widget
12716 gtk_widget_get_margin_top (GtkWidget *widget)
12718 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12720 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12724 * gtk_widget_set_margin_top:
12725 * @widget: a #GtkWidget
12726 * @margin: the top margin
12728 * Sets the top margin of @widget.
12729 * See the #GtkWidget:margin-top property.
12734 gtk_widget_set_margin_top (GtkWidget *widget,
12737 GtkWidgetAuxInfo *aux_info;
12739 g_return_if_fail (GTK_IS_WIDGET (widget));
12740 g_return_if_fail (margin <= G_MAXINT16);
12742 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12744 if (aux_info->margin.top == margin)
12747 aux_info->margin.top = margin;
12748 gtk_widget_queue_resize (widget);
12749 g_object_notify (G_OBJECT (widget), "margin-top");
12753 * gtk_widget_get_margin_bottom:
12754 * @widget: a #GtkWidget
12756 * Gets the value of the #GtkWidget:margin-bottom property.
12758 * Returns: The bottom margin of @widget
12763 gtk_widget_get_margin_bottom (GtkWidget *widget)
12765 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12767 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
12771 * gtk_widget_set_margin_bottom:
12772 * @widget: a #GtkWidget
12773 * @margin: the bottom margin
12775 * Sets the bottom margin of @widget.
12776 * See the #GtkWidget:margin-bottom property.
12781 gtk_widget_set_margin_bottom (GtkWidget *widget,
12784 GtkWidgetAuxInfo *aux_info;
12786 g_return_if_fail (GTK_IS_WIDGET (widget));
12787 g_return_if_fail (margin <= G_MAXINT16);
12789 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12791 if (aux_info->margin.bottom == margin)
12794 aux_info->margin.bottom = margin;
12795 gtk_widget_queue_resize (widget);
12796 g_object_notify (G_OBJECT (widget), "margin-bottom");
12800 * gtk_widget_get_clipboard:
12801 * @widget: a #GtkWidget
12802 * @selection: a #GdkAtom which identifies the clipboard
12803 * to use. %GDK_SELECTION_CLIPBOARD gives the
12804 * default clipboard. Another common value
12805 * is %GDK_SELECTION_PRIMARY, which gives
12806 * the primary X selection.
12808 * Returns the clipboard object for the given selection to
12809 * be used with @widget. @widget must have a #GdkDisplay
12810 * associated with it, so must be attached to a toplevel
12813 * Return value: (transfer none): the appropriate clipboard object. If no
12814 * clipboard already exists, a new one will
12815 * be created. Once a clipboard object has
12816 * been created, it is persistent for all time.
12821 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
12823 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12824 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
12826 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
12831 * gtk_widget_list_mnemonic_labels:
12832 * @widget: a #GtkWidget
12834 * Returns a newly allocated list of the widgets, normally labels, for
12835 * which this widget is the target of a mnemonic (see for example,
12836 * gtk_label_set_mnemonic_widget()).
12838 * The widgets in the list are not individually referenced. If you
12839 * want to iterate through the list and perform actions involving
12840 * callbacks that might destroy the widgets, you
12841 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
12842 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
12843 * widgets afterwards.
12845 * Return value: (element-type GtkWidget) (transfer container): the list of
12846 * mnemonic labels; free this list
12847 * with g_list_free() when you are done with it.
12852 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
12854 GList *list = NULL;
12857 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12859 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
12860 list = g_list_prepend (list, l->data);
12866 * gtk_widget_add_mnemonic_label:
12867 * @widget: a #GtkWidget
12868 * @label: a #GtkWidget that acts as a mnemonic label for @widget
12870 * Adds a widget to the list of mnemonic labels for
12871 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
12872 * list of mnemonic labels for the widget is cleared when the
12873 * widget is destroyed, so the caller must make sure to update
12874 * its internal state at this point as well, by using a connection
12875 * to the #GtkWidget::destroy signal or a weak notifier.
12880 gtk_widget_add_mnemonic_label (GtkWidget *widget,
12883 GSList *old_list, *new_list;
12885 g_return_if_fail (GTK_IS_WIDGET (widget));
12886 g_return_if_fail (GTK_IS_WIDGET (label));
12888 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12889 new_list = g_slist_prepend (old_list, label);
12891 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12892 new_list, (GDestroyNotify) g_slist_free);
12896 * gtk_widget_remove_mnemonic_label:
12897 * @widget: a #GtkWidget
12898 * @label: a #GtkWidget that was previously set as a mnemnic label for
12899 * @widget with gtk_widget_add_mnemonic_label().
12901 * Removes a widget from the list of mnemonic labels for
12902 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
12903 * must have previously been added to the list with
12904 * gtk_widget_add_mnemonic_label().
12909 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
12912 GSList *old_list, *new_list;
12914 g_return_if_fail (GTK_IS_WIDGET (widget));
12915 g_return_if_fail (GTK_IS_WIDGET (label));
12917 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12918 new_list = g_slist_remove (old_list, label);
12921 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12922 new_list, (GDestroyNotify) g_slist_free);
12926 * gtk_widget_get_no_show_all:
12927 * @widget: a #GtkWidget
12929 * Returns the current value of the #GtkWidget:no-show-all property,
12930 * which determines whether calls to gtk_widget_show_all()
12931 * will affect this widget.
12933 * Return value: the current value of the "no-show-all" property.
12938 gtk_widget_get_no_show_all (GtkWidget *widget)
12940 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12942 return widget->priv->no_show_all;
12946 * gtk_widget_set_no_show_all:
12947 * @widget: a #GtkWidget
12948 * @no_show_all: the new value for the "no-show-all" property
12950 * Sets the #GtkWidget:no-show-all property, which determines whether
12951 * calls to gtk_widget_show_all() will affect this widget.
12953 * This is mostly for use in constructing widget hierarchies with externally
12954 * controlled visibility, see #GtkUIManager.
12959 gtk_widget_set_no_show_all (GtkWidget *widget,
12960 gboolean no_show_all)
12962 g_return_if_fail (GTK_IS_WIDGET (widget));
12964 no_show_all = (no_show_all != FALSE);
12966 if (widget->priv->no_show_all != no_show_all)
12968 widget->priv->no_show_all = no_show_all;
12970 g_object_notify (G_OBJECT (widget), "no-show-all");
12976 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
12977 gboolean has_tooltip,
12980 GtkWidgetPrivate *priv = widget->priv;
12981 gboolean priv_has_tooltip;
12983 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
12984 quark_has_tooltip));
12986 if (priv_has_tooltip != has_tooltip || force)
12988 priv_has_tooltip = has_tooltip;
12990 if (priv_has_tooltip)
12992 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
12993 gdk_window_set_events (priv->window,
12994 gdk_window_get_events (priv->window) |
12995 GDK_LEAVE_NOTIFY_MASK |
12996 GDK_POINTER_MOTION_MASK |
12997 GDK_POINTER_MOTION_HINT_MASK);
12999 if (gtk_widget_get_has_window (widget))
13000 gtk_widget_add_events (widget,
13001 GDK_LEAVE_NOTIFY_MASK |
13002 GDK_POINTER_MOTION_MASK |
13003 GDK_POINTER_MOTION_HINT_MASK);
13006 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13007 GUINT_TO_POINTER (priv_has_tooltip));
13012 * gtk_widget_set_tooltip_window:
13013 * @widget: a #GtkWidget
13014 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13016 * Replaces the default, usually yellow, window used for displaying
13017 * tooltips with @custom_window. GTK+ will take care of showing and
13018 * hiding @custom_window at the right moment, to behave likewise as
13019 * the default tooltip window. If @custom_window is %NULL, the default
13020 * tooltip window will be used.
13022 * If the custom window should have the default theming it needs to
13023 * have the name "gtk-tooltip", see gtk_widget_set_name().
13028 gtk_widget_set_tooltip_window (GtkWidget *widget,
13029 GtkWindow *custom_window)
13031 gboolean has_tooltip;
13032 gchar *tooltip_markup;
13034 g_return_if_fail (GTK_IS_WIDGET (widget));
13035 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13037 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13040 g_object_ref (custom_window);
13042 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13043 custom_window, g_object_unref);
13045 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13046 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13048 if (has_tooltip && gtk_widget_get_visible (widget))
13049 gtk_widget_queue_tooltip_query (widget);
13053 * gtk_widget_get_tooltip_window:
13054 * @widget: a #GtkWidget
13056 * Returns the #GtkWindow of the current tooltip. This can be the
13057 * GtkWindow created by default, or the custom tooltip window set
13058 * using gtk_widget_set_tooltip_window().
13060 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13065 gtk_widget_get_tooltip_window (GtkWidget *widget)
13067 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13069 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13073 * gtk_widget_trigger_tooltip_query:
13074 * @widget: a #GtkWidget
13076 * Triggers a tooltip query on the display where the toplevel of @widget
13077 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13083 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13085 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13088 static guint tooltip_query_id;
13089 static GSList *tooltip_query_displays;
13092 tooltip_query_idle (gpointer data)
13094 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13095 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13096 g_slist_free (tooltip_query_displays);
13098 tooltip_query_displays = NULL;
13099 tooltip_query_id = 0;
13105 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13107 GdkDisplay *display;
13109 display = gtk_widget_get_display (widget);
13111 if (!g_slist_find (tooltip_query_displays, display))
13112 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13114 if (tooltip_query_id == 0)
13115 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13119 * gtk_widget_set_tooltip_text:
13120 * @widget: a #GtkWidget
13121 * @text: the contents of the tooltip for @widget
13123 * Sets @text as the contents of the tooltip. This function will take
13124 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13125 * handler for the #GtkWidget::query-tooltip signal.
13127 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13132 gtk_widget_set_tooltip_text (GtkWidget *widget,
13135 g_return_if_fail (GTK_IS_WIDGET (widget));
13137 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13141 * gtk_widget_get_tooltip_text:
13142 * @widget: a #GtkWidget
13144 * Gets the contents of the tooltip for @widget.
13146 * Return value: the tooltip text, or %NULL. You should free the
13147 * returned string with g_free() when done.
13152 gtk_widget_get_tooltip_text (GtkWidget *widget)
13154 gchar *text = NULL;
13156 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13158 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13164 * gtk_widget_set_tooltip_markup:
13165 * @widget: a #GtkWidget
13166 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13168 * Sets @markup as the contents of the tooltip, which is marked up with
13169 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13171 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13172 * and of the default handler for the #GtkWidget::query-tooltip signal.
13174 * See also the #GtkWidget:tooltip-markup property and
13175 * gtk_tooltip_set_markup().
13180 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13181 const gchar *markup)
13183 g_return_if_fail (GTK_IS_WIDGET (widget));
13185 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13189 * gtk_widget_get_tooltip_markup:
13190 * @widget: a #GtkWidget
13192 * Gets the contents of the tooltip for @widget.
13194 * Return value: the tooltip text, or %NULL. You should free the
13195 * returned string with g_free() when done.
13200 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13202 gchar *text = NULL;
13204 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13206 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13212 * gtk_widget_set_has_tooltip:
13213 * @widget: a #GtkWidget
13214 * @has_tooltip: whether or not @widget has a tooltip.
13216 * Sets the has-tooltip property on @widget to @has_tooltip. See
13217 * #GtkWidget:has-tooltip for more information.
13222 gtk_widget_set_has_tooltip (GtkWidget *widget,
13223 gboolean has_tooltip)
13225 g_return_if_fail (GTK_IS_WIDGET (widget));
13227 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13231 * gtk_widget_get_has_tooltip:
13232 * @widget: a #GtkWidget
13234 * Returns the current value of the has-tooltip property. See
13235 * #GtkWidget:has-tooltip for more information.
13237 * Return value: current value of has-tooltip on @widget.
13242 gtk_widget_get_has_tooltip (GtkWidget *widget)
13244 gboolean has_tooltip = FALSE;
13246 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13248 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13250 return has_tooltip;
13254 * gtk_widget_get_allocation:
13255 * @widget: a #GtkWidget
13256 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13258 * Retrieves the widget's allocation.
13260 * Note, when implementing a #GtkContainer: a widget's allocation will
13261 * be its "adjusted" allocation, that is, the widget's parent
13262 * container typically calls gtk_widget_size_allocate() with an
13263 * allocation, and that allocation is then adjusted (to handle margin
13264 * and alignment for example) before assignment to the widget.
13265 * gtk_widget_get_allocation() returns the adjusted allocation that
13266 * was actually assigned to the widget. The adjusted allocation is
13267 * guaranteed to be completely contained within the
13268 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13269 * is guaranteed that its children stay inside the assigned bounds,
13270 * but not that they have exactly the bounds the container assigned.
13271 * There is no way to get the original allocation assigned by
13272 * gtk_widget_size_allocate(), since it isn't stored; if a container
13273 * implementation needs that information it will have to track it itself.
13278 gtk_widget_get_allocation (GtkWidget *widget,
13279 GtkAllocation *allocation)
13281 GtkWidgetPrivate *priv;
13283 g_return_if_fail (GTK_IS_WIDGET (widget));
13284 g_return_if_fail (allocation != NULL);
13286 priv = widget->priv;
13288 *allocation = priv->allocation;
13292 * gtk_widget_set_allocation:
13293 * @widget: a #GtkWidget
13294 * @allocation: a pointer to a #GtkAllocation to copy from
13296 * Sets the widget's allocation. This should not be used
13297 * directly, but from within a widget's size_allocate method.
13299 * The allocation set should be the "adjusted" or actual
13300 * allocation. If you're implementing a #GtkContainer, you want to use
13301 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13302 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13303 * allocation inside gtk_widget_size_allocate() to create an adjusted
13309 gtk_widget_set_allocation (GtkWidget *widget,
13310 const GtkAllocation *allocation)
13312 GtkWidgetPrivate *priv;
13314 g_return_if_fail (GTK_IS_WIDGET (widget));
13315 g_return_if_fail (allocation != NULL);
13317 priv = widget->priv;
13319 priv->allocation = *allocation;
13323 * gtk_widget_get_allocated_width:
13324 * @widget: the widget to query
13326 * Returns the width that has currently been allocated to @widget.
13327 * This function is intended to be used when implementing handlers
13328 * for the #GtkWidget::draw function.
13330 * Returns: the width of the @widget
13333 gtk_widget_get_allocated_width (GtkWidget *widget)
13335 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13337 return widget->priv->allocation.width;
13341 * gtk_widget_get_allocated_height:
13342 * @widget: the widget to query
13344 * Returns the height that has currently been allocated to @widget.
13345 * This function is intended to be used when implementing handlers
13346 * for the #GtkWidget::draw function.
13348 * Returns: the height of the @widget
13351 gtk_widget_get_allocated_height (GtkWidget *widget)
13353 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13355 return widget->priv->allocation.height;
13359 * gtk_widget_get_requisition:
13360 * @widget: a #GtkWidget
13361 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13363 * Retrieves the widget's requisition.
13365 * This function should only be used by widget implementations in
13366 * order to figure whether the widget's requisition has actually
13367 * changed after some internal state change (so that they can call
13368 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13370 * Normally, gtk_widget_size_request() should be used.
13374 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13375 * removed, If you need to cache sizes across requests and allocations,
13376 * add an explicit cache to the widget in question instead.
13379 gtk_widget_get_requisition (GtkWidget *widget,
13380 GtkRequisition *requisition)
13382 g_return_if_fail (GTK_IS_WIDGET (widget));
13383 g_return_if_fail (requisition != NULL);
13385 gtk_widget_get_preferred_size (widget, requisition, NULL);
13389 * gtk_widget_set_window:
13390 * @widget: a #GtkWidget
13391 * @window: (transfer full): a #GdkWindow
13393 * Sets a widget's window. This function should only be used in a
13394 * widget's #GtkWidget::realize implementation. The %window passed is
13395 * usually either new window created with gdk_window_new(), or the
13396 * window of its parent widget as returned by
13397 * gtk_widget_get_parent_window().
13399 * Widgets must indicate whether they will create their own #GdkWindow
13400 * by calling gtk_widget_set_has_window(). This is usually done in the
13401 * widget's init() function.
13403 * <note><para>This function does not add any reference to @window.</para></note>
13408 gtk_widget_set_window (GtkWidget *widget,
13411 GtkWidgetPrivate *priv;
13413 g_return_if_fail (GTK_IS_WIDGET (widget));
13414 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13416 priv = widget->priv;
13418 if (priv->window != window)
13420 priv->window = window;
13421 g_object_notify (G_OBJECT (widget), "window");
13426 * gtk_widget_get_window:
13427 * @widget: a #GtkWidget
13429 * Returns the widget's window if it is realized, %NULL otherwise
13431 * Return value: (transfer none): @widget's window.
13436 gtk_widget_get_window (GtkWidget *widget)
13438 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13440 return widget->priv->window;
13444 * gtk_widget_get_support_multidevice:
13445 * @widget: a #GtkWidget
13447 * Returns %TRUE if @widget is multiple pointer aware. See
13448 * gtk_widget_set_support_multidevice() for more information.
13450 * Returns: %TRUE if @widget is multidevice aware.
13453 gtk_widget_get_support_multidevice (GtkWidget *widget)
13455 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13457 return widget->priv->multidevice;
13461 * gtk_widget_set_support_multidevice:
13462 * @widget: a #GtkWidget
13463 * @support_multidevice: %TRUE to support input from multiple devices.
13465 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13466 * @widget will start receiving multiple, per device enter/leave events. Note
13467 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13468 * gdk_window_set_support_multidevice() will have to be called manually on them.
13473 gtk_widget_set_support_multidevice (GtkWidget *widget,
13474 gboolean support_multidevice)
13476 GtkWidgetPrivate *priv;
13478 g_return_if_fail (GTK_IS_WIDGET (widget));
13480 priv = widget->priv;
13481 priv->multidevice = (support_multidevice == TRUE);
13483 if (gtk_widget_get_realized (widget))
13484 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13488 _gtk_widget_set_has_focus (GtkWidget *widget,
13489 gboolean has_focus)
13491 widget->priv->has_focus = has_focus;
13494 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
13496 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
13500 * gtk_widget_send_focus_change:
13501 * @widget: a #GtkWidget
13502 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13504 * Sends the focus change @event to @widget
13506 * This function is not meant to be used by applications. The only time it
13507 * should be used is when it is necessary for a #GtkWidget to assign focus
13508 * to a widget that is semantically owned by the first widget even though
13509 * it's not a direct child - for instance, a search entry in a floating
13510 * window similar to the quick search in #GtkTreeView.
13512 * An example of its usage is:
13515 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13517 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13518 * fevent->focus_change.in = TRUE;
13519 * fevent->focus_change.window = gtk_widget_get_window (widget);
13520 * if (fevent->focus_change.window != NULL)
13521 * g_object_ref (fevent->focus_change.window);
13523 * gtk_widget_send_focus_change (widget, fevent);
13525 * gdk_event_free (event);
13528 * Return value: the return value from the event signal emission: %TRUE
13529 * if the event was handled, and %FALSE otherwise
13534 gtk_widget_send_focus_change (GtkWidget *widget,
13539 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13540 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13542 g_object_ref (widget);
13544 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13546 res = gtk_widget_event (widget, event);
13548 g_object_notify (G_OBJECT (widget), "has-focus");
13550 g_object_unref (widget);
13556 * gtk_widget_in_destruction:
13557 * @widget: a #GtkWidget
13559 * Returns whether the widget is currently being destroyed.
13560 * This information can sometimes be used to avoid doing
13561 * unnecessary work.
13563 * Returns: %TRUE if @widget is being destroyed
13566 gtk_widget_in_destruction (GtkWidget *widget)
13568 return widget->priv->in_destruction;
13572 _gtk_widget_get_resize_pending (GtkWidget *widget)
13574 return widget->priv->resize_pending;
13578 _gtk_widget_set_resize_pending (GtkWidget *widget,
13579 gboolean resize_pending)
13581 widget->priv->resize_pending = resize_pending;
13585 _gtk_widget_get_in_reparent (GtkWidget *widget)
13587 return widget->priv->in_reparent;
13591 _gtk_widget_set_in_reparent (GtkWidget *widget,
13592 gboolean in_reparent)
13594 widget->priv->in_reparent = in_reparent;
13598 _gtk_widget_get_anchored (GtkWidget *widget)
13600 return widget->priv->anchored;
13604 _gtk_widget_set_anchored (GtkWidget *widget,
13607 widget->priv->anchored = anchored;
13611 _gtk_widget_get_shadowed (GtkWidget *widget)
13613 return widget->priv->shadowed;
13617 _gtk_widget_set_shadowed (GtkWidget *widget,
13620 widget->priv->shadowed = shadowed;
13624 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13626 return widget->priv->alloc_needed;
13630 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13631 gboolean alloc_needed)
13633 widget->priv->alloc_needed = alloc_needed;
13637 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13639 return widget->priv->width_request_needed;
13643 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13644 gboolean width_request_needed)
13646 widget->priv->width_request_needed = width_request_needed;
13650 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13652 return widget->priv->height_request_needed;
13656 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13657 gboolean height_request_needed)
13659 widget->priv->height_request_needed = height_request_needed;
13663 _gtk_widget_get_sizegroup_visited (GtkWidget *widget)
13665 return widget->priv->sizegroup_visited;
13669 _gtk_widget_set_sizegroup_visited (GtkWidget *widget,
13672 widget->priv->sizegroup_visited = visited;
13676 _gtk_widget_get_sizegroup_bumping (GtkWidget *widget)
13678 return widget->priv->sizegroup_bumping;
13682 _gtk_widget_set_sizegroup_bumping (GtkWidget *widget,
13685 widget->priv->sizegroup_bumping = bumping;
13689 _gtk_widget_add_sizegroup (GtkWidget *widget,
13694 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13695 groups = g_slist_prepend (groups, group);
13696 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13698 widget->priv->have_size_groups = TRUE;
13702 _gtk_widget_remove_sizegroup (GtkWidget *widget,
13707 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13708 groups = g_slist_remove (groups, group);
13709 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13711 widget->priv->have_size_groups = groups != NULL;
13715 _gtk_widget_get_sizegroups (GtkWidget *widget)
13717 if (widget->priv->have_size_groups)
13718 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13724 _gtk_widget_add_attached_window (GtkWidget *widget,
13727 widget->priv->attached_windows = g_list_prepend (widget->priv->attached_windows, window);
13731 _gtk_widget_remove_attached_window (GtkWidget *widget,
13734 widget->priv->attached_windows = g_list_remove (widget->priv->attached_windows, window);
13738 * gtk_widget_path_append_for_widget:
13739 * @path: a widget path
13740 * @widget: the widget to append to the widget path
13742 * Appends the data from @widget to the widget hierarchy represented
13743 * by @path. This function is a shortcut for adding information from
13744 * @widget to the given @path. This includes setting the name or
13745 * adding the style classes from @widget.
13747 * Returns: the position where the data was inserted
13752 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
13757 g_return_val_if_fail (path != NULL, 0);
13758 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13760 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
13762 if (widget->priv->name)
13763 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
13765 if (widget->priv->context)
13767 GList *classes, *l;
13769 /* Also add any persistent classes in
13770 * the style context the widget path
13772 classes = gtk_style_context_list_classes (widget->priv->context);
13774 for (l = classes; l; l = l->next)
13775 gtk_widget_path_iter_add_class (path, pos, l->data);
13777 g_list_free (classes);
13784 * gtk_widget_get_path:
13785 * @widget: a #GtkWidget
13787 * Returns the #GtkWidgetPath representing @widget, if the widget
13788 * is not connected to a toplevel widget, a partial path will be
13791 * Returns: (transfer none): The #GtkWidgetPath representing @widget
13794 gtk_widget_get_path (GtkWidget *widget)
13796 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13798 /* As strange as it may seem, this may happen on object construction.
13799 * init() implementations of parent types may eventually call this function,
13800 * each with its corresponding GType, which could leave a child
13801 * implementation with a wrong widget type in the widget path
13803 if (widget->priv->path &&
13804 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (widget->priv->path))
13806 gtk_widget_path_free (widget->priv->path);
13807 widget->priv->path = NULL;
13810 if (!widget->priv->path)
13814 parent = widget->priv->parent;
13817 widget->priv->path = gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
13820 /* Widget is either toplevel or unparented, treat both
13821 * as toplevels style wise, since there are situations
13822 * where style properties might be retrieved on that
13825 GtkWidget *attach_widget = NULL;
13827 if (GTK_IS_WINDOW (widget))
13828 attach_widget = gtk_window_get_attached_to (GTK_WINDOW (widget));
13830 if (attach_widget != NULL)
13831 widget->priv->path = gtk_widget_path_copy (gtk_widget_get_path (attach_widget));
13833 widget->priv->path = gtk_widget_path_new ();
13835 gtk_widget_path_append_for_widget (widget->priv->path, widget);
13838 if (widget->priv->context)
13839 gtk_style_context_set_path (widget->priv->context,
13840 widget->priv->path);
13843 return widget->priv->path;
13847 style_context_changed (GtkStyleContext *context,
13848 gpointer user_data)
13850 GtkWidget *widget = user_data;
13852 if (gtk_widget_get_realized (widget))
13853 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
13856 /* Compress all style updates so it
13857 * is only emitted once pre-realize.
13859 widget->priv->style_update_pending = TRUE;
13862 if (widget->priv->anchored)
13863 gtk_widget_queue_resize (widget);
13867 * gtk_widget_get_style_context:
13868 * @widget: a #GtkWidget
13870 * Returns the style context associated to @widget.
13872 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
13873 * must not be freed.
13876 gtk_widget_get_style_context (GtkWidget *widget)
13878 GtkWidgetPrivate *priv;
13879 GtkWidgetPath *path;
13881 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13883 priv = widget->priv;
13885 /* updates style context if it exists already */
13886 path = gtk_widget_get_path (widget);
13888 if (G_UNLIKELY (priv->context == NULL))
13892 priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
13893 "direction", gtk_widget_get_direction (widget),
13896 g_signal_connect (widget->priv->context, "changed",
13897 G_CALLBACK (style_context_changed), widget);
13899 screen = gtk_widget_get_screen (widget);
13902 gtk_style_context_set_screen (priv->context, screen);
13904 gtk_style_context_set_path (priv->context, path);
13906 gtk_style_context_set_parent (priv->context,
13907 gtk_widget_get_style_context (priv->parent));
13910 return widget->priv->context;
13914 * gtk_widget_get_modifier_mask:
13915 * @widget: a #GtkWidget
13916 * @intent: the use case for the modifier mask
13918 * Returns the modifier mask the @widget's windowing system backend
13919 * uses for a particular purpose.
13921 * See gdk_keymap_get_modifier_mask().
13923 * Returns: the modifier mask used for @intent.
13928 gtk_widget_get_modifier_mask (GtkWidget *widget,
13929 GdkModifierIntent intent)
13931 GdkDisplay *display;
13933 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13935 display = gtk_widget_get_display (widget);
13937 return gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
13942 _gtk_widget_get_style (GtkWidget *widget)
13944 return widget->priv->style;
13948 _gtk_widget_set_style (GtkWidget *widget,
13951 widget->priv->style = style;