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, see <http://www.gnu.org/licenses/>.
19 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include <gobject/gvaluecollector.h>
32 #include <gobject/gobjectnotifyqueue.c>
33 #include <cairo-gobject.h>
35 #include "gtkcontainer.h"
36 #include "gtkaccelmapprivate.h"
37 #include "gtkclipboard.h"
38 #include "gtkiconfactory.h"
40 #include "gtkmarshalers.h"
41 #include "gtkselectionprivate.h"
42 #include "gtksettingsprivate.h"
43 #include "gtksizegroup-private.h"
44 #include "gtkwidget.h"
45 #include "gtkwidgetprivate.h"
46 #include "gtkwindowprivate.h"
47 #include "gtkcontainerprivate.h"
48 #include "gtkbindings.h"
49 #include "gtkprivate.h"
50 #include "gtkaccessible.h"
51 #include "gtktooltip.h"
52 #include "gtkinvisible.h"
53 #include "gtkbuildable.h"
54 #include "gtkbuilderprivate.h"
55 #include "gtksizerequest.h"
56 #include "gtkstylecontextprivate.h"
57 #include "gtksymboliccolor.h"
58 #include "gtkcssprovider.h"
59 #include "gtkmodifierstyle.h"
60 #include "gtkversion.h"
63 #include "gtktypebuiltins.h"
64 #include "a11y/gtkwidgetaccessible.h"
68 * @Short_description: Base class for all widgets
71 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
72 * widget lifecycle, states and style.
74 * <refsect2 id="geometry-management">
75 * <title>Height-for-width Geometry Management</title>
77 * GTK+ uses a height-for-width (and width-for-height) geometry management
78 * system. Height-for-width means that a widget can change how much
79 * vertical space it needs, depending on the amount of horizontal space
80 * that it is given (and similar for width-for-height). The most common
81 * example is a label that reflows to fill up the available width, wraps
82 * to fewer lines, and therefore needs less height.
84 * Height-for-width geometry management is implemented in GTK+ by way
85 * of five virtual methods:
87 * <listitem>#GtkWidgetClass.get_request_mode()</listitem>
88 * <listitem>#GtkWidgetClass.get_preferred_width()</listitem>
89 * <listitem>#GtkWidgetClass.get_preferred_height()</listitem>
90 * <listitem>#GtkWidgetClass.get_preferred_height_for_width()</listitem>
91 * <listitem>#GtkWidgetClass.get_preferred_width_for_height()</listitem>
94 * There are some important things to keep in mind when implementing
95 * height-for-width and when using it in container implementations.
97 * The geometry management system will query a widget hierarchy in
98 * only one orientation at a time. When widgets are initially queried
99 * for their minimum sizes it is generally done in two initial passes
100 * in the #GtkSizeRequestMode chosen by the toplevel.
102 * For example, when queried in the normal
103 * %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode:
104 * First, the default minimum and natural width for each widget
105 * in the interface will be computed using gtk_widget_get_preferred_width().
106 * Because the preferred widths for each container depend on the preferred
107 * widths of their children, this information propagates up the hierarchy,
108 * and finally a minimum and natural width is determined for the entire
109 * toplevel. Next, the toplevel will use the minimum width to query for the
110 * minimum height contextual to that width using
111 * gtk_widget_get_preferred_height_for_width(), which will also be a highly
112 * recursive operation. The minimum height for the minimum width is normally
113 * used to set the minimum size constraint on the toplevel
114 * (unless gtk_window_set_geometry_hints() is explicitly used instead).
116 * After the toplevel window has initially requested its size in both
117 * dimensions it can go on to allocate itself a reasonable size (or a size
118 * previously specified with gtk_window_set_default_size()). During the
119 * recursive allocation process it's important to note that request cycles
120 * will be recursively executed while container widgets allocate their children.
121 * Each container widget, once allocated a size, will go on to first share the
122 * space in one orientation among its children and then request each child's
123 * height for its target allocated width or its width for allocated height,
124 * depending. In this way a #GtkWidget will typically be requested its size
125 * a number of times before actually being allocated a size. The size a
126 * widget is finally allocated can of course differ from the size it has
127 * requested. For this reason, #GtkWidget caches a small number of results
128 * to avoid re-querying for the same sizes in one allocation cycle.
130 * See <link linkend="container-geometry-management">GtkContainer's
131 * geometry management section</link>
132 * to learn more about how height-for-width allocations are performed
133 * by container widgets.
135 * If a widget does move content around to intelligently use up the
136 * allocated size then it must support the request in both
137 * #GtkSizeRequestModes even if the widget in question only
138 * trades sizes in a single orientation.
140 * For instance, a #GtkLabel that does height-for-width word wrapping
141 * will not expect to have #GtkWidgetClass.get_preferred_height() called
142 * because that call is specific to a width-for-height request. In this
143 * case the label must return the height required for its own minimum
144 * possible width. By following this rule any widget that handles
145 * height-for-width or width-for-height requests will always be allocated
146 * at least enough space to fit its own content.
148 * Here are some examples of how a %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH widget
149 * generally deals with width-for-height requests, for #GtkWidgetClass.get_preferred_height()
151 * <programlisting><![CDATA[
153 * foo_widget_get_preferred_height (GtkWidget *widget, gint *min_height, gint *nat_height)
155 * if (i_am_in_height_for_width_mode)
159 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
160 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width,
161 * min_height, nat_height);
165 * ... some widgets do both. For instance, if a GtkLabel is rotated to 90 degrees
166 * it will return the minimum and natural height for the rotated label here.
169 * ]]></programlisting>
171 * And in #GtkWidgetClass.get_preferred_width_for_height() it will simply return
172 * the minimum and natural width:
174 * <programlisting><![CDATA[
176 * foo_widget_get_preferred_width_for_height (GtkWidget *widget, gint for_height,
177 * gint *min_width, gint *nat_width)
179 * if (i_am_in_height_for_width_mode)
181 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, min_width, nat_width);
185 * ... again if a widget is sometimes operating in width-for-height mode
186 * (like a rotated GtkLabel) it can go ahead and do its real width for
187 * height calculation here.
190 * ]]></programlisting>
192 * Often a widget needs to get its own request during size request or
193 * allocation. For example, when computing height it may need to also
194 * compute width. Or when deciding how to use an allocation, the widget
195 * may need to know its natural size. In these cases, the widget should
196 * be careful to call its virtual methods directly, like this:
198 * <title>Widget calling its own size request method.</title>
200 * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget),
205 * It will not work to use the wrapper functions, such as
206 * gtk_widget_get_preferred_width() inside your own size request
207 * implementation. These return a request adjusted by #GtkSizeGroup
208 * and by the #GtkWidgetClass.adjust_size_request() virtual method. If a
209 * widget used the wrappers inside its virtual method implementations,
210 * then the adjustments (such as widget margins) would be applied
211 * twice. GTK+ therefore does not allow this and will warn if you try
214 * Of course if you are getting the size request for
215 * <emphasis>another</emphasis> widget, such as a child of a
216 * container, you <emphasis>must</emphasis> use the wrapper APIs.
217 * Otherwise, you would not properly consider widget margins,
218 * #GtkSizeGroup, and so forth.
221 * <refsect2 id="style-properties">
222 * <title>Style Properties</title>
224 * <structname>GtkWidget</structname> introduces <firstterm>style
225 * properties</firstterm> - these are basically object properties that are stored
226 * not on the object, but in the style object associated to the widget. Style
227 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
228 * This mechanism is used for configuring such things as the location of the
229 * scrollbar arrows through the theme, giving theme authors more control over the
230 * look of applications without the need to write a theme engine in C.
233 * Use gtk_widget_class_install_style_property() to install style properties for
234 * a widget class, gtk_widget_class_find_style_property() or
235 * gtk_widget_class_list_style_properties() to get information about existing
236 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
237 * gtk_widget_style_get_valist() to obtain the value of a style property.
240 * <refsect2 id="GtkWidget-BUILDER-UI">
241 * <title>GtkWidget as GtkBuildable</title>
243 * The GtkWidget implementation of the GtkBuildable interface supports a
244 * custom <accelerator> element, which has attributes named key,
245 * modifiers and signal and allows to specify accelerators.
248 * <title>A UI definition fragment specifying an accelerator</title>
249 * <programlisting><![CDATA[
250 * <object class="GtkButton">
251 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
253 * ]]></programlisting>
256 * In addition to accelerators, <structname>GtkWidget</structname> also support a
257 * custom <accessible> element, which supports actions and relations.
258 * Properties on the accessible implementation of an object can be set by accessing the
259 * internal child "accessible" of a <structname>GtkWidget</structname>.
262 * <title>A UI definition fragment specifying an accessible</title>
263 * <programlisting><![CDATA[
264 * <object class="GtkButton" id="label1"/>
265 * <property name="label">I am a Label for a Button</property>
267 * <object class="GtkButton" id="button1">
269 * <action action_name="click" translatable="yes">Click the button.</action>
270 * <relation target="label1" type="labelled-by"/>
272 * <child internal-child="accessible">
273 * <object class="AtkObject" id="a11y-button1">
274 * <property name="AtkObject::name">Clickable Button</property>
278 * ]]></programlisting>
281 * Finally, GtkWidget allows style information such as style classes to
282 * be associated with widgets, using the custom <style> element:
284 * <title>A UI definition fragment specifying an style class</title>
285 * <programlisting><![CDATA[
286 * <object class="GtkButton" id="button1">
288 * <class name="my-special-button-class"/>
289 * <class name="dark-button"/>
292 * ]]></programlisting>
298 /* Add flags here that should not be propagated to children. By default,
299 * all flags will be set on children (think prelight or active), but we
300 * might want to not do this for some.
302 #define GTK_STATE_FLAGS_DONT_PROPAGATE (GTK_STATE_FLAG_FOCUSED)
303 #define GTK_STATE_FLAGS_DO_PROPAGATE (~GTK_STATE_FLAGS_DONT_PROPAGATE)
305 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
307 #define GTK_STATE_FLAGS_BITS 7
309 struct _GtkWidgetPrivate
311 /* The state of the widget. Needs to be able to hold all GtkStateFlags bits
312 * (defined in "gtkenums.h").
314 guint state_flags : GTK_STATE_FLAGS_BITS;
318 guint in_destruction : 1;
321 guint composite_child : 1;
329 guint can_default : 1;
330 guint has_default : 1;
331 guint receives_default : 1;
334 guint style_update_pending : 1;
335 guint app_paintable : 1;
336 guint double_buffered : 1;
337 guint redraw_on_alloc : 1;
338 guint no_show_all : 1;
339 guint child_visible : 1;
340 guint multidevice : 1;
341 guint has_shape_mask : 1;
342 guint in_reparent : 1;
344 /* Queue-resize related flags */
345 guint alloc_needed : 1;
346 guint width_request_needed : 1;
347 guint height_request_needed : 1;
349 /* Expand-related flags */
350 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
351 guint computed_hexpand : 1; /* computed results (composite of child flags) */
352 guint computed_vexpand : 1;
353 guint hexpand : 1; /* application-forced expand */
355 guint hexpand_set : 1; /* whether to use application-forced */
356 guint vexpand_set : 1; /* instead of computing from children */
358 /* SizeGroup related flags */
359 guint sizegroup_visited : 1;
360 guint sizegroup_bumping : 1;
361 guint have_size_groups : 1;
363 /* The widget's name. If the widget does not have a name
364 * (the name is NULL), then its name (as returned by
365 * "gtk_widget_get_name") is its class's name.
366 * Among other things, the widget name is used to determine
367 * the style to use for a widget.
371 /* The list of attached windows to this widget.
372 * We keep a list in order to call reset_style to all of them,
374 GList *attached_windows;
376 /* The style for the widget. The style contains the
377 * colors the widget should be drawn in for each state
378 * along with graphics contexts used to draw with and
379 * the font to use for text.
382 GtkStyleContext *context;
384 /* Widget's path for styling */
387 /* The widget's allocated size */
388 GtkAllocation allocation;
390 /* The widget's requested sizes */
391 SizeRequestCache requests;
393 /* actions attached to this or any parent widget */
396 /* The widget's window or its parent window if it does
397 * not have a window. (Which will be indicated by the
398 * GTK_NO_WINDOW flag being set).
402 /* The widget's parent */
405 #ifdef G_ENABLE_DEBUG
406 /* Number of gtk_widget_push_verify_invariants () */
407 guint verifying_invariants_count;
408 #endif /* G_ENABLE_DEBUG */
411 struct _GtkWidgetClassPrivate
413 GType accessible_type;
414 AtkRole accessible_role;
443 BUTTON_RELEASE_EVENT,
457 PROPERTY_NOTIFY_EVENT,
458 SELECTION_CLEAR_EVENT,
459 SELECTION_REQUEST_EVENT,
460 SELECTION_NOTIFY_EVENT,
465 VISIBILITY_NOTIFY_EVENT,
479 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_constructed (GObject *object);
556 static void gtk_widget_dispose (GObject *object);
557 static void gtk_widget_real_destroy (GtkWidget *object);
558 static void gtk_widget_finalize (GObject *object);
559 static void gtk_widget_real_show (GtkWidget *widget);
560 static void gtk_widget_real_hide (GtkWidget *widget);
561 static void gtk_widget_real_map (GtkWidget *widget);
562 static void gtk_widget_real_unmap (GtkWidget *widget);
563 static void gtk_widget_real_realize (GtkWidget *widget);
564 static void gtk_widget_real_unrealize (GtkWidget *widget);
565 static void gtk_widget_real_size_allocate (GtkWidget *widget,
566 GtkAllocation *allocation);
567 static void gtk_widget_real_style_set (GtkWidget *widget,
568 GtkStyle *previous_style);
569 static void gtk_widget_real_direction_changed(GtkWidget *widget,
570 GtkTextDirection previous_direction);
572 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
573 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
576 gboolean keyboard_tip,
577 GtkTooltip *tooltip);
578 static void gtk_widget_real_style_updated (GtkWidget *widget);
579 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
580 GtkWidgetHelpType help_type);
582 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
584 GParamSpec **pspecs);
585 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
587 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
589 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
590 GdkEventFocus *event);
591 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
592 GdkEventFocus *event);
593 static gboolean gtk_widget_real_touch_event (GtkWidget *widget,
594 GdkEventTouch *event);
595 static gboolean gtk_widget_real_focus (GtkWidget *widget,
596 GtkDirectionType direction);
597 static void gtk_widget_real_move_focus (GtkWidget *widget,
598 GtkDirectionType direction);
599 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
600 GtkDirectionType direction);
601 #ifdef G_ENABLE_DEBUG
602 static void gtk_widget_verify_invariants (GtkWidget *widget);
603 static void gtk_widget_push_verify_invariants (GtkWidget *widget);
604 static void gtk_widget_pop_verify_invariants (GtkWidget *widget);
606 #define gtk_widget_verify_invariants(widget)
607 #define gtk_widget_push_verify_invariants(widget)
608 #define gtk_widget_pop_verify_invariants(widget)
610 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
611 static void gtk_widget_update_pango_context (GtkWidget *widget);
612 static void gtk_widget_propagate_state (GtkWidget *widget,
615 static gint gtk_widget_event_internal (GtkWidget *widget,
617 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
618 gboolean group_cycling);
619 static void gtk_widget_real_get_width (GtkWidget *widget,
622 static void gtk_widget_real_get_height (GtkWidget *widget,
625 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
627 gint *minimum_height,
628 gint *natural_height);
629 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
632 gint *natural_width);
633 static void gtk_widget_real_state_flags_changed (GtkWidget *widget,
634 GtkStateFlags old_state);
635 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
636 static GtkWidgetAuxInfo* gtk_widget_get_aux_info (GtkWidget *widget,
638 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
639 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
640 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
641 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
642 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
643 cairo_region_t *region);
644 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
645 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
646 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
649 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
650 gboolean has_tooltip,
652 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
653 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
655 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
656 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
658 const gchar *childname);
659 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
662 const GValue *value);
663 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
666 const gchar *tagname,
667 GMarkupParser *parser,
669 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
672 const gchar *tagname,
674 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
675 GtkBuilder *builder);
677 static GtkSizeRequestMode gtk_widget_real_get_request_mode (GtkWidget *widget);
678 static void gtk_widget_real_get_width (GtkWidget *widget,
681 static void gtk_widget_real_get_height (GtkWidget *widget,
685 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
688 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
689 GtkOrientation orientation,
692 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
693 GtkOrientation orientation,
697 gint *allocated_size);
699 static void gtk_widget_set_usize_internal (GtkWidget *widget,
702 GtkQueueResizeFlags flags);
704 static void gtk_widget_add_events_internal (GtkWidget *widget,
707 static void gtk_widget_set_device_enabled_internal (GtkWidget *widget,
711 static gboolean event_window_is_still_viewable (GdkEvent *event);
713 /* --- variables --- */
714 static gpointer gtk_widget_parent_class = NULL;
715 static guint widget_signals[LAST_SIGNAL] = { 0 };
716 static guint composite_child_stack = 0;
717 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
718 static GParamSpecPool *style_property_spec_pool = NULL;
720 static GQuark quark_property_parser = 0;
721 static GQuark quark_aux_info = 0;
722 static GQuark quark_accel_path = 0;
723 static GQuark quark_accel_closures = 0;
724 static GQuark quark_event_mask = 0;
725 static GQuark quark_device_event_mask = 0;
726 static GQuark quark_parent_window = 0;
727 static GQuark quark_pointer_window = 0;
728 static GQuark quark_shape_info = 0;
729 static GQuark quark_input_shape_info = 0;
730 static GQuark quark_pango_context = 0;
731 static GQuark quark_accessible_object = 0;
732 static GQuark quark_mnemonic_labels = 0;
733 static GQuark quark_tooltip_markup = 0;
734 static GQuark quark_has_tooltip = 0;
735 static GQuark quark_tooltip_window = 0;
736 static GQuark quark_visual = 0;
737 static GQuark quark_modifier_style = 0;
738 static GQuark quark_enabled_devices = 0;
739 static GQuark quark_size_groups = 0;
740 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
741 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
743 /* --- functions --- */
745 gtk_widget_get_type (void)
747 static GType widget_type = 0;
749 if (G_UNLIKELY (widget_type == 0))
751 const GTypeInfo widget_info =
753 sizeof (GtkWidgetClass),
754 gtk_widget_base_class_init,
755 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
756 (GClassInitFunc) gtk_widget_class_init,
757 NULL, /* class_finalize */
758 NULL, /* class_init */
761 (GInstanceInitFunc) gtk_widget_init,
762 NULL, /* value_table */
765 const GInterfaceInfo accessibility_info =
767 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
768 (GInterfaceFinalizeFunc) NULL,
769 NULL /* interface data */
772 const GInterfaceInfo buildable_info =
774 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
775 (GInterfaceFinalizeFunc) NULL,
776 NULL /* interface data */
779 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
780 &widget_info, G_TYPE_FLAG_ABSTRACT);
782 g_type_add_class_private (widget_type, sizeof (GtkWidgetClassPrivate));
784 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
785 &accessibility_info) ;
786 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
794 gtk_widget_base_class_init (gpointer g_class)
796 GtkWidgetClass *klass = g_class;
798 klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
802 child_property_notify_dispatcher (GObject *object,
806 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
809 /* We guard against the draw signal callbacks modifying the state of the
810 * cairo context by surounding it with save/restore.
811 * Maybe we should also cairo_new_path() just to be sure?
814 gtk_widget_draw_marshaller (GClosure *closure,
815 GValue *return_value,
816 guint n_param_values,
817 const GValue *param_values,
818 gpointer invocation_hint,
819 gpointer marshal_data)
821 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
825 _gtk_marshal_BOOLEAN__BOXED (closure,
836 gtk_widget_draw_marshallerv (GClosure *closure,
837 GValue *return_value,
840 gpointer marshal_data,
847 G_VA_COPY (args_copy, args);
848 cr = va_arg (args_copy, gpointer);
852 _gtk_marshal_BOOLEAN__BOXEDv (closure,
864 gtk_widget_class_init (GtkWidgetClass *klass)
866 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
867 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
868 GtkBindingSet *binding_set;
870 gtk_widget_parent_class = g_type_class_peek_parent (klass);
872 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
873 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
874 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
875 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
876 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
877 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
878 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
879 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
880 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
881 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
882 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
883 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
884 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
885 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
886 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
887 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
888 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
889 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
890 quark_enabled_devices = g_quark_from_static_string ("gtk-widget-enabled-devices");
891 quark_size_groups = g_quark_from_static_string ("gtk-widget-size-groups");
893 style_property_spec_pool = g_param_spec_pool_new (FALSE);
894 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
895 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
896 cpn_context.dispatcher = child_property_notify_dispatcher;
897 _gtk_widget_child_property_notify_context = &cpn_context;
899 gobject_class->constructed = gtk_widget_constructed;
900 gobject_class->dispose = gtk_widget_dispose;
901 gobject_class->finalize = gtk_widget_finalize;
902 gobject_class->set_property = gtk_widget_set_property;
903 gobject_class->get_property = gtk_widget_get_property;
905 klass->destroy = gtk_widget_real_destroy;
907 klass->activate_signal = 0;
908 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
909 klass->show = gtk_widget_real_show;
910 klass->show_all = gtk_widget_show;
911 klass->hide = gtk_widget_real_hide;
912 klass->map = gtk_widget_real_map;
913 klass->unmap = gtk_widget_real_unmap;
914 klass->realize = gtk_widget_real_realize;
915 klass->unrealize = gtk_widget_real_unrealize;
916 klass->size_allocate = gtk_widget_real_size_allocate;
917 klass->get_request_mode = gtk_widget_real_get_request_mode;
918 klass->get_preferred_width = gtk_widget_real_get_width;
919 klass->get_preferred_height = gtk_widget_real_get_height;
920 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
921 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
922 klass->state_changed = NULL;
923 klass->state_flags_changed = gtk_widget_real_state_flags_changed;
924 klass->parent_set = NULL;
925 klass->hierarchy_changed = NULL;
926 klass->style_set = gtk_widget_real_style_set;
927 klass->direction_changed = gtk_widget_real_direction_changed;
928 klass->grab_notify = NULL;
929 klass->child_notify = NULL;
931 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
932 klass->grab_focus = gtk_widget_real_grab_focus;
933 klass->focus = gtk_widget_real_focus;
934 klass->move_focus = gtk_widget_real_move_focus;
935 klass->keynav_failed = gtk_widget_real_keynav_failed;
937 klass->button_press_event = NULL;
938 klass->button_release_event = NULL;
939 klass->motion_notify_event = NULL;
940 klass->touch_event = gtk_widget_real_touch_event;
941 klass->delete_event = NULL;
942 klass->destroy_event = NULL;
943 klass->key_press_event = gtk_widget_real_key_press_event;
944 klass->key_release_event = gtk_widget_real_key_release_event;
945 klass->enter_notify_event = NULL;
946 klass->leave_notify_event = NULL;
947 klass->configure_event = NULL;
948 klass->focus_in_event = gtk_widget_real_focus_in_event;
949 klass->focus_out_event = gtk_widget_real_focus_out_event;
950 klass->map_event = NULL;
951 klass->unmap_event = NULL;
952 klass->window_state_event = NULL;
953 klass->property_notify_event = _gtk_selection_property_notify;
954 klass->selection_clear_event = _gtk_selection_clear;
955 klass->selection_request_event = _gtk_selection_request;
956 klass->selection_notify_event = _gtk_selection_notify;
957 klass->selection_received = NULL;
958 klass->proximity_in_event = NULL;
959 klass->proximity_out_event = NULL;
960 klass->drag_begin = NULL;
961 klass->drag_end = NULL;
962 klass->drag_data_delete = NULL;
963 klass->drag_leave = NULL;
964 klass->drag_motion = NULL;
965 klass->drag_drop = NULL;
966 klass->drag_data_received = NULL;
967 klass->screen_changed = NULL;
968 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
969 klass->grab_broken_event = NULL;
970 klass->query_tooltip = gtk_widget_real_query_tooltip;
971 klass->style_updated = gtk_widget_real_style_updated;
973 klass->show_help = gtk_widget_real_show_help;
975 /* Accessibility support */
976 klass->priv->accessible_type = GTK_TYPE_ACCESSIBLE;
977 klass->priv->accessible_role = ATK_ROLE_INVALID;
978 klass->get_accessible = gtk_widget_real_get_accessible;
980 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
981 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
983 g_object_class_install_property (gobject_class,
985 g_param_spec_string ("name",
987 P_("The name of the widget"),
989 GTK_PARAM_READWRITE));
990 g_object_class_install_property (gobject_class,
992 g_param_spec_object ("parent",
994 P_("The parent widget of this widget. Must be a Container widget"),
996 GTK_PARAM_READWRITE));
998 g_object_class_install_property (gobject_class,
1000 g_param_spec_int ("width-request",
1001 P_("Width request"),
1002 P_("Override for width request of the widget, or -1 if natural request should be used"),
1006 GTK_PARAM_READWRITE));
1007 g_object_class_install_property (gobject_class,
1008 PROP_HEIGHT_REQUEST,
1009 g_param_spec_int ("height-request",
1010 P_("Height request"),
1011 P_("Override for height request of the widget, or -1 if natural request should be used"),
1015 GTK_PARAM_READWRITE));
1016 g_object_class_install_property (gobject_class,
1018 g_param_spec_boolean ("visible",
1020 P_("Whether the widget is visible"),
1022 GTK_PARAM_READWRITE));
1023 g_object_class_install_property (gobject_class,
1025 g_param_spec_boolean ("sensitive",
1027 P_("Whether the widget responds to input"),
1029 GTK_PARAM_READWRITE));
1030 g_object_class_install_property (gobject_class,
1032 g_param_spec_boolean ("app-paintable",
1033 P_("Application paintable"),
1034 P_("Whether the application will paint directly on the widget"),
1036 GTK_PARAM_READWRITE));
1037 g_object_class_install_property (gobject_class,
1039 g_param_spec_boolean ("can-focus",
1041 P_("Whether the widget can accept the input focus"),
1043 GTK_PARAM_READWRITE));
1044 g_object_class_install_property (gobject_class,
1046 g_param_spec_boolean ("has-focus",
1048 P_("Whether the widget has the input focus"),
1050 GTK_PARAM_READWRITE));
1051 g_object_class_install_property (gobject_class,
1053 g_param_spec_boolean ("is-focus",
1055 P_("Whether the widget is the focus widget within the toplevel"),
1057 GTK_PARAM_READWRITE));
1058 g_object_class_install_property (gobject_class,
1060 g_param_spec_boolean ("can-default",
1062 P_("Whether the widget can be the default widget"),
1064 GTK_PARAM_READWRITE));
1065 g_object_class_install_property (gobject_class,
1067 g_param_spec_boolean ("has-default",
1069 P_("Whether the widget is the default widget"),
1071 GTK_PARAM_READWRITE));
1072 g_object_class_install_property (gobject_class,
1073 PROP_RECEIVES_DEFAULT,
1074 g_param_spec_boolean ("receives-default",
1075 P_("Receives default"),
1076 P_("If TRUE, the widget will receive the default action when it is focused"),
1078 GTK_PARAM_READWRITE));
1079 g_object_class_install_property (gobject_class,
1080 PROP_COMPOSITE_CHILD,
1081 g_param_spec_boolean ("composite-child",
1082 P_("Composite child"),
1083 P_("Whether the widget is part of a composite widget"),
1085 GTK_PARAM_READABLE));
1086 g_object_class_install_property (gobject_class,
1088 g_param_spec_object ("style",
1090 P_("The style of the widget, which contains information about how it will look (colors etc)"),
1092 GTK_PARAM_READWRITE));
1093 g_object_class_install_property (gobject_class,
1095 g_param_spec_flags ("events",
1097 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1098 GDK_TYPE_EVENT_MASK,
1100 GTK_PARAM_READWRITE));
1101 g_object_class_install_property (gobject_class,
1103 g_param_spec_boolean ("no-show-all",
1105 P_("Whether gtk_widget_show_all() should not affect this widget"),
1107 GTK_PARAM_READWRITE));
1110 * GtkWidget:has-tooltip:
1112 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1113 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1114 * the widget will be queried using #GtkWidget::query-tooltip to determine
1115 * whether it will provide a tooltip or not.
1117 * Note that setting this property to %TRUE for the first time will change
1118 * the event masks of the GdkWindows of this widget to include leave-notify
1119 * and motion-notify events. This cannot and will not be undone when the
1120 * property is set to %FALSE again.
1124 g_object_class_install_property (gobject_class,
1126 g_param_spec_boolean ("has-tooltip",
1128 P_("Whether this widget has a tooltip"),
1130 GTK_PARAM_READWRITE));
1132 * GtkWidget:tooltip-text:
1134 * Sets the text of tooltip to be the given string.
1136 * Also see gtk_tooltip_set_text().
1138 * This is a convenience property which will take care of getting the
1139 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1140 * will automatically be set to %TRUE and there will be taken care of
1141 * #GtkWidget::query-tooltip in the default signal handler.
1145 g_object_class_install_property (gobject_class,
1147 g_param_spec_string ("tooltip-text",
1149 P_("The contents of the tooltip for this widget"),
1151 GTK_PARAM_READWRITE));
1153 * GtkWidget:tooltip-markup:
1155 * Sets the text of tooltip to be the given string, which is marked up
1156 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1157 * Also see gtk_tooltip_set_markup().
1159 * This is a convenience property which will take care of getting the
1160 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1161 * will automatically be set to %TRUE and there will be taken care of
1162 * #GtkWidget::query-tooltip in the default signal handler.
1166 g_object_class_install_property (gobject_class,
1167 PROP_TOOLTIP_MARKUP,
1168 g_param_spec_string ("tooltip-markup",
1169 P_("Tooltip markup"),
1170 P_("The contents of the tooltip for this widget"),
1172 GTK_PARAM_READWRITE));
1177 * The widget's window if it is realized, %NULL otherwise.
1181 g_object_class_install_property (gobject_class,
1183 g_param_spec_object ("window",
1185 P_("The widget's window if it is realized"),
1187 GTK_PARAM_READABLE));
1190 * GtkWidget:double-buffered:
1192 * Whether the widget is double buffered.
1196 g_object_class_install_property (gobject_class,
1197 PROP_DOUBLE_BUFFERED,
1198 g_param_spec_boolean ("double-buffered",
1199 P_("Double Buffered"),
1200 P_("Whether the widget is double buffered"),
1202 GTK_PARAM_READWRITE));
1207 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1211 g_object_class_install_property (gobject_class,
1213 g_param_spec_enum ("halign",
1214 P_("Horizontal Alignment"),
1215 P_("How to position in extra horizontal space"),
1218 GTK_PARAM_READWRITE));
1223 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1227 g_object_class_install_property (gobject_class,
1229 g_param_spec_enum ("valign",
1230 P_("Vertical Alignment"),
1231 P_("How to position in extra vertical space"),
1234 GTK_PARAM_READWRITE));
1237 * GtkWidget:margin-left:
1239 * Margin on left side of widget.
1241 * This property adds margin outside of the widget's normal size
1242 * request, the margin will be added in addition to the size from
1243 * gtk_widget_set_size_request() for example.
1247 g_object_class_install_property (gobject_class,
1249 g_param_spec_int ("margin-left",
1250 P_("Margin on Left"),
1251 P_("Pixels of extra space on the left side"),
1255 GTK_PARAM_READWRITE));
1258 * GtkWidget:margin-right:
1260 * Margin on right side of widget.
1262 * This property adds margin outside of the widget's normal size
1263 * request, the margin will be added in addition to the size from
1264 * gtk_widget_set_size_request() for example.
1268 g_object_class_install_property (gobject_class,
1270 g_param_spec_int ("margin-right",
1271 P_("Margin on Right"),
1272 P_("Pixels of extra space on the right side"),
1276 GTK_PARAM_READWRITE));
1279 * GtkWidget:margin-top:
1281 * Margin on top side of widget.
1283 * This property adds margin outside of the widget's normal size
1284 * request, the margin will be added in addition to the size from
1285 * gtk_widget_set_size_request() for example.
1289 g_object_class_install_property (gobject_class,
1291 g_param_spec_int ("margin-top",
1292 P_("Margin on Top"),
1293 P_("Pixels of extra space on the top side"),
1297 GTK_PARAM_READWRITE));
1300 * GtkWidget:margin-bottom:
1302 * Margin on bottom side of widget.
1304 * This property adds margin outside of the widget's normal size
1305 * request, the margin will be added in addition to the size from
1306 * gtk_widget_set_size_request() for example.
1310 g_object_class_install_property (gobject_class,
1312 g_param_spec_int ("margin-bottom",
1313 P_("Margin on Bottom"),
1314 P_("Pixels of extra space on the bottom side"),
1318 GTK_PARAM_READWRITE));
1323 * Sets all four sides' margin at once. If read, returns max
1324 * margin on any side.
1328 g_object_class_install_property (gobject_class,
1330 g_param_spec_int ("margin",
1332 P_("Pixels of extra space on all four sides"),
1336 GTK_PARAM_READWRITE));
1339 * GtkWidget::destroy:
1340 * @object: the object which received the signal
1342 * Signals that all holders of a reference to the widget should release
1343 * the reference that they hold. May result in finalization of the widget
1344 * if all references are released.
1346 widget_signals[DESTROY] =
1347 g_signal_new (I_("destroy"),
1348 G_TYPE_FROM_CLASS (gobject_class),
1349 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1350 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1352 _gtk_marshal_VOID__VOID,
1356 * GtkWidget:hexpand:
1358 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1362 g_object_class_install_property (gobject_class,
1364 g_param_spec_boolean ("hexpand",
1365 P_("Horizontal Expand"),
1366 P_("Whether widget wants more horizontal space"),
1368 GTK_PARAM_READWRITE));
1371 * GtkWidget:hexpand-set:
1373 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1377 g_object_class_install_property (gobject_class,
1379 g_param_spec_boolean ("hexpand-set",
1380 P_("Horizontal Expand Set"),
1381 P_("Whether to use the hexpand property"),
1383 GTK_PARAM_READWRITE));
1386 * GtkWidget:vexpand:
1388 * Whether to expand vertically. See gtk_widget_set_vexpand().
1392 g_object_class_install_property (gobject_class,
1394 g_param_spec_boolean ("vexpand",
1395 P_("Vertical Expand"),
1396 P_("Whether widget wants more vertical space"),
1398 GTK_PARAM_READWRITE));
1401 * GtkWidget:vexpand-set:
1403 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1407 g_object_class_install_property (gobject_class,
1409 g_param_spec_boolean ("vexpand-set",
1410 P_("Vertical Expand Set"),
1411 P_("Whether to use the vexpand property"),
1413 GTK_PARAM_READWRITE));
1418 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1422 g_object_class_install_property (gobject_class,
1424 g_param_spec_boolean ("expand",
1426 P_("Whether widget wants to expand in both directions"),
1428 GTK_PARAM_READWRITE));
1432 * @widget: the object which received the signal.
1434 widget_signals[SHOW] =
1435 g_signal_new (I_("show"),
1436 G_TYPE_FROM_CLASS (gobject_class),
1438 G_STRUCT_OFFSET (GtkWidgetClass, show),
1440 _gtk_marshal_VOID__VOID,
1445 * @widget: the object which received the signal.
1447 widget_signals[HIDE] =
1448 g_signal_new (I_("hide"),
1449 G_TYPE_FROM_CLASS (gobject_class),
1451 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1453 _gtk_marshal_VOID__VOID,
1458 * @widget: the object which received the signal.
1460 widget_signals[MAP] =
1461 g_signal_new (I_("map"),
1462 G_TYPE_FROM_CLASS (gobject_class),
1464 G_STRUCT_OFFSET (GtkWidgetClass, map),
1466 _gtk_marshal_VOID__VOID,
1471 * @widget: the object which received the signal.
1473 widget_signals[UNMAP] =
1474 g_signal_new (I_("unmap"),
1475 G_TYPE_FROM_CLASS (gobject_class),
1477 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1479 _gtk_marshal_VOID__VOID,
1483 * GtkWidget::realize:
1484 * @widget: the object which received the signal.
1486 widget_signals[REALIZE] =
1487 g_signal_new (I_("realize"),
1488 G_TYPE_FROM_CLASS (gobject_class),
1490 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1492 _gtk_marshal_VOID__VOID,
1496 * GtkWidget::unrealize:
1497 * @widget: the object which received the signal.
1499 widget_signals[UNREALIZE] =
1500 g_signal_new (I_("unrealize"),
1501 G_TYPE_FROM_CLASS (gobject_class),
1503 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1505 _gtk_marshal_VOID__VOID,
1509 * GtkWidget::size-allocate:
1510 * @widget: the object which received the signal.
1513 widget_signals[SIZE_ALLOCATE] =
1514 g_signal_new (I_("size-allocate"),
1515 G_TYPE_FROM_CLASS (gobject_class),
1517 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1519 _gtk_marshal_VOID__BOXED,
1521 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1524 * GtkWidget::state-changed:
1525 * @widget: the object which received the signal.
1526 * @state: the previous state
1528 * The ::state-changed signal is emitted when the widget state changes.
1529 * See gtk_widget_get_state().
1531 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1533 widget_signals[STATE_CHANGED] =
1534 g_signal_new (I_("state-changed"),
1535 G_TYPE_FROM_CLASS (gobject_class),
1537 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1539 _gtk_marshal_VOID__ENUM,
1541 GTK_TYPE_STATE_TYPE);
1544 * GtkWidget::state-flags-changed:
1545 * @widget: the object which received the signal.
1546 * @flags: The previous state flags.
1548 * The ::state-flags-changed signal is emitted when the widget state
1549 * changes, see gtk_widget_get_state_flags().
1553 widget_signals[STATE_FLAGS_CHANGED] =
1554 g_signal_new (I_("state-flags-changed"),
1555 G_TYPE_FROM_CLASS (gobject_class),
1557 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1559 _gtk_marshal_VOID__FLAGS,
1561 GTK_TYPE_STATE_FLAGS);
1564 * GtkWidget::parent-set:
1565 * @widget: the object on which the signal is emitted
1566 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1567 * just got its initial parent.
1569 * The ::parent-set signal is emitted when a new parent
1570 * has been set on a widget.
1572 widget_signals[PARENT_SET] =
1573 g_signal_new (I_("parent-set"),
1574 G_TYPE_FROM_CLASS (gobject_class),
1576 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1578 _gtk_marshal_VOID__OBJECT,
1583 * GtkWidget::hierarchy-changed:
1584 * @widget: the object on which the signal is emitted
1585 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1586 * if the widget was previously unanchored
1588 * The ::hierarchy-changed signal is emitted when the
1589 * anchored state of a widget changes. A widget is
1590 * <firstterm>anchored</firstterm> when its toplevel
1591 * ancestor is a #GtkWindow. This signal is emitted when
1592 * a widget changes from un-anchored to anchored or vice-versa.
1594 widget_signals[HIERARCHY_CHANGED] =
1595 g_signal_new (I_("hierarchy-changed"),
1596 G_TYPE_FROM_CLASS (gobject_class),
1598 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1600 _gtk_marshal_VOID__OBJECT,
1605 * GtkWidget::style-set:
1606 * @widget: the object on which the signal is emitted
1607 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1608 * just got its initial style
1610 * The ::style-set signal is emitted when a new style has been set
1611 * on a widget. Note that style-modifying functions like
1612 * gtk_widget_modify_base() also cause this signal to be emitted.
1614 * Note that this signal is emitted for changes to the deprecated
1615 * #GtkStyle. To track changes to the #GtkStyleContext associated
1616 * with a widget, use the #GtkWidget::style-updated signal.
1618 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1620 widget_signals[STYLE_SET] =
1621 g_signal_new (I_("style-set"),
1622 G_TYPE_FROM_CLASS (gobject_class),
1624 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1626 _gtk_marshal_VOID__OBJECT,
1631 * GtkWidget::style-updated:
1632 * @widget: the object on which the signal is emitted
1634 * The ::style-updated signal is emitted when the #GtkStyleContext
1635 * of a widget is changed. Note that style-modifying functions like
1636 * gtk_widget_override_color() also cause this signal to be emitted.
1640 widget_signals[STYLE_UPDATED] =
1641 g_signal_new (I_("style-updated"),
1642 G_TYPE_FROM_CLASS (gobject_class),
1644 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1646 g_cclosure_marshal_VOID__VOID,
1650 * GtkWidget::direction-changed:
1651 * @widget: the object on which the signal is emitted
1652 * @previous_direction: the previous text direction of @widget
1654 * The ::direction-changed signal is emitted when the text direction
1655 * of a widget changes.
1657 widget_signals[DIRECTION_CHANGED] =
1658 g_signal_new (I_("direction-changed"),
1659 G_TYPE_FROM_CLASS (gobject_class),
1661 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1663 _gtk_marshal_VOID__ENUM,
1665 GTK_TYPE_TEXT_DIRECTION);
1668 * GtkWidget::grab-notify:
1669 * @widget: the object which received the signal
1670 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1671 * if it becomes unshadowed
1673 * The ::grab-notify signal is emitted when a widget becomes
1674 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1675 * another widget, or when it becomes unshadowed due to a grab
1678 * A widget is shadowed by a gtk_grab_add() when the topmost
1679 * grab widget in the grab stack of its window group is not
1682 widget_signals[GRAB_NOTIFY] =
1683 g_signal_new (I_("grab-notify"),
1684 G_TYPE_FROM_CLASS (gobject_class),
1686 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1688 _gtk_marshal_VOID__BOOLEAN,
1693 * GtkWidget::child-notify:
1694 * @widget: the object which received the signal
1695 * @child_property: the #GParamSpec of the changed child property
1697 * The ::child-notify signal is emitted for each
1698 * <link linkend="child-properties">child property</link> that has
1699 * changed on an object. The signal's detail holds the property name.
1701 widget_signals[CHILD_NOTIFY] =
1702 g_signal_new (I_("child-notify"),
1703 G_TYPE_FROM_CLASS (gobject_class),
1704 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1705 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1707 g_cclosure_marshal_VOID__PARAM,
1713 * @widget: the object which received the signal
1714 * @cr: the cairo context to draw to
1716 * This signal is emitted when a widget is supposed to render itself.
1717 * The @widget's top left corner must be painted at the origin of
1718 * the passed in context and be sized to the values returned by
1719 * gtk_widget_get_allocated_width() and
1720 * gtk_widget_get_allocated_height().
1722 * Signal handlers connected to this signal can modify the cairo
1723 * context passed as @cr in any way they like and don't need to
1724 * restore it. The signal emission takes care of calling cairo_save()
1725 * before and cairo_restore() after invoking the handler.
1727 * Returns: %TRUE to stop other handlers from being invoked for the event.
1728 % %FALSE to propagate the event further.
1732 widget_signals[DRAW] =
1733 g_signal_new (I_("draw"),
1734 G_TYPE_FROM_CLASS (gobject_class),
1736 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1737 _gtk_boolean_handled_accumulator, NULL,
1738 gtk_widget_draw_marshaller,
1740 CAIRO_GOBJECT_TYPE_CONTEXT);
1741 g_signal_set_va_marshaller (widget_signals[DRAW], G_TYPE_FROM_CLASS (klass),
1742 gtk_widget_draw_marshallerv);
1745 * GtkWidget::mnemonic-activate:
1746 * @widget: the object which received the signal.
1749 * Returns: %TRUE to stop other handlers from being invoked for the event.
1750 * %FALSE to propagate the event further.
1752 widget_signals[MNEMONIC_ACTIVATE] =
1753 g_signal_new (I_("mnemonic-activate"),
1754 G_TYPE_FROM_CLASS (gobject_class),
1756 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1757 _gtk_boolean_handled_accumulator, NULL,
1758 _gtk_marshal_BOOLEAN__BOOLEAN,
1763 * GtkWidget::grab-focus:
1764 * @widget: the object which received the signal.
1766 widget_signals[GRAB_FOCUS] =
1767 g_signal_new (I_("grab-focus"),
1768 G_TYPE_FROM_CLASS (gobject_class),
1769 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1770 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1772 _gtk_marshal_VOID__VOID,
1777 * @widget: the object which received the signal.
1780 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1782 widget_signals[FOCUS] =
1783 g_signal_new (I_("focus"),
1784 G_TYPE_FROM_CLASS (klass),
1786 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1787 _gtk_boolean_handled_accumulator, NULL,
1788 _gtk_marshal_BOOLEAN__ENUM,
1790 GTK_TYPE_DIRECTION_TYPE);
1793 * GtkWidget::move-focus:
1794 * @widget: the object which received the signal.
1797 widget_signals[MOVE_FOCUS] =
1798 g_signal_new (I_("move-focus"),
1799 G_TYPE_FROM_CLASS (klass),
1800 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1801 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1803 _gtk_marshal_VOID__ENUM,
1806 GTK_TYPE_DIRECTION_TYPE);
1809 * GtkWidget::keynav-failed:
1810 * @widget: the object which received the signal
1811 * @direction: the direction of movement
1813 * Gets emitted if keyboard navigation fails.
1814 * See gtk_widget_keynav_failed() for details.
1816 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1817 * if the emitting widget should try to handle the keyboard
1818 * navigation attempt in its parent container(s).
1822 widget_signals[KEYNAV_FAILED] =
1823 g_signal_new (I_("keynav-failed"),
1824 G_TYPE_FROM_CLASS (klass),
1826 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1827 _gtk_boolean_handled_accumulator, NULL,
1828 _gtk_marshal_BOOLEAN__ENUM,
1830 GTK_TYPE_DIRECTION_TYPE);
1834 * @widget: the object which received the signal.
1835 * @event: the #GdkEvent which triggered this signal
1837 * The GTK+ main loop will emit three signals for each GDK event delivered
1838 * to a widget: one generic ::event signal, another, more specific,
1839 * signal that matches the type of event delivered (e.g.
1840 * #GtkWidget::key-press-event) and finally a generic
1841 * #GtkWidget::event-after signal.
1843 * Returns: %TRUE to stop other handlers from being invoked for the event
1844 * and to cancel the emission of the second specific ::event signal.
1845 * %FALSE to propagate the event further and to allow the emission of
1846 * the second signal. The ::event-after signal is emitted regardless of
1849 widget_signals[EVENT] =
1850 g_signal_new (I_("event"),
1851 G_TYPE_FROM_CLASS (klass),
1853 G_STRUCT_OFFSET (GtkWidgetClass, event),
1854 _gtk_boolean_handled_accumulator, NULL,
1855 _gtk_marshal_BOOLEAN__BOXED,
1857 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1858 g_signal_set_va_marshaller (widget_signals[EVENT], G_TYPE_FROM_CLASS (klass),
1859 _gtk_marshal_BOOLEAN__BOXEDv);
1862 * GtkWidget::event-after:
1863 * @widget: the object which received the signal.
1864 * @event: the #GdkEvent which triggered this signal
1866 * After the emission of the #GtkWidget::event signal and (optionally)
1867 * the second more specific signal, ::event-after will be emitted
1868 * regardless of the previous two signals handlers return values.
1871 widget_signals[EVENT_AFTER] =
1872 g_signal_new (I_("event-after"),
1873 G_TYPE_FROM_CLASS (klass),
1877 _gtk_marshal_VOID__BOXED,
1879 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1880 g_signal_set_va_marshaller (widget_signals[EVENT_AFTER], G_TYPE_FROM_CLASS (klass),
1881 _gtk_marshal_BOOLEAN__BOXEDv);
1884 * GtkWidget::button-press-event:
1885 * @widget: the object which received the signal.
1886 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1889 * The ::button-press-event signal will be emitted when a button
1890 * (typically from a mouse) is pressed.
1892 * To receive this signal, the #GdkWindow associated to the
1893 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1895 * This signal will be sent to the grab widget if there is one.
1897 * Returns: %TRUE to stop other handlers from being invoked for the event.
1898 * %FALSE to propagate the event further.
1900 widget_signals[BUTTON_PRESS_EVENT] =
1901 g_signal_new (I_("button-press-event"),
1902 G_TYPE_FROM_CLASS (klass),
1904 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1905 _gtk_boolean_handled_accumulator, NULL,
1906 _gtk_marshal_BOOLEAN__BOXED,
1908 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1909 g_signal_set_va_marshaller (widget_signals[BUTTON_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
1910 _gtk_marshal_BOOLEAN__BOXEDv);
1913 * GtkWidget::button-release-event:
1914 * @widget: the object which received the signal.
1915 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1918 * The ::button-release-event signal will be emitted when a button
1919 * (typically from a mouse) is released.
1921 * To receive this signal, the #GdkWindow associated to the
1922 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1924 * This signal will be sent to the grab widget if there is one.
1926 * Returns: %TRUE to stop other handlers from being invoked for the event.
1927 * %FALSE to propagate the event further.
1929 widget_signals[BUTTON_RELEASE_EVENT] =
1930 g_signal_new (I_("button-release-event"),
1931 G_TYPE_FROM_CLASS (klass),
1933 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1934 _gtk_boolean_handled_accumulator, NULL,
1935 _gtk_marshal_BOOLEAN__BOXED,
1937 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1938 g_signal_set_va_marshaller (widget_signals[BUTTON_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
1939 _gtk_marshal_BOOLEAN__BOXEDv);
1941 widget_signals[TOUCH_EVENT] =
1942 g_signal_new (I_("touch-event"),
1943 G_TYPE_FROM_CLASS (klass),
1945 G_STRUCT_OFFSET (GtkWidgetClass, touch_event),
1946 _gtk_boolean_handled_accumulator, NULL,
1947 _gtk_marshal_BOOLEAN__BOXED,
1949 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1950 g_signal_set_va_marshaller (widget_signals[TOUCH_EVENT], G_TYPE_FROM_CLASS (klass),
1951 _gtk_marshal_BOOLEAN__BOXEDv);
1954 * GtkWidget::scroll-event:
1955 * @widget: the object which received the signal.
1956 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1959 * The ::scroll-event signal is emitted when a button in the 4 to 7
1960 * range is pressed. Wheel mice are usually configured to generate
1961 * button press events for buttons 4 and 5 when the wheel is turned.
1963 * To receive this signal, the #GdkWindow associated to the widget needs
1964 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1966 * This signal will be sent to the grab widget if there is one.
1968 * Returns: %TRUE to stop other handlers from being invoked for the event.
1969 * %FALSE to propagate the event further.
1971 widget_signals[SCROLL_EVENT] =
1972 g_signal_new (I_("scroll-event"),
1973 G_TYPE_FROM_CLASS (klass),
1975 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1976 _gtk_boolean_handled_accumulator, NULL,
1977 _gtk_marshal_BOOLEAN__BOXED,
1979 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1980 g_signal_set_va_marshaller (widget_signals[SCROLL_EVENT], G_TYPE_FROM_CLASS (klass),
1981 _gtk_marshal_BOOLEAN__BOXEDv);
1984 * GtkWidget::motion-notify-event:
1985 * @widget: the object which received the signal.
1986 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1989 * The ::motion-notify-event signal is emitted when the pointer moves
1990 * over the widget's #GdkWindow.
1992 * To receive this signal, the #GdkWindow associated to the widget
1993 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1995 * This signal will be sent to the grab widget if there is one.
1997 * Returns: %TRUE to stop other handlers from being invoked for the event.
1998 * %FALSE to propagate the event further.
2000 widget_signals[MOTION_NOTIFY_EVENT] =
2001 g_signal_new (I_("motion-notify-event"),
2002 G_TYPE_FROM_CLASS (klass),
2004 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
2005 _gtk_boolean_handled_accumulator, NULL,
2006 _gtk_marshal_BOOLEAN__BOXED,
2008 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2009 g_signal_set_va_marshaller (widget_signals[MOTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2010 _gtk_marshal_BOOLEAN__BOXEDv);
2013 * GtkWidget::composited-changed:
2014 * @widget: the object on which the signal is emitted
2016 * The ::composited-changed signal is emitted when the composited
2017 * status of @widget<!-- -->s screen changes.
2018 * See gdk_screen_is_composited().
2020 widget_signals[COMPOSITED_CHANGED] =
2021 g_signal_new (I_("composited-changed"),
2022 G_TYPE_FROM_CLASS (klass),
2023 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2024 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
2026 _gtk_marshal_VOID__VOID,
2030 * GtkWidget::delete-event:
2031 * @widget: the object which received the signal
2032 * @event: the event which triggered this signal
2034 * The ::delete-event signal is emitted if a user requests that
2035 * a toplevel window is closed. The default handler for this signal
2036 * destroys the window. Connecting gtk_widget_hide_on_delete() to
2037 * this signal will cause the window to be hidden instead, so that
2038 * it can later be shown again without reconstructing it.
2040 * Returns: %TRUE to stop other handlers from being invoked for the event.
2041 * %FALSE to propagate the event further.
2043 widget_signals[DELETE_EVENT] =
2044 g_signal_new (I_("delete-event"),
2045 G_TYPE_FROM_CLASS (klass),
2047 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
2048 _gtk_boolean_handled_accumulator, NULL,
2049 _gtk_marshal_BOOLEAN__BOXED,
2051 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2052 g_signal_set_va_marshaller (widget_signals[DELETE_EVENT], G_TYPE_FROM_CLASS (klass),
2053 _gtk_marshal_BOOLEAN__BOXEDv);
2056 * GtkWidget::destroy-event:
2057 * @widget: the object which received the signal.
2058 * @event: the event which triggered this signal
2060 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
2061 * You rarely get this signal, because most widgets disconnect themselves
2062 * from their window before they destroy it, so no widget owns the
2063 * window at destroy time.
2065 * To receive this signal, the #GdkWindow associated to the widget needs
2066 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2067 * automatically for all new windows.
2069 * Returns: %TRUE to stop other handlers from being invoked for the event.
2070 * %FALSE to propagate the event further.
2072 widget_signals[DESTROY_EVENT] =
2073 g_signal_new (I_("destroy-event"),
2074 G_TYPE_FROM_CLASS (klass),
2076 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
2077 _gtk_boolean_handled_accumulator, NULL,
2078 _gtk_marshal_BOOLEAN__BOXED,
2080 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2081 g_signal_set_va_marshaller (widget_signals[DESTROY_EVENT], G_TYPE_FROM_CLASS (klass),
2082 _gtk_marshal_BOOLEAN__BOXEDv);
2085 * GtkWidget::key-press-event:
2086 * @widget: the object which received the signal
2087 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2089 * The ::key-press-event signal is emitted when a key is pressed. The signal
2090 * emission will reoccur at the key-repeat rate when the key is kept pressed.
2092 * To receive this signal, the #GdkWindow associated to the widget needs
2093 * to enable the #GDK_KEY_PRESS_MASK mask.
2095 * This signal will be sent to the grab widget if there is one.
2097 * Returns: %TRUE to stop other handlers from being invoked for the event.
2098 * %FALSE to propagate the event further.
2100 widget_signals[KEY_PRESS_EVENT] =
2101 g_signal_new (I_("key-press-event"),
2102 G_TYPE_FROM_CLASS (klass),
2104 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
2105 _gtk_boolean_handled_accumulator, NULL,
2106 _gtk_marshal_BOOLEAN__BOXED,
2108 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2109 g_signal_set_va_marshaller (widget_signals[KEY_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
2110 _gtk_marshal_BOOLEAN__BOXEDv);
2113 * GtkWidget::key-release-event:
2114 * @widget: the object which received the signal
2115 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2117 * The ::key-release-event signal is emitted when a key is released.
2119 * To receive this signal, the #GdkWindow associated to the widget needs
2120 * to enable the #GDK_KEY_RELEASE_MASK mask.
2122 * This signal will be sent to the grab widget if there is one.
2124 * Returns: %TRUE to stop other handlers from being invoked for the event.
2125 * %FALSE to propagate the event further.
2127 widget_signals[KEY_RELEASE_EVENT] =
2128 g_signal_new (I_("key-release-event"),
2129 G_TYPE_FROM_CLASS (klass),
2131 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2132 _gtk_boolean_handled_accumulator, NULL,
2133 _gtk_marshal_BOOLEAN__BOXED,
2135 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2136 g_signal_set_va_marshaller (widget_signals[KEY_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
2137 _gtk_marshal_BOOLEAN__BOXEDv);
2140 * GtkWidget::enter-notify-event:
2141 * @widget: the object which received the signal
2142 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2145 * The ::enter-notify-event will be emitted when the pointer enters
2146 * the @widget's window.
2148 * To receive this signal, the #GdkWindow associated to the widget needs
2149 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2151 * This signal will be sent to the grab widget if there is one.
2153 * Returns: %TRUE to stop other handlers from being invoked for the event.
2154 * %FALSE to propagate the event further.
2156 widget_signals[ENTER_NOTIFY_EVENT] =
2157 g_signal_new (I_("enter-notify-event"),
2158 G_TYPE_FROM_CLASS (klass),
2160 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2161 _gtk_boolean_handled_accumulator, NULL,
2162 _gtk_marshal_BOOLEAN__BOXED,
2164 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2165 g_signal_set_va_marshaller (widget_signals[ENTER_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2166 _gtk_marshal_BOOLEAN__BOXEDv);
2169 * GtkWidget::leave-notify-event:
2170 * @widget: the object which received the signal
2171 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2174 * The ::leave-notify-event will be emitted when the pointer leaves
2175 * the @widget's window.
2177 * To receive this signal, the #GdkWindow associated to the widget needs
2178 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2180 * This signal will be sent to the grab widget if there is one.
2182 * Returns: %TRUE to stop other handlers from being invoked for the event.
2183 * %FALSE to propagate the event further.
2185 widget_signals[LEAVE_NOTIFY_EVENT] =
2186 g_signal_new (I_("leave-notify-event"),
2187 G_TYPE_FROM_CLASS (klass),
2189 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2190 _gtk_boolean_handled_accumulator, NULL,
2191 _gtk_marshal_BOOLEAN__BOXED,
2193 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2194 g_signal_set_va_marshaller (widget_signals[LEAVE_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2195 _gtk_marshal_BOOLEAN__BOXEDv);
2198 * GtkWidget::configure-event:
2199 * @widget: the object which received the signal
2200 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2203 * The ::configure-event signal will be emitted when the size, position or
2204 * stacking of the @widget's window has changed.
2206 * To receive this signal, the #GdkWindow associated to the widget needs
2207 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2208 * automatically for all new windows.
2210 * Returns: %TRUE to stop other handlers from being invoked for the event.
2211 * %FALSE to propagate the event further.
2213 widget_signals[CONFIGURE_EVENT] =
2214 g_signal_new (I_("configure-event"),
2215 G_TYPE_FROM_CLASS (klass),
2217 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2218 _gtk_boolean_handled_accumulator, NULL,
2219 _gtk_marshal_BOOLEAN__BOXED,
2221 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2222 g_signal_set_va_marshaller (widget_signals[CONFIGURE_EVENT], G_TYPE_FROM_CLASS (klass),
2223 _gtk_marshal_BOOLEAN__BOXEDv);
2226 * GtkWidget::focus-in-event:
2227 * @widget: the object which received the signal
2228 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2231 * The ::focus-in-event signal will be emitted when the keyboard focus
2232 * enters the @widget's window.
2234 * To receive this signal, the #GdkWindow associated to the widget needs
2235 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2237 * Returns: %TRUE to stop other handlers from being invoked for the event.
2238 * %FALSE to propagate the event further.
2240 widget_signals[FOCUS_IN_EVENT] =
2241 g_signal_new (I_("focus-in-event"),
2242 G_TYPE_FROM_CLASS (klass),
2244 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2245 _gtk_boolean_handled_accumulator, NULL,
2246 _gtk_marshal_BOOLEAN__BOXED,
2248 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2249 g_signal_set_va_marshaller (widget_signals[FOCUS_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2250 _gtk_marshal_BOOLEAN__BOXEDv);
2253 * GtkWidget::focus-out-event:
2254 * @widget: the object which received the signal
2255 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2258 * The ::focus-out-event signal will be emitted when the keyboard focus
2259 * leaves the @widget's window.
2261 * To receive this signal, the #GdkWindow associated to the widget needs
2262 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2264 * Returns: %TRUE to stop other handlers from being invoked for the event.
2265 * %FALSE to propagate the event further.
2267 widget_signals[FOCUS_OUT_EVENT] =
2268 g_signal_new (I_("focus-out-event"),
2269 G_TYPE_FROM_CLASS (klass),
2271 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2272 _gtk_boolean_handled_accumulator, NULL,
2273 _gtk_marshal_BOOLEAN__BOXED,
2275 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2276 g_signal_set_va_marshaller (widget_signals[FOCUS_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2277 _gtk_marshal_BOOLEAN__BOXEDv);
2280 * GtkWidget::map-event:
2281 * @widget: the object which received the signal
2282 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2284 * The ::map-event signal will be emitted when the @widget's window is
2285 * mapped. A window is mapped when it becomes visible on the screen.
2287 * To receive this signal, the #GdkWindow associated to the widget needs
2288 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2289 * automatically for all new windows.
2291 * Returns: %TRUE to stop other handlers from being invoked for the event.
2292 * %FALSE to propagate the event further.
2294 widget_signals[MAP_EVENT] =
2295 g_signal_new (I_("map-event"),
2296 G_TYPE_FROM_CLASS (klass),
2298 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2299 _gtk_boolean_handled_accumulator, NULL,
2300 _gtk_marshal_BOOLEAN__BOXED,
2302 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2303 g_signal_set_va_marshaller (widget_signals[MAP_EVENT], G_TYPE_FROM_CLASS (klass),
2304 _gtk_marshal_BOOLEAN__BOXEDv);
2307 * GtkWidget::unmap-event:
2308 * @widget: the object which received the signal
2309 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2311 * The ::unmap-event signal will be emitted when the @widget's window is
2312 * unmapped. A window is unmapped when it becomes invisible on the screen.
2314 * To receive this signal, the #GdkWindow associated to the widget needs
2315 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2316 * automatically for all new windows.
2318 * Returns: %TRUE to stop other handlers from being invoked for the event.
2319 * %FALSE to propagate the event further.
2321 widget_signals[UNMAP_EVENT] =
2322 g_signal_new (I_("unmap-event"),
2323 G_TYPE_FROM_CLASS (klass),
2325 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2326 _gtk_boolean_handled_accumulator, NULL,
2327 _gtk_marshal_BOOLEAN__BOXED,
2329 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2330 g_signal_set_va_marshaller (widget_signals[UNMAP_EVENT], G_TYPE_FROM_CLASS (klass),
2331 _gtk_marshal_BOOLEAN__BOXEDv);
2334 * GtkWidget::property-notify-event:
2335 * @widget: the object which received the signal
2336 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2339 * The ::property-notify-event signal will be emitted when a property on
2340 * the @widget's window has been changed or deleted.
2342 * To receive this signal, the #GdkWindow associated to the widget needs
2343 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2345 * Returns: %TRUE to stop other handlers from being invoked for the event.
2346 * %FALSE to propagate the event further.
2348 widget_signals[PROPERTY_NOTIFY_EVENT] =
2349 g_signal_new (I_("property-notify-event"),
2350 G_TYPE_FROM_CLASS (klass),
2352 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2353 _gtk_boolean_handled_accumulator, NULL,
2354 _gtk_marshal_BOOLEAN__BOXED,
2356 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2357 g_signal_set_va_marshaller (widget_signals[PROPERTY_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2358 _gtk_marshal_BOOLEAN__BOXEDv);
2361 * GtkWidget::selection-clear-event:
2362 * @widget: the object which received the signal
2363 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2366 * The ::selection-clear-event signal will be emitted when the
2367 * the @widget's window has lost ownership of a selection.
2369 * Returns: %TRUE to stop other handlers from being invoked for the event.
2370 * %FALSE to propagate the event further.
2372 widget_signals[SELECTION_CLEAR_EVENT] =
2373 g_signal_new (I_("selection-clear-event"),
2374 G_TYPE_FROM_CLASS (klass),
2376 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2377 _gtk_boolean_handled_accumulator, NULL,
2378 _gtk_marshal_BOOLEAN__BOXED,
2380 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2381 g_signal_set_va_marshaller (widget_signals[SELECTION_CLEAR_EVENT], G_TYPE_FROM_CLASS (klass),
2382 _gtk_marshal_BOOLEAN__BOXEDv);
2385 * GtkWidget::selection-request-event:
2386 * @widget: the object which received the signal
2387 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2390 * The ::selection-request-event signal will be emitted when
2391 * another client requests ownership of the selection owned by
2392 * the @widget's window.
2394 * Returns: %TRUE to stop other handlers from being invoked for the event.
2395 * %FALSE to propagate the event further.
2397 widget_signals[SELECTION_REQUEST_EVENT] =
2398 g_signal_new (I_("selection-request-event"),
2399 G_TYPE_FROM_CLASS (klass),
2401 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2402 _gtk_boolean_handled_accumulator, NULL,
2403 _gtk_marshal_BOOLEAN__BOXED,
2405 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2406 g_signal_set_va_marshaller (widget_signals[SELECTION_REQUEST_EVENT], G_TYPE_FROM_CLASS (klass),
2407 _gtk_marshal_BOOLEAN__BOXEDv);
2410 * GtkWidget::selection-notify-event:
2411 * @widget: the object which received the signal.
2412 * @event: (type Gdk.EventSelection):
2414 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2416 widget_signals[SELECTION_NOTIFY_EVENT] =
2417 g_signal_new (I_("selection-notify-event"),
2418 G_TYPE_FROM_CLASS (klass),
2420 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2421 _gtk_boolean_handled_accumulator, NULL,
2422 _gtk_marshal_BOOLEAN__BOXED,
2424 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2425 g_signal_set_va_marshaller (widget_signals[SELECTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2426 _gtk_marshal_BOOLEAN__BOXEDv);
2429 * GtkWidget::selection-received:
2430 * @widget: the object which received the signal.
2434 widget_signals[SELECTION_RECEIVED] =
2435 g_signal_new (I_("selection-received"),
2436 G_TYPE_FROM_CLASS (klass),
2438 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2440 _gtk_marshal_VOID__BOXED_UINT,
2442 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2446 * GtkWidget::selection-get:
2447 * @widget: the object which received the signal.
2452 widget_signals[SELECTION_GET] =
2453 g_signal_new (I_("selection-get"),
2454 G_TYPE_FROM_CLASS (klass),
2456 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2458 _gtk_marshal_VOID__BOXED_UINT_UINT,
2460 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2465 * GtkWidget::proximity-in-event:
2466 * @widget: the object which received the signal
2467 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2470 * To receive this signal the #GdkWindow associated to the widget needs
2471 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2473 * This signal will be sent to the grab widget if there is one.
2475 * Returns: %TRUE to stop other handlers from being invoked for the event.
2476 * %FALSE to propagate the event further.
2478 widget_signals[PROXIMITY_IN_EVENT] =
2479 g_signal_new (I_("proximity-in-event"),
2480 G_TYPE_FROM_CLASS (klass),
2482 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2483 _gtk_boolean_handled_accumulator, NULL,
2484 _gtk_marshal_BOOLEAN__BOXED,
2486 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2487 g_signal_set_va_marshaller (widget_signals[PROXIMITY_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2488 _gtk_marshal_BOOLEAN__BOXEDv);
2491 * GtkWidget::proximity-out-event:
2492 * @widget: the object which received the signal
2493 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2496 * To receive this signal the #GdkWindow associated to the widget needs
2497 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2499 * This signal will be sent to the grab widget if there is one.
2501 * Returns: %TRUE to stop other handlers from being invoked for the event.
2502 * %FALSE to propagate the event further.
2504 widget_signals[PROXIMITY_OUT_EVENT] =
2505 g_signal_new (I_("proximity-out-event"),
2506 G_TYPE_FROM_CLASS (klass),
2508 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2509 _gtk_boolean_handled_accumulator, NULL,
2510 _gtk_marshal_BOOLEAN__BOXED,
2512 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2513 g_signal_set_va_marshaller (widget_signals[PROXIMITY_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2514 _gtk_marshal_BOOLEAN__BOXEDv);
2517 * GtkWidget::drag-leave:
2518 * @widget: the object which received the signal.
2519 * @drag_context: the drag context
2520 * @time: the timestamp of the motion event
2522 * The ::drag-leave signal is emitted on the drop site when the cursor
2523 * leaves the widget. A typical reason to connect to this signal is to
2524 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2525 * with gtk_drag_unhighlight()
2527 widget_signals[DRAG_LEAVE] =
2528 g_signal_new (I_("drag-leave"),
2529 G_TYPE_FROM_CLASS (klass),
2531 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2533 _gtk_marshal_VOID__OBJECT_UINT,
2535 GDK_TYPE_DRAG_CONTEXT,
2539 * GtkWidget::drag-begin:
2540 * @widget: the object which received the signal
2541 * @drag_context: the drag context
2543 * The ::drag-begin signal is emitted on the drag source when a drag is
2544 * started. A typical reason to connect to this signal is to set up a
2545 * custom drag icon with e.g. gtk_drag_source_set_icon_pixbuf().
2547 * Note that some widgets set up a drag icon in the default handler of
2548 * this signal, so you may have to use g_signal_connect_after() to
2549 * override what the default handler did.
2551 widget_signals[DRAG_BEGIN] =
2552 g_signal_new (I_("drag-begin"),
2553 G_TYPE_FROM_CLASS (klass),
2555 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2557 _gtk_marshal_VOID__OBJECT,
2559 GDK_TYPE_DRAG_CONTEXT);
2562 * GtkWidget::drag-end:
2563 * @widget: the object which received the signal
2564 * @drag_context: the drag context
2566 * The ::drag-end signal is emitted on the drag source when a drag is
2567 * finished. A typical reason to connect to this signal is to undo
2568 * things done in #GtkWidget::drag-begin.
2570 widget_signals[DRAG_END] =
2571 g_signal_new (I_("drag-end"),
2572 G_TYPE_FROM_CLASS (klass),
2574 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2576 _gtk_marshal_VOID__OBJECT,
2578 GDK_TYPE_DRAG_CONTEXT);
2581 * GtkWidget::drag-data-delete:
2582 * @widget: the object which received the signal
2583 * @drag_context: the drag context
2585 * The ::drag-data-delete signal is emitted on the drag source when a drag
2586 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2587 * handler is responsible for deleting the data that has been dropped. What
2588 * "delete" means depends on the context of the drag operation.
2590 widget_signals[DRAG_DATA_DELETE] =
2591 g_signal_new (I_("drag-data-delete"),
2592 G_TYPE_FROM_CLASS (klass),
2594 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2596 _gtk_marshal_VOID__OBJECT,
2598 GDK_TYPE_DRAG_CONTEXT);
2601 * GtkWidget::drag-failed:
2602 * @widget: the object which received the signal
2603 * @drag_context: the drag context
2604 * @result: the result of the drag operation
2606 * The ::drag-failed signal is emitted on the drag source when a drag has
2607 * failed. The signal handler may hook custom code to handle a failed DND
2608 * operation based on the type of error, it returns %TRUE is the failure has
2609 * been already handled (not showing the default "drag operation failed"
2610 * animation), otherwise it returns %FALSE.
2612 * Return value: %TRUE if the failed drag operation has been already handled.
2616 widget_signals[DRAG_FAILED] =
2617 g_signal_new (I_("drag-failed"),
2618 G_TYPE_FROM_CLASS (klass),
2620 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2621 _gtk_boolean_handled_accumulator, NULL,
2622 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2624 GDK_TYPE_DRAG_CONTEXT,
2625 GTK_TYPE_DRAG_RESULT);
2628 * GtkWidget::drag-motion:
2629 * @widget: the object which received the signal
2630 * @drag_context: the drag context
2631 * @x: the x coordinate of the current cursor position
2632 * @y: the y coordinate of the current cursor position
2633 * @time: the timestamp of the motion event
2635 * The drag-motion signal is emitted on the drop site when the user
2636 * moves the cursor over the widget during a drag. The signal handler
2637 * must determine whether the cursor position is in a drop zone or not.
2638 * If it is not in a drop zone, it returns %FALSE and no further processing
2639 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2640 * handler is responsible for providing the necessary information for
2641 * displaying feedback to the user, by calling gdk_drag_status().
2643 * If the decision whether the drop will be accepted or rejected can't be
2644 * made based solely on the cursor position and the type of the data, the
2645 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2646 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2647 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2648 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2649 * when using the drag-motion signal that way.
2651 * Also note that there is no drag-enter signal. The drag receiver has to
2652 * keep track of whether he has received any drag-motion signals since the
2653 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2654 * an "enter" signal. Upon an "enter", the handler will typically highlight
2655 * the drop site with gtk_drag_highlight().
2658 * drag_motion (GtkWidget *widget,
2659 * GdkDragContext *context,
2666 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2668 * if (!private_data->drag_highlight)
2670 * private_data->drag_highlight = 1;
2671 * gtk_drag_highlight (widget);
2674 * target = gtk_drag_dest_find_target (widget, context, NULL);
2675 * if (target == GDK_NONE)
2676 * gdk_drag_status (context, 0, time);
2679 * private_data->pending_status = context->suggested_action;
2680 * gtk_drag_get_data (widget, context, target, time);
2687 * drag_data_received (GtkWidget *widget,
2688 * GdkDragContext *context,
2691 * GtkSelectionData *selection_data,
2695 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2697 * if (private_data->suggested_action)
2699 * private_data->suggested_action = 0;
2701 * /* We are getting this data due to a request in drag_motion,
2702 * * rather than due to a request in drag_drop, so we are just
2703 * * supposed to call gdk_drag_status (), not actually paste in
2706 * str = gtk_selection_data_get_text (selection_data);
2707 * if (!data_is_acceptable (str))
2708 * gdk_drag_status (context, 0, time);
2710 * gdk_drag_status (context, private_data->suggested_action, time);
2714 * /* accept the drop */
2719 * Returns: whether the cursor position is in a drop zone
2721 widget_signals[DRAG_MOTION] =
2722 g_signal_new (I_("drag-motion"),
2723 G_TYPE_FROM_CLASS (klass),
2725 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2726 _gtk_boolean_handled_accumulator, NULL,
2727 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2729 GDK_TYPE_DRAG_CONTEXT,
2735 * GtkWidget::drag-drop:
2736 * @widget: the object which received the signal
2737 * @drag_context: the drag context
2738 * @x: the x coordinate of the current cursor position
2739 * @y: the y coordinate of the current cursor position
2740 * @time: the timestamp of the motion event
2742 * The ::drag-drop signal is emitted on the drop site when the user drops
2743 * the data onto the widget. The signal handler must determine whether
2744 * the cursor position is in a drop zone or not. If it is not in a drop
2745 * zone, it returns %FALSE and no further processing is necessary.
2746 * Otherwise, the handler returns %TRUE. In this case, the handler must
2747 * ensure that gtk_drag_finish() is called to let the source know that
2748 * the drop is done. The call to gtk_drag_finish() can be done either
2749 * directly or in a #GtkWidget::drag-data-received handler which gets
2750 * triggered by calling gtk_drag_get_data() to receive the data for one
2751 * or more of the supported targets.
2753 * Returns: whether the cursor position is in a drop zone
2755 widget_signals[DRAG_DROP] =
2756 g_signal_new (I_("drag-drop"),
2757 G_TYPE_FROM_CLASS (klass),
2759 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2760 _gtk_boolean_handled_accumulator, NULL,
2761 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2763 GDK_TYPE_DRAG_CONTEXT,
2769 * GtkWidget::drag-data-get:
2770 * @widget: the object which received the signal
2771 * @drag_context: the drag context
2772 * @data: the #GtkSelectionData to be filled with the dragged data
2773 * @info: the info that has been registered with the target in the
2775 * @time: the timestamp at which the data was requested
2777 * The ::drag-data-get signal is emitted on the drag source when the drop
2778 * site requests the data which is dragged. It is the responsibility of
2779 * the signal handler to fill @data with the data in the format which
2780 * is indicated by @info. See gtk_selection_data_set() and
2781 * gtk_selection_data_set_text().
2783 widget_signals[DRAG_DATA_GET] =
2784 g_signal_new (I_("drag-data-get"),
2785 G_TYPE_FROM_CLASS (klass),
2787 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2789 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2791 GDK_TYPE_DRAG_CONTEXT,
2792 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2797 * GtkWidget::drag-data-received:
2798 * @widget: the object which received the signal
2799 * @drag_context: the drag context
2800 * @x: where the drop happened
2801 * @y: where the drop happened
2802 * @data: the received data
2803 * @info: the info that has been registered with the target in the
2805 * @time: the timestamp at which the data was received
2807 * The ::drag-data-received signal is emitted on the drop site when the
2808 * dragged data has been received. If the data was received in order to
2809 * determine whether the drop will be accepted, the handler is expected
2810 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2811 * If the data was received in response to a #GtkWidget::drag-drop signal
2812 * (and this is the last target to be received), the handler for this
2813 * signal is expected to process the received data and then call
2814 * gtk_drag_finish(), setting the @success parameter depending on whether
2815 * the data was processed successfully.
2817 * The handler may inspect and modify @drag_context->action before calling
2818 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2819 * following example:
2822 * drag_data_received (GtkWidget *widget,
2823 * GdkDragContext *drag_context,
2826 * GtkSelectionData *data,
2830 * if ((data->length >= 0) && (data->format == 8))
2832 * if (drag_context->action == GDK_ACTION_ASK)
2834 * GtkWidget *dialog;
2837 * dialog = gtk_message_dialog_new (NULL,
2838 * GTK_DIALOG_MODAL |
2839 * GTK_DIALOG_DESTROY_WITH_PARENT,
2841 * GTK_BUTTONS_YES_NO,
2842 * "Move the data ?\n");
2843 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2844 * gtk_widget_destroy (dialog);
2846 * if (response == GTK_RESPONSE_YES)
2847 * drag_context->action = GDK_ACTION_MOVE;
2849 * drag_context->action = GDK_ACTION_COPY;
2852 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2856 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2860 widget_signals[DRAG_DATA_RECEIVED] =
2861 g_signal_new (I_("drag-data-received"),
2862 G_TYPE_FROM_CLASS (klass),
2864 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2866 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2868 GDK_TYPE_DRAG_CONTEXT,
2871 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2876 * GtkWidget::visibility-notify-event:
2877 * @widget: the object which received the signal
2878 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2879 * triggered this signal.
2881 * The ::visibility-notify-event will be emitted when the @widget's window
2882 * is obscured or unobscured.
2884 * To receive this signal the #GdkWindow associated to the widget needs
2885 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2887 * Returns: %TRUE to stop other handlers from being invoked for the event.
2888 * %FALSE to propagate the event further.
2890 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2891 g_signal_new (I_("visibility-notify-event"),
2892 G_TYPE_FROM_CLASS (klass),
2894 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2895 _gtk_boolean_handled_accumulator, NULL,
2896 _gtk_marshal_BOOLEAN__BOXED,
2898 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2901 * GtkWidget::window-state-event:
2902 * @widget: the object which received the signal
2903 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2904 * triggered this signal.
2906 * The ::window-state-event will be emitted when the state of the
2907 * toplevel window associated to the @widget changes.
2909 * To receive this signal the #GdkWindow associated to the widget
2910 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2911 * this mask automatically for all new windows.
2913 * Returns: %TRUE to stop other handlers from being invoked for the
2914 * event. %FALSE to propagate the event further.
2916 widget_signals[WINDOW_STATE_EVENT] =
2917 g_signal_new (I_("window-state-event"),
2918 G_TYPE_FROM_CLASS (klass),
2920 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2921 _gtk_boolean_handled_accumulator, NULL,
2922 _gtk_marshal_BOOLEAN__BOXED,
2924 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2925 g_signal_set_va_marshaller (widget_signals[WINDOW_STATE_EVENT], G_TYPE_FROM_CLASS (klass),
2926 _gtk_marshal_BOOLEAN__BOXEDv);
2929 * GtkWidget::damage-event:
2930 * @widget: the object which received the signal
2931 * @event: (type Gdk.EventExpose): the #GdkEventExpose event
2933 * Emitted when a redirected window belonging to @widget gets drawn into.
2934 * The region/area members of the event shows what area of the redirected
2935 * drawable was drawn into.
2937 * Returns: %TRUE to stop other handlers from being invoked for the event.
2938 * %FALSE to propagate the event further.
2942 widget_signals[DAMAGE_EVENT] =
2943 g_signal_new (I_("damage-event"),
2944 G_TYPE_FROM_CLASS (klass),
2946 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2947 _gtk_boolean_handled_accumulator, NULL,
2948 _gtk_marshal_BOOLEAN__BOXED,
2950 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2951 g_signal_set_va_marshaller (widget_signals[DAMAGE_EVENT], G_TYPE_FROM_CLASS (klass),
2952 _gtk_marshal_BOOLEAN__BOXEDv);
2955 * GtkWidget::grab-broken-event:
2956 * @widget: the object which received the signal
2957 * @event: (type Gdk.EventGrabBroken): the #GdkEventGrabBroken event
2959 * Emitted when a pointer or keyboard grab on a window belonging
2960 * to @widget gets broken.
2962 * On X11, this happens when the grab window becomes unviewable
2963 * (i.e. it or one of its ancestors is unmapped), or if the same
2964 * application grabs the pointer or keyboard again.
2966 * Returns: %TRUE to stop other handlers from being invoked for
2967 * the event. %FALSE to propagate the event further.
2971 widget_signals[GRAB_BROKEN_EVENT] =
2972 g_signal_new (I_("grab-broken-event"),
2973 G_TYPE_FROM_CLASS (klass),
2975 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2976 _gtk_boolean_handled_accumulator, NULL,
2977 _gtk_marshal_BOOLEAN__BOXED,
2979 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2980 g_signal_set_va_marshaller (widget_signals[GRAB_BROKEN_EVENT], G_TYPE_FROM_CLASS (klass),
2981 _gtk_marshal_BOOLEAN__BOXEDv);
2984 * GtkWidget::query-tooltip:
2985 * @widget: the object which received the signal
2986 * @x: the x coordinate of the cursor position where the request has
2987 * been emitted, relative to @widget's left side
2988 * @y: the y coordinate of the cursor position where the request has
2989 * been emitted, relative to @widget's top
2990 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2991 * @tooltip: a #GtkTooltip
2993 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2994 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2995 * focus in keyboard mode.
2997 * Using the given coordinates, the signal handler should determine
2998 * whether a tooltip should be shown for @widget. If this is the case
2999 * %TRUE should be returned, %FALSE otherwise. Note that if
3000 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
3001 * should not be used.
3003 * The signal handler is free to manipulate @tooltip with the therefore
3004 * destined function calls.
3006 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
3010 widget_signals[QUERY_TOOLTIP] =
3011 g_signal_new (I_("query-tooltip"),
3012 G_TYPE_FROM_CLASS (klass),
3014 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
3015 _gtk_boolean_handled_accumulator, NULL,
3016 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
3024 * GtkWidget::popup-menu:
3025 * @widget: the object which received the signal
3027 * This signal gets emitted whenever a widget should pop up a context
3028 * menu. This usually happens through the standard key binding mechanism;
3029 * by pressing a certain key while a widget is focused, the user can cause
3030 * the widget to pop up a menu. For example, the #GtkEntry widget creates
3031 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
3032 * for an example of how to use this signal.
3034 * Returns: %TRUE if a menu was activated
3036 widget_signals[POPUP_MENU] =
3037 g_signal_new (I_("popup-menu"),
3038 G_TYPE_FROM_CLASS (klass),
3039 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3040 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
3041 _gtk_boolean_handled_accumulator, NULL,
3042 _gtk_marshal_BOOLEAN__VOID,
3046 * GtkWidget::show-help:
3047 * @widget: the object which received the signal.
3050 * Returns: %TRUE to stop other handlers from being invoked for the event.
3051 * %FALSE to propagate the event further.
3053 widget_signals[SHOW_HELP] =
3054 g_signal_new (I_("show-help"),
3055 G_TYPE_FROM_CLASS (klass),
3056 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3057 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
3058 _gtk_boolean_handled_accumulator, NULL,
3059 _gtk_marshal_BOOLEAN__ENUM,
3061 GTK_TYPE_WIDGET_HELP_TYPE);
3064 * GtkWidget::accel-closures-changed:
3065 * @widget: the object which received the signal.
3067 widget_signals[ACCEL_CLOSURES_CHANGED] =
3068 g_signal_new (I_("accel-closures-changed"),
3069 G_TYPE_FROM_CLASS (klass),
3073 _gtk_marshal_VOID__VOID,
3077 * GtkWidget::screen-changed:
3078 * @widget: the object on which the signal is emitted
3079 * @previous_screen: (allow-none): the previous screen, or %NULL if the
3080 * widget was not associated with a screen before
3082 * The ::screen-changed signal gets emitted when the
3083 * screen of a widget has changed.
3085 widget_signals[SCREEN_CHANGED] =
3086 g_signal_new (I_("screen-changed"),
3087 G_TYPE_FROM_CLASS (klass),
3089 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
3091 _gtk_marshal_VOID__OBJECT,
3096 * GtkWidget::can-activate-accel:
3097 * @widget: the object which received the signal
3098 * @signal_id: the ID of a signal installed on @widget
3100 * Determines whether an accelerator that activates the signal
3101 * identified by @signal_id can currently be activated.
3102 * This signal is present to allow applications and derived
3103 * widgets to override the default #GtkWidget handling
3104 * for determining whether an accelerator can be activated.
3106 * Returns: %TRUE if the signal can be activated.
3108 widget_signals[CAN_ACTIVATE_ACCEL] =
3109 g_signal_new (I_("can-activate-accel"),
3110 G_TYPE_FROM_CLASS (klass),
3112 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
3113 _gtk_boolean_handled_accumulator, NULL,
3114 _gtk_marshal_BOOLEAN__UINT,
3115 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
3117 binding_set = gtk_binding_set_by_class (klass);
3118 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
3120 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
3123 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
3125 GTK_TYPE_WIDGET_HELP_TYPE,
3126 GTK_WIDGET_HELP_TOOLTIP);
3127 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
3129 GTK_TYPE_WIDGET_HELP_TYPE,
3130 GTK_WIDGET_HELP_TOOLTIP);
3131 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
3133 GTK_TYPE_WIDGET_HELP_TYPE,
3134 GTK_WIDGET_HELP_WHATS_THIS);
3135 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
3137 GTK_TYPE_WIDGET_HELP_TYPE,
3138 GTK_WIDGET_HELP_WHATS_THIS);
3140 gtk_widget_class_install_style_property (klass,
3141 g_param_spec_boolean ("interior-focus",
3142 P_("Interior Focus"),
3143 P_("Whether to draw the focus indicator inside widgets"),
3145 GTK_PARAM_READABLE));
3147 gtk_widget_class_install_style_property (klass,
3148 g_param_spec_int ("focus-line-width",
3149 P_("Focus linewidth"),
3150 P_("Width, in pixels, of the focus indicator line"),
3152 GTK_PARAM_READABLE));
3154 gtk_widget_class_install_style_property (klass,
3155 g_param_spec_string ("focus-line-pattern",
3156 P_("Focus line dash pattern"),
3157 P_("Dash pattern used to draw the focus indicator"),
3159 GTK_PARAM_READABLE));
3160 gtk_widget_class_install_style_property (klass,
3161 g_param_spec_int ("focus-padding",
3162 P_("Focus padding"),
3163 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3165 GTK_PARAM_READABLE));
3166 gtk_widget_class_install_style_property (klass,
3167 g_param_spec_boxed ("cursor-color",
3169 P_("Color with which to draw insertion cursor"),
3171 GTK_PARAM_READABLE));
3172 gtk_widget_class_install_style_property (klass,
3173 g_param_spec_boxed ("secondary-cursor-color",
3174 P_("Secondary cursor color"),
3175 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3177 GTK_PARAM_READABLE));
3178 gtk_widget_class_install_style_property (klass,
3179 g_param_spec_float ("cursor-aspect-ratio",
3180 P_("Cursor line aspect ratio"),
3181 P_("Aspect ratio with which to draw insertion cursor"),
3183 GTK_PARAM_READABLE));
3185 gtk_widget_class_install_style_property (klass,
3186 g_param_spec_boolean ("window-dragging",
3187 P_("Window dragging"),
3188 P_("Whether windows can be dragged by clicking on empty areas"),
3190 GTK_PARAM_READABLE));
3193 * GtkWidget:link-color:
3195 * The "link-color" style property defines the color of unvisited links.
3199 gtk_widget_class_install_style_property (klass,
3200 g_param_spec_boxed ("link-color",
3201 P_("Unvisited Link Color"),
3202 P_("Color of unvisited links"),
3204 GTK_PARAM_READABLE));
3207 * GtkWidget:visited-link-color:
3209 * The "visited-link-color" style property defines the color of visited links.
3213 gtk_widget_class_install_style_property (klass,
3214 g_param_spec_boxed ("visited-link-color",
3215 P_("Visited Link Color"),
3216 P_("Color of visited links"),
3218 GTK_PARAM_READABLE));
3221 * GtkWidget:wide-separators:
3223 * The "wide-separators" style property defines whether separators have
3224 * configurable width and should be drawn using a box instead of a line.
3228 gtk_widget_class_install_style_property (klass,
3229 g_param_spec_boolean ("wide-separators",
3230 P_("Wide Separators"),
3231 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3233 GTK_PARAM_READABLE));
3236 * GtkWidget:separator-width:
3238 * The "separator-width" style property defines the width of separators.
3239 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3243 gtk_widget_class_install_style_property (klass,
3244 g_param_spec_int ("separator-width",
3245 P_("Separator Width"),
3246 P_("The width of separators if wide-separators is TRUE"),
3248 GTK_PARAM_READABLE));
3251 * GtkWidget:separator-height:
3253 * The "separator-height" style property defines the height of separators.
3254 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3258 gtk_widget_class_install_style_property (klass,
3259 g_param_spec_int ("separator-height",
3260 P_("Separator Height"),
3261 P_("The height of separators if \"wide-separators\" is TRUE"),
3263 GTK_PARAM_READABLE));
3266 * GtkWidget:scroll-arrow-hlength:
3268 * The "scroll-arrow-hlength" style property defines the length of
3269 * horizontal scroll arrows.
3273 gtk_widget_class_install_style_property (klass,
3274 g_param_spec_int ("scroll-arrow-hlength",
3275 P_("Horizontal Scroll Arrow Length"),
3276 P_("The length of horizontal scroll arrows"),
3278 GTK_PARAM_READABLE));
3281 * GtkWidget:scroll-arrow-vlength:
3283 * The "scroll-arrow-vlength" style property defines the length of
3284 * vertical scroll arrows.
3288 gtk_widget_class_install_style_property (klass,
3289 g_param_spec_int ("scroll-arrow-vlength",
3290 P_("Vertical Scroll Arrow Length"),
3291 P_("The length of vertical scroll arrows"),
3293 GTK_PARAM_READABLE));
3295 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3297 gtk_widget_class_set_accessible_type (klass, GTK_TYPE_WIDGET_ACCESSIBLE);
3301 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3305 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3306 for (node = list; node; node = node->next)
3308 GParamSpec *pspec = node->data;
3310 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3311 g_param_spec_unref (pspec);
3317 gtk_widget_set_property (GObject *object,
3319 const GValue *value,
3322 GtkWidget *widget = GTK_WIDGET (object);
3327 gchar *tooltip_markup;
3328 const gchar *tooltip_text;
3329 GtkWindow *tooltip_window;
3332 gtk_widget_set_name (widget, g_value_get_string (value));
3335 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3337 case PROP_WIDTH_REQUEST:
3338 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3340 case PROP_HEIGHT_REQUEST:
3341 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3344 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3346 case PROP_SENSITIVE:
3347 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3349 case PROP_APP_PAINTABLE:
3350 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3352 case PROP_CAN_FOCUS:
3353 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3355 case PROP_HAS_FOCUS:
3356 if (g_value_get_boolean (value))
3357 gtk_widget_grab_focus (widget);
3360 if (g_value_get_boolean (value))
3361 gtk_widget_grab_focus (widget);
3363 case PROP_CAN_DEFAULT:
3364 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3366 case PROP_HAS_DEFAULT:
3367 if (g_value_get_boolean (value))
3368 gtk_widget_grab_default (widget);
3370 case PROP_RECEIVES_DEFAULT:
3371 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3374 gtk_widget_set_style (widget, g_value_get_object (value));
3377 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3378 gtk_widget_set_events (widget, g_value_get_flags (value));
3380 case PROP_NO_SHOW_ALL:
3381 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3383 case PROP_HAS_TOOLTIP:
3384 gtk_widget_real_set_has_tooltip (widget,
3385 g_value_get_boolean (value), FALSE);
3387 case PROP_TOOLTIP_MARKUP:
3388 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3389 tooltip_markup = g_value_dup_string (value);
3391 /* Treat an empty string as a NULL string,
3392 * because an empty string would be useless for a tooltip:
3394 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3396 g_free (tooltip_markup);
3397 tooltip_markup = NULL;
3400 g_object_set_qdata_full (object, quark_tooltip_markup,
3401 tooltip_markup, g_free);
3403 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3404 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3405 if (gtk_widget_get_visible (widget))
3406 gtk_widget_queue_tooltip_query (widget);
3408 case PROP_TOOLTIP_TEXT:
3409 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3411 tooltip_text = g_value_get_string (value);
3413 /* Treat an empty string as a NULL string,
3414 * because an empty string would be useless for a tooltip:
3416 if (tooltip_text && (strlen (tooltip_text) == 0))
3417 tooltip_text = NULL;
3419 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3421 g_object_set_qdata_full (object, quark_tooltip_markup,
3422 tooltip_markup, g_free);
3424 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3425 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3426 if (gtk_widget_get_visible (widget))
3427 gtk_widget_queue_tooltip_query (widget);
3429 case PROP_DOUBLE_BUFFERED:
3430 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3433 gtk_widget_set_halign (widget, g_value_get_enum (value));
3436 gtk_widget_set_valign (widget, g_value_get_enum (value));
3438 case PROP_MARGIN_LEFT:
3439 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3441 case PROP_MARGIN_RIGHT:
3442 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3444 case PROP_MARGIN_TOP:
3445 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3447 case PROP_MARGIN_BOTTOM:
3448 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3451 g_object_freeze_notify (G_OBJECT (widget));
3452 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3453 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3454 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3455 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3456 g_object_thaw_notify (G_OBJECT (widget));
3459 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3461 case PROP_HEXPAND_SET:
3462 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3465 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3467 case PROP_VEXPAND_SET:
3468 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3471 g_object_freeze_notify (G_OBJECT (widget));
3472 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3473 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3474 g_object_thaw_notify (G_OBJECT (widget));
3477 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3483 gtk_widget_get_property (GObject *object,
3488 GtkWidget *widget = GTK_WIDGET (object);
3489 GtkWidgetPrivate *priv = widget->priv;
3497 g_value_set_string (value, priv->name);
3499 g_value_set_static_string (value, "");
3502 g_value_set_object (value, priv->parent);
3504 case PROP_WIDTH_REQUEST:
3507 gtk_widget_get_size_request (widget, &w, NULL);
3508 g_value_set_int (value, w);
3511 case PROP_HEIGHT_REQUEST:
3514 gtk_widget_get_size_request (widget, NULL, &h);
3515 g_value_set_int (value, h);
3519 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3521 case PROP_SENSITIVE:
3522 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3524 case PROP_APP_PAINTABLE:
3525 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3527 case PROP_CAN_FOCUS:
3528 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3530 case PROP_HAS_FOCUS:
3531 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3534 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3536 case PROP_CAN_DEFAULT:
3537 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3539 case PROP_HAS_DEFAULT:
3540 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3542 case PROP_RECEIVES_DEFAULT:
3543 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3545 case PROP_COMPOSITE_CHILD:
3546 g_value_set_boolean (value, widget->priv->composite_child);
3549 g_value_set_object (value, gtk_widget_get_style (widget));
3552 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3553 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3555 case PROP_NO_SHOW_ALL:
3556 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3558 case PROP_HAS_TOOLTIP:
3559 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3561 case PROP_TOOLTIP_TEXT:
3563 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3566 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3567 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3569 g_value_take_string (value, text);
3572 case PROP_TOOLTIP_MARKUP:
3573 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3576 g_value_set_object (value, gtk_widget_get_window (widget));
3578 case PROP_DOUBLE_BUFFERED:
3579 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3582 g_value_set_enum (value, gtk_widget_get_halign (widget));
3585 g_value_set_enum (value, gtk_widget_get_valign (widget));
3587 case PROP_MARGIN_LEFT:
3588 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3590 case PROP_MARGIN_RIGHT:
3591 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3593 case PROP_MARGIN_TOP:
3594 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3596 case PROP_MARGIN_BOTTOM:
3597 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3601 GtkWidgetAuxInfo *aux_info = gtk_widget_get_aux_info (widget, FALSE);
3602 if (aux_info == NULL)
3604 g_value_set_int (value, 0);
3608 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3609 aux_info->margin.right),
3610 MAX (aux_info->margin.top,
3611 aux_info->margin.bottom)));
3616 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3618 case PROP_HEXPAND_SET:
3619 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3622 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3624 case PROP_VEXPAND_SET:
3625 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3628 g_value_set_boolean (value,
3629 gtk_widget_get_hexpand (widget) &&
3630 gtk_widget_get_vexpand (widget));
3633 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3639 gtk_widget_init (GtkWidget *widget)
3641 GtkWidgetPrivate *priv;
3643 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3646 priv = widget->priv;
3648 priv->child_visible = TRUE;
3650 priv->allocation.x = -1;
3651 priv->allocation.y = -1;
3652 priv->allocation.width = 1;
3653 priv->allocation.height = 1;
3654 priv->window = NULL;
3655 priv->parent = NULL;
3657 priv->sensitive = TRUE;
3658 priv->composite_child = composite_child_stack != 0;
3659 priv->double_buffered = TRUE;
3660 priv->redraw_on_alloc = TRUE;
3661 priv->width_request_needed = TRUE;
3662 priv->height_request_needed = TRUE;
3663 priv->alloc_needed = TRUE;
3665 /* this will be set to TRUE if the widget gets a child or if the
3666 * expand flag is set on the widget, but until one of those happen
3667 * we know the expand is already properly FALSE.
3669 * We really want to default FALSE here to avoid computing expand
3670 * all over the place while initially building a widget tree.
3672 priv->need_compute_expand = FALSE;
3674 priv->style = gtk_widget_get_default_style ();
3675 g_object_ref (priv->style);
3680 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3682 GParamSpec **pspecs)
3684 GtkWidgetPrivate *priv = widget->priv;
3685 GtkWidget *container = priv->parent;
3688 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3689 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3693 * gtk_widget_freeze_child_notify:
3694 * @widget: a #GtkWidget
3696 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3697 * signals are queued until gtk_widget_thaw_child_notify() is called
3700 * This is the analogue of g_object_freeze_notify() for child properties.
3703 gtk_widget_freeze_child_notify (GtkWidget *widget)
3705 g_return_if_fail (GTK_IS_WIDGET (widget));
3707 if (!G_OBJECT (widget)->ref_count)
3710 g_object_ref (widget);
3711 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3712 g_object_unref (widget);
3716 * gtk_widget_child_notify:
3717 * @widget: a #GtkWidget
3718 * @child_property: the name of a child property installed on the
3719 * class of @widget<!-- -->'s parent
3721 * Emits a #GtkWidget::child-notify signal for the
3722 * <link linkend="child-properties">child property</link> @child_property
3725 * This is the analogue of g_object_notify() for child properties.
3727 * Also see gtk_container_child_notify().
3730 gtk_widget_child_notify (GtkWidget *widget,
3731 const gchar *child_property)
3733 if (widget->priv->parent == NULL)
3736 gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
3740 * gtk_widget_thaw_child_notify:
3741 * @widget: a #GtkWidget
3743 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3744 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3748 gtk_widget_thaw_child_notify (GtkWidget *widget)
3750 GObjectNotifyQueue *nqueue;
3752 g_return_if_fail (GTK_IS_WIDGET (widget));
3754 if (!G_OBJECT (widget)->ref_count)
3757 g_object_ref (widget);
3758 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3759 if (!nqueue || !nqueue->freeze_count)
3760 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3761 G_OBJECT_TYPE_NAME (widget), widget);
3763 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3764 g_object_unref (widget);
3770 * @type: type ID of the widget to create
3771 * @first_property_name: name of first property to set
3772 * @...: value of first property, followed by more properties,
3775 * This is a convenience function for creating a widget and setting
3776 * its properties in one go. For example you might write:
3777 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3778 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3779 * g_object_new(), but returns a widget so you don't have to
3780 * cast the object yourself.
3782 * Return value: a new #GtkWidget of type @widget_type
3785 gtk_widget_new (GType type,
3786 const gchar *first_property_name,
3792 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3794 va_start (var_args, first_property_name);
3795 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3802 gtk_widget_queue_draw_child (GtkWidget *widget)
3804 GtkWidgetPrivate *priv = widget->priv;
3807 parent = priv->parent;
3808 if (parent && gtk_widget_is_drawable (parent))
3809 gtk_widget_queue_draw_area (parent,
3812 priv->allocation.width,
3813 priv->allocation.height);
3817 * gtk_widget_unparent:
3818 * @widget: a #GtkWidget
3820 * This function is only for use in widget implementations.
3821 * Should be called by implementations of the remove method
3822 * on #GtkContainer, to dissociate a child from the container.
3825 gtk_widget_unparent (GtkWidget *widget)
3827 GtkWidgetPrivate *priv;
3828 GObjectNotifyQueue *nqueue;
3829 GtkWidget *toplevel;
3830 GtkWidget *old_parent;
3832 g_return_if_fail (GTK_IS_WIDGET (widget));
3834 priv = widget->priv;
3836 if (priv->parent == NULL)
3839 /* keep this function in sync with gtk_menu_detach() */
3841 gtk_widget_push_verify_invariants (widget);
3843 g_object_freeze_notify (G_OBJECT (widget));
3844 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3846 toplevel = gtk_widget_get_toplevel (widget);
3847 if (gtk_widget_is_toplevel (toplevel))
3848 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3850 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3851 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3853 gtk_widget_queue_draw_child (widget);
3855 /* Reset the width and height here, to force reallocation if we
3856 * get added back to a new parent. This won't work if our new
3857 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3858 * (would 0x0 be OK here?)
3860 priv->allocation.width = 1;
3861 priv->allocation.height = 1;
3863 if (gtk_widget_get_realized (widget))
3865 if (priv->in_reparent)
3866 gtk_widget_unmap (widget);
3868 gtk_widget_unrealize (widget);
3871 /* If we are unanchoring the child, we save around the toplevel
3872 * to emit hierarchy changed
3874 if (priv->parent->priv->anchored)
3875 g_object_ref (toplevel);
3879 /* Removing a widget from a container restores the child visible
3880 * flag to the default state, so it doesn't affect the child
3881 * in the next parent.
3883 priv->child_visible = TRUE;
3885 old_parent = priv->parent;
3886 priv->parent = NULL;
3888 /* parent may no longer expand if the removed
3889 * child was expand=TRUE and could therefore
3892 if (gtk_widget_get_visible (widget) &&
3893 (priv->need_compute_expand ||
3894 priv->computed_hexpand ||
3895 priv->computed_vexpand))
3897 gtk_widget_queue_compute_expand (old_parent);
3900 /* Unset BACKDROP since we are no longer inside a toplevel window */
3901 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_BACKDROP);
3903 gtk_style_context_set_parent (priv->context, NULL);
3905 _gtk_widget_update_parent_muxer (widget);
3907 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3910 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3911 g_object_unref (toplevel);
3914 /* Now that the parent pointer is nullified and the hierarchy-changed
3915 * already passed, go ahead and unset the parent window, if we are unparenting
3916 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
3917 * will fire again for the new subhierarchy.
3919 gtk_widget_set_parent_window (widget, NULL);
3921 g_object_notify (G_OBJECT (widget), "parent");
3922 g_object_thaw_notify (G_OBJECT (widget));
3924 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3925 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3927 gtk_widget_pop_verify_invariants (widget);
3928 g_object_unref (widget);
3932 * gtk_widget_destroy:
3933 * @widget: a #GtkWidget
3935 * Destroys a widget.
3938 * destroyed, it will break any references it holds to other objects.
3939 * If the widget is inside a container, the widget will be removed
3940 * from the container. If the widget is a toplevel (derived from
3941 * #GtkWindow), it will be removed from the list of toplevels, and the
3942 * reference GTK+ holds to it will be removed. Removing a
3943 * widget from its container or the list of toplevels results in the
3944 * widget being finalized, unless you've added additional references
3945 * to the widget with g_object_ref().
3947 * In most cases, only toplevel widgets (windows) require explicit
3948 * destruction, because when you destroy a toplevel its children will
3949 * be destroyed as well.
3952 gtk_widget_destroy (GtkWidget *widget)
3954 g_return_if_fail (GTK_IS_WIDGET (widget));
3956 if (!widget->priv->in_destruction)
3957 g_object_run_dispose (G_OBJECT (widget));
3961 * gtk_widget_destroyed:
3962 * @widget: a #GtkWidget
3963 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3965 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3966 * %NULL. It's intended to be used as a callback connected to the
3967 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3968 * as a signal handler, and pass the address of your widget variable
3969 * as user data. Then when the widget is destroyed, the variable will
3970 * be set to %NULL. Useful for example to avoid multiple copies
3971 * of the same dialog.
3974 gtk_widget_destroyed (GtkWidget *widget,
3975 GtkWidget **widget_pointer)
3977 /* Don't make any assumptions about the
3979 * Even check widget_pointer.
3982 *widget_pointer = NULL;
3987 * @widget: a #GtkWidget
3989 * Flags a widget to be displayed. Any widget that isn't shown will
3990 * not appear on the screen. If you want to show all the widgets in a
3991 * container, it's easier to call gtk_widget_show_all() on the
3992 * container, instead of individually showing the widgets.
3994 * Remember that you have to show the containers containing a widget,
3995 * in addition to the widget itself, before it will appear onscreen.
3997 * When a toplevel container is shown, it is immediately realized and
3998 * mapped; other shown widgets are realized and mapped when their
3999 * toplevel container is realized and mapped.
4002 gtk_widget_show (GtkWidget *widget)
4004 g_return_if_fail (GTK_IS_WIDGET (widget));
4006 if (!gtk_widget_get_visible (widget))
4008 g_object_ref (widget);
4009 gtk_widget_push_verify_invariants (widget);
4011 if (!gtk_widget_is_toplevel (widget))
4012 gtk_widget_queue_resize (widget);
4014 /* see comment in set_parent() for why this should and can be
4017 if (widget->priv->need_compute_expand ||
4018 widget->priv->computed_hexpand ||
4019 widget->priv->computed_vexpand)
4021 if (widget->priv->parent != NULL)
4022 gtk_widget_queue_compute_expand (widget->priv->parent);
4025 g_signal_emit (widget, widget_signals[SHOW], 0);
4026 g_object_notify (G_OBJECT (widget), "visible");
4028 gtk_widget_pop_verify_invariants (widget);
4029 g_object_unref (widget);
4034 gtk_widget_real_show (GtkWidget *widget)
4036 GtkWidgetPrivate *priv = widget->priv;
4038 if (!gtk_widget_get_visible (widget))
4040 priv->visible = TRUE;
4043 gtk_widget_get_mapped (priv->parent) &&
4044 gtk_widget_get_child_visible (widget) &&
4045 !gtk_widget_get_mapped (widget))
4046 gtk_widget_map (widget);
4051 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
4054 g_signal_handlers_disconnect_by_func (widget,
4055 gtk_widget_show_map_callback,
4060 * gtk_widget_show_now:
4061 * @widget: a #GtkWidget
4063 * Shows a widget. If the widget is an unmapped toplevel widget
4064 * (i.e. a #GtkWindow that has not yet been shown), enter the main
4065 * loop and wait for the window to actually be mapped. Be careful;
4066 * because the main loop is running, anything can happen during
4070 gtk_widget_show_now (GtkWidget *widget)
4074 g_return_if_fail (GTK_IS_WIDGET (widget));
4076 /* make sure we will get event */
4077 if (!gtk_widget_get_mapped (widget) &&
4078 gtk_widget_is_toplevel (widget))
4080 gtk_widget_show (widget);
4082 g_signal_connect (widget, "map-event",
4083 G_CALLBACK (gtk_widget_show_map_callback),
4087 gtk_main_iteration ();
4090 gtk_widget_show (widget);
4095 * @widget: a #GtkWidget
4097 * Reverses the effects of gtk_widget_show(), causing the widget to be
4098 * hidden (invisible to the user).
4101 gtk_widget_hide (GtkWidget *widget)
4103 g_return_if_fail (GTK_IS_WIDGET (widget));
4105 if (gtk_widget_get_visible (widget))
4107 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
4109 g_object_ref (widget);
4110 gtk_widget_push_verify_invariants (widget);
4112 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
4113 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
4115 /* a parent may now be expand=FALSE since we're hidden. */
4116 if (widget->priv->need_compute_expand ||
4117 widget->priv->computed_hexpand ||
4118 widget->priv->computed_vexpand)
4120 gtk_widget_queue_compute_expand (widget);
4123 g_signal_emit (widget, widget_signals[HIDE], 0);
4124 if (!gtk_widget_is_toplevel (widget))
4125 gtk_widget_queue_resize (widget);
4126 g_object_notify (G_OBJECT (widget), "visible");
4128 gtk_widget_pop_verify_invariants (widget);
4129 g_object_unref (widget);
4134 gtk_widget_real_hide (GtkWidget *widget)
4136 if (gtk_widget_get_visible (widget))
4138 widget->priv->visible = FALSE;
4140 if (gtk_widget_get_mapped (widget))
4141 gtk_widget_unmap (widget);
4143 if (widget->priv->context)
4144 _gtk_style_context_stop_animations (widget->priv->context);
4149 * gtk_widget_hide_on_delete:
4150 * @widget: a #GtkWidget
4152 * Utility function; intended to be connected to the #GtkWidget::delete-event
4153 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4154 * argument, then returns %TRUE. If connected to ::delete-event, the
4155 * result is that clicking the close button for a window (on the
4156 * window frame, top right corner usually) will hide but not destroy
4157 * the window. By default, GTK+ destroys windows when ::delete-event
4160 * Return value: %TRUE
4163 gtk_widget_hide_on_delete (GtkWidget *widget)
4165 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4167 gtk_widget_hide (widget);
4173 * gtk_widget_show_all:
4174 * @widget: a #GtkWidget
4176 * Recursively shows a widget, and any child widgets (if the widget is
4180 gtk_widget_show_all (GtkWidget *widget)
4182 GtkWidgetClass *class;
4184 g_return_if_fail (GTK_IS_WIDGET (widget));
4186 if (gtk_widget_get_no_show_all (widget))
4189 class = GTK_WIDGET_GET_CLASS (widget);
4191 if (class->show_all)
4192 class->show_all (widget);
4197 * @widget: a #GtkWidget
4199 * This function is only for use in widget implementations. Causes
4200 * a widget to be mapped if it isn't already.
4203 gtk_widget_map (GtkWidget *widget)
4205 GtkWidgetPrivate *priv;
4207 g_return_if_fail (GTK_IS_WIDGET (widget));
4208 g_return_if_fail (gtk_widget_get_visible (widget));
4209 g_return_if_fail (gtk_widget_get_child_visible (widget));
4211 priv = widget->priv;
4213 if (!gtk_widget_get_mapped (widget))
4215 gtk_widget_push_verify_invariants (widget);
4217 if (!gtk_widget_get_realized (widget))
4218 gtk_widget_realize (widget);
4220 g_signal_emit (widget, widget_signals[MAP], 0);
4222 if (!gtk_widget_get_has_window (widget))
4223 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4225 gtk_widget_pop_verify_invariants (widget);
4231 * @widget: a #GtkWidget
4233 * This function is only for use in widget implementations. Causes
4234 * a widget to be unmapped if it's currently mapped.
4237 gtk_widget_unmap (GtkWidget *widget)
4239 GtkWidgetPrivate *priv;
4241 g_return_if_fail (GTK_IS_WIDGET (widget));
4243 priv = widget->priv;
4245 if (gtk_widget_get_mapped (widget))
4247 gtk_widget_push_verify_invariants (widget);
4249 if (!gtk_widget_get_has_window (widget))
4250 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4251 _gtk_tooltip_hide (widget);
4252 g_signal_emit (widget, widget_signals[UNMAP], 0);
4254 gtk_widget_pop_verify_invariants (widget);
4256 /* Unset pointer/window info */
4257 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4262 _gtk_widget_enable_device_events (GtkWidget *widget)
4264 GHashTable *device_events;
4265 GHashTableIter iter;
4266 gpointer key, value;
4268 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4273 g_hash_table_iter_init (&iter, device_events);
4275 while (g_hash_table_iter_next (&iter, &key, &value))
4278 GdkEventMask event_mask;
4281 event_mask = GPOINTER_TO_UINT (value);
4282 gtk_widget_add_events_internal (widget, device, event_mask);
4287 get_widget_windows (GtkWidget *widget)
4289 GList *window_list, *last, *l, *children, *ret;
4291 if (gtk_widget_get_has_window (widget))
4292 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4294 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4296 last = g_list_last (window_list);
4299 for (l = window_list; l; l = l->next)
4301 GtkWidget *window_widget = NULL;
4303 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4305 if (widget != window_widget)
4308 ret = g_list_prepend (ret, l->data);
4309 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4313 last = g_list_concat (last, children);
4314 last = g_list_last (last);
4318 g_list_free (window_list);
4324 device_enable_foreach (GtkWidget *widget,
4327 GdkDevice *device = user_data;
4328 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4332 device_disable_foreach (GtkWidget *widget,
4335 GdkDevice *device = user_data;
4336 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4340 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4345 GList *window_list, *l;
4347 window_list = get_widget_windows (widget);
4349 for (l = window_list; l; l = l->next)
4351 GdkEventMask events = 0;
4357 events = gdk_window_get_events (window);
4359 gdk_window_set_device_events (window, device, events);
4362 if (recurse && GTK_IS_CONTAINER (widget))
4365 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4367 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4370 g_list_free (window_list);
4374 gtk_widget_update_devices_mask (GtkWidget *widget,
4377 GList *enabled_devices, *l;
4379 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4381 for (l = enabled_devices; l; l = l->next)
4382 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4386 * gtk_widget_realize:
4387 * @widget: a #GtkWidget
4389 * Creates the GDK (windowing system) resources associated with a
4390 * widget. For example, @widget->window will be created when a widget
4391 * is realized. Normally realization happens implicitly; if you show
4392 * a widget and all its parent containers, then the widget will be
4393 * realized and mapped automatically.
4395 * Realizing a widget requires all
4396 * the widget's parent widgets to be realized; calling
4397 * gtk_widget_realize() realizes the widget's parents in addition to
4398 * @widget itself. If a widget is not yet inside a toplevel window
4399 * when you realize it, bad things will happen.
4401 * This function is primarily used in widget implementations, and
4402 * isn't very useful otherwise. Many times when you think you might
4403 * need it, a better approach is to connect to a signal that will be
4404 * called after the widget is realized automatically, such as
4405 * #GtkWidget::draw. Or simply g_signal_connect () to the
4406 * #GtkWidget::realize signal.
4409 gtk_widget_realize (GtkWidget *widget)
4411 GtkWidgetPrivate *priv;
4412 cairo_region_t *region;
4414 g_return_if_fail (GTK_IS_WIDGET (widget));
4415 g_return_if_fail (widget->priv->anchored ||
4416 GTK_IS_INVISIBLE (widget));
4418 priv = widget->priv;
4420 if (!gtk_widget_get_realized (widget))
4422 gtk_widget_push_verify_invariants (widget);
4425 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4426 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4429 if (priv->parent == NULL &&
4430 !gtk_widget_is_toplevel (widget))
4431 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4432 "inside a toplevel window is not going to work very well. "
4433 "Widgets must be inside a toplevel container before realizing them.");
4435 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4436 gtk_widget_realize (priv->parent);
4438 gtk_widget_ensure_style (widget);
4440 if (priv->style_update_pending)
4441 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4443 g_signal_emit (widget, widget_signals[REALIZE], 0);
4445 gtk_widget_real_set_has_tooltip (widget,
4446 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4449 if (priv->has_shape_mask)
4451 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4452 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4455 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4457 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4459 if (priv->multidevice)
4460 gdk_window_set_support_multidevice (priv->window, TRUE);
4462 _gtk_widget_enable_device_events (widget);
4463 gtk_widget_update_devices_mask (widget, TRUE);
4465 gtk_widget_pop_verify_invariants (widget);
4470 * gtk_widget_unrealize:
4471 * @widget: a #GtkWidget
4473 * This function is only useful in widget implementations.
4474 * Causes a widget to be unrealized (frees all GDK resources
4475 * associated with the widget, such as @widget->window).
4478 gtk_widget_unrealize (GtkWidget *widget)
4480 g_return_if_fail (GTK_IS_WIDGET (widget));
4482 gtk_widget_push_verify_invariants (widget);
4484 if (widget->priv->has_shape_mask)
4485 gtk_widget_shape_combine_region (widget, NULL);
4487 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4488 gtk_widget_input_shape_combine_region (widget, NULL);
4490 if (gtk_widget_get_realized (widget))
4492 g_object_ref (widget);
4494 if (widget->priv->mapped)
4495 gtk_widget_unmap (widget);
4497 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4498 g_assert (!widget->priv->mapped);
4499 gtk_widget_set_realized (widget, FALSE);
4501 g_object_unref (widget);
4504 gtk_widget_pop_verify_invariants (widget);
4507 /*****************************************
4509 *****************************************/
4512 * gtk_widget_queue_draw_region:
4513 * @widget: a #GtkWidget
4514 * @region: region to draw
4516 * Invalidates the rectangular area of @widget defined by @region by
4517 * calling gdk_window_invalidate_region() on the widget's window and
4518 * all its child windows. Once the main loop becomes idle (after the
4519 * current batch of events has been processed, roughly), the window
4520 * will receive expose events for the union of all regions that have
4523 * Normally you would only use this function in widget
4524 * implementations. You might also use it to schedule a redraw of a
4525 * #GtkDrawingArea or some portion thereof.
4530 gtk_widget_queue_draw_region (GtkWidget *widget,
4531 const cairo_region_t *region)
4533 GtkWidgetPrivate *priv;
4536 g_return_if_fail (GTK_IS_WIDGET (widget));
4538 priv = widget->priv;
4540 if (!gtk_widget_get_realized (widget))
4543 /* Just return if the widget or one of its ancestors isn't mapped */
4544 for (w = widget; w != NULL; w = w->priv->parent)
4545 if (!gtk_widget_get_mapped (w))
4548 gdk_window_invalidate_region (priv->window, region, TRUE);
4552 * gtk_widget_queue_draw_area:
4553 * @widget: a #GtkWidget
4554 * @x: x coordinate of upper-left corner of rectangle to redraw
4555 * @y: y coordinate of upper-left corner of rectangle to redraw
4556 * @width: width of region to draw
4557 * @height: height of region to draw
4559 * Convenience function that calls gtk_widget_queue_draw_region() on
4560 * the region created from the given coordinates.
4562 * The region here is specified in widget coordinates.
4563 * Widget coordinates are a bit odd; for historical reasons, they are
4564 * defined as @widget->window coordinates for widgets that are not
4565 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4566 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4569 gtk_widget_queue_draw_area (GtkWidget *widget,
4576 cairo_region_t *region;
4578 g_return_if_fail (GTK_IS_WIDGET (widget));
4583 rect.height = height;
4585 region = cairo_region_create_rectangle (&rect);
4586 gtk_widget_queue_draw_region (widget, region);
4587 cairo_region_destroy (region);
4591 * gtk_widget_queue_draw:
4592 * @widget: a #GtkWidget
4594 * Equivalent to calling gtk_widget_queue_draw_area() for the
4595 * entire area of a widget.
4598 gtk_widget_queue_draw (GtkWidget *widget)
4602 g_return_if_fail (GTK_IS_WIDGET (widget));
4604 gtk_widget_get_allocation (widget, &rect);
4606 if (!gtk_widget_get_has_window (widget))
4607 gtk_widget_queue_draw_area (widget,
4608 rect.x, rect.y, rect.width, rect.height);
4610 gtk_widget_queue_draw_area (widget,
4611 0, 0, rect.width, rect.height);
4615 * gtk_widget_queue_resize:
4616 * @widget: a #GtkWidget
4618 * This function is only for use in widget implementations.
4619 * Flags a widget to have its size renegotiated; should
4620 * be called when a widget for some reason has a new size request.
4621 * For example, when you change the text in a #GtkLabel, #GtkLabel
4622 * queues a resize to ensure there's enough space for the new text.
4624 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4625 * from inside its implementation of the GtkWidgetClass::size_allocate
4626 * virtual method. Calls to gtk_widget_queue_resize() from inside
4627 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4630 gtk_widget_queue_resize (GtkWidget *widget)
4632 g_return_if_fail (GTK_IS_WIDGET (widget));
4634 if (gtk_widget_get_realized (widget))
4635 gtk_widget_queue_shallow_draw (widget);
4637 _gtk_size_group_queue_resize (widget, 0);
4641 * gtk_widget_queue_resize_no_redraw:
4642 * @widget: a #GtkWidget
4644 * This function works like gtk_widget_queue_resize(),
4645 * except that the widget is not invalidated.
4650 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4652 g_return_if_fail (GTK_IS_WIDGET (widget));
4654 _gtk_size_group_queue_resize (widget, 0);
4658 * gtk_widget_size_request:
4659 * @widget: a #GtkWidget
4660 * @requisition: (out): a #GtkRequisition to be filled in
4662 * This function is typically used when implementing a #GtkContainer
4663 * subclass. Obtains the preferred size of a widget. The container
4664 * uses this information to arrange its child widgets and decide what
4665 * size allocations to give them with gtk_widget_size_allocate().
4667 * You can also call this function from an application, with some
4668 * caveats. Most notably, getting a size request requires the widget
4669 * to be associated with a screen, because font information may be
4670 * needed. Multihead-aware applications should keep this in mind.
4672 * Also remember that the size request is not necessarily the size
4673 * a widget will actually be allocated.
4675 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4678 gtk_widget_size_request (GtkWidget *widget,
4679 GtkRequisition *requisition)
4681 g_return_if_fail (GTK_IS_WIDGET (widget));
4683 gtk_widget_get_preferred_size (widget, requisition, NULL);
4687 * gtk_widget_get_child_requisition:
4688 * @widget: a #GtkWidget
4689 * @requisition: (out): a #GtkRequisition to be filled in
4691 * This function is only for use in widget implementations. Obtains
4692 * @widget->requisition, unless someone has forced a particular
4693 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4694 * in which case it returns that geometry instead of the widget's
4697 * This function differs from gtk_widget_size_request() in that
4698 * it retrieves the last size request value from @widget->requisition,
4699 * while gtk_widget_size_request() actually calls the "size_request" method
4700 * on @widget to compute the size request and fill in @widget->requisition,
4701 * and only then returns @widget->requisition.
4703 * Because this function does not call the "size_request" method, it
4704 * can only be used when you know that @widget->requisition is
4705 * up-to-date, that is, gtk_widget_size_request() has been called
4706 * since the last time a resize was queued. In general, only container
4707 * implementations have this information; applications should use
4708 * gtk_widget_size_request().
4711 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4714 gtk_widget_get_child_requisition (GtkWidget *widget,
4715 GtkRequisition *requisition)
4717 gtk_widget_get_preferred_size (widget, requisition, NULL);
4721 invalidate_predicate (GdkWindow *window,
4726 gdk_window_get_user_data (window, &user_data);
4728 return (user_data == data);
4731 /* Invalidate @region in widget->window and all children
4732 * of widget->window owned by widget. @region is in the
4733 * same coordinates as widget->allocation and will be
4734 * modified by this call.
4737 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4738 cairo_region_t *region)
4740 GtkWidgetPrivate *priv = widget->priv;
4742 if (!gtk_widget_get_realized (widget))
4745 if (gtk_widget_get_has_window (widget) && priv->parent)
4749 gdk_window_get_position (priv->window, &x, &y);
4750 cairo_region_translate (region, -x, -y);
4753 gdk_window_invalidate_maybe_recurse (priv->window, region,
4754 invalidate_predicate, widget);
4758 * gtk_widget_queue_shallow_draw:
4759 * @widget: a #GtkWidget
4761 * Like gtk_widget_queue_draw(), but only windows owned
4762 * by @widget are invalidated.
4765 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4768 cairo_region_t *region;
4770 if (!gtk_widget_get_realized (widget))
4773 gtk_widget_get_allocation (widget, &rect);
4775 region = cairo_region_create_rectangle (&rect);
4776 gtk_widget_invalidate_widget_windows (widget, region);
4777 cairo_region_destroy (region);
4781 * gtk_widget_size_allocate:
4782 * @widget: a #GtkWidget
4783 * @allocation: position and size to be allocated to @widget
4785 * This function is only used by #GtkContainer subclasses, to assign a size
4786 * and position to their child widgets.
4788 * In this function, the allocation may be adjusted. It will be forced
4789 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4790 * method on the child will be used to adjust the allocation. Standard
4791 * adjustments include removing the widget's margins, and applying the
4792 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4795 gtk_widget_size_allocate (GtkWidget *widget,
4796 GtkAllocation *allocation)
4798 GtkWidgetPrivate *priv;
4799 GdkRectangle real_allocation;
4800 GdkRectangle old_allocation;
4801 GdkRectangle adjusted_allocation;
4802 gboolean alloc_needed;
4803 gboolean size_changed;
4804 gboolean position_changed;
4805 gint natural_width, natural_height, dummy;
4806 gint min_width, min_height;
4808 priv = widget->priv;
4810 g_return_if_fail (GTK_IS_WIDGET (widget));
4812 gtk_widget_push_verify_invariants (widget);
4814 #ifdef G_ENABLE_DEBUG
4815 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4826 parent = gtk_widget_get_parent (parent);
4829 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4830 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4831 2 * depth, " ", name,
4832 allocation->width, allocation->height);
4834 #endif /* G_ENABLE_DEBUG */
4836 alloc_needed = priv->alloc_needed;
4837 if (!priv->width_request_needed && !priv->height_request_needed)
4838 /* Preserve request/allocate ordering */
4839 priv->alloc_needed = FALSE;
4841 old_allocation = priv->allocation;
4842 real_allocation = *allocation;
4844 adjusted_allocation = real_allocation;
4845 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4847 /* Go ahead and request the height for allocated width, note that the internals
4848 * of get_height_for_width will internally limit the for_size to natural size
4849 * when aligning implicitly.
4851 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4852 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
4856 /* Go ahead and request the width for allocated height, note that the internals
4857 * of get_width_for_height will internally limit the for_size to natural size
4858 * when aligning implicitly.
4860 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4861 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
4864 #ifdef G_ENABLE_DEBUG
4865 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4867 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
4868 !GTK_IS_SCROLLABLE (widget))
4869 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
4870 "Allocation is %dx%d, but minimum required size is %dx%d.",
4871 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
4872 G_OBJECT_TYPE_NAME (widget), widget,
4873 real_allocation.width, real_allocation.height,
4874 min_width, min_height);
4877 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4878 * allocated sizes and possibly limit them to the natural sizes */
4879 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4880 GTK_ORIENTATION_HORIZONTAL,
4883 &adjusted_allocation.x,
4884 &adjusted_allocation.width);
4885 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4886 GTK_ORIENTATION_VERTICAL,
4889 &adjusted_allocation.y,
4890 &adjusted_allocation.height);
4892 if (adjusted_allocation.x < real_allocation.x ||
4893 adjusted_allocation.y < real_allocation.y ||
4894 (adjusted_allocation.x + adjusted_allocation.width) >
4895 (real_allocation.x + real_allocation.width) ||
4896 (adjusted_allocation.y + adjusted_allocation.height >
4897 real_allocation.y + real_allocation.height))
4899 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",
4900 G_OBJECT_TYPE_NAME (widget), widget,
4901 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4902 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4903 adjusted_allocation = real_allocation; /* veto it */
4907 real_allocation = adjusted_allocation;
4910 if (real_allocation.width < 0 || real_allocation.height < 0)
4912 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4913 real_allocation.width,
4914 real_allocation.height);
4917 real_allocation.width = MAX (real_allocation.width, 1);
4918 real_allocation.height = MAX (real_allocation.height, 1);
4920 size_changed = (old_allocation.width != real_allocation.width ||
4921 old_allocation.height != real_allocation.height);
4922 position_changed = (old_allocation.x != real_allocation.x ||
4923 old_allocation.y != real_allocation.y);
4925 if (!alloc_needed && !size_changed && !position_changed)
4928 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4930 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4931 priv->width_request_needed = FALSE;
4932 priv->height_request_needed = FALSE;
4933 priv->alloc_needed = FALSE;
4935 if (gtk_widget_get_mapped (widget))
4937 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4939 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4941 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4942 cairo_region_union_rectangle (invalidate, &old_allocation);
4944 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4945 cairo_region_destroy (invalidate);
4950 if (priv->redraw_on_alloc)
4952 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4954 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4955 cairo_region_union_rectangle (invalidate, &old_allocation);
4957 gtk_widget_invalidate_widget_windows (widget, invalidate);
4958 cairo_region_destroy (invalidate);
4963 if ((size_changed || position_changed) && priv->parent &&
4964 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4966 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4967 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4968 cairo_region_destroy (invalidate);
4972 gtk_widget_pop_verify_invariants (widget);
4976 * gtk_widget_common_ancestor:
4977 * @widget_a: a #GtkWidget
4978 * @widget_b: a #GtkWidget
4980 * Find the common ancestor of @widget_a and @widget_b that
4981 * is closest to the two widgets.
4983 * Return value: the closest common ancestor of @widget_a and
4984 * @widget_b or %NULL if @widget_a and @widget_b do not
4985 * share a common ancestor.
4988 gtk_widget_common_ancestor (GtkWidget *widget_a,
4989 GtkWidget *widget_b)
4991 GtkWidget *parent_a;
4992 GtkWidget *parent_b;
4996 parent_a = widget_a;
4997 while (parent_a->priv->parent)
4999 parent_a = parent_a->priv->parent;
5003 parent_b = widget_b;
5004 while (parent_b->priv->parent)
5006 parent_b = parent_b->priv->parent;
5010 if (parent_a != parent_b)
5013 while (depth_a > depth_b)
5015 widget_a = widget_a->priv->parent;
5019 while (depth_b > depth_a)
5021 widget_b = widget_b->priv->parent;
5025 while (widget_a != widget_b)
5027 widget_a = widget_a->priv->parent;
5028 widget_b = widget_b->priv->parent;
5035 * gtk_widget_translate_coordinates:
5036 * @src_widget: a #GtkWidget
5037 * @dest_widget: a #GtkWidget
5038 * @src_x: X position relative to @src_widget
5039 * @src_y: Y position relative to @src_widget
5040 * @dest_x: (out): location to store X position relative to @dest_widget
5041 * @dest_y: (out): location to store Y position relative to @dest_widget
5043 * Translate coordinates relative to @src_widget's allocation to coordinates
5044 * relative to @dest_widget's allocations. In order to perform this
5045 * operation, both widgets must be realized, and must share a common
5048 * Return value: %FALSE if either widget was not realized, or there
5049 * was no common ancestor. In this case, nothing is stored in
5050 * *@dest_x and *@dest_y. Otherwise %TRUE.
5053 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5054 GtkWidget *dest_widget,
5060 GtkWidgetPrivate *src_priv = src_widget->priv;
5061 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5062 GtkWidget *ancestor;
5064 GList *dest_list = NULL;
5066 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5067 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5069 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5070 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5073 /* Translate from allocation relative to window relative */
5074 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5077 gdk_window_get_position (src_priv->window, &wx, &wy);
5079 src_x -= wx - src_priv->allocation.x;
5080 src_y -= wy - src_priv->allocation.y;
5084 src_x += src_priv->allocation.x;
5085 src_y += src_priv->allocation.y;
5088 /* Translate to the common ancestor */
5089 window = src_priv->window;
5090 while (window != ancestor->priv->window)
5094 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5099 window = gdk_window_get_effective_parent (window);
5101 if (!window) /* Handle GtkHandleBox */
5106 window = dest_priv->window;
5107 while (window != ancestor->priv->window)
5109 dest_list = g_list_prepend (dest_list, window);
5111 window = gdk_window_get_effective_parent (window);
5113 if (!window) /* Handle GtkHandleBox */
5115 g_list_free (dest_list);
5124 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5129 dest_list = g_list_remove (dest_list, dest_list->data);
5132 /* Translate from window relative to allocation relative */
5133 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5136 gdk_window_get_position (dest_priv->window, &wx, &wy);
5138 src_x += wx - dest_priv->allocation.x;
5139 src_y += wy - dest_priv->allocation.y;
5143 src_x -= dest_priv->allocation.x;
5144 src_y -= dest_priv->allocation.y;
5156 gtk_widget_real_size_allocate (GtkWidget *widget,
5157 GtkAllocation *allocation)
5159 GtkWidgetPrivate *priv = widget->priv;
5161 priv->allocation = *allocation;
5163 if (gtk_widget_get_realized (widget) &&
5164 gtk_widget_get_has_window (widget))
5166 gdk_window_move_resize (priv->window,
5167 allocation->x, allocation->y,
5168 allocation->width, allocation->height);
5172 /* translate initial/final into start/end */
5174 effective_align (GtkAlign align,
5175 GtkTextDirection direction)
5179 case GTK_ALIGN_START:
5180 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5182 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5189 adjust_for_align (GtkAlign align,
5191 gint *allocated_pos,
5192 gint *allocated_size)
5196 case GTK_ALIGN_FILL:
5197 /* change nothing */
5199 case GTK_ALIGN_START:
5200 /* keep *allocated_pos where it is */
5201 *allocated_size = MIN (*allocated_size, *natural_size);
5204 if (*allocated_size > *natural_size)
5206 *allocated_pos += (*allocated_size - *natural_size);
5207 *allocated_size = *natural_size;
5210 case GTK_ALIGN_CENTER:
5211 if (*allocated_size > *natural_size)
5213 *allocated_pos += (*allocated_size - *natural_size) / 2;
5214 *allocated_size = MIN (*allocated_size, *natural_size);
5221 adjust_for_margin(gint start_margin,
5225 gint *allocated_pos,
5226 gint *allocated_size)
5228 *minimum_size -= (start_margin + end_margin);
5229 *natural_size -= (start_margin + end_margin);
5230 *allocated_pos += start_margin;
5231 *allocated_size -= (start_margin + end_margin);
5235 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5236 GtkOrientation orientation,
5239 gint *allocated_pos,
5240 gint *allocated_size)
5242 const GtkWidgetAuxInfo *aux_info;
5244 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5246 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5248 adjust_for_margin (aux_info->margin.left,
5249 aux_info->margin.right,
5250 minimum_size, natural_size,
5251 allocated_pos, allocated_size);
5252 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5253 natural_size, allocated_pos, allocated_size);
5257 adjust_for_margin (aux_info->margin.top,
5258 aux_info->margin.bottom,
5259 minimum_size, natural_size,
5260 allocated_pos, allocated_size);
5261 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5262 natural_size, allocated_pos, allocated_size);
5267 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5270 GtkWidgetPrivate *priv = widget->priv;
5272 /* widgets must be onscreen for accels to take effect */
5273 return gtk_widget_is_sensitive (widget) &&
5274 gtk_widget_is_drawable (widget) &&
5275 gdk_window_is_viewable (priv->window);
5279 * gtk_widget_can_activate_accel:
5280 * @widget: a #GtkWidget
5281 * @signal_id: the ID of a signal installed on @widget
5283 * Determines whether an accelerator that activates the signal
5284 * identified by @signal_id can currently be activated.
5285 * This is done by emitting the #GtkWidget::can-activate-accel
5286 * signal on @widget; if the signal isn't overridden by a
5287 * handler or in a derived widget, then the default check is
5288 * that the widget must be sensitive, and the widget and all
5289 * its ancestors mapped.
5291 * Return value: %TRUE if the accelerator can be activated.
5296 gtk_widget_can_activate_accel (GtkWidget *widget,
5299 gboolean can_activate = FALSE;
5300 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5301 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5302 return can_activate;
5311 closure_accel_activate (GClosure *closure,
5312 GValue *return_value,
5313 guint n_param_values,
5314 const GValue *param_values,
5315 gpointer invocation_hint,
5316 gpointer marshal_data)
5318 AccelClosure *aclosure = (AccelClosure*) closure;
5319 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5322 g_signal_emit (closure->data, aclosure->signal_id, 0);
5324 /* whether accelerator was handled */
5325 g_value_set_boolean (return_value, can_activate);
5329 closures_destroy (gpointer data)
5331 GSList *slist, *closures = data;
5333 for (slist = closures; slist; slist = slist->next)
5335 g_closure_invalidate (slist->data);
5336 g_closure_unref (slist->data);
5338 g_slist_free (closures);
5342 widget_new_accel_closure (GtkWidget *widget,
5345 AccelClosure *aclosure;
5346 GClosure *closure = NULL;
5347 GSList *slist, *closures;
5349 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5350 for (slist = closures; slist; slist = slist->next)
5351 if (!gtk_accel_group_from_accel_closure (slist->data))
5353 /* reuse this closure */
5354 closure = slist->data;
5359 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5360 closures = g_slist_prepend (closures, g_closure_ref (closure));
5361 g_closure_sink (closure);
5362 g_closure_set_marshal (closure, closure_accel_activate);
5364 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5366 aclosure = (AccelClosure*) closure;
5367 g_assert (closure->data == widget);
5368 g_assert (closure->marshal == closure_accel_activate);
5369 aclosure->signal_id = signal_id;
5375 * gtk_widget_add_accelerator:
5376 * @widget: widget to install an accelerator on
5377 * @accel_signal: widget signal to emit on accelerator activation
5378 * @accel_group: accel group for this widget, added to its toplevel
5379 * @accel_key: GDK keyval of the accelerator
5380 * @accel_mods: modifier key combination of the accelerator
5381 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5383 * Installs an accelerator for this @widget in @accel_group that causes
5384 * @accel_signal to be emitted if the accelerator is activated.
5385 * The @accel_group needs to be added to the widget's toplevel via
5386 * gtk_window_add_accel_group(), and the signal must be of type %G_SIGNAL_ACTION.
5387 * Accelerators added through this function are not user changeable during
5388 * runtime. If you want to support accelerators that can be changed by the
5389 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5390 * gtk_menu_item_set_accel_path() instead.
5393 gtk_widget_add_accelerator (GtkWidget *widget,
5394 const gchar *accel_signal,
5395 GtkAccelGroup *accel_group,
5397 GdkModifierType accel_mods,
5398 GtkAccelFlags accel_flags)
5403 g_return_if_fail (GTK_IS_WIDGET (widget));
5404 g_return_if_fail (accel_signal != NULL);
5405 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5407 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5408 if (!query.signal_id ||
5409 !(query.signal_flags & G_SIGNAL_ACTION) ||
5410 query.return_type != G_TYPE_NONE ||
5413 /* hmm, should be elaborate enough */
5414 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5415 G_OBJECT_TYPE_NAME (widget), accel_signal);
5419 closure = widget_new_accel_closure (widget, query.signal_id);
5421 g_object_ref (widget);
5423 /* install the accelerator. since we don't map this onto an accel_path,
5424 * the accelerator will automatically be locked.
5426 gtk_accel_group_connect (accel_group,
5429 accel_flags | GTK_ACCEL_LOCKED,
5432 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5434 g_object_unref (widget);
5438 * gtk_widget_remove_accelerator:
5439 * @widget: widget to install an accelerator on
5440 * @accel_group: accel group for this widget
5441 * @accel_key: GDK keyval of the accelerator
5442 * @accel_mods: modifier key combination of the accelerator
5444 * Removes an accelerator from @widget, previously installed with
5445 * gtk_widget_add_accelerator().
5447 * Returns: whether an accelerator was installed and could be removed
5450 gtk_widget_remove_accelerator (GtkWidget *widget,
5451 GtkAccelGroup *accel_group,
5453 GdkModifierType accel_mods)
5455 GtkAccelGroupEntry *ag_entry;
5456 GList *slist, *clist;
5459 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5460 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5462 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5463 clist = gtk_widget_list_accel_closures (widget);
5464 for (slist = clist; slist; slist = slist->next)
5468 for (i = 0; i < n; i++)
5469 if (slist->data == (gpointer) ag_entry[i].closure)
5471 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5473 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5475 g_list_free (clist);
5480 g_list_free (clist);
5482 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5483 accel_key, accel_mods, accel_group,
5484 G_OBJECT_TYPE_NAME (widget), widget);
5490 * gtk_widget_list_accel_closures:
5491 * @widget: widget to list accelerator closures for
5493 * Lists the closures used by @widget for accelerator group connections
5494 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5495 * The closures can be used to monitor accelerator changes on @widget,
5496 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5497 * #GtkAccelGroup of a closure which can be found out with
5498 * gtk_accel_group_from_accel_closure().
5500 * Return value: (transfer container) (element-type GClosure):
5501 * a newly allocated #GList of closures
5504 gtk_widget_list_accel_closures (GtkWidget *widget)
5507 GList *clist = NULL;
5509 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5511 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5512 if (gtk_accel_group_from_accel_closure (slist->data))
5513 clist = g_list_prepend (clist, slist->data);
5519 GtkAccelGroup *accel_group;
5524 destroy_accel_path (gpointer data)
5526 AccelPath *apath = data;
5528 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5530 /* closures_destroy takes care of unrefing the closure */
5531 g_object_unref (apath->accel_group);
5533 g_slice_free (AccelPath, apath);
5538 * gtk_widget_set_accel_path:
5539 * @widget: a #GtkWidget
5540 * @accel_path: (allow-none): path used to look up the accelerator
5541 * @accel_group: (allow-none): a #GtkAccelGroup.
5543 * Given an accelerator group, @accel_group, and an accelerator path,
5544 * @accel_path, sets up an accelerator in @accel_group so whenever the
5545 * key binding that is defined for @accel_path is pressed, @widget
5546 * will be activated. This removes any accelerators (for any
5547 * accelerator group) installed by previous calls to
5548 * gtk_widget_set_accel_path(). Associating accelerators with
5549 * paths allows them to be modified by the user and the modifications
5550 * to be saved for future use. (See gtk_accel_map_save().)
5552 * This function is a low level function that would most likely
5553 * be used by a menu creation system like #GtkUIManager. If you
5554 * use #GtkUIManager, setting up accelerator paths will be done
5557 * Even when you you aren't using #GtkUIManager, if you only want to
5558 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5559 * provides a somewhat more convenient interface.
5561 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5562 * pass a static string, you can save some memory by interning it first with
5563 * g_intern_static_string().
5566 gtk_widget_set_accel_path (GtkWidget *widget,
5567 const gchar *accel_path,
5568 GtkAccelGroup *accel_group)
5572 g_return_if_fail (GTK_IS_WIDGET (widget));
5573 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5577 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5578 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5580 gtk_accel_map_add_entry (accel_path, 0, 0);
5581 apath = g_slice_new (AccelPath);
5582 apath->accel_group = g_object_ref (accel_group);
5583 apath->path_quark = g_quark_from_string (accel_path);
5584 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5589 /* also removes possible old settings */
5590 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5593 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5595 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5599 _gtk_widget_get_accel_path (GtkWidget *widget,
5604 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5606 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5608 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5609 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5613 * gtk_widget_mnemonic_activate:
5614 * @widget: a #GtkWidget
5615 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5617 * Emits the #GtkWidget::mnemonic-activate signal.
5619 * The default handler for this signal activates the @widget if
5620 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5623 * Returns: %TRUE if the signal has been handled
5626 gtk_widget_mnemonic_activate (GtkWidget *widget,
5627 gboolean group_cycling)
5631 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5633 group_cycling = group_cycling != FALSE;
5634 if (!gtk_widget_is_sensitive (widget))
5637 g_signal_emit (widget,
5638 widget_signals[MNEMONIC_ACTIVATE],
5646 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5647 gboolean group_cycling)
5649 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5650 gtk_widget_activate (widget);
5651 else if (gtk_widget_get_can_focus (widget))
5652 gtk_widget_grab_focus (widget);
5655 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5656 G_OBJECT_TYPE_NAME (widget));
5657 gtk_widget_error_bell (widget);
5662 static const cairo_user_data_key_t event_key;
5665 _gtk_cairo_get_event (cairo_t *cr)
5667 g_return_val_if_fail (cr != NULL, NULL);
5669 return cairo_get_user_data (cr, &event_key);
5673 gtk_cairo_set_event (cairo_t *cr,
5674 GdkEventExpose *event)
5676 cairo_set_user_data (cr, &event_key, event, NULL);
5680 * gtk_cairo_should_draw_window:
5681 * @cr: a cairo context
5682 * @window: the window to check. @window may not be an input-only
5685 * This function is supposed to be called in #GtkWidget::draw
5686 * implementations for widgets that support multiple windows.
5687 * @cr must be untransformed from invoking of the draw function.
5688 * This function will return %TRUE if the contents of the given
5689 * @window are supposed to be drawn and %FALSE otherwise. Note
5690 * that when the drawing was not initiated by the windowing
5691 * system this function will return %TRUE for all windows, so
5692 * you need to draw the bottommost window first. Also, do not
5693 * use "else if" statements to check which window should be drawn.
5695 * Returns: %TRUE if @window should be drawn
5700 gtk_cairo_should_draw_window (cairo_t *cr,
5703 GdkEventExpose *event;
5705 g_return_val_if_fail (cr != NULL, FALSE);
5706 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5708 event = _gtk_cairo_get_event (cr);
5710 return event == NULL ||
5711 event->window == window;
5715 gtk_widget_get_clip_draw (GtkWidget *widget)
5717 /* labels are not clipped, because clipping them would cause
5718 * mnemonics to not appear on characters that go beyond the
5720 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
5722 if (GTK_IS_LABEL (widget))
5728 /* code shared by gtk_container_propagate_draw() and
5732 _gtk_widget_draw_internal (GtkWidget *widget,
5734 gboolean clip_to_size)
5736 if (!gtk_widget_is_drawable (widget))
5739 clip_to_size &= gtk_widget_get_clip_draw (widget);
5743 cairo_rectangle (cr,
5745 widget->priv->allocation.width,
5746 widget->priv->allocation.height);
5750 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5754 g_signal_emit (widget, widget_signals[DRAW],
5758 if (cairo_status (cr) &&
5759 _gtk_cairo_get_event (cr))
5761 /* We check the event so we only warn about internal GTK calls.
5762 * Errors might come from PDF streams having write failures and
5763 * we don't want to spam stderr in that case.
5764 * We do want to catch errors from
5766 g_warning ("drawing failure for widget `%s': %s",
5767 G_OBJECT_TYPE_NAME (widget),
5768 cairo_status_to_string (cairo_status (cr)));
5775 * @widget: the widget to draw. It must be drawable (see
5776 * gtk_widget_is_drawable()) and a size must have been allocated.
5777 * @cr: a cairo context to draw to
5779 * Draws @widget to @cr. The top left corner of the widget will be
5780 * drawn to the currently set origin point of @cr.
5782 * You should pass a cairo context as @cr argument that is in an
5783 * original state. Otherwise the resulting drawing is undefined. For
5784 * example changing the operator using cairo_set_operator() or the
5785 * line width using cairo_set_line_width() might have unwanted side
5787 * You may however change the context's transform matrix - like with
5788 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5789 * region with cairo_clip() prior to calling this function. Also, it
5790 * is fine to modify the context with cairo_save() and
5791 * cairo_push_group() prior to calling this function.
5793 * <note><para>Special purpose widgets may contain special code for
5794 * rendering to the screen and might appear differently on screen
5795 * and when rendered using gtk_widget_draw().</para></note>
5800 gtk_widget_draw (GtkWidget *widget,
5803 GdkEventExpose *tmp_event;
5805 g_return_if_fail (GTK_IS_WIDGET (widget));
5806 g_return_if_fail (!widget->priv->alloc_needed);
5807 g_return_if_fail (cr != NULL);
5810 /* We have to reset the event here so that draw functions can call
5811 * gtk_widget_draw() on random other widgets and get the desired
5812 * effect: Drawing all contents, not just the current window.
5814 tmp_event = _gtk_cairo_get_event (cr);
5815 gtk_cairo_set_event (cr, NULL);
5817 _gtk_widget_draw_internal (widget, cr, TRUE);
5819 gtk_cairo_set_event (cr, tmp_event);
5824 gtk_widget_real_key_press_event (GtkWidget *widget,
5827 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5831 gtk_widget_real_key_release_event (GtkWidget *widget,
5834 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5838 gtk_widget_real_focus_in_event (GtkWidget *widget,
5839 GdkEventFocus *event)
5841 gtk_widget_queue_shallow_draw (widget);
5847 gtk_widget_real_focus_out_event (GtkWidget *widget,
5848 GdkEventFocus *event)
5850 gtk_widget_queue_shallow_draw (widget);
5856 gtk_widget_real_touch_event (GtkWidget *widget,
5857 GdkEventTouch *event)
5860 gboolean return_val;
5863 if (!event->emulating_pointer)
5866 if (event->type == GDK_TOUCH_BEGIN ||
5867 event->type == GDK_TOUCH_END)
5871 if (event->type == GDK_TOUCH_BEGIN)
5873 type = GDK_BUTTON_PRESS;
5874 signum = BUTTON_PRESS_EVENT;
5878 type = GDK_BUTTON_RELEASE;
5879 signum = BUTTON_RELEASE_EVENT;
5881 bevent = gdk_event_new (type);
5882 bevent->any.window = g_object_ref (event->window);
5883 bevent->any.send_event = FALSE;
5884 bevent->button.time = event->time;
5885 bevent->button.state = event->state;
5886 bevent->button.button = 1;
5887 bevent->button.x_root = event->x_root;
5888 bevent->button.y_root = event->y_root;
5889 bevent->button.x = event->x;
5890 bevent->button.y = event->y;
5891 bevent->button.device = event->device;
5892 bevent->button.axes = g_memdup (event->axes,
5893 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
5894 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
5896 else if (event->type == GDK_TOUCH_UPDATE)
5898 signum = MOTION_NOTIFY_EVENT;
5899 bevent = gdk_event_new (GDK_MOTION_NOTIFY);
5900 bevent->any.window = g_object_ref (event->window);
5901 bevent->any.send_event = FALSE;
5902 bevent->motion.time = event->time;
5903 bevent->motion.state = event->state;
5904 bevent->motion.x_root = event->x_root;
5905 bevent->motion.y_root = event->y_root;
5906 bevent->motion.x = event->x;
5907 bevent->motion.y = event->y;
5908 bevent->motion.device = event->device;
5909 bevent->motion.is_hint = FALSE;
5910 bevent->motion.axes = g_memdup (event->axes,
5911 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
5912 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
5917 g_signal_emit (widget, widget_signals[signum], 0, bevent, &return_val);
5919 gdk_event_free (bevent);
5925 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5926 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5930 * @widget: a #GtkWidget
5931 * @event: a #GdkEvent
5933 * Rarely-used function. This function is used to emit
5934 * the event signals on a widget (those signals should never
5935 * be emitted without using this function to do so).
5936 * If you want to synthesize an event though, don't use this function;
5937 * instead, use gtk_main_do_event() so the event will behave as if
5938 * it were in the event queue. Don't synthesize expose events; instead,
5939 * use gdk_window_invalidate_rect() to invalidate a region of the
5942 * Return value: return from the event signal emission (%TRUE if
5943 * the event was handled)
5946 gtk_widget_event (GtkWidget *widget,
5949 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5950 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5952 if (event->type == GDK_EXPOSE)
5954 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5955 "the same effect, call gdk_window_invalidate_rect/region(), "
5956 "followed by gdk_window_process_updates().");
5960 return gtk_widget_event_internal (widget, event);
5964 _gtk_widget_set_captured_event_handler (GtkWidget *widget,
5965 GtkCapturedEventHandler callback)
5967 g_object_set_data (G_OBJECT (widget), "captured-event-handler", callback);
5971 _gtk_widget_captured_event (GtkWidget *widget,
5974 gboolean return_val = FALSE;
5975 GtkCapturedEventHandler handler;
5977 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5978 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5980 if (event->type == GDK_EXPOSE)
5982 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5983 "the same effect, call gdk_window_invalidate_rect/region(), "
5984 "followed by gdk_window_process_updates().");
5988 if (!event_window_is_still_viewable (event))
5991 handler = g_object_get_data (G_OBJECT (widget), "captured-event-handler");
5995 g_object_ref (widget);
5997 return_val = handler (widget, event);
5998 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6000 /* The widget that was originally to receive the event
6001 * handles motion hints, but the capturing widget might
6002 * not, so ensure we get further motion events.
6005 event->type == GDK_MOTION_NOTIFY &&
6006 event->motion.is_hint &&
6007 (gdk_window_get_events (event->any.window) &
6008 GDK_POINTER_MOTION_HINT_MASK) != 0)
6009 gdk_event_request_motions (&event->motion);
6011 g_object_unref (widget);
6016 /* Returns TRUE if a translation should be done */
6018 _gtk_widget_get_translation_to_window (GtkWidget *widget,
6023 GdkWindow *w, *widget_window;
6025 if (!gtk_widget_get_has_window (widget))
6027 *x = -widget->priv->allocation.x;
6028 *y = -widget->priv->allocation.y;
6036 widget_window = gtk_widget_get_window (widget);
6038 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
6041 gdk_window_get_position (w, &wx, &wy);
6058 * gtk_cairo_transform_to_window:
6059 * @cr: the cairo context to transform
6060 * @widget: the widget the context is currently centered for
6061 * @window: the window to transform the context to
6063 * Transforms the given cairo context @cr that from @widget-relative
6064 * coordinates to @window-relative coordinates.
6065 * If the @widget's window is not an ancestor of @window, no
6066 * modification will be applied.
6068 * This is the inverse to the transformation GTK applies when
6069 * preparing an expose event to be emitted with the #GtkWidget::draw
6070 * signal. It is intended to help porting multiwindow widgets from
6071 * GTK+ 2 to the rendering architecture of GTK+ 3.
6076 gtk_cairo_transform_to_window (cairo_t *cr,
6082 g_return_if_fail (cr != NULL);
6083 g_return_if_fail (GTK_IS_WIDGET (widget));
6084 g_return_if_fail (GDK_IS_WINDOW (window));
6086 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
6087 cairo_translate (cr, x, y);
6091 * gtk_widget_send_expose:
6092 * @widget: a #GtkWidget
6093 * @event: a expose #GdkEvent
6095 * Very rarely-used function. This function is used to emit
6096 * an expose event on a widget. This function is not normally used
6097 * directly. The only time it is used is when propagating an expose
6098 * event to a child %NO_WINDOW widget, and that is normally done
6099 * using gtk_container_propagate_draw().
6101 * If you want to force an area of a window to be redrawn,
6102 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
6103 * To cause the redraw to be done immediately, follow that call
6104 * with a call to gdk_window_process_updates().
6106 * Return value: return from the event signal emission (%TRUE if
6107 * the event was handled)
6110 gtk_widget_send_expose (GtkWidget *widget,
6113 gboolean result = FALSE;
6118 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6119 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
6120 g_return_val_if_fail (event != NULL, TRUE);
6121 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
6123 cr = gdk_cairo_create (event->expose.window);
6124 gtk_cairo_set_event (cr, &event->expose);
6126 gdk_cairo_region (cr, event->expose.region);
6129 do_clip = _gtk_widget_get_translation_to_window (widget,
6130 event->expose.window,
6132 cairo_translate (cr, -x, -y);
6134 _gtk_widget_draw_internal (widget, cr, do_clip);
6136 /* unset here, so if someone keeps a reference to cr we
6137 * don't leak the window. */
6138 gtk_cairo_set_event (cr, NULL);
6145 event_window_is_still_viewable (GdkEvent *event)
6147 /* Check that we think the event's window is viewable before
6148 * delivering the event, to prevent suprises. We do this here
6149 * at the last moment, since the event may have been queued
6150 * up behind other events, held over a recursive main loop, etc.
6152 switch (event->type)
6155 case GDK_MOTION_NOTIFY:
6156 case GDK_BUTTON_PRESS:
6157 case GDK_2BUTTON_PRESS:
6158 case GDK_3BUTTON_PRESS:
6160 case GDK_ENTER_NOTIFY:
6161 case GDK_PROXIMITY_IN:
6163 return event->any.window && gdk_window_is_viewable (event->any.window);
6166 /* The following events are the second half of paired events;
6167 * we always deliver them to deal with widgets that clean up
6168 * on the second half.
6170 case GDK_BUTTON_RELEASE:
6171 case GDK_KEY_RELEASE:
6172 case GDK_LEAVE_NOTIFY:
6173 case GDK_PROXIMITY_OUT:
6177 /* Remaining events would make sense on an not-viewable window,
6178 * or don't have an associated window.
6185 gtk_widget_event_internal (GtkWidget *widget,
6188 gboolean return_val = FALSE;
6190 /* We check only once for is-still-visible; if someone
6191 * hides the window in on of the signals on the widget,
6192 * they are responsible for returning TRUE to terminate
6195 if (!event_window_is_still_viewable (event))
6198 g_object_ref (widget);
6200 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6201 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6206 switch (event->type)
6212 case GDK_BUTTON_PRESS:
6213 case GDK_2BUTTON_PRESS:
6214 case GDK_3BUTTON_PRESS:
6215 signal_num = BUTTON_PRESS_EVENT;
6217 case GDK_TOUCH_BEGIN:
6218 case GDK_TOUCH_UPDATE:
6220 case GDK_TOUCH_CANCEL:
6221 signal_num = TOUCH_EVENT;
6224 signal_num = SCROLL_EVENT;
6226 case GDK_BUTTON_RELEASE:
6227 signal_num = BUTTON_RELEASE_EVENT;
6229 case GDK_MOTION_NOTIFY:
6230 signal_num = MOTION_NOTIFY_EVENT;
6233 signal_num = DELETE_EVENT;
6236 signal_num = DESTROY_EVENT;
6237 _gtk_tooltip_hide (widget);
6240 signal_num = KEY_PRESS_EVENT;
6242 case GDK_KEY_RELEASE:
6243 signal_num = KEY_RELEASE_EVENT;
6245 case GDK_ENTER_NOTIFY:
6246 signal_num = ENTER_NOTIFY_EVENT;
6248 case GDK_LEAVE_NOTIFY:
6249 signal_num = LEAVE_NOTIFY_EVENT;
6251 case GDK_FOCUS_CHANGE:
6252 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6253 if (event->focus_change.in)
6254 _gtk_tooltip_focus_in (widget);
6256 _gtk_tooltip_focus_out (widget);
6259 signal_num = CONFIGURE_EVENT;
6262 signal_num = MAP_EVENT;
6265 signal_num = UNMAP_EVENT;
6267 case GDK_WINDOW_STATE:
6268 signal_num = WINDOW_STATE_EVENT;
6270 case GDK_PROPERTY_NOTIFY:
6271 signal_num = PROPERTY_NOTIFY_EVENT;
6273 case GDK_SELECTION_CLEAR:
6274 signal_num = SELECTION_CLEAR_EVENT;
6276 case GDK_SELECTION_REQUEST:
6277 signal_num = SELECTION_REQUEST_EVENT;
6279 case GDK_SELECTION_NOTIFY:
6280 signal_num = SELECTION_NOTIFY_EVENT;
6282 case GDK_PROXIMITY_IN:
6283 signal_num = PROXIMITY_IN_EVENT;
6285 case GDK_PROXIMITY_OUT:
6286 signal_num = PROXIMITY_OUT_EVENT;
6288 case GDK_VISIBILITY_NOTIFY:
6289 signal_num = VISIBILITY_NOTIFY_EVENT;
6291 case GDK_GRAB_BROKEN:
6292 signal_num = GRAB_BROKEN_EVENT;
6295 signal_num = DAMAGE_EVENT;
6298 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6302 if (signal_num != -1)
6303 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6305 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6306 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6310 g_object_unref (widget);
6316 * gtk_widget_activate:
6317 * @widget: a #GtkWidget that's activatable
6319 * For widgets that can be "activated" (buttons, menu items, etc.)
6320 * this function activates them. Activation is what happens when you
6321 * press Enter on a widget during key navigation. If @widget isn't
6322 * activatable, the function returns %FALSE.
6324 * Return value: %TRUE if the widget was activatable
6327 gtk_widget_activate (GtkWidget *widget)
6329 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6331 if (WIDGET_CLASS (widget)->activate_signal)
6333 /* FIXME: we should eventually check the signals signature here */
6334 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6343 gtk_widget_reparent_subwindows (GtkWidget *widget,
6344 GdkWindow *new_window)
6346 GtkWidgetPrivate *priv = widget->priv;
6348 if (!gtk_widget_get_has_window (widget))
6350 GList *children = gdk_window_get_children (priv->window);
6353 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6355 GdkWindow *window = tmp_list->data;
6358 gdk_window_get_user_data (window, &child);
6359 while (child && child != widget)
6360 child = ((GtkWidget*) child)->priv->parent;
6363 gdk_window_reparent (window, new_window, 0, 0);
6366 g_list_free (children);
6371 GList *tmp_list, *children;
6373 parent = gdk_window_get_parent (priv->window);
6376 gdk_window_reparent (priv->window, new_window, 0, 0);
6379 children = gdk_window_get_children (parent);
6381 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6383 GdkWindow *window = tmp_list->data;
6386 gdk_window_get_user_data (window, &child);
6388 if (child == widget)
6389 gdk_window_reparent (window, new_window, 0, 0);
6392 g_list_free (children);
6398 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6399 gpointer client_data)
6401 GtkWidgetPrivate *priv = widget->priv;
6403 g_assert (client_data != NULL);
6405 if (!gtk_widget_get_has_window (widget))
6408 g_object_unref (priv->window);
6409 priv->window = (GdkWindow*) client_data;
6411 g_object_ref (priv->window);
6413 if (GTK_IS_CONTAINER (widget))
6414 gtk_container_forall (GTK_CONTAINER (widget),
6415 gtk_widget_reparent_fixup_child,
6421 * gtk_widget_reparent:
6422 * @widget: a #GtkWidget
6423 * @new_parent: a #GtkContainer to move the widget into
6425 * Moves a widget from one #GtkContainer to another, handling reference
6426 * count issues to avoid destroying the widget.
6429 gtk_widget_reparent (GtkWidget *widget,
6430 GtkWidget *new_parent)
6432 GtkWidgetPrivate *priv;
6434 g_return_if_fail (GTK_IS_WIDGET (widget));
6435 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6436 priv = widget->priv;
6437 g_return_if_fail (priv->parent != NULL);
6439 if (priv->parent != new_parent)
6441 /* First try to see if we can get away without unrealizing
6442 * the widget as we reparent it. if so we set a flag so
6443 * that gtk_widget_unparent doesn't unrealize widget
6445 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6446 priv->in_reparent = TRUE;
6448 g_object_ref (widget);
6449 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6450 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6451 g_object_unref (widget);
6453 if (priv->in_reparent)
6455 priv->in_reparent = FALSE;
6457 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6458 gtk_widget_reparent_fixup_child (widget,
6459 gtk_widget_get_parent_window (widget));
6462 g_object_notify (G_OBJECT (widget), "parent");
6467 * gtk_widget_intersect:
6468 * @widget: a #GtkWidget
6469 * @area: a rectangle
6470 * @intersection: rectangle to store intersection of @widget and @area
6472 * Computes the intersection of a @widget's area and @area, storing
6473 * the intersection in @intersection, and returns %TRUE if there was
6474 * an intersection. @intersection may be %NULL if you're only
6475 * interested in whether there was an intersection.
6477 * Return value: %TRUE if there was an intersection
6480 gtk_widget_intersect (GtkWidget *widget,
6481 const GdkRectangle *area,
6482 GdkRectangle *intersection)
6484 GtkWidgetPrivate *priv;
6489 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6490 g_return_val_if_fail (area != NULL, FALSE);
6492 priv = widget->priv;
6495 dest = intersection;
6499 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6501 if (return_val && intersection && gtk_widget_get_has_window (widget))
6503 intersection->x -= priv->allocation.x;
6504 intersection->y -= priv->allocation.y;
6511 * gtk_widget_region_intersect:
6512 * @widget: a #GtkWidget
6513 * @region: a #cairo_region_t, in the same coordinate system as
6514 * @widget->allocation. That is, relative to @widget->window
6515 * for %NO_WINDOW widgets; relative to the parent window
6516 * of @widget->window for widgets with their own window.
6518 * Computes the intersection of a @widget's area and @region, returning
6519 * the intersection. The result may be empty, use cairo_region_is_empty() to
6522 * Returns: A newly allocated region holding the intersection of @widget
6523 * and @region. The coordinates of the return value are relative to
6524 * @widget->window for %NO_WINDOW widgets, and relative to the parent
6525 * window of @widget->window for widgets with their own window.
6528 gtk_widget_region_intersect (GtkWidget *widget,
6529 const cairo_region_t *region)
6532 cairo_region_t *dest;
6534 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6535 g_return_val_if_fail (region != NULL, NULL);
6537 gtk_widget_get_allocation (widget, &rect);
6539 dest = cairo_region_create_rectangle (&rect);
6541 cairo_region_intersect (dest, region);
6547 * _gtk_widget_grab_notify:
6548 * @widget: a #GtkWidget
6549 * @was_grabbed: whether a grab is now in effect
6551 * Emits the #GtkWidget::grab-notify signal on @widget.
6556 _gtk_widget_grab_notify (GtkWidget *widget,
6557 gboolean was_grabbed)
6559 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6563 * gtk_widget_grab_focus:
6564 * @widget: a #GtkWidget
6566 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6567 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6568 * something like #GtkFrame won't work.
6570 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6571 * gtk_widget_set_can_focus() to modify that flag.
6573 * The widget also needs to be realized and mapped. This is indicated by the
6574 * related signals. Grabbing the focus immediately after creating the widget
6575 * will likely fail and cause critical warnings.
6578 gtk_widget_grab_focus (GtkWidget *widget)
6580 g_return_if_fail (GTK_IS_WIDGET (widget));
6582 if (!gtk_widget_is_sensitive (widget))
6585 g_object_ref (widget);
6586 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6587 g_object_notify (G_OBJECT (widget), "has-focus");
6588 g_object_unref (widget);
6592 reset_focus_recurse (GtkWidget *widget,
6595 if (GTK_IS_CONTAINER (widget))
6597 GtkContainer *container;
6599 container = GTK_CONTAINER (widget);
6600 gtk_container_set_focus_child (container, NULL);
6602 gtk_container_foreach (container,
6603 reset_focus_recurse,
6609 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6611 if (gtk_widget_get_can_focus (focus_widget))
6613 GtkWidget *toplevel;
6616 /* clear the current focus setting, break if the current widget
6617 * is the focus widget's parent, since containers above that will
6618 * be set by the next loop.
6620 toplevel = gtk_widget_get_toplevel (focus_widget);
6621 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6623 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6625 if (widget == focus_widget)
6627 /* We call _gtk_window_internal_set_focus() here so that the
6628 * toplevel window can request the focus if necessary.
6629 * This is needed when the toplevel is a GtkPlug
6631 if (!gtk_widget_has_focus (widget))
6632 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6639 GtkWidget *common_ancestor = gtk_widget_common_ancestor (widget, focus_widget);
6641 if (widget != common_ancestor)
6643 while (widget->priv->parent && widget->priv->parent != common_ancestor)
6645 widget = widget->priv->parent;
6646 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6651 else if (toplevel != focus_widget)
6653 /* gtk_widget_grab_focus() operates on a tree without window...
6654 * actually, this is very questionable behaviour.
6657 gtk_container_foreach (GTK_CONTAINER (toplevel),
6658 reset_focus_recurse,
6662 /* now propagate the new focus up the widget tree and finally
6663 * set it on the window
6665 widget = focus_widget;
6666 while (widget->priv->parent)
6668 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6669 widget = widget->priv->parent;
6671 if (GTK_IS_WINDOW (widget))
6672 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6677 gtk_widget_real_query_tooltip (GtkWidget *widget,
6680 gboolean keyboard_tip,
6681 GtkTooltip *tooltip)
6683 gchar *tooltip_markup;
6684 gboolean has_tooltip;
6686 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6687 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6689 if (has_tooltip && tooltip_markup)
6691 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6699 gtk_widget_real_state_flags_changed (GtkWidget *widget,
6700 GtkStateFlags old_state)
6702 gtk_widget_update_pango_context (widget);
6706 gtk_widget_real_style_updated (GtkWidget *widget)
6708 GtkWidgetPrivate *priv = widget->priv;
6710 gtk_widget_update_pango_context (widget);
6712 if (priv->style != NULL &&
6713 priv->style != gtk_widget_get_default_style ())
6715 /* Trigger ::style-set for old
6716 * widgets not listening to this
6718 g_signal_emit (widget,
6719 widget_signals[STYLE_SET],
6721 widget->priv->style);
6724 if (widget->priv->context)
6726 if (gtk_widget_get_realized (widget) &&
6727 gtk_widget_get_has_window (widget) &&
6728 !gtk_widget_get_app_paintable (widget))
6729 gtk_style_context_set_background (widget->priv->context,
6730 widget->priv->window);
6733 if (widget->priv->anchored)
6734 gtk_widget_queue_resize (widget);
6738 gtk_widget_real_show_help (GtkWidget *widget,
6739 GtkWidgetHelpType help_type)
6741 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6743 _gtk_tooltip_toggle_keyboard_mode (widget);
6752 gtk_widget_real_focus (GtkWidget *widget,
6753 GtkDirectionType direction)
6755 if (!gtk_widget_get_can_focus (widget))
6758 if (!gtk_widget_is_focus (widget))
6760 gtk_widget_grab_focus (widget);
6768 gtk_widget_real_move_focus (GtkWidget *widget,
6769 GtkDirectionType direction)
6771 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6773 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6775 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6781 gtk_widget_real_keynav_failed (GtkWidget *widget,
6782 GtkDirectionType direction)
6784 gboolean cursor_only;
6788 case GTK_DIR_TAB_FORWARD:
6789 case GTK_DIR_TAB_BACKWARD:
6796 g_object_get (gtk_widget_get_settings (widget),
6797 "gtk-keynav-cursor-only", &cursor_only,
6804 gtk_widget_error_bell (widget);
6810 * gtk_widget_set_can_focus:
6811 * @widget: a #GtkWidget
6812 * @can_focus: whether or not @widget can own the input focus.
6814 * Specifies whether @widget can own the input focus. See
6815 * gtk_widget_grab_focus() for actually setting the input focus on a
6821 gtk_widget_set_can_focus (GtkWidget *widget,
6824 g_return_if_fail (GTK_IS_WIDGET (widget));
6826 if (widget->priv->can_focus != can_focus)
6828 widget->priv->can_focus = can_focus;
6830 gtk_widget_queue_resize (widget);
6831 g_object_notify (G_OBJECT (widget), "can-focus");
6836 * gtk_widget_get_can_focus:
6837 * @widget: a #GtkWidget
6839 * Determines whether @widget can own the input focus. See
6840 * gtk_widget_set_can_focus().
6842 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6847 gtk_widget_get_can_focus (GtkWidget *widget)
6849 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6851 return widget->priv->can_focus;
6855 * gtk_widget_has_focus:
6856 * @widget: a #GtkWidget
6858 * Determines if the widget has the global input focus. See
6859 * gtk_widget_is_focus() for the difference between having the global
6860 * input focus, and only having the focus within a toplevel.
6862 * Return value: %TRUE if the widget has the global input focus.
6867 gtk_widget_has_focus (GtkWidget *widget)
6869 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6871 return widget->priv->has_focus;
6875 * gtk_widget_has_visible_focus:
6876 * @widget: a #GtkWidget
6878 * Determines if the widget should show a visible indication that
6879 * it has the global input focus. This is a convenience function for
6880 * use in ::draw handlers that takes into account whether focus
6881 * indication should currently be shown in the toplevel window of
6882 * @widget. See gtk_window_get_focus_visible() for more information
6883 * about focus indication.
6885 * To find out if the widget has the global input focus, use
6886 * gtk_widget_has_focus().
6888 * Return value: %TRUE if the widget should display a 'focus rectangle'
6893 gtk_widget_has_visible_focus (GtkWidget *widget)
6895 gboolean draw_focus;
6897 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6899 if (widget->priv->has_focus)
6901 GtkWidget *toplevel;
6903 toplevel = gtk_widget_get_toplevel (widget);
6905 if (GTK_IS_WINDOW (toplevel))
6906 draw_focus = gtk_window_get_focus_visible (GTK_WINDOW (toplevel));
6917 * gtk_widget_is_focus:
6918 * @widget: a #GtkWidget
6920 * Determines if the widget is the focus widget within its
6921 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6922 * necessarily set; %HAS_FOCUS will only be set if the
6923 * toplevel widget additionally has the global input focus.)
6925 * Return value: %TRUE if the widget is the focus widget.
6928 gtk_widget_is_focus (GtkWidget *widget)
6930 GtkWidget *toplevel;
6932 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6934 toplevel = gtk_widget_get_toplevel (widget);
6936 if (GTK_IS_WINDOW (toplevel))
6937 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6943 * gtk_widget_set_can_default:
6944 * @widget: a #GtkWidget
6945 * @can_default: whether or not @widget can be a default widget.
6947 * Specifies whether @widget can be a default widget. See
6948 * gtk_widget_grab_default() for details about the meaning of
6954 gtk_widget_set_can_default (GtkWidget *widget,
6955 gboolean can_default)
6957 g_return_if_fail (GTK_IS_WIDGET (widget));
6959 if (widget->priv->can_default != can_default)
6961 widget->priv->can_default = can_default;
6963 gtk_widget_queue_resize (widget);
6964 g_object_notify (G_OBJECT (widget), "can-default");
6969 * gtk_widget_get_can_default:
6970 * @widget: a #GtkWidget
6972 * Determines whether @widget can be a default widget. See
6973 * gtk_widget_set_can_default().
6975 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6980 gtk_widget_get_can_default (GtkWidget *widget)
6982 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6984 return widget->priv->can_default;
6988 * gtk_widget_has_default:
6989 * @widget: a #GtkWidget
6991 * Determines whether @widget is the current default widget within its
6992 * toplevel. See gtk_widget_set_can_default().
6994 * Return value: %TRUE if @widget is the current default widget within
6995 * its toplevel, %FALSE otherwise
7000 gtk_widget_has_default (GtkWidget *widget)
7002 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7004 return widget->priv->has_default;
7008 _gtk_widget_set_has_default (GtkWidget *widget,
7009 gboolean has_default)
7011 GtkStyleContext *context;
7013 widget->priv->has_default = has_default;
7015 context = gtk_widget_get_style_context (widget);
7018 gtk_style_context_add_class (context, GTK_STYLE_CLASS_DEFAULT);
7020 gtk_style_context_remove_class (context, GTK_STYLE_CLASS_DEFAULT);
7024 * gtk_widget_grab_default:
7025 * @widget: a #GtkWidget
7027 * Causes @widget to become the default widget. @widget must be able to be
7028 * a default widget; typically you would ensure this yourself
7029 * by calling gtk_widget_set_can_default() with a %TRUE value.
7030 * The default widget is activated when
7031 * the user presses Enter in a window. Default widgets must be
7032 * activatable, that is, gtk_widget_activate() should affect them. Note
7033 * that #GtkEntry widgets require the "activates-default" property
7034 * set to %TRUE before they activate the default widget when Enter
7035 * is pressed and the #GtkEntry is focused.
7038 gtk_widget_grab_default (GtkWidget *widget)
7042 g_return_if_fail (GTK_IS_WIDGET (widget));
7043 g_return_if_fail (gtk_widget_get_can_default (widget));
7045 window = gtk_widget_get_toplevel (widget);
7047 if (window && gtk_widget_is_toplevel (window))
7048 gtk_window_set_default (GTK_WINDOW (window), widget);
7050 g_warning (G_STRLOC ": widget not within a GtkWindow");
7054 * gtk_widget_set_receives_default:
7055 * @widget: a #GtkWidget
7056 * @receives_default: whether or not @widget can be a default widget.
7058 * Specifies whether @widget will be treated as the default widget
7059 * within its toplevel when it has the focus, even if another widget
7062 * See gtk_widget_grab_default() for details about the meaning of
7068 gtk_widget_set_receives_default (GtkWidget *widget,
7069 gboolean receives_default)
7071 g_return_if_fail (GTK_IS_WIDGET (widget));
7073 if (widget->priv->receives_default != receives_default)
7075 widget->priv->receives_default = receives_default;
7077 g_object_notify (G_OBJECT (widget), "receives-default");
7082 * gtk_widget_get_receives_default:
7083 * @widget: a #GtkWidget
7085 * Determines whether @widget is alyways treated as default widget
7086 * withing its toplevel when it has the focus, even if another widget
7089 * See gtk_widget_set_receives_default().
7091 * Return value: %TRUE if @widget acts as default widget when focussed,
7097 gtk_widget_get_receives_default (GtkWidget *widget)
7099 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7101 return widget->priv->receives_default;
7105 * gtk_widget_has_grab:
7106 * @widget: a #GtkWidget
7108 * Determines whether the widget is currently grabbing events, so it
7109 * is the only widget receiving input events (keyboard and mouse).
7111 * See also gtk_grab_add().
7113 * Return value: %TRUE if the widget is in the grab_widgets stack
7118 gtk_widget_has_grab (GtkWidget *widget)
7120 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7122 return widget->priv->has_grab;
7126 _gtk_widget_set_has_grab (GtkWidget *widget,
7129 widget->priv->has_grab = has_grab;
7133 * gtk_widget_device_is_shadowed:
7134 * @widget: a #GtkWidget
7135 * @device: a #GdkDevice
7137 * Returns %TRUE if @device has been shadowed by a GTK+
7138 * device grab on another widget, so it would stop sending
7139 * events to @widget. This may be used in the
7140 * #GtkWidget::grab-notify signal to check for specific
7141 * devices. See gtk_device_grab_add().
7143 * Returns: %TRUE if there is an ongoing grab on @device
7144 * by another #GtkWidget than @widget.
7149 gtk_widget_device_is_shadowed (GtkWidget *widget,
7152 GtkWindowGroup *group;
7153 GtkWidget *grab_widget, *toplevel;
7155 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7156 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
7158 if (!gtk_widget_get_realized (widget))
7161 toplevel = gtk_widget_get_toplevel (widget);
7163 if (GTK_IS_WINDOW (toplevel))
7164 group = gtk_window_get_group (GTK_WINDOW (toplevel));
7166 group = gtk_window_get_group (NULL);
7168 grab_widget = gtk_window_group_get_current_device_grab (group, device);
7170 /* Widget not inside the hierarchy of grab_widget */
7172 widget != grab_widget &&
7173 !gtk_widget_is_ancestor (widget, grab_widget))
7176 grab_widget = gtk_window_group_get_current_grab (group);
7177 if (grab_widget && widget != grab_widget &&
7178 !gtk_widget_is_ancestor (widget, grab_widget))
7185 * gtk_widget_set_name:
7186 * @widget: a #GtkWidget
7187 * @name: name for the widget
7189 * Widgets can be named, which allows you to refer to them from a
7190 * CSS file. You can apply a style to widgets with a particular name
7191 * in the CSS file. See the documentation for the CSS syntax (on the
7192 * same page as the docs for #GtkStyleContext).
7194 * Note that the CSS syntax has certain special characters to delimit
7195 * and represent elements in a selector (period, #, >, *...),
7196 * so using these will make your widget impossible to match by name.
7197 * Any combination of alphanumeric symbols, dashes and underscores will
7201 gtk_widget_set_name (GtkWidget *widget,
7204 GtkWidgetPrivate *priv;
7207 g_return_if_fail (GTK_IS_WIDGET (widget));
7209 priv = widget->priv;
7211 new_name = g_strdup (name);
7212 g_free (priv->name);
7213 priv->name = new_name;
7215 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_NAME);
7217 g_object_notify (G_OBJECT (widget), "name");
7221 * gtk_widget_get_name:
7222 * @widget: a #GtkWidget
7224 * Retrieves the name of a widget. See gtk_widget_set_name() for the
7225 * significance of widget names.
7227 * Return value: name of the widget. This string is owned by GTK+ and
7228 * should not be modified or freed
7231 gtk_widget_get_name (GtkWidget *widget)
7233 GtkWidgetPrivate *priv;
7235 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7237 priv = widget->priv;
7241 return G_OBJECT_TYPE_NAME (widget);
7245 _gtk_widget_update_state_flags (GtkWidget *widget,
7246 GtkStateFlags flags,
7249 GtkWidgetPrivate *priv;
7251 priv = widget->priv;
7253 /* Handle insensitive first, since it is propagated
7254 * differently throughout the widget hierarchy.
7256 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_UNSET))
7257 gtk_widget_set_sensitive (widget, TRUE);
7258 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation != STATE_CHANGE_UNSET))
7259 gtk_widget_set_sensitive (widget, FALSE);
7260 else if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && !(flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_REPLACE))
7261 gtk_widget_set_sensitive (widget, TRUE);
7263 if (operation != STATE_CHANGE_REPLACE)
7264 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
7267 operation == STATE_CHANGE_REPLACE)
7272 data.operation = operation;
7274 gtk_widget_propagate_state (widget, &data);
7276 gtk_widget_queue_resize (widget);
7281 * gtk_widget_set_state_flags:
7282 * @widget: a #GtkWidget
7283 * @flags: State flags to turn on
7284 * @clear: Whether to clear state before turning on @flags
7286 * This function is for use in widget implementations. Turns on flag
7287 * values in the current widget state (insensitive, prelighted, etc.).
7289 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7290 * will be propagated down to all non-internal children if @widget is a
7291 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7292 * down to all #GtkContainer children by different means than turning on the
7293 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7294 * gtk_widget_is_sensitive() will make use of these.
7299 gtk_widget_set_state_flags (GtkWidget *widget,
7300 GtkStateFlags flags,
7303 g_return_if_fail (GTK_IS_WIDGET (widget));
7305 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7306 (clear && widget->priv->state_flags == flags))
7310 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7312 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
7316 * gtk_widget_unset_state_flags:
7317 * @widget: a #GtkWidget
7318 * @flags: State flags to turn off
7320 * This function is for use in widget implementations. Turns off flag
7321 * values for the current widget state (insensitive, prelighted, etc.).
7322 * See gtk_widget_set_state_flags().
7327 gtk_widget_unset_state_flags (GtkWidget *widget,
7328 GtkStateFlags flags)
7330 g_return_if_fail (GTK_IS_WIDGET (widget));
7332 if ((widget->priv->state_flags & flags) == 0)
7335 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
7339 * gtk_widget_get_state_flags:
7340 * @widget: a #GtkWidget
7342 * Returns the widget state as a flag set. It is worth mentioning
7343 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7344 * returned, that is, also based on parent insensitivity, even if
7345 * @widget itself is sensitive.
7347 * Returns: The state flags for widget
7352 gtk_widget_get_state_flags (GtkWidget *widget)
7354 GtkStateFlags flags;
7356 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7358 flags = widget->priv->state_flags;
7360 if (gtk_widget_has_focus (widget))
7361 flags |= GTK_STATE_FLAG_FOCUSED;
7367 * gtk_widget_set_state:
7368 * @widget: a #GtkWidget
7369 * @state: new state for @widget
7371 * This function is for use in widget implementations. Sets the state
7372 * of a widget (insensitive, prelighted, etc.) Usually you should set
7373 * the state using wrapper functions such as gtk_widget_set_sensitive().
7375 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7378 gtk_widget_set_state (GtkWidget *widget,
7381 GtkStateFlags flags;
7383 if (state == gtk_widget_get_state (widget))
7388 case GTK_STATE_ACTIVE:
7389 flags = GTK_STATE_FLAG_ACTIVE;
7391 case GTK_STATE_PRELIGHT:
7392 flags = GTK_STATE_FLAG_PRELIGHT;
7394 case GTK_STATE_SELECTED:
7395 flags = GTK_STATE_FLAG_SELECTED;
7397 case GTK_STATE_INSENSITIVE:
7398 flags = GTK_STATE_FLAG_INSENSITIVE;
7400 case GTK_STATE_INCONSISTENT:
7401 flags = GTK_STATE_FLAG_INCONSISTENT;
7403 case GTK_STATE_FOCUSED:
7404 flags = GTK_STATE_FLAG_FOCUSED;
7406 case GTK_STATE_NORMAL:
7412 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7416 * gtk_widget_get_state:
7417 * @widget: a #GtkWidget
7419 * Returns the widget's state. See gtk_widget_set_state().
7421 * Returns: the state of @widget.
7425 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7428 gtk_widget_get_state (GtkWidget *widget)
7430 GtkStateFlags flags;
7432 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7434 flags = gtk_widget_get_state_flags (widget);
7436 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7437 return GTK_STATE_INSENSITIVE;
7438 else if (flags & GTK_STATE_FLAG_ACTIVE)
7439 return GTK_STATE_ACTIVE;
7440 else if (flags & GTK_STATE_FLAG_SELECTED)
7441 return GTK_STATE_SELECTED;
7442 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7443 return GTK_STATE_PRELIGHT;
7445 return GTK_STATE_NORMAL;
7449 * gtk_widget_set_visible:
7450 * @widget: a #GtkWidget
7451 * @visible: whether the widget should be shown or not
7453 * Sets the visibility state of @widget. Note that setting this to
7454 * %TRUE doesn't mean the widget is actually viewable, see
7455 * gtk_widget_get_visible().
7457 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7458 * but is nicer to use when the visibility of the widget depends on
7464 gtk_widget_set_visible (GtkWidget *widget,
7467 g_return_if_fail (GTK_IS_WIDGET (widget));
7469 if (visible != gtk_widget_get_visible (widget))
7472 gtk_widget_show (widget);
7474 gtk_widget_hide (widget);
7479 _gtk_widget_set_visible_flag (GtkWidget *widget,
7482 widget->priv->visible = visible;
7486 * gtk_widget_get_visible:
7487 * @widget: a #GtkWidget
7489 * Determines whether the widget is visible. Note that this doesn't
7490 * take into account whether the widget's parent is also visible
7491 * or the widget is obscured in any way.
7493 * See gtk_widget_set_visible().
7495 * Return value: %TRUE if the widget is visible
7500 gtk_widget_get_visible (GtkWidget *widget)
7502 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7504 return widget->priv->visible;
7508 * gtk_widget_set_has_window:
7509 * @widget: a #GtkWidget
7510 * @has_window: whether or not @widget has a window.
7512 * Specifies whether @widget has a #GdkWindow of its own. Note that
7513 * all realized widgets have a non-%NULL "window" pointer
7514 * (gtk_widget_get_window() never returns a %NULL window when a widget
7515 * is realized), but for many of them it's actually the #GdkWindow of
7516 * one of its parent widgets. Widgets that do not create a %window for
7517 * themselves in #GtkWidget::realize must announce this by
7518 * calling this function with @has_window = %FALSE.
7520 * This function should only be called by widget implementations,
7521 * and they should call it in their init() function.
7526 gtk_widget_set_has_window (GtkWidget *widget,
7527 gboolean has_window)
7529 g_return_if_fail (GTK_IS_WIDGET (widget));
7531 widget->priv->no_window = !has_window;
7535 * gtk_widget_get_has_window:
7536 * @widget: a #GtkWidget
7538 * Determines whether @widget has a #GdkWindow of its own. See
7539 * gtk_widget_set_has_window().
7541 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7546 gtk_widget_get_has_window (GtkWidget *widget)
7548 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7550 return ! widget->priv->no_window;
7554 * gtk_widget_is_toplevel:
7555 * @widget: a #GtkWidget
7557 * Determines whether @widget is a toplevel widget.
7559 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7560 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7563 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7568 gtk_widget_is_toplevel (GtkWidget *widget)
7570 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7572 return widget->priv->toplevel;
7576 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7577 gboolean is_toplevel)
7579 widget->priv->toplevel = is_toplevel;
7583 * gtk_widget_is_drawable:
7584 * @widget: a #GtkWidget
7586 * Determines whether @widget can be drawn to. A widget can be drawn
7587 * to if it is mapped and visible.
7589 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7594 gtk_widget_is_drawable (GtkWidget *widget)
7596 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7598 return (gtk_widget_get_visible (widget) &&
7599 gtk_widget_get_mapped (widget));
7603 * gtk_widget_get_realized:
7604 * @widget: a #GtkWidget
7606 * Determines whether @widget is realized.
7608 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7613 gtk_widget_get_realized (GtkWidget *widget)
7615 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7617 return widget->priv->realized;
7621 * gtk_widget_set_realized:
7622 * @widget: a #GtkWidget
7623 * @realized: %TRUE to mark the widget as realized
7625 * Marks the widget as being realized.
7627 * This function should only ever be called in a derived widget's
7628 * "realize" or "unrealize" implementation.
7633 gtk_widget_set_realized (GtkWidget *widget,
7636 g_return_if_fail (GTK_IS_WIDGET (widget));
7638 widget->priv->realized = realized;
7642 * gtk_widget_get_mapped:
7643 * @widget: a #GtkWidget
7645 * Whether the widget is mapped.
7647 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7652 gtk_widget_get_mapped (GtkWidget *widget)
7654 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7656 return widget->priv->mapped;
7660 * gtk_widget_set_mapped:
7661 * @widget: a #GtkWidget
7662 * @mapped: %TRUE to mark the widget as mapped
7664 * Marks the widget as being realized.
7666 * This function should only ever be called in a derived widget's
7667 * "map" or "unmap" implementation.
7672 gtk_widget_set_mapped (GtkWidget *widget,
7675 g_return_if_fail (GTK_IS_WIDGET (widget));
7677 widget->priv->mapped = mapped;
7681 * gtk_widget_set_app_paintable:
7682 * @widget: a #GtkWidget
7683 * @app_paintable: %TRUE if the application will paint on the widget
7685 * Sets whether the application intends to draw on the widget in
7686 * an #GtkWidget::draw handler.
7688 * This is a hint to the widget and does not affect the behavior of
7689 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7690 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7691 * the effect is to suppress default themed drawing of the widget's
7692 * background. (Children of the widget will still be drawn.) The application
7693 * is then entirely responsible for drawing the widget background.
7695 * Note that the background is still drawn when the widget is mapped.
7698 gtk_widget_set_app_paintable (GtkWidget *widget,
7699 gboolean app_paintable)
7701 g_return_if_fail (GTK_IS_WIDGET (widget));
7703 app_paintable = (app_paintable != FALSE);
7705 if (widget->priv->app_paintable != app_paintable)
7707 widget->priv->app_paintable = app_paintable;
7709 if (gtk_widget_is_drawable (widget))
7710 gtk_widget_queue_draw (widget);
7712 g_object_notify (G_OBJECT (widget), "app-paintable");
7717 * gtk_widget_get_app_paintable:
7718 * @widget: a #GtkWidget
7720 * Determines whether the application intends to draw on the widget in
7721 * an #GtkWidget::draw handler.
7723 * See gtk_widget_set_app_paintable()
7725 * Return value: %TRUE if the widget is app paintable
7730 gtk_widget_get_app_paintable (GtkWidget *widget)
7732 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7734 return widget->priv->app_paintable;
7738 * gtk_widget_set_double_buffered:
7739 * @widget: a #GtkWidget
7740 * @double_buffered: %TRUE to double-buffer a widget
7742 * Widgets are double buffered by default; you can use this function
7743 * to turn off the buffering. "Double buffered" simply means that
7744 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7745 * automatically around expose events sent to the
7746 * widget. gdk_window_begin_paint_region() diverts all drawing to a widget's
7747 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7748 * buffer to the screen. The result is that users see the window
7749 * update in one smooth step, and don't see individual graphics
7750 * primitives being rendered.
7752 * In very simple terms, double buffered widgets don't flicker,
7753 * so you would only use this function to turn off double buffering
7754 * if you had special needs and really knew what you were doing.
7756 * Note: if you turn off double-buffering, you have to handle
7757 * expose events, since even the clearing to the background color or
7758 * pixmap will not happen automatically (as it is done in
7759 * gdk_window_begin_paint_region()).
7762 gtk_widget_set_double_buffered (GtkWidget *widget,
7763 gboolean double_buffered)
7765 g_return_if_fail (GTK_IS_WIDGET (widget));
7767 double_buffered = (double_buffered != FALSE);
7769 if (widget->priv->double_buffered != double_buffered)
7771 widget->priv->double_buffered = double_buffered;
7773 g_object_notify (G_OBJECT (widget), "double-buffered");
7778 * gtk_widget_get_double_buffered:
7779 * @widget: a #GtkWidget
7781 * Determines whether the widget is double buffered.
7783 * See gtk_widget_set_double_buffered()
7785 * Return value: %TRUE if the widget is double buffered
7790 gtk_widget_get_double_buffered (GtkWidget *widget)
7792 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7794 return widget->priv->double_buffered;
7798 * gtk_widget_set_redraw_on_allocate:
7799 * @widget: a #GtkWidget
7800 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7801 * when it is allocated to a new size. Otherwise, only the
7802 * new portion of the widget will be redrawn.
7804 * Sets whether the entire widget is queued for drawing when its size
7805 * allocation changes. By default, this setting is %TRUE and
7806 * the entire widget is redrawn on every size change. If your widget
7807 * leaves the upper left unchanged when made bigger, turning this
7808 * setting off will improve performance.
7810 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7811 * off all allocation on resizing: the widget will not even redraw if
7812 * its position changes; this is to allow containers that don't draw
7813 * anything to avoid excess invalidations. If you set this flag on a
7814 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7815 * you are responsible for invalidating both the old and new allocation
7816 * of the widget when the widget is moved and responsible for invalidating
7817 * regions newly when the widget increases size.
7820 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7821 gboolean redraw_on_allocate)
7823 g_return_if_fail (GTK_IS_WIDGET (widget));
7825 widget->priv->redraw_on_alloc = redraw_on_allocate;
7829 * gtk_widget_set_sensitive:
7830 * @widget: a #GtkWidget
7831 * @sensitive: %TRUE to make the widget sensitive
7833 * Sets the sensitivity of a widget. A widget is sensitive if the user
7834 * can interact with it. Insensitive widgets are "grayed out" and the
7835 * user can't interact with them. Insensitive widgets are known as
7836 * "inactive", "disabled", or "ghosted" in some other toolkits.
7839 gtk_widget_set_sensitive (GtkWidget *widget,
7842 GtkWidgetPrivate *priv;
7844 g_return_if_fail (GTK_IS_WIDGET (widget));
7846 priv = widget->priv;
7848 sensitive = (sensitive != FALSE);
7850 if (priv->sensitive == sensitive)
7853 priv->sensitive = sensitive;
7855 if (priv->parent == NULL
7856 || gtk_widget_is_sensitive (priv->parent))
7860 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7863 data.operation = STATE_CHANGE_UNSET;
7865 data.operation = STATE_CHANGE_SET;
7867 gtk_widget_propagate_state (widget, &data);
7869 gtk_widget_queue_resize (widget);
7872 g_object_notify (G_OBJECT (widget), "sensitive");
7876 * gtk_widget_get_sensitive:
7877 * @widget: a #GtkWidget
7879 * Returns the widget's sensitivity (in the sense of returning
7880 * the value that has been set using gtk_widget_set_sensitive()).
7882 * The effective sensitivity of a widget is however determined by both its
7883 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7885 * Returns: %TRUE if the widget is sensitive
7890 gtk_widget_get_sensitive (GtkWidget *widget)
7892 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7894 return widget->priv->sensitive;
7898 * gtk_widget_is_sensitive:
7899 * @widget: a #GtkWidget
7901 * Returns the widget's effective sensitivity, which means
7902 * it is sensitive itself and also its parent widget is sensitive
7904 * Returns: %TRUE if the widget is effectively sensitive
7909 gtk_widget_is_sensitive (GtkWidget *widget)
7911 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7913 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
7917 * gtk_widget_set_parent:
7918 * @widget: a #GtkWidget
7919 * @parent: parent container
7921 * This function is useful only when implementing subclasses of
7923 * Sets the container as the parent of @widget, and takes care of
7924 * some details such as updating the state and style of the child
7925 * to reflect its new location. The opposite function is
7926 * gtk_widget_unparent().
7929 gtk_widget_set_parent (GtkWidget *widget,
7932 GtkStateFlags parent_flags;
7933 GtkWidgetPrivate *priv;
7936 g_return_if_fail (GTK_IS_WIDGET (widget));
7937 g_return_if_fail (GTK_IS_WIDGET (parent));
7938 g_return_if_fail (widget != parent);
7940 priv = widget->priv;
7942 if (priv->parent != NULL)
7944 g_warning ("Can't set a parent on widget which has a parent\n");
7947 if (gtk_widget_is_toplevel (widget))
7949 g_warning ("Can't set a parent on a toplevel widget\n");
7953 /* keep this function in sync with gtk_menu_attach_to_widget()
7956 g_object_ref_sink (widget);
7958 gtk_widget_push_verify_invariants (widget);
7960 priv->parent = parent;
7962 parent_flags = gtk_widget_get_state_flags (parent);
7964 /* Merge both old state and current parent state,
7965 * making sure to only propagate the right states */
7966 data.flags = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
7967 data.flags |= priv->state_flags;
7969 data.operation = STATE_CHANGE_REPLACE;
7970 gtk_widget_propagate_state (widget, &data);
7973 gtk_style_context_set_parent (priv->context,
7974 gtk_widget_get_style_context (parent));
7976 _gtk_widget_update_parent_muxer (widget);
7978 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7979 if (priv->parent->priv->anchored)
7980 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7981 g_object_notify (G_OBJECT (widget), "parent");
7983 /* Enforce realized/mapped invariants
7985 if (gtk_widget_get_realized (priv->parent))
7986 gtk_widget_realize (widget);
7988 if (gtk_widget_get_visible (priv->parent) &&
7989 gtk_widget_get_visible (widget))
7991 if (gtk_widget_get_child_visible (widget) &&
7992 gtk_widget_get_mapped (priv->parent))
7993 gtk_widget_map (widget);
7995 gtk_widget_queue_resize (widget);
7998 /* child may cause parent's expand to change, if the child is
7999 * expanded. If child is not expanded, then it can't modify the
8000 * parent's expand. If the child becomes expanded later then it will
8001 * queue compute_expand then. This optimization plus defaulting
8002 * newly-constructed widgets to need_compute_expand=FALSE should
8003 * mean that initially building a widget tree doesn't have to keep
8004 * walking up setting need_compute_expand on parents over and over.
8006 * We can't change a parent to need to expand unless we're visible.
8008 if (gtk_widget_get_visible (widget) &&
8009 (priv->need_compute_expand ||
8010 priv->computed_hexpand ||
8011 priv->computed_vexpand))
8013 gtk_widget_queue_compute_expand (parent);
8016 gtk_widget_pop_verify_invariants (widget);
8020 * gtk_widget_get_parent:
8021 * @widget: a #GtkWidget
8023 * Returns the parent container of @widget.
8025 * Return value: (transfer none): the parent container of @widget, or %NULL
8028 gtk_widget_get_parent (GtkWidget *widget)
8030 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8032 return widget->priv->parent;
8036 modifier_style_changed (GtkModifierStyle *style,
8039 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8042 static GtkModifierStyle *
8043 _gtk_widget_get_modifier_properties (GtkWidget *widget)
8045 GtkModifierStyle *style;
8047 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
8049 if (G_UNLIKELY (!style))
8051 GtkStyleContext *context;
8053 style = _gtk_modifier_style_new ();
8054 g_object_set_qdata_full (G_OBJECT (widget),
8055 quark_modifier_style,
8057 (GDestroyNotify) g_object_unref);
8059 g_signal_connect (style, "changed",
8060 G_CALLBACK (modifier_style_changed), widget);
8062 context = gtk_widget_get_style_context (widget);
8064 gtk_style_context_add_provider (context,
8065 GTK_STYLE_PROVIDER (style),
8066 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
8073 * gtk_widget_override_color:
8074 * @widget: a #GtkWidget
8075 * @state: the state for which to set the color
8076 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8077 * of previous calls to gtk_widget_override_color()
8079 * Sets the color to use for a widget.
8081 * All other style values are left untouched.
8084 * This API is mostly meant as a quick way for applications to
8085 * change a widget appearance. If you are developing a widgets
8086 * library and intend this change to be themeable, it is better
8087 * done by setting meaningful CSS classes and regions in your
8088 * widget/container implementation through gtk_style_context_add_class()
8089 * and gtk_style_context_add_region().
8091 * This way, your widget library can install a #GtkCssProvider
8092 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
8093 * to provide a default styling for those widgets that need so, and
8094 * this theming may fully overridden by the user's theme.
8097 * Note that for complex widgets this may bring in undesired
8098 * results (such as uniform background color everywhere), in
8099 * these cases it is better to fully style such widgets through a
8100 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8107 gtk_widget_override_color (GtkWidget *widget,
8108 GtkStateFlags state,
8109 const GdkRGBA *color)
8111 GtkModifierStyle *style;
8113 g_return_if_fail (GTK_IS_WIDGET (widget));
8115 style = _gtk_widget_get_modifier_properties (widget);
8116 _gtk_modifier_style_set_color (style, state, color);
8120 * gtk_widget_override_background_color:
8121 * @widget: a #GtkWidget
8122 * @state: the state for which to set the background color
8123 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8124 * of previous calls to gtk_widget_override_background_color()
8126 * Sets the background color to use for a widget.
8128 * All other style values are left untouched.
8129 * See gtk_widget_override_color().
8134 gtk_widget_override_background_color (GtkWidget *widget,
8135 GtkStateFlags state,
8136 const GdkRGBA *color)
8138 GtkModifierStyle *style;
8140 g_return_if_fail (GTK_IS_WIDGET (widget));
8142 style = _gtk_widget_get_modifier_properties (widget);
8143 _gtk_modifier_style_set_background_color (style, state, color);
8147 * gtk_widget_override_font:
8148 * @widget: a #GtkWidget
8149 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
8150 * the effect of previous calls to gtk_widget_override_font()
8152 * Sets the font to use for a widget. All other style values are
8153 * left untouched. See gtk_widget_override_color().
8158 gtk_widget_override_font (GtkWidget *widget,
8159 const PangoFontDescription *font_desc)
8161 GtkModifierStyle *style;
8163 g_return_if_fail (GTK_IS_WIDGET (widget));
8165 style = _gtk_widget_get_modifier_properties (widget);
8166 _gtk_modifier_style_set_font (style, font_desc);
8170 * gtk_widget_override_symbolic_color:
8171 * @widget: a #GtkWidget
8172 * @name: the name of the symbolic color to modify
8173 * @color: (allow-none): the color to assign (does not need
8174 * to be allocated), or %NULL to undo the effect of previous
8175 * calls to gtk_widget_override_symbolic_color()
8177 * Sets a symbolic color for a widget.
8179 * All other style values are left untouched.
8180 * See gtk_widget_override_color() for overriding the foreground
8181 * or background color.
8186 gtk_widget_override_symbolic_color (GtkWidget *widget,
8188 const GdkRGBA *color)
8190 GtkModifierStyle *style;
8192 g_return_if_fail (GTK_IS_WIDGET (widget));
8194 style = _gtk_widget_get_modifier_properties (widget);
8195 _gtk_modifier_style_map_color (style, name, color);
8199 * gtk_widget_override_cursor:
8200 * @widget: a #GtkWidget
8201 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8202 * allocated), or %NULL to undo the effect of previous calls to
8203 * of gtk_widget_override_cursor().
8204 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8205 * need to be allocated), or %NULL to undo the effect of previous
8206 * calls to of gtk_widget_override_cursor().
8208 * Sets the cursor color to use in a widget, overriding the
8209 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8210 * style properties. All other style values are left untouched.
8211 * See also gtk_widget_modify_style().
8213 * Note that the underlying properties have the #GdkColor type,
8214 * so the alpha value in @primary and @secondary will be ignored.
8219 gtk_widget_override_cursor (GtkWidget *widget,
8220 const GdkRGBA *cursor,
8221 const GdkRGBA *secondary_cursor)
8223 GtkModifierStyle *style;
8225 g_return_if_fail (GTK_IS_WIDGET (widget));
8227 style = _gtk_widget_get_modifier_properties (widget);
8228 _gtk_modifier_style_set_color_property (style,
8230 "cursor-color", cursor);
8231 _gtk_modifier_style_set_color_property (style,
8233 "secondary-cursor-color",
8238 gtk_widget_real_direction_changed (GtkWidget *widget,
8239 GtkTextDirection previous_direction)
8241 gtk_widget_queue_resize (widget);
8245 gtk_widget_real_style_set (GtkWidget *widget,
8246 GtkStyle *previous_style)
8251 GtkWidget *previous_toplevel;
8252 GdkScreen *previous_screen;
8253 GdkScreen *new_screen;
8254 } HierarchyChangedInfo;
8257 do_screen_change (GtkWidget *widget,
8258 GdkScreen *old_screen,
8259 GdkScreen *new_screen)
8261 if (old_screen != new_screen)
8263 GtkWidgetPrivate *priv = widget->priv;
8267 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8269 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8272 _gtk_tooltip_hide (widget);
8274 if (new_screen && priv->context)
8275 gtk_style_context_set_screen (priv->context, new_screen);
8277 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8282 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8283 gpointer client_data)
8285 GtkWidgetPrivate *priv = widget->priv;
8286 HierarchyChangedInfo *info = client_data;
8287 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8288 (priv->parent && priv->parent->priv->anchored);
8290 if (priv->anchored != new_anchored)
8292 g_object_ref (widget);
8294 priv->anchored = new_anchored;
8296 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8297 do_screen_change (widget, info->previous_screen, info->new_screen);
8299 if (GTK_IS_CONTAINER (widget))
8300 gtk_container_forall (GTK_CONTAINER (widget),
8301 gtk_widget_propagate_hierarchy_changed_recurse,
8304 g_object_unref (widget);
8309 * _gtk_widget_propagate_hierarchy_changed:
8310 * @widget: a #GtkWidget
8311 * @previous_toplevel: Previous toplevel
8313 * Propagates changes in the anchored state to a widget and all
8314 * children, unsetting or setting the %ANCHORED flag, and
8315 * emitting #GtkWidget::hierarchy-changed.
8318 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8319 GtkWidget *previous_toplevel)
8321 GtkWidgetPrivate *priv = widget->priv;
8322 HierarchyChangedInfo info;
8324 info.previous_toplevel = previous_toplevel;
8325 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8327 if (gtk_widget_is_toplevel (widget) ||
8328 (priv->parent && priv->parent->priv->anchored))
8329 info.new_screen = gtk_widget_get_screen (widget);
8331 info.new_screen = NULL;
8333 if (info.previous_screen)
8334 g_object_ref (info.previous_screen);
8335 if (previous_toplevel)
8336 g_object_ref (previous_toplevel);
8338 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8340 if (previous_toplevel)
8341 g_object_unref (previous_toplevel);
8342 if (info.previous_screen)
8343 g_object_unref (info.previous_screen);
8347 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8348 gpointer client_data)
8350 HierarchyChangedInfo *info = client_data;
8352 g_object_ref (widget);
8354 do_screen_change (widget, info->previous_screen, info->new_screen);
8356 if (GTK_IS_CONTAINER (widget))
8357 gtk_container_forall (GTK_CONTAINER (widget),
8358 gtk_widget_propagate_screen_changed_recurse,
8361 g_object_unref (widget);
8365 * gtk_widget_is_composited:
8366 * @widget: a #GtkWidget
8368 * Whether @widget can rely on having its alpha channel
8369 * drawn correctly. On X11 this function returns whether a
8370 * compositing manager is running for @widget's screen.
8372 * Please note that the semantics of this call will change
8373 * in the future if used on a widget that has a composited
8374 * window in its hierarchy (as set by gdk_window_set_composited()).
8376 * Return value: %TRUE if the widget can rely on its alpha
8377 * channel being drawn correctly.
8382 gtk_widget_is_composited (GtkWidget *widget)
8386 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8388 screen = gtk_widget_get_screen (widget);
8390 return gdk_screen_is_composited (screen);
8394 propagate_composited_changed (GtkWidget *widget,
8397 if (GTK_IS_CONTAINER (widget))
8399 gtk_container_forall (GTK_CONTAINER (widget),
8400 propagate_composited_changed,
8404 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8408 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8410 propagate_composited_changed (widget, NULL);
8414 * _gtk_widget_propagate_screen_changed:
8415 * @widget: a #GtkWidget
8416 * @previous_screen: Previous screen
8418 * Propagates changes in the screen for a widget to all
8419 * children, emitting #GtkWidget::screen-changed.
8422 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8423 GdkScreen *previous_screen)
8425 HierarchyChangedInfo info;
8427 info.previous_screen = previous_screen;
8428 info.new_screen = gtk_widget_get_screen (widget);
8430 if (previous_screen)
8431 g_object_ref (previous_screen);
8433 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8435 if (previous_screen)
8436 g_object_unref (previous_screen);
8440 reset_style_recurse (GtkWidget *widget, gpointer data)
8442 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8444 if (GTK_IS_CONTAINER (widget))
8445 gtk_container_forall (GTK_CONTAINER (widget),
8446 reset_style_recurse,
8451 * gtk_widget_reset_style:
8452 * @widget: a #GtkWidget
8454 * Updates the style context of @widget and all descendents
8455 * by updating its widget path. #GtkContainer<!-- -->s may want
8456 * to use this on a child when reordering it in a way that a different
8457 * style might apply to it. See also gtk_container_get_path_for_child().
8462 gtk_widget_reset_style (GtkWidget *widget)
8464 g_return_if_fail (GTK_IS_WIDGET (widget));
8466 reset_style_recurse (widget, NULL);
8468 g_list_foreach (widget->priv->attached_windows,
8469 (GFunc) reset_style_recurse, NULL);
8472 #ifdef G_ENABLE_DEBUG
8474 /* Verify invariants, see docs/widget_system.txt for notes on much of
8475 * this. Invariants may be temporarily broken while we're in the
8476 * process of updating state, of course, so you can only
8477 * verify_invariants() after a given operation is complete.
8478 * Use push/pop_verify_invariants to help with that.
8481 gtk_widget_verify_invariants (GtkWidget *widget)
8485 if (widget->priv->verifying_invariants_count > 0)
8488 parent = widget->priv->parent;
8490 if (widget->priv->mapped)
8492 /* Mapped implies ... */
8494 if (!widget->priv->realized)
8495 g_warning ("%s %p is mapped but not realized",
8496 G_OBJECT_TYPE_NAME (widget), widget);
8498 if (!widget->priv->visible)
8499 g_warning ("%s %p is mapped but not visible",
8500 G_OBJECT_TYPE_NAME (widget), widget);
8502 if (!widget->priv->toplevel)
8504 if (!widget->priv->child_visible)
8505 g_warning ("%s %p is mapped but not child_visible",
8506 G_OBJECT_TYPE_NAME (widget), widget);
8511 /* Not mapped implies... */
8514 /* This check makes sense for normal toplevels, but for
8515 * something like a toplevel that is embedded within a clutter
8516 * state, mapping may depend on external factors.
8518 if (widget->priv->toplevel)
8520 if (widget->priv->visible)
8521 g_warning ("%s %p toplevel is visible but not mapped",
8522 G_OBJECT_TYPE_NAME (widget), widget);
8527 /* Parent related checks aren't possible if parent has
8528 * verifying_invariants_count > 0 because parent needs to recurse
8529 * children first before the invariants will hold.
8531 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8534 parent->priv->realized)
8536 /* Parent realized implies... */
8539 /* This is in widget_system.txt but appears to fail
8540 * because there's no gtk_container_realize() that
8541 * realizes all children... instead we just lazily
8542 * wait for map to fix things up.
8544 if (!widget->priv->realized)
8545 g_warning ("%s %p is realized but child %s %p is not realized",
8546 G_OBJECT_TYPE_NAME (parent), parent,
8547 G_OBJECT_TYPE_NAME (widget), widget);
8550 else if (!widget->priv->toplevel)
8552 /* No parent or parent not realized on non-toplevel implies... */
8554 if (widget->priv->realized && !widget->priv->in_reparent)
8555 g_warning ("%s %p is not realized but child %s %p is realized",
8556 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8557 G_OBJECT_TYPE_NAME (widget), widget);
8561 parent->priv->mapped &&
8562 widget->priv->visible &&
8563 widget->priv->child_visible)
8565 /* Parent mapped and we are visible implies... */
8567 if (!widget->priv->mapped)
8568 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8569 G_OBJECT_TYPE_NAME (parent), parent,
8570 G_OBJECT_TYPE_NAME (widget), widget);
8572 else if (!widget->priv->toplevel)
8574 /* No parent or parent not mapped on non-toplevel implies... */
8576 if (widget->priv->mapped && !widget->priv->in_reparent)
8577 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8578 G_OBJECT_TYPE_NAME (widget), widget,
8579 widget->priv->visible,
8580 widget->priv->child_visible,
8581 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8582 parent ? parent->priv->mapped : FALSE);
8586 if (!widget->priv->realized)
8588 /* Not realized implies... */
8591 /* widget_system.txt says these hold, but they don't. */
8592 if (widget->priv->alloc_needed)
8593 g_warning ("%s %p alloc needed but not realized",
8594 G_OBJECT_TYPE_NAME (widget), widget);
8596 if (widget->priv->width_request_needed)
8597 g_warning ("%s %p width request needed but not realized",
8598 G_OBJECT_TYPE_NAME (widget), widget);
8600 if (widget->priv->height_request_needed)
8601 g_warning ("%s %p height request needed but not realized",
8602 G_OBJECT_TYPE_NAME (widget), widget);
8607 /* The point of this push/pop is that invariants may not hold while
8608 * we're busy making changes. So we only check at the outermost call
8609 * on the call stack, after we finish updating everything.
8612 gtk_widget_push_verify_invariants (GtkWidget *widget)
8614 widget->priv->verifying_invariants_count += 1;
8618 gtk_widget_verify_child_invariants (GtkWidget *widget,
8619 gpointer client_data)
8621 /* We don't recurse further; this is a one-level check. */
8622 gtk_widget_verify_invariants (widget);
8626 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8628 g_assert (widget->priv->verifying_invariants_count > 0);
8630 widget->priv->verifying_invariants_count -= 1;
8632 if (widget->priv->verifying_invariants_count == 0)
8634 gtk_widget_verify_invariants (widget);
8636 if (GTK_IS_CONTAINER (widget))
8638 /* Check one level of children, because our
8639 * push_verify_invariants() will have prevented some of the
8640 * checks. This does not recurse because if recursion is
8641 * needed, it will happen naturally as each child has a
8642 * push/pop on that child. For example if we're recursively
8643 * mapping children, we'll push/pop on each child as we map
8646 gtk_container_forall (GTK_CONTAINER (widget),
8647 gtk_widget_verify_child_invariants,
8652 #endif /* G_ENABLE_DEBUG */
8654 static PangoContext *
8655 gtk_widget_peek_pango_context (GtkWidget *widget)
8657 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8661 * gtk_widget_get_pango_context:
8662 * @widget: a #GtkWidget
8664 * Gets a #PangoContext with the appropriate font map, font description,
8665 * and base direction for this widget. Unlike the context returned
8666 * by gtk_widget_create_pango_context(), this context is owned by
8667 * the widget (it can be used until the screen for the widget changes
8668 * or the widget is removed from its toplevel), and will be updated to
8669 * match any changes to the widget's attributes.
8671 * If you create and keep a #PangoLayout using this context, you must
8672 * deal with changes to the context by calling pango_layout_context_changed()
8673 * on the layout in response to the #GtkWidget::style-updated and
8674 * #GtkWidget::direction-changed signals for the widget.
8676 * Return value: (transfer none): the #PangoContext for the widget.
8679 gtk_widget_get_pango_context (GtkWidget *widget)
8681 PangoContext *context;
8683 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8685 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8688 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8689 g_object_set_qdata_full (G_OBJECT (widget),
8690 quark_pango_context,
8699 update_pango_context (GtkWidget *widget,
8700 PangoContext *context)
8702 const PangoFontDescription *font_desc;
8703 GtkStyleContext *style_context;
8705 style_context = gtk_widget_get_style_context (widget);
8707 font_desc = gtk_style_context_get_font (style_context,
8708 gtk_widget_get_state_flags (widget));
8710 pango_context_set_font_description (context, font_desc);
8711 pango_context_set_base_dir (context,
8712 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8713 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8717 gtk_widget_update_pango_context (GtkWidget *widget)
8719 PangoContext *context = gtk_widget_peek_pango_context (widget);
8725 update_pango_context (widget, context);
8727 screen = gtk_widget_get_screen_unchecked (widget);
8730 pango_cairo_context_set_resolution (context,
8731 gdk_screen_get_resolution (screen));
8732 pango_cairo_context_set_font_options (context,
8733 gdk_screen_get_font_options (screen));
8739 * gtk_widget_create_pango_context:
8740 * @widget: a #GtkWidget
8742 * Creates a new #PangoContext with the appropriate font map,
8743 * font description, and base direction for drawing text for
8744 * this widget. See also gtk_widget_get_pango_context().
8746 * Return value: (transfer full): the new #PangoContext
8749 gtk_widget_create_pango_context (GtkWidget *widget)
8752 PangoContext *context;
8754 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8756 screen = gtk_widget_get_screen_unchecked (widget);
8759 GTK_NOTE (MULTIHEAD,
8760 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8762 screen = gdk_screen_get_default ();
8765 context = gdk_pango_context_get_for_screen (screen);
8767 update_pango_context (widget, context);
8768 pango_context_set_language (context, gtk_get_default_language ());
8774 * gtk_widget_create_pango_layout:
8775 * @widget: a #GtkWidget
8776 * @text: text to set on the layout (can be %NULL)
8778 * Creates a new #PangoLayout with the appropriate font map,
8779 * font description, and base direction for drawing text for
8782 * If you keep a #PangoLayout created in this way around, in order to
8783 * notify the layout of changes to the base direction or font of this
8784 * widget, you must call pango_layout_context_changed() in response to
8785 * the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
8788 * Return value: (transfer full): the new #PangoLayout
8791 gtk_widget_create_pango_layout (GtkWidget *widget,
8794 PangoLayout *layout;
8795 PangoContext *context;
8797 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8799 context = gtk_widget_get_pango_context (widget);
8800 layout = pango_layout_new (context);
8803 pango_layout_set_text (layout, text, -1);
8809 * gtk_widget_render_icon_pixbuf:
8810 * @widget: a #GtkWidget
8811 * @stock_id: a stock ID
8812 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8813 * render at the size of the source and don't scale (if there are
8814 * multiple source sizes, GTK+ picks one of the available sizes).
8816 * A convenience function that uses the theme engine and style
8817 * settings for @widget to look up @stock_id and render it to
8818 * a pixbuf. @stock_id should be a stock icon ID such as
8819 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8820 * such as #GTK_ICON_SIZE_MENU.
8822 * The pixels in the returned #GdkPixbuf are shared with the rest of
8823 * the application and should not be modified. The pixbuf should be freed
8824 * after use with g_object_unref().
8826 * Return value: (transfer full): a new pixbuf, or %NULL if the
8827 * stock ID wasn't known
8832 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
8833 const gchar *stock_id,
8836 GtkStyleContext *context;
8837 GtkIconSet *icon_set;
8839 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8840 g_return_val_if_fail (stock_id != NULL, NULL);
8841 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8843 context = gtk_widget_get_style_context (widget);
8844 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
8846 if (icon_set == NULL)
8849 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
8853 * gtk_widget_set_parent_window:
8854 * @widget: a #GtkWidget.
8855 * @parent_window: the new parent window.
8857 * Sets a non default parent window for @widget.
8859 * For GtkWindow classes, setting a @parent_window effects whether
8860 * the window is a toplevel window or can be embedded into other
8864 * For GtkWindow classes, this needs to be called before the
8865 * window is realized.
8870 gtk_widget_set_parent_window (GtkWidget *widget,
8871 GdkWindow *parent_window)
8873 GdkWindow *old_parent_window;
8875 g_return_if_fail (GTK_IS_WIDGET (widget));
8877 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8878 quark_parent_window);
8880 if (parent_window != old_parent_window)
8884 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8886 if (old_parent_window)
8887 g_object_unref (old_parent_window);
8889 g_object_ref (parent_window);
8891 /* Unset toplevel flag when adding a parent window to a widget,
8892 * this is the primary entry point to allow toplevels to be
8895 #ifdef GDK_WINDOWING_X11
8896 is_plug = GTK_IS_PLUG (widget);
8900 if (GTK_IS_WINDOW (widget) && !is_plug)
8901 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
8906 * gtk_widget_get_parent_window:
8907 * @widget: a #GtkWidget.
8909 * Gets @widget's parent window.
8911 * Returns: (transfer none): the parent window of @widget.
8914 gtk_widget_get_parent_window (GtkWidget *widget)
8916 GtkWidgetPrivate *priv;
8917 GdkWindow *parent_window;
8919 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8921 priv = widget->priv;
8923 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8925 return (parent_window != NULL) ? parent_window :
8926 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8931 * gtk_widget_set_child_visible:
8932 * @widget: a #GtkWidget
8933 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8935 * Sets whether @widget should be mapped along with its when its parent
8936 * is mapped and @widget has been shown with gtk_widget_show().
8938 * The child visibility can be set for widget before it is added to
8939 * a container with gtk_widget_set_parent(), to avoid mapping
8940 * children unnecessary before immediately unmapping them. However
8941 * it will be reset to its default state of %TRUE when the widget
8942 * is removed from a container.
8944 * Note that changing the child visibility of a widget does not
8945 * queue a resize on the widget. Most of the time, the size of
8946 * a widget is computed from all visible children, whether or
8947 * not they are mapped. If this is not the case, the container
8948 * can queue a resize itself.
8950 * This function is only useful for container implementations and
8951 * never should be called by an application.
8954 gtk_widget_set_child_visible (GtkWidget *widget,
8955 gboolean is_visible)
8957 GtkWidgetPrivate *priv;
8959 g_return_if_fail (GTK_IS_WIDGET (widget));
8960 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8962 priv = widget->priv;
8964 g_object_ref (widget);
8965 gtk_widget_verify_invariants (widget);
8968 priv->child_visible = TRUE;
8971 GtkWidget *toplevel;
8973 priv->child_visible = FALSE;
8975 toplevel = gtk_widget_get_toplevel (widget);
8976 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8977 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8980 if (priv->parent && gtk_widget_get_realized (priv->parent))
8982 if (gtk_widget_get_mapped (priv->parent) &&
8983 priv->child_visible &&
8984 gtk_widget_get_visible (widget))
8985 gtk_widget_map (widget);
8987 gtk_widget_unmap (widget);
8990 gtk_widget_verify_invariants (widget);
8991 g_object_unref (widget);
8995 * gtk_widget_get_child_visible:
8996 * @widget: a #GtkWidget
8998 * Gets the value set with gtk_widget_set_child_visible().
8999 * If you feel a need to use this function, your code probably
9000 * needs reorganization.
9002 * This function is only useful for container implementations and
9003 * never should be called by an application.
9005 * Return value: %TRUE if the widget is mapped with the parent.
9008 gtk_widget_get_child_visible (GtkWidget *widget)
9010 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9012 return widget->priv->child_visible;
9016 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9018 GtkWidget *toplevel;
9020 toplevel = gtk_widget_get_toplevel (widget);
9022 if (gtk_widget_is_toplevel (toplevel))
9024 if (GTK_IS_WINDOW (toplevel))
9025 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9026 else if (GTK_IS_INVISIBLE (toplevel))
9027 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9034 * gtk_widget_get_screen:
9035 * @widget: a #GtkWidget
9037 * Get the #GdkScreen from the toplevel window associated with
9038 * this widget. This function can only be called after the widget
9039 * has been added to a widget hierarchy with a #GtkWindow
9042 * In general, you should only create screen specific
9043 * resources when a widget has been realized, and you should
9044 * free those resources when the widget is unrealized.
9046 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9051 gtk_widget_get_screen (GtkWidget *widget)
9055 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9057 screen = gtk_widget_get_screen_unchecked (widget);
9064 g_warning (G_STRLOC ": Can't get associated screen"
9065 " for a widget unless it is inside a toplevel GtkWindow\n"
9066 " widget type is %s associated top level type is %s",
9067 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9068 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9070 return gdk_screen_get_default ();
9075 * gtk_widget_has_screen:
9076 * @widget: a #GtkWidget
9078 * Checks whether there is a #GdkScreen is associated with
9079 * this widget. All toplevel widgets have an associated
9080 * screen, and all widgets added into a hierarchy with a toplevel
9081 * window at the top.
9083 * Return value: %TRUE if there is a #GdkScreen associcated
9089 gtk_widget_has_screen (GtkWidget *widget)
9091 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9093 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9097 * gtk_widget_get_display:
9098 * @widget: a #GtkWidget
9100 * Get the #GdkDisplay for the toplevel window associated with
9101 * this widget. This function can only be called after the widget
9102 * has been added to a widget hierarchy with a #GtkWindow at the top.
9104 * In general, you should only create display specific
9105 * resources when a widget has been realized, and you should
9106 * free those resources when the widget is unrealized.
9108 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9113 gtk_widget_get_display (GtkWidget *widget)
9115 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9117 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9121 * gtk_widget_get_root_window:
9122 * @widget: a #GtkWidget
9124 * Get the root window where this widget is located. This function can
9125 * only be called after the widget has been added to a widget
9126 * hierarchy with #GtkWindow at the top.
9128 * The root window is useful for such purposes as creating a popup
9129 * #GdkWindow associated with the window. In general, you should only
9130 * create display specific resources when a widget has been realized,
9131 * and you should free those resources when the widget is unrealized.
9133 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9138 gtk_widget_get_root_window (GtkWidget *widget)
9140 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9142 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9146 * gtk_widget_child_focus:
9147 * @widget: a #GtkWidget
9148 * @direction: direction of focus movement
9150 * This function is used by custom widget implementations; if you're
9151 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9152 * to a particular widget, and gtk_container_set_focus_chain() to
9153 * change the focus tab order. So you may want to investigate those
9154 * functions instead.
9156 * gtk_widget_child_focus() is called by containers as the user moves
9157 * around the window using keyboard shortcuts. @direction indicates
9158 * what kind of motion is taking place (up, down, left, right, tab
9159 * forward, tab backward). gtk_widget_child_focus() emits the
9160 * #GtkWidget::focus signal; widgets override the default handler
9161 * for this signal in order to implement appropriate focus behavior.
9163 * The default ::focus handler for a widget should return %TRUE if
9164 * moving in @direction left the focus on a focusable location inside
9165 * that widget, and %FALSE if moving in @direction moved the focus
9166 * outside the widget. If returning %TRUE, widgets normally
9167 * call gtk_widget_grab_focus() to place the focus accordingly;
9168 * if returning %FALSE, they don't modify the current focus location.
9170 * Return value: %TRUE if focus ended up inside @widget
9173 gtk_widget_child_focus (GtkWidget *widget,
9174 GtkDirectionType direction)
9176 gboolean return_val;
9178 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9180 if (!gtk_widget_get_visible (widget) ||
9181 !gtk_widget_is_sensitive (widget))
9184 /* child widgets must set CAN_FOCUS, containers
9185 * don't have to though.
9187 if (!GTK_IS_CONTAINER (widget) &&
9188 !gtk_widget_get_can_focus (widget))
9191 g_signal_emit (widget,
9192 widget_signals[FOCUS],
9194 direction, &return_val);
9200 * gtk_widget_keynav_failed:
9201 * @widget: a #GtkWidget
9202 * @direction: direction of focus movement
9204 * This function should be called whenever keyboard navigation within
9205 * a single widget hits a boundary. The function emits the
9206 * #GtkWidget::keynav-failed signal on the widget and its return
9207 * value should be interpreted in a way similar to the return value of
9208 * gtk_widget_child_focus():
9210 * When %TRUE is returned, stay in the widget, the failed keyboard
9211 * navigation is Ok and/or there is nowhere we can/should move the
9214 * When %FALSE is returned, the caller should continue with keyboard
9215 * navigation outside the widget, e.g. by calling
9216 * gtk_widget_child_focus() on the widget's toplevel.
9218 * The default ::keynav-failed handler returns %TRUE for
9219 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9220 * values of #GtkDirectionType, it looks at the
9221 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9222 * if the setting is %TRUE. This way the entire user interface
9223 * becomes cursor-navigatable on input devices such as mobile phones
9224 * which only have cursor keys but no tab key.
9226 * Whenever the default handler returns %TRUE, it also calls
9227 * gtk_widget_error_bell() to notify the user of the failed keyboard
9230 * A use case for providing an own implementation of ::keynav-failed
9231 * (either by connecting to it or by overriding it) would be a row of
9232 * #GtkEntry widgets where the user should be able to navigate the
9233 * entire row with the cursor keys, as e.g. known from user interfaces
9234 * that require entering license keys.
9236 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9237 * if the emitting widget should try to handle the keyboard
9238 * navigation attempt in its parent container(s).
9243 gtk_widget_keynav_failed (GtkWidget *widget,
9244 GtkDirectionType direction)
9246 gboolean return_val;
9248 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9250 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9251 direction, &return_val);
9257 * gtk_widget_error_bell:
9258 * @widget: a #GtkWidget
9260 * Notifies the user about an input-related error on this widget.
9261 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9262 * gdk_window_beep(), otherwise it does nothing.
9264 * Note that the effect of gdk_window_beep() can be configured in many
9265 * ways, depending on the windowing backend and the desktop environment
9266 * or window manager that is used.
9271 gtk_widget_error_bell (GtkWidget *widget)
9273 GtkWidgetPrivate *priv;
9274 GtkSettings* settings;
9277 g_return_if_fail (GTK_IS_WIDGET (widget));
9279 priv = widget->priv;
9281 settings = gtk_widget_get_settings (widget);
9285 g_object_get (settings,
9286 "gtk-error-bell", &beep,
9289 if (beep && priv->window)
9290 gdk_window_beep (priv->window);
9294 gtk_widget_set_usize_internal (GtkWidget *widget,
9297 GtkQueueResizeFlags flags)
9299 GtkWidgetAuxInfo *aux_info;
9300 gboolean changed = FALSE;
9302 g_object_freeze_notify (G_OBJECT (widget));
9304 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9306 if (width > -2 && aux_info->width != width)
9308 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9309 g_object_notify (G_OBJECT (widget), "width-request");
9310 aux_info->width = width;
9313 if (height > -2 && aux_info->height != height)
9315 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9316 g_object_notify (G_OBJECT (widget), "height-request");
9317 aux_info->height = height;
9321 if (gtk_widget_get_visible (widget) && changed)
9323 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9324 gtk_widget_queue_resize (widget);
9326 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9329 g_object_thaw_notify (G_OBJECT (widget));
9333 * gtk_widget_set_size_request:
9334 * @widget: a #GtkWidget
9335 * @width: width @widget should request, or -1 to unset
9336 * @height: height @widget should request, or -1 to unset
9338 * Sets the minimum size of a widget; that is, the widget's size
9339 * request will be @width by @height. You can use this function to
9340 * force a widget to be either larger or smaller than it normally
9343 * In most cases, gtk_window_set_default_size() is a better choice for
9344 * toplevel windows than this function; setting the default size will
9345 * still allow users to shrink the window. Setting the size request
9346 * will force them to leave the window at least as large as the size
9347 * request. When dealing with window sizes,
9348 * gtk_window_set_geometry_hints() can be a useful function as well.
9350 * Note the inherent danger of setting any fixed size - themes,
9351 * translations into other languages, different fonts, and user action
9352 * can all change the appropriate size for a given widget. So, it's
9353 * basically impossible to hardcode a size that will always be
9356 * The size request of a widget is the smallest size a widget can
9357 * accept while still functioning well and drawing itself correctly.
9358 * However in some strange cases a widget may be allocated less than
9359 * its requested size, and in many cases a widget may be allocated more
9360 * space than it requested.
9362 * If the size request in a given direction is -1 (unset), then
9363 * the "natural" size request of the widget will be used instead.
9365 * Widgets can't actually be allocated a size less than 1 by 1, but
9366 * you can pass 0,0 to this function to mean "as small as possible."
9368 * The size request set here does not include any margin from the
9369 * #GtkWidget properties margin-left, margin-right, margin-top, and
9370 * margin-bottom, but it does include pretty much all other padding
9371 * or border properties set by any subclass of #GtkWidget.
9374 gtk_widget_set_size_request (GtkWidget *widget,
9378 g_return_if_fail (GTK_IS_WIDGET (widget));
9379 g_return_if_fail (width >= -1);
9380 g_return_if_fail (height >= -1);
9387 gtk_widget_set_usize_internal (widget, width, height, 0);
9392 * gtk_widget_get_size_request:
9393 * @widget: a #GtkWidget
9394 * @width: (out) (allow-none): return location for width, or %NULL
9395 * @height: (out) (allow-none): return location for height, or %NULL
9397 * Gets the size request that was explicitly set for the widget using
9398 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9399 * @height indicates that that dimension has not been set explicitly
9400 * and the natural requisition of the widget will be used intead. See
9401 * gtk_widget_set_size_request(). To get the size a widget will
9402 * actually request, call gtk_widget_get_preferred_size() instead of
9406 gtk_widget_get_size_request (GtkWidget *widget,
9410 const GtkWidgetAuxInfo *aux_info;
9412 g_return_if_fail (GTK_IS_WIDGET (widget));
9414 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9417 *width = aux_info->width;
9420 *height = aux_info->height;
9424 * _gtk_widget_override_size_request:
9425 * @widget: a #GtkWidget
9426 * @width: new forced minimum width
9427 * @height: new forced minimum height
9428 * @old_width: location to store previous forced minimum width
9429 * @old_height: location to store previous forced minumum height
9431 * Temporarily establishes a forced minimum size for a widget; this
9432 * is used by GtkWindow when calculating the size to add to the
9433 * window's geometry widget. Cached sizes for the widget and its
9434 * parents are invalidated, so that subsequent calls to the size
9435 * negotiation machinery produce the overriden result, but the
9436 * widget is not queued for relayout or redraw. The old size must
9437 * be restored with _gtk_widget_restore_size_request() or things
9441 _gtk_widget_override_size_request (GtkWidget *widget,
9447 gtk_widget_get_size_request (widget, old_width, old_height);
9448 gtk_widget_set_usize_internal (widget, width, height,
9449 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9453 * _gtk_widget_restore_size_request:
9454 * @widget: a #GtkWidget
9455 * @old_width: saved forced minimum size
9456 * @old_height: saved forced minimum size
9458 * Undoes the operation of_gtk_widget_override_size_request().
9461 _gtk_widget_restore_size_request (GtkWidget *widget,
9465 gtk_widget_set_usize_internal (widget, old_width, old_height,
9466 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9470 * gtk_widget_set_events:
9471 * @widget: a #GtkWidget
9472 * @events: event mask
9474 * Sets the event mask (see #GdkEventMask) for a widget. The event
9475 * mask determines which events a widget will receive. Keep in mind
9476 * that different widgets have different default event masks, and by
9477 * changing the event mask you may disrupt a widget's functionality,
9478 * so be careful. This function must be called while a widget is
9479 * unrealized. Consider gtk_widget_add_events() for widgets that are
9480 * already realized, or if you want to preserve the existing event
9481 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9482 * to get events on those widgets, place them inside a #GtkEventBox
9483 * and receive events on the event box.
9486 gtk_widget_set_events (GtkWidget *widget,
9489 g_return_if_fail (GTK_IS_WIDGET (widget));
9490 g_return_if_fail (!gtk_widget_get_realized (widget));
9492 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9493 GINT_TO_POINTER (events));
9494 g_object_notify (G_OBJECT (widget), "events");
9498 * gtk_widget_set_device_events:
9499 * @widget: a #GtkWidget
9500 * @device: a #GdkDevice
9501 * @events: event mask
9503 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9504 * mask determines which events a widget will receive from @device. Keep
9505 * in mind that different widgets have different default event masks, and by
9506 * changing the event mask you may disrupt a widget's functionality,
9507 * so be careful. This function must be called while a widget is
9508 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9509 * already realized, or if you want to preserve the existing event
9510 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9511 * to get events on those widgets, place them inside a #GtkEventBox
9512 * and receive events on the event box.
9517 gtk_widget_set_device_events (GtkWidget *widget,
9519 GdkEventMask events)
9521 GHashTable *device_events;
9523 g_return_if_fail (GTK_IS_WIDGET (widget));
9524 g_return_if_fail (GDK_IS_DEVICE (device));
9525 g_return_if_fail (!gtk_widget_get_realized (widget));
9527 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9529 if (G_UNLIKELY (!device_events))
9531 device_events = g_hash_table_new (NULL, NULL);
9532 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9533 (GDestroyNotify) g_hash_table_unref);
9536 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9540 * gtk_widget_set_device_enabled:
9541 * @widget: a #GtkWidget
9542 * @device: a #GdkDevice
9543 * @enabled: whether to enable the device
9545 * Enables or disables a #GdkDevice to interact with @widget
9546 * and all its children.
9548 * It does so by descending through the #GdkWindow hierarchy
9549 * and enabling the same mask that is has for core events
9550 * (i.e. the one that gdk_window_get_events() returns).
9555 gtk_widget_set_device_enabled (GtkWidget *widget,
9559 GList *enabled_devices;
9561 g_return_if_fail (GTK_IS_WIDGET (widget));
9562 g_return_if_fail (GDK_IS_DEVICE (device));
9564 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9565 enabled_devices = g_list_append (enabled_devices, device);
9567 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9568 enabled_devices, (GDestroyNotify) g_list_free);;
9570 if (gtk_widget_get_realized (widget))
9571 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9575 * gtk_widget_get_device_enabled:
9576 * @widget: a #GtkWidget
9577 * @device: a #GdkDevice
9579 * Returns whether @device can interact with @widget and its
9580 * children. See gtk_widget_set_device_enabled().
9582 * Return value: %TRUE is @device is enabled for @widget
9587 gtk_widget_get_device_enabled (GtkWidget *widget,
9590 GList *enabled_devices;
9592 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9593 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9595 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9597 return g_list_find (enabled_devices, device) != NULL;
9601 gtk_widget_add_events_internal_list (GtkWidget *widget,
9608 for (l = window_list; l != NULL; l = l->next)
9610 GdkWindow *window = l->data;
9613 gdk_window_get_user_data (window, &user_data);
9614 if (user_data == widget)
9619 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9621 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9623 children = gdk_window_get_children (window);
9624 gtk_widget_add_events_internal_list (widget, device, events, children);
9625 g_list_free (children);
9631 gtk_widget_add_events_internal (GtkWidget *widget,
9635 GtkWidgetPrivate *priv = widget->priv;
9638 if (!gtk_widget_get_has_window (widget))
9639 window_list = gdk_window_get_children (priv->window);
9641 window_list = g_list_prepend (NULL, priv->window);
9643 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9645 g_list_free (window_list);
9649 * gtk_widget_add_events:
9650 * @widget: a #GtkWidget
9651 * @events: an event mask, see #GdkEventMask
9653 * Adds the events in the bitfield @events to the event mask for
9654 * @widget. See gtk_widget_set_events() for details.
9657 gtk_widget_add_events (GtkWidget *widget,
9662 g_return_if_fail (GTK_IS_WIDGET (widget));
9664 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9665 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9666 GINT_TO_POINTER (old_events | events));
9668 if (gtk_widget_get_realized (widget))
9670 gtk_widget_add_events_internal (widget, NULL, events);
9671 gtk_widget_update_devices_mask (widget, FALSE);
9674 g_object_notify (G_OBJECT (widget), "events");
9678 * gtk_widget_add_device_events:
9679 * @widget: a #GtkWidget
9680 * @device: a #GdkDevice
9681 * @events: an event mask, see #GdkEventMask
9683 * Adds the device events in the bitfield @events to the event mask for
9684 * @widget. See gtk_widget_set_device_events() for details.
9689 gtk_widget_add_device_events (GtkWidget *widget,
9691 GdkEventMask events)
9693 GdkEventMask old_events;
9694 GHashTable *device_events;
9696 g_return_if_fail (GTK_IS_WIDGET (widget));
9697 g_return_if_fail (GDK_IS_DEVICE (device));
9699 old_events = gtk_widget_get_device_events (widget, device);
9701 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9703 if (G_UNLIKELY (!device_events))
9705 device_events = g_hash_table_new (NULL, NULL);
9706 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9707 (GDestroyNotify) g_hash_table_unref);
9710 g_hash_table_insert (device_events, device,
9711 GUINT_TO_POINTER (old_events | events));
9713 if (gtk_widget_get_realized (widget))
9714 gtk_widget_add_events_internal (widget, device, events);
9716 g_object_notify (G_OBJECT (widget), "events");
9720 * gtk_widget_get_toplevel:
9721 * @widget: a #GtkWidget
9723 * This function returns the topmost widget in the container hierarchy
9724 * @widget is a part of. If @widget has no parent widgets, it will be
9725 * returned as the topmost widget. No reference will be added to the
9726 * returned widget; it should not be unreferenced.
9728 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9729 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9731 * %NULL if @widget wasn't inside a toplevel window, and if the
9732 * window was inside a #GtkWindow<!-- -->-derived widget which was in turn
9733 * inside the toplevel #GtkWindow. While the second case may
9734 * seem unlikely, it actually happens when a #GtkPlug is embedded
9735 * inside a #GtkSocket within the same application.
9737 * To reliably find the toplevel #GtkWindow, use
9738 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9739 * is set on the result.
9741 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9742 * if (gtk_widget_is_toplevel (toplevel))
9744 * /* Perform action on toplevel. */
9748 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9749 * if there's no ancestor.
9752 gtk_widget_get_toplevel (GtkWidget *widget)
9754 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9756 while (widget->priv->parent)
9757 widget = widget->priv->parent;
9763 * gtk_widget_get_ancestor:
9764 * @widget: a #GtkWidget
9765 * @widget_type: ancestor type
9767 * Gets the first ancestor of @widget with type @widget_type. For example,
9768 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9769 * the first #GtkBox that's an ancestor of @widget. No reference will be
9770 * added to the returned widget; it should not be unreferenced. See note
9771 * about checking for a toplevel #GtkWindow in the docs for
9772 * gtk_widget_get_toplevel().
9774 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9775 * considers @widget to be an ancestor of itself.
9777 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9780 gtk_widget_get_ancestor (GtkWidget *widget,
9783 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9785 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9786 widget = widget->priv->parent;
9788 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9795 * gtk_widget_set_visual:
9796 * @widget: a #GtkWidget
9797 * @visual: visual to be used or %NULL to unset a previous one
9799 * Sets the visual that should be used for by widget and its children for
9800 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9801 * returned by gtk_widget_get_screen(), so handling the
9802 * #GtkWidget::screen-changed signal is necessary.
9804 * Setting a new @visual will not cause @widget to recreate its windows,
9805 * so you should call this function before @widget is realized.
9808 gtk_widget_set_visual (GtkWidget *widget,
9811 g_return_if_fail (GTK_IS_WIDGET (widget));
9812 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9815 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9818 g_object_set_qdata_full (G_OBJECT (widget),
9820 g_object_ref (visual),
9825 * gtk_widget_get_visual:
9826 * @widget: a #GtkWidget
9828 * Gets the visual that will be used to render @widget.
9830 * Return value: (transfer none): the visual for @widget
9833 gtk_widget_get_visual (GtkWidget *widget)
9839 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9841 if (gtk_widget_get_has_window (widget) &&
9842 widget->priv->window)
9843 return gdk_window_get_visual (widget->priv->window);
9845 screen = gtk_widget_get_screen (widget);
9847 for (w = widget; w != NULL; w = w->priv->parent)
9849 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9852 if (gdk_visual_get_screen (visual) == screen)
9855 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9856 gtk_widget_get_name (widget));
9860 return gdk_screen_get_system_visual (screen);
9864 * gtk_widget_get_settings:
9865 * @widget: a #GtkWidget
9867 * Gets the settings object holding the settings used for this widget.
9869 * Note that this function can only be called when the #GtkWidget
9870 * is attached to a toplevel, since the settings object is specific
9871 * to a particular #GdkScreen.
9873 * Return value: (transfer none): the relevant #GtkSettings object
9876 gtk_widget_get_settings (GtkWidget *widget)
9878 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9880 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9884 * gtk_widget_get_events:
9885 * @widget: a #GtkWidget
9887 * Returns the event mask for the widget (a bitfield containing flags
9888 * from the #GdkEventMask enumeration). These are the events that the widget
9891 * Return value: event mask for @widget
9894 gtk_widget_get_events (GtkWidget *widget)
9896 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9898 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9902 * gtk_widget_get_device_events:
9903 * @widget: a #GtkWidget
9904 * @device: a #GdkDevice
9906 * Returns the events mask for the widget corresponding to an specific device. These
9907 * are the events that the widget will receive when @device operates on it.
9909 * Returns: device event mask for @widget
9914 gtk_widget_get_device_events (GtkWidget *widget,
9917 GHashTable *device_events;
9919 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9920 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9922 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9927 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9931 * gtk_widget_get_pointer:
9932 * @widget: a #GtkWidget
9933 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9934 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9936 * Obtains the location of the mouse pointer in widget coordinates.
9937 * Widget coordinates are a bit odd; for historical reasons, they are
9938 * defined as @widget->window coordinates for widgets that are not
9939 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9940 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9942 * Deprecated: 3.4: Use gdk_window_get_device_position() instead.
9945 gtk_widget_get_pointer (GtkWidget *widget,
9949 GtkWidgetPrivate *priv;
9951 g_return_if_fail (GTK_IS_WIDGET (widget));
9953 priv = widget->priv;
9960 if (gtk_widget_get_realized (widget))
9962 gdk_window_get_device_position (priv->window,
9963 gdk_device_manager_get_client_pointer (
9964 gdk_display_get_device_manager (
9965 gtk_widget_get_display (widget))),
9968 if (!gtk_widget_get_has_window (widget))
9971 *x -= priv->allocation.x;
9973 *y -= priv->allocation.y;
9979 * gtk_widget_is_ancestor:
9980 * @widget: a #GtkWidget
9981 * @ancestor: another #GtkWidget
9983 * Determines whether @widget is somewhere inside @ancestor, possibly with
9984 * intermediate containers.
9986 * Return value: %TRUE if @ancestor contains @widget as a child,
9987 * grandchild, great grandchild, etc.
9990 gtk_widget_is_ancestor (GtkWidget *widget,
9991 GtkWidget *ancestor)
9993 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9994 g_return_val_if_fail (ancestor != NULL, FALSE);
9998 if (widget->priv->parent == ancestor)
10000 widget = widget->priv->parent;
10006 static GQuark quark_composite_name = 0;
10009 * gtk_widget_set_composite_name:
10010 * @widget: a #GtkWidget.
10011 * @name: the name to set
10013 * Sets a widgets composite name. The widget must be
10014 * a composite child of its parent; see gtk_widget_push_composite_child().
10017 gtk_widget_set_composite_name (GtkWidget *widget,
10020 g_return_if_fail (GTK_IS_WIDGET (widget));
10021 g_return_if_fail (widget->priv->composite_child);
10022 g_return_if_fail (name != NULL);
10024 if (!quark_composite_name)
10025 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10027 g_object_set_qdata_full (G_OBJECT (widget),
10028 quark_composite_name,
10034 * gtk_widget_get_composite_name:
10035 * @widget: a #GtkWidget
10037 * Obtains the composite name of a widget.
10039 * Returns: the composite name of @widget, or %NULL if @widget is not
10040 * a composite child. The string should be freed when it is no
10044 gtk_widget_get_composite_name (GtkWidget *widget)
10046 GtkWidgetPrivate *priv;
10048 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10050 priv = widget->priv;
10052 if (widget->priv->composite_child && priv->parent)
10053 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10060 * gtk_widget_push_composite_child:
10062 * Makes all newly-created widgets as composite children until
10063 * the corresponding gtk_widget_pop_composite_child() call.
10065 * A composite child is a child that's an implementation detail of the
10066 * container it's inside and should not be visible to people using the
10067 * container. Composite children aren't treated differently by GTK (but
10068 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10069 * builders might want to treat them in a different way.
10071 * Here is a simple example:
10073 * gtk_widget_push_composite_child ();
10074 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10075 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10076 * gtk_widget_pop_composite_child ();
10077 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10078 * GTK_WIDGET (scrolled_window));
10079 * g_object_ref (scrolled_window->hscrollbar);
10083 gtk_widget_push_composite_child (void)
10085 composite_child_stack++;
10089 * gtk_widget_pop_composite_child:
10091 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10094 gtk_widget_pop_composite_child (void)
10096 if (composite_child_stack)
10097 composite_child_stack--;
10101 gtk_widget_emit_direction_changed (GtkWidget *widget,
10102 GtkTextDirection old_dir)
10104 gtk_widget_update_pango_context (widget);
10106 if (widget->priv->context)
10107 gtk_style_context_set_direction (widget->priv->context,
10108 gtk_widget_get_direction (widget));
10110 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10114 * gtk_widget_set_direction:
10115 * @widget: a #GtkWidget
10116 * @dir: the new direction
10118 * Sets the reading direction on a particular widget. This direction
10119 * controls the primary direction for widgets containing text,
10120 * and also the direction in which the children of a container are
10121 * packed. The ability to set the direction is present in order
10122 * so that correct localization into languages with right-to-left
10123 * reading directions can be done. Generally, applications will
10124 * let the default reading direction present, except for containers
10125 * where the containers are arranged in an order that is explicitely
10126 * visual rather than logical (such as buttons for text justification).
10128 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10129 * set by gtk_widget_set_default_direction() will be used.
10132 gtk_widget_set_direction (GtkWidget *widget,
10133 GtkTextDirection dir)
10135 GtkTextDirection old_dir;
10137 g_return_if_fail (GTK_IS_WIDGET (widget));
10138 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10140 old_dir = gtk_widget_get_direction (widget);
10142 widget->priv->direction = dir;
10144 if (old_dir != gtk_widget_get_direction (widget))
10145 gtk_widget_emit_direction_changed (widget, old_dir);
10149 * gtk_widget_get_direction:
10150 * @widget: a #GtkWidget
10152 * Gets the reading direction for a particular widget. See
10153 * gtk_widget_set_direction().
10155 * Return value: the reading direction for the widget.
10158 gtk_widget_get_direction (GtkWidget *widget)
10160 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10162 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10163 return gtk_default_direction;
10165 return widget->priv->direction;
10169 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10171 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10173 g_object_ref (widget);
10175 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10176 gtk_widget_emit_direction_changed (widget, old_dir);
10178 if (GTK_IS_CONTAINER (widget))
10179 gtk_container_forall (GTK_CONTAINER (widget),
10180 gtk_widget_set_default_direction_recurse,
10183 g_object_unref (widget);
10187 * gtk_widget_set_default_direction:
10188 * @dir: the new default direction. This cannot be
10189 * %GTK_TEXT_DIR_NONE.
10191 * Sets the default reading direction for widgets where the
10192 * direction has not been explicitly set by gtk_widget_set_direction().
10195 gtk_widget_set_default_direction (GtkTextDirection dir)
10197 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10199 if (dir != gtk_default_direction)
10201 GList *toplevels, *tmp_list;
10202 GtkTextDirection old_dir = gtk_default_direction;
10204 gtk_default_direction = dir;
10206 tmp_list = toplevels = gtk_window_list_toplevels ();
10207 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10211 gtk_widget_set_default_direction_recurse (tmp_list->data,
10212 GUINT_TO_POINTER (old_dir));
10213 g_object_unref (tmp_list->data);
10214 tmp_list = tmp_list->next;
10217 g_list_free (toplevels);
10222 * gtk_widget_get_default_direction:
10224 * Obtains the current default reading direction. See
10225 * gtk_widget_set_default_direction().
10227 * Return value: the current default direction.
10230 gtk_widget_get_default_direction (void)
10232 return gtk_default_direction;
10236 gtk_widget_constructed (GObject *object)
10238 GtkWidget *widget = GTK_WIDGET (object);
10239 GtkWidgetPrivate *priv = widget->priv;
10241 /* As strange as it may seem, this may happen on object construction.
10242 * init() implementations of parent types may eventually call this function,
10243 * each with its corresponding GType, which could leave a child
10244 * implementation with a wrong widget type in the widget path
10247 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (priv->path))
10249 gtk_widget_path_free (priv->path);
10253 G_OBJECT_CLASS (gtk_widget_parent_class)->constructed (object);
10257 gtk_widget_dispose (GObject *object)
10259 GtkWidget *widget = GTK_WIDGET (object);
10260 GtkWidgetPrivate *priv = widget->priv;
10263 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10264 else if (gtk_widget_get_visible (widget))
10265 gtk_widget_hide (widget);
10267 priv->visible = FALSE;
10268 if (gtk_widget_get_realized (widget))
10269 gtk_widget_unrealize (widget);
10271 if (!priv->in_destruction)
10273 priv->in_destruction = TRUE;
10274 g_signal_emit (object, widget_signals[DESTROY], 0);
10275 priv->in_destruction = FALSE;
10278 g_clear_object (&priv->muxer);
10280 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10284 gtk_widget_real_destroy (GtkWidget *object)
10286 /* gtk_object_destroy() will already hold a refcount on object */
10287 GtkWidget *widget = GTK_WIDGET (object);
10288 GtkWidgetPrivate *priv = widget->priv;
10290 if (GTK_WIDGET_GET_CLASS (widget)->priv->accessible_type != GTK_TYPE_ACCESSIBLE)
10292 GtkAccessible *accessible = g_object_steal_qdata (G_OBJECT (widget), quark_accessible_object);
10296 gtk_accessible_set_widget (accessible, NULL);
10297 g_object_unref (accessible);
10301 /* wipe accelerator closures (keep order) */
10302 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10303 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10305 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10306 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10308 gtk_grab_remove (widget);
10311 g_object_unref (priv->style);
10312 priv->style = gtk_widget_get_default_style ();
10313 g_object_ref (priv->style);
10317 gtk_widget_finalize (GObject *object)
10319 GtkWidget *widget = GTK_WIDGET (object);
10320 GtkWidgetPrivate *priv = widget->priv;
10321 GtkWidgetAuxInfo *aux_info;
10322 GtkAccessible *accessible;
10324 gtk_grab_remove (widget);
10326 g_object_unref (priv->style);
10327 priv->style = NULL;
10329 g_free (priv->name);
10331 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10333 gtk_widget_aux_info_destroy (aux_info);
10335 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10337 g_object_unref (accessible);
10340 gtk_widget_path_free (priv->path);
10344 _gtk_style_context_set_widget (priv->context, NULL);
10345 g_object_unref (priv->context);
10348 _gtk_widget_free_cached_sizes (widget);
10350 if (g_object_is_floating (object))
10351 g_warning ("A floating object was finalized. This means that someone\n"
10352 "called g_object_unref() on an object that had only a floating\n"
10353 "reference; the initial floating reference is not owned by anyone\n"
10354 "and must be removed with g_object_ref_sink().");
10356 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10359 /*****************************************
10360 * gtk_widget_real_map:
10365 *****************************************/
10368 gtk_widget_real_map (GtkWidget *widget)
10370 GtkWidgetPrivate *priv = widget->priv;
10372 g_assert (gtk_widget_get_realized (widget));
10374 if (!gtk_widget_get_mapped (widget))
10376 gtk_widget_set_mapped (widget, TRUE);
10378 if (gtk_widget_get_has_window (widget))
10379 gdk_window_show (priv->window);
10383 /*****************************************
10384 * gtk_widget_real_unmap:
10389 *****************************************/
10392 gtk_widget_real_unmap (GtkWidget *widget)
10394 GtkWidgetPrivate *priv = widget->priv;
10396 if (gtk_widget_get_mapped (widget))
10398 gtk_widget_set_mapped (widget, FALSE);
10400 if (gtk_widget_get_has_window (widget))
10401 gdk_window_hide (priv->window);
10405 /*****************************************
10406 * gtk_widget_real_realize:
10411 *****************************************/
10414 gtk_widget_real_realize (GtkWidget *widget)
10416 GtkWidgetPrivate *priv = widget->priv;
10418 g_assert (!gtk_widget_get_has_window (widget));
10420 gtk_widget_set_realized (widget, TRUE);
10423 priv->window = gtk_widget_get_parent_window (widget);
10424 g_object_ref (priv->window);
10428 /*****************************************
10429 * gtk_widget_real_unrealize:
10434 *****************************************/
10437 gtk_widget_real_unrealize (GtkWidget *widget)
10439 GtkWidgetPrivate *priv = widget->priv;
10441 g_assert (!widget->priv->mapped);
10443 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10446 /* We must do unrealize child widget BEFORE container widget.
10447 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10448 * So, unrealizing container widget bofore its children causes the problem
10449 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10452 if (GTK_IS_CONTAINER (widget))
10453 gtk_container_forall (GTK_CONTAINER (widget),
10454 (GtkCallback) gtk_widget_unrealize,
10457 if (gtk_widget_get_has_window (widget))
10459 gdk_window_set_user_data (priv->window, NULL);
10460 gdk_window_destroy (priv->window);
10461 priv->window = NULL;
10465 g_object_unref (priv->window);
10466 priv->window = NULL;
10469 gtk_selection_remove_all (widget);
10471 gtk_widget_set_realized (widget, FALSE);
10475 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10476 GtkOrientation orientation,
10477 gint *minimum_size,
10478 gint *natural_size)
10480 const GtkWidgetAuxInfo *aux_info;
10482 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10484 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10485 aux_info->width > 0)
10487 *minimum_size = MAX (*minimum_size, aux_info->width);
10489 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10490 aux_info->height > 0)
10492 *minimum_size = MAX (*minimum_size, aux_info->height);
10495 /* Fix it if set_size_request made natural size smaller than min size.
10496 * This would also silently fix broken widgets, but we warn about them
10497 * in gtksizerequest.c when calling their size request vfuncs.
10499 *natural_size = MAX (*natural_size, *minimum_size);
10501 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10503 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10504 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10508 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10509 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10514 * _gtk_widget_peek_request_cache:
10516 * Returns the address of the widget's request cache (strictly for
10517 * internal use in gtksizerequest.c)
10519 * Return value: the address of @widget's size request cache.
10522 _gtk_widget_peek_request_cache (GtkWidget *widget)
10524 /* Don't bother slowing things down with the return_if_fail guards here */
10525 return &widget->priv->requests;
10529 * _gtk_widget_set_device_window:
10530 * @widget: a #GtkWidget
10531 * @device: a #GdkDevice
10532 * @window: the new device window
10534 * Sets pointer window for @widget and @device.
10535 * Does not ref @window.
10538 _gtk_widget_set_device_window (GtkWidget *widget,
10542 GHashTable *device_window;
10544 g_return_if_fail (GTK_IS_WIDGET (widget));
10545 g_return_if_fail (GDK_IS_DEVICE (device));
10546 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10548 if (!gtk_widget_get_mapped (widget))
10551 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10553 if (!device_window && window)
10555 device_window = g_hash_table_new (NULL, NULL);
10556 g_object_set_qdata_full (G_OBJECT (widget),
10557 quark_pointer_window,
10559 (GDestroyNotify) g_hash_table_destroy);
10563 g_hash_table_insert (device_window, device, window);
10564 else if (device_window)
10566 g_hash_table_remove (device_window, device);
10568 if (g_hash_table_size (device_window) == 0)
10569 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10574 * _gtk_widget_get_device_window:
10575 * @widget: a #GtkWidget
10576 * @device: a #GdkDevice
10578 * Return value: the device window set on @widget, or %NULL
10581 _gtk_widget_get_device_window (GtkWidget *widget,
10584 GHashTable *device_window;
10586 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10587 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10589 if (!gtk_widget_get_mapped (widget))
10592 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10594 if (!device_window)
10597 return g_hash_table_lookup (device_window, device);
10601 * _gtk_widget_list_devices:
10602 * @widget: a #GtkWidget
10604 * Returns the list of #GdkDevices that is currently on top
10605 * of any window belonging to @widget.
10606 * Free the list with g_list_free(), the elements are owned
10607 * by GTK+ and must not be freed.
10610 _gtk_widget_list_devices (GtkWidget *widget)
10612 GHashTableIter iter;
10613 GHashTable *device_window;
10614 GList *devices = NULL;
10615 gpointer key, value;
10617 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10619 if (!gtk_widget_get_mapped (widget))
10622 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10624 if (G_UNLIKELY (!device_window))
10627 g_hash_table_iter_init (&iter, device_window);
10629 while (g_hash_table_iter_next (&iter, &key, &value))
10630 devices = g_list_prepend (devices, key);
10636 synth_crossing (GtkWidget *widget,
10640 GdkCrossingMode mode,
10641 GdkNotifyType detail)
10645 event = gdk_event_new (type);
10647 event->crossing.window = g_object_ref (window);
10648 event->crossing.send_event = TRUE;
10649 event->crossing.subwindow = g_object_ref (window);
10650 event->crossing.time = GDK_CURRENT_TIME;
10651 event->crossing.x = event->crossing.y = 0;
10652 event->crossing.x_root = event->crossing.y_root = 0;
10653 event->crossing.mode = mode;
10654 event->crossing.detail = detail;
10655 event->crossing.focus = FALSE;
10656 event->crossing.state = 0;
10657 gdk_event_set_device (event, device);
10660 widget = gtk_get_event_widget (event);
10663 gtk_widget_event_internal (widget, event);
10665 gdk_event_free (event);
10669 * _gtk_widget_synthesize_crossing:
10670 * @from: the #GtkWidget the virtual pointer is leaving.
10671 * @to: the #GtkWidget the virtual pointer is moving to.
10672 * @mode: the #GdkCrossingMode to place on the synthesized events.
10674 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10676 * The real pointer window is the window that most recently received an enter notify
10677 * event. Windows that don't select for crossing events can't become the real
10678 * poiner window. The real pointer widget that owns the real pointer window. The
10679 * effective pointer window is the same as the real pointer window unless the real
10680 * pointer widget is either insensitive or there is a grab on a widget that is not
10681 * an ancestor of the real pointer widget (in which case the effective pointer
10682 * window should be the root window).
10684 * When the effective pointer window is the same as the real poiner window, we
10685 * receive crossing events from the windowing system. When the effective pointer
10686 * window changes to become different from the real pointer window we synthesize
10687 * crossing events, attempting to follow X protocol rules:
10689 * When the root window becomes the effective pointer window:
10690 * - leave notify on real pointer window, detail Ancestor
10691 * - leave notify on all of its ancestors, detail Virtual
10692 * - enter notify on root window, detail Inferior
10694 * When the root window ceases to be the effective pointer window:
10695 * - leave notify on root window, detail Inferior
10696 * - enter notify on all ancestors of real pointer window, detail Virtual
10697 * - enter notify on real pointer window, detail Ancestor
10700 _gtk_widget_synthesize_crossing (GtkWidget *from,
10703 GdkCrossingMode mode)
10705 GdkWindow *from_window = NULL, *to_window = NULL;
10707 g_return_if_fail (from != NULL || to != NULL);
10711 from_window = _gtk_widget_get_device_window (from, device);
10714 from_window = from->priv->window;
10719 to_window = _gtk_widget_get_device_window (to, device);
10722 to_window = to->priv->window;
10725 if (from_window == NULL && to_window == NULL)
10727 else if (from_window != NULL && to_window == NULL)
10729 GList *from_ancestors = NULL, *list;
10730 GdkWindow *from_ancestor = from_window;
10732 while (from_ancestor != NULL)
10734 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10735 if (from_ancestor == NULL)
10737 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10740 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10741 device, mode, GDK_NOTIFY_ANCESTOR);
10742 for (list = g_list_last (from_ancestors); list; list = list->prev)
10744 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10745 device, mode, GDK_NOTIFY_VIRTUAL);
10748 /* XXX: enter/inferior on root window? */
10750 g_list_free (from_ancestors);
10752 else if (from_window == NULL && to_window != NULL)
10754 GList *to_ancestors = NULL, *list;
10755 GdkWindow *to_ancestor = to_window;
10757 while (to_ancestor != NULL)
10759 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10760 if (to_ancestor == NULL)
10762 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10765 /* XXX: leave/inferior on root window? */
10767 for (list = to_ancestors; list; list = list->next)
10769 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10770 device, mode, GDK_NOTIFY_VIRTUAL);
10772 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10773 device, mode, GDK_NOTIFY_ANCESTOR);
10775 g_list_free (to_ancestors);
10777 else if (from_window == to_window)
10781 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10782 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10784 while (from_ancestor != NULL || to_ancestor != NULL)
10786 if (from_ancestor != NULL)
10788 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10789 if (from_ancestor == to_window)
10792 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10794 if (to_ancestor != NULL)
10796 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10797 if (to_ancestor == from_window)
10800 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10803 if (to_ancestor == from_window)
10805 if (mode != GDK_CROSSING_GTK_UNGRAB)
10806 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10807 device, mode, GDK_NOTIFY_INFERIOR);
10808 for (list = to_ancestors; list; list = list->next)
10809 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10810 device, mode, GDK_NOTIFY_VIRTUAL);
10811 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10812 device, mode, GDK_NOTIFY_ANCESTOR);
10814 else if (from_ancestor == to_window)
10816 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10817 device, mode, GDK_NOTIFY_ANCESTOR);
10818 for (list = g_list_last (from_ancestors); list; list = list->prev)
10820 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10821 device, mode, GDK_NOTIFY_VIRTUAL);
10823 if (mode != GDK_CROSSING_GTK_GRAB)
10824 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10825 device, mode, GDK_NOTIFY_INFERIOR);
10829 while (from_ancestors != NULL && to_ancestors != NULL
10830 && from_ancestors->data == to_ancestors->data)
10832 from_ancestors = g_list_delete_link (from_ancestors,
10834 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10837 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10838 device, mode, GDK_NOTIFY_NONLINEAR);
10840 for (list = g_list_last (from_ancestors); list; list = list->prev)
10842 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10843 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10845 for (list = to_ancestors; list; list = list->next)
10847 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10848 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10850 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10851 device, mode, GDK_NOTIFY_NONLINEAR);
10853 g_list_free (from_ancestors);
10854 g_list_free (to_ancestors);
10859 gtk_widget_propagate_state (GtkWidget *widget,
10860 GtkStateData *data)
10862 GtkWidgetPrivate *priv = widget->priv;
10863 GtkStateFlags new_flags, old_flags = priv->state_flags;
10864 GtkStateType old_state;
10866 old_state = gtk_widget_get_state (widget);
10868 switch (data->operation)
10870 case STATE_CHANGE_REPLACE:
10871 priv->state_flags = data->flags;
10873 case STATE_CHANGE_SET:
10874 priv->state_flags |= data->flags;
10876 case STATE_CHANGE_UNSET:
10877 priv->state_flags &= ~(data->flags);
10881 /* make insensitivity unoverridable */
10882 if (!priv->sensitive)
10883 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
10885 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10889 window = gtk_widget_get_toplevel (widget);
10891 if (window && gtk_widget_is_toplevel (window))
10892 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10895 new_flags = priv->state_flags;
10897 if (old_flags != new_flags)
10899 g_object_ref (widget);
10901 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10902 gtk_grab_remove (widget);
10904 gtk_style_context_set_state (gtk_widget_get_style_context (widget), new_flags);
10906 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10907 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
10909 if (!priv->shadowed &&
10910 (new_flags & GTK_STATE_FLAG_INSENSITIVE) != (old_flags & GTK_STATE_FLAG_INSENSITIVE))
10912 GList *event_windows = NULL;
10913 GList *devices, *d;
10915 devices = _gtk_widget_list_devices (widget);
10917 for (d = devices; d; d = d->next)
10923 window = _gtk_widget_get_device_window (widget, device);
10925 /* Do not propagate more than once to the
10926 * same window if non-multidevice aware.
10928 if (!gdk_window_get_support_multidevice (window) &&
10929 g_list_find (event_windows, window))
10932 if (!gtk_widget_is_sensitive (widget))
10933 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10934 GDK_CROSSING_STATE_CHANGED);
10936 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10937 GDK_CROSSING_STATE_CHANGED);
10939 event_windows = g_list_prepend (event_windows, window);
10942 g_list_free (event_windows);
10943 g_list_free (devices);
10946 if (GTK_IS_CONTAINER (widget))
10948 GtkStateData child_data = *data;
10950 /* Make sure to only propate the right states further */
10951 child_data.flags &= GTK_STATE_FLAGS_DO_PROPAGATE;
10953 gtk_container_forall (GTK_CONTAINER (widget),
10954 (GtkCallback) gtk_widget_propagate_state,
10958 g_object_unref (widget);
10962 static const GtkWidgetAuxInfo default_aux_info = {
10970 * gtk_widget_get_aux_info:
10971 * @widget: a #GtkWidget
10972 * @create: if %TRUE, create the structure if it doesn't exist
10974 * Get the #GtkWidgetAuxInfo structure for the widget.
10976 * Return value: the #GtkAuxInfo structure for the widget, or
10977 * %NULL if @create is %FALSE and one doesn't already exist.
10979 static GtkWidgetAuxInfo *
10980 gtk_widget_get_aux_info (GtkWidget *widget,
10983 GtkWidgetAuxInfo *aux_info;
10985 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
10986 if (!aux_info && create)
10988 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
10990 *aux_info = default_aux_info;
10992 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
10998 static const GtkWidgetAuxInfo*
10999 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11001 GtkWidgetAuxInfo *aux_info;
11003 aux_info = gtk_widget_get_aux_info (widget, FALSE);
11004 if (aux_info == NULL)
11006 return &default_aux_info;
11014 /*****************************************
11015 * gtk_widget_aux_info_destroy:
11020 *****************************************/
11023 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11025 g_slice_free (GtkWidgetAuxInfo, aux_info);
11029 * gtk_widget_shape_combine_region:
11030 * @widget: a #GtkWidget
11031 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11033 * Sets a shape for this widget's GDK window. This allows for
11034 * transparent windows etc., see gdk_window_shape_combine_region()
11035 * for more information.
11040 gtk_widget_shape_combine_region (GtkWidget *widget,
11041 cairo_region_t *region)
11043 GtkWidgetPrivate *priv;
11045 g_return_if_fail (GTK_IS_WIDGET (widget));
11046 /* set_shape doesn't work on widgets without gdk window */
11047 g_return_if_fail (gtk_widget_get_has_window (widget));
11049 priv = widget->priv;
11051 if (region == NULL)
11053 priv->has_shape_mask = FALSE;
11056 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11058 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11062 priv->has_shape_mask = TRUE;
11064 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11065 cairo_region_copy (region),
11066 (GDestroyNotify) cairo_region_destroy);
11068 /* set shape if widget has a gdk window already.
11069 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11072 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11077 * gtk_widget_input_shape_combine_region:
11078 * @widget: a #GtkWidget
11079 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11081 * Sets an input shape for this widget's GDK window. This allows for
11082 * windows which react to mouse click in a nonrectangular region, see
11083 * gdk_window_input_shape_combine_region() for more information.
11088 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11089 cairo_region_t *region)
11091 GtkWidgetPrivate *priv;
11093 g_return_if_fail (GTK_IS_WIDGET (widget));
11094 /* set_shape doesn't work on widgets without gdk window */
11095 g_return_if_fail (gtk_widget_get_has_window (widget));
11097 priv = widget->priv;
11099 if (region == NULL)
11102 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11104 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11108 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11109 cairo_region_copy (region),
11110 (GDestroyNotify) cairo_region_destroy);
11112 /* set shape if widget has a gdk window already.
11113 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11116 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11121 /* style properties
11125 * gtk_widget_class_install_style_property_parser: (skip)
11126 * @klass: a #GtkWidgetClass
11127 * @pspec: the #GParamSpec for the style property
11128 * @parser: the parser for the style property
11130 * Installs a style property on a widget class.
11133 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11135 GtkRcPropertyParser parser)
11137 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11138 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11139 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11140 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11142 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11144 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11145 G_OBJECT_CLASS_NAME (klass),
11150 g_param_spec_ref_sink (pspec);
11151 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11152 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11156 * gtk_widget_class_install_style_property:
11157 * @klass: a #GtkWidgetClass
11158 * @pspec: the #GParamSpec for the property
11160 * Installs a style property on a widget class. The parser for the
11161 * style property is determined by the value type of @pspec.
11164 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11167 GtkRcPropertyParser parser;
11169 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11170 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11172 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11174 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11178 * gtk_widget_class_find_style_property:
11179 * @klass: a #GtkWidgetClass
11180 * @property_name: the name of the style property to find
11182 * Finds a style property of a widget class by name.
11184 * Returns: (transfer none): the #GParamSpec of the style property or
11185 * %NULL if @class has no style property with that name.
11190 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11191 const gchar *property_name)
11193 g_return_val_if_fail (property_name != NULL, NULL);
11195 return g_param_spec_pool_lookup (style_property_spec_pool,
11197 G_OBJECT_CLASS_TYPE (klass),
11202 * gtk_widget_class_list_style_properties:
11203 * @klass: a #GtkWidgetClass
11204 * @n_properties: location to return the number of style properties found
11206 * Returns all style properties of a widget class.
11208 * Returns: (array length=n_properties) (transfer container): a
11209 * newly allocated array of #GParamSpec*. The array must be
11210 * freed with g_free().
11215 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11216 guint *n_properties)
11218 GParamSpec **pspecs;
11221 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11222 G_OBJECT_CLASS_TYPE (klass),
11231 * gtk_widget_style_get_property:
11232 * @widget: a #GtkWidget
11233 * @property_name: the name of a style property
11234 * @value: location to return the property value
11236 * Gets the value of a style property of @widget.
11239 gtk_widget_style_get_property (GtkWidget *widget,
11240 const gchar *property_name,
11245 g_return_if_fail (GTK_IS_WIDGET (widget));
11246 g_return_if_fail (property_name != NULL);
11247 g_return_if_fail (G_IS_VALUE (value));
11249 g_object_ref (widget);
11250 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11252 G_OBJECT_TYPE (widget),
11255 g_warning ("%s: widget class `%s' has no property named `%s'",
11257 G_OBJECT_TYPE_NAME (widget),
11261 GtkStyleContext *context;
11262 const GValue *peek_value;
11263 GtkStateFlags state;
11265 context = gtk_widget_get_style_context (widget);
11266 state = gtk_widget_get_state_flags (widget);
11268 peek_value = _gtk_style_context_peek_style_property (context,
11269 G_OBJECT_TYPE (widget),
11272 /* auto-conversion of the caller's value type
11274 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11275 g_value_copy (peek_value, value);
11276 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11277 g_value_transform (peek_value, value);
11279 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11281 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11282 G_VALUE_TYPE_NAME (value));
11284 g_object_unref (widget);
11288 * gtk_widget_style_get_valist:
11289 * @widget: a #GtkWidget
11290 * @first_property_name: the name of the first property to get
11291 * @var_args: a <type>va_list</type> of pairs of property names and
11292 * locations to return the property values, starting with the location
11293 * for @first_property_name.
11295 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11299 gtk_widget_style_get_valist (GtkWidget *widget,
11300 const gchar *first_property_name,
11303 GtkStyleContext *context;
11304 GtkStateFlags state;
11307 g_return_if_fail (GTK_IS_WIDGET (widget));
11309 g_object_ref (widget);
11310 context = gtk_widget_get_style_context (widget);
11311 state = gtk_widget_get_state_flags (widget);
11313 name = first_property_name;
11316 const GValue *peek_value;
11320 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11322 G_OBJECT_TYPE (widget),
11326 g_warning ("%s: widget class `%s' has no property named `%s'",
11328 G_OBJECT_TYPE_NAME (widget),
11332 /* style pspecs are always readable so we can spare that check here */
11334 peek_value = _gtk_style_context_peek_style_property (context,
11335 G_OBJECT_TYPE (widget),
11338 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11341 g_warning ("%s: %s", G_STRLOC, error);
11346 name = va_arg (var_args, gchar*);
11349 g_object_unref (widget);
11353 * gtk_widget_style_get:
11354 * @widget: a #GtkWidget
11355 * @first_property_name: the name of the first property to get
11356 * @...: pairs of property names and locations to return the
11357 * property values, starting with the location for
11358 * @first_property_name, terminated by %NULL.
11360 * Gets the values of a multiple style properties of @widget.
11363 gtk_widget_style_get (GtkWidget *widget,
11364 const gchar *first_property_name,
11369 g_return_if_fail (GTK_IS_WIDGET (widget));
11371 va_start (var_args, first_property_name);
11372 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11377 * gtk_requisition_new:
11379 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11381 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11382 * be freed with gtk_requisition_free().
11387 gtk_requisition_new (void)
11389 return g_slice_new0 (GtkRequisition);
11393 * gtk_requisition_copy:
11394 * @requisition: a #GtkRequisition
11396 * Copies a #GtkRequisition.
11398 * Returns: a copy of @requisition
11401 gtk_requisition_copy (const GtkRequisition *requisition)
11403 return g_slice_dup (GtkRequisition, requisition);
11407 * gtk_requisition_free:
11408 * @requisition: a #GtkRequisition
11410 * Frees a #GtkRequisition.
11413 gtk_requisition_free (GtkRequisition *requisition)
11415 g_slice_free (GtkRequisition, requisition);
11418 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11419 gtk_requisition_copy,
11420 gtk_requisition_free)
11423 * gtk_widget_class_set_accessible_type:
11424 * @widget_class: class to set the accessible type for
11425 * @type: The object type that implements the accessible for @widget_class
11427 * Sets the type to be used for creating accessibles for widgets of
11428 * @widget_class. The given @type must be a subtype of the type used for
11429 * accessibles of the parent class.
11431 * This function should only be called from class init functions of widgets.
11436 gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class,
11439 GtkWidgetClassPrivate *priv;
11441 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11442 g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type));
11444 priv = widget_class->priv;
11446 priv->accessible_type = type;
11447 /* reset this - honoring the type's role is better. */
11448 priv->accessible_role = ATK_ROLE_INVALID;
11452 * gtk_widget_class_set_accessible_role:
11453 * @widget_class: class to set the accessible role for
11454 * @role: The role to use for accessibles created for @widget_class
11456 * Sets the default #AtkRole to be set on accessibles created for
11457 * widgets of @widget_class. Accessibles may decide to not honor this
11458 * setting if their role reporting is more refined. Calls to
11459 * gtk_widget_class_set_accessible_type() will reset this value.
11461 * In cases where you want more fine-grained control over the role of
11462 * accessibles created for @widget_class, you should provide your own
11463 * accessible type and use gtk_widget_class_set_accessible_type()
11466 * If @role is #ATK_ROLE_INVALID, the default role will not be changed
11467 * and the accessible's default role will be used instead.
11469 * This function should only be called from class init functions of widgets.
11474 gtk_widget_class_set_accessible_role (GtkWidgetClass *widget_class,
11477 GtkWidgetClassPrivate *priv;
11479 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11481 priv = widget_class->priv;
11483 priv->accessible_role = role;
11487 * _gtk_widget_peek_accessible:
11488 * @widget: a #GtkWidget
11490 * Gets the accessible for @widget, if it has been created yet.
11491 * Otherwise, this function returns %NULL. If the @widget's implementation
11492 * does not use the default way to create accessibles, %NULL will always be
11495 * Returns: the accessible for @widget or %NULL if none has been
11499 _gtk_widget_peek_accessible (GtkWidget *widget)
11501 return g_object_get_qdata (G_OBJECT (widget),
11502 quark_accessible_object);
11506 * gtk_widget_get_accessible:
11507 * @widget: a #GtkWidget
11509 * Returns the accessible object that describes the widget to an
11510 * assistive technology.
11512 * If accessibility support is not available, this #AtkObject
11513 * instance may be a no-op. Likewise, if no class-specific #AtkObject
11514 * implementation is available for the widget instance in question,
11515 * it will inherit an #AtkObject implementation from the first ancestor
11516 * class for which such an implementation is defined.
11518 * The documentation of the
11519 * <ulink url="http://developer.gnome.org/atk/stable/">ATK</ulink>
11520 * library contains more information about accessible objects and their uses.
11522 * Returns: (transfer none): the #AtkObject associated with @widget
11525 gtk_widget_get_accessible (GtkWidget *widget)
11527 GtkWidgetClass *klass;
11529 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11531 klass = GTK_WIDGET_GET_CLASS (widget);
11533 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11535 return klass->get_accessible (widget);
11539 gtk_widget_real_get_accessible (GtkWidget *widget)
11541 AtkObject* accessible;
11543 accessible = g_object_get_qdata (G_OBJECT (widget),
11544 quark_accessible_object);
11547 GtkWidgetClass *widget_class;
11548 GtkWidgetClassPrivate *priv;
11549 AtkObjectFactory *factory;
11550 AtkRegistry *default_registry;
11552 widget_class = GTK_WIDGET_GET_CLASS (widget);
11553 priv = widget_class->priv;
11555 if (priv->accessible_type == GTK_TYPE_ACCESSIBLE)
11557 default_registry = atk_get_default_registry ();
11558 factory = atk_registry_get_factory (default_registry,
11559 G_TYPE_FROM_INSTANCE (widget));
11561 atk_object_factory_create_accessible (factory,
11562 G_OBJECT (widget));
11564 if (priv->accessible_role != ATK_ROLE_INVALID)
11565 atk_object_set_role (accessible, priv->accessible_role);
11567 g_object_set_qdata (G_OBJECT (widget),
11568 quark_accessible_object,
11573 accessible = g_object_new (priv->accessible_type,
11576 if (priv->accessible_role != ATK_ROLE_INVALID)
11577 atk_object_set_role (accessible, priv->accessible_role);
11579 g_object_set_qdata (G_OBJECT (widget),
11580 quark_accessible_object,
11583 atk_object_initialize (accessible, widget);
11585 /* Set the role again, since we don't want a role set
11586 * in some parent initialize() function to override
11589 if (priv->accessible_role != ATK_ROLE_INVALID)
11590 atk_object_set_role (accessible, priv->accessible_role);
11597 * Initialize a AtkImplementorIface instance's virtual pointers as
11598 * appropriate to this implementor's class (GtkWidget).
11601 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11603 iface->ref_accessible = gtk_widget_ref_accessible;
11607 gtk_widget_ref_accessible (AtkImplementor *implementor)
11609 AtkObject *accessible;
11611 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11613 g_object_ref (accessible);
11618 * Expand flag management
11622 gtk_widget_update_computed_expand (GtkWidget *widget)
11624 GtkWidgetPrivate *priv;
11626 priv = widget->priv;
11628 if (priv->need_compute_expand)
11632 if (priv->hexpand_set)
11637 if (priv->vexpand_set)
11642 /* we don't need to use compute_expand if both expands are
11643 * forced by the app
11645 if (!(priv->hexpand_set && priv->vexpand_set))
11647 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11651 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11652 priv->hexpand_set ? &ignored : &h,
11653 priv->vexpand_set ? &ignored : &v);
11657 priv->need_compute_expand = FALSE;
11658 priv->computed_hexpand = h != FALSE;
11659 priv->computed_vexpand = v != FALSE;
11664 * gtk_widget_queue_compute_expand:
11665 * @widget: a #GtkWidget
11667 * Mark @widget as needing to recompute its expand flags. Call
11668 * this function when setting legacy expand child properties
11669 * on the child of a container.
11671 * See gtk_widget_compute_expand().
11674 gtk_widget_queue_compute_expand (GtkWidget *widget)
11677 gboolean changed_anything;
11679 if (widget->priv->need_compute_expand)
11682 changed_anything = FALSE;
11684 while (parent != NULL)
11686 if (!parent->priv->need_compute_expand)
11688 parent->priv->need_compute_expand = TRUE;
11689 changed_anything = TRUE;
11692 /* Note: if we had an invariant that "if a child needs to
11693 * compute expand, its parents also do" then we could stop going
11694 * up when we got to a parent that already needed to
11695 * compute. However, in general we compute expand lazily (as
11696 * soon as we see something in a subtree that is expand, we know
11697 * we're expanding) and so this invariant does not hold and we
11698 * have to always walk all the way up in case some ancestor
11699 * is not currently need_compute_expand.
11702 parent = parent->priv->parent;
11705 /* recomputing expand always requires
11706 * a relayout as well
11708 if (changed_anything)
11709 gtk_widget_queue_resize (widget);
11713 * gtk_widget_compute_expand:
11714 * @widget: the widget
11715 * @orientation: expand direction
11717 * Computes whether a container should give this widget extra space
11718 * when possible. Containers should check this, rather than
11719 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11721 * This function already checks whether the widget is visible, so
11722 * visibility does not need to be checked separately. Non-visible
11723 * widgets are not expanded.
11725 * The computed expand value uses either the expand setting explicitly
11726 * set on the widget itself, or, if none has been explicitly set,
11727 * the widget may expand if some of its children do.
11729 * Return value: whether widget tree rooted here should be expanded
11732 gtk_widget_compute_expand (GtkWidget *widget,
11733 GtkOrientation orientation)
11735 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11737 /* We never make a widget expand if not even showing. */
11738 if (!gtk_widget_get_visible (widget))
11741 gtk_widget_update_computed_expand (widget);
11743 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11745 return widget->priv->computed_hexpand;
11749 return widget->priv->computed_vexpand;
11754 gtk_widget_set_expand (GtkWidget *widget,
11755 GtkOrientation orientation,
11758 const char *expand_prop;
11759 const char *expand_set_prop;
11761 GtkWidgetPrivate *priv;
11763 g_return_if_fail (GTK_IS_WIDGET (widget));
11765 priv = widget->priv;
11767 expand = expand != FALSE;
11769 was_both = priv->hexpand && priv->vexpand;
11771 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11773 if (priv->hexpand_set &&
11774 priv->hexpand == expand)
11777 priv->hexpand_set = TRUE;
11778 priv->hexpand = expand;
11780 expand_prop = "hexpand";
11781 expand_set_prop = "hexpand-set";
11785 if (priv->vexpand_set &&
11786 priv->vexpand == expand)
11789 priv->vexpand_set = TRUE;
11790 priv->vexpand = expand;
11792 expand_prop = "vexpand";
11793 expand_set_prop = "vexpand-set";
11796 gtk_widget_queue_compute_expand (widget);
11798 g_object_freeze_notify (G_OBJECT (widget));
11799 g_object_notify (G_OBJECT (widget), expand_prop);
11800 g_object_notify (G_OBJECT (widget), expand_set_prop);
11801 if (was_both != (priv->hexpand && priv->vexpand))
11802 g_object_notify (G_OBJECT (widget), "expand");
11803 g_object_thaw_notify (G_OBJECT (widget));
11807 gtk_widget_set_expand_set (GtkWidget *widget,
11808 GtkOrientation orientation,
11811 GtkWidgetPrivate *priv;
11814 priv = widget->priv;
11816 set = set != FALSE;
11818 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11820 if (set == priv->hexpand_set)
11823 priv->hexpand_set = set;
11824 prop = "hexpand-set";
11828 if (set == priv->vexpand_set)
11831 priv->vexpand_set = set;
11832 prop = "vexpand-set";
11835 gtk_widget_queue_compute_expand (widget);
11837 g_object_notify (G_OBJECT (widget), prop);
11841 * gtk_widget_get_hexpand:
11842 * @widget: the widget
11844 * Gets whether the widget would like any available extra horizontal
11845 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11846 * generally receive the extra space. For example, a list or
11847 * scrollable area or document in your window would often be set to
11850 * Containers should use gtk_widget_compute_expand() rather than
11851 * this function, to see whether a widget, or any of its children,
11852 * has the expand flag set. If any child of a widget wants to
11853 * expand, the parent may ask to expand also.
11855 * This function only looks at the widget's own hexpand flag, rather
11856 * than computing whether the entire widget tree rooted at this widget
11859 * Return value: whether hexpand flag is set
11862 gtk_widget_get_hexpand (GtkWidget *widget)
11864 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11866 return widget->priv->hexpand;
11870 * gtk_widget_set_hexpand:
11871 * @widget: the widget
11872 * @expand: whether to expand
11874 * Sets whether the widget would like any available extra horizontal
11875 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11876 * generally receive the extra space. For example, a list or
11877 * scrollable area or document in your window would often be set to
11880 * Call this function to set the expand flag if you would like your
11881 * widget to become larger horizontally when the window has extra
11884 * By default, widgets automatically expand if any of their children
11885 * want to expand. (To see if a widget will automatically expand given
11886 * its current children and state, call gtk_widget_compute_expand(). A
11887 * container can decide how the expandability of children affects the
11888 * expansion of the container by overriding the compute_expand virtual
11889 * method on #GtkWidget.).
11891 * Setting hexpand explicitly with this function will override the
11892 * automatic expand behavior.
11894 * This function forces the widget to expand or not to expand,
11895 * regardless of children. The override occurs because
11896 * gtk_widget_set_hexpand() sets the hexpand-set property (see
11897 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
11898 * value to be used, rather than looking at children and widget state.
11901 gtk_widget_set_hexpand (GtkWidget *widget,
11904 g_return_if_fail (GTK_IS_WIDGET (widget));
11906 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
11910 * gtk_widget_get_hexpand_set:
11911 * @widget: the widget
11913 * Gets whether gtk_widget_set_hexpand() has been used to
11914 * explicitly set the expand flag on this widget.
11916 * If hexpand is set, then it overrides any computed
11917 * expand value based on child widgets. If hexpand is not
11918 * set, then the expand value depends on whether any
11919 * children of the widget would like to expand.
11921 * There are few reasons to use this function, but it's here
11922 * for completeness and consistency.
11924 * Return value: whether hexpand has been explicitly set
11927 gtk_widget_get_hexpand_set (GtkWidget *widget)
11929 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11931 return widget->priv->hexpand_set;
11935 * gtk_widget_set_hexpand_set:
11936 * @widget: the widget
11937 * @set: value for hexpand-set property
11939 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
11942 * The hexpand-set property will be set automatically when you call
11943 * gtk_widget_set_hexpand() to set hexpand, so the most likely
11944 * reason to use this function would be to unset an explicit expand
11947 * If hexpand is set, then it overrides any computed
11948 * expand value based on child widgets. If hexpand is not
11949 * set, then the expand value depends on whether any
11950 * children of the widget would like to expand.
11952 * There are few reasons to use this function, but it's here
11953 * for completeness and consistency.
11956 gtk_widget_set_hexpand_set (GtkWidget *widget,
11959 g_return_if_fail (GTK_IS_WIDGET (widget));
11961 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
11966 * gtk_widget_get_vexpand:
11967 * @widget: the widget
11969 * Gets whether the widget would like any available extra vertical
11972 * See gtk_widget_get_hexpand() for more detail.
11974 * Return value: whether vexpand flag is set
11977 gtk_widget_get_vexpand (GtkWidget *widget)
11979 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11981 return widget->priv->vexpand;
11985 * gtk_widget_set_vexpand:
11986 * @widget: the widget
11987 * @expand: whether to expand
11989 * Sets whether the widget would like any available extra vertical
11992 * See gtk_widget_set_hexpand() for more detail.
11995 gtk_widget_set_vexpand (GtkWidget *widget,
11998 g_return_if_fail (GTK_IS_WIDGET (widget));
12000 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12004 * gtk_widget_get_vexpand_set:
12005 * @widget: the widget
12007 * Gets whether gtk_widget_set_vexpand() has been used to
12008 * explicitly set the expand flag on this widget.
12010 * See gtk_widget_get_hexpand_set() for more detail.
12012 * Return value: whether vexpand has been explicitly set
12015 gtk_widget_get_vexpand_set (GtkWidget *widget)
12017 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12019 return widget->priv->vexpand_set;
12023 * gtk_widget_set_vexpand_set:
12024 * @widget: the widget
12025 * @set: value for vexpand-set property
12027 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12030 * See gtk_widget_set_hexpand_set() for more detail.
12033 gtk_widget_set_vexpand_set (GtkWidget *widget,
12036 g_return_if_fail (GTK_IS_WIDGET (widget));
12038 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12042 * GtkBuildable implementation
12044 static GQuark quark_builder_has_default = 0;
12045 static GQuark quark_builder_has_focus = 0;
12046 static GQuark quark_builder_atk_relations = 0;
12047 static GQuark quark_builder_set_name = 0;
12050 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12052 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12053 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12054 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12055 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12057 iface->set_name = gtk_widget_buildable_set_name;
12058 iface->get_name = gtk_widget_buildable_get_name;
12059 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12060 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12061 iface->parser_finished = gtk_widget_buildable_parser_finished;
12062 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12063 iface->custom_finished = gtk_widget_buildable_custom_finished;
12067 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12070 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12071 g_strdup (name), g_free);
12074 static const gchar *
12075 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12077 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12081 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12082 GtkBuilder *builder,
12083 const gchar *childname)
12085 if (strcmp (childname, "accessible") == 0)
12086 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12092 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12093 GtkBuilder *builder,
12095 const GValue *value)
12097 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12098 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12099 GINT_TO_POINTER (TRUE));
12100 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12101 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12102 GINT_TO_POINTER (TRUE));
12104 g_object_set_property (G_OBJECT (buildable), name, value);
12109 gchar *action_name;
12110 GString *description;
12112 gboolean translatable;
12122 free_action (AtkActionData *data, gpointer user_data)
12124 g_free (data->action_name);
12125 g_string_free (data->description, TRUE);
12126 g_free (data->context);
12127 g_slice_free (AtkActionData, data);
12131 free_relation (AtkRelationData *data, gpointer user_data)
12133 g_free (data->target);
12134 g_free (data->type);
12135 g_slice_free (AtkRelationData, data);
12139 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12140 GtkBuilder *builder)
12142 GSList *atk_relations;
12144 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12145 gtk_widget_grab_default (GTK_WIDGET (buildable));
12146 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12147 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12149 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12150 quark_builder_atk_relations);
12153 AtkObject *accessible;
12154 AtkRelationSet *relation_set;
12157 AtkRelationType relation_type;
12158 AtkObject *target_accessible;
12160 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12161 relation_set = atk_object_ref_relation_set (accessible);
12163 for (l = atk_relations; l; l = l->next)
12165 AtkRelationData *relation = (AtkRelationData*)l->data;
12167 target = gtk_builder_get_object (builder, relation->target);
12170 g_warning ("Target object %s in <relation> does not exist",
12174 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12175 g_assert (target_accessible != NULL);
12177 relation_type = atk_relation_type_for_name (relation->type);
12178 if (relation_type == ATK_RELATION_NULL)
12180 g_warning ("<relation> type %s not found",
12184 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12185 target_accessible);
12187 g_object_unref (relation_set);
12189 g_slist_free_full (atk_relations, (GDestroyNotify) free_relation);
12190 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12199 } AccessibilitySubParserData;
12202 accessibility_start_element (GMarkupParseContext *context,
12203 const gchar *element_name,
12204 const gchar **names,
12205 const gchar **values,
12206 gpointer user_data,
12209 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12211 gint line_number, char_number;
12213 if (strcmp (element_name, "relation") == 0)
12215 gchar *target = NULL;
12216 gchar *type = NULL;
12217 AtkRelationData *relation;
12219 for (i = 0; names[i]; i++)
12221 if (strcmp (names[i], "target") == 0)
12222 target = g_strdup (values[i]);
12223 else if (strcmp (names[i], "type") == 0)
12224 type = g_strdup (values[i]);
12227 g_markup_parse_context_get_position (context,
12230 g_set_error (error,
12232 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12233 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12235 line_number, char_number, names[i], "relation");
12242 if (!target || !type)
12244 g_markup_parse_context_get_position (context,
12247 g_set_error (error,
12249 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12250 "%s:%d:%d <%s> requires attribute \"%s\"",
12252 line_number, char_number, "relation",
12253 type ? "target" : "type");
12259 relation = g_slice_new (AtkRelationData);
12260 relation->target = target;
12261 relation->type = type;
12263 data->relations = g_slist_prepend (data->relations, relation);
12265 else if (strcmp (element_name, "action") == 0)
12267 const gchar *action_name = NULL;
12268 const gchar *description = NULL;
12269 const gchar *msg_context = NULL;
12270 gboolean translatable = FALSE;
12271 AtkActionData *action;
12273 for (i = 0; names[i]; i++)
12275 if (strcmp (names[i], "action_name") == 0)
12276 action_name = values[i];
12277 else if (strcmp (names[i], "description") == 0)
12278 description = values[i];
12279 else if (strcmp (names[i], "translatable") == 0)
12281 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12284 else if (strcmp (names[i], "comments") == 0)
12286 /* do nothing, comments are for translators */
12288 else if (strcmp (names[i], "context") == 0)
12289 msg_context = values[i];
12292 g_markup_parse_context_get_position (context,
12295 g_set_error (error,
12297 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12298 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12300 line_number, char_number, names[i], "action");
12307 g_markup_parse_context_get_position (context,
12310 g_set_error (error,
12312 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12313 "%s:%d:%d <%s> requires attribute \"%s\"",
12315 line_number, char_number, "action",
12320 action = g_slice_new (AtkActionData);
12321 action->action_name = g_strdup (action_name);
12322 action->description = g_string_new (description);
12323 action->context = g_strdup (msg_context);
12324 action->translatable = translatable;
12326 data->actions = g_slist_prepend (data->actions, action);
12328 else if (strcmp (element_name, "accessibility") == 0)
12331 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12335 accessibility_text (GMarkupParseContext *context,
12338 gpointer user_data,
12341 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12343 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12345 AtkActionData *action = data->actions->data;
12347 g_string_append_len (action->description, text, text_len);
12351 static const GMarkupParser accessibility_parser =
12353 accessibility_start_element,
12355 accessibility_text,
12364 } AccelGroupParserData;
12367 accel_group_start_element (GMarkupParseContext *context,
12368 const gchar *element_name,
12369 const gchar **names,
12370 const gchar **values,
12371 gpointer user_data,
12376 guint modifiers = 0;
12377 gchar *signal = NULL;
12378 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12380 for (i = 0; names[i]; i++)
12382 if (strcmp (names[i], "key") == 0)
12383 key = gdk_keyval_from_name (values[i]);
12384 else if (strcmp (names[i], "modifiers") == 0)
12386 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12392 else if (strcmp (names[i], "signal") == 0)
12393 signal = g_strdup (values[i]);
12396 if (key == 0 || signal == NULL)
12398 g_warning ("<accelerator> requires key and signal attributes");
12401 parser_data->key = key;
12402 parser_data->modifiers = modifiers;
12403 parser_data->signal = signal;
12406 static const GMarkupParser accel_group_parser =
12408 accel_group_start_element,
12417 style_start_element (GMarkupParseContext *context,
12418 const gchar *element_name,
12419 const gchar **names,
12420 const gchar **values,
12421 gpointer user_data,
12424 StyleParserData *style_data = (StyleParserData *)user_data;
12427 if (strcmp (element_name, "class") == 0)
12429 if (g_markup_collect_attributes (element_name,
12433 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12434 G_MARKUP_COLLECT_INVALID))
12436 style_data->classes = g_slist_append (style_data->classes, class_name);
12439 else if (strcmp (element_name, "style") == 0)
12442 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12445 static const GMarkupParser style_parser =
12447 style_start_element,
12451 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12452 GtkBuilder *builder,
12454 const gchar *tagname,
12455 GMarkupParser *parser,
12458 g_assert (buildable);
12460 if (strcmp (tagname, "accelerator") == 0)
12462 AccelGroupParserData *parser_data;
12464 parser_data = g_slice_new0 (AccelGroupParserData);
12465 parser_data->object = g_object_ref (buildable);
12466 *parser = accel_group_parser;
12467 *data = parser_data;
12470 if (strcmp (tagname, "accessibility") == 0)
12472 AccessibilitySubParserData *parser_data;
12474 parser_data = g_slice_new0 (AccessibilitySubParserData);
12475 *parser = accessibility_parser;
12476 *data = parser_data;
12479 if (strcmp (tagname, "style") == 0)
12481 StyleParserData *parser_data;
12483 parser_data = g_slice_new0 (StyleParserData);
12484 *parser = style_parser;
12485 *data = parser_data;
12493 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12494 GtkWidget *toplevel,
12495 gpointer user_data)
12497 AccelGroupParserData *accel_data;
12498 GSList *accel_groups;
12499 GtkAccelGroup *accel_group;
12501 g_return_if_fail (GTK_IS_WIDGET (widget));
12502 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12503 g_return_if_fail (user_data != NULL);
12505 accel_data = (AccelGroupParserData*)user_data;
12506 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12507 if (g_slist_length (accel_groups) == 0)
12509 accel_group = gtk_accel_group_new ();
12510 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12514 g_assert (g_slist_length (accel_groups) == 1);
12515 accel_group = g_slist_nth_data (accel_groups, 0);
12518 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12519 accel_data->signal,
12522 accel_data->modifiers,
12523 GTK_ACCEL_VISIBLE);
12525 g_object_unref (accel_data->object);
12526 g_free (accel_data->signal);
12527 g_slice_free (AccelGroupParserData, accel_data);
12531 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12532 GtkBuilder *builder,
12534 const gchar *tagname,
12535 gpointer user_data)
12537 if (strcmp (tagname, "accelerator") == 0)
12539 AccelGroupParserData *accel_data;
12540 GtkWidget *toplevel;
12542 accel_data = (AccelGroupParserData*)user_data;
12543 g_assert (accel_data->object);
12545 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12547 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12549 else if (strcmp (tagname, "accessibility") == 0)
12551 AccessibilitySubParserData *a11y_data;
12553 a11y_data = (AccessibilitySubParserData*)user_data;
12555 if (a11y_data->actions)
12557 AtkObject *accessible;
12562 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12564 if (ATK_IS_ACTION (accessible))
12566 action = ATK_ACTION (accessible);
12567 n_actions = atk_action_get_n_actions (action);
12569 for (l = a11y_data->actions; l; l = l->next)
12571 AtkActionData *action_data = (AtkActionData*)l->data;
12573 for (i = 0; i < n_actions; i++)
12574 if (strcmp (atk_action_get_name (action, i),
12575 action_data->action_name) == 0)
12580 gchar *description;
12582 if (action_data->translatable && action_data->description->len)
12583 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12584 action_data->context,
12585 action_data->description->str);
12587 description = action_data->description->str;
12589 atk_action_set_description (action, i, description);
12594 g_warning ("accessibility action on a widget that does not implement AtkAction");
12596 g_slist_free_full (a11y_data->actions, (GDestroyNotify) free_action);
12599 if (a11y_data->relations)
12600 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12601 a11y_data->relations);
12603 g_slice_free (AccessibilitySubParserData, a11y_data);
12605 else if (strcmp (tagname, "style") == 0)
12607 StyleParserData *style_data = (StyleParserData *)user_data;
12608 GtkStyleContext *context;
12611 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
12613 for (l = style_data->classes; l; l = l->next)
12614 gtk_style_context_add_class (context, (const gchar *)l->data);
12616 gtk_widget_reset_style (GTK_WIDGET (buildable));
12618 g_slist_free_full (style_data->classes, g_free);
12619 g_slice_free (StyleParserData, style_data);
12623 static GtkSizeRequestMode
12624 gtk_widget_real_get_request_mode (GtkWidget *widget)
12626 /* By default widgets dont trade size at all. */
12627 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
12631 gtk_widget_real_get_width (GtkWidget *widget,
12632 gint *minimum_size,
12633 gint *natural_size)
12643 gtk_widget_real_get_height (GtkWidget *widget,
12644 gint *minimum_size,
12645 gint *natural_size)
12655 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12657 gint *minimum_height,
12658 gint *natural_height)
12660 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12664 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12666 gint *minimum_width,
12667 gint *natural_width)
12669 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12673 * gtk_widget_get_halign:
12674 * @widget: a #GtkWidget
12676 * Gets the value of the #GtkWidget:halign property.
12678 * Returns: the horizontal alignment of @widget
12681 gtk_widget_get_halign (GtkWidget *widget)
12683 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12684 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12688 * gtk_widget_set_halign:
12689 * @widget: a #GtkWidget
12690 * @align: the horizontal alignment
12692 * Sets the horizontal alignment of @widget.
12693 * See the #GtkWidget:halign property.
12696 gtk_widget_set_halign (GtkWidget *widget,
12699 GtkWidgetAuxInfo *aux_info;
12701 g_return_if_fail (GTK_IS_WIDGET (widget));
12703 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12705 if (aux_info->halign == align)
12708 aux_info->halign = align;
12709 gtk_widget_queue_resize (widget);
12710 g_object_notify (G_OBJECT (widget), "halign");
12714 * gtk_widget_get_valign:
12715 * @widget: a #GtkWidget
12717 * Gets the value of the #GtkWidget:valign property.
12719 * Returns: the vertical alignment of @widget
12722 gtk_widget_get_valign (GtkWidget *widget)
12724 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12725 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12729 * gtk_widget_set_valign:
12730 * @widget: a #GtkWidget
12731 * @align: the vertical alignment
12733 * Sets the vertical alignment of @widget.
12734 * See the #GtkWidget:valign property.
12737 gtk_widget_set_valign (GtkWidget *widget,
12740 GtkWidgetAuxInfo *aux_info;
12742 g_return_if_fail (GTK_IS_WIDGET (widget));
12744 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12746 if (aux_info->valign == align)
12749 aux_info->valign = align;
12750 gtk_widget_queue_resize (widget);
12751 g_object_notify (G_OBJECT (widget), "valign");
12755 * gtk_widget_get_margin_left:
12756 * @widget: a #GtkWidget
12758 * Gets the value of the #GtkWidget:margin-left property.
12760 * Returns: The left margin of @widget
12765 gtk_widget_get_margin_left (GtkWidget *widget)
12767 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12769 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12773 * gtk_widget_set_margin_left:
12774 * @widget: a #GtkWidget
12775 * @margin: the left margin
12777 * Sets the left margin of @widget.
12778 * See the #GtkWidget:margin-left property.
12783 gtk_widget_set_margin_left (GtkWidget *widget,
12786 GtkWidgetAuxInfo *aux_info;
12788 g_return_if_fail (GTK_IS_WIDGET (widget));
12789 g_return_if_fail (margin <= G_MAXINT16);
12791 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12793 if (aux_info->margin.left == margin)
12796 aux_info->margin.left = margin;
12797 gtk_widget_queue_resize (widget);
12798 g_object_notify (G_OBJECT (widget), "margin-left");
12802 * gtk_widget_get_margin_right:
12803 * @widget: a #GtkWidget
12805 * Gets the value of the #GtkWidget:margin-right property.
12807 * Returns: The right margin of @widget
12812 gtk_widget_get_margin_right (GtkWidget *widget)
12814 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12816 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12820 * gtk_widget_set_margin_right:
12821 * @widget: a #GtkWidget
12822 * @margin: the right margin
12824 * Sets the right margin of @widget.
12825 * See the #GtkWidget:margin-right property.
12830 gtk_widget_set_margin_right (GtkWidget *widget,
12833 GtkWidgetAuxInfo *aux_info;
12835 g_return_if_fail (GTK_IS_WIDGET (widget));
12836 g_return_if_fail (margin <= G_MAXINT16);
12838 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12840 if (aux_info->margin.right == margin)
12843 aux_info->margin.right = margin;
12844 gtk_widget_queue_resize (widget);
12845 g_object_notify (G_OBJECT (widget), "margin-right");
12849 * gtk_widget_get_margin_top:
12850 * @widget: a #GtkWidget
12852 * Gets the value of the #GtkWidget:margin-top property.
12854 * Returns: The top margin of @widget
12859 gtk_widget_get_margin_top (GtkWidget *widget)
12861 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12863 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12867 * gtk_widget_set_margin_top:
12868 * @widget: a #GtkWidget
12869 * @margin: the top margin
12871 * Sets the top margin of @widget.
12872 * See the #GtkWidget:margin-top property.
12877 gtk_widget_set_margin_top (GtkWidget *widget,
12880 GtkWidgetAuxInfo *aux_info;
12882 g_return_if_fail (GTK_IS_WIDGET (widget));
12883 g_return_if_fail (margin <= G_MAXINT16);
12885 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12887 if (aux_info->margin.top == margin)
12890 aux_info->margin.top = margin;
12891 gtk_widget_queue_resize (widget);
12892 g_object_notify (G_OBJECT (widget), "margin-top");
12896 * gtk_widget_get_margin_bottom:
12897 * @widget: a #GtkWidget
12899 * Gets the value of the #GtkWidget:margin-bottom property.
12901 * Returns: The bottom margin of @widget
12906 gtk_widget_get_margin_bottom (GtkWidget *widget)
12908 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12910 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
12914 * gtk_widget_set_margin_bottom:
12915 * @widget: a #GtkWidget
12916 * @margin: the bottom margin
12918 * Sets the bottom margin of @widget.
12919 * See the #GtkWidget:margin-bottom property.
12924 gtk_widget_set_margin_bottom (GtkWidget *widget,
12927 GtkWidgetAuxInfo *aux_info;
12929 g_return_if_fail (GTK_IS_WIDGET (widget));
12930 g_return_if_fail (margin <= G_MAXINT16);
12932 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12934 if (aux_info->margin.bottom == margin)
12937 aux_info->margin.bottom = margin;
12938 gtk_widget_queue_resize (widget);
12939 g_object_notify (G_OBJECT (widget), "margin-bottom");
12943 * gtk_widget_get_clipboard:
12944 * @widget: a #GtkWidget
12945 * @selection: a #GdkAtom which identifies the clipboard
12946 * to use. %GDK_SELECTION_CLIPBOARD gives the
12947 * default clipboard. Another common value
12948 * is %GDK_SELECTION_PRIMARY, which gives
12949 * the primary X selection.
12951 * Returns the clipboard object for the given selection to
12952 * be used with @widget. @widget must have a #GdkDisplay
12953 * associated with it, so must be attached to a toplevel
12956 * Return value: (transfer none): the appropriate clipboard object. If no
12957 * clipboard already exists, a new one will
12958 * be created. Once a clipboard object has
12959 * been created, it is persistent for all time.
12964 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
12966 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12967 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
12969 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
12974 * gtk_widget_list_mnemonic_labels:
12975 * @widget: a #GtkWidget
12977 * Returns a newly allocated list of the widgets, normally labels, for
12978 * which this widget is the target of a mnemonic (see for example,
12979 * gtk_label_set_mnemonic_widget()).
12981 * The widgets in the list are not individually referenced. If you
12982 * want to iterate through the list and perform actions involving
12983 * callbacks that might destroy the widgets, you
12984 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
12985 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
12986 * widgets afterwards.
12988 * Return value: (element-type GtkWidget) (transfer container): the list of
12989 * mnemonic labels; free this list
12990 * with g_list_free() when you are done with it.
12995 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
12997 GList *list = NULL;
13000 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13002 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13003 list = g_list_prepend (list, l->data);
13009 * gtk_widget_add_mnemonic_label:
13010 * @widget: a #GtkWidget
13011 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13013 * Adds a widget to the list of mnemonic labels for
13014 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13015 * list of mnemonic labels for the widget is cleared when the
13016 * widget is destroyed, so the caller must make sure to update
13017 * its internal state at this point as well, by using a connection
13018 * to the #GtkWidget::destroy signal or a weak notifier.
13023 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13026 GSList *old_list, *new_list;
13028 g_return_if_fail (GTK_IS_WIDGET (widget));
13029 g_return_if_fail (GTK_IS_WIDGET (label));
13031 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13032 new_list = g_slist_prepend (old_list, label);
13034 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13035 new_list, (GDestroyNotify) g_slist_free);
13039 * gtk_widget_remove_mnemonic_label:
13040 * @widget: a #GtkWidget
13041 * @label: a #GtkWidget that was previously set as a mnemnic label for
13042 * @widget with gtk_widget_add_mnemonic_label().
13044 * Removes a widget from the list of mnemonic labels for
13045 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13046 * must have previously been added to the list with
13047 * gtk_widget_add_mnemonic_label().
13052 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13055 GSList *old_list, *new_list;
13057 g_return_if_fail (GTK_IS_WIDGET (widget));
13058 g_return_if_fail (GTK_IS_WIDGET (label));
13060 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13061 new_list = g_slist_remove (old_list, label);
13064 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13065 new_list, (GDestroyNotify) g_slist_free);
13069 * gtk_widget_get_no_show_all:
13070 * @widget: a #GtkWidget
13072 * Returns the current value of the #GtkWidget:no-show-all property,
13073 * which determines whether calls to gtk_widget_show_all()
13074 * will affect this widget.
13076 * Return value: the current value of the "no-show-all" property.
13081 gtk_widget_get_no_show_all (GtkWidget *widget)
13083 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13085 return widget->priv->no_show_all;
13089 * gtk_widget_set_no_show_all:
13090 * @widget: a #GtkWidget
13091 * @no_show_all: the new value for the "no-show-all" property
13093 * Sets the #GtkWidget:no-show-all property, which determines whether
13094 * calls to gtk_widget_show_all() will affect this widget.
13096 * This is mostly for use in constructing widget hierarchies with externally
13097 * controlled visibility, see #GtkUIManager.
13102 gtk_widget_set_no_show_all (GtkWidget *widget,
13103 gboolean no_show_all)
13105 g_return_if_fail (GTK_IS_WIDGET (widget));
13107 no_show_all = (no_show_all != FALSE);
13109 if (widget->priv->no_show_all != no_show_all)
13111 widget->priv->no_show_all = no_show_all;
13113 g_object_notify (G_OBJECT (widget), "no-show-all");
13119 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13120 gboolean has_tooltip,
13123 GtkWidgetPrivate *priv = widget->priv;
13124 gboolean priv_has_tooltip;
13126 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13127 quark_has_tooltip));
13129 if (priv_has_tooltip != has_tooltip || force)
13131 priv_has_tooltip = has_tooltip;
13133 if (priv_has_tooltip)
13135 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13136 gdk_window_set_events (priv->window,
13137 gdk_window_get_events (priv->window) |
13138 GDK_LEAVE_NOTIFY_MASK |
13139 GDK_POINTER_MOTION_MASK |
13140 GDK_POINTER_MOTION_HINT_MASK);
13142 if (gtk_widget_get_has_window (widget))
13143 gtk_widget_add_events (widget,
13144 GDK_LEAVE_NOTIFY_MASK |
13145 GDK_POINTER_MOTION_MASK |
13146 GDK_POINTER_MOTION_HINT_MASK);
13149 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13150 GUINT_TO_POINTER (priv_has_tooltip));
13155 * gtk_widget_set_tooltip_window:
13156 * @widget: a #GtkWidget
13157 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13159 * Replaces the default, usually yellow, window used for displaying
13160 * tooltips with @custom_window. GTK+ will take care of showing and
13161 * hiding @custom_window at the right moment, to behave likewise as
13162 * the default tooltip window. If @custom_window is %NULL, the default
13163 * tooltip window will be used.
13165 * If the custom window should have the default theming it needs to
13166 * have the name "gtk-tooltip", see gtk_widget_set_name().
13171 gtk_widget_set_tooltip_window (GtkWidget *widget,
13172 GtkWindow *custom_window)
13174 gboolean has_tooltip;
13175 gchar *tooltip_markup;
13177 g_return_if_fail (GTK_IS_WIDGET (widget));
13178 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13180 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13183 g_object_ref (custom_window);
13185 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13186 custom_window, g_object_unref);
13188 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13189 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13191 if (has_tooltip && gtk_widget_get_visible (widget))
13192 gtk_widget_queue_tooltip_query (widget);
13196 * gtk_widget_get_tooltip_window:
13197 * @widget: a #GtkWidget
13199 * Returns the #GtkWindow of the current tooltip. This can be the
13200 * GtkWindow created by default, or the custom tooltip window set
13201 * using gtk_widget_set_tooltip_window().
13203 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13208 gtk_widget_get_tooltip_window (GtkWidget *widget)
13210 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13212 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13216 * gtk_widget_trigger_tooltip_query:
13217 * @widget: a #GtkWidget
13219 * Triggers a tooltip query on the display where the toplevel of @widget
13220 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13226 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13228 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13231 static guint tooltip_query_id;
13232 static GSList *tooltip_query_displays;
13235 tooltip_query_idle (gpointer data)
13237 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13238 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13239 g_slist_free (tooltip_query_displays);
13241 tooltip_query_displays = NULL;
13242 tooltip_query_id = 0;
13248 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13250 GdkDisplay *display;
13252 display = gtk_widget_get_display (widget);
13254 if (!g_slist_find (tooltip_query_displays, display))
13255 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13257 if (tooltip_query_id == 0)
13258 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13262 * gtk_widget_set_tooltip_text:
13263 * @widget: a #GtkWidget
13264 * @text: the contents of the tooltip for @widget
13266 * Sets @text as the contents of the tooltip. This function will take
13267 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13268 * handler for the #GtkWidget::query-tooltip signal.
13270 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13275 gtk_widget_set_tooltip_text (GtkWidget *widget,
13278 g_return_if_fail (GTK_IS_WIDGET (widget));
13280 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13284 * gtk_widget_get_tooltip_text:
13285 * @widget: a #GtkWidget
13287 * Gets the contents of the tooltip for @widget.
13289 * Return value: the tooltip text, or %NULL. You should free the
13290 * returned string with g_free() when done.
13295 gtk_widget_get_tooltip_text (GtkWidget *widget)
13297 gchar *text = NULL;
13299 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13301 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13307 * gtk_widget_set_tooltip_markup:
13308 * @widget: a #GtkWidget
13309 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13311 * Sets @markup as the contents of the tooltip, which is marked up with
13312 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13314 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13315 * and of the default handler for the #GtkWidget::query-tooltip signal.
13317 * See also the #GtkWidget:tooltip-markup property and
13318 * gtk_tooltip_set_markup().
13323 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13324 const gchar *markup)
13326 g_return_if_fail (GTK_IS_WIDGET (widget));
13328 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13332 * gtk_widget_get_tooltip_markup:
13333 * @widget: a #GtkWidget
13335 * Gets the contents of the tooltip for @widget.
13337 * Return value: the tooltip text, or %NULL. You should free the
13338 * returned string with g_free() when done.
13343 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13345 gchar *text = NULL;
13347 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13349 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13355 * gtk_widget_set_has_tooltip:
13356 * @widget: a #GtkWidget
13357 * @has_tooltip: whether or not @widget has a tooltip.
13359 * Sets the has-tooltip property on @widget to @has_tooltip. See
13360 * #GtkWidget:has-tooltip for more information.
13365 gtk_widget_set_has_tooltip (GtkWidget *widget,
13366 gboolean has_tooltip)
13368 g_return_if_fail (GTK_IS_WIDGET (widget));
13370 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13374 * gtk_widget_get_has_tooltip:
13375 * @widget: a #GtkWidget
13377 * Returns the current value of the has-tooltip property. See
13378 * #GtkWidget:has-tooltip for more information.
13380 * Return value: current value of has-tooltip on @widget.
13385 gtk_widget_get_has_tooltip (GtkWidget *widget)
13387 gboolean has_tooltip = FALSE;
13389 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13391 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13393 return has_tooltip;
13397 * gtk_widget_get_allocation:
13398 * @widget: a #GtkWidget
13399 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13401 * Retrieves the widget's allocation.
13403 * Note, when implementing a #GtkContainer: a widget's allocation will
13404 * be its "adjusted" allocation, that is, the widget's parent
13405 * container typically calls gtk_widget_size_allocate() with an
13406 * allocation, and that allocation is then adjusted (to handle margin
13407 * and alignment for example) before assignment to the widget.
13408 * gtk_widget_get_allocation() returns the adjusted allocation that
13409 * was actually assigned to the widget. The adjusted allocation is
13410 * guaranteed to be completely contained within the
13411 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13412 * is guaranteed that its children stay inside the assigned bounds,
13413 * but not that they have exactly the bounds the container assigned.
13414 * There is no way to get the original allocation assigned by
13415 * gtk_widget_size_allocate(), since it isn't stored; if a container
13416 * implementation needs that information it will have to track it itself.
13421 gtk_widget_get_allocation (GtkWidget *widget,
13422 GtkAllocation *allocation)
13424 GtkWidgetPrivate *priv;
13426 g_return_if_fail (GTK_IS_WIDGET (widget));
13427 g_return_if_fail (allocation != NULL);
13429 priv = widget->priv;
13431 *allocation = priv->allocation;
13435 * gtk_widget_set_allocation:
13436 * @widget: a #GtkWidget
13437 * @allocation: a pointer to a #GtkAllocation to copy from
13439 * Sets the widget's allocation. This should not be used
13440 * directly, but from within a widget's size_allocate method.
13442 * The allocation set should be the "adjusted" or actual
13443 * allocation. If you're implementing a #GtkContainer, you want to use
13444 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13445 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13446 * allocation inside gtk_widget_size_allocate() to create an adjusted
13452 gtk_widget_set_allocation (GtkWidget *widget,
13453 const GtkAllocation *allocation)
13455 GtkWidgetPrivate *priv;
13457 g_return_if_fail (GTK_IS_WIDGET (widget));
13458 g_return_if_fail (allocation != NULL);
13460 priv = widget->priv;
13462 priv->allocation = *allocation;
13466 * gtk_widget_get_allocated_width:
13467 * @widget: the widget to query
13469 * Returns the width that has currently been allocated to @widget.
13470 * This function is intended to be used when implementing handlers
13471 * for the #GtkWidget::draw function.
13473 * Returns: the width of the @widget
13476 gtk_widget_get_allocated_width (GtkWidget *widget)
13478 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13480 return widget->priv->allocation.width;
13484 * gtk_widget_get_allocated_height:
13485 * @widget: the widget to query
13487 * Returns the height that has currently been allocated to @widget.
13488 * This function is intended to be used when implementing handlers
13489 * for the #GtkWidget::draw function.
13491 * Returns: the height of the @widget
13494 gtk_widget_get_allocated_height (GtkWidget *widget)
13496 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13498 return widget->priv->allocation.height;
13502 * gtk_widget_get_requisition:
13503 * @widget: a #GtkWidget
13504 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13506 * Retrieves the widget's requisition.
13508 * This function should only be used by widget implementations in
13509 * order to figure whether the widget's requisition has actually
13510 * changed after some internal state change (so that they can call
13511 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13513 * Normally, gtk_widget_size_request() should be used.
13517 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13518 * removed, If you need to cache sizes across requests and allocations,
13519 * add an explicit cache to the widget in question instead.
13522 gtk_widget_get_requisition (GtkWidget *widget,
13523 GtkRequisition *requisition)
13525 g_return_if_fail (GTK_IS_WIDGET (widget));
13526 g_return_if_fail (requisition != NULL);
13528 gtk_widget_get_preferred_size (widget, requisition, NULL);
13532 * gtk_widget_set_window:
13533 * @widget: a #GtkWidget
13534 * @window: (transfer full): a #GdkWindow
13536 * Sets a widget's window. This function should only be used in a
13537 * widget's #GtkWidget::realize implementation. The %window passed is
13538 * usually either new window created with gdk_window_new(), or the
13539 * window of its parent widget as returned by
13540 * gtk_widget_get_parent_window().
13542 * Widgets must indicate whether they will create their own #GdkWindow
13543 * by calling gtk_widget_set_has_window(). This is usually done in the
13544 * widget's init() function.
13546 * <note><para>This function does not add any reference to @window.</para></note>
13551 gtk_widget_set_window (GtkWidget *widget,
13554 GtkWidgetPrivate *priv;
13556 g_return_if_fail (GTK_IS_WIDGET (widget));
13557 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13559 priv = widget->priv;
13561 if (priv->window != window)
13563 priv->window = window;
13564 g_object_notify (G_OBJECT (widget), "window");
13569 * gtk_widget_get_window:
13570 * @widget: a #GtkWidget
13572 * Returns the widget's window if it is realized, %NULL otherwise
13574 * Return value: (transfer none): @widget's window.
13579 gtk_widget_get_window (GtkWidget *widget)
13581 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13583 return widget->priv->window;
13587 * gtk_widget_get_support_multidevice:
13588 * @widget: a #GtkWidget
13590 * Returns %TRUE if @widget is multiple pointer aware. See
13591 * gtk_widget_set_support_multidevice() for more information.
13593 * Returns: %TRUE if @widget is multidevice aware.
13596 gtk_widget_get_support_multidevice (GtkWidget *widget)
13598 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13600 return widget->priv->multidevice;
13604 * gtk_widget_set_support_multidevice:
13605 * @widget: a #GtkWidget
13606 * @support_multidevice: %TRUE to support input from multiple devices.
13608 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13609 * @widget will start receiving multiple, per device enter/leave events. Note
13610 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13611 * gdk_window_set_support_multidevice() will have to be called manually on them.
13616 gtk_widget_set_support_multidevice (GtkWidget *widget,
13617 gboolean support_multidevice)
13619 GtkWidgetPrivate *priv;
13621 g_return_if_fail (GTK_IS_WIDGET (widget));
13623 priv = widget->priv;
13624 priv->multidevice = (support_multidevice == TRUE);
13626 if (gtk_widget_get_realized (widget))
13627 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13631 _gtk_widget_set_has_focus (GtkWidget *widget,
13632 gboolean has_focus)
13634 widget->priv->has_focus = has_focus;
13637 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
13639 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
13643 * gtk_widget_send_focus_change:
13644 * @widget: a #GtkWidget
13645 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13647 * Sends the focus change @event to @widget
13649 * This function is not meant to be used by applications. The only time it
13650 * should be used is when it is necessary for a #GtkWidget to assign focus
13651 * to a widget that is semantically owned by the first widget even though
13652 * it's not a direct child - for instance, a search entry in a floating
13653 * window similar to the quick search in #GtkTreeView.
13655 * An example of its usage is:
13658 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13660 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13661 * fevent->focus_change.in = TRUE;
13662 * fevent->focus_change.window = gtk_widget_get_window (widget);
13663 * if (fevent->focus_change.window != NULL)
13664 * g_object_ref (fevent->focus_change.window);
13666 * gtk_widget_send_focus_change (widget, fevent);
13668 * gdk_event_free (event);
13671 * Return value: the return value from the event signal emission: %TRUE
13672 * if the event was handled, and %FALSE otherwise
13677 gtk_widget_send_focus_change (GtkWidget *widget,
13682 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13683 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13685 g_object_ref (widget);
13687 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13689 res = gtk_widget_event (widget, event);
13691 g_object_notify (G_OBJECT (widget), "has-focus");
13693 g_object_unref (widget);
13699 * gtk_widget_in_destruction:
13700 * @widget: a #GtkWidget
13702 * Returns whether the widget is currently being destroyed.
13703 * This information can sometimes be used to avoid doing
13704 * unnecessary work.
13706 * Returns: %TRUE if @widget is being destroyed
13709 gtk_widget_in_destruction (GtkWidget *widget)
13711 return widget->priv->in_destruction;
13715 _gtk_widget_get_in_reparent (GtkWidget *widget)
13717 return widget->priv->in_reparent;
13721 _gtk_widget_set_in_reparent (GtkWidget *widget,
13722 gboolean in_reparent)
13724 widget->priv->in_reparent = in_reparent;
13728 _gtk_widget_get_anchored (GtkWidget *widget)
13730 return widget->priv->anchored;
13734 _gtk_widget_set_anchored (GtkWidget *widget,
13737 widget->priv->anchored = anchored;
13741 _gtk_widget_get_shadowed (GtkWidget *widget)
13743 return widget->priv->shadowed;
13747 _gtk_widget_set_shadowed (GtkWidget *widget,
13750 widget->priv->shadowed = shadowed;
13754 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13756 return widget->priv->alloc_needed;
13760 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13761 gboolean alloc_needed)
13763 widget->priv->alloc_needed = alloc_needed;
13767 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13769 return widget->priv->width_request_needed;
13773 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13774 gboolean width_request_needed)
13776 widget->priv->width_request_needed = width_request_needed;
13780 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13782 return widget->priv->height_request_needed;
13786 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13787 gboolean height_request_needed)
13789 widget->priv->height_request_needed = height_request_needed;
13793 _gtk_widget_get_sizegroup_visited (GtkWidget *widget)
13795 return widget->priv->sizegroup_visited;
13799 _gtk_widget_set_sizegroup_visited (GtkWidget *widget,
13802 widget->priv->sizegroup_visited = visited;
13806 _gtk_widget_get_sizegroup_bumping (GtkWidget *widget)
13808 return widget->priv->sizegroup_bumping;
13812 _gtk_widget_set_sizegroup_bumping (GtkWidget *widget,
13815 widget->priv->sizegroup_bumping = bumping;
13819 _gtk_widget_add_sizegroup (GtkWidget *widget,
13824 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13825 groups = g_slist_prepend (groups, group);
13826 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13828 widget->priv->have_size_groups = TRUE;
13832 _gtk_widget_remove_sizegroup (GtkWidget *widget,
13837 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13838 groups = g_slist_remove (groups, group);
13839 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13841 widget->priv->have_size_groups = groups != NULL;
13845 _gtk_widget_get_sizegroups (GtkWidget *widget)
13847 if (widget->priv->have_size_groups)
13848 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13854 _gtk_widget_add_attached_window (GtkWidget *widget,
13857 widget->priv->attached_windows = g_list_prepend (widget->priv->attached_windows, window);
13861 _gtk_widget_remove_attached_window (GtkWidget *widget,
13864 widget->priv->attached_windows = g_list_remove (widget->priv->attached_windows, window);
13868 * gtk_widget_path_append_for_widget:
13869 * @path: a widget path
13870 * @widget: the widget to append to the widget path
13872 * Appends the data from @widget to the widget hierarchy represented
13873 * by @path. This function is a shortcut for adding information from
13874 * @widget to the given @path. This includes setting the name or
13875 * adding the style classes from @widget.
13877 * Returns: the position where the data was inserted
13882 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
13887 g_return_val_if_fail (path != NULL, 0);
13888 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13890 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
13892 if (widget->priv->name)
13893 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
13895 if (widget->priv->context)
13897 GList *classes, *l;
13899 /* Also add any persistent classes in
13900 * the style context the widget path
13902 classes = gtk_style_context_list_classes (widget->priv->context);
13904 for (l = classes; l; l = l->next)
13905 gtk_widget_path_iter_add_class (path, pos, l->data);
13907 g_list_free (classes);
13914 _gtk_widget_create_path (GtkWidget *widget)
13918 parent = widget->priv->parent;
13921 return gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
13924 /* Widget is either toplevel or unparented, treat both
13925 * as toplevels style wise, since there are situations
13926 * where style properties might be retrieved on that
13929 GtkWidget *attach_widget = NULL;
13930 GtkWidgetPath *result;
13932 if (GTK_IS_WINDOW (widget))
13933 attach_widget = gtk_window_get_attached_to (GTK_WINDOW (widget));
13935 if (attach_widget != NULL)
13936 result = gtk_widget_path_copy (gtk_widget_get_path (attach_widget));
13938 result = gtk_widget_path_new ();
13940 gtk_widget_path_append_for_widget (result, widget);
13947 * gtk_widget_get_path:
13948 * @widget: a #GtkWidget
13950 * Returns the #GtkWidgetPath representing @widget, if the widget
13951 * is not connected to a toplevel widget, a partial path will be
13954 * Returns: (transfer none): The #GtkWidgetPath representing @widget
13957 gtk_widget_get_path (GtkWidget *widget)
13959 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13961 if (!widget->priv->path)
13962 widget->priv->path = _gtk_widget_create_path (widget);
13964 return widget->priv->path;
13968 _gtk_widget_style_context_invalidated (GtkWidget *widget)
13970 if (widget->priv->path)
13972 gtk_widget_path_free (widget->priv->path);
13973 widget->priv->path = NULL;
13976 if (gtk_widget_get_realized (widget))
13977 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
13980 /* Compress all style updates so it
13981 * is only emitted once pre-realize.
13983 widget->priv->style_update_pending = TRUE;
13986 if (widget->priv->anchored)
13987 gtk_widget_queue_resize (widget);
13991 * gtk_widget_get_style_context:
13992 * @widget: a #GtkWidget
13994 * Returns the style context associated to @widget.
13996 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
13997 * must not be freed.
14000 gtk_widget_get_style_context (GtkWidget *widget)
14002 GtkWidgetPrivate *priv;
14004 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14006 priv = widget->priv;
14008 if (G_UNLIKELY (priv->context == NULL))
14012 priv->context = gtk_style_context_new ();
14014 gtk_style_context_set_direction (priv->context, gtk_widget_get_direction (widget));
14016 screen = gtk_widget_get_screen (widget);
14018 gtk_style_context_set_screen (priv->context, screen);
14021 gtk_style_context_set_parent (priv->context,
14022 gtk_widget_get_style_context (priv->parent));
14024 _gtk_style_context_set_widget (priv->context, widget);
14027 return widget->priv->context;
14031 _gtk_widget_invalidate_style_context (GtkWidget *widget,
14032 GtkCssChange change)
14034 GtkWidgetPrivate *priv;
14036 priv = widget->priv;
14038 if (priv->context == NULL)
14041 _gtk_style_context_queue_invalidate (priv->context, change);
14045 * gtk_widget_get_modifier_mask:
14046 * @widget: a #GtkWidget
14047 * @intent: the use case for the modifier mask
14049 * Returns the modifier mask the @widget's windowing system backend
14050 * uses for a particular purpose.
14052 * See gdk_keymap_get_modifier_mask().
14054 * Returns: the modifier mask used for @intent.
14059 gtk_widget_get_modifier_mask (GtkWidget *widget,
14060 GdkModifierIntent intent)
14062 GdkDisplay *display;
14064 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14066 display = gtk_widget_get_display (widget);
14068 return gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
14073 _gtk_widget_get_style (GtkWidget *widget)
14075 return widget->priv->style;
14079 _gtk_widget_set_style (GtkWidget *widget,
14082 widget->priv->style = style;
14086 _gtk_widget_update_parent_muxer (GtkWidget *widget)
14089 GActionMuxer *parent_muxer;
14091 if (widget->priv->muxer == NULL)
14094 if (GTK_IS_MENU (widget))
14095 parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
14097 parent = gtk_widget_get_parent (widget);
14099 parent_muxer = parent ? _gtk_widget_get_action_muxer (parent) : NULL;
14101 g_action_muxer_set_parent (widget->priv->muxer, parent_muxer);
14105 _gtk_widget_get_action_muxer (GtkWidget *widget)
14107 if (widget->priv->muxer == NULL)
14109 widget->priv->muxer = g_action_muxer_new ();
14110 _gtk_widget_update_parent_muxer (widget);
14113 return widget->priv->muxer;
14117 * gtk_widget_insert_action_group:
14118 * @widget: a #GtkWidget
14119 * @name: the prefix for actions in @group
14120 * @group: a #GActionGroup
14122 * Inserts @group into @widget. Children of @widget that implement
14123 * #GtkActionable can then be associated with actions in @group by
14124 * setting their 'action-name' to
14125 * @prefix.<replaceable>action-name</replaceable>.
14130 gtk_widget_insert_action_group (GtkWidget *widget,
14132 GActionGroup *group)
14134 GActionMuxer *muxer;
14136 g_return_if_fail (GTK_IS_WIDGET (widget));
14137 g_return_if_fail (name != NULL);
14139 muxer = _gtk_widget_get_action_muxer (widget);
14142 g_action_muxer_insert (muxer, name, group);
14144 g_action_muxer_remove (muxer, name);