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 gtk_widget_class_install_style_property (klass,
3296 g_param_spec_int ("text-handle-width",
3297 P_("Width of text selection handles"),
3298 P_("Width of text selection handles"),
3300 GTK_PARAM_READABLE));
3301 gtk_widget_class_install_style_property (klass,
3302 g_param_spec_int ("text-handle-height",
3303 P_("Height of text selection handles"),
3304 P_("Height of text selection handles"),
3306 GTK_PARAM_READABLE));
3308 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3310 gtk_widget_class_set_accessible_type (klass, GTK_TYPE_WIDGET_ACCESSIBLE);
3314 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3318 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3319 for (node = list; node; node = node->next)
3321 GParamSpec *pspec = node->data;
3323 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3324 g_param_spec_unref (pspec);
3330 gtk_widget_set_property (GObject *object,
3332 const GValue *value,
3335 GtkWidget *widget = GTK_WIDGET (object);
3340 gchar *tooltip_markup;
3341 const gchar *tooltip_text;
3342 GtkWindow *tooltip_window;
3345 gtk_widget_set_name (widget, g_value_get_string (value));
3348 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3350 case PROP_WIDTH_REQUEST:
3351 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3353 case PROP_HEIGHT_REQUEST:
3354 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3357 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3359 case PROP_SENSITIVE:
3360 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3362 case PROP_APP_PAINTABLE:
3363 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3365 case PROP_CAN_FOCUS:
3366 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3368 case PROP_HAS_FOCUS:
3369 if (g_value_get_boolean (value))
3370 gtk_widget_grab_focus (widget);
3373 if (g_value_get_boolean (value))
3374 gtk_widget_grab_focus (widget);
3376 case PROP_CAN_DEFAULT:
3377 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3379 case PROP_HAS_DEFAULT:
3380 if (g_value_get_boolean (value))
3381 gtk_widget_grab_default (widget);
3383 case PROP_RECEIVES_DEFAULT:
3384 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3387 gtk_widget_set_style (widget, g_value_get_object (value));
3390 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3391 gtk_widget_set_events (widget, g_value_get_flags (value));
3393 case PROP_NO_SHOW_ALL:
3394 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3396 case PROP_HAS_TOOLTIP:
3397 gtk_widget_real_set_has_tooltip (widget,
3398 g_value_get_boolean (value), FALSE);
3400 case PROP_TOOLTIP_MARKUP:
3401 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3402 tooltip_markup = g_value_dup_string (value);
3404 /* Treat an empty string as a NULL string,
3405 * because an empty string would be useless for a tooltip:
3407 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3409 g_free (tooltip_markup);
3410 tooltip_markup = NULL;
3413 g_object_set_qdata_full (object, quark_tooltip_markup,
3414 tooltip_markup, g_free);
3416 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3417 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3418 if (gtk_widget_get_visible (widget))
3419 gtk_widget_queue_tooltip_query (widget);
3421 case PROP_TOOLTIP_TEXT:
3422 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3424 tooltip_text = g_value_get_string (value);
3426 /* Treat an empty string as a NULL string,
3427 * because an empty string would be useless for a tooltip:
3429 if (tooltip_text && (strlen (tooltip_text) == 0))
3430 tooltip_text = NULL;
3432 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3434 g_object_set_qdata_full (object, quark_tooltip_markup,
3435 tooltip_markup, g_free);
3437 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3438 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3439 if (gtk_widget_get_visible (widget))
3440 gtk_widget_queue_tooltip_query (widget);
3442 case PROP_DOUBLE_BUFFERED:
3443 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3446 gtk_widget_set_halign (widget, g_value_get_enum (value));
3449 gtk_widget_set_valign (widget, g_value_get_enum (value));
3451 case PROP_MARGIN_LEFT:
3452 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3454 case PROP_MARGIN_RIGHT:
3455 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3457 case PROP_MARGIN_TOP:
3458 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3460 case PROP_MARGIN_BOTTOM:
3461 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3464 g_object_freeze_notify (G_OBJECT (widget));
3465 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3466 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3467 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3468 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3469 g_object_thaw_notify (G_OBJECT (widget));
3472 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3474 case PROP_HEXPAND_SET:
3475 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3478 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3480 case PROP_VEXPAND_SET:
3481 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3484 g_object_freeze_notify (G_OBJECT (widget));
3485 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3486 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3487 g_object_thaw_notify (G_OBJECT (widget));
3490 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3496 gtk_widget_get_property (GObject *object,
3501 GtkWidget *widget = GTK_WIDGET (object);
3502 GtkWidgetPrivate *priv = widget->priv;
3510 g_value_set_string (value, priv->name);
3512 g_value_set_static_string (value, "");
3515 g_value_set_object (value, priv->parent);
3517 case PROP_WIDTH_REQUEST:
3520 gtk_widget_get_size_request (widget, &w, NULL);
3521 g_value_set_int (value, w);
3524 case PROP_HEIGHT_REQUEST:
3527 gtk_widget_get_size_request (widget, NULL, &h);
3528 g_value_set_int (value, h);
3532 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3534 case PROP_SENSITIVE:
3535 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3537 case PROP_APP_PAINTABLE:
3538 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3540 case PROP_CAN_FOCUS:
3541 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3543 case PROP_HAS_FOCUS:
3544 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3547 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3549 case PROP_CAN_DEFAULT:
3550 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3552 case PROP_HAS_DEFAULT:
3553 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3555 case PROP_RECEIVES_DEFAULT:
3556 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3558 case PROP_COMPOSITE_CHILD:
3559 g_value_set_boolean (value, widget->priv->composite_child);
3562 g_value_set_object (value, gtk_widget_get_style (widget));
3565 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3566 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3568 case PROP_NO_SHOW_ALL:
3569 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3571 case PROP_HAS_TOOLTIP:
3572 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3574 case PROP_TOOLTIP_TEXT:
3576 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3579 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3580 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3582 g_value_take_string (value, text);
3585 case PROP_TOOLTIP_MARKUP:
3586 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3589 g_value_set_object (value, gtk_widget_get_window (widget));
3591 case PROP_DOUBLE_BUFFERED:
3592 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3595 g_value_set_enum (value, gtk_widget_get_halign (widget));
3598 g_value_set_enum (value, gtk_widget_get_valign (widget));
3600 case PROP_MARGIN_LEFT:
3601 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3603 case PROP_MARGIN_RIGHT:
3604 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3606 case PROP_MARGIN_TOP:
3607 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3609 case PROP_MARGIN_BOTTOM:
3610 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3614 GtkWidgetAuxInfo *aux_info = gtk_widget_get_aux_info (widget, FALSE);
3615 if (aux_info == NULL)
3617 g_value_set_int (value, 0);
3621 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3622 aux_info->margin.right),
3623 MAX (aux_info->margin.top,
3624 aux_info->margin.bottom)));
3629 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3631 case PROP_HEXPAND_SET:
3632 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3635 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3637 case PROP_VEXPAND_SET:
3638 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3641 g_value_set_boolean (value,
3642 gtk_widget_get_hexpand (widget) &&
3643 gtk_widget_get_vexpand (widget));
3646 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3652 gtk_widget_init (GtkWidget *widget)
3654 GtkWidgetPrivate *priv;
3656 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3659 priv = widget->priv;
3661 priv->child_visible = TRUE;
3663 priv->allocation.x = -1;
3664 priv->allocation.y = -1;
3665 priv->allocation.width = 1;
3666 priv->allocation.height = 1;
3667 priv->window = NULL;
3668 priv->parent = NULL;
3670 priv->sensitive = TRUE;
3671 priv->composite_child = composite_child_stack != 0;
3672 priv->double_buffered = TRUE;
3673 priv->redraw_on_alloc = TRUE;
3674 priv->width_request_needed = TRUE;
3675 priv->height_request_needed = TRUE;
3676 priv->alloc_needed = TRUE;
3678 /* this will be set to TRUE if the widget gets a child or if the
3679 * expand flag is set on the widget, but until one of those happen
3680 * we know the expand is already properly FALSE.
3682 * We really want to default FALSE here to avoid computing expand
3683 * all over the place while initially building a widget tree.
3685 priv->need_compute_expand = FALSE;
3687 priv->style = gtk_widget_get_default_style ();
3688 g_object_ref (priv->style);
3693 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3695 GParamSpec **pspecs)
3697 GtkWidgetPrivate *priv = widget->priv;
3698 GtkWidget *container = priv->parent;
3701 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3702 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3706 * gtk_widget_freeze_child_notify:
3707 * @widget: a #GtkWidget
3709 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3710 * signals are queued until gtk_widget_thaw_child_notify() is called
3713 * This is the analogue of g_object_freeze_notify() for child properties.
3716 gtk_widget_freeze_child_notify (GtkWidget *widget)
3718 g_return_if_fail (GTK_IS_WIDGET (widget));
3720 if (!G_OBJECT (widget)->ref_count)
3723 g_object_ref (widget);
3724 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3725 g_object_unref (widget);
3729 * gtk_widget_child_notify:
3730 * @widget: a #GtkWidget
3731 * @child_property: the name of a child property installed on the
3732 * class of @widget<!-- -->'s parent
3734 * Emits a #GtkWidget::child-notify signal for the
3735 * <link linkend="child-properties">child property</link> @child_property
3738 * This is the analogue of g_object_notify() for child properties.
3740 * Also see gtk_container_child_notify().
3743 gtk_widget_child_notify (GtkWidget *widget,
3744 const gchar *child_property)
3746 if (widget->priv->parent == NULL)
3749 gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
3753 * gtk_widget_thaw_child_notify:
3754 * @widget: a #GtkWidget
3756 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3757 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3761 gtk_widget_thaw_child_notify (GtkWidget *widget)
3763 GObjectNotifyQueue *nqueue;
3765 g_return_if_fail (GTK_IS_WIDGET (widget));
3767 if (!G_OBJECT (widget)->ref_count)
3770 g_object_ref (widget);
3771 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3772 if (!nqueue || !nqueue->freeze_count)
3773 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3774 G_OBJECT_TYPE_NAME (widget), widget);
3776 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3777 g_object_unref (widget);
3783 * @type: type ID of the widget to create
3784 * @first_property_name: name of first property to set
3785 * @...: value of first property, followed by more properties,
3788 * This is a convenience function for creating a widget and setting
3789 * its properties in one go. For example you might write:
3790 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3791 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3792 * g_object_new(), but returns a widget so you don't have to
3793 * cast the object yourself.
3795 * Return value: a new #GtkWidget of type @widget_type
3798 gtk_widget_new (GType type,
3799 const gchar *first_property_name,
3805 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3807 va_start (var_args, first_property_name);
3808 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3815 gtk_widget_queue_draw_child (GtkWidget *widget)
3817 GtkWidgetPrivate *priv = widget->priv;
3820 parent = priv->parent;
3821 if (parent && gtk_widget_is_drawable (parent))
3822 gtk_widget_queue_draw_area (parent,
3825 priv->allocation.width,
3826 priv->allocation.height);
3830 * gtk_widget_unparent:
3831 * @widget: a #GtkWidget
3833 * This function is only for use in widget implementations.
3834 * Should be called by implementations of the remove method
3835 * on #GtkContainer, to dissociate a child from the container.
3838 gtk_widget_unparent (GtkWidget *widget)
3840 GtkWidgetPrivate *priv;
3841 GObjectNotifyQueue *nqueue;
3842 GtkWidget *toplevel;
3843 GtkWidget *old_parent;
3845 g_return_if_fail (GTK_IS_WIDGET (widget));
3847 priv = widget->priv;
3849 if (priv->parent == NULL)
3852 /* keep this function in sync with gtk_menu_detach() */
3854 gtk_widget_push_verify_invariants (widget);
3856 g_object_freeze_notify (G_OBJECT (widget));
3857 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3859 toplevel = gtk_widget_get_toplevel (widget);
3860 if (gtk_widget_is_toplevel (toplevel))
3861 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3863 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3864 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3866 gtk_widget_queue_draw_child (widget);
3868 /* Reset the width and height here, to force reallocation if we
3869 * get added back to a new parent. This won't work if our new
3870 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3871 * (would 0x0 be OK here?)
3873 priv->allocation.width = 1;
3874 priv->allocation.height = 1;
3876 if (gtk_widget_get_realized (widget))
3878 if (priv->in_reparent)
3879 gtk_widget_unmap (widget);
3881 gtk_widget_unrealize (widget);
3884 /* If we are unanchoring the child, we save around the toplevel
3885 * to emit hierarchy changed
3887 if (priv->parent->priv->anchored)
3888 g_object_ref (toplevel);
3892 /* Removing a widget from a container restores the child visible
3893 * flag to the default state, so it doesn't affect the child
3894 * in the next parent.
3896 priv->child_visible = TRUE;
3898 old_parent = priv->parent;
3899 priv->parent = NULL;
3901 /* parent may no longer expand if the removed
3902 * child was expand=TRUE and could therefore
3905 if (gtk_widget_get_visible (widget) &&
3906 (priv->need_compute_expand ||
3907 priv->computed_hexpand ||
3908 priv->computed_vexpand))
3910 gtk_widget_queue_compute_expand (old_parent);
3913 /* Unset BACKDROP since we are no longer inside a toplevel window */
3914 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_BACKDROP);
3916 gtk_style_context_set_parent (priv->context, NULL);
3918 _gtk_widget_update_parent_muxer (widget);
3920 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3923 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3924 g_object_unref (toplevel);
3927 /* Now that the parent pointer is nullified and the hierarchy-changed
3928 * already passed, go ahead and unset the parent window, if we are unparenting
3929 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
3930 * will fire again for the new subhierarchy.
3932 gtk_widget_set_parent_window (widget, NULL);
3934 g_object_notify (G_OBJECT (widget), "parent");
3935 g_object_thaw_notify (G_OBJECT (widget));
3937 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3938 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3940 gtk_widget_pop_verify_invariants (widget);
3941 g_object_unref (widget);
3945 * gtk_widget_destroy:
3946 * @widget: a #GtkWidget
3948 * Destroys a widget.
3951 * destroyed, it will break any references it holds to other objects.
3952 * If the widget is inside a container, the widget will be removed
3953 * from the container. If the widget is a toplevel (derived from
3954 * #GtkWindow), it will be removed from the list of toplevels, and the
3955 * reference GTK+ holds to it will be removed. Removing a
3956 * widget from its container or the list of toplevels results in the
3957 * widget being finalized, unless you've added additional references
3958 * to the widget with g_object_ref().
3960 * In most cases, only toplevel widgets (windows) require explicit
3961 * destruction, because when you destroy a toplevel its children will
3962 * be destroyed as well.
3965 gtk_widget_destroy (GtkWidget *widget)
3967 g_return_if_fail (GTK_IS_WIDGET (widget));
3969 if (!widget->priv->in_destruction)
3970 g_object_run_dispose (G_OBJECT (widget));
3974 * gtk_widget_destroyed:
3975 * @widget: a #GtkWidget
3976 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3978 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3979 * %NULL. It's intended to be used as a callback connected to the
3980 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3981 * as a signal handler, and pass the address of your widget variable
3982 * as user data. Then when the widget is destroyed, the variable will
3983 * be set to %NULL. Useful for example to avoid multiple copies
3984 * of the same dialog.
3987 gtk_widget_destroyed (GtkWidget *widget,
3988 GtkWidget **widget_pointer)
3990 /* Don't make any assumptions about the
3992 * Even check widget_pointer.
3995 *widget_pointer = NULL;
4000 * @widget: a #GtkWidget
4002 * Flags a widget to be displayed. Any widget that isn't shown will
4003 * not appear on the screen. If you want to show all the widgets in a
4004 * container, it's easier to call gtk_widget_show_all() on the
4005 * container, instead of individually showing the widgets.
4007 * Remember that you have to show the containers containing a widget,
4008 * in addition to the widget itself, before it will appear onscreen.
4010 * When a toplevel container is shown, it is immediately realized and
4011 * mapped; other shown widgets are realized and mapped when their
4012 * toplevel container is realized and mapped.
4015 gtk_widget_show (GtkWidget *widget)
4017 g_return_if_fail (GTK_IS_WIDGET (widget));
4019 if (!gtk_widget_get_visible (widget))
4021 g_object_ref (widget);
4022 gtk_widget_push_verify_invariants (widget);
4024 if (!gtk_widget_is_toplevel (widget))
4025 gtk_widget_queue_resize (widget);
4027 /* see comment in set_parent() for why this should and can be
4030 if (widget->priv->need_compute_expand ||
4031 widget->priv->computed_hexpand ||
4032 widget->priv->computed_vexpand)
4034 if (widget->priv->parent != NULL)
4035 gtk_widget_queue_compute_expand (widget->priv->parent);
4038 g_signal_emit (widget, widget_signals[SHOW], 0);
4039 g_object_notify (G_OBJECT (widget), "visible");
4041 gtk_widget_pop_verify_invariants (widget);
4042 g_object_unref (widget);
4047 gtk_widget_real_show (GtkWidget *widget)
4049 GtkWidgetPrivate *priv = widget->priv;
4051 if (!gtk_widget_get_visible (widget))
4053 priv->visible = TRUE;
4056 gtk_widget_get_mapped (priv->parent) &&
4057 gtk_widget_get_child_visible (widget) &&
4058 !gtk_widget_get_mapped (widget))
4059 gtk_widget_map (widget);
4064 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
4067 g_signal_handlers_disconnect_by_func (widget,
4068 gtk_widget_show_map_callback,
4073 * gtk_widget_show_now:
4074 * @widget: a #GtkWidget
4076 * Shows a widget. If the widget is an unmapped toplevel widget
4077 * (i.e. a #GtkWindow that has not yet been shown), enter the main
4078 * loop and wait for the window to actually be mapped. Be careful;
4079 * because the main loop is running, anything can happen during
4083 gtk_widget_show_now (GtkWidget *widget)
4087 g_return_if_fail (GTK_IS_WIDGET (widget));
4089 /* make sure we will get event */
4090 if (!gtk_widget_get_mapped (widget) &&
4091 gtk_widget_is_toplevel (widget))
4093 gtk_widget_show (widget);
4095 g_signal_connect (widget, "map-event",
4096 G_CALLBACK (gtk_widget_show_map_callback),
4100 gtk_main_iteration ();
4103 gtk_widget_show (widget);
4108 * @widget: a #GtkWidget
4110 * Reverses the effects of gtk_widget_show(), causing the widget to be
4111 * hidden (invisible to the user).
4114 gtk_widget_hide (GtkWidget *widget)
4116 g_return_if_fail (GTK_IS_WIDGET (widget));
4118 if (gtk_widget_get_visible (widget))
4120 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
4122 g_object_ref (widget);
4123 gtk_widget_push_verify_invariants (widget);
4125 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
4126 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
4128 /* a parent may now be expand=FALSE since we're hidden. */
4129 if (widget->priv->need_compute_expand ||
4130 widget->priv->computed_hexpand ||
4131 widget->priv->computed_vexpand)
4133 gtk_widget_queue_compute_expand (widget);
4136 g_signal_emit (widget, widget_signals[HIDE], 0);
4137 if (!gtk_widget_is_toplevel (widget))
4138 gtk_widget_queue_resize (widget);
4139 g_object_notify (G_OBJECT (widget), "visible");
4141 gtk_widget_pop_verify_invariants (widget);
4142 g_object_unref (widget);
4147 gtk_widget_real_hide (GtkWidget *widget)
4149 if (gtk_widget_get_visible (widget))
4151 widget->priv->visible = FALSE;
4153 if (gtk_widget_get_mapped (widget))
4154 gtk_widget_unmap (widget);
4156 if (widget->priv->context)
4157 _gtk_style_context_stop_animations (widget->priv->context);
4162 * gtk_widget_hide_on_delete:
4163 * @widget: a #GtkWidget
4165 * Utility function; intended to be connected to the #GtkWidget::delete-event
4166 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4167 * argument, then returns %TRUE. If connected to ::delete-event, the
4168 * result is that clicking the close button for a window (on the
4169 * window frame, top right corner usually) will hide but not destroy
4170 * the window. By default, GTK+ destroys windows when ::delete-event
4173 * Return value: %TRUE
4176 gtk_widget_hide_on_delete (GtkWidget *widget)
4178 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4180 gtk_widget_hide (widget);
4186 * gtk_widget_show_all:
4187 * @widget: a #GtkWidget
4189 * Recursively shows a widget, and any child widgets (if the widget is
4193 gtk_widget_show_all (GtkWidget *widget)
4195 GtkWidgetClass *class;
4197 g_return_if_fail (GTK_IS_WIDGET (widget));
4199 if (gtk_widget_get_no_show_all (widget))
4202 class = GTK_WIDGET_GET_CLASS (widget);
4204 if (class->show_all)
4205 class->show_all (widget);
4210 * @widget: a #GtkWidget
4212 * This function is only for use in widget implementations. Causes
4213 * a widget to be mapped if it isn't already.
4216 gtk_widget_map (GtkWidget *widget)
4218 GtkWidgetPrivate *priv;
4220 g_return_if_fail (GTK_IS_WIDGET (widget));
4221 g_return_if_fail (gtk_widget_get_visible (widget));
4222 g_return_if_fail (gtk_widget_get_child_visible (widget));
4224 priv = widget->priv;
4226 if (!gtk_widget_get_mapped (widget))
4228 gtk_widget_push_verify_invariants (widget);
4230 if (!gtk_widget_get_realized (widget))
4231 gtk_widget_realize (widget);
4233 g_signal_emit (widget, widget_signals[MAP], 0);
4235 if (!gtk_widget_get_has_window (widget))
4236 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4238 gtk_widget_pop_verify_invariants (widget);
4244 * @widget: a #GtkWidget
4246 * This function is only for use in widget implementations. Causes
4247 * a widget to be unmapped if it's currently mapped.
4250 gtk_widget_unmap (GtkWidget *widget)
4252 GtkWidgetPrivate *priv;
4254 g_return_if_fail (GTK_IS_WIDGET (widget));
4256 priv = widget->priv;
4258 if (gtk_widget_get_mapped (widget))
4260 gtk_widget_push_verify_invariants (widget);
4262 if (!gtk_widget_get_has_window (widget))
4263 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4264 _gtk_tooltip_hide (widget);
4265 g_signal_emit (widget, widget_signals[UNMAP], 0);
4267 gtk_widget_pop_verify_invariants (widget);
4269 /* Unset pointer/window info */
4270 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4275 _gtk_widget_enable_device_events (GtkWidget *widget)
4277 GHashTable *device_events;
4278 GHashTableIter iter;
4279 gpointer key, value;
4281 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4286 g_hash_table_iter_init (&iter, device_events);
4288 while (g_hash_table_iter_next (&iter, &key, &value))
4291 GdkEventMask event_mask;
4294 event_mask = GPOINTER_TO_UINT (value);
4295 gtk_widget_add_events_internal (widget, device, event_mask);
4300 get_widget_windows (GtkWidget *widget)
4302 GList *window_list, *last, *l, *children, *ret;
4304 if (gtk_widget_get_has_window (widget))
4305 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4307 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4309 last = g_list_last (window_list);
4312 for (l = window_list; l; l = l->next)
4314 GtkWidget *window_widget = NULL;
4316 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4318 if (widget != window_widget)
4321 ret = g_list_prepend (ret, l->data);
4322 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4326 last = g_list_concat (last, children);
4327 last = g_list_last (last);
4331 g_list_free (window_list);
4337 device_enable_foreach (GtkWidget *widget,
4340 GdkDevice *device = user_data;
4341 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4345 device_disable_foreach (GtkWidget *widget,
4348 GdkDevice *device = user_data;
4349 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4353 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4358 GList *window_list, *l;
4360 window_list = get_widget_windows (widget);
4362 for (l = window_list; l; l = l->next)
4364 GdkEventMask events = 0;
4370 events = gdk_window_get_events (window);
4372 gdk_window_set_device_events (window, device, events);
4375 if (recurse && GTK_IS_CONTAINER (widget))
4378 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4380 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4383 g_list_free (window_list);
4387 gtk_widget_update_devices_mask (GtkWidget *widget,
4390 GList *enabled_devices, *l;
4392 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4394 for (l = enabled_devices; l; l = l->next)
4395 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4399 * gtk_widget_realize:
4400 * @widget: a #GtkWidget
4402 * Creates the GDK (windowing system) resources associated with a
4403 * widget. For example, @widget->window will be created when a widget
4404 * is realized. Normally realization happens implicitly; if you show
4405 * a widget and all its parent containers, then the widget will be
4406 * realized and mapped automatically.
4408 * Realizing a widget requires all
4409 * the widget's parent widgets to be realized; calling
4410 * gtk_widget_realize() realizes the widget's parents in addition to
4411 * @widget itself. If a widget is not yet inside a toplevel window
4412 * when you realize it, bad things will happen.
4414 * This function is primarily used in widget implementations, and
4415 * isn't very useful otherwise. Many times when you think you might
4416 * need it, a better approach is to connect to a signal that will be
4417 * called after the widget is realized automatically, such as
4418 * #GtkWidget::draw. Or simply g_signal_connect () to the
4419 * #GtkWidget::realize signal.
4422 gtk_widget_realize (GtkWidget *widget)
4424 GtkWidgetPrivate *priv;
4425 cairo_region_t *region;
4427 g_return_if_fail (GTK_IS_WIDGET (widget));
4428 g_return_if_fail (widget->priv->anchored ||
4429 GTK_IS_INVISIBLE (widget));
4431 priv = widget->priv;
4433 if (!gtk_widget_get_realized (widget))
4435 gtk_widget_push_verify_invariants (widget);
4438 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4439 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4442 if (priv->parent == NULL &&
4443 !gtk_widget_is_toplevel (widget))
4444 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4445 "inside a toplevel window is not going to work very well. "
4446 "Widgets must be inside a toplevel container before realizing them.");
4448 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4449 gtk_widget_realize (priv->parent);
4451 gtk_widget_ensure_style (widget);
4453 if (priv->style_update_pending)
4454 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4456 g_signal_emit (widget, widget_signals[REALIZE], 0);
4458 gtk_widget_real_set_has_tooltip (widget,
4459 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4462 if (priv->has_shape_mask)
4464 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4465 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4468 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4470 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4472 if (priv->multidevice)
4473 gdk_window_set_support_multidevice (priv->window, TRUE);
4475 _gtk_widget_enable_device_events (widget);
4476 gtk_widget_update_devices_mask (widget, TRUE);
4478 gtk_widget_pop_verify_invariants (widget);
4483 * gtk_widget_unrealize:
4484 * @widget: a #GtkWidget
4486 * This function is only useful in widget implementations.
4487 * Causes a widget to be unrealized (frees all GDK resources
4488 * associated with the widget, such as @widget->window).
4491 gtk_widget_unrealize (GtkWidget *widget)
4493 g_return_if_fail (GTK_IS_WIDGET (widget));
4495 gtk_widget_push_verify_invariants (widget);
4497 if (widget->priv->has_shape_mask)
4498 gtk_widget_shape_combine_region (widget, NULL);
4500 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4501 gtk_widget_input_shape_combine_region (widget, NULL);
4503 if (gtk_widget_get_realized (widget))
4505 g_object_ref (widget);
4507 if (widget->priv->mapped)
4508 gtk_widget_unmap (widget);
4510 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4511 g_assert (!widget->priv->mapped);
4512 gtk_widget_set_realized (widget, FALSE);
4514 g_object_unref (widget);
4517 gtk_widget_pop_verify_invariants (widget);
4520 /*****************************************
4522 *****************************************/
4525 * gtk_widget_queue_draw_region:
4526 * @widget: a #GtkWidget
4527 * @region: region to draw
4529 * Invalidates the rectangular area of @widget defined by @region by
4530 * calling gdk_window_invalidate_region() on the widget's window and
4531 * all its child windows. Once the main loop becomes idle (after the
4532 * current batch of events has been processed, roughly), the window
4533 * will receive expose events for the union of all regions that have
4536 * Normally you would only use this function in widget
4537 * implementations. You might also use it to schedule a redraw of a
4538 * #GtkDrawingArea or some portion thereof.
4543 gtk_widget_queue_draw_region (GtkWidget *widget,
4544 const cairo_region_t *region)
4546 GtkWidgetPrivate *priv;
4549 g_return_if_fail (GTK_IS_WIDGET (widget));
4551 priv = widget->priv;
4553 if (!gtk_widget_get_realized (widget))
4556 /* Just return if the widget or one of its ancestors isn't mapped */
4557 for (w = widget; w != NULL; w = w->priv->parent)
4558 if (!gtk_widget_get_mapped (w))
4561 gdk_window_invalidate_region (priv->window, region, TRUE);
4565 * gtk_widget_queue_draw_area:
4566 * @widget: a #GtkWidget
4567 * @x: x coordinate of upper-left corner of rectangle to redraw
4568 * @y: y coordinate of upper-left corner of rectangle to redraw
4569 * @width: width of region to draw
4570 * @height: height of region to draw
4572 * Convenience function that calls gtk_widget_queue_draw_region() on
4573 * the region created from the given coordinates.
4575 * The region here is specified in widget coordinates.
4576 * Widget coordinates are a bit odd; for historical reasons, they are
4577 * defined as @widget->window coordinates for widgets that are not
4578 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4579 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4582 gtk_widget_queue_draw_area (GtkWidget *widget,
4589 cairo_region_t *region;
4591 g_return_if_fail (GTK_IS_WIDGET (widget));
4596 rect.height = height;
4598 region = cairo_region_create_rectangle (&rect);
4599 gtk_widget_queue_draw_region (widget, region);
4600 cairo_region_destroy (region);
4604 * gtk_widget_queue_draw:
4605 * @widget: a #GtkWidget
4607 * Equivalent to calling gtk_widget_queue_draw_area() for the
4608 * entire area of a widget.
4611 gtk_widget_queue_draw (GtkWidget *widget)
4615 g_return_if_fail (GTK_IS_WIDGET (widget));
4617 gtk_widget_get_allocation (widget, &rect);
4619 if (!gtk_widget_get_has_window (widget))
4620 gtk_widget_queue_draw_area (widget,
4621 rect.x, rect.y, rect.width, rect.height);
4623 gtk_widget_queue_draw_area (widget,
4624 0, 0, rect.width, rect.height);
4628 * gtk_widget_queue_resize:
4629 * @widget: a #GtkWidget
4631 * This function is only for use in widget implementations.
4632 * Flags a widget to have its size renegotiated; should
4633 * be called when a widget for some reason has a new size request.
4634 * For example, when you change the text in a #GtkLabel, #GtkLabel
4635 * queues a resize to ensure there's enough space for the new text.
4637 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4638 * from inside its implementation of the GtkWidgetClass::size_allocate
4639 * virtual method. Calls to gtk_widget_queue_resize() from inside
4640 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4643 gtk_widget_queue_resize (GtkWidget *widget)
4645 g_return_if_fail (GTK_IS_WIDGET (widget));
4647 if (gtk_widget_get_realized (widget))
4648 gtk_widget_queue_shallow_draw (widget);
4650 _gtk_size_group_queue_resize (widget, 0);
4654 * gtk_widget_queue_resize_no_redraw:
4655 * @widget: a #GtkWidget
4657 * This function works like gtk_widget_queue_resize(),
4658 * except that the widget is not invalidated.
4663 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4665 g_return_if_fail (GTK_IS_WIDGET (widget));
4667 _gtk_size_group_queue_resize (widget, 0);
4671 * gtk_widget_size_request:
4672 * @widget: a #GtkWidget
4673 * @requisition: (out): a #GtkRequisition to be filled in
4675 * This function is typically used when implementing a #GtkContainer
4676 * subclass. Obtains the preferred size of a widget. The container
4677 * uses this information to arrange its child widgets and decide what
4678 * size allocations to give them with gtk_widget_size_allocate().
4680 * You can also call this function from an application, with some
4681 * caveats. Most notably, getting a size request requires the widget
4682 * to be associated with a screen, because font information may be
4683 * needed. Multihead-aware applications should keep this in mind.
4685 * Also remember that the size request is not necessarily the size
4686 * a widget will actually be allocated.
4688 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4691 gtk_widget_size_request (GtkWidget *widget,
4692 GtkRequisition *requisition)
4694 g_return_if_fail (GTK_IS_WIDGET (widget));
4696 gtk_widget_get_preferred_size (widget, requisition, NULL);
4700 * gtk_widget_get_child_requisition:
4701 * @widget: a #GtkWidget
4702 * @requisition: (out): a #GtkRequisition to be filled in
4704 * This function is only for use in widget implementations. Obtains
4705 * @widget->requisition, unless someone has forced a particular
4706 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4707 * in which case it returns that geometry instead of the widget's
4710 * This function differs from gtk_widget_size_request() in that
4711 * it retrieves the last size request value from @widget->requisition,
4712 * while gtk_widget_size_request() actually calls the "size_request" method
4713 * on @widget to compute the size request and fill in @widget->requisition,
4714 * and only then returns @widget->requisition.
4716 * Because this function does not call the "size_request" method, it
4717 * can only be used when you know that @widget->requisition is
4718 * up-to-date, that is, gtk_widget_size_request() has been called
4719 * since the last time a resize was queued. In general, only container
4720 * implementations have this information; applications should use
4721 * gtk_widget_size_request().
4724 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4727 gtk_widget_get_child_requisition (GtkWidget *widget,
4728 GtkRequisition *requisition)
4730 gtk_widget_get_preferred_size (widget, requisition, NULL);
4734 invalidate_predicate (GdkWindow *window,
4739 gdk_window_get_user_data (window, &user_data);
4741 return (user_data == data);
4744 /* Invalidate @region in widget->window and all children
4745 * of widget->window owned by widget. @region is in the
4746 * same coordinates as widget->allocation and will be
4747 * modified by this call.
4750 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4751 cairo_region_t *region)
4753 GtkWidgetPrivate *priv = widget->priv;
4755 if (!gtk_widget_get_realized (widget))
4758 if (gtk_widget_get_has_window (widget) && priv->parent)
4762 gdk_window_get_position (priv->window, &x, &y);
4763 cairo_region_translate (region, -x, -y);
4766 gdk_window_invalidate_maybe_recurse (priv->window, region,
4767 invalidate_predicate, widget);
4771 * gtk_widget_queue_shallow_draw:
4772 * @widget: a #GtkWidget
4774 * Like gtk_widget_queue_draw(), but only windows owned
4775 * by @widget are invalidated.
4778 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4781 cairo_region_t *region;
4783 if (!gtk_widget_get_realized (widget))
4786 gtk_widget_get_allocation (widget, &rect);
4788 region = cairo_region_create_rectangle (&rect);
4789 gtk_widget_invalidate_widget_windows (widget, region);
4790 cairo_region_destroy (region);
4794 * gtk_widget_size_allocate:
4795 * @widget: a #GtkWidget
4796 * @allocation: position and size to be allocated to @widget
4798 * This function is only used by #GtkContainer subclasses, to assign a size
4799 * and position to their child widgets.
4801 * In this function, the allocation may be adjusted. It will be forced
4802 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4803 * method on the child will be used to adjust the allocation. Standard
4804 * adjustments include removing the widget's margins, and applying the
4805 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4808 gtk_widget_size_allocate (GtkWidget *widget,
4809 GtkAllocation *allocation)
4811 GtkWidgetPrivate *priv;
4812 GdkRectangle real_allocation;
4813 GdkRectangle old_allocation;
4814 GdkRectangle adjusted_allocation;
4815 gboolean alloc_needed;
4816 gboolean size_changed;
4817 gboolean position_changed;
4818 gint natural_width, natural_height, dummy;
4819 gint min_width, min_height;
4821 priv = widget->priv;
4823 g_return_if_fail (GTK_IS_WIDGET (widget));
4825 gtk_widget_push_verify_invariants (widget);
4827 #ifdef G_ENABLE_DEBUG
4828 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4839 parent = gtk_widget_get_parent (parent);
4842 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4843 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4844 2 * depth, " ", name,
4845 allocation->width, allocation->height);
4847 #endif /* G_ENABLE_DEBUG */
4849 alloc_needed = priv->alloc_needed;
4850 if (!priv->width_request_needed && !priv->height_request_needed)
4851 /* Preserve request/allocate ordering */
4852 priv->alloc_needed = FALSE;
4854 old_allocation = priv->allocation;
4855 real_allocation = *allocation;
4857 adjusted_allocation = real_allocation;
4858 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4860 /* Go ahead and request the height for allocated width, note that the internals
4861 * of get_height_for_width will internally limit the for_size to natural size
4862 * when aligning implicitly.
4864 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4865 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
4869 /* Go ahead and request the width for allocated height, note that the internals
4870 * of get_width_for_height will internally limit the for_size to natural size
4871 * when aligning implicitly.
4873 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4874 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
4877 #ifdef G_ENABLE_DEBUG
4878 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4880 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
4881 !GTK_IS_SCROLLABLE (widget))
4882 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
4883 "Allocation is %dx%d, but minimum required size is %dx%d.",
4884 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
4885 G_OBJECT_TYPE_NAME (widget), widget,
4886 real_allocation.width, real_allocation.height,
4887 min_width, min_height);
4890 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4891 * allocated sizes and possibly limit them to the natural sizes */
4892 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4893 GTK_ORIENTATION_HORIZONTAL,
4896 &adjusted_allocation.x,
4897 &adjusted_allocation.width);
4898 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4899 GTK_ORIENTATION_VERTICAL,
4902 &adjusted_allocation.y,
4903 &adjusted_allocation.height);
4905 if (adjusted_allocation.x < real_allocation.x ||
4906 adjusted_allocation.y < real_allocation.y ||
4907 (adjusted_allocation.x + adjusted_allocation.width) >
4908 (real_allocation.x + real_allocation.width) ||
4909 (adjusted_allocation.y + adjusted_allocation.height >
4910 real_allocation.y + real_allocation.height))
4912 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",
4913 G_OBJECT_TYPE_NAME (widget), widget,
4914 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4915 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4916 adjusted_allocation = real_allocation; /* veto it */
4920 real_allocation = adjusted_allocation;
4923 if (real_allocation.width < 0 || real_allocation.height < 0)
4925 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4926 real_allocation.width,
4927 real_allocation.height);
4930 real_allocation.width = MAX (real_allocation.width, 1);
4931 real_allocation.height = MAX (real_allocation.height, 1);
4933 size_changed = (old_allocation.width != real_allocation.width ||
4934 old_allocation.height != real_allocation.height);
4935 position_changed = (old_allocation.x != real_allocation.x ||
4936 old_allocation.y != real_allocation.y);
4938 if (!alloc_needed && !size_changed && !position_changed)
4941 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4943 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4944 priv->width_request_needed = FALSE;
4945 priv->height_request_needed = FALSE;
4946 priv->alloc_needed = FALSE;
4948 if (gtk_widget_get_mapped (widget))
4950 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4952 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4954 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4955 cairo_region_union_rectangle (invalidate, &old_allocation);
4957 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4958 cairo_region_destroy (invalidate);
4963 if (priv->redraw_on_alloc)
4965 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4967 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4968 cairo_region_union_rectangle (invalidate, &old_allocation);
4970 gtk_widget_invalidate_widget_windows (widget, invalidate);
4971 cairo_region_destroy (invalidate);
4976 if ((size_changed || position_changed) && priv->parent &&
4977 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4979 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4980 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4981 cairo_region_destroy (invalidate);
4985 gtk_widget_pop_verify_invariants (widget);
4989 * gtk_widget_common_ancestor:
4990 * @widget_a: a #GtkWidget
4991 * @widget_b: a #GtkWidget
4993 * Find the common ancestor of @widget_a and @widget_b that
4994 * is closest to the two widgets.
4996 * Return value: the closest common ancestor of @widget_a and
4997 * @widget_b or %NULL if @widget_a and @widget_b do not
4998 * share a common ancestor.
5001 gtk_widget_common_ancestor (GtkWidget *widget_a,
5002 GtkWidget *widget_b)
5004 GtkWidget *parent_a;
5005 GtkWidget *parent_b;
5009 parent_a = widget_a;
5010 while (parent_a->priv->parent)
5012 parent_a = parent_a->priv->parent;
5016 parent_b = widget_b;
5017 while (parent_b->priv->parent)
5019 parent_b = parent_b->priv->parent;
5023 if (parent_a != parent_b)
5026 while (depth_a > depth_b)
5028 widget_a = widget_a->priv->parent;
5032 while (depth_b > depth_a)
5034 widget_b = widget_b->priv->parent;
5038 while (widget_a != widget_b)
5040 widget_a = widget_a->priv->parent;
5041 widget_b = widget_b->priv->parent;
5048 * gtk_widget_translate_coordinates:
5049 * @src_widget: a #GtkWidget
5050 * @dest_widget: a #GtkWidget
5051 * @src_x: X position relative to @src_widget
5052 * @src_y: Y position relative to @src_widget
5053 * @dest_x: (out): location to store X position relative to @dest_widget
5054 * @dest_y: (out): location to store Y position relative to @dest_widget
5056 * Translate coordinates relative to @src_widget's allocation to coordinates
5057 * relative to @dest_widget's allocations. In order to perform this
5058 * operation, both widgets must be realized, and must share a common
5061 * Return value: %FALSE if either widget was not realized, or there
5062 * was no common ancestor. In this case, nothing is stored in
5063 * *@dest_x and *@dest_y. Otherwise %TRUE.
5066 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5067 GtkWidget *dest_widget,
5073 GtkWidgetPrivate *src_priv = src_widget->priv;
5074 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5075 GtkWidget *ancestor;
5077 GList *dest_list = NULL;
5079 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5080 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5082 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5083 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5086 /* Translate from allocation relative to window relative */
5087 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5090 gdk_window_get_position (src_priv->window, &wx, &wy);
5092 src_x -= wx - src_priv->allocation.x;
5093 src_y -= wy - src_priv->allocation.y;
5097 src_x += src_priv->allocation.x;
5098 src_y += src_priv->allocation.y;
5101 /* Translate to the common ancestor */
5102 window = src_priv->window;
5103 while (window != ancestor->priv->window)
5107 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5112 window = gdk_window_get_effective_parent (window);
5114 if (!window) /* Handle GtkHandleBox */
5119 window = dest_priv->window;
5120 while (window != ancestor->priv->window)
5122 dest_list = g_list_prepend (dest_list, window);
5124 window = gdk_window_get_effective_parent (window);
5126 if (!window) /* Handle GtkHandleBox */
5128 g_list_free (dest_list);
5137 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5142 dest_list = g_list_remove (dest_list, dest_list->data);
5145 /* Translate from window relative to allocation relative */
5146 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5149 gdk_window_get_position (dest_priv->window, &wx, &wy);
5151 src_x += wx - dest_priv->allocation.x;
5152 src_y += wy - dest_priv->allocation.y;
5156 src_x -= dest_priv->allocation.x;
5157 src_y -= dest_priv->allocation.y;
5169 gtk_widget_real_size_allocate (GtkWidget *widget,
5170 GtkAllocation *allocation)
5172 GtkWidgetPrivate *priv = widget->priv;
5174 priv->allocation = *allocation;
5176 if (gtk_widget_get_realized (widget) &&
5177 gtk_widget_get_has_window (widget))
5179 gdk_window_move_resize (priv->window,
5180 allocation->x, allocation->y,
5181 allocation->width, allocation->height);
5185 /* translate initial/final into start/end */
5187 effective_align (GtkAlign align,
5188 GtkTextDirection direction)
5192 case GTK_ALIGN_START:
5193 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5195 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5202 adjust_for_align (GtkAlign align,
5204 gint *allocated_pos,
5205 gint *allocated_size)
5209 case GTK_ALIGN_FILL:
5210 /* change nothing */
5212 case GTK_ALIGN_START:
5213 /* keep *allocated_pos where it is */
5214 *allocated_size = MIN (*allocated_size, *natural_size);
5217 if (*allocated_size > *natural_size)
5219 *allocated_pos += (*allocated_size - *natural_size);
5220 *allocated_size = *natural_size;
5223 case GTK_ALIGN_CENTER:
5224 if (*allocated_size > *natural_size)
5226 *allocated_pos += (*allocated_size - *natural_size) / 2;
5227 *allocated_size = MIN (*allocated_size, *natural_size);
5234 adjust_for_margin(gint start_margin,
5238 gint *allocated_pos,
5239 gint *allocated_size)
5241 *minimum_size -= (start_margin + end_margin);
5242 *natural_size -= (start_margin + end_margin);
5243 *allocated_pos += start_margin;
5244 *allocated_size -= (start_margin + end_margin);
5248 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5249 GtkOrientation orientation,
5252 gint *allocated_pos,
5253 gint *allocated_size)
5255 const GtkWidgetAuxInfo *aux_info;
5257 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5259 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5261 adjust_for_margin (aux_info->margin.left,
5262 aux_info->margin.right,
5263 minimum_size, natural_size,
5264 allocated_pos, allocated_size);
5265 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5266 natural_size, allocated_pos, allocated_size);
5270 adjust_for_margin (aux_info->margin.top,
5271 aux_info->margin.bottom,
5272 minimum_size, natural_size,
5273 allocated_pos, allocated_size);
5274 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5275 natural_size, allocated_pos, allocated_size);
5280 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5283 GtkWidgetPrivate *priv = widget->priv;
5285 /* widgets must be onscreen for accels to take effect */
5286 return gtk_widget_is_sensitive (widget) &&
5287 gtk_widget_is_drawable (widget) &&
5288 gdk_window_is_viewable (priv->window);
5292 * gtk_widget_can_activate_accel:
5293 * @widget: a #GtkWidget
5294 * @signal_id: the ID of a signal installed on @widget
5296 * Determines whether an accelerator that activates the signal
5297 * identified by @signal_id can currently be activated.
5298 * This is done by emitting the #GtkWidget::can-activate-accel
5299 * signal on @widget; if the signal isn't overridden by a
5300 * handler or in a derived widget, then the default check is
5301 * that the widget must be sensitive, and the widget and all
5302 * its ancestors mapped.
5304 * Return value: %TRUE if the accelerator can be activated.
5309 gtk_widget_can_activate_accel (GtkWidget *widget,
5312 gboolean can_activate = FALSE;
5313 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5314 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5315 return can_activate;
5324 closure_accel_activate (GClosure *closure,
5325 GValue *return_value,
5326 guint n_param_values,
5327 const GValue *param_values,
5328 gpointer invocation_hint,
5329 gpointer marshal_data)
5331 AccelClosure *aclosure = (AccelClosure*) closure;
5332 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5335 g_signal_emit (closure->data, aclosure->signal_id, 0);
5337 /* whether accelerator was handled */
5338 g_value_set_boolean (return_value, can_activate);
5342 closures_destroy (gpointer data)
5344 GSList *slist, *closures = data;
5346 for (slist = closures; slist; slist = slist->next)
5348 g_closure_invalidate (slist->data);
5349 g_closure_unref (slist->data);
5351 g_slist_free (closures);
5355 widget_new_accel_closure (GtkWidget *widget,
5358 AccelClosure *aclosure;
5359 GClosure *closure = NULL;
5360 GSList *slist, *closures;
5362 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5363 for (slist = closures; slist; slist = slist->next)
5364 if (!gtk_accel_group_from_accel_closure (slist->data))
5366 /* reuse this closure */
5367 closure = slist->data;
5372 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5373 closures = g_slist_prepend (closures, g_closure_ref (closure));
5374 g_closure_sink (closure);
5375 g_closure_set_marshal (closure, closure_accel_activate);
5377 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5379 aclosure = (AccelClosure*) closure;
5380 g_assert (closure->data == widget);
5381 g_assert (closure->marshal == closure_accel_activate);
5382 aclosure->signal_id = signal_id;
5388 * gtk_widget_add_accelerator:
5389 * @widget: widget to install an accelerator on
5390 * @accel_signal: widget signal to emit on accelerator activation
5391 * @accel_group: accel group for this widget, added to its toplevel
5392 * @accel_key: GDK keyval of the accelerator
5393 * @accel_mods: modifier key combination of the accelerator
5394 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5396 * Installs an accelerator for this @widget in @accel_group that causes
5397 * @accel_signal to be emitted if the accelerator is activated.
5398 * The @accel_group needs to be added to the widget's toplevel via
5399 * gtk_window_add_accel_group(), and the signal must be of type %G_SIGNAL_ACTION.
5400 * Accelerators added through this function are not user changeable during
5401 * runtime. If you want to support accelerators that can be changed by the
5402 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5403 * gtk_menu_item_set_accel_path() instead.
5406 gtk_widget_add_accelerator (GtkWidget *widget,
5407 const gchar *accel_signal,
5408 GtkAccelGroup *accel_group,
5410 GdkModifierType accel_mods,
5411 GtkAccelFlags accel_flags)
5416 g_return_if_fail (GTK_IS_WIDGET (widget));
5417 g_return_if_fail (accel_signal != NULL);
5418 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5420 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5421 if (!query.signal_id ||
5422 !(query.signal_flags & G_SIGNAL_ACTION) ||
5423 query.return_type != G_TYPE_NONE ||
5426 /* hmm, should be elaborate enough */
5427 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5428 G_OBJECT_TYPE_NAME (widget), accel_signal);
5432 closure = widget_new_accel_closure (widget, query.signal_id);
5434 g_object_ref (widget);
5436 /* install the accelerator. since we don't map this onto an accel_path,
5437 * the accelerator will automatically be locked.
5439 gtk_accel_group_connect (accel_group,
5442 accel_flags | GTK_ACCEL_LOCKED,
5445 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5447 g_object_unref (widget);
5451 * gtk_widget_remove_accelerator:
5452 * @widget: widget to install an accelerator on
5453 * @accel_group: accel group for this widget
5454 * @accel_key: GDK keyval of the accelerator
5455 * @accel_mods: modifier key combination of the accelerator
5457 * Removes an accelerator from @widget, previously installed with
5458 * gtk_widget_add_accelerator().
5460 * Returns: whether an accelerator was installed and could be removed
5463 gtk_widget_remove_accelerator (GtkWidget *widget,
5464 GtkAccelGroup *accel_group,
5466 GdkModifierType accel_mods)
5468 GtkAccelGroupEntry *ag_entry;
5469 GList *slist, *clist;
5472 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5473 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5475 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5476 clist = gtk_widget_list_accel_closures (widget);
5477 for (slist = clist; slist; slist = slist->next)
5481 for (i = 0; i < n; i++)
5482 if (slist->data == (gpointer) ag_entry[i].closure)
5484 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5486 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5488 g_list_free (clist);
5493 g_list_free (clist);
5495 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5496 accel_key, accel_mods, accel_group,
5497 G_OBJECT_TYPE_NAME (widget), widget);
5503 * gtk_widget_list_accel_closures:
5504 * @widget: widget to list accelerator closures for
5506 * Lists the closures used by @widget for accelerator group connections
5507 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5508 * The closures can be used to monitor accelerator changes on @widget,
5509 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5510 * #GtkAccelGroup of a closure which can be found out with
5511 * gtk_accel_group_from_accel_closure().
5513 * Return value: (transfer container) (element-type GClosure):
5514 * a newly allocated #GList of closures
5517 gtk_widget_list_accel_closures (GtkWidget *widget)
5520 GList *clist = NULL;
5522 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5524 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5525 if (gtk_accel_group_from_accel_closure (slist->data))
5526 clist = g_list_prepend (clist, slist->data);
5532 GtkAccelGroup *accel_group;
5537 destroy_accel_path (gpointer data)
5539 AccelPath *apath = data;
5541 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5543 /* closures_destroy takes care of unrefing the closure */
5544 g_object_unref (apath->accel_group);
5546 g_slice_free (AccelPath, apath);
5551 * gtk_widget_set_accel_path:
5552 * @widget: a #GtkWidget
5553 * @accel_path: (allow-none): path used to look up the accelerator
5554 * @accel_group: (allow-none): a #GtkAccelGroup.
5556 * Given an accelerator group, @accel_group, and an accelerator path,
5557 * @accel_path, sets up an accelerator in @accel_group so whenever the
5558 * key binding that is defined for @accel_path is pressed, @widget
5559 * will be activated. This removes any accelerators (for any
5560 * accelerator group) installed by previous calls to
5561 * gtk_widget_set_accel_path(). Associating accelerators with
5562 * paths allows them to be modified by the user and the modifications
5563 * to be saved for future use. (See gtk_accel_map_save().)
5565 * This function is a low level function that would most likely
5566 * be used by a menu creation system like #GtkUIManager. If you
5567 * use #GtkUIManager, setting up accelerator paths will be done
5570 * Even when you you aren't using #GtkUIManager, if you only want to
5571 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5572 * provides a somewhat more convenient interface.
5574 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5575 * pass a static string, you can save some memory by interning it first with
5576 * g_intern_static_string().
5579 gtk_widget_set_accel_path (GtkWidget *widget,
5580 const gchar *accel_path,
5581 GtkAccelGroup *accel_group)
5585 g_return_if_fail (GTK_IS_WIDGET (widget));
5586 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5590 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5591 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5593 gtk_accel_map_add_entry (accel_path, 0, 0);
5594 apath = g_slice_new (AccelPath);
5595 apath->accel_group = g_object_ref (accel_group);
5596 apath->path_quark = g_quark_from_string (accel_path);
5597 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5602 /* also removes possible old settings */
5603 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5606 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5608 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5612 _gtk_widget_get_accel_path (GtkWidget *widget,
5617 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5619 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5621 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5622 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5626 * gtk_widget_mnemonic_activate:
5627 * @widget: a #GtkWidget
5628 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5630 * Emits the #GtkWidget::mnemonic-activate signal.
5632 * The default handler for this signal activates the @widget if
5633 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5636 * Returns: %TRUE if the signal has been handled
5639 gtk_widget_mnemonic_activate (GtkWidget *widget,
5640 gboolean group_cycling)
5644 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5646 group_cycling = group_cycling != FALSE;
5647 if (!gtk_widget_is_sensitive (widget))
5650 g_signal_emit (widget,
5651 widget_signals[MNEMONIC_ACTIVATE],
5659 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5660 gboolean group_cycling)
5662 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5663 gtk_widget_activate (widget);
5664 else if (gtk_widget_get_can_focus (widget))
5665 gtk_widget_grab_focus (widget);
5668 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5669 G_OBJECT_TYPE_NAME (widget));
5670 gtk_widget_error_bell (widget);
5675 static const cairo_user_data_key_t event_key;
5678 _gtk_cairo_get_event (cairo_t *cr)
5680 g_return_val_if_fail (cr != NULL, NULL);
5682 return cairo_get_user_data (cr, &event_key);
5686 gtk_cairo_set_event (cairo_t *cr,
5687 GdkEventExpose *event)
5689 cairo_set_user_data (cr, &event_key, event, NULL);
5693 * gtk_cairo_should_draw_window:
5694 * @cr: a cairo context
5695 * @window: the window to check. @window may not be an input-only
5698 * This function is supposed to be called in #GtkWidget::draw
5699 * implementations for widgets that support multiple windows.
5700 * @cr must be untransformed from invoking of the draw function.
5701 * This function will return %TRUE if the contents of the given
5702 * @window are supposed to be drawn and %FALSE otherwise. Note
5703 * that when the drawing was not initiated by the windowing
5704 * system this function will return %TRUE for all windows, so
5705 * you need to draw the bottommost window first. Also, do not
5706 * use "else if" statements to check which window should be drawn.
5708 * Returns: %TRUE if @window should be drawn
5713 gtk_cairo_should_draw_window (cairo_t *cr,
5716 GdkEventExpose *event;
5718 g_return_val_if_fail (cr != NULL, FALSE);
5719 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5721 event = _gtk_cairo_get_event (cr);
5723 return event == NULL ||
5724 event->window == window;
5728 gtk_widget_get_clip_draw (GtkWidget *widget)
5730 /* labels are not clipped, because clipping them would cause
5731 * mnemonics to not appear on characters that go beyond the
5733 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
5735 if (GTK_IS_LABEL (widget))
5741 /* code shared by gtk_container_propagate_draw() and
5745 _gtk_widget_draw_internal (GtkWidget *widget,
5747 gboolean clip_to_size)
5749 if (!gtk_widget_is_drawable (widget))
5752 clip_to_size &= gtk_widget_get_clip_draw (widget);
5756 cairo_rectangle (cr,
5758 widget->priv->allocation.width,
5759 widget->priv->allocation.height);
5763 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5767 g_signal_emit (widget, widget_signals[DRAW],
5771 if (cairo_status (cr) &&
5772 _gtk_cairo_get_event (cr))
5774 /* We check the event so we only warn about internal GTK calls.
5775 * Errors might come from PDF streams having write failures and
5776 * we don't want to spam stderr in that case.
5777 * We do want to catch errors from
5779 g_warning ("drawing failure for widget `%s': %s",
5780 G_OBJECT_TYPE_NAME (widget),
5781 cairo_status_to_string (cairo_status (cr)));
5788 * @widget: the widget to draw. It must be drawable (see
5789 * gtk_widget_is_drawable()) and a size must have been allocated.
5790 * @cr: a cairo context to draw to
5792 * Draws @widget to @cr. The top left corner of the widget will be
5793 * drawn to the currently set origin point of @cr.
5795 * You should pass a cairo context as @cr argument that is in an
5796 * original state. Otherwise the resulting drawing is undefined. For
5797 * example changing the operator using cairo_set_operator() or the
5798 * line width using cairo_set_line_width() might have unwanted side
5800 * You may however change the context's transform matrix - like with
5801 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5802 * region with cairo_clip() prior to calling this function. Also, it
5803 * is fine to modify the context with cairo_save() and
5804 * cairo_push_group() prior to calling this function.
5806 * <note><para>Special purpose widgets may contain special code for
5807 * rendering to the screen and might appear differently on screen
5808 * and when rendered using gtk_widget_draw().</para></note>
5813 gtk_widget_draw (GtkWidget *widget,
5816 GdkEventExpose *tmp_event;
5818 g_return_if_fail (GTK_IS_WIDGET (widget));
5819 g_return_if_fail (!widget->priv->alloc_needed);
5820 g_return_if_fail (cr != NULL);
5823 /* We have to reset the event here so that draw functions can call
5824 * gtk_widget_draw() on random other widgets and get the desired
5825 * effect: Drawing all contents, not just the current window.
5827 tmp_event = _gtk_cairo_get_event (cr);
5828 gtk_cairo_set_event (cr, NULL);
5830 _gtk_widget_draw_internal (widget, cr, TRUE);
5832 gtk_cairo_set_event (cr, tmp_event);
5837 gtk_widget_real_key_press_event (GtkWidget *widget,
5840 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5844 gtk_widget_real_key_release_event (GtkWidget *widget,
5847 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5851 gtk_widget_real_focus_in_event (GtkWidget *widget,
5852 GdkEventFocus *event)
5854 gtk_widget_queue_shallow_draw (widget);
5860 gtk_widget_real_focus_out_event (GtkWidget *widget,
5861 GdkEventFocus *event)
5863 gtk_widget_queue_shallow_draw (widget);
5869 gtk_widget_real_touch_event (GtkWidget *widget,
5870 GdkEventTouch *event)
5873 gboolean return_val;
5876 if (!event->emulating_pointer)
5879 if (event->type == GDK_TOUCH_BEGIN ||
5880 event->type == GDK_TOUCH_END)
5884 if (event->type == GDK_TOUCH_BEGIN)
5886 type = GDK_BUTTON_PRESS;
5887 signum = BUTTON_PRESS_EVENT;
5891 type = GDK_BUTTON_RELEASE;
5892 signum = BUTTON_RELEASE_EVENT;
5894 bevent = gdk_event_new (type);
5895 bevent->any.window = g_object_ref (event->window);
5896 bevent->any.send_event = FALSE;
5897 bevent->button.time = event->time;
5898 bevent->button.state = event->state;
5899 bevent->button.button = 1;
5900 bevent->button.x_root = event->x_root;
5901 bevent->button.y_root = event->y_root;
5902 bevent->button.x = event->x;
5903 bevent->button.y = event->y;
5904 bevent->button.device = event->device;
5905 bevent->button.axes = g_memdup (event->axes,
5906 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
5907 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
5909 else if (event->type == GDK_TOUCH_UPDATE)
5911 signum = MOTION_NOTIFY_EVENT;
5912 bevent = gdk_event_new (GDK_MOTION_NOTIFY);
5913 bevent->any.window = g_object_ref (event->window);
5914 bevent->any.send_event = FALSE;
5915 bevent->motion.time = event->time;
5916 bevent->motion.state = event->state;
5917 bevent->motion.x_root = event->x_root;
5918 bevent->motion.y_root = event->y_root;
5919 bevent->motion.x = event->x;
5920 bevent->motion.y = event->y;
5921 bevent->motion.device = event->device;
5922 bevent->motion.is_hint = FALSE;
5923 bevent->motion.axes = g_memdup (event->axes,
5924 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
5925 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
5930 g_signal_emit (widget, widget_signals[signum], 0, bevent, &return_val);
5932 gdk_event_free (bevent);
5938 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5939 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5943 * @widget: a #GtkWidget
5944 * @event: a #GdkEvent
5946 * Rarely-used function. This function is used to emit
5947 * the event signals on a widget (those signals should never
5948 * be emitted without using this function to do so).
5949 * If you want to synthesize an event though, don't use this function;
5950 * instead, use gtk_main_do_event() so the event will behave as if
5951 * it were in the event queue. Don't synthesize expose events; instead,
5952 * use gdk_window_invalidate_rect() to invalidate a region of the
5955 * Return value: return from the event signal emission (%TRUE if
5956 * the event was handled)
5959 gtk_widget_event (GtkWidget *widget,
5962 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5963 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5965 if (event->type == GDK_EXPOSE)
5967 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5968 "the same effect, call gdk_window_invalidate_rect/region(), "
5969 "followed by gdk_window_process_updates().");
5973 return gtk_widget_event_internal (widget, event);
5977 _gtk_widget_set_captured_event_handler (GtkWidget *widget,
5978 GtkCapturedEventHandler callback)
5980 g_object_set_data (G_OBJECT (widget), "captured-event-handler", callback);
5984 _gtk_widget_captured_event (GtkWidget *widget,
5987 gboolean return_val = FALSE;
5988 GtkCapturedEventHandler handler;
5990 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5991 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5993 if (event->type == GDK_EXPOSE)
5995 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5996 "the same effect, call gdk_window_invalidate_rect/region(), "
5997 "followed by gdk_window_process_updates().");
6001 if (!event_window_is_still_viewable (event))
6004 handler = g_object_get_data (G_OBJECT (widget), "captured-event-handler");
6008 g_object_ref (widget);
6010 return_val = handler (widget, event);
6011 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6013 /* The widget that was originally to receive the event
6014 * handles motion hints, but the capturing widget might
6015 * not, so ensure we get further motion events.
6018 event->type == GDK_MOTION_NOTIFY &&
6019 event->motion.is_hint &&
6020 (gdk_window_get_events (event->any.window) &
6021 GDK_POINTER_MOTION_HINT_MASK) != 0)
6022 gdk_event_request_motions (&event->motion);
6024 g_object_unref (widget);
6029 /* Returns TRUE if a translation should be done */
6031 _gtk_widget_get_translation_to_window (GtkWidget *widget,
6036 GdkWindow *w, *widget_window;
6038 if (!gtk_widget_get_has_window (widget))
6040 *x = -widget->priv->allocation.x;
6041 *y = -widget->priv->allocation.y;
6049 widget_window = gtk_widget_get_window (widget);
6051 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
6054 gdk_window_get_position (w, &wx, &wy);
6071 * gtk_cairo_transform_to_window:
6072 * @cr: the cairo context to transform
6073 * @widget: the widget the context is currently centered for
6074 * @window: the window to transform the context to
6076 * Transforms the given cairo context @cr that from @widget-relative
6077 * coordinates to @window-relative coordinates.
6078 * If the @widget's window is not an ancestor of @window, no
6079 * modification will be applied.
6081 * This is the inverse to the transformation GTK applies when
6082 * preparing an expose event to be emitted with the #GtkWidget::draw
6083 * signal. It is intended to help porting multiwindow widgets from
6084 * GTK+ 2 to the rendering architecture of GTK+ 3.
6089 gtk_cairo_transform_to_window (cairo_t *cr,
6095 g_return_if_fail (cr != NULL);
6096 g_return_if_fail (GTK_IS_WIDGET (widget));
6097 g_return_if_fail (GDK_IS_WINDOW (window));
6099 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
6100 cairo_translate (cr, x, y);
6104 * gtk_widget_send_expose:
6105 * @widget: a #GtkWidget
6106 * @event: a expose #GdkEvent
6108 * Very rarely-used function. This function is used to emit
6109 * an expose event on a widget. This function is not normally used
6110 * directly. The only time it is used is when propagating an expose
6111 * event to a child %NO_WINDOW widget, and that is normally done
6112 * using gtk_container_propagate_draw().
6114 * If you want to force an area of a window to be redrawn,
6115 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
6116 * To cause the redraw to be done immediately, follow that call
6117 * with a call to gdk_window_process_updates().
6119 * Return value: return from the event signal emission (%TRUE if
6120 * the event was handled)
6123 gtk_widget_send_expose (GtkWidget *widget,
6126 gboolean result = FALSE;
6131 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6132 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
6133 g_return_val_if_fail (event != NULL, TRUE);
6134 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
6136 cr = gdk_cairo_create (event->expose.window);
6137 gtk_cairo_set_event (cr, &event->expose);
6139 gdk_cairo_region (cr, event->expose.region);
6142 do_clip = _gtk_widget_get_translation_to_window (widget,
6143 event->expose.window,
6145 cairo_translate (cr, -x, -y);
6147 _gtk_widget_draw_internal (widget, cr, do_clip);
6149 /* unset here, so if someone keeps a reference to cr we
6150 * don't leak the window. */
6151 gtk_cairo_set_event (cr, NULL);
6158 event_window_is_still_viewable (GdkEvent *event)
6160 /* Check that we think the event's window is viewable before
6161 * delivering the event, to prevent suprises. We do this here
6162 * at the last moment, since the event may have been queued
6163 * up behind other events, held over a recursive main loop, etc.
6165 switch (event->type)
6168 case GDK_MOTION_NOTIFY:
6169 case GDK_BUTTON_PRESS:
6170 case GDK_2BUTTON_PRESS:
6171 case GDK_3BUTTON_PRESS:
6173 case GDK_ENTER_NOTIFY:
6174 case GDK_PROXIMITY_IN:
6176 return event->any.window && gdk_window_is_viewable (event->any.window);
6179 /* The following events are the second half of paired events;
6180 * we always deliver them to deal with widgets that clean up
6181 * on the second half.
6183 case GDK_BUTTON_RELEASE:
6184 case GDK_KEY_RELEASE:
6185 case GDK_LEAVE_NOTIFY:
6186 case GDK_PROXIMITY_OUT:
6190 /* Remaining events would make sense on an not-viewable window,
6191 * or don't have an associated window.
6198 gtk_widget_event_internal (GtkWidget *widget,
6201 gboolean return_val = FALSE;
6203 /* We check only once for is-still-visible; if someone
6204 * hides the window in on of the signals on the widget,
6205 * they are responsible for returning TRUE to terminate
6208 if (!event_window_is_still_viewable (event))
6211 g_object_ref (widget);
6213 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6214 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6219 switch (event->type)
6225 case GDK_BUTTON_PRESS:
6226 case GDK_2BUTTON_PRESS:
6227 case GDK_3BUTTON_PRESS:
6228 signal_num = BUTTON_PRESS_EVENT;
6230 case GDK_TOUCH_BEGIN:
6231 case GDK_TOUCH_UPDATE:
6233 case GDK_TOUCH_CANCEL:
6234 signal_num = TOUCH_EVENT;
6237 signal_num = SCROLL_EVENT;
6239 case GDK_BUTTON_RELEASE:
6240 signal_num = BUTTON_RELEASE_EVENT;
6242 case GDK_MOTION_NOTIFY:
6243 signal_num = MOTION_NOTIFY_EVENT;
6246 signal_num = DELETE_EVENT;
6249 signal_num = DESTROY_EVENT;
6250 _gtk_tooltip_hide (widget);
6253 signal_num = KEY_PRESS_EVENT;
6255 case GDK_KEY_RELEASE:
6256 signal_num = KEY_RELEASE_EVENT;
6258 case GDK_ENTER_NOTIFY:
6259 signal_num = ENTER_NOTIFY_EVENT;
6261 case GDK_LEAVE_NOTIFY:
6262 signal_num = LEAVE_NOTIFY_EVENT;
6264 case GDK_FOCUS_CHANGE:
6265 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6266 if (event->focus_change.in)
6267 _gtk_tooltip_focus_in (widget);
6269 _gtk_tooltip_focus_out (widget);
6272 signal_num = CONFIGURE_EVENT;
6275 signal_num = MAP_EVENT;
6278 signal_num = UNMAP_EVENT;
6280 case GDK_WINDOW_STATE:
6281 signal_num = WINDOW_STATE_EVENT;
6283 case GDK_PROPERTY_NOTIFY:
6284 signal_num = PROPERTY_NOTIFY_EVENT;
6286 case GDK_SELECTION_CLEAR:
6287 signal_num = SELECTION_CLEAR_EVENT;
6289 case GDK_SELECTION_REQUEST:
6290 signal_num = SELECTION_REQUEST_EVENT;
6292 case GDK_SELECTION_NOTIFY:
6293 signal_num = SELECTION_NOTIFY_EVENT;
6295 case GDK_PROXIMITY_IN:
6296 signal_num = PROXIMITY_IN_EVENT;
6298 case GDK_PROXIMITY_OUT:
6299 signal_num = PROXIMITY_OUT_EVENT;
6301 case GDK_VISIBILITY_NOTIFY:
6302 signal_num = VISIBILITY_NOTIFY_EVENT;
6304 case GDK_GRAB_BROKEN:
6305 signal_num = GRAB_BROKEN_EVENT;
6308 signal_num = DAMAGE_EVENT;
6311 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6315 if (signal_num != -1)
6316 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6318 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6319 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6323 g_object_unref (widget);
6329 * gtk_widget_activate:
6330 * @widget: a #GtkWidget that's activatable
6332 * For widgets that can be "activated" (buttons, menu items, etc.)
6333 * this function activates them. Activation is what happens when you
6334 * press Enter on a widget during key navigation. If @widget isn't
6335 * activatable, the function returns %FALSE.
6337 * Return value: %TRUE if the widget was activatable
6340 gtk_widget_activate (GtkWidget *widget)
6342 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6344 if (WIDGET_CLASS (widget)->activate_signal)
6346 /* FIXME: we should eventually check the signals signature here */
6347 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6356 gtk_widget_reparent_subwindows (GtkWidget *widget,
6357 GdkWindow *new_window)
6359 GtkWidgetPrivate *priv = widget->priv;
6361 if (!gtk_widget_get_has_window (widget))
6363 GList *children = gdk_window_get_children (priv->window);
6366 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6368 GdkWindow *window = tmp_list->data;
6371 gdk_window_get_user_data (window, &child);
6372 while (child && child != widget)
6373 child = ((GtkWidget*) child)->priv->parent;
6376 gdk_window_reparent (window, new_window, 0, 0);
6379 g_list_free (children);
6384 GList *tmp_list, *children;
6386 parent = gdk_window_get_parent (priv->window);
6389 gdk_window_reparent (priv->window, new_window, 0, 0);
6392 children = gdk_window_get_children (parent);
6394 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6396 GdkWindow *window = tmp_list->data;
6399 gdk_window_get_user_data (window, &child);
6401 if (child == widget)
6402 gdk_window_reparent (window, new_window, 0, 0);
6405 g_list_free (children);
6411 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6412 gpointer client_data)
6414 GtkWidgetPrivate *priv = widget->priv;
6416 g_assert (client_data != NULL);
6418 if (!gtk_widget_get_has_window (widget))
6421 g_object_unref (priv->window);
6422 priv->window = (GdkWindow*) client_data;
6424 g_object_ref (priv->window);
6426 if (GTK_IS_CONTAINER (widget))
6427 gtk_container_forall (GTK_CONTAINER (widget),
6428 gtk_widget_reparent_fixup_child,
6434 * gtk_widget_reparent:
6435 * @widget: a #GtkWidget
6436 * @new_parent: a #GtkContainer to move the widget into
6438 * Moves a widget from one #GtkContainer to another, handling reference
6439 * count issues to avoid destroying the widget.
6442 gtk_widget_reparent (GtkWidget *widget,
6443 GtkWidget *new_parent)
6445 GtkWidgetPrivate *priv;
6447 g_return_if_fail (GTK_IS_WIDGET (widget));
6448 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6449 priv = widget->priv;
6450 g_return_if_fail (priv->parent != NULL);
6452 if (priv->parent != new_parent)
6454 /* First try to see if we can get away without unrealizing
6455 * the widget as we reparent it. if so we set a flag so
6456 * that gtk_widget_unparent doesn't unrealize widget
6458 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6459 priv->in_reparent = TRUE;
6461 g_object_ref (widget);
6462 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6463 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6464 g_object_unref (widget);
6466 if (priv->in_reparent)
6468 priv->in_reparent = FALSE;
6470 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6471 gtk_widget_reparent_fixup_child (widget,
6472 gtk_widget_get_parent_window (widget));
6475 g_object_notify (G_OBJECT (widget), "parent");
6480 * gtk_widget_intersect:
6481 * @widget: a #GtkWidget
6482 * @area: a rectangle
6483 * @intersection: rectangle to store intersection of @widget and @area
6485 * Computes the intersection of a @widget's area and @area, storing
6486 * the intersection in @intersection, and returns %TRUE if there was
6487 * an intersection. @intersection may be %NULL if you're only
6488 * interested in whether there was an intersection.
6490 * Return value: %TRUE if there was an intersection
6493 gtk_widget_intersect (GtkWidget *widget,
6494 const GdkRectangle *area,
6495 GdkRectangle *intersection)
6497 GtkWidgetPrivate *priv;
6502 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6503 g_return_val_if_fail (area != NULL, FALSE);
6505 priv = widget->priv;
6508 dest = intersection;
6512 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6514 if (return_val && intersection && gtk_widget_get_has_window (widget))
6516 intersection->x -= priv->allocation.x;
6517 intersection->y -= priv->allocation.y;
6524 * gtk_widget_region_intersect:
6525 * @widget: a #GtkWidget
6526 * @region: a #cairo_region_t, in the same coordinate system as
6527 * @widget->allocation. That is, relative to @widget->window
6528 * for %NO_WINDOW widgets; relative to the parent window
6529 * of @widget->window for widgets with their own window.
6531 * Computes the intersection of a @widget's area and @region, returning
6532 * the intersection. The result may be empty, use cairo_region_is_empty() to
6535 * Returns: A newly allocated region holding the intersection of @widget
6536 * and @region. The coordinates of the return value are relative to
6537 * @widget->window for %NO_WINDOW widgets, and relative to the parent
6538 * window of @widget->window for widgets with their own window.
6541 gtk_widget_region_intersect (GtkWidget *widget,
6542 const cairo_region_t *region)
6545 cairo_region_t *dest;
6547 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6548 g_return_val_if_fail (region != NULL, NULL);
6550 gtk_widget_get_allocation (widget, &rect);
6552 dest = cairo_region_create_rectangle (&rect);
6554 cairo_region_intersect (dest, region);
6560 * _gtk_widget_grab_notify:
6561 * @widget: a #GtkWidget
6562 * @was_grabbed: whether a grab is now in effect
6564 * Emits the #GtkWidget::grab-notify signal on @widget.
6569 _gtk_widget_grab_notify (GtkWidget *widget,
6570 gboolean was_grabbed)
6572 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6576 * gtk_widget_grab_focus:
6577 * @widget: a #GtkWidget
6579 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6580 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6581 * something like #GtkFrame won't work.
6583 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6584 * gtk_widget_set_can_focus() to modify that flag.
6586 * The widget also needs to be realized and mapped. This is indicated by the
6587 * related signals. Grabbing the focus immediately after creating the widget
6588 * will likely fail and cause critical warnings.
6591 gtk_widget_grab_focus (GtkWidget *widget)
6593 g_return_if_fail (GTK_IS_WIDGET (widget));
6595 if (!gtk_widget_is_sensitive (widget))
6598 g_object_ref (widget);
6599 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6600 g_object_notify (G_OBJECT (widget), "has-focus");
6601 g_object_unref (widget);
6605 reset_focus_recurse (GtkWidget *widget,
6608 if (GTK_IS_CONTAINER (widget))
6610 GtkContainer *container;
6612 container = GTK_CONTAINER (widget);
6613 gtk_container_set_focus_child (container, NULL);
6615 gtk_container_foreach (container,
6616 reset_focus_recurse,
6622 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6624 if (gtk_widget_get_can_focus (focus_widget))
6626 GtkWidget *toplevel;
6629 /* clear the current focus setting, break if the current widget
6630 * is the focus widget's parent, since containers above that will
6631 * be set by the next loop.
6633 toplevel = gtk_widget_get_toplevel (focus_widget);
6634 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6636 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6638 if (widget == focus_widget)
6640 /* We call _gtk_window_internal_set_focus() here so that the
6641 * toplevel window can request the focus if necessary.
6642 * This is needed when the toplevel is a GtkPlug
6644 if (!gtk_widget_has_focus (widget))
6645 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6652 GtkWidget *common_ancestor = gtk_widget_common_ancestor (widget, focus_widget);
6654 if (widget != common_ancestor)
6656 while (widget->priv->parent && widget->priv->parent != common_ancestor)
6658 widget = widget->priv->parent;
6659 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6664 else if (toplevel != focus_widget)
6666 /* gtk_widget_grab_focus() operates on a tree without window...
6667 * actually, this is very questionable behaviour.
6670 gtk_container_foreach (GTK_CONTAINER (toplevel),
6671 reset_focus_recurse,
6675 /* now propagate the new focus up the widget tree and finally
6676 * set it on the window
6678 widget = focus_widget;
6679 while (widget->priv->parent)
6681 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6682 widget = widget->priv->parent;
6684 if (GTK_IS_WINDOW (widget))
6685 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6690 gtk_widget_real_query_tooltip (GtkWidget *widget,
6693 gboolean keyboard_tip,
6694 GtkTooltip *tooltip)
6696 gchar *tooltip_markup;
6697 gboolean has_tooltip;
6699 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6700 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6702 if (has_tooltip && tooltip_markup)
6704 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6712 gtk_widget_real_state_flags_changed (GtkWidget *widget,
6713 GtkStateFlags old_state)
6715 gtk_widget_update_pango_context (widget);
6719 gtk_widget_real_style_updated (GtkWidget *widget)
6721 GtkWidgetPrivate *priv = widget->priv;
6723 gtk_widget_update_pango_context (widget);
6725 if (priv->style != NULL &&
6726 priv->style != gtk_widget_get_default_style ())
6728 /* Trigger ::style-set for old
6729 * widgets not listening to this
6731 g_signal_emit (widget,
6732 widget_signals[STYLE_SET],
6734 widget->priv->style);
6737 if (widget->priv->context)
6739 if (gtk_widget_get_realized (widget) &&
6740 gtk_widget_get_has_window (widget) &&
6741 !gtk_widget_get_app_paintable (widget))
6742 gtk_style_context_set_background (widget->priv->context,
6743 widget->priv->window);
6746 if (widget->priv->anchored)
6747 gtk_widget_queue_resize (widget);
6751 gtk_widget_real_show_help (GtkWidget *widget,
6752 GtkWidgetHelpType help_type)
6754 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6756 _gtk_tooltip_toggle_keyboard_mode (widget);
6765 gtk_widget_real_focus (GtkWidget *widget,
6766 GtkDirectionType direction)
6768 if (!gtk_widget_get_can_focus (widget))
6771 if (!gtk_widget_is_focus (widget))
6773 gtk_widget_grab_focus (widget);
6781 gtk_widget_real_move_focus (GtkWidget *widget,
6782 GtkDirectionType direction)
6784 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6786 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6788 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6794 gtk_widget_real_keynav_failed (GtkWidget *widget,
6795 GtkDirectionType direction)
6797 gboolean cursor_only;
6801 case GTK_DIR_TAB_FORWARD:
6802 case GTK_DIR_TAB_BACKWARD:
6809 g_object_get (gtk_widget_get_settings (widget),
6810 "gtk-keynav-cursor-only", &cursor_only,
6817 gtk_widget_error_bell (widget);
6823 * gtk_widget_set_can_focus:
6824 * @widget: a #GtkWidget
6825 * @can_focus: whether or not @widget can own the input focus.
6827 * Specifies whether @widget can own the input focus. See
6828 * gtk_widget_grab_focus() for actually setting the input focus on a
6834 gtk_widget_set_can_focus (GtkWidget *widget,
6837 g_return_if_fail (GTK_IS_WIDGET (widget));
6839 if (widget->priv->can_focus != can_focus)
6841 widget->priv->can_focus = can_focus;
6843 gtk_widget_queue_resize (widget);
6844 g_object_notify (G_OBJECT (widget), "can-focus");
6849 * gtk_widget_get_can_focus:
6850 * @widget: a #GtkWidget
6852 * Determines whether @widget can own the input focus. See
6853 * gtk_widget_set_can_focus().
6855 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6860 gtk_widget_get_can_focus (GtkWidget *widget)
6862 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6864 return widget->priv->can_focus;
6868 * gtk_widget_has_focus:
6869 * @widget: a #GtkWidget
6871 * Determines if the widget has the global input focus. See
6872 * gtk_widget_is_focus() for the difference between having the global
6873 * input focus, and only having the focus within a toplevel.
6875 * Return value: %TRUE if the widget has the global input focus.
6880 gtk_widget_has_focus (GtkWidget *widget)
6882 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6884 return widget->priv->has_focus;
6888 * gtk_widget_has_visible_focus:
6889 * @widget: a #GtkWidget
6891 * Determines if the widget should show a visible indication that
6892 * it has the global input focus. This is a convenience function for
6893 * use in ::draw handlers that takes into account whether focus
6894 * indication should currently be shown in the toplevel window of
6895 * @widget. See gtk_window_get_focus_visible() for more information
6896 * about focus indication.
6898 * To find out if the widget has the global input focus, use
6899 * gtk_widget_has_focus().
6901 * Return value: %TRUE if the widget should display a 'focus rectangle'
6906 gtk_widget_has_visible_focus (GtkWidget *widget)
6908 gboolean draw_focus;
6910 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6912 if (widget->priv->has_focus)
6914 GtkWidget *toplevel;
6916 toplevel = gtk_widget_get_toplevel (widget);
6918 if (GTK_IS_WINDOW (toplevel))
6919 draw_focus = gtk_window_get_focus_visible (GTK_WINDOW (toplevel));
6930 * gtk_widget_is_focus:
6931 * @widget: a #GtkWidget
6933 * Determines if the widget is the focus widget within its
6934 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6935 * necessarily set; %HAS_FOCUS will only be set if the
6936 * toplevel widget additionally has the global input focus.)
6938 * Return value: %TRUE if the widget is the focus widget.
6941 gtk_widget_is_focus (GtkWidget *widget)
6943 GtkWidget *toplevel;
6945 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6947 toplevel = gtk_widget_get_toplevel (widget);
6949 if (GTK_IS_WINDOW (toplevel))
6950 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6956 * gtk_widget_set_can_default:
6957 * @widget: a #GtkWidget
6958 * @can_default: whether or not @widget can be a default widget.
6960 * Specifies whether @widget can be a default widget. See
6961 * gtk_widget_grab_default() for details about the meaning of
6967 gtk_widget_set_can_default (GtkWidget *widget,
6968 gboolean can_default)
6970 g_return_if_fail (GTK_IS_WIDGET (widget));
6972 if (widget->priv->can_default != can_default)
6974 widget->priv->can_default = can_default;
6976 gtk_widget_queue_resize (widget);
6977 g_object_notify (G_OBJECT (widget), "can-default");
6982 * gtk_widget_get_can_default:
6983 * @widget: a #GtkWidget
6985 * Determines whether @widget can be a default widget. See
6986 * gtk_widget_set_can_default().
6988 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6993 gtk_widget_get_can_default (GtkWidget *widget)
6995 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6997 return widget->priv->can_default;
7001 * gtk_widget_has_default:
7002 * @widget: a #GtkWidget
7004 * Determines whether @widget is the current default widget within its
7005 * toplevel. See gtk_widget_set_can_default().
7007 * Return value: %TRUE if @widget is the current default widget within
7008 * its toplevel, %FALSE otherwise
7013 gtk_widget_has_default (GtkWidget *widget)
7015 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7017 return widget->priv->has_default;
7021 _gtk_widget_set_has_default (GtkWidget *widget,
7022 gboolean has_default)
7024 GtkStyleContext *context;
7026 widget->priv->has_default = has_default;
7028 context = gtk_widget_get_style_context (widget);
7031 gtk_style_context_add_class (context, GTK_STYLE_CLASS_DEFAULT);
7033 gtk_style_context_remove_class (context, GTK_STYLE_CLASS_DEFAULT);
7037 * gtk_widget_grab_default:
7038 * @widget: a #GtkWidget
7040 * Causes @widget to become the default widget. @widget must be able to be
7041 * a default widget; typically you would ensure this yourself
7042 * by calling gtk_widget_set_can_default() with a %TRUE value.
7043 * The default widget is activated when
7044 * the user presses Enter in a window. Default widgets must be
7045 * activatable, that is, gtk_widget_activate() should affect them. Note
7046 * that #GtkEntry widgets require the "activates-default" property
7047 * set to %TRUE before they activate the default widget when Enter
7048 * is pressed and the #GtkEntry is focused.
7051 gtk_widget_grab_default (GtkWidget *widget)
7055 g_return_if_fail (GTK_IS_WIDGET (widget));
7056 g_return_if_fail (gtk_widget_get_can_default (widget));
7058 window = gtk_widget_get_toplevel (widget);
7060 if (window && gtk_widget_is_toplevel (window))
7061 gtk_window_set_default (GTK_WINDOW (window), widget);
7063 g_warning (G_STRLOC ": widget not within a GtkWindow");
7067 * gtk_widget_set_receives_default:
7068 * @widget: a #GtkWidget
7069 * @receives_default: whether or not @widget can be a default widget.
7071 * Specifies whether @widget will be treated as the default widget
7072 * within its toplevel when it has the focus, even if another widget
7075 * See gtk_widget_grab_default() for details about the meaning of
7081 gtk_widget_set_receives_default (GtkWidget *widget,
7082 gboolean receives_default)
7084 g_return_if_fail (GTK_IS_WIDGET (widget));
7086 if (widget->priv->receives_default != receives_default)
7088 widget->priv->receives_default = receives_default;
7090 g_object_notify (G_OBJECT (widget), "receives-default");
7095 * gtk_widget_get_receives_default:
7096 * @widget: a #GtkWidget
7098 * Determines whether @widget is alyways treated as default widget
7099 * withing its toplevel when it has the focus, even if another widget
7102 * See gtk_widget_set_receives_default().
7104 * Return value: %TRUE if @widget acts as default widget when focussed,
7110 gtk_widget_get_receives_default (GtkWidget *widget)
7112 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7114 return widget->priv->receives_default;
7118 * gtk_widget_has_grab:
7119 * @widget: a #GtkWidget
7121 * Determines whether the widget is currently grabbing events, so it
7122 * is the only widget receiving input events (keyboard and mouse).
7124 * See also gtk_grab_add().
7126 * Return value: %TRUE if the widget is in the grab_widgets stack
7131 gtk_widget_has_grab (GtkWidget *widget)
7133 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7135 return widget->priv->has_grab;
7139 _gtk_widget_set_has_grab (GtkWidget *widget,
7142 widget->priv->has_grab = has_grab;
7146 * gtk_widget_device_is_shadowed:
7147 * @widget: a #GtkWidget
7148 * @device: a #GdkDevice
7150 * Returns %TRUE if @device has been shadowed by a GTK+
7151 * device grab on another widget, so it would stop sending
7152 * events to @widget. This may be used in the
7153 * #GtkWidget::grab-notify signal to check for specific
7154 * devices. See gtk_device_grab_add().
7156 * Returns: %TRUE if there is an ongoing grab on @device
7157 * by another #GtkWidget than @widget.
7162 gtk_widget_device_is_shadowed (GtkWidget *widget,
7165 GtkWindowGroup *group;
7166 GtkWidget *grab_widget, *toplevel;
7168 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7169 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
7171 if (!gtk_widget_get_realized (widget))
7174 toplevel = gtk_widget_get_toplevel (widget);
7176 if (GTK_IS_WINDOW (toplevel))
7177 group = gtk_window_get_group (GTK_WINDOW (toplevel));
7179 group = gtk_window_get_group (NULL);
7181 grab_widget = gtk_window_group_get_current_device_grab (group, device);
7183 /* Widget not inside the hierarchy of grab_widget */
7185 widget != grab_widget &&
7186 !gtk_widget_is_ancestor (widget, grab_widget))
7189 grab_widget = gtk_window_group_get_current_grab (group);
7190 if (grab_widget && widget != grab_widget &&
7191 !gtk_widget_is_ancestor (widget, grab_widget))
7198 * gtk_widget_set_name:
7199 * @widget: a #GtkWidget
7200 * @name: name for the widget
7202 * Widgets can be named, which allows you to refer to them from a
7203 * CSS file. You can apply a style to widgets with a particular name
7204 * in the CSS file. See the documentation for the CSS syntax (on the
7205 * same page as the docs for #GtkStyleContext).
7207 * Note that the CSS syntax has certain special characters to delimit
7208 * and represent elements in a selector (period, #, >, *...),
7209 * so using these will make your widget impossible to match by name.
7210 * Any combination of alphanumeric symbols, dashes and underscores will
7214 gtk_widget_set_name (GtkWidget *widget,
7217 GtkWidgetPrivate *priv;
7220 g_return_if_fail (GTK_IS_WIDGET (widget));
7222 priv = widget->priv;
7224 new_name = g_strdup (name);
7225 g_free (priv->name);
7226 priv->name = new_name;
7228 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_NAME);
7230 g_object_notify (G_OBJECT (widget), "name");
7234 * gtk_widget_get_name:
7235 * @widget: a #GtkWidget
7237 * Retrieves the name of a widget. See gtk_widget_set_name() for the
7238 * significance of widget names.
7240 * Return value: name of the widget. This string is owned by GTK+ and
7241 * should not be modified or freed
7244 gtk_widget_get_name (GtkWidget *widget)
7246 GtkWidgetPrivate *priv;
7248 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7250 priv = widget->priv;
7254 return G_OBJECT_TYPE_NAME (widget);
7258 _gtk_widget_update_state_flags (GtkWidget *widget,
7259 GtkStateFlags flags,
7262 GtkWidgetPrivate *priv;
7264 priv = widget->priv;
7266 /* Handle insensitive first, since it is propagated
7267 * differently throughout the widget hierarchy.
7269 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_UNSET))
7270 gtk_widget_set_sensitive (widget, TRUE);
7271 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation != STATE_CHANGE_UNSET))
7272 gtk_widget_set_sensitive (widget, FALSE);
7273 else if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && !(flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_REPLACE))
7274 gtk_widget_set_sensitive (widget, TRUE);
7276 if (operation != STATE_CHANGE_REPLACE)
7277 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
7280 operation == STATE_CHANGE_REPLACE)
7285 data.operation = operation;
7287 gtk_widget_propagate_state (widget, &data);
7289 gtk_widget_queue_resize (widget);
7294 * gtk_widget_set_state_flags:
7295 * @widget: a #GtkWidget
7296 * @flags: State flags to turn on
7297 * @clear: Whether to clear state before turning on @flags
7299 * This function is for use in widget implementations. Turns on flag
7300 * values in the current widget state (insensitive, prelighted, etc.).
7302 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7303 * will be propagated down to all non-internal children if @widget is a
7304 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7305 * down to all #GtkContainer children by different means than turning on the
7306 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7307 * gtk_widget_is_sensitive() will make use of these.
7312 gtk_widget_set_state_flags (GtkWidget *widget,
7313 GtkStateFlags flags,
7316 g_return_if_fail (GTK_IS_WIDGET (widget));
7318 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7319 (clear && widget->priv->state_flags == flags))
7323 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7325 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
7329 * gtk_widget_unset_state_flags:
7330 * @widget: a #GtkWidget
7331 * @flags: State flags to turn off
7333 * This function is for use in widget implementations. Turns off flag
7334 * values for the current widget state (insensitive, prelighted, etc.).
7335 * See gtk_widget_set_state_flags().
7340 gtk_widget_unset_state_flags (GtkWidget *widget,
7341 GtkStateFlags flags)
7343 g_return_if_fail (GTK_IS_WIDGET (widget));
7345 if ((widget->priv->state_flags & flags) == 0)
7348 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
7352 * gtk_widget_get_state_flags:
7353 * @widget: a #GtkWidget
7355 * Returns the widget state as a flag set. It is worth mentioning
7356 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7357 * returned, that is, also based on parent insensitivity, even if
7358 * @widget itself is sensitive.
7360 * Returns: The state flags for widget
7365 gtk_widget_get_state_flags (GtkWidget *widget)
7367 GtkStateFlags flags;
7369 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7371 flags = widget->priv->state_flags;
7373 if (gtk_widget_has_focus (widget))
7374 flags |= GTK_STATE_FLAG_FOCUSED;
7380 * gtk_widget_set_state:
7381 * @widget: a #GtkWidget
7382 * @state: new state for @widget
7384 * This function is for use in widget implementations. Sets the state
7385 * of a widget (insensitive, prelighted, etc.) Usually you should set
7386 * the state using wrapper functions such as gtk_widget_set_sensitive().
7388 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7391 gtk_widget_set_state (GtkWidget *widget,
7394 GtkStateFlags flags;
7396 if (state == gtk_widget_get_state (widget))
7401 case GTK_STATE_ACTIVE:
7402 flags = GTK_STATE_FLAG_ACTIVE;
7404 case GTK_STATE_PRELIGHT:
7405 flags = GTK_STATE_FLAG_PRELIGHT;
7407 case GTK_STATE_SELECTED:
7408 flags = GTK_STATE_FLAG_SELECTED;
7410 case GTK_STATE_INSENSITIVE:
7411 flags = GTK_STATE_FLAG_INSENSITIVE;
7413 case GTK_STATE_INCONSISTENT:
7414 flags = GTK_STATE_FLAG_INCONSISTENT;
7416 case GTK_STATE_FOCUSED:
7417 flags = GTK_STATE_FLAG_FOCUSED;
7419 case GTK_STATE_NORMAL:
7425 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7429 * gtk_widget_get_state:
7430 * @widget: a #GtkWidget
7432 * Returns the widget's state. See gtk_widget_set_state().
7434 * Returns: the state of @widget.
7438 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7441 gtk_widget_get_state (GtkWidget *widget)
7443 GtkStateFlags flags;
7445 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7447 flags = gtk_widget_get_state_flags (widget);
7449 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7450 return GTK_STATE_INSENSITIVE;
7451 else if (flags & GTK_STATE_FLAG_ACTIVE)
7452 return GTK_STATE_ACTIVE;
7453 else if (flags & GTK_STATE_FLAG_SELECTED)
7454 return GTK_STATE_SELECTED;
7455 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7456 return GTK_STATE_PRELIGHT;
7458 return GTK_STATE_NORMAL;
7462 * gtk_widget_set_visible:
7463 * @widget: a #GtkWidget
7464 * @visible: whether the widget should be shown or not
7466 * Sets the visibility state of @widget. Note that setting this to
7467 * %TRUE doesn't mean the widget is actually viewable, see
7468 * gtk_widget_get_visible().
7470 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7471 * but is nicer to use when the visibility of the widget depends on
7477 gtk_widget_set_visible (GtkWidget *widget,
7480 g_return_if_fail (GTK_IS_WIDGET (widget));
7482 if (visible != gtk_widget_get_visible (widget))
7485 gtk_widget_show (widget);
7487 gtk_widget_hide (widget);
7492 _gtk_widget_set_visible_flag (GtkWidget *widget,
7495 widget->priv->visible = visible;
7499 * gtk_widget_get_visible:
7500 * @widget: a #GtkWidget
7502 * Determines whether the widget is visible. Note that this doesn't
7503 * take into account whether the widget's parent is also visible
7504 * or the widget is obscured in any way.
7506 * See gtk_widget_set_visible().
7508 * Return value: %TRUE if the widget is visible
7513 gtk_widget_get_visible (GtkWidget *widget)
7515 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7517 return widget->priv->visible;
7521 * gtk_widget_set_has_window:
7522 * @widget: a #GtkWidget
7523 * @has_window: whether or not @widget has a window.
7525 * Specifies whether @widget has a #GdkWindow of its own. Note that
7526 * all realized widgets have a non-%NULL "window" pointer
7527 * (gtk_widget_get_window() never returns a %NULL window when a widget
7528 * is realized), but for many of them it's actually the #GdkWindow of
7529 * one of its parent widgets. Widgets that do not create a %window for
7530 * themselves in #GtkWidget::realize must announce this by
7531 * calling this function with @has_window = %FALSE.
7533 * This function should only be called by widget implementations,
7534 * and they should call it in their init() function.
7539 gtk_widget_set_has_window (GtkWidget *widget,
7540 gboolean has_window)
7542 g_return_if_fail (GTK_IS_WIDGET (widget));
7544 widget->priv->no_window = !has_window;
7548 * gtk_widget_get_has_window:
7549 * @widget: a #GtkWidget
7551 * Determines whether @widget has a #GdkWindow of its own. See
7552 * gtk_widget_set_has_window().
7554 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7559 gtk_widget_get_has_window (GtkWidget *widget)
7561 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7563 return ! widget->priv->no_window;
7567 * gtk_widget_is_toplevel:
7568 * @widget: a #GtkWidget
7570 * Determines whether @widget is a toplevel widget.
7572 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7573 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7576 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7581 gtk_widget_is_toplevel (GtkWidget *widget)
7583 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7585 return widget->priv->toplevel;
7589 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7590 gboolean is_toplevel)
7592 widget->priv->toplevel = is_toplevel;
7596 * gtk_widget_is_drawable:
7597 * @widget: a #GtkWidget
7599 * Determines whether @widget can be drawn to. A widget can be drawn
7600 * to if it is mapped and visible.
7602 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7607 gtk_widget_is_drawable (GtkWidget *widget)
7609 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7611 return (gtk_widget_get_visible (widget) &&
7612 gtk_widget_get_mapped (widget));
7616 * gtk_widget_get_realized:
7617 * @widget: a #GtkWidget
7619 * Determines whether @widget is realized.
7621 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7626 gtk_widget_get_realized (GtkWidget *widget)
7628 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7630 return widget->priv->realized;
7634 * gtk_widget_set_realized:
7635 * @widget: a #GtkWidget
7636 * @realized: %TRUE to mark the widget as realized
7638 * Marks the widget as being realized.
7640 * This function should only ever be called in a derived widget's
7641 * "realize" or "unrealize" implementation.
7646 gtk_widget_set_realized (GtkWidget *widget,
7649 g_return_if_fail (GTK_IS_WIDGET (widget));
7651 widget->priv->realized = realized;
7655 * gtk_widget_get_mapped:
7656 * @widget: a #GtkWidget
7658 * Whether the widget is mapped.
7660 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7665 gtk_widget_get_mapped (GtkWidget *widget)
7667 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7669 return widget->priv->mapped;
7673 * gtk_widget_set_mapped:
7674 * @widget: a #GtkWidget
7675 * @mapped: %TRUE to mark the widget as mapped
7677 * Marks the widget as being realized.
7679 * This function should only ever be called in a derived widget's
7680 * "map" or "unmap" implementation.
7685 gtk_widget_set_mapped (GtkWidget *widget,
7688 g_return_if_fail (GTK_IS_WIDGET (widget));
7690 widget->priv->mapped = mapped;
7694 * gtk_widget_set_app_paintable:
7695 * @widget: a #GtkWidget
7696 * @app_paintable: %TRUE if the application will paint on the widget
7698 * Sets whether the application intends to draw on the widget in
7699 * an #GtkWidget::draw handler.
7701 * This is a hint to the widget and does not affect the behavior of
7702 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7703 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7704 * the effect is to suppress default themed drawing of the widget's
7705 * background. (Children of the widget will still be drawn.) The application
7706 * is then entirely responsible for drawing the widget background.
7708 * Note that the background is still drawn when the widget is mapped.
7711 gtk_widget_set_app_paintable (GtkWidget *widget,
7712 gboolean app_paintable)
7714 g_return_if_fail (GTK_IS_WIDGET (widget));
7716 app_paintable = (app_paintable != FALSE);
7718 if (widget->priv->app_paintable != app_paintable)
7720 widget->priv->app_paintable = app_paintable;
7722 if (gtk_widget_is_drawable (widget))
7723 gtk_widget_queue_draw (widget);
7725 g_object_notify (G_OBJECT (widget), "app-paintable");
7730 * gtk_widget_get_app_paintable:
7731 * @widget: a #GtkWidget
7733 * Determines whether the application intends to draw on the widget in
7734 * an #GtkWidget::draw handler.
7736 * See gtk_widget_set_app_paintable()
7738 * Return value: %TRUE if the widget is app paintable
7743 gtk_widget_get_app_paintable (GtkWidget *widget)
7745 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7747 return widget->priv->app_paintable;
7751 * gtk_widget_set_double_buffered:
7752 * @widget: a #GtkWidget
7753 * @double_buffered: %TRUE to double-buffer a widget
7755 * Widgets are double buffered by default; you can use this function
7756 * to turn off the buffering. "Double buffered" simply means that
7757 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7758 * automatically around expose events sent to the
7759 * widget. gdk_window_begin_paint_region() diverts all drawing to a widget's
7760 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7761 * buffer to the screen. The result is that users see the window
7762 * update in one smooth step, and don't see individual graphics
7763 * primitives being rendered.
7765 * In very simple terms, double buffered widgets don't flicker,
7766 * so you would only use this function to turn off double buffering
7767 * if you had special needs and really knew what you were doing.
7769 * Note: if you turn off double-buffering, you have to handle
7770 * expose events, since even the clearing to the background color or
7771 * pixmap will not happen automatically (as it is done in
7772 * gdk_window_begin_paint_region()).
7775 gtk_widget_set_double_buffered (GtkWidget *widget,
7776 gboolean double_buffered)
7778 g_return_if_fail (GTK_IS_WIDGET (widget));
7780 double_buffered = (double_buffered != FALSE);
7782 if (widget->priv->double_buffered != double_buffered)
7784 widget->priv->double_buffered = double_buffered;
7786 g_object_notify (G_OBJECT (widget), "double-buffered");
7791 * gtk_widget_get_double_buffered:
7792 * @widget: a #GtkWidget
7794 * Determines whether the widget is double buffered.
7796 * See gtk_widget_set_double_buffered()
7798 * Return value: %TRUE if the widget is double buffered
7803 gtk_widget_get_double_buffered (GtkWidget *widget)
7805 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7807 return widget->priv->double_buffered;
7811 * gtk_widget_set_redraw_on_allocate:
7812 * @widget: a #GtkWidget
7813 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7814 * when it is allocated to a new size. Otherwise, only the
7815 * new portion of the widget will be redrawn.
7817 * Sets whether the entire widget is queued for drawing when its size
7818 * allocation changes. By default, this setting is %TRUE and
7819 * the entire widget is redrawn on every size change. If your widget
7820 * leaves the upper left unchanged when made bigger, turning this
7821 * setting off will improve performance.
7823 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7824 * off all allocation on resizing: the widget will not even redraw if
7825 * its position changes; this is to allow containers that don't draw
7826 * anything to avoid excess invalidations. If you set this flag on a
7827 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7828 * you are responsible for invalidating both the old and new allocation
7829 * of the widget when the widget is moved and responsible for invalidating
7830 * regions newly when the widget increases size.
7833 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7834 gboolean redraw_on_allocate)
7836 g_return_if_fail (GTK_IS_WIDGET (widget));
7838 widget->priv->redraw_on_alloc = redraw_on_allocate;
7842 * gtk_widget_set_sensitive:
7843 * @widget: a #GtkWidget
7844 * @sensitive: %TRUE to make the widget sensitive
7846 * Sets the sensitivity of a widget. A widget is sensitive if the user
7847 * can interact with it. Insensitive widgets are "grayed out" and the
7848 * user can't interact with them. Insensitive widgets are known as
7849 * "inactive", "disabled", or "ghosted" in some other toolkits.
7852 gtk_widget_set_sensitive (GtkWidget *widget,
7855 GtkWidgetPrivate *priv;
7857 g_return_if_fail (GTK_IS_WIDGET (widget));
7859 priv = widget->priv;
7861 sensitive = (sensitive != FALSE);
7863 if (priv->sensitive == sensitive)
7866 priv->sensitive = sensitive;
7868 if (priv->parent == NULL
7869 || gtk_widget_is_sensitive (priv->parent))
7873 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7876 data.operation = STATE_CHANGE_UNSET;
7878 data.operation = STATE_CHANGE_SET;
7880 gtk_widget_propagate_state (widget, &data);
7882 gtk_widget_queue_resize (widget);
7885 g_object_notify (G_OBJECT (widget), "sensitive");
7889 * gtk_widget_get_sensitive:
7890 * @widget: a #GtkWidget
7892 * Returns the widget's sensitivity (in the sense of returning
7893 * the value that has been set using gtk_widget_set_sensitive()).
7895 * The effective sensitivity of a widget is however determined by both its
7896 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7898 * Returns: %TRUE if the widget is sensitive
7903 gtk_widget_get_sensitive (GtkWidget *widget)
7905 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7907 return widget->priv->sensitive;
7911 * gtk_widget_is_sensitive:
7912 * @widget: a #GtkWidget
7914 * Returns the widget's effective sensitivity, which means
7915 * it is sensitive itself and also its parent widget is sensitive
7917 * Returns: %TRUE if the widget is effectively sensitive
7922 gtk_widget_is_sensitive (GtkWidget *widget)
7924 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7926 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
7930 * gtk_widget_set_parent:
7931 * @widget: a #GtkWidget
7932 * @parent: parent container
7934 * This function is useful only when implementing subclasses of
7936 * Sets the container as the parent of @widget, and takes care of
7937 * some details such as updating the state and style of the child
7938 * to reflect its new location. The opposite function is
7939 * gtk_widget_unparent().
7942 gtk_widget_set_parent (GtkWidget *widget,
7945 GtkStateFlags parent_flags;
7946 GtkWidgetPrivate *priv;
7949 g_return_if_fail (GTK_IS_WIDGET (widget));
7950 g_return_if_fail (GTK_IS_WIDGET (parent));
7951 g_return_if_fail (widget != parent);
7953 priv = widget->priv;
7955 if (priv->parent != NULL)
7957 g_warning ("Can't set a parent on widget which has a parent\n");
7960 if (gtk_widget_is_toplevel (widget))
7962 g_warning ("Can't set a parent on a toplevel widget\n");
7966 /* keep this function in sync with gtk_menu_attach_to_widget()
7969 g_object_ref_sink (widget);
7971 gtk_widget_push_verify_invariants (widget);
7973 priv->parent = parent;
7975 parent_flags = gtk_widget_get_state_flags (parent);
7977 /* Merge both old state and current parent state,
7978 * making sure to only propagate the right states */
7979 data.flags = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
7980 data.flags |= priv->state_flags;
7982 data.operation = STATE_CHANGE_REPLACE;
7983 gtk_widget_propagate_state (widget, &data);
7986 gtk_style_context_set_parent (priv->context,
7987 gtk_widget_get_style_context (parent));
7989 _gtk_widget_update_parent_muxer (widget);
7991 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7992 if (priv->parent->priv->anchored)
7993 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7994 g_object_notify (G_OBJECT (widget), "parent");
7996 /* Enforce realized/mapped invariants
7998 if (gtk_widget_get_realized (priv->parent))
7999 gtk_widget_realize (widget);
8001 if (gtk_widget_get_visible (priv->parent) &&
8002 gtk_widget_get_visible (widget))
8004 if (gtk_widget_get_child_visible (widget) &&
8005 gtk_widget_get_mapped (priv->parent))
8006 gtk_widget_map (widget);
8008 gtk_widget_queue_resize (widget);
8011 /* child may cause parent's expand to change, if the child is
8012 * expanded. If child is not expanded, then it can't modify the
8013 * parent's expand. If the child becomes expanded later then it will
8014 * queue compute_expand then. This optimization plus defaulting
8015 * newly-constructed widgets to need_compute_expand=FALSE should
8016 * mean that initially building a widget tree doesn't have to keep
8017 * walking up setting need_compute_expand on parents over and over.
8019 * We can't change a parent to need to expand unless we're visible.
8021 if (gtk_widget_get_visible (widget) &&
8022 (priv->need_compute_expand ||
8023 priv->computed_hexpand ||
8024 priv->computed_vexpand))
8026 gtk_widget_queue_compute_expand (parent);
8029 gtk_widget_pop_verify_invariants (widget);
8033 * gtk_widget_get_parent:
8034 * @widget: a #GtkWidget
8036 * Returns the parent container of @widget.
8038 * Return value: (transfer none): the parent container of @widget, or %NULL
8041 gtk_widget_get_parent (GtkWidget *widget)
8043 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8045 return widget->priv->parent;
8049 modifier_style_changed (GtkModifierStyle *style,
8052 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8055 static GtkModifierStyle *
8056 _gtk_widget_get_modifier_properties (GtkWidget *widget)
8058 GtkModifierStyle *style;
8060 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
8062 if (G_UNLIKELY (!style))
8064 GtkStyleContext *context;
8066 style = _gtk_modifier_style_new ();
8067 g_object_set_qdata_full (G_OBJECT (widget),
8068 quark_modifier_style,
8070 (GDestroyNotify) g_object_unref);
8072 g_signal_connect (style, "changed",
8073 G_CALLBACK (modifier_style_changed), widget);
8075 context = gtk_widget_get_style_context (widget);
8077 gtk_style_context_add_provider (context,
8078 GTK_STYLE_PROVIDER (style),
8079 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
8086 * gtk_widget_override_color:
8087 * @widget: a #GtkWidget
8088 * @state: the state for which to set the color
8089 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8090 * of previous calls to gtk_widget_override_color()
8092 * Sets the color to use for a widget.
8094 * All other style values are left untouched.
8097 * This API is mostly meant as a quick way for applications to
8098 * change a widget appearance. If you are developing a widgets
8099 * library and intend this change to be themeable, it is better
8100 * done by setting meaningful CSS classes and regions in your
8101 * widget/container implementation through gtk_style_context_add_class()
8102 * and gtk_style_context_add_region().
8104 * This way, your widget library can install a #GtkCssProvider
8105 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
8106 * to provide a default styling for those widgets that need so, and
8107 * this theming may fully overridden by the user's theme.
8110 * Note that for complex widgets this may bring in undesired
8111 * results (such as uniform background color everywhere), in
8112 * these cases it is better to fully style such widgets through a
8113 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8120 gtk_widget_override_color (GtkWidget *widget,
8121 GtkStateFlags state,
8122 const GdkRGBA *color)
8124 GtkModifierStyle *style;
8126 g_return_if_fail (GTK_IS_WIDGET (widget));
8128 style = _gtk_widget_get_modifier_properties (widget);
8129 _gtk_modifier_style_set_color (style, state, color);
8133 * gtk_widget_override_background_color:
8134 * @widget: a #GtkWidget
8135 * @state: the state for which to set the background color
8136 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8137 * of previous calls to gtk_widget_override_background_color()
8139 * Sets the background color to use for a widget.
8141 * All other style values are left untouched.
8142 * See gtk_widget_override_color().
8147 gtk_widget_override_background_color (GtkWidget *widget,
8148 GtkStateFlags state,
8149 const GdkRGBA *color)
8151 GtkModifierStyle *style;
8153 g_return_if_fail (GTK_IS_WIDGET (widget));
8155 style = _gtk_widget_get_modifier_properties (widget);
8156 _gtk_modifier_style_set_background_color (style, state, color);
8160 * gtk_widget_override_font:
8161 * @widget: a #GtkWidget
8162 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
8163 * the effect of previous calls to gtk_widget_override_font()
8165 * Sets the font to use for a widget. All other style values are
8166 * left untouched. See gtk_widget_override_color().
8171 gtk_widget_override_font (GtkWidget *widget,
8172 const PangoFontDescription *font_desc)
8174 GtkModifierStyle *style;
8176 g_return_if_fail (GTK_IS_WIDGET (widget));
8178 style = _gtk_widget_get_modifier_properties (widget);
8179 _gtk_modifier_style_set_font (style, font_desc);
8183 * gtk_widget_override_symbolic_color:
8184 * @widget: a #GtkWidget
8185 * @name: the name of the symbolic color to modify
8186 * @color: (allow-none): the color to assign (does not need
8187 * to be allocated), or %NULL to undo the effect of previous
8188 * calls to gtk_widget_override_symbolic_color()
8190 * Sets a symbolic color for a widget.
8192 * All other style values are left untouched.
8193 * See gtk_widget_override_color() for overriding the foreground
8194 * or background color.
8199 gtk_widget_override_symbolic_color (GtkWidget *widget,
8201 const GdkRGBA *color)
8203 GtkModifierStyle *style;
8205 g_return_if_fail (GTK_IS_WIDGET (widget));
8207 style = _gtk_widget_get_modifier_properties (widget);
8208 _gtk_modifier_style_map_color (style, name, color);
8212 * gtk_widget_override_cursor:
8213 * @widget: a #GtkWidget
8214 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8215 * allocated), or %NULL to undo the effect of previous calls to
8216 * of gtk_widget_override_cursor().
8217 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8218 * need to be allocated), or %NULL to undo the effect of previous
8219 * calls to of gtk_widget_override_cursor().
8221 * Sets the cursor color to use in a widget, overriding the
8222 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8223 * style properties. All other style values are left untouched.
8224 * See also gtk_widget_modify_style().
8226 * Note that the underlying properties have the #GdkColor type,
8227 * so the alpha value in @primary and @secondary will be ignored.
8232 gtk_widget_override_cursor (GtkWidget *widget,
8233 const GdkRGBA *cursor,
8234 const GdkRGBA *secondary_cursor)
8236 GtkModifierStyle *style;
8238 g_return_if_fail (GTK_IS_WIDGET (widget));
8240 style = _gtk_widget_get_modifier_properties (widget);
8241 _gtk_modifier_style_set_color_property (style,
8243 "cursor-color", cursor);
8244 _gtk_modifier_style_set_color_property (style,
8246 "secondary-cursor-color",
8251 gtk_widget_real_direction_changed (GtkWidget *widget,
8252 GtkTextDirection previous_direction)
8254 gtk_widget_queue_resize (widget);
8258 gtk_widget_real_style_set (GtkWidget *widget,
8259 GtkStyle *previous_style)
8264 GtkWidget *previous_toplevel;
8265 GdkScreen *previous_screen;
8266 GdkScreen *new_screen;
8267 } HierarchyChangedInfo;
8270 do_screen_change (GtkWidget *widget,
8271 GdkScreen *old_screen,
8272 GdkScreen *new_screen)
8274 if (old_screen != new_screen)
8276 GtkWidgetPrivate *priv = widget->priv;
8280 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8282 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8285 _gtk_tooltip_hide (widget);
8287 if (new_screen && priv->context)
8288 gtk_style_context_set_screen (priv->context, new_screen);
8290 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8295 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8296 gpointer client_data)
8298 GtkWidgetPrivate *priv = widget->priv;
8299 HierarchyChangedInfo *info = client_data;
8300 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8301 (priv->parent && priv->parent->priv->anchored);
8303 if (priv->anchored != new_anchored)
8305 g_object_ref (widget);
8307 priv->anchored = new_anchored;
8309 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8310 do_screen_change (widget, info->previous_screen, info->new_screen);
8312 if (GTK_IS_CONTAINER (widget))
8313 gtk_container_forall (GTK_CONTAINER (widget),
8314 gtk_widget_propagate_hierarchy_changed_recurse,
8317 g_object_unref (widget);
8322 * _gtk_widget_propagate_hierarchy_changed:
8323 * @widget: a #GtkWidget
8324 * @previous_toplevel: Previous toplevel
8326 * Propagates changes in the anchored state to a widget and all
8327 * children, unsetting or setting the %ANCHORED flag, and
8328 * emitting #GtkWidget::hierarchy-changed.
8331 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8332 GtkWidget *previous_toplevel)
8334 GtkWidgetPrivate *priv = widget->priv;
8335 HierarchyChangedInfo info;
8337 info.previous_toplevel = previous_toplevel;
8338 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8340 if (gtk_widget_is_toplevel (widget) ||
8341 (priv->parent && priv->parent->priv->anchored))
8342 info.new_screen = gtk_widget_get_screen (widget);
8344 info.new_screen = NULL;
8346 if (info.previous_screen)
8347 g_object_ref (info.previous_screen);
8348 if (previous_toplevel)
8349 g_object_ref (previous_toplevel);
8351 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8353 if (previous_toplevel)
8354 g_object_unref (previous_toplevel);
8355 if (info.previous_screen)
8356 g_object_unref (info.previous_screen);
8360 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8361 gpointer client_data)
8363 HierarchyChangedInfo *info = client_data;
8365 g_object_ref (widget);
8367 do_screen_change (widget, info->previous_screen, info->new_screen);
8369 if (GTK_IS_CONTAINER (widget))
8370 gtk_container_forall (GTK_CONTAINER (widget),
8371 gtk_widget_propagate_screen_changed_recurse,
8374 g_object_unref (widget);
8378 * gtk_widget_is_composited:
8379 * @widget: a #GtkWidget
8381 * Whether @widget can rely on having its alpha channel
8382 * drawn correctly. On X11 this function returns whether a
8383 * compositing manager is running for @widget's screen.
8385 * Please note that the semantics of this call will change
8386 * in the future if used on a widget that has a composited
8387 * window in its hierarchy (as set by gdk_window_set_composited()).
8389 * Return value: %TRUE if the widget can rely on its alpha
8390 * channel being drawn correctly.
8395 gtk_widget_is_composited (GtkWidget *widget)
8399 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8401 screen = gtk_widget_get_screen (widget);
8403 return gdk_screen_is_composited (screen);
8407 propagate_composited_changed (GtkWidget *widget,
8410 if (GTK_IS_CONTAINER (widget))
8412 gtk_container_forall (GTK_CONTAINER (widget),
8413 propagate_composited_changed,
8417 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8421 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8423 propagate_composited_changed (widget, NULL);
8427 * _gtk_widget_propagate_screen_changed:
8428 * @widget: a #GtkWidget
8429 * @previous_screen: Previous screen
8431 * Propagates changes in the screen for a widget to all
8432 * children, emitting #GtkWidget::screen-changed.
8435 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8436 GdkScreen *previous_screen)
8438 HierarchyChangedInfo info;
8440 info.previous_screen = previous_screen;
8441 info.new_screen = gtk_widget_get_screen (widget);
8443 if (previous_screen)
8444 g_object_ref (previous_screen);
8446 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8448 if (previous_screen)
8449 g_object_unref (previous_screen);
8453 reset_style_recurse (GtkWidget *widget, gpointer data)
8455 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8457 if (GTK_IS_CONTAINER (widget))
8458 gtk_container_forall (GTK_CONTAINER (widget),
8459 reset_style_recurse,
8464 * gtk_widget_reset_style:
8465 * @widget: a #GtkWidget
8467 * Updates the style context of @widget and all descendents
8468 * by updating its widget path. #GtkContainer<!-- -->s may want
8469 * to use this on a child when reordering it in a way that a different
8470 * style might apply to it. See also gtk_container_get_path_for_child().
8475 gtk_widget_reset_style (GtkWidget *widget)
8477 g_return_if_fail (GTK_IS_WIDGET (widget));
8479 reset_style_recurse (widget, NULL);
8481 g_list_foreach (widget->priv->attached_windows,
8482 (GFunc) reset_style_recurse, NULL);
8485 #ifdef G_ENABLE_DEBUG
8487 /* Verify invariants, see docs/widget_system.txt for notes on much of
8488 * this. Invariants may be temporarily broken while we're in the
8489 * process of updating state, of course, so you can only
8490 * verify_invariants() after a given operation is complete.
8491 * Use push/pop_verify_invariants to help with that.
8494 gtk_widget_verify_invariants (GtkWidget *widget)
8498 if (widget->priv->verifying_invariants_count > 0)
8501 parent = widget->priv->parent;
8503 if (widget->priv->mapped)
8505 /* Mapped implies ... */
8507 if (!widget->priv->realized)
8508 g_warning ("%s %p is mapped but not realized",
8509 G_OBJECT_TYPE_NAME (widget), widget);
8511 if (!widget->priv->visible)
8512 g_warning ("%s %p is mapped but not visible",
8513 G_OBJECT_TYPE_NAME (widget), widget);
8515 if (!widget->priv->toplevel)
8517 if (!widget->priv->child_visible)
8518 g_warning ("%s %p is mapped but not child_visible",
8519 G_OBJECT_TYPE_NAME (widget), widget);
8524 /* Not mapped implies... */
8527 /* This check makes sense for normal toplevels, but for
8528 * something like a toplevel that is embedded within a clutter
8529 * state, mapping may depend on external factors.
8531 if (widget->priv->toplevel)
8533 if (widget->priv->visible)
8534 g_warning ("%s %p toplevel is visible but not mapped",
8535 G_OBJECT_TYPE_NAME (widget), widget);
8540 /* Parent related checks aren't possible if parent has
8541 * verifying_invariants_count > 0 because parent needs to recurse
8542 * children first before the invariants will hold.
8544 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8547 parent->priv->realized)
8549 /* Parent realized implies... */
8552 /* This is in widget_system.txt but appears to fail
8553 * because there's no gtk_container_realize() that
8554 * realizes all children... instead we just lazily
8555 * wait for map to fix things up.
8557 if (!widget->priv->realized)
8558 g_warning ("%s %p is realized but child %s %p is not realized",
8559 G_OBJECT_TYPE_NAME (parent), parent,
8560 G_OBJECT_TYPE_NAME (widget), widget);
8563 else if (!widget->priv->toplevel)
8565 /* No parent or parent not realized on non-toplevel implies... */
8567 if (widget->priv->realized && !widget->priv->in_reparent)
8568 g_warning ("%s %p is not realized but child %s %p is realized",
8569 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8570 G_OBJECT_TYPE_NAME (widget), widget);
8574 parent->priv->mapped &&
8575 widget->priv->visible &&
8576 widget->priv->child_visible)
8578 /* Parent mapped and we are visible implies... */
8580 if (!widget->priv->mapped)
8581 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8582 G_OBJECT_TYPE_NAME (parent), parent,
8583 G_OBJECT_TYPE_NAME (widget), widget);
8585 else if (!widget->priv->toplevel)
8587 /* No parent or parent not mapped on non-toplevel implies... */
8589 if (widget->priv->mapped && !widget->priv->in_reparent)
8590 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8591 G_OBJECT_TYPE_NAME (widget), widget,
8592 widget->priv->visible,
8593 widget->priv->child_visible,
8594 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8595 parent ? parent->priv->mapped : FALSE);
8599 if (!widget->priv->realized)
8601 /* Not realized implies... */
8604 /* widget_system.txt says these hold, but they don't. */
8605 if (widget->priv->alloc_needed)
8606 g_warning ("%s %p alloc needed but not realized",
8607 G_OBJECT_TYPE_NAME (widget), widget);
8609 if (widget->priv->width_request_needed)
8610 g_warning ("%s %p width request needed but not realized",
8611 G_OBJECT_TYPE_NAME (widget), widget);
8613 if (widget->priv->height_request_needed)
8614 g_warning ("%s %p height request needed but not realized",
8615 G_OBJECT_TYPE_NAME (widget), widget);
8620 /* The point of this push/pop is that invariants may not hold while
8621 * we're busy making changes. So we only check at the outermost call
8622 * on the call stack, after we finish updating everything.
8625 gtk_widget_push_verify_invariants (GtkWidget *widget)
8627 widget->priv->verifying_invariants_count += 1;
8631 gtk_widget_verify_child_invariants (GtkWidget *widget,
8632 gpointer client_data)
8634 /* We don't recurse further; this is a one-level check. */
8635 gtk_widget_verify_invariants (widget);
8639 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8641 g_assert (widget->priv->verifying_invariants_count > 0);
8643 widget->priv->verifying_invariants_count -= 1;
8645 if (widget->priv->verifying_invariants_count == 0)
8647 gtk_widget_verify_invariants (widget);
8649 if (GTK_IS_CONTAINER (widget))
8651 /* Check one level of children, because our
8652 * push_verify_invariants() will have prevented some of the
8653 * checks. This does not recurse because if recursion is
8654 * needed, it will happen naturally as each child has a
8655 * push/pop on that child. For example if we're recursively
8656 * mapping children, we'll push/pop on each child as we map
8659 gtk_container_forall (GTK_CONTAINER (widget),
8660 gtk_widget_verify_child_invariants,
8665 #endif /* G_ENABLE_DEBUG */
8667 static PangoContext *
8668 gtk_widget_peek_pango_context (GtkWidget *widget)
8670 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8674 * gtk_widget_get_pango_context:
8675 * @widget: a #GtkWidget
8677 * Gets a #PangoContext with the appropriate font map, font description,
8678 * and base direction for this widget. Unlike the context returned
8679 * by gtk_widget_create_pango_context(), this context is owned by
8680 * the widget (it can be used until the screen for the widget changes
8681 * or the widget is removed from its toplevel), and will be updated to
8682 * match any changes to the widget's attributes.
8684 * If you create and keep a #PangoLayout using this context, you must
8685 * deal with changes to the context by calling pango_layout_context_changed()
8686 * on the layout in response to the #GtkWidget::style-updated and
8687 * #GtkWidget::direction-changed signals for the widget.
8689 * Return value: (transfer none): the #PangoContext for the widget.
8692 gtk_widget_get_pango_context (GtkWidget *widget)
8694 PangoContext *context;
8696 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8698 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8701 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8702 g_object_set_qdata_full (G_OBJECT (widget),
8703 quark_pango_context,
8712 update_pango_context (GtkWidget *widget,
8713 PangoContext *context)
8715 const PangoFontDescription *font_desc;
8716 GtkStyleContext *style_context;
8718 style_context = gtk_widget_get_style_context (widget);
8720 font_desc = gtk_style_context_get_font (style_context,
8721 gtk_widget_get_state_flags (widget));
8723 pango_context_set_font_description (context, font_desc);
8724 pango_context_set_base_dir (context,
8725 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8726 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8730 gtk_widget_update_pango_context (GtkWidget *widget)
8732 PangoContext *context = gtk_widget_peek_pango_context (widget);
8738 update_pango_context (widget, context);
8740 screen = gtk_widget_get_screen_unchecked (widget);
8743 pango_cairo_context_set_resolution (context,
8744 gdk_screen_get_resolution (screen));
8745 pango_cairo_context_set_font_options (context,
8746 gdk_screen_get_font_options (screen));
8752 * gtk_widget_create_pango_context:
8753 * @widget: a #GtkWidget
8755 * Creates a new #PangoContext with the appropriate font map,
8756 * font description, and base direction for drawing text for
8757 * this widget. See also gtk_widget_get_pango_context().
8759 * Return value: (transfer full): the new #PangoContext
8762 gtk_widget_create_pango_context (GtkWidget *widget)
8765 PangoContext *context;
8767 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8769 screen = gtk_widget_get_screen_unchecked (widget);
8772 GTK_NOTE (MULTIHEAD,
8773 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8775 screen = gdk_screen_get_default ();
8778 context = gdk_pango_context_get_for_screen (screen);
8780 update_pango_context (widget, context);
8781 pango_context_set_language (context, gtk_get_default_language ());
8787 * gtk_widget_create_pango_layout:
8788 * @widget: a #GtkWidget
8789 * @text: text to set on the layout (can be %NULL)
8791 * Creates a new #PangoLayout with the appropriate font map,
8792 * font description, and base direction for drawing text for
8795 * If you keep a #PangoLayout created in this way around, in order to
8796 * notify the layout of changes to the base direction or font of this
8797 * widget, you must call pango_layout_context_changed() in response to
8798 * the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
8801 * Return value: (transfer full): the new #PangoLayout
8804 gtk_widget_create_pango_layout (GtkWidget *widget,
8807 PangoLayout *layout;
8808 PangoContext *context;
8810 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8812 context = gtk_widget_get_pango_context (widget);
8813 layout = pango_layout_new (context);
8816 pango_layout_set_text (layout, text, -1);
8822 * gtk_widget_render_icon_pixbuf:
8823 * @widget: a #GtkWidget
8824 * @stock_id: a stock ID
8825 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8826 * render at the size of the source and don't scale (if there are
8827 * multiple source sizes, GTK+ picks one of the available sizes).
8829 * A convenience function that uses the theme engine and style
8830 * settings for @widget to look up @stock_id and render it to
8831 * a pixbuf. @stock_id should be a stock icon ID such as
8832 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8833 * such as #GTK_ICON_SIZE_MENU.
8835 * The pixels in the returned #GdkPixbuf are shared with the rest of
8836 * the application and should not be modified. The pixbuf should be freed
8837 * after use with g_object_unref().
8839 * Return value: (transfer full): a new pixbuf, or %NULL if the
8840 * stock ID wasn't known
8845 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
8846 const gchar *stock_id,
8849 GtkStyleContext *context;
8850 GtkIconSet *icon_set;
8852 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8853 g_return_val_if_fail (stock_id != NULL, NULL);
8854 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8856 context = gtk_widget_get_style_context (widget);
8857 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
8859 if (icon_set == NULL)
8862 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
8866 * gtk_widget_set_parent_window:
8867 * @widget: a #GtkWidget.
8868 * @parent_window: the new parent window.
8870 * Sets a non default parent window for @widget.
8872 * For GtkWindow classes, setting a @parent_window effects whether
8873 * the window is a toplevel window or can be embedded into other
8877 * For GtkWindow classes, this needs to be called before the
8878 * window is realized.
8883 gtk_widget_set_parent_window (GtkWidget *widget,
8884 GdkWindow *parent_window)
8886 GdkWindow *old_parent_window;
8888 g_return_if_fail (GTK_IS_WIDGET (widget));
8890 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8891 quark_parent_window);
8893 if (parent_window != old_parent_window)
8897 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8899 if (old_parent_window)
8900 g_object_unref (old_parent_window);
8902 g_object_ref (parent_window);
8904 /* Unset toplevel flag when adding a parent window to a widget,
8905 * this is the primary entry point to allow toplevels to be
8908 #ifdef GDK_WINDOWING_X11
8909 is_plug = GTK_IS_PLUG (widget);
8913 if (GTK_IS_WINDOW (widget) && !is_plug)
8914 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
8919 * gtk_widget_get_parent_window:
8920 * @widget: a #GtkWidget.
8922 * Gets @widget's parent window.
8924 * Returns: (transfer none): the parent window of @widget.
8927 gtk_widget_get_parent_window (GtkWidget *widget)
8929 GtkWidgetPrivate *priv;
8930 GdkWindow *parent_window;
8932 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8934 priv = widget->priv;
8936 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8938 return (parent_window != NULL) ? parent_window :
8939 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8944 * gtk_widget_set_child_visible:
8945 * @widget: a #GtkWidget
8946 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8948 * Sets whether @widget should be mapped along with its when its parent
8949 * is mapped and @widget has been shown with gtk_widget_show().
8951 * The child visibility can be set for widget before it is added to
8952 * a container with gtk_widget_set_parent(), to avoid mapping
8953 * children unnecessary before immediately unmapping them. However
8954 * it will be reset to its default state of %TRUE when the widget
8955 * is removed from a container.
8957 * Note that changing the child visibility of a widget does not
8958 * queue a resize on the widget. Most of the time, the size of
8959 * a widget is computed from all visible children, whether or
8960 * not they are mapped. If this is not the case, the container
8961 * can queue a resize itself.
8963 * This function is only useful for container implementations and
8964 * never should be called by an application.
8967 gtk_widget_set_child_visible (GtkWidget *widget,
8968 gboolean is_visible)
8970 GtkWidgetPrivate *priv;
8972 g_return_if_fail (GTK_IS_WIDGET (widget));
8973 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8975 priv = widget->priv;
8977 g_object_ref (widget);
8978 gtk_widget_verify_invariants (widget);
8981 priv->child_visible = TRUE;
8984 GtkWidget *toplevel;
8986 priv->child_visible = FALSE;
8988 toplevel = gtk_widget_get_toplevel (widget);
8989 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8990 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8993 if (priv->parent && gtk_widget_get_realized (priv->parent))
8995 if (gtk_widget_get_mapped (priv->parent) &&
8996 priv->child_visible &&
8997 gtk_widget_get_visible (widget))
8998 gtk_widget_map (widget);
9000 gtk_widget_unmap (widget);
9003 gtk_widget_verify_invariants (widget);
9004 g_object_unref (widget);
9008 * gtk_widget_get_child_visible:
9009 * @widget: a #GtkWidget
9011 * Gets the value set with gtk_widget_set_child_visible().
9012 * If you feel a need to use this function, your code probably
9013 * needs reorganization.
9015 * This function is only useful for container implementations and
9016 * never should be called by an application.
9018 * Return value: %TRUE if the widget is mapped with the parent.
9021 gtk_widget_get_child_visible (GtkWidget *widget)
9023 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9025 return widget->priv->child_visible;
9029 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9031 GtkWidget *toplevel;
9033 toplevel = gtk_widget_get_toplevel (widget);
9035 if (gtk_widget_is_toplevel (toplevel))
9037 if (GTK_IS_WINDOW (toplevel))
9038 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9039 else if (GTK_IS_INVISIBLE (toplevel))
9040 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9047 * gtk_widget_get_screen:
9048 * @widget: a #GtkWidget
9050 * Get the #GdkScreen from the toplevel window associated with
9051 * this widget. This function can only be called after the widget
9052 * has been added to a widget hierarchy with a #GtkWindow
9055 * In general, you should only create screen specific
9056 * resources when a widget has been realized, and you should
9057 * free those resources when the widget is unrealized.
9059 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9064 gtk_widget_get_screen (GtkWidget *widget)
9068 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9070 screen = gtk_widget_get_screen_unchecked (widget);
9077 g_warning (G_STRLOC ": Can't get associated screen"
9078 " for a widget unless it is inside a toplevel GtkWindow\n"
9079 " widget type is %s associated top level type is %s",
9080 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9081 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9083 return gdk_screen_get_default ();
9088 * gtk_widget_has_screen:
9089 * @widget: a #GtkWidget
9091 * Checks whether there is a #GdkScreen is associated with
9092 * this widget. All toplevel widgets have an associated
9093 * screen, and all widgets added into a hierarchy with a toplevel
9094 * window at the top.
9096 * Return value: %TRUE if there is a #GdkScreen associcated
9102 gtk_widget_has_screen (GtkWidget *widget)
9104 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9106 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9110 * gtk_widget_get_display:
9111 * @widget: a #GtkWidget
9113 * Get the #GdkDisplay for the toplevel window associated with
9114 * this widget. This function can only be called after the widget
9115 * has been added to a widget hierarchy with a #GtkWindow at the top.
9117 * In general, you should only create display specific
9118 * resources when a widget has been realized, and you should
9119 * free those resources when the widget is unrealized.
9121 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9126 gtk_widget_get_display (GtkWidget *widget)
9128 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9130 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9134 * gtk_widget_get_root_window:
9135 * @widget: a #GtkWidget
9137 * Get the root window where this widget is located. This function can
9138 * only be called after the widget has been added to a widget
9139 * hierarchy with #GtkWindow at the top.
9141 * The root window is useful for such purposes as creating a popup
9142 * #GdkWindow associated with the window. In general, you should only
9143 * create display specific resources when a widget has been realized,
9144 * and you should free those resources when the widget is unrealized.
9146 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9151 gtk_widget_get_root_window (GtkWidget *widget)
9153 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9155 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9159 * gtk_widget_child_focus:
9160 * @widget: a #GtkWidget
9161 * @direction: direction of focus movement
9163 * This function is used by custom widget implementations; if you're
9164 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9165 * to a particular widget, and gtk_container_set_focus_chain() to
9166 * change the focus tab order. So you may want to investigate those
9167 * functions instead.
9169 * gtk_widget_child_focus() is called by containers as the user moves
9170 * around the window using keyboard shortcuts. @direction indicates
9171 * what kind of motion is taking place (up, down, left, right, tab
9172 * forward, tab backward). gtk_widget_child_focus() emits the
9173 * #GtkWidget::focus signal; widgets override the default handler
9174 * for this signal in order to implement appropriate focus behavior.
9176 * The default ::focus handler for a widget should return %TRUE if
9177 * moving in @direction left the focus on a focusable location inside
9178 * that widget, and %FALSE if moving in @direction moved the focus
9179 * outside the widget. If returning %TRUE, widgets normally
9180 * call gtk_widget_grab_focus() to place the focus accordingly;
9181 * if returning %FALSE, they don't modify the current focus location.
9183 * Return value: %TRUE if focus ended up inside @widget
9186 gtk_widget_child_focus (GtkWidget *widget,
9187 GtkDirectionType direction)
9189 gboolean return_val;
9191 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9193 if (!gtk_widget_get_visible (widget) ||
9194 !gtk_widget_is_sensitive (widget))
9197 /* child widgets must set CAN_FOCUS, containers
9198 * don't have to though.
9200 if (!GTK_IS_CONTAINER (widget) &&
9201 !gtk_widget_get_can_focus (widget))
9204 g_signal_emit (widget,
9205 widget_signals[FOCUS],
9207 direction, &return_val);
9213 * gtk_widget_keynav_failed:
9214 * @widget: a #GtkWidget
9215 * @direction: direction of focus movement
9217 * This function should be called whenever keyboard navigation within
9218 * a single widget hits a boundary. The function emits the
9219 * #GtkWidget::keynav-failed signal on the widget and its return
9220 * value should be interpreted in a way similar to the return value of
9221 * gtk_widget_child_focus():
9223 * When %TRUE is returned, stay in the widget, the failed keyboard
9224 * navigation is Ok and/or there is nowhere we can/should move the
9227 * When %FALSE is returned, the caller should continue with keyboard
9228 * navigation outside the widget, e.g. by calling
9229 * gtk_widget_child_focus() on the widget's toplevel.
9231 * The default ::keynav-failed handler returns %TRUE for
9232 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9233 * values of #GtkDirectionType, it looks at the
9234 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9235 * if the setting is %TRUE. This way the entire user interface
9236 * becomes cursor-navigatable on input devices such as mobile phones
9237 * which only have cursor keys but no tab key.
9239 * Whenever the default handler returns %TRUE, it also calls
9240 * gtk_widget_error_bell() to notify the user of the failed keyboard
9243 * A use case for providing an own implementation of ::keynav-failed
9244 * (either by connecting to it or by overriding it) would be a row of
9245 * #GtkEntry widgets where the user should be able to navigate the
9246 * entire row with the cursor keys, as e.g. known from user interfaces
9247 * that require entering license keys.
9249 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9250 * if the emitting widget should try to handle the keyboard
9251 * navigation attempt in its parent container(s).
9256 gtk_widget_keynav_failed (GtkWidget *widget,
9257 GtkDirectionType direction)
9259 gboolean return_val;
9261 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9263 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9264 direction, &return_val);
9270 * gtk_widget_error_bell:
9271 * @widget: a #GtkWidget
9273 * Notifies the user about an input-related error on this widget.
9274 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9275 * gdk_window_beep(), otherwise it does nothing.
9277 * Note that the effect of gdk_window_beep() can be configured in many
9278 * ways, depending on the windowing backend and the desktop environment
9279 * or window manager that is used.
9284 gtk_widget_error_bell (GtkWidget *widget)
9286 GtkWidgetPrivate *priv;
9287 GtkSettings* settings;
9290 g_return_if_fail (GTK_IS_WIDGET (widget));
9292 priv = widget->priv;
9294 settings = gtk_widget_get_settings (widget);
9298 g_object_get (settings,
9299 "gtk-error-bell", &beep,
9302 if (beep && priv->window)
9303 gdk_window_beep (priv->window);
9307 gtk_widget_set_usize_internal (GtkWidget *widget,
9310 GtkQueueResizeFlags flags)
9312 GtkWidgetAuxInfo *aux_info;
9313 gboolean changed = FALSE;
9315 g_object_freeze_notify (G_OBJECT (widget));
9317 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9319 if (width > -2 && aux_info->width != width)
9321 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9322 g_object_notify (G_OBJECT (widget), "width-request");
9323 aux_info->width = width;
9326 if (height > -2 && aux_info->height != height)
9328 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9329 g_object_notify (G_OBJECT (widget), "height-request");
9330 aux_info->height = height;
9334 if (gtk_widget_get_visible (widget) && changed)
9336 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9337 gtk_widget_queue_resize (widget);
9339 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9342 g_object_thaw_notify (G_OBJECT (widget));
9346 * gtk_widget_set_size_request:
9347 * @widget: a #GtkWidget
9348 * @width: width @widget should request, or -1 to unset
9349 * @height: height @widget should request, or -1 to unset
9351 * Sets the minimum size of a widget; that is, the widget's size
9352 * request will be @width by @height. You can use this function to
9353 * force a widget to be either larger or smaller than it normally
9356 * In most cases, gtk_window_set_default_size() is a better choice for
9357 * toplevel windows than this function; setting the default size will
9358 * still allow users to shrink the window. Setting the size request
9359 * will force them to leave the window at least as large as the size
9360 * request. When dealing with window sizes,
9361 * gtk_window_set_geometry_hints() can be a useful function as well.
9363 * Note the inherent danger of setting any fixed size - themes,
9364 * translations into other languages, different fonts, and user action
9365 * can all change the appropriate size for a given widget. So, it's
9366 * basically impossible to hardcode a size that will always be
9369 * The size request of a widget is the smallest size a widget can
9370 * accept while still functioning well and drawing itself correctly.
9371 * However in some strange cases a widget may be allocated less than
9372 * its requested size, and in many cases a widget may be allocated more
9373 * space than it requested.
9375 * If the size request in a given direction is -1 (unset), then
9376 * the "natural" size request of the widget will be used instead.
9378 * Widgets can't actually be allocated a size less than 1 by 1, but
9379 * you can pass 0,0 to this function to mean "as small as possible."
9381 * The size request set here does not include any margin from the
9382 * #GtkWidget properties margin-left, margin-right, margin-top, and
9383 * margin-bottom, but it does include pretty much all other padding
9384 * or border properties set by any subclass of #GtkWidget.
9387 gtk_widget_set_size_request (GtkWidget *widget,
9391 g_return_if_fail (GTK_IS_WIDGET (widget));
9392 g_return_if_fail (width >= -1);
9393 g_return_if_fail (height >= -1);
9400 gtk_widget_set_usize_internal (widget, width, height, 0);
9405 * gtk_widget_get_size_request:
9406 * @widget: a #GtkWidget
9407 * @width: (out) (allow-none): return location for width, or %NULL
9408 * @height: (out) (allow-none): return location for height, or %NULL
9410 * Gets the size request that was explicitly set for the widget using
9411 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9412 * @height indicates that that dimension has not been set explicitly
9413 * and the natural requisition of the widget will be used intead. See
9414 * gtk_widget_set_size_request(). To get the size a widget will
9415 * actually request, call gtk_widget_get_preferred_size() instead of
9419 gtk_widget_get_size_request (GtkWidget *widget,
9423 const GtkWidgetAuxInfo *aux_info;
9425 g_return_if_fail (GTK_IS_WIDGET (widget));
9427 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9430 *width = aux_info->width;
9433 *height = aux_info->height;
9437 * _gtk_widget_override_size_request:
9438 * @widget: a #GtkWidget
9439 * @width: new forced minimum width
9440 * @height: new forced minimum height
9441 * @old_width: location to store previous forced minimum width
9442 * @old_height: location to store previous forced minumum height
9444 * Temporarily establishes a forced minimum size for a widget; this
9445 * is used by GtkWindow when calculating the size to add to the
9446 * window's geometry widget. Cached sizes for the widget and its
9447 * parents are invalidated, so that subsequent calls to the size
9448 * negotiation machinery produce the overriden result, but the
9449 * widget is not queued for relayout or redraw. The old size must
9450 * be restored with _gtk_widget_restore_size_request() or things
9454 _gtk_widget_override_size_request (GtkWidget *widget,
9460 gtk_widget_get_size_request (widget, old_width, old_height);
9461 gtk_widget_set_usize_internal (widget, width, height,
9462 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9466 * _gtk_widget_restore_size_request:
9467 * @widget: a #GtkWidget
9468 * @old_width: saved forced minimum size
9469 * @old_height: saved forced minimum size
9471 * Undoes the operation of_gtk_widget_override_size_request().
9474 _gtk_widget_restore_size_request (GtkWidget *widget,
9478 gtk_widget_set_usize_internal (widget, old_width, old_height,
9479 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9483 * gtk_widget_set_events:
9484 * @widget: a #GtkWidget
9485 * @events: event mask
9487 * Sets the event mask (see #GdkEventMask) for a widget. The event
9488 * mask determines which events a widget will receive. Keep in mind
9489 * that different widgets have different default event masks, and by
9490 * changing the event mask you may disrupt a widget's functionality,
9491 * so be careful. This function must be called while a widget is
9492 * unrealized. Consider gtk_widget_add_events() for widgets that are
9493 * already realized, or if you want to preserve the existing event
9494 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9495 * to get events on those widgets, place them inside a #GtkEventBox
9496 * and receive events on the event box.
9499 gtk_widget_set_events (GtkWidget *widget,
9502 g_return_if_fail (GTK_IS_WIDGET (widget));
9503 g_return_if_fail (!gtk_widget_get_realized (widget));
9505 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9506 GINT_TO_POINTER (events));
9507 g_object_notify (G_OBJECT (widget), "events");
9511 * gtk_widget_set_device_events:
9512 * @widget: a #GtkWidget
9513 * @device: a #GdkDevice
9514 * @events: event mask
9516 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9517 * mask determines which events a widget will receive from @device. Keep
9518 * in mind that different widgets have different default event masks, and by
9519 * changing the event mask you may disrupt a widget's functionality,
9520 * so be careful. This function must be called while a widget is
9521 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9522 * already realized, or if you want to preserve the existing event
9523 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9524 * to get events on those widgets, place them inside a #GtkEventBox
9525 * and receive events on the event box.
9530 gtk_widget_set_device_events (GtkWidget *widget,
9532 GdkEventMask events)
9534 GHashTable *device_events;
9536 g_return_if_fail (GTK_IS_WIDGET (widget));
9537 g_return_if_fail (GDK_IS_DEVICE (device));
9538 g_return_if_fail (!gtk_widget_get_realized (widget));
9540 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9542 if (G_UNLIKELY (!device_events))
9544 device_events = g_hash_table_new (NULL, NULL);
9545 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9546 (GDestroyNotify) g_hash_table_unref);
9549 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9553 * gtk_widget_set_device_enabled:
9554 * @widget: a #GtkWidget
9555 * @device: a #GdkDevice
9556 * @enabled: whether to enable the device
9558 * Enables or disables a #GdkDevice to interact with @widget
9559 * and all its children.
9561 * It does so by descending through the #GdkWindow hierarchy
9562 * and enabling the same mask that is has for core events
9563 * (i.e. the one that gdk_window_get_events() returns).
9568 gtk_widget_set_device_enabled (GtkWidget *widget,
9572 GList *enabled_devices;
9574 g_return_if_fail (GTK_IS_WIDGET (widget));
9575 g_return_if_fail (GDK_IS_DEVICE (device));
9577 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9578 enabled_devices = g_list_append (enabled_devices, device);
9580 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9581 enabled_devices, (GDestroyNotify) g_list_free);;
9583 if (gtk_widget_get_realized (widget))
9584 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9588 * gtk_widget_get_device_enabled:
9589 * @widget: a #GtkWidget
9590 * @device: a #GdkDevice
9592 * Returns whether @device can interact with @widget and its
9593 * children. See gtk_widget_set_device_enabled().
9595 * Return value: %TRUE is @device is enabled for @widget
9600 gtk_widget_get_device_enabled (GtkWidget *widget,
9603 GList *enabled_devices;
9605 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9606 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9608 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9610 return g_list_find (enabled_devices, device) != NULL;
9614 gtk_widget_add_events_internal_list (GtkWidget *widget,
9621 for (l = window_list; l != NULL; l = l->next)
9623 GdkWindow *window = l->data;
9626 gdk_window_get_user_data (window, &user_data);
9627 if (user_data == widget)
9632 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9634 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9636 children = gdk_window_get_children (window);
9637 gtk_widget_add_events_internal_list (widget, device, events, children);
9638 g_list_free (children);
9644 gtk_widget_add_events_internal (GtkWidget *widget,
9648 GtkWidgetPrivate *priv = widget->priv;
9651 if (!gtk_widget_get_has_window (widget))
9652 window_list = gdk_window_get_children (priv->window);
9654 window_list = g_list_prepend (NULL, priv->window);
9656 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9658 g_list_free (window_list);
9662 * gtk_widget_add_events:
9663 * @widget: a #GtkWidget
9664 * @events: an event mask, see #GdkEventMask
9666 * Adds the events in the bitfield @events to the event mask for
9667 * @widget. See gtk_widget_set_events() for details.
9670 gtk_widget_add_events (GtkWidget *widget,
9675 g_return_if_fail (GTK_IS_WIDGET (widget));
9677 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9678 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9679 GINT_TO_POINTER (old_events | events));
9681 if (gtk_widget_get_realized (widget))
9683 gtk_widget_add_events_internal (widget, NULL, events);
9684 gtk_widget_update_devices_mask (widget, FALSE);
9687 g_object_notify (G_OBJECT (widget), "events");
9691 * gtk_widget_add_device_events:
9692 * @widget: a #GtkWidget
9693 * @device: a #GdkDevice
9694 * @events: an event mask, see #GdkEventMask
9696 * Adds the device events in the bitfield @events to the event mask for
9697 * @widget. See gtk_widget_set_device_events() for details.
9702 gtk_widget_add_device_events (GtkWidget *widget,
9704 GdkEventMask events)
9706 GdkEventMask old_events;
9707 GHashTable *device_events;
9709 g_return_if_fail (GTK_IS_WIDGET (widget));
9710 g_return_if_fail (GDK_IS_DEVICE (device));
9712 old_events = gtk_widget_get_device_events (widget, device);
9714 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9716 if (G_UNLIKELY (!device_events))
9718 device_events = g_hash_table_new (NULL, NULL);
9719 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9720 (GDestroyNotify) g_hash_table_unref);
9723 g_hash_table_insert (device_events, device,
9724 GUINT_TO_POINTER (old_events | events));
9726 if (gtk_widget_get_realized (widget))
9727 gtk_widget_add_events_internal (widget, device, events);
9729 g_object_notify (G_OBJECT (widget), "events");
9733 * gtk_widget_get_toplevel:
9734 * @widget: a #GtkWidget
9736 * This function returns the topmost widget in the container hierarchy
9737 * @widget is a part of. If @widget has no parent widgets, it will be
9738 * returned as the topmost widget. No reference will be added to the
9739 * returned widget; it should not be unreferenced.
9741 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9742 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9744 * %NULL if @widget wasn't inside a toplevel window, and if the
9745 * window was inside a #GtkWindow<!-- -->-derived widget which was in turn
9746 * inside the toplevel #GtkWindow. While the second case may
9747 * seem unlikely, it actually happens when a #GtkPlug is embedded
9748 * inside a #GtkSocket within the same application.
9750 * To reliably find the toplevel #GtkWindow, use
9751 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9752 * is set on the result.
9754 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9755 * if (gtk_widget_is_toplevel (toplevel))
9757 * /* Perform action on toplevel. */
9761 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9762 * if there's no ancestor.
9765 gtk_widget_get_toplevel (GtkWidget *widget)
9767 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9769 while (widget->priv->parent)
9770 widget = widget->priv->parent;
9776 * gtk_widget_get_ancestor:
9777 * @widget: a #GtkWidget
9778 * @widget_type: ancestor type
9780 * Gets the first ancestor of @widget with type @widget_type. For example,
9781 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9782 * the first #GtkBox that's an ancestor of @widget. No reference will be
9783 * added to the returned widget; it should not be unreferenced. See note
9784 * about checking for a toplevel #GtkWindow in the docs for
9785 * gtk_widget_get_toplevel().
9787 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9788 * considers @widget to be an ancestor of itself.
9790 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9793 gtk_widget_get_ancestor (GtkWidget *widget,
9796 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9798 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9799 widget = widget->priv->parent;
9801 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9808 * gtk_widget_set_visual:
9809 * @widget: a #GtkWidget
9810 * @visual: visual to be used or %NULL to unset a previous one
9812 * Sets the visual that should be used for by widget and its children for
9813 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9814 * returned by gtk_widget_get_screen(), so handling the
9815 * #GtkWidget::screen-changed signal is necessary.
9817 * Setting a new @visual will not cause @widget to recreate its windows,
9818 * so you should call this function before @widget is realized.
9821 gtk_widget_set_visual (GtkWidget *widget,
9824 g_return_if_fail (GTK_IS_WIDGET (widget));
9825 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9828 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9831 g_object_set_qdata_full (G_OBJECT (widget),
9833 g_object_ref (visual),
9838 * gtk_widget_get_visual:
9839 * @widget: a #GtkWidget
9841 * Gets the visual that will be used to render @widget.
9843 * Return value: (transfer none): the visual for @widget
9846 gtk_widget_get_visual (GtkWidget *widget)
9852 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9854 if (gtk_widget_get_has_window (widget) &&
9855 widget->priv->window)
9856 return gdk_window_get_visual (widget->priv->window);
9858 screen = gtk_widget_get_screen (widget);
9860 for (w = widget; w != NULL; w = w->priv->parent)
9862 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9865 if (gdk_visual_get_screen (visual) == screen)
9868 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9869 gtk_widget_get_name (widget));
9873 return gdk_screen_get_system_visual (screen);
9877 * gtk_widget_get_settings:
9878 * @widget: a #GtkWidget
9880 * Gets the settings object holding the settings used for this widget.
9882 * Note that this function can only be called when the #GtkWidget
9883 * is attached to a toplevel, since the settings object is specific
9884 * to a particular #GdkScreen.
9886 * Return value: (transfer none): the relevant #GtkSettings object
9889 gtk_widget_get_settings (GtkWidget *widget)
9891 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9893 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9897 * gtk_widget_get_events:
9898 * @widget: a #GtkWidget
9900 * Returns the event mask for the widget (a bitfield containing flags
9901 * from the #GdkEventMask enumeration). These are the events that the widget
9904 * Return value: event mask for @widget
9907 gtk_widget_get_events (GtkWidget *widget)
9909 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9911 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9915 * gtk_widget_get_device_events:
9916 * @widget: a #GtkWidget
9917 * @device: a #GdkDevice
9919 * Returns the events mask for the widget corresponding to an specific device. These
9920 * are the events that the widget will receive when @device operates on it.
9922 * Returns: device event mask for @widget
9927 gtk_widget_get_device_events (GtkWidget *widget,
9930 GHashTable *device_events;
9932 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9933 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9935 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9940 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9944 * gtk_widget_get_pointer:
9945 * @widget: a #GtkWidget
9946 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9947 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9949 * Obtains the location of the mouse pointer in widget coordinates.
9950 * Widget coordinates are a bit odd; for historical reasons, they are
9951 * defined as @widget->window coordinates for widgets that are not
9952 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9953 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9955 * Deprecated: 3.4: Use gdk_window_get_device_position() instead.
9958 gtk_widget_get_pointer (GtkWidget *widget,
9962 GtkWidgetPrivate *priv;
9964 g_return_if_fail (GTK_IS_WIDGET (widget));
9966 priv = widget->priv;
9973 if (gtk_widget_get_realized (widget))
9975 gdk_window_get_device_position (priv->window,
9976 gdk_device_manager_get_client_pointer (
9977 gdk_display_get_device_manager (
9978 gtk_widget_get_display (widget))),
9981 if (!gtk_widget_get_has_window (widget))
9984 *x -= priv->allocation.x;
9986 *y -= priv->allocation.y;
9992 * gtk_widget_is_ancestor:
9993 * @widget: a #GtkWidget
9994 * @ancestor: another #GtkWidget
9996 * Determines whether @widget is somewhere inside @ancestor, possibly with
9997 * intermediate containers.
9999 * Return value: %TRUE if @ancestor contains @widget as a child,
10000 * grandchild, great grandchild, etc.
10003 gtk_widget_is_ancestor (GtkWidget *widget,
10004 GtkWidget *ancestor)
10006 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10007 g_return_val_if_fail (ancestor != NULL, FALSE);
10011 if (widget->priv->parent == ancestor)
10013 widget = widget->priv->parent;
10019 static GQuark quark_composite_name = 0;
10022 * gtk_widget_set_composite_name:
10023 * @widget: a #GtkWidget.
10024 * @name: the name to set
10026 * Sets a widgets composite name. The widget must be
10027 * a composite child of its parent; see gtk_widget_push_composite_child().
10030 gtk_widget_set_composite_name (GtkWidget *widget,
10033 g_return_if_fail (GTK_IS_WIDGET (widget));
10034 g_return_if_fail (widget->priv->composite_child);
10035 g_return_if_fail (name != NULL);
10037 if (!quark_composite_name)
10038 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10040 g_object_set_qdata_full (G_OBJECT (widget),
10041 quark_composite_name,
10047 * gtk_widget_get_composite_name:
10048 * @widget: a #GtkWidget
10050 * Obtains the composite name of a widget.
10052 * Returns: the composite name of @widget, or %NULL if @widget is not
10053 * a composite child. The string should be freed when it is no
10057 gtk_widget_get_composite_name (GtkWidget *widget)
10059 GtkWidgetPrivate *priv;
10061 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10063 priv = widget->priv;
10065 if (widget->priv->composite_child && priv->parent)
10066 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10073 * gtk_widget_push_composite_child:
10075 * Makes all newly-created widgets as composite children until
10076 * the corresponding gtk_widget_pop_composite_child() call.
10078 * A composite child is a child that's an implementation detail of the
10079 * container it's inside and should not be visible to people using the
10080 * container. Composite children aren't treated differently by GTK (but
10081 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10082 * builders might want to treat them in a different way.
10084 * Here is a simple example:
10086 * gtk_widget_push_composite_child ();
10087 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10088 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10089 * gtk_widget_pop_composite_child ();
10090 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10091 * GTK_WIDGET (scrolled_window));
10092 * g_object_ref (scrolled_window->hscrollbar);
10096 gtk_widget_push_composite_child (void)
10098 composite_child_stack++;
10102 * gtk_widget_pop_composite_child:
10104 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10107 gtk_widget_pop_composite_child (void)
10109 if (composite_child_stack)
10110 composite_child_stack--;
10114 gtk_widget_emit_direction_changed (GtkWidget *widget,
10115 GtkTextDirection old_dir)
10117 gtk_widget_update_pango_context (widget);
10119 if (widget->priv->context)
10120 gtk_style_context_set_direction (widget->priv->context,
10121 gtk_widget_get_direction (widget));
10123 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10127 * gtk_widget_set_direction:
10128 * @widget: a #GtkWidget
10129 * @dir: the new direction
10131 * Sets the reading direction on a particular widget. This direction
10132 * controls the primary direction for widgets containing text,
10133 * and also the direction in which the children of a container are
10134 * packed. The ability to set the direction is present in order
10135 * so that correct localization into languages with right-to-left
10136 * reading directions can be done. Generally, applications will
10137 * let the default reading direction present, except for containers
10138 * where the containers are arranged in an order that is explicitely
10139 * visual rather than logical (such as buttons for text justification).
10141 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10142 * set by gtk_widget_set_default_direction() will be used.
10145 gtk_widget_set_direction (GtkWidget *widget,
10146 GtkTextDirection dir)
10148 GtkTextDirection old_dir;
10150 g_return_if_fail (GTK_IS_WIDGET (widget));
10151 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10153 old_dir = gtk_widget_get_direction (widget);
10155 widget->priv->direction = dir;
10157 if (old_dir != gtk_widget_get_direction (widget))
10158 gtk_widget_emit_direction_changed (widget, old_dir);
10162 * gtk_widget_get_direction:
10163 * @widget: a #GtkWidget
10165 * Gets the reading direction for a particular widget. See
10166 * gtk_widget_set_direction().
10168 * Return value: the reading direction for the widget.
10171 gtk_widget_get_direction (GtkWidget *widget)
10173 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10175 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10176 return gtk_default_direction;
10178 return widget->priv->direction;
10182 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10184 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10186 g_object_ref (widget);
10188 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10189 gtk_widget_emit_direction_changed (widget, old_dir);
10191 if (GTK_IS_CONTAINER (widget))
10192 gtk_container_forall (GTK_CONTAINER (widget),
10193 gtk_widget_set_default_direction_recurse,
10196 g_object_unref (widget);
10200 * gtk_widget_set_default_direction:
10201 * @dir: the new default direction. This cannot be
10202 * %GTK_TEXT_DIR_NONE.
10204 * Sets the default reading direction for widgets where the
10205 * direction has not been explicitly set by gtk_widget_set_direction().
10208 gtk_widget_set_default_direction (GtkTextDirection dir)
10210 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10212 if (dir != gtk_default_direction)
10214 GList *toplevels, *tmp_list;
10215 GtkTextDirection old_dir = gtk_default_direction;
10217 gtk_default_direction = dir;
10219 tmp_list = toplevels = gtk_window_list_toplevels ();
10220 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10224 gtk_widget_set_default_direction_recurse (tmp_list->data,
10225 GUINT_TO_POINTER (old_dir));
10226 g_object_unref (tmp_list->data);
10227 tmp_list = tmp_list->next;
10230 g_list_free (toplevels);
10235 * gtk_widget_get_default_direction:
10237 * Obtains the current default reading direction. See
10238 * gtk_widget_set_default_direction().
10240 * Return value: the current default direction.
10243 gtk_widget_get_default_direction (void)
10245 return gtk_default_direction;
10249 gtk_widget_constructed (GObject *object)
10251 GtkWidget *widget = GTK_WIDGET (object);
10252 GtkWidgetPrivate *priv = widget->priv;
10254 /* As strange as it may seem, this may happen on object construction.
10255 * init() implementations of parent types may eventually call this function,
10256 * each with its corresponding GType, which could leave a child
10257 * implementation with a wrong widget type in the widget path
10260 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (priv->path))
10262 gtk_widget_path_free (priv->path);
10266 G_OBJECT_CLASS (gtk_widget_parent_class)->constructed (object);
10270 gtk_widget_dispose (GObject *object)
10272 GtkWidget *widget = GTK_WIDGET (object);
10273 GtkWidgetPrivate *priv = widget->priv;
10276 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10277 else if (gtk_widget_get_visible (widget))
10278 gtk_widget_hide (widget);
10280 priv->visible = FALSE;
10281 if (gtk_widget_get_realized (widget))
10282 gtk_widget_unrealize (widget);
10284 if (!priv->in_destruction)
10286 priv->in_destruction = TRUE;
10287 g_signal_emit (object, widget_signals[DESTROY], 0);
10288 priv->in_destruction = FALSE;
10291 g_clear_object (&priv->muxer);
10293 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10297 gtk_widget_real_destroy (GtkWidget *object)
10299 /* gtk_object_destroy() will already hold a refcount on object */
10300 GtkWidget *widget = GTK_WIDGET (object);
10301 GtkWidgetPrivate *priv = widget->priv;
10303 if (GTK_WIDGET_GET_CLASS (widget)->priv->accessible_type != GTK_TYPE_ACCESSIBLE)
10305 GtkAccessible *accessible = g_object_steal_qdata (G_OBJECT (widget), quark_accessible_object);
10309 gtk_accessible_set_widget (accessible, NULL);
10310 g_object_unref (accessible);
10314 /* wipe accelerator closures (keep order) */
10315 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10316 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10318 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10319 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10321 gtk_grab_remove (widget);
10324 g_object_unref (priv->style);
10325 priv->style = gtk_widget_get_default_style ();
10326 g_object_ref (priv->style);
10330 gtk_widget_finalize (GObject *object)
10332 GtkWidget *widget = GTK_WIDGET (object);
10333 GtkWidgetPrivate *priv = widget->priv;
10334 GtkWidgetAuxInfo *aux_info;
10335 GtkAccessible *accessible;
10337 gtk_grab_remove (widget);
10339 g_object_unref (priv->style);
10340 priv->style = NULL;
10342 g_free (priv->name);
10344 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10346 gtk_widget_aux_info_destroy (aux_info);
10348 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10350 g_object_unref (accessible);
10353 gtk_widget_path_free (priv->path);
10357 _gtk_style_context_set_widget (priv->context, NULL);
10358 g_object_unref (priv->context);
10361 _gtk_widget_free_cached_sizes (widget);
10363 if (g_object_is_floating (object))
10364 g_warning ("A floating object was finalized. This means that someone\n"
10365 "called g_object_unref() on an object that had only a floating\n"
10366 "reference; the initial floating reference is not owned by anyone\n"
10367 "and must be removed with g_object_ref_sink().");
10369 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10372 /*****************************************
10373 * gtk_widget_real_map:
10378 *****************************************/
10381 gtk_widget_real_map (GtkWidget *widget)
10383 GtkWidgetPrivate *priv = widget->priv;
10385 g_assert (gtk_widget_get_realized (widget));
10387 if (!gtk_widget_get_mapped (widget))
10389 gtk_widget_set_mapped (widget, TRUE);
10391 if (gtk_widget_get_has_window (widget))
10392 gdk_window_show (priv->window);
10396 /*****************************************
10397 * gtk_widget_real_unmap:
10402 *****************************************/
10405 gtk_widget_real_unmap (GtkWidget *widget)
10407 GtkWidgetPrivate *priv = widget->priv;
10409 if (gtk_widget_get_mapped (widget))
10411 gtk_widget_set_mapped (widget, FALSE);
10413 if (gtk_widget_get_has_window (widget))
10414 gdk_window_hide (priv->window);
10418 /*****************************************
10419 * gtk_widget_real_realize:
10424 *****************************************/
10427 gtk_widget_real_realize (GtkWidget *widget)
10429 GtkWidgetPrivate *priv = widget->priv;
10431 g_assert (!gtk_widget_get_has_window (widget));
10433 gtk_widget_set_realized (widget, TRUE);
10436 priv->window = gtk_widget_get_parent_window (widget);
10437 g_object_ref (priv->window);
10441 /*****************************************
10442 * gtk_widget_real_unrealize:
10447 *****************************************/
10450 gtk_widget_real_unrealize (GtkWidget *widget)
10452 GtkWidgetPrivate *priv = widget->priv;
10454 g_assert (!widget->priv->mapped);
10456 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10459 /* We must do unrealize child widget BEFORE container widget.
10460 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10461 * So, unrealizing container widget bofore its children causes the problem
10462 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10465 if (GTK_IS_CONTAINER (widget))
10466 gtk_container_forall (GTK_CONTAINER (widget),
10467 (GtkCallback) gtk_widget_unrealize,
10470 if (gtk_widget_get_has_window (widget))
10472 gdk_window_set_user_data (priv->window, NULL);
10473 gdk_window_destroy (priv->window);
10474 priv->window = NULL;
10478 g_object_unref (priv->window);
10479 priv->window = NULL;
10482 gtk_selection_remove_all (widget);
10484 gtk_widget_set_realized (widget, FALSE);
10488 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10489 GtkOrientation orientation,
10490 gint *minimum_size,
10491 gint *natural_size)
10493 const GtkWidgetAuxInfo *aux_info;
10495 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10497 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10498 aux_info->width > 0)
10500 *minimum_size = MAX (*minimum_size, aux_info->width);
10502 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10503 aux_info->height > 0)
10505 *minimum_size = MAX (*minimum_size, aux_info->height);
10508 /* Fix it if set_size_request made natural size smaller than min size.
10509 * This would also silently fix broken widgets, but we warn about them
10510 * in gtksizerequest.c when calling their size request vfuncs.
10512 *natural_size = MAX (*natural_size, *minimum_size);
10514 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10516 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10517 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10521 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10522 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10527 * _gtk_widget_peek_request_cache:
10529 * Returns the address of the widget's request cache (strictly for
10530 * internal use in gtksizerequest.c)
10532 * Return value: the address of @widget's size request cache.
10535 _gtk_widget_peek_request_cache (GtkWidget *widget)
10537 /* Don't bother slowing things down with the return_if_fail guards here */
10538 return &widget->priv->requests;
10542 * _gtk_widget_set_device_window:
10543 * @widget: a #GtkWidget
10544 * @device: a #GdkDevice
10545 * @window: the new device window
10547 * Sets pointer window for @widget and @device.
10548 * Does not ref @window.
10551 _gtk_widget_set_device_window (GtkWidget *widget,
10555 GHashTable *device_window;
10557 g_return_if_fail (GTK_IS_WIDGET (widget));
10558 g_return_if_fail (GDK_IS_DEVICE (device));
10559 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10561 if (!gtk_widget_get_mapped (widget))
10564 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10566 if (!device_window && window)
10568 device_window = g_hash_table_new (NULL, NULL);
10569 g_object_set_qdata_full (G_OBJECT (widget),
10570 quark_pointer_window,
10572 (GDestroyNotify) g_hash_table_destroy);
10576 g_hash_table_insert (device_window, device, window);
10577 else if (device_window)
10579 g_hash_table_remove (device_window, device);
10581 if (g_hash_table_size (device_window) == 0)
10582 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10587 * _gtk_widget_get_device_window:
10588 * @widget: a #GtkWidget
10589 * @device: a #GdkDevice
10591 * Return value: the device window set on @widget, or %NULL
10594 _gtk_widget_get_device_window (GtkWidget *widget,
10597 GHashTable *device_window;
10599 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10600 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10602 if (!gtk_widget_get_mapped (widget))
10605 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10607 if (!device_window)
10610 return g_hash_table_lookup (device_window, device);
10614 * _gtk_widget_list_devices:
10615 * @widget: a #GtkWidget
10617 * Returns the list of #GdkDevices that is currently on top
10618 * of any window belonging to @widget.
10619 * Free the list with g_list_free(), the elements are owned
10620 * by GTK+ and must not be freed.
10623 _gtk_widget_list_devices (GtkWidget *widget)
10625 GHashTableIter iter;
10626 GHashTable *device_window;
10627 GList *devices = NULL;
10628 gpointer key, value;
10630 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10632 if (!gtk_widget_get_mapped (widget))
10635 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10637 if (G_UNLIKELY (!device_window))
10640 g_hash_table_iter_init (&iter, device_window);
10642 while (g_hash_table_iter_next (&iter, &key, &value))
10643 devices = g_list_prepend (devices, key);
10649 synth_crossing (GtkWidget *widget,
10653 GdkCrossingMode mode,
10654 GdkNotifyType detail)
10658 event = gdk_event_new (type);
10660 event->crossing.window = g_object_ref (window);
10661 event->crossing.send_event = TRUE;
10662 event->crossing.subwindow = g_object_ref (window);
10663 event->crossing.time = GDK_CURRENT_TIME;
10664 event->crossing.x = event->crossing.y = 0;
10665 event->crossing.x_root = event->crossing.y_root = 0;
10666 event->crossing.mode = mode;
10667 event->crossing.detail = detail;
10668 event->crossing.focus = FALSE;
10669 event->crossing.state = 0;
10670 gdk_event_set_device (event, device);
10673 widget = gtk_get_event_widget (event);
10676 gtk_widget_event_internal (widget, event);
10678 gdk_event_free (event);
10682 * _gtk_widget_synthesize_crossing:
10683 * @from: the #GtkWidget the virtual pointer is leaving.
10684 * @to: the #GtkWidget the virtual pointer is moving to.
10685 * @mode: the #GdkCrossingMode to place on the synthesized events.
10687 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10689 * The real pointer window is the window that most recently received an enter notify
10690 * event. Windows that don't select for crossing events can't become the real
10691 * poiner window. The real pointer widget that owns the real pointer window. The
10692 * effective pointer window is the same as the real pointer window unless the real
10693 * pointer widget is either insensitive or there is a grab on a widget that is not
10694 * an ancestor of the real pointer widget (in which case the effective pointer
10695 * window should be the root window).
10697 * When the effective pointer window is the same as the real poiner window, we
10698 * receive crossing events from the windowing system. When the effective pointer
10699 * window changes to become different from the real pointer window we synthesize
10700 * crossing events, attempting to follow X protocol rules:
10702 * When the root window becomes the effective pointer window:
10703 * - leave notify on real pointer window, detail Ancestor
10704 * - leave notify on all of its ancestors, detail Virtual
10705 * - enter notify on root window, detail Inferior
10707 * When the root window ceases to be the effective pointer window:
10708 * - leave notify on root window, detail Inferior
10709 * - enter notify on all ancestors of real pointer window, detail Virtual
10710 * - enter notify on real pointer window, detail Ancestor
10713 _gtk_widget_synthesize_crossing (GtkWidget *from,
10716 GdkCrossingMode mode)
10718 GdkWindow *from_window = NULL, *to_window = NULL;
10720 g_return_if_fail (from != NULL || to != NULL);
10724 from_window = _gtk_widget_get_device_window (from, device);
10727 from_window = from->priv->window;
10732 to_window = _gtk_widget_get_device_window (to, device);
10735 to_window = to->priv->window;
10738 if (from_window == NULL && to_window == NULL)
10740 else if (from_window != NULL && to_window == NULL)
10742 GList *from_ancestors = NULL, *list;
10743 GdkWindow *from_ancestor = from_window;
10745 while (from_ancestor != NULL)
10747 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10748 if (from_ancestor == NULL)
10750 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10753 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10754 device, mode, GDK_NOTIFY_ANCESTOR);
10755 for (list = g_list_last (from_ancestors); list; list = list->prev)
10757 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10758 device, mode, GDK_NOTIFY_VIRTUAL);
10761 /* XXX: enter/inferior on root window? */
10763 g_list_free (from_ancestors);
10765 else if (from_window == NULL && to_window != NULL)
10767 GList *to_ancestors = NULL, *list;
10768 GdkWindow *to_ancestor = to_window;
10770 while (to_ancestor != NULL)
10772 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10773 if (to_ancestor == NULL)
10775 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10778 /* XXX: leave/inferior on root window? */
10780 for (list = to_ancestors; list; list = list->next)
10782 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10783 device, mode, GDK_NOTIFY_VIRTUAL);
10785 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10786 device, mode, GDK_NOTIFY_ANCESTOR);
10788 g_list_free (to_ancestors);
10790 else if (from_window == to_window)
10794 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10795 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10797 while (from_ancestor != NULL || to_ancestor != NULL)
10799 if (from_ancestor != NULL)
10801 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10802 if (from_ancestor == to_window)
10805 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10807 if (to_ancestor != NULL)
10809 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10810 if (to_ancestor == from_window)
10813 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10816 if (to_ancestor == from_window)
10818 if (mode != GDK_CROSSING_GTK_UNGRAB)
10819 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10820 device, mode, GDK_NOTIFY_INFERIOR);
10821 for (list = to_ancestors; list; list = list->next)
10822 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10823 device, mode, GDK_NOTIFY_VIRTUAL);
10824 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10825 device, mode, GDK_NOTIFY_ANCESTOR);
10827 else if (from_ancestor == to_window)
10829 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10830 device, mode, GDK_NOTIFY_ANCESTOR);
10831 for (list = g_list_last (from_ancestors); list; list = list->prev)
10833 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10834 device, mode, GDK_NOTIFY_VIRTUAL);
10836 if (mode != GDK_CROSSING_GTK_GRAB)
10837 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10838 device, mode, GDK_NOTIFY_INFERIOR);
10842 while (from_ancestors != NULL && to_ancestors != NULL
10843 && from_ancestors->data == to_ancestors->data)
10845 from_ancestors = g_list_delete_link (from_ancestors,
10847 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10850 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10851 device, mode, GDK_NOTIFY_NONLINEAR);
10853 for (list = g_list_last (from_ancestors); list; list = list->prev)
10855 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10856 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10858 for (list = to_ancestors; list; list = list->next)
10860 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10861 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10863 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10864 device, mode, GDK_NOTIFY_NONLINEAR);
10866 g_list_free (from_ancestors);
10867 g_list_free (to_ancestors);
10872 gtk_widget_propagate_state (GtkWidget *widget,
10873 GtkStateData *data)
10875 GtkWidgetPrivate *priv = widget->priv;
10876 GtkStateFlags new_flags, old_flags = priv->state_flags;
10877 GtkStateType old_state;
10879 old_state = gtk_widget_get_state (widget);
10881 switch (data->operation)
10883 case STATE_CHANGE_REPLACE:
10884 priv->state_flags = data->flags;
10886 case STATE_CHANGE_SET:
10887 priv->state_flags |= data->flags;
10889 case STATE_CHANGE_UNSET:
10890 priv->state_flags &= ~(data->flags);
10894 /* make insensitivity unoverridable */
10895 if (!priv->sensitive)
10896 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
10898 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10902 window = gtk_widget_get_toplevel (widget);
10904 if (window && gtk_widget_is_toplevel (window))
10905 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10908 new_flags = priv->state_flags;
10910 if (old_flags != new_flags)
10912 g_object_ref (widget);
10914 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10915 gtk_grab_remove (widget);
10917 gtk_style_context_set_state (gtk_widget_get_style_context (widget), new_flags);
10919 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10920 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
10922 if (!priv->shadowed &&
10923 (new_flags & GTK_STATE_FLAG_INSENSITIVE) != (old_flags & GTK_STATE_FLAG_INSENSITIVE))
10925 GList *event_windows = NULL;
10926 GList *devices, *d;
10928 devices = _gtk_widget_list_devices (widget);
10930 for (d = devices; d; d = d->next)
10936 window = _gtk_widget_get_device_window (widget, device);
10938 /* Do not propagate more than once to the
10939 * same window if non-multidevice aware.
10941 if (!gdk_window_get_support_multidevice (window) &&
10942 g_list_find (event_windows, window))
10945 if (!gtk_widget_is_sensitive (widget))
10946 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10947 GDK_CROSSING_STATE_CHANGED);
10949 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10950 GDK_CROSSING_STATE_CHANGED);
10952 event_windows = g_list_prepend (event_windows, window);
10955 g_list_free (event_windows);
10956 g_list_free (devices);
10959 if (GTK_IS_CONTAINER (widget))
10961 GtkStateData child_data = *data;
10963 /* Make sure to only propate the right states further */
10964 child_data.flags &= GTK_STATE_FLAGS_DO_PROPAGATE;
10966 gtk_container_forall (GTK_CONTAINER (widget),
10967 (GtkCallback) gtk_widget_propagate_state,
10971 g_object_unref (widget);
10975 static const GtkWidgetAuxInfo default_aux_info = {
10983 * gtk_widget_get_aux_info:
10984 * @widget: a #GtkWidget
10985 * @create: if %TRUE, create the structure if it doesn't exist
10987 * Get the #GtkWidgetAuxInfo structure for the widget.
10989 * Return value: the #GtkAuxInfo structure for the widget, or
10990 * %NULL if @create is %FALSE and one doesn't already exist.
10992 static GtkWidgetAuxInfo *
10993 gtk_widget_get_aux_info (GtkWidget *widget,
10996 GtkWidgetAuxInfo *aux_info;
10998 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
10999 if (!aux_info && create)
11001 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
11003 *aux_info = default_aux_info;
11005 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
11011 static const GtkWidgetAuxInfo*
11012 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11014 GtkWidgetAuxInfo *aux_info;
11016 aux_info = gtk_widget_get_aux_info (widget, FALSE);
11017 if (aux_info == NULL)
11019 return &default_aux_info;
11027 /*****************************************
11028 * gtk_widget_aux_info_destroy:
11033 *****************************************/
11036 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11038 g_slice_free (GtkWidgetAuxInfo, aux_info);
11042 * gtk_widget_shape_combine_region:
11043 * @widget: a #GtkWidget
11044 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11046 * Sets a shape for this widget's GDK window. This allows for
11047 * transparent windows etc., see gdk_window_shape_combine_region()
11048 * for more information.
11053 gtk_widget_shape_combine_region (GtkWidget *widget,
11054 cairo_region_t *region)
11056 GtkWidgetPrivate *priv;
11058 g_return_if_fail (GTK_IS_WIDGET (widget));
11059 /* set_shape doesn't work on widgets without gdk window */
11060 g_return_if_fail (gtk_widget_get_has_window (widget));
11062 priv = widget->priv;
11064 if (region == NULL)
11066 priv->has_shape_mask = FALSE;
11069 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11071 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11075 priv->has_shape_mask = TRUE;
11077 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11078 cairo_region_copy (region),
11079 (GDestroyNotify) cairo_region_destroy);
11081 /* set shape if widget has a gdk window already.
11082 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11085 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11090 * gtk_widget_input_shape_combine_region:
11091 * @widget: a #GtkWidget
11092 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11094 * Sets an input shape for this widget's GDK window. This allows for
11095 * windows which react to mouse click in a nonrectangular region, see
11096 * gdk_window_input_shape_combine_region() for more information.
11101 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11102 cairo_region_t *region)
11104 GtkWidgetPrivate *priv;
11106 g_return_if_fail (GTK_IS_WIDGET (widget));
11107 /* set_shape doesn't work on widgets without gdk window */
11108 g_return_if_fail (gtk_widget_get_has_window (widget));
11110 priv = widget->priv;
11112 if (region == NULL)
11115 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11117 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11121 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11122 cairo_region_copy (region),
11123 (GDestroyNotify) cairo_region_destroy);
11125 /* set shape if widget has a gdk window already.
11126 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11129 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11134 /* style properties
11138 * gtk_widget_class_install_style_property_parser: (skip)
11139 * @klass: a #GtkWidgetClass
11140 * @pspec: the #GParamSpec for the style property
11141 * @parser: the parser for the style property
11143 * Installs a style property on a widget class.
11146 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11148 GtkRcPropertyParser parser)
11150 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11151 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11152 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11153 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11155 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11157 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11158 G_OBJECT_CLASS_NAME (klass),
11163 g_param_spec_ref_sink (pspec);
11164 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11165 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11169 * gtk_widget_class_install_style_property:
11170 * @klass: a #GtkWidgetClass
11171 * @pspec: the #GParamSpec for the property
11173 * Installs a style property on a widget class. The parser for the
11174 * style property is determined by the value type of @pspec.
11177 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11180 GtkRcPropertyParser parser;
11182 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11183 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11185 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11187 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11191 * gtk_widget_class_find_style_property:
11192 * @klass: a #GtkWidgetClass
11193 * @property_name: the name of the style property to find
11195 * Finds a style property of a widget class by name.
11197 * Returns: (transfer none): the #GParamSpec of the style property or
11198 * %NULL if @class has no style property with that name.
11203 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11204 const gchar *property_name)
11206 g_return_val_if_fail (property_name != NULL, NULL);
11208 return g_param_spec_pool_lookup (style_property_spec_pool,
11210 G_OBJECT_CLASS_TYPE (klass),
11215 * gtk_widget_class_list_style_properties:
11216 * @klass: a #GtkWidgetClass
11217 * @n_properties: location to return the number of style properties found
11219 * Returns all style properties of a widget class.
11221 * Returns: (array length=n_properties) (transfer container): a
11222 * newly allocated array of #GParamSpec*. The array must be
11223 * freed with g_free().
11228 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11229 guint *n_properties)
11231 GParamSpec **pspecs;
11234 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11235 G_OBJECT_CLASS_TYPE (klass),
11244 * gtk_widget_style_get_property:
11245 * @widget: a #GtkWidget
11246 * @property_name: the name of a style property
11247 * @value: location to return the property value
11249 * Gets the value of a style property of @widget.
11252 gtk_widget_style_get_property (GtkWidget *widget,
11253 const gchar *property_name,
11258 g_return_if_fail (GTK_IS_WIDGET (widget));
11259 g_return_if_fail (property_name != NULL);
11260 g_return_if_fail (G_IS_VALUE (value));
11262 g_object_ref (widget);
11263 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11265 G_OBJECT_TYPE (widget),
11268 g_warning ("%s: widget class `%s' has no property named `%s'",
11270 G_OBJECT_TYPE_NAME (widget),
11274 GtkStyleContext *context;
11275 const GValue *peek_value;
11276 GtkStateFlags state;
11278 context = gtk_widget_get_style_context (widget);
11279 state = gtk_widget_get_state_flags (widget);
11281 peek_value = _gtk_style_context_peek_style_property (context,
11282 G_OBJECT_TYPE (widget),
11285 /* auto-conversion of the caller's value type
11287 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11288 g_value_copy (peek_value, value);
11289 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11290 g_value_transform (peek_value, value);
11292 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11294 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11295 G_VALUE_TYPE_NAME (value));
11297 g_object_unref (widget);
11301 * gtk_widget_style_get_valist:
11302 * @widget: a #GtkWidget
11303 * @first_property_name: the name of the first property to get
11304 * @var_args: a <type>va_list</type> of pairs of property names and
11305 * locations to return the property values, starting with the location
11306 * for @first_property_name.
11308 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11312 gtk_widget_style_get_valist (GtkWidget *widget,
11313 const gchar *first_property_name,
11316 GtkStyleContext *context;
11317 GtkStateFlags state;
11320 g_return_if_fail (GTK_IS_WIDGET (widget));
11322 g_object_ref (widget);
11323 context = gtk_widget_get_style_context (widget);
11324 state = gtk_widget_get_state_flags (widget);
11326 name = first_property_name;
11329 const GValue *peek_value;
11333 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11335 G_OBJECT_TYPE (widget),
11339 g_warning ("%s: widget class `%s' has no property named `%s'",
11341 G_OBJECT_TYPE_NAME (widget),
11345 /* style pspecs are always readable so we can spare that check here */
11347 peek_value = _gtk_style_context_peek_style_property (context,
11348 G_OBJECT_TYPE (widget),
11351 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11354 g_warning ("%s: %s", G_STRLOC, error);
11359 name = va_arg (var_args, gchar*);
11362 g_object_unref (widget);
11366 * gtk_widget_style_get:
11367 * @widget: a #GtkWidget
11368 * @first_property_name: the name of the first property to get
11369 * @...: pairs of property names and locations to return the
11370 * property values, starting with the location for
11371 * @first_property_name, terminated by %NULL.
11373 * Gets the values of a multiple style properties of @widget.
11376 gtk_widget_style_get (GtkWidget *widget,
11377 const gchar *first_property_name,
11382 g_return_if_fail (GTK_IS_WIDGET (widget));
11384 va_start (var_args, first_property_name);
11385 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11390 * gtk_requisition_new:
11392 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11394 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11395 * be freed with gtk_requisition_free().
11400 gtk_requisition_new (void)
11402 return g_slice_new0 (GtkRequisition);
11406 * gtk_requisition_copy:
11407 * @requisition: a #GtkRequisition
11409 * Copies a #GtkRequisition.
11411 * Returns: a copy of @requisition
11414 gtk_requisition_copy (const GtkRequisition *requisition)
11416 return g_slice_dup (GtkRequisition, requisition);
11420 * gtk_requisition_free:
11421 * @requisition: a #GtkRequisition
11423 * Frees a #GtkRequisition.
11426 gtk_requisition_free (GtkRequisition *requisition)
11428 g_slice_free (GtkRequisition, requisition);
11431 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11432 gtk_requisition_copy,
11433 gtk_requisition_free)
11436 * gtk_widget_class_set_accessible_type:
11437 * @widget_class: class to set the accessible type for
11438 * @type: The object type that implements the accessible for @widget_class
11440 * Sets the type to be used for creating accessibles for widgets of
11441 * @widget_class. The given @type must be a subtype of the type used for
11442 * accessibles of the parent class.
11444 * This function should only be called from class init functions of widgets.
11449 gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class,
11452 GtkWidgetClassPrivate *priv;
11454 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11455 g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type));
11457 priv = widget_class->priv;
11459 priv->accessible_type = type;
11460 /* reset this - honoring the type's role is better. */
11461 priv->accessible_role = ATK_ROLE_INVALID;
11465 * gtk_widget_class_set_accessible_role:
11466 * @widget_class: class to set the accessible role for
11467 * @role: The role to use for accessibles created for @widget_class
11469 * Sets the default #AtkRole to be set on accessibles created for
11470 * widgets of @widget_class. Accessibles may decide to not honor this
11471 * setting if their role reporting is more refined. Calls to
11472 * gtk_widget_class_set_accessible_type() will reset this value.
11474 * In cases where you want more fine-grained control over the role of
11475 * accessibles created for @widget_class, you should provide your own
11476 * accessible type and use gtk_widget_class_set_accessible_type()
11479 * If @role is #ATK_ROLE_INVALID, the default role will not be changed
11480 * and the accessible's default role will be used instead.
11482 * This function should only be called from class init functions of widgets.
11487 gtk_widget_class_set_accessible_role (GtkWidgetClass *widget_class,
11490 GtkWidgetClassPrivate *priv;
11492 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11494 priv = widget_class->priv;
11496 priv->accessible_role = role;
11500 * _gtk_widget_peek_accessible:
11501 * @widget: a #GtkWidget
11503 * Gets the accessible for @widget, if it has been created yet.
11504 * Otherwise, this function returns %NULL. If the @widget's implementation
11505 * does not use the default way to create accessibles, %NULL will always be
11508 * Returns: the accessible for @widget or %NULL if none has been
11512 _gtk_widget_peek_accessible (GtkWidget *widget)
11514 return g_object_get_qdata (G_OBJECT (widget),
11515 quark_accessible_object);
11519 * gtk_widget_get_accessible:
11520 * @widget: a #GtkWidget
11522 * Returns the accessible object that describes the widget to an
11523 * assistive technology.
11525 * If accessibility support is not available, this #AtkObject
11526 * instance may be a no-op. Likewise, if no class-specific #AtkObject
11527 * implementation is available for the widget instance in question,
11528 * it will inherit an #AtkObject implementation from the first ancestor
11529 * class for which such an implementation is defined.
11531 * The documentation of the
11532 * <ulink url="http://developer.gnome.org/atk/stable/">ATK</ulink>
11533 * library contains more information about accessible objects and their uses.
11535 * Returns: (transfer none): the #AtkObject associated with @widget
11538 gtk_widget_get_accessible (GtkWidget *widget)
11540 GtkWidgetClass *klass;
11542 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11544 klass = GTK_WIDGET_GET_CLASS (widget);
11546 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11548 return klass->get_accessible (widget);
11552 gtk_widget_real_get_accessible (GtkWidget *widget)
11554 AtkObject* accessible;
11556 accessible = g_object_get_qdata (G_OBJECT (widget),
11557 quark_accessible_object);
11560 GtkWidgetClass *widget_class;
11561 GtkWidgetClassPrivate *priv;
11562 AtkObjectFactory *factory;
11563 AtkRegistry *default_registry;
11565 widget_class = GTK_WIDGET_GET_CLASS (widget);
11566 priv = widget_class->priv;
11568 if (priv->accessible_type == GTK_TYPE_ACCESSIBLE)
11570 default_registry = atk_get_default_registry ();
11571 factory = atk_registry_get_factory (default_registry,
11572 G_TYPE_FROM_INSTANCE (widget));
11574 atk_object_factory_create_accessible (factory,
11575 G_OBJECT (widget));
11577 if (priv->accessible_role != ATK_ROLE_INVALID)
11578 atk_object_set_role (accessible, priv->accessible_role);
11580 g_object_set_qdata (G_OBJECT (widget),
11581 quark_accessible_object,
11586 accessible = g_object_new (priv->accessible_type,
11589 if (priv->accessible_role != ATK_ROLE_INVALID)
11590 atk_object_set_role (accessible, priv->accessible_role);
11592 g_object_set_qdata (G_OBJECT (widget),
11593 quark_accessible_object,
11596 atk_object_initialize (accessible, widget);
11598 /* Set the role again, since we don't want a role set
11599 * in some parent initialize() function to override
11602 if (priv->accessible_role != ATK_ROLE_INVALID)
11603 atk_object_set_role (accessible, priv->accessible_role);
11610 * Initialize a AtkImplementorIface instance's virtual pointers as
11611 * appropriate to this implementor's class (GtkWidget).
11614 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11616 iface->ref_accessible = gtk_widget_ref_accessible;
11620 gtk_widget_ref_accessible (AtkImplementor *implementor)
11622 AtkObject *accessible;
11624 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11626 g_object_ref (accessible);
11631 * Expand flag management
11635 gtk_widget_update_computed_expand (GtkWidget *widget)
11637 GtkWidgetPrivate *priv;
11639 priv = widget->priv;
11641 if (priv->need_compute_expand)
11645 if (priv->hexpand_set)
11650 if (priv->vexpand_set)
11655 /* we don't need to use compute_expand if both expands are
11656 * forced by the app
11658 if (!(priv->hexpand_set && priv->vexpand_set))
11660 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11664 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11665 priv->hexpand_set ? &ignored : &h,
11666 priv->vexpand_set ? &ignored : &v);
11670 priv->need_compute_expand = FALSE;
11671 priv->computed_hexpand = h != FALSE;
11672 priv->computed_vexpand = v != FALSE;
11677 * gtk_widget_queue_compute_expand:
11678 * @widget: a #GtkWidget
11680 * Mark @widget as needing to recompute its expand flags. Call
11681 * this function when setting legacy expand child properties
11682 * on the child of a container.
11684 * See gtk_widget_compute_expand().
11687 gtk_widget_queue_compute_expand (GtkWidget *widget)
11690 gboolean changed_anything;
11692 if (widget->priv->need_compute_expand)
11695 changed_anything = FALSE;
11697 while (parent != NULL)
11699 if (!parent->priv->need_compute_expand)
11701 parent->priv->need_compute_expand = TRUE;
11702 changed_anything = TRUE;
11705 /* Note: if we had an invariant that "if a child needs to
11706 * compute expand, its parents also do" then we could stop going
11707 * up when we got to a parent that already needed to
11708 * compute. However, in general we compute expand lazily (as
11709 * soon as we see something in a subtree that is expand, we know
11710 * we're expanding) and so this invariant does not hold and we
11711 * have to always walk all the way up in case some ancestor
11712 * is not currently need_compute_expand.
11715 parent = parent->priv->parent;
11718 /* recomputing expand always requires
11719 * a relayout as well
11721 if (changed_anything)
11722 gtk_widget_queue_resize (widget);
11726 * gtk_widget_compute_expand:
11727 * @widget: the widget
11728 * @orientation: expand direction
11730 * Computes whether a container should give this widget extra space
11731 * when possible. Containers should check this, rather than
11732 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11734 * This function already checks whether the widget is visible, so
11735 * visibility does not need to be checked separately. Non-visible
11736 * widgets are not expanded.
11738 * The computed expand value uses either the expand setting explicitly
11739 * set on the widget itself, or, if none has been explicitly set,
11740 * the widget may expand if some of its children do.
11742 * Return value: whether widget tree rooted here should be expanded
11745 gtk_widget_compute_expand (GtkWidget *widget,
11746 GtkOrientation orientation)
11748 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11750 /* We never make a widget expand if not even showing. */
11751 if (!gtk_widget_get_visible (widget))
11754 gtk_widget_update_computed_expand (widget);
11756 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11758 return widget->priv->computed_hexpand;
11762 return widget->priv->computed_vexpand;
11767 gtk_widget_set_expand (GtkWidget *widget,
11768 GtkOrientation orientation,
11771 const char *expand_prop;
11772 const char *expand_set_prop;
11774 GtkWidgetPrivate *priv;
11776 g_return_if_fail (GTK_IS_WIDGET (widget));
11778 priv = widget->priv;
11780 expand = expand != FALSE;
11782 was_both = priv->hexpand && priv->vexpand;
11784 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11786 if (priv->hexpand_set &&
11787 priv->hexpand == expand)
11790 priv->hexpand_set = TRUE;
11791 priv->hexpand = expand;
11793 expand_prop = "hexpand";
11794 expand_set_prop = "hexpand-set";
11798 if (priv->vexpand_set &&
11799 priv->vexpand == expand)
11802 priv->vexpand_set = TRUE;
11803 priv->vexpand = expand;
11805 expand_prop = "vexpand";
11806 expand_set_prop = "vexpand-set";
11809 gtk_widget_queue_compute_expand (widget);
11811 g_object_freeze_notify (G_OBJECT (widget));
11812 g_object_notify (G_OBJECT (widget), expand_prop);
11813 g_object_notify (G_OBJECT (widget), expand_set_prop);
11814 if (was_both != (priv->hexpand && priv->vexpand))
11815 g_object_notify (G_OBJECT (widget), "expand");
11816 g_object_thaw_notify (G_OBJECT (widget));
11820 gtk_widget_set_expand_set (GtkWidget *widget,
11821 GtkOrientation orientation,
11824 GtkWidgetPrivate *priv;
11827 priv = widget->priv;
11829 set = set != FALSE;
11831 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11833 if (set == priv->hexpand_set)
11836 priv->hexpand_set = set;
11837 prop = "hexpand-set";
11841 if (set == priv->vexpand_set)
11844 priv->vexpand_set = set;
11845 prop = "vexpand-set";
11848 gtk_widget_queue_compute_expand (widget);
11850 g_object_notify (G_OBJECT (widget), prop);
11854 * gtk_widget_get_hexpand:
11855 * @widget: the widget
11857 * Gets whether the widget would like any available extra horizontal
11858 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11859 * generally receive the extra space. For example, a list or
11860 * scrollable area or document in your window would often be set to
11863 * Containers should use gtk_widget_compute_expand() rather than
11864 * this function, to see whether a widget, or any of its children,
11865 * has the expand flag set. If any child of a widget wants to
11866 * expand, the parent may ask to expand also.
11868 * This function only looks at the widget's own hexpand flag, rather
11869 * than computing whether the entire widget tree rooted at this widget
11872 * Return value: whether hexpand flag is set
11875 gtk_widget_get_hexpand (GtkWidget *widget)
11877 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11879 return widget->priv->hexpand;
11883 * gtk_widget_set_hexpand:
11884 * @widget: the widget
11885 * @expand: whether to expand
11887 * Sets whether the widget would like any available extra horizontal
11888 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11889 * generally receive the extra space. For example, a list or
11890 * scrollable area or document in your window would often be set to
11893 * Call this function to set the expand flag if you would like your
11894 * widget to become larger horizontally when the window has extra
11897 * By default, widgets automatically expand if any of their children
11898 * want to expand. (To see if a widget will automatically expand given
11899 * its current children and state, call gtk_widget_compute_expand(). A
11900 * container can decide how the expandability of children affects the
11901 * expansion of the container by overriding the compute_expand virtual
11902 * method on #GtkWidget.).
11904 * Setting hexpand explicitly with this function will override the
11905 * automatic expand behavior.
11907 * This function forces the widget to expand or not to expand,
11908 * regardless of children. The override occurs because
11909 * gtk_widget_set_hexpand() sets the hexpand-set property (see
11910 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
11911 * value to be used, rather than looking at children and widget state.
11914 gtk_widget_set_hexpand (GtkWidget *widget,
11917 g_return_if_fail (GTK_IS_WIDGET (widget));
11919 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
11923 * gtk_widget_get_hexpand_set:
11924 * @widget: the widget
11926 * Gets whether gtk_widget_set_hexpand() has been used to
11927 * explicitly set the expand flag on this widget.
11929 * If hexpand is set, then it overrides any computed
11930 * expand value based on child widgets. If hexpand is not
11931 * set, then the expand value depends on whether any
11932 * children of the widget would like to expand.
11934 * There are few reasons to use this function, but it's here
11935 * for completeness and consistency.
11937 * Return value: whether hexpand has been explicitly set
11940 gtk_widget_get_hexpand_set (GtkWidget *widget)
11942 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11944 return widget->priv->hexpand_set;
11948 * gtk_widget_set_hexpand_set:
11949 * @widget: the widget
11950 * @set: value for hexpand-set property
11952 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
11955 * The hexpand-set property will be set automatically when you call
11956 * gtk_widget_set_hexpand() to set hexpand, so the most likely
11957 * reason to use this function would be to unset an explicit expand
11960 * If hexpand is set, then it overrides any computed
11961 * expand value based on child widgets. If hexpand is not
11962 * set, then the expand value depends on whether any
11963 * children of the widget would like to expand.
11965 * There are few reasons to use this function, but it's here
11966 * for completeness and consistency.
11969 gtk_widget_set_hexpand_set (GtkWidget *widget,
11972 g_return_if_fail (GTK_IS_WIDGET (widget));
11974 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
11979 * gtk_widget_get_vexpand:
11980 * @widget: the widget
11982 * Gets whether the widget would like any available extra vertical
11985 * See gtk_widget_get_hexpand() for more detail.
11987 * Return value: whether vexpand flag is set
11990 gtk_widget_get_vexpand (GtkWidget *widget)
11992 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11994 return widget->priv->vexpand;
11998 * gtk_widget_set_vexpand:
11999 * @widget: the widget
12000 * @expand: whether to expand
12002 * Sets whether the widget would like any available extra vertical
12005 * See gtk_widget_set_hexpand() for more detail.
12008 gtk_widget_set_vexpand (GtkWidget *widget,
12011 g_return_if_fail (GTK_IS_WIDGET (widget));
12013 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12017 * gtk_widget_get_vexpand_set:
12018 * @widget: the widget
12020 * Gets whether gtk_widget_set_vexpand() has been used to
12021 * explicitly set the expand flag on this widget.
12023 * See gtk_widget_get_hexpand_set() for more detail.
12025 * Return value: whether vexpand has been explicitly set
12028 gtk_widget_get_vexpand_set (GtkWidget *widget)
12030 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12032 return widget->priv->vexpand_set;
12036 * gtk_widget_set_vexpand_set:
12037 * @widget: the widget
12038 * @set: value for vexpand-set property
12040 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12043 * See gtk_widget_set_hexpand_set() for more detail.
12046 gtk_widget_set_vexpand_set (GtkWidget *widget,
12049 g_return_if_fail (GTK_IS_WIDGET (widget));
12051 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12055 * GtkBuildable implementation
12057 static GQuark quark_builder_has_default = 0;
12058 static GQuark quark_builder_has_focus = 0;
12059 static GQuark quark_builder_atk_relations = 0;
12060 static GQuark quark_builder_set_name = 0;
12063 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12065 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12066 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12067 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12068 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12070 iface->set_name = gtk_widget_buildable_set_name;
12071 iface->get_name = gtk_widget_buildable_get_name;
12072 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12073 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12074 iface->parser_finished = gtk_widget_buildable_parser_finished;
12075 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12076 iface->custom_finished = gtk_widget_buildable_custom_finished;
12080 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12083 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12084 g_strdup (name), g_free);
12087 static const gchar *
12088 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12090 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12094 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12095 GtkBuilder *builder,
12096 const gchar *childname)
12098 if (strcmp (childname, "accessible") == 0)
12099 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12105 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12106 GtkBuilder *builder,
12108 const GValue *value)
12110 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12111 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12112 GINT_TO_POINTER (TRUE));
12113 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12114 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12115 GINT_TO_POINTER (TRUE));
12117 g_object_set_property (G_OBJECT (buildable), name, value);
12122 gchar *action_name;
12123 GString *description;
12125 gboolean translatable;
12135 free_action (AtkActionData *data, gpointer user_data)
12137 g_free (data->action_name);
12138 g_string_free (data->description, TRUE);
12139 g_free (data->context);
12140 g_slice_free (AtkActionData, data);
12144 free_relation (AtkRelationData *data, gpointer user_data)
12146 g_free (data->target);
12147 g_free (data->type);
12148 g_slice_free (AtkRelationData, data);
12152 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12153 GtkBuilder *builder)
12155 GSList *atk_relations;
12157 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12158 gtk_widget_grab_default (GTK_WIDGET (buildable));
12159 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12160 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12162 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12163 quark_builder_atk_relations);
12166 AtkObject *accessible;
12167 AtkRelationSet *relation_set;
12170 AtkRelationType relation_type;
12171 AtkObject *target_accessible;
12173 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12174 relation_set = atk_object_ref_relation_set (accessible);
12176 for (l = atk_relations; l; l = l->next)
12178 AtkRelationData *relation = (AtkRelationData*)l->data;
12180 target = gtk_builder_get_object (builder, relation->target);
12183 g_warning ("Target object %s in <relation> does not exist",
12187 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12188 g_assert (target_accessible != NULL);
12190 relation_type = atk_relation_type_for_name (relation->type);
12191 if (relation_type == ATK_RELATION_NULL)
12193 g_warning ("<relation> type %s not found",
12197 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12198 target_accessible);
12200 g_object_unref (relation_set);
12202 g_slist_free_full (atk_relations, (GDestroyNotify) free_relation);
12203 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12212 } AccessibilitySubParserData;
12215 accessibility_start_element (GMarkupParseContext *context,
12216 const gchar *element_name,
12217 const gchar **names,
12218 const gchar **values,
12219 gpointer user_data,
12222 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12224 gint line_number, char_number;
12226 if (strcmp (element_name, "relation") == 0)
12228 gchar *target = NULL;
12229 gchar *type = NULL;
12230 AtkRelationData *relation;
12232 for (i = 0; names[i]; i++)
12234 if (strcmp (names[i], "target") == 0)
12235 target = g_strdup (values[i]);
12236 else if (strcmp (names[i], "type") == 0)
12237 type = g_strdup (values[i]);
12240 g_markup_parse_context_get_position (context,
12243 g_set_error (error,
12245 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12246 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12248 line_number, char_number, names[i], "relation");
12255 if (!target || !type)
12257 g_markup_parse_context_get_position (context,
12260 g_set_error (error,
12262 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12263 "%s:%d:%d <%s> requires attribute \"%s\"",
12265 line_number, char_number, "relation",
12266 type ? "target" : "type");
12272 relation = g_slice_new (AtkRelationData);
12273 relation->target = target;
12274 relation->type = type;
12276 data->relations = g_slist_prepend (data->relations, relation);
12278 else if (strcmp (element_name, "action") == 0)
12280 const gchar *action_name = NULL;
12281 const gchar *description = NULL;
12282 const gchar *msg_context = NULL;
12283 gboolean translatable = FALSE;
12284 AtkActionData *action;
12286 for (i = 0; names[i]; i++)
12288 if (strcmp (names[i], "action_name") == 0)
12289 action_name = values[i];
12290 else if (strcmp (names[i], "description") == 0)
12291 description = values[i];
12292 else if (strcmp (names[i], "translatable") == 0)
12294 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12297 else if (strcmp (names[i], "comments") == 0)
12299 /* do nothing, comments are for translators */
12301 else if (strcmp (names[i], "context") == 0)
12302 msg_context = values[i];
12305 g_markup_parse_context_get_position (context,
12308 g_set_error (error,
12310 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12311 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12313 line_number, char_number, names[i], "action");
12320 g_markup_parse_context_get_position (context,
12323 g_set_error (error,
12325 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12326 "%s:%d:%d <%s> requires attribute \"%s\"",
12328 line_number, char_number, "action",
12333 action = g_slice_new (AtkActionData);
12334 action->action_name = g_strdup (action_name);
12335 action->description = g_string_new (description);
12336 action->context = g_strdup (msg_context);
12337 action->translatable = translatable;
12339 data->actions = g_slist_prepend (data->actions, action);
12341 else if (strcmp (element_name, "accessibility") == 0)
12344 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12348 accessibility_text (GMarkupParseContext *context,
12351 gpointer user_data,
12354 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12356 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12358 AtkActionData *action = data->actions->data;
12360 g_string_append_len (action->description, text, text_len);
12364 static const GMarkupParser accessibility_parser =
12366 accessibility_start_element,
12368 accessibility_text,
12377 } AccelGroupParserData;
12380 accel_group_start_element (GMarkupParseContext *context,
12381 const gchar *element_name,
12382 const gchar **names,
12383 const gchar **values,
12384 gpointer user_data,
12389 guint modifiers = 0;
12390 gchar *signal = NULL;
12391 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12393 for (i = 0; names[i]; i++)
12395 if (strcmp (names[i], "key") == 0)
12396 key = gdk_keyval_from_name (values[i]);
12397 else if (strcmp (names[i], "modifiers") == 0)
12399 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12405 else if (strcmp (names[i], "signal") == 0)
12406 signal = g_strdup (values[i]);
12409 if (key == 0 || signal == NULL)
12411 g_warning ("<accelerator> requires key and signal attributes");
12414 parser_data->key = key;
12415 parser_data->modifiers = modifiers;
12416 parser_data->signal = signal;
12419 static const GMarkupParser accel_group_parser =
12421 accel_group_start_element,
12430 style_start_element (GMarkupParseContext *context,
12431 const gchar *element_name,
12432 const gchar **names,
12433 const gchar **values,
12434 gpointer user_data,
12437 StyleParserData *style_data = (StyleParserData *)user_data;
12440 if (strcmp (element_name, "class") == 0)
12442 if (g_markup_collect_attributes (element_name,
12446 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12447 G_MARKUP_COLLECT_INVALID))
12449 style_data->classes = g_slist_append (style_data->classes, class_name);
12452 else if (strcmp (element_name, "style") == 0)
12455 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12458 static const GMarkupParser style_parser =
12460 style_start_element,
12464 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12465 GtkBuilder *builder,
12467 const gchar *tagname,
12468 GMarkupParser *parser,
12471 g_assert (buildable);
12473 if (strcmp (tagname, "accelerator") == 0)
12475 AccelGroupParserData *parser_data;
12477 parser_data = g_slice_new0 (AccelGroupParserData);
12478 parser_data->object = g_object_ref (buildable);
12479 *parser = accel_group_parser;
12480 *data = parser_data;
12483 if (strcmp (tagname, "accessibility") == 0)
12485 AccessibilitySubParserData *parser_data;
12487 parser_data = g_slice_new0 (AccessibilitySubParserData);
12488 *parser = accessibility_parser;
12489 *data = parser_data;
12492 if (strcmp (tagname, "style") == 0)
12494 StyleParserData *parser_data;
12496 parser_data = g_slice_new0 (StyleParserData);
12497 *parser = style_parser;
12498 *data = parser_data;
12506 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12507 GtkWidget *toplevel,
12508 gpointer user_data)
12510 AccelGroupParserData *accel_data;
12511 GSList *accel_groups;
12512 GtkAccelGroup *accel_group;
12514 g_return_if_fail (GTK_IS_WIDGET (widget));
12515 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12516 g_return_if_fail (user_data != NULL);
12518 accel_data = (AccelGroupParserData*)user_data;
12519 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12520 if (g_slist_length (accel_groups) == 0)
12522 accel_group = gtk_accel_group_new ();
12523 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12527 g_assert (g_slist_length (accel_groups) == 1);
12528 accel_group = g_slist_nth_data (accel_groups, 0);
12531 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12532 accel_data->signal,
12535 accel_data->modifiers,
12536 GTK_ACCEL_VISIBLE);
12538 g_object_unref (accel_data->object);
12539 g_free (accel_data->signal);
12540 g_slice_free (AccelGroupParserData, accel_data);
12544 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12545 GtkBuilder *builder,
12547 const gchar *tagname,
12548 gpointer user_data)
12550 if (strcmp (tagname, "accelerator") == 0)
12552 AccelGroupParserData *accel_data;
12553 GtkWidget *toplevel;
12555 accel_data = (AccelGroupParserData*)user_data;
12556 g_assert (accel_data->object);
12558 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12560 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12562 else if (strcmp (tagname, "accessibility") == 0)
12564 AccessibilitySubParserData *a11y_data;
12566 a11y_data = (AccessibilitySubParserData*)user_data;
12568 if (a11y_data->actions)
12570 AtkObject *accessible;
12575 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12577 if (ATK_IS_ACTION (accessible))
12579 action = ATK_ACTION (accessible);
12580 n_actions = atk_action_get_n_actions (action);
12582 for (l = a11y_data->actions; l; l = l->next)
12584 AtkActionData *action_data = (AtkActionData*)l->data;
12586 for (i = 0; i < n_actions; i++)
12587 if (strcmp (atk_action_get_name (action, i),
12588 action_data->action_name) == 0)
12593 gchar *description;
12595 if (action_data->translatable && action_data->description->len)
12596 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12597 action_data->context,
12598 action_data->description->str);
12600 description = action_data->description->str;
12602 atk_action_set_description (action, i, description);
12607 g_warning ("accessibility action on a widget that does not implement AtkAction");
12609 g_slist_free_full (a11y_data->actions, (GDestroyNotify) free_action);
12612 if (a11y_data->relations)
12613 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12614 a11y_data->relations);
12616 g_slice_free (AccessibilitySubParserData, a11y_data);
12618 else if (strcmp (tagname, "style") == 0)
12620 StyleParserData *style_data = (StyleParserData *)user_data;
12621 GtkStyleContext *context;
12624 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
12626 for (l = style_data->classes; l; l = l->next)
12627 gtk_style_context_add_class (context, (const gchar *)l->data);
12629 gtk_widget_reset_style (GTK_WIDGET (buildable));
12631 g_slist_free_full (style_data->classes, g_free);
12632 g_slice_free (StyleParserData, style_data);
12636 static GtkSizeRequestMode
12637 gtk_widget_real_get_request_mode (GtkWidget *widget)
12639 /* By default widgets dont trade size at all. */
12640 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
12644 gtk_widget_real_get_width (GtkWidget *widget,
12645 gint *minimum_size,
12646 gint *natural_size)
12656 gtk_widget_real_get_height (GtkWidget *widget,
12657 gint *minimum_size,
12658 gint *natural_size)
12668 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12670 gint *minimum_height,
12671 gint *natural_height)
12673 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12677 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12679 gint *minimum_width,
12680 gint *natural_width)
12682 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12686 * gtk_widget_get_halign:
12687 * @widget: a #GtkWidget
12689 * Gets the value of the #GtkWidget:halign property.
12691 * Returns: the horizontal alignment of @widget
12694 gtk_widget_get_halign (GtkWidget *widget)
12696 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12697 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12701 * gtk_widget_set_halign:
12702 * @widget: a #GtkWidget
12703 * @align: the horizontal alignment
12705 * Sets the horizontal alignment of @widget.
12706 * See the #GtkWidget:halign property.
12709 gtk_widget_set_halign (GtkWidget *widget,
12712 GtkWidgetAuxInfo *aux_info;
12714 g_return_if_fail (GTK_IS_WIDGET (widget));
12716 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12718 if (aux_info->halign == align)
12721 aux_info->halign = align;
12722 gtk_widget_queue_resize (widget);
12723 g_object_notify (G_OBJECT (widget), "halign");
12727 * gtk_widget_get_valign:
12728 * @widget: a #GtkWidget
12730 * Gets the value of the #GtkWidget:valign property.
12732 * Returns: the vertical alignment of @widget
12735 gtk_widget_get_valign (GtkWidget *widget)
12737 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12738 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12742 * gtk_widget_set_valign:
12743 * @widget: a #GtkWidget
12744 * @align: the vertical alignment
12746 * Sets the vertical alignment of @widget.
12747 * See the #GtkWidget:valign property.
12750 gtk_widget_set_valign (GtkWidget *widget,
12753 GtkWidgetAuxInfo *aux_info;
12755 g_return_if_fail (GTK_IS_WIDGET (widget));
12757 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12759 if (aux_info->valign == align)
12762 aux_info->valign = align;
12763 gtk_widget_queue_resize (widget);
12764 g_object_notify (G_OBJECT (widget), "valign");
12768 * gtk_widget_get_margin_left:
12769 * @widget: a #GtkWidget
12771 * Gets the value of the #GtkWidget:margin-left property.
12773 * Returns: The left margin of @widget
12778 gtk_widget_get_margin_left (GtkWidget *widget)
12780 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12782 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12786 * gtk_widget_set_margin_left:
12787 * @widget: a #GtkWidget
12788 * @margin: the left margin
12790 * Sets the left margin of @widget.
12791 * See the #GtkWidget:margin-left property.
12796 gtk_widget_set_margin_left (GtkWidget *widget,
12799 GtkWidgetAuxInfo *aux_info;
12801 g_return_if_fail (GTK_IS_WIDGET (widget));
12802 g_return_if_fail (margin <= G_MAXINT16);
12804 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12806 if (aux_info->margin.left == margin)
12809 aux_info->margin.left = margin;
12810 gtk_widget_queue_resize (widget);
12811 g_object_notify (G_OBJECT (widget), "margin-left");
12815 * gtk_widget_get_margin_right:
12816 * @widget: a #GtkWidget
12818 * Gets the value of the #GtkWidget:margin-right property.
12820 * Returns: The right margin of @widget
12825 gtk_widget_get_margin_right (GtkWidget *widget)
12827 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12829 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12833 * gtk_widget_set_margin_right:
12834 * @widget: a #GtkWidget
12835 * @margin: the right margin
12837 * Sets the right margin of @widget.
12838 * See the #GtkWidget:margin-right property.
12843 gtk_widget_set_margin_right (GtkWidget *widget,
12846 GtkWidgetAuxInfo *aux_info;
12848 g_return_if_fail (GTK_IS_WIDGET (widget));
12849 g_return_if_fail (margin <= G_MAXINT16);
12851 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12853 if (aux_info->margin.right == margin)
12856 aux_info->margin.right = margin;
12857 gtk_widget_queue_resize (widget);
12858 g_object_notify (G_OBJECT (widget), "margin-right");
12862 * gtk_widget_get_margin_top:
12863 * @widget: a #GtkWidget
12865 * Gets the value of the #GtkWidget:margin-top property.
12867 * Returns: The top margin of @widget
12872 gtk_widget_get_margin_top (GtkWidget *widget)
12874 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12876 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12880 * gtk_widget_set_margin_top:
12881 * @widget: a #GtkWidget
12882 * @margin: the top margin
12884 * Sets the top margin of @widget.
12885 * See the #GtkWidget:margin-top property.
12890 gtk_widget_set_margin_top (GtkWidget *widget,
12893 GtkWidgetAuxInfo *aux_info;
12895 g_return_if_fail (GTK_IS_WIDGET (widget));
12896 g_return_if_fail (margin <= G_MAXINT16);
12898 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12900 if (aux_info->margin.top == margin)
12903 aux_info->margin.top = margin;
12904 gtk_widget_queue_resize (widget);
12905 g_object_notify (G_OBJECT (widget), "margin-top");
12909 * gtk_widget_get_margin_bottom:
12910 * @widget: a #GtkWidget
12912 * Gets the value of the #GtkWidget:margin-bottom property.
12914 * Returns: The bottom margin of @widget
12919 gtk_widget_get_margin_bottom (GtkWidget *widget)
12921 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12923 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
12927 * gtk_widget_set_margin_bottom:
12928 * @widget: a #GtkWidget
12929 * @margin: the bottom margin
12931 * Sets the bottom margin of @widget.
12932 * See the #GtkWidget:margin-bottom property.
12937 gtk_widget_set_margin_bottom (GtkWidget *widget,
12940 GtkWidgetAuxInfo *aux_info;
12942 g_return_if_fail (GTK_IS_WIDGET (widget));
12943 g_return_if_fail (margin <= G_MAXINT16);
12945 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12947 if (aux_info->margin.bottom == margin)
12950 aux_info->margin.bottom = margin;
12951 gtk_widget_queue_resize (widget);
12952 g_object_notify (G_OBJECT (widget), "margin-bottom");
12956 * gtk_widget_get_clipboard:
12957 * @widget: a #GtkWidget
12958 * @selection: a #GdkAtom which identifies the clipboard
12959 * to use. %GDK_SELECTION_CLIPBOARD gives the
12960 * default clipboard. Another common value
12961 * is %GDK_SELECTION_PRIMARY, which gives
12962 * the primary X selection.
12964 * Returns the clipboard object for the given selection to
12965 * be used with @widget. @widget must have a #GdkDisplay
12966 * associated with it, so must be attached to a toplevel
12969 * Return value: (transfer none): the appropriate clipboard object. If no
12970 * clipboard already exists, a new one will
12971 * be created. Once a clipboard object has
12972 * been created, it is persistent for all time.
12977 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
12979 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12980 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
12982 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
12987 * gtk_widget_list_mnemonic_labels:
12988 * @widget: a #GtkWidget
12990 * Returns a newly allocated list of the widgets, normally labels, for
12991 * which this widget is the target of a mnemonic (see for example,
12992 * gtk_label_set_mnemonic_widget()).
12994 * The widgets in the list are not individually referenced. If you
12995 * want to iterate through the list and perform actions involving
12996 * callbacks that might destroy the widgets, you
12997 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
12998 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
12999 * widgets afterwards.
13001 * Return value: (element-type GtkWidget) (transfer container): the list of
13002 * mnemonic labels; free this list
13003 * with g_list_free() when you are done with it.
13008 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
13010 GList *list = NULL;
13013 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13015 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13016 list = g_list_prepend (list, l->data);
13022 * gtk_widget_add_mnemonic_label:
13023 * @widget: a #GtkWidget
13024 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13026 * Adds a widget to the list of mnemonic labels for
13027 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13028 * list of mnemonic labels for the widget is cleared when the
13029 * widget is destroyed, so the caller must make sure to update
13030 * its internal state at this point as well, by using a connection
13031 * to the #GtkWidget::destroy signal or a weak notifier.
13036 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13039 GSList *old_list, *new_list;
13041 g_return_if_fail (GTK_IS_WIDGET (widget));
13042 g_return_if_fail (GTK_IS_WIDGET (label));
13044 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13045 new_list = g_slist_prepend (old_list, label);
13047 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13048 new_list, (GDestroyNotify) g_slist_free);
13052 * gtk_widget_remove_mnemonic_label:
13053 * @widget: a #GtkWidget
13054 * @label: a #GtkWidget that was previously set as a mnemnic label for
13055 * @widget with gtk_widget_add_mnemonic_label().
13057 * Removes a widget from the list of mnemonic labels for
13058 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13059 * must have previously been added to the list with
13060 * gtk_widget_add_mnemonic_label().
13065 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13068 GSList *old_list, *new_list;
13070 g_return_if_fail (GTK_IS_WIDGET (widget));
13071 g_return_if_fail (GTK_IS_WIDGET (label));
13073 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13074 new_list = g_slist_remove (old_list, label);
13077 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13078 new_list, (GDestroyNotify) g_slist_free);
13082 * gtk_widget_get_no_show_all:
13083 * @widget: a #GtkWidget
13085 * Returns the current value of the #GtkWidget:no-show-all property,
13086 * which determines whether calls to gtk_widget_show_all()
13087 * will affect this widget.
13089 * Return value: the current value of the "no-show-all" property.
13094 gtk_widget_get_no_show_all (GtkWidget *widget)
13096 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13098 return widget->priv->no_show_all;
13102 * gtk_widget_set_no_show_all:
13103 * @widget: a #GtkWidget
13104 * @no_show_all: the new value for the "no-show-all" property
13106 * Sets the #GtkWidget:no-show-all property, which determines whether
13107 * calls to gtk_widget_show_all() will affect this widget.
13109 * This is mostly for use in constructing widget hierarchies with externally
13110 * controlled visibility, see #GtkUIManager.
13115 gtk_widget_set_no_show_all (GtkWidget *widget,
13116 gboolean no_show_all)
13118 g_return_if_fail (GTK_IS_WIDGET (widget));
13120 no_show_all = (no_show_all != FALSE);
13122 if (widget->priv->no_show_all != no_show_all)
13124 widget->priv->no_show_all = no_show_all;
13126 g_object_notify (G_OBJECT (widget), "no-show-all");
13132 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13133 gboolean has_tooltip,
13136 GtkWidgetPrivate *priv = widget->priv;
13137 gboolean priv_has_tooltip;
13139 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13140 quark_has_tooltip));
13142 if (priv_has_tooltip != has_tooltip || force)
13144 priv_has_tooltip = has_tooltip;
13146 if (priv_has_tooltip)
13148 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13149 gdk_window_set_events (priv->window,
13150 gdk_window_get_events (priv->window) |
13151 GDK_LEAVE_NOTIFY_MASK |
13152 GDK_POINTER_MOTION_MASK |
13153 GDK_POINTER_MOTION_HINT_MASK);
13155 if (gtk_widget_get_has_window (widget))
13156 gtk_widget_add_events (widget,
13157 GDK_LEAVE_NOTIFY_MASK |
13158 GDK_POINTER_MOTION_MASK |
13159 GDK_POINTER_MOTION_HINT_MASK);
13162 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13163 GUINT_TO_POINTER (priv_has_tooltip));
13168 * gtk_widget_set_tooltip_window:
13169 * @widget: a #GtkWidget
13170 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13172 * Replaces the default, usually yellow, window used for displaying
13173 * tooltips with @custom_window. GTK+ will take care of showing and
13174 * hiding @custom_window at the right moment, to behave likewise as
13175 * the default tooltip window. If @custom_window is %NULL, the default
13176 * tooltip window will be used.
13178 * If the custom window should have the default theming it needs to
13179 * have the name "gtk-tooltip", see gtk_widget_set_name().
13184 gtk_widget_set_tooltip_window (GtkWidget *widget,
13185 GtkWindow *custom_window)
13187 gboolean has_tooltip;
13188 gchar *tooltip_markup;
13190 g_return_if_fail (GTK_IS_WIDGET (widget));
13191 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13193 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13196 g_object_ref (custom_window);
13198 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13199 custom_window, g_object_unref);
13201 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13202 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13204 if (has_tooltip && gtk_widget_get_visible (widget))
13205 gtk_widget_queue_tooltip_query (widget);
13209 * gtk_widget_get_tooltip_window:
13210 * @widget: a #GtkWidget
13212 * Returns the #GtkWindow of the current tooltip. This can be the
13213 * GtkWindow created by default, or the custom tooltip window set
13214 * using gtk_widget_set_tooltip_window().
13216 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13221 gtk_widget_get_tooltip_window (GtkWidget *widget)
13223 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13225 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13229 * gtk_widget_trigger_tooltip_query:
13230 * @widget: a #GtkWidget
13232 * Triggers a tooltip query on the display where the toplevel of @widget
13233 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13239 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13241 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13244 static guint tooltip_query_id;
13245 static GSList *tooltip_query_displays;
13248 tooltip_query_idle (gpointer data)
13250 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13251 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13252 g_slist_free (tooltip_query_displays);
13254 tooltip_query_displays = NULL;
13255 tooltip_query_id = 0;
13261 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13263 GdkDisplay *display;
13265 display = gtk_widget_get_display (widget);
13267 if (!g_slist_find (tooltip_query_displays, display))
13268 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13270 if (tooltip_query_id == 0)
13271 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13275 * gtk_widget_set_tooltip_text:
13276 * @widget: a #GtkWidget
13277 * @text: the contents of the tooltip for @widget
13279 * Sets @text as the contents of the tooltip. This function will take
13280 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13281 * handler for the #GtkWidget::query-tooltip signal.
13283 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13288 gtk_widget_set_tooltip_text (GtkWidget *widget,
13291 g_return_if_fail (GTK_IS_WIDGET (widget));
13293 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13297 * gtk_widget_get_tooltip_text:
13298 * @widget: a #GtkWidget
13300 * Gets the contents of the tooltip for @widget.
13302 * Return value: the tooltip text, or %NULL. You should free the
13303 * returned string with g_free() when done.
13308 gtk_widget_get_tooltip_text (GtkWidget *widget)
13310 gchar *text = NULL;
13312 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13314 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13320 * gtk_widget_set_tooltip_markup:
13321 * @widget: a #GtkWidget
13322 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13324 * Sets @markup as the contents of the tooltip, which is marked up with
13325 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13327 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13328 * and of the default handler for the #GtkWidget::query-tooltip signal.
13330 * See also the #GtkWidget:tooltip-markup property and
13331 * gtk_tooltip_set_markup().
13336 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13337 const gchar *markup)
13339 g_return_if_fail (GTK_IS_WIDGET (widget));
13341 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13345 * gtk_widget_get_tooltip_markup:
13346 * @widget: a #GtkWidget
13348 * Gets the contents of the tooltip for @widget.
13350 * Return value: the tooltip text, or %NULL. You should free the
13351 * returned string with g_free() when done.
13356 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13358 gchar *text = NULL;
13360 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13362 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13368 * gtk_widget_set_has_tooltip:
13369 * @widget: a #GtkWidget
13370 * @has_tooltip: whether or not @widget has a tooltip.
13372 * Sets the has-tooltip property on @widget to @has_tooltip. See
13373 * #GtkWidget:has-tooltip for more information.
13378 gtk_widget_set_has_tooltip (GtkWidget *widget,
13379 gboolean has_tooltip)
13381 g_return_if_fail (GTK_IS_WIDGET (widget));
13383 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13387 * gtk_widget_get_has_tooltip:
13388 * @widget: a #GtkWidget
13390 * Returns the current value of the has-tooltip property. See
13391 * #GtkWidget:has-tooltip for more information.
13393 * Return value: current value of has-tooltip on @widget.
13398 gtk_widget_get_has_tooltip (GtkWidget *widget)
13400 gboolean has_tooltip = FALSE;
13402 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13404 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13406 return has_tooltip;
13410 * gtk_widget_get_allocation:
13411 * @widget: a #GtkWidget
13412 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13414 * Retrieves the widget's allocation.
13416 * Note, when implementing a #GtkContainer: a widget's allocation will
13417 * be its "adjusted" allocation, that is, the widget's parent
13418 * container typically calls gtk_widget_size_allocate() with an
13419 * allocation, and that allocation is then adjusted (to handle margin
13420 * and alignment for example) before assignment to the widget.
13421 * gtk_widget_get_allocation() returns the adjusted allocation that
13422 * was actually assigned to the widget. The adjusted allocation is
13423 * guaranteed to be completely contained within the
13424 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13425 * is guaranteed that its children stay inside the assigned bounds,
13426 * but not that they have exactly the bounds the container assigned.
13427 * There is no way to get the original allocation assigned by
13428 * gtk_widget_size_allocate(), since it isn't stored; if a container
13429 * implementation needs that information it will have to track it itself.
13434 gtk_widget_get_allocation (GtkWidget *widget,
13435 GtkAllocation *allocation)
13437 GtkWidgetPrivate *priv;
13439 g_return_if_fail (GTK_IS_WIDGET (widget));
13440 g_return_if_fail (allocation != NULL);
13442 priv = widget->priv;
13444 *allocation = priv->allocation;
13448 * gtk_widget_set_allocation:
13449 * @widget: a #GtkWidget
13450 * @allocation: a pointer to a #GtkAllocation to copy from
13452 * Sets the widget's allocation. This should not be used
13453 * directly, but from within a widget's size_allocate method.
13455 * The allocation set should be the "adjusted" or actual
13456 * allocation. If you're implementing a #GtkContainer, you want to use
13457 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13458 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13459 * allocation inside gtk_widget_size_allocate() to create an adjusted
13465 gtk_widget_set_allocation (GtkWidget *widget,
13466 const GtkAllocation *allocation)
13468 GtkWidgetPrivate *priv;
13470 g_return_if_fail (GTK_IS_WIDGET (widget));
13471 g_return_if_fail (allocation != NULL);
13473 priv = widget->priv;
13475 priv->allocation = *allocation;
13479 * gtk_widget_get_allocated_width:
13480 * @widget: the widget to query
13482 * Returns the width that has currently been allocated to @widget.
13483 * This function is intended to be used when implementing handlers
13484 * for the #GtkWidget::draw function.
13486 * Returns: the width of the @widget
13489 gtk_widget_get_allocated_width (GtkWidget *widget)
13491 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13493 return widget->priv->allocation.width;
13497 * gtk_widget_get_allocated_height:
13498 * @widget: the widget to query
13500 * Returns the height that has currently been allocated to @widget.
13501 * This function is intended to be used when implementing handlers
13502 * for the #GtkWidget::draw function.
13504 * Returns: the height of the @widget
13507 gtk_widget_get_allocated_height (GtkWidget *widget)
13509 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13511 return widget->priv->allocation.height;
13515 * gtk_widget_get_requisition:
13516 * @widget: a #GtkWidget
13517 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13519 * Retrieves the widget's requisition.
13521 * This function should only be used by widget implementations in
13522 * order to figure whether the widget's requisition has actually
13523 * changed after some internal state change (so that they can call
13524 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13526 * Normally, gtk_widget_size_request() should be used.
13530 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13531 * removed, If you need to cache sizes across requests and allocations,
13532 * add an explicit cache to the widget in question instead.
13535 gtk_widget_get_requisition (GtkWidget *widget,
13536 GtkRequisition *requisition)
13538 g_return_if_fail (GTK_IS_WIDGET (widget));
13539 g_return_if_fail (requisition != NULL);
13541 gtk_widget_get_preferred_size (widget, requisition, NULL);
13545 * gtk_widget_set_window:
13546 * @widget: a #GtkWidget
13547 * @window: (transfer full): a #GdkWindow
13549 * Sets a widget's window. This function should only be used in a
13550 * widget's #GtkWidget::realize implementation. The %window passed is
13551 * usually either new window created with gdk_window_new(), or the
13552 * window of its parent widget as returned by
13553 * gtk_widget_get_parent_window().
13555 * Widgets must indicate whether they will create their own #GdkWindow
13556 * by calling gtk_widget_set_has_window(). This is usually done in the
13557 * widget's init() function.
13559 * <note><para>This function does not add any reference to @window.</para></note>
13564 gtk_widget_set_window (GtkWidget *widget,
13567 GtkWidgetPrivate *priv;
13569 g_return_if_fail (GTK_IS_WIDGET (widget));
13570 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13572 priv = widget->priv;
13574 if (priv->window != window)
13576 priv->window = window;
13577 g_object_notify (G_OBJECT (widget), "window");
13582 * gtk_widget_get_window:
13583 * @widget: a #GtkWidget
13585 * Returns the widget's window if it is realized, %NULL otherwise
13587 * Return value: (transfer none): @widget's window.
13592 gtk_widget_get_window (GtkWidget *widget)
13594 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13596 return widget->priv->window;
13600 * gtk_widget_get_support_multidevice:
13601 * @widget: a #GtkWidget
13603 * Returns %TRUE if @widget is multiple pointer aware. See
13604 * gtk_widget_set_support_multidevice() for more information.
13606 * Returns: %TRUE if @widget is multidevice aware.
13609 gtk_widget_get_support_multidevice (GtkWidget *widget)
13611 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13613 return widget->priv->multidevice;
13617 * gtk_widget_set_support_multidevice:
13618 * @widget: a #GtkWidget
13619 * @support_multidevice: %TRUE to support input from multiple devices.
13621 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13622 * @widget will start receiving multiple, per device enter/leave events. Note
13623 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13624 * gdk_window_set_support_multidevice() will have to be called manually on them.
13629 gtk_widget_set_support_multidevice (GtkWidget *widget,
13630 gboolean support_multidevice)
13632 GtkWidgetPrivate *priv;
13634 g_return_if_fail (GTK_IS_WIDGET (widget));
13636 priv = widget->priv;
13637 priv->multidevice = (support_multidevice == TRUE);
13639 if (gtk_widget_get_realized (widget))
13640 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13644 _gtk_widget_set_has_focus (GtkWidget *widget,
13645 gboolean has_focus)
13647 widget->priv->has_focus = has_focus;
13650 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
13652 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
13656 * gtk_widget_send_focus_change:
13657 * @widget: a #GtkWidget
13658 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13660 * Sends the focus change @event to @widget
13662 * This function is not meant to be used by applications. The only time it
13663 * should be used is when it is necessary for a #GtkWidget to assign focus
13664 * to a widget that is semantically owned by the first widget even though
13665 * it's not a direct child - for instance, a search entry in a floating
13666 * window similar to the quick search in #GtkTreeView.
13668 * An example of its usage is:
13671 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13673 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13674 * fevent->focus_change.in = TRUE;
13675 * fevent->focus_change.window = gtk_widget_get_window (widget);
13676 * if (fevent->focus_change.window != NULL)
13677 * g_object_ref (fevent->focus_change.window);
13679 * gtk_widget_send_focus_change (widget, fevent);
13681 * gdk_event_free (event);
13684 * Return value: the return value from the event signal emission: %TRUE
13685 * if the event was handled, and %FALSE otherwise
13690 gtk_widget_send_focus_change (GtkWidget *widget,
13695 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13696 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13698 g_object_ref (widget);
13700 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13702 res = gtk_widget_event (widget, event);
13704 g_object_notify (G_OBJECT (widget), "has-focus");
13706 g_object_unref (widget);
13712 * gtk_widget_in_destruction:
13713 * @widget: a #GtkWidget
13715 * Returns whether the widget is currently being destroyed.
13716 * This information can sometimes be used to avoid doing
13717 * unnecessary work.
13719 * Returns: %TRUE if @widget is being destroyed
13722 gtk_widget_in_destruction (GtkWidget *widget)
13724 return widget->priv->in_destruction;
13728 _gtk_widget_get_in_reparent (GtkWidget *widget)
13730 return widget->priv->in_reparent;
13734 _gtk_widget_set_in_reparent (GtkWidget *widget,
13735 gboolean in_reparent)
13737 widget->priv->in_reparent = in_reparent;
13741 _gtk_widget_get_anchored (GtkWidget *widget)
13743 return widget->priv->anchored;
13747 _gtk_widget_set_anchored (GtkWidget *widget,
13750 widget->priv->anchored = anchored;
13754 _gtk_widget_get_shadowed (GtkWidget *widget)
13756 return widget->priv->shadowed;
13760 _gtk_widget_set_shadowed (GtkWidget *widget,
13763 widget->priv->shadowed = shadowed;
13767 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13769 return widget->priv->alloc_needed;
13773 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13774 gboolean alloc_needed)
13776 widget->priv->alloc_needed = alloc_needed;
13780 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13782 return widget->priv->width_request_needed;
13786 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13787 gboolean width_request_needed)
13789 widget->priv->width_request_needed = width_request_needed;
13793 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13795 return widget->priv->height_request_needed;
13799 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13800 gboolean height_request_needed)
13802 widget->priv->height_request_needed = height_request_needed;
13806 _gtk_widget_get_sizegroup_visited (GtkWidget *widget)
13808 return widget->priv->sizegroup_visited;
13812 _gtk_widget_set_sizegroup_visited (GtkWidget *widget,
13815 widget->priv->sizegroup_visited = visited;
13819 _gtk_widget_get_sizegroup_bumping (GtkWidget *widget)
13821 return widget->priv->sizegroup_bumping;
13825 _gtk_widget_set_sizegroup_bumping (GtkWidget *widget,
13828 widget->priv->sizegroup_bumping = bumping;
13832 _gtk_widget_add_sizegroup (GtkWidget *widget,
13837 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13838 groups = g_slist_prepend (groups, group);
13839 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13841 widget->priv->have_size_groups = TRUE;
13845 _gtk_widget_remove_sizegroup (GtkWidget *widget,
13850 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13851 groups = g_slist_remove (groups, group);
13852 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13854 widget->priv->have_size_groups = groups != NULL;
13858 _gtk_widget_get_sizegroups (GtkWidget *widget)
13860 if (widget->priv->have_size_groups)
13861 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13867 _gtk_widget_add_attached_window (GtkWidget *widget,
13870 widget->priv->attached_windows = g_list_prepend (widget->priv->attached_windows, window);
13874 _gtk_widget_remove_attached_window (GtkWidget *widget,
13877 widget->priv->attached_windows = g_list_remove (widget->priv->attached_windows, window);
13881 * gtk_widget_path_append_for_widget:
13882 * @path: a widget path
13883 * @widget: the widget to append to the widget path
13885 * Appends the data from @widget to the widget hierarchy represented
13886 * by @path. This function is a shortcut for adding information from
13887 * @widget to the given @path. This includes setting the name or
13888 * adding the style classes from @widget.
13890 * Returns: the position where the data was inserted
13895 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
13900 g_return_val_if_fail (path != NULL, 0);
13901 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13903 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
13905 if (widget->priv->name)
13906 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
13908 if (widget->priv->context)
13910 GList *classes, *l;
13912 /* Also add any persistent classes in
13913 * the style context the widget path
13915 classes = gtk_style_context_list_classes (widget->priv->context);
13917 for (l = classes; l; l = l->next)
13918 gtk_widget_path_iter_add_class (path, pos, l->data);
13920 g_list_free (classes);
13927 _gtk_widget_create_path (GtkWidget *widget)
13931 parent = widget->priv->parent;
13934 return gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
13937 /* Widget is either toplevel or unparented, treat both
13938 * as toplevels style wise, since there are situations
13939 * where style properties might be retrieved on that
13942 GtkWidget *attach_widget = NULL;
13943 GtkWidgetPath *result;
13945 if (GTK_IS_WINDOW (widget))
13946 attach_widget = gtk_window_get_attached_to (GTK_WINDOW (widget));
13948 if (attach_widget != NULL)
13949 result = gtk_widget_path_copy (gtk_widget_get_path (attach_widget));
13951 result = gtk_widget_path_new ();
13953 gtk_widget_path_append_for_widget (result, widget);
13960 * gtk_widget_get_path:
13961 * @widget: a #GtkWidget
13963 * Returns the #GtkWidgetPath representing @widget, if the widget
13964 * is not connected to a toplevel widget, a partial path will be
13967 * Returns: (transfer none): The #GtkWidgetPath representing @widget
13970 gtk_widget_get_path (GtkWidget *widget)
13972 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13974 if (!widget->priv->path)
13975 widget->priv->path = _gtk_widget_create_path (widget);
13977 return widget->priv->path;
13981 _gtk_widget_style_context_invalidated (GtkWidget *widget)
13983 if (widget->priv->path)
13985 gtk_widget_path_free (widget->priv->path);
13986 widget->priv->path = NULL;
13989 if (gtk_widget_get_realized (widget))
13990 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
13993 /* Compress all style updates so it
13994 * is only emitted once pre-realize.
13996 widget->priv->style_update_pending = TRUE;
13999 if (widget->priv->anchored)
14000 gtk_widget_queue_resize (widget);
14004 * gtk_widget_get_style_context:
14005 * @widget: a #GtkWidget
14007 * Returns the style context associated to @widget.
14009 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
14010 * must not be freed.
14013 gtk_widget_get_style_context (GtkWidget *widget)
14015 GtkWidgetPrivate *priv;
14017 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14019 priv = widget->priv;
14021 if (G_UNLIKELY (priv->context == NULL))
14025 priv->context = gtk_style_context_new ();
14027 gtk_style_context_set_direction (priv->context, gtk_widget_get_direction (widget));
14029 screen = gtk_widget_get_screen (widget);
14031 gtk_style_context_set_screen (priv->context, screen);
14034 gtk_style_context_set_parent (priv->context,
14035 gtk_widget_get_style_context (priv->parent));
14037 _gtk_style_context_set_widget (priv->context, widget);
14040 return widget->priv->context;
14044 _gtk_widget_invalidate_style_context (GtkWidget *widget,
14045 GtkCssChange change)
14047 GtkWidgetPrivate *priv;
14049 priv = widget->priv;
14051 if (priv->context == NULL)
14054 _gtk_style_context_queue_invalidate (priv->context, change);
14058 * gtk_widget_get_modifier_mask:
14059 * @widget: a #GtkWidget
14060 * @intent: the use case for the modifier mask
14062 * Returns the modifier mask the @widget's windowing system backend
14063 * uses for a particular purpose.
14065 * See gdk_keymap_get_modifier_mask().
14067 * Returns: the modifier mask used for @intent.
14072 gtk_widget_get_modifier_mask (GtkWidget *widget,
14073 GdkModifierIntent intent)
14075 GdkDisplay *display;
14077 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14079 display = gtk_widget_get_display (widget);
14081 return gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
14086 _gtk_widget_get_style (GtkWidget *widget)
14088 return widget->priv->style;
14092 _gtk_widget_set_style (GtkWidget *widget,
14095 widget->priv->style = style;
14099 _gtk_widget_update_parent_muxer (GtkWidget *widget)
14102 GActionMuxer *parent_muxer;
14104 if (widget->priv->muxer == NULL)
14107 if (GTK_IS_MENU (widget))
14108 parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
14110 parent = gtk_widget_get_parent (widget);
14112 parent_muxer = parent ? _gtk_widget_get_action_muxer (parent) : NULL;
14114 g_action_muxer_set_parent (widget->priv->muxer, parent_muxer);
14118 _gtk_widget_get_action_muxer (GtkWidget *widget)
14120 if (widget->priv->muxer == NULL)
14122 widget->priv->muxer = g_action_muxer_new ();
14123 _gtk_widget_update_parent_muxer (widget);
14126 return widget->priv->muxer;
14130 * gtk_widget_insert_action_group:
14131 * @widget: a #GtkWidget
14132 * @name: the prefix for actions in @group
14133 * @group: a #GActionGroup
14135 * Inserts @group into @widget. Children of @widget that implement
14136 * #GtkActionable can then be associated with actions in @group by
14137 * setting their 'action-name' to
14138 * @prefix.<replaceable>action-name</replaceable>.
14143 gtk_widget_insert_action_group (GtkWidget *widget,
14145 GActionGroup *group)
14147 GActionMuxer *muxer;
14149 g_return_if_fail (GTK_IS_WIDGET (widget));
14150 g_return_if_fail (name != NULL);
14152 muxer = _gtk_widget_get_action_muxer (widget);
14155 g_action_muxer_insert (muxer, name, group);
14157 g_action_muxer_remove (muxer, name);