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 /* The widget's window or its parent window if it does
394 * not have a window. (Which will be indicated by the
395 * GTK_NO_WINDOW flag being set).
399 /* The widget's parent */
402 #ifdef G_ENABLE_DEBUG
403 /* Number of gtk_widget_push_verify_invariants () */
404 guint verifying_invariants_count;
405 #endif /* G_ENABLE_DEBUG */
408 struct _GtkWidgetClassPrivate
410 GType accessible_type;
411 AtkRole accessible_role;
440 BUTTON_RELEASE_EVENT,
454 PROPERTY_NOTIFY_EVENT,
455 SELECTION_CLEAR_EVENT,
456 SELECTION_REQUEST_EVENT,
457 SELECTION_NOTIFY_EVENT,
462 VISIBILITY_NOTIFY_EVENT,
476 ACCEL_CLOSURES_CHANGED,
501 PROP_RECEIVES_DEFAULT,
502 PROP_COMPOSITE_CHILD,
510 PROP_DOUBLE_BUFFERED,
525 typedef struct _GtkStateData GtkStateData;
528 STATE_CHANGE_REPLACE,
535 guint flags : GTK_STATE_FLAGS_BITS;
539 /* --- prototypes --- */
540 static void gtk_widget_base_class_init (gpointer g_class);
541 static void gtk_widget_class_init (GtkWidgetClass *klass);
542 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
543 static void gtk_widget_init (GtkWidget *widget);
544 static void gtk_widget_set_property (GObject *object,
548 static void gtk_widget_get_property (GObject *object,
552 static void gtk_widget_constructed (GObject *object);
553 static void gtk_widget_dispose (GObject *object);
554 static void gtk_widget_real_destroy (GtkWidget *object);
555 static void gtk_widget_finalize (GObject *object);
556 static void gtk_widget_real_show (GtkWidget *widget);
557 static void gtk_widget_real_hide (GtkWidget *widget);
558 static void gtk_widget_real_map (GtkWidget *widget);
559 static void gtk_widget_real_unmap (GtkWidget *widget);
560 static void gtk_widget_real_realize (GtkWidget *widget);
561 static void gtk_widget_real_unrealize (GtkWidget *widget);
562 static void gtk_widget_real_size_allocate (GtkWidget *widget,
563 GtkAllocation *allocation);
564 static void gtk_widget_real_style_set (GtkWidget *widget,
565 GtkStyle *previous_style);
566 static void gtk_widget_real_direction_changed(GtkWidget *widget,
567 GtkTextDirection previous_direction);
569 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
570 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
573 gboolean keyboard_tip,
574 GtkTooltip *tooltip);
575 static void gtk_widget_real_style_updated (GtkWidget *widget);
576 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
577 GtkWidgetHelpType help_type);
579 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
581 GParamSpec **pspecs);
582 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
584 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
586 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
587 GdkEventFocus *event);
588 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
589 GdkEventFocus *event);
590 static gboolean gtk_widget_real_touch_event (GtkWidget *widget,
591 GdkEventTouch *event);
592 static gboolean gtk_widget_real_focus (GtkWidget *widget,
593 GtkDirectionType direction);
594 static void gtk_widget_real_move_focus (GtkWidget *widget,
595 GtkDirectionType direction);
596 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
597 GtkDirectionType direction);
598 #ifdef G_ENABLE_DEBUG
599 static void gtk_widget_verify_invariants (GtkWidget *widget);
600 static void gtk_widget_push_verify_invariants (GtkWidget *widget);
601 static void gtk_widget_pop_verify_invariants (GtkWidget *widget);
603 #define gtk_widget_verify_invariants(widget)
604 #define gtk_widget_push_verify_invariants(widget)
605 #define gtk_widget_pop_verify_invariants(widget)
607 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
608 static void gtk_widget_update_pango_context (GtkWidget *widget);
609 static void gtk_widget_propagate_state (GtkWidget *widget,
612 static gint gtk_widget_event_internal (GtkWidget *widget,
614 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
615 gboolean group_cycling);
616 static void gtk_widget_real_get_width (GtkWidget *widget,
619 static void gtk_widget_real_get_height (GtkWidget *widget,
622 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
624 gint *minimum_height,
625 gint *natural_height);
626 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
629 gint *natural_width);
630 static void gtk_widget_real_state_flags_changed (GtkWidget *widget,
631 GtkStateFlags old_state);
632 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
633 static GtkWidgetAuxInfo* gtk_widget_get_aux_info (GtkWidget *widget,
635 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
636 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
637 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
638 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
639 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
640 cairo_region_t *region);
641 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
642 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
643 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
646 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
647 gboolean has_tooltip,
649 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
650 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
652 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
653 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
655 const gchar *childname);
656 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
659 const GValue *value);
660 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
663 const gchar *tagname,
664 GMarkupParser *parser,
666 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
669 const gchar *tagname,
671 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
672 GtkBuilder *builder);
674 static GtkSizeRequestMode gtk_widget_real_get_request_mode (GtkWidget *widget);
675 static void gtk_widget_real_get_width (GtkWidget *widget,
678 static void gtk_widget_real_get_height (GtkWidget *widget,
682 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
685 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
686 GtkOrientation orientation,
689 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
690 GtkOrientation orientation,
694 gint *allocated_size);
696 static void gtk_widget_set_usize_internal (GtkWidget *widget,
699 GtkQueueResizeFlags flags);
701 static void gtk_widget_add_events_internal (GtkWidget *widget,
704 static void gtk_widget_set_device_enabled_internal (GtkWidget *widget,
708 static gboolean event_window_is_still_viewable (GdkEvent *event);
710 /* --- variables --- */
711 static gpointer gtk_widget_parent_class = NULL;
712 static guint widget_signals[LAST_SIGNAL] = { 0 };
713 static guint composite_child_stack = 0;
714 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
715 static GParamSpecPool *style_property_spec_pool = NULL;
717 static GQuark quark_property_parser = 0;
718 static GQuark quark_aux_info = 0;
719 static GQuark quark_accel_path = 0;
720 static GQuark quark_accel_closures = 0;
721 static GQuark quark_event_mask = 0;
722 static GQuark quark_device_event_mask = 0;
723 static GQuark quark_parent_window = 0;
724 static GQuark quark_pointer_window = 0;
725 static GQuark quark_shape_info = 0;
726 static GQuark quark_input_shape_info = 0;
727 static GQuark quark_pango_context = 0;
728 static GQuark quark_accessible_object = 0;
729 static GQuark quark_mnemonic_labels = 0;
730 static GQuark quark_tooltip_markup = 0;
731 static GQuark quark_has_tooltip = 0;
732 static GQuark quark_tooltip_window = 0;
733 static GQuark quark_visual = 0;
734 static GQuark quark_modifier_style = 0;
735 static GQuark quark_enabled_devices = 0;
736 static GQuark quark_size_groups = 0;
737 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
738 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
740 /* --- functions --- */
742 gtk_widget_get_type (void)
744 static GType widget_type = 0;
746 if (G_UNLIKELY (widget_type == 0))
748 const GTypeInfo widget_info =
750 sizeof (GtkWidgetClass),
751 gtk_widget_base_class_init,
752 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
753 (GClassInitFunc) gtk_widget_class_init,
754 NULL, /* class_finalize */
755 NULL, /* class_init */
758 (GInstanceInitFunc) gtk_widget_init,
759 NULL, /* value_table */
762 const GInterfaceInfo accessibility_info =
764 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
765 (GInterfaceFinalizeFunc) NULL,
766 NULL /* interface data */
769 const GInterfaceInfo buildable_info =
771 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
772 (GInterfaceFinalizeFunc) NULL,
773 NULL /* interface data */
776 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
777 &widget_info, G_TYPE_FLAG_ABSTRACT);
779 g_type_add_class_private (widget_type, sizeof (GtkWidgetClassPrivate));
781 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
782 &accessibility_info) ;
783 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
791 gtk_widget_base_class_init (gpointer g_class)
793 GtkWidgetClass *klass = g_class;
795 klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
799 child_property_notify_dispatcher (GObject *object,
803 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
806 /* We guard against the draw signal callbacks modifying the state of the
807 * cairo context by surounding it with save/restore.
808 * Maybe we should also cairo_new_path() just to be sure?
811 gtk_widget_draw_marshaller (GClosure *closure,
812 GValue *return_value,
813 guint n_param_values,
814 const GValue *param_values,
815 gpointer invocation_hint,
816 gpointer marshal_data)
818 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
822 _gtk_marshal_BOOLEAN__BOXED (closure,
833 gtk_widget_draw_marshallerv (GClosure *closure,
834 GValue *return_value,
837 gpointer marshal_data,
844 G_VA_COPY (args_copy, args);
845 cr = va_arg (args_copy, gpointer);
849 _gtk_marshal_BOOLEAN__BOXEDv (closure,
861 gtk_widget_class_init (GtkWidgetClass *klass)
863 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
864 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
865 GtkBindingSet *binding_set;
867 gtk_widget_parent_class = g_type_class_peek_parent (klass);
869 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
870 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
871 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
872 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
873 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
874 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
875 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
876 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
877 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
878 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
879 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
880 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
881 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
882 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
883 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
884 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
885 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
886 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
887 quark_enabled_devices = g_quark_from_static_string ("gtk-widget-enabled-devices");
888 quark_size_groups = g_quark_from_static_string ("gtk-widget-size-groups");
890 style_property_spec_pool = g_param_spec_pool_new (FALSE);
891 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
892 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
893 cpn_context.dispatcher = child_property_notify_dispatcher;
894 _gtk_widget_child_property_notify_context = &cpn_context;
896 gobject_class->constructed = gtk_widget_constructed;
897 gobject_class->dispose = gtk_widget_dispose;
898 gobject_class->finalize = gtk_widget_finalize;
899 gobject_class->set_property = gtk_widget_set_property;
900 gobject_class->get_property = gtk_widget_get_property;
902 klass->destroy = gtk_widget_real_destroy;
904 klass->activate_signal = 0;
905 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
906 klass->show = gtk_widget_real_show;
907 klass->show_all = gtk_widget_show;
908 klass->hide = gtk_widget_real_hide;
909 klass->map = gtk_widget_real_map;
910 klass->unmap = gtk_widget_real_unmap;
911 klass->realize = gtk_widget_real_realize;
912 klass->unrealize = gtk_widget_real_unrealize;
913 klass->size_allocate = gtk_widget_real_size_allocate;
914 klass->get_request_mode = gtk_widget_real_get_request_mode;
915 klass->get_preferred_width = gtk_widget_real_get_width;
916 klass->get_preferred_height = gtk_widget_real_get_height;
917 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
918 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
919 klass->state_changed = NULL;
920 klass->state_flags_changed = gtk_widget_real_state_flags_changed;
921 klass->parent_set = NULL;
922 klass->hierarchy_changed = NULL;
923 klass->style_set = gtk_widget_real_style_set;
924 klass->direction_changed = gtk_widget_real_direction_changed;
925 klass->grab_notify = NULL;
926 klass->child_notify = NULL;
928 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
929 klass->grab_focus = gtk_widget_real_grab_focus;
930 klass->focus = gtk_widget_real_focus;
931 klass->move_focus = gtk_widget_real_move_focus;
932 klass->keynav_failed = gtk_widget_real_keynav_failed;
934 klass->button_press_event = NULL;
935 klass->button_release_event = NULL;
936 klass->motion_notify_event = NULL;
937 klass->touch_event = gtk_widget_real_touch_event;
938 klass->delete_event = NULL;
939 klass->destroy_event = NULL;
940 klass->key_press_event = gtk_widget_real_key_press_event;
941 klass->key_release_event = gtk_widget_real_key_release_event;
942 klass->enter_notify_event = NULL;
943 klass->leave_notify_event = NULL;
944 klass->configure_event = NULL;
945 klass->focus_in_event = gtk_widget_real_focus_in_event;
946 klass->focus_out_event = gtk_widget_real_focus_out_event;
947 klass->map_event = NULL;
948 klass->unmap_event = NULL;
949 klass->window_state_event = NULL;
950 klass->property_notify_event = _gtk_selection_property_notify;
951 klass->selection_clear_event = _gtk_selection_clear;
952 klass->selection_request_event = _gtk_selection_request;
953 klass->selection_notify_event = _gtk_selection_notify;
954 klass->selection_received = NULL;
955 klass->proximity_in_event = NULL;
956 klass->proximity_out_event = NULL;
957 klass->drag_begin = NULL;
958 klass->drag_end = NULL;
959 klass->drag_data_delete = NULL;
960 klass->drag_leave = NULL;
961 klass->drag_motion = NULL;
962 klass->drag_drop = NULL;
963 klass->drag_data_received = NULL;
964 klass->screen_changed = NULL;
965 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
966 klass->grab_broken_event = NULL;
967 klass->query_tooltip = gtk_widget_real_query_tooltip;
968 klass->style_updated = gtk_widget_real_style_updated;
970 klass->show_help = gtk_widget_real_show_help;
972 /* Accessibility support */
973 klass->priv->accessible_type = GTK_TYPE_ACCESSIBLE;
974 klass->priv->accessible_role = ATK_ROLE_INVALID;
975 klass->get_accessible = gtk_widget_real_get_accessible;
977 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
978 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
980 g_object_class_install_property (gobject_class,
982 g_param_spec_string ("name",
984 P_("The name of the widget"),
986 GTK_PARAM_READWRITE));
987 g_object_class_install_property (gobject_class,
989 g_param_spec_object ("parent",
991 P_("The parent widget of this widget. Must be a Container widget"),
993 GTK_PARAM_READWRITE));
995 g_object_class_install_property (gobject_class,
997 g_param_spec_int ("width-request",
999 P_("Override for width request of the widget, or -1 if natural request should be used"),
1003 GTK_PARAM_READWRITE));
1004 g_object_class_install_property (gobject_class,
1005 PROP_HEIGHT_REQUEST,
1006 g_param_spec_int ("height-request",
1007 P_("Height request"),
1008 P_("Override for height request of the widget, or -1 if natural request should be used"),
1012 GTK_PARAM_READWRITE));
1013 g_object_class_install_property (gobject_class,
1015 g_param_spec_boolean ("visible",
1017 P_("Whether the widget is visible"),
1019 GTK_PARAM_READWRITE));
1020 g_object_class_install_property (gobject_class,
1022 g_param_spec_boolean ("sensitive",
1024 P_("Whether the widget responds to input"),
1026 GTK_PARAM_READWRITE));
1027 g_object_class_install_property (gobject_class,
1029 g_param_spec_boolean ("app-paintable",
1030 P_("Application paintable"),
1031 P_("Whether the application will paint directly on the widget"),
1033 GTK_PARAM_READWRITE));
1034 g_object_class_install_property (gobject_class,
1036 g_param_spec_boolean ("can-focus",
1038 P_("Whether the widget can accept the input focus"),
1040 GTK_PARAM_READWRITE));
1041 g_object_class_install_property (gobject_class,
1043 g_param_spec_boolean ("has-focus",
1045 P_("Whether the widget has the input focus"),
1047 GTK_PARAM_READWRITE));
1048 g_object_class_install_property (gobject_class,
1050 g_param_spec_boolean ("is-focus",
1052 P_("Whether the widget is the focus widget within the toplevel"),
1054 GTK_PARAM_READWRITE));
1055 g_object_class_install_property (gobject_class,
1057 g_param_spec_boolean ("can-default",
1059 P_("Whether the widget can be the default widget"),
1061 GTK_PARAM_READWRITE));
1062 g_object_class_install_property (gobject_class,
1064 g_param_spec_boolean ("has-default",
1066 P_("Whether the widget is the default widget"),
1068 GTK_PARAM_READWRITE));
1069 g_object_class_install_property (gobject_class,
1070 PROP_RECEIVES_DEFAULT,
1071 g_param_spec_boolean ("receives-default",
1072 P_("Receives default"),
1073 P_("If TRUE, the widget will receive the default action when it is focused"),
1075 GTK_PARAM_READWRITE));
1076 g_object_class_install_property (gobject_class,
1077 PROP_COMPOSITE_CHILD,
1078 g_param_spec_boolean ("composite-child",
1079 P_("Composite child"),
1080 P_("Whether the widget is part of a composite widget"),
1082 GTK_PARAM_READABLE));
1083 g_object_class_install_property (gobject_class,
1085 g_param_spec_object ("style",
1087 P_("The style of the widget, which contains information about how it will look (colors etc)"),
1089 GTK_PARAM_READWRITE));
1090 g_object_class_install_property (gobject_class,
1092 g_param_spec_flags ("events",
1094 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1095 GDK_TYPE_EVENT_MASK,
1097 GTK_PARAM_READWRITE));
1098 g_object_class_install_property (gobject_class,
1100 g_param_spec_boolean ("no-show-all",
1102 P_("Whether gtk_widget_show_all() should not affect this widget"),
1104 GTK_PARAM_READWRITE));
1107 * GtkWidget:has-tooltip:
1109 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1110 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1111 * the widget will be queried using #GtkWidget::query-tooltip to determine
1112 * whether it will provide a tooltip or not.
1114 * Note that setting this property to %TRUE for the first time will change
1115 * the event masks of the GdkWindows of this widget to include leave-notify
1116 * and motion-notify events. This cannot and will not be undone when the
1117 * property is set to %FALSE again.
1121 g_object_class_install_property (gobject_class,
1123 g_param_spec_boolean ("has-tooltip",
1125 P_("Whether this widget has a tooltip"),
1127 GTK_PARAM_READWRITE));
1129 * GtkWidget:tooltip-text:
1131 * Sets the text of tooltip to be the given string.
1133 * Also see gtk_tooltip_set_text().
1135 * This is a convenience property which will take care of getting the
1136 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1137 * will automatically be set to %TRUE and there will be taken care of
1138 * #GtkWidget::query-tooltip in the default signal handler.
1142 g_object_class_install_property (gobject_class,
1144 g_param_spec_string ("tooltip-text",
1146 P_("The contents of the tooltip for this widget"),
1148 GTK_PARAM_READWRITE));
1150 * GtkWidget:tooltip-markup:
1152 * Sets the text of tooltip to be the given string, which is marked up
1153 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1154 * Also see gtk_tooltip_set_markup().
1156 * This is a convenience property which will take care of getting the
1157 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1158 * will automatically be set to %TRUE and there will be taken care of
1159 * #GtkWidget::query-tooltip in the default signal handler.
1163 g_object_class_install_property (gobject_class,
1164 PROP_TOOLTIP_MARKUP,
1165 g_param_spec_string ("tooltip-markup",
1166 P_("Tooltip markup"),
1167 P_("The contents of the tooltip for this widget"),
1169 GTK_PARAM_READWRITE));
1174 * The widget's window if it is realized, %NULL otherwise.
1178 g_object_class_install_property (gobject_class,
1180 g_param_spec_object ("window",
1182 P_("The widget's window if it is realized"),
1184 GTK_PARAM_READABLE));
1187 * GtkWidget:double-buffered:
1189 * Whether the widget is double buffered.
1193 g_object_class_install_property (gobject_class,
1194 PROP_DOUBLE_BUFFERED,
1195 g_param_spec_boolean ("double-buffered",
1196 P_("Double Buffered"),
1197 P_("Whether the widget is double buffered"),
1199 GTK_PARAM_READWRITE));
1204 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1208 g_object_class_install_property (gobject_class,
1210 g_param_spec_enum ("halign",
1211 P_("Horizontal Alignment"),
1212 P_("How to position in extra horizontal space"),
1215 GTK_PARAM_READWRITE));
1220 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1224 g_object_class_install_property (gobject_class,
1226 g_param_spec_enum ("valign",
1227 P_("Vertical Alignment"),
1228 P_("How to position in extra vertical space"),
1231 GTK_PARAM_READWRITE));
1234 * GtkWidget:margin-left:
1236 * Margin on left side of widget.
1238 * This property adds margin outside of the widget's normal size
1239 * request, the margin will be added in addition to the size from
1240 * gtk_widget_set_size_request() for example.
1244 g_object_class_install_property (gobject_class,
1246 g_param_spec_int ("margin-left",
1247 P_("Margin on Left"),
1248 P_("Pixels of extra space on the left side"),
1252 GTK_PARAM_READWRITE));
1255 * GtkWidget:margin-right:
1257 * Margin on right side of widget.
1259 * This property adds margin outside of the widget's normal size
1260 * request, the margin will be added in addition to the size from
1261 * gtk_widget_set_size_request() for example.
1265 g_object_class_install_property (gobject_class,
1267 g_param_spec_int ("margin-right",
1268 P_("Margin on Right"),
1269 P_("Pixels of extra space on the right side"),
1273 GTK_PARAM_READWRITE));
1276 * GtkWidget:margin-top:
1278 * Margin on top side of widget.
1280 * This property adds margin outside of the widget's normal size
1281 * request, the margin will be added in addition to the size from
1282 * gtk_widget_set_size_request() for example.
1286 g_object_class_install_property (gobject_class,
1288 g_param_spec_int ("margin-top",
1289 P_("Margin on Top"),
1290 P_("Pixels of extra space on the top side"),
1294 GTK_PARAM_READWRITE));
1297 * GtkWidget:margin-bottom:
1299 * Margin on bottom side of widget.
1301 * This property adds margin outside of the widget's normal size
1302 * request, the margin will be added in addition to the size from
1303 * gtk_widget_set_size_request() for example.
1307 g_object_class_install_property (gobject_class,
1309 g_param_spec_int ("margin-bottom",
1310 P_("Margin on Bottom"),
1311 P_("Pixels of extra space on the bottom side"),
1315 GTK_PARAM_READWRITE));
1320 * Sets all four sides' margin at once. If read, returns max
1321 * margin on any side.
1325 g_object_class_install_property (gobject_class,
1327 g_param_spec_int ("margin",
1329 P_("Pixels of extra space on all four sides"),
1333 GTK_PARAM_READWRITE));
1336 * GtkWidget::destroy:
1337 * @object: the object which received the signal
1339 * Signals that all holders of a reference to the widget should release
1340 * the reference that they hold. May result in finalization of the widget
1341 * if all references are released.
1343 widget_signals[DESTROY] =
1344 g_signal_new (I_("destroy"),
1345 G_TYPE_FROM_CLASS (gobject_class),
1346 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1347 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1349 _gtk_marshal_VOID__VOID,
1353 * GtkWidget:hexpand:
1355 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1359 g_object_class_install_property (gobject_class,
1361 g_param_spec_boolean ("hexpand",
1362 P_("Horizontal Expand"),
1363 P_("Whether widget wants more horizontal space"),
1365 GTK_PARAM_READWRITE));
1368 * GtkWidget:hexpand-set:
1370 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1374 g_object_class_install_property (gobject_class,
1376 g_param_spec_boolean ("hexpand-set",
1377 P_("Horizontal Expand Set"),
1378 P_("Whether to use the hexpand property"),
1380 GTK_PARAM_READWRITE));
1383 * GtkWidget:vexpand:
1385 * Whether to expand vertically. See gtk_widget_set_vexpand().
1389 g_object_class_install_property (gobject_class,
1391 g_param_spec_boolean ("vexpand",
1392 P_("Vertical Expand"),
1393 P_("Whether widget wants more vertical space"),
1395 GTK_PARAM_READWRITE));
1398 * GtkWidget:vexpand-set:
1400 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1404 g_object_class_install_property (gobject_class,
1406 g_param_spec_boolean ("vexpand-set",
1407 P_("Vertical Expand Set"),
1408 P_("Whether to use the vexpand property"),
1410 GTK_PARAM_READWRITE));
1415 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1419 g_object_class_install_property (gobject_class,
1421 g_param_spec_boolean ("expand",
1423 P_("Whether widget wants to expand in both directions"),
1425 GTK_PARAM_READWRITE));
1429 * @widget: the object which received the signal.
1431 widget_signals[SHOW] =
1432 g_signal_new (I_("show"),
1433 G_TYPE_FROM_CLASS (gobject_class),
1435 G_STRUCT_OFFSET (GtkWidgetClass, show),
1437 _gtk_marshal_VOID__VOID,
1442 * @widget: the object which received the signal.
1444 widget_signals[HIDE] =
1445 g_signal_new (I_("hide"),
1446 G_TYPE_FROM_CLASS (gobject_class),
1448 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1450 _gtk_marshal_VOID__VOID,
1455 * @widget: the object which received the signal.
1457 widget_signals[MAP] =
1458 g_signal_new (I_("map"),
1459 G_TYPE_FROM_CLASS (gobject_class),
1461 G_STRUCT_OFFSET (GtkWidgetClass, map),
1463 _gtk_marshal_VOID__VOID,
1468 * @widget: the object which received the signal.
1470 widget_signals[UNMAP] =
1471 g_signal_new (I_("unmap"),
1472 G_TYPE_FROM_CLASS (gobject_class),
1474 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1476 _gtk_marshal_VOID__VOID,
1480 * GtkWidget::realize:
1481 * @widget: the object which received the signal.
1483 widget_signals[REALIZE] =
1484 g_signal_new (I_("realize"),
1485 G_TYPE_FROM_CLASS (gobject_class),
1487 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1489 _gtk_marshal_VOID__VOID,
1493 * GtkWidget::unrealize:
1494 * @widget: the object which received the signal.
1496 widget_signals[UNREALIZE] =
1497 g_signal_new (I_("unrealize"),
1498 G_TYPE_FROM_CLASS (gobject_class),
1500 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1502 _gtk_marshal_VOID__VOID,
1506 * GtkWidget::size-allocate:
1507 * @widget: the object which received the signal.
1510 widget_signals[SIZE_ALLOCATE] =
1511 g_signal_new (I_("size-allocate"),
1512 G_TYPE_FROM_CLASS (gobject_class),
1514 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1516 _gtk_marshal_VOID__BOXED,
1518 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1521 * GtkWidget::state-changed:
1522 * @widget: the object which received the signal.
1523 * @state: the previous state
1525 * The ::state-changed signal is emitted when the widget state changes.
1526 * See gtk_widget_get_state().
1528 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1530 widget_signals[STATE_CHANGED] =
1531 g_signal_new (I_("state-changed"),
1532 G_TYPE_FROM_CLASS (gobject_class),
1534 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1536 _gtk_marshal_VOID__ENUM,
1538 GTK_TYPE_STATE_TYPE);
1541 * GtkWidget::state-flags-changed:
1542 * @widget: the object which received the signal.
1543 * @flags: The previous state flags.
1545 * The ::state-flags-changed signal is emitted when the widget state
1546 * changes, see gtk_widget_get_state_flags().
1550 widget_signals[STATE_FLAGS_CHANGED] =
1551 g_signal_new (I_("state-flags-changed"),
1552 G_TYPE_FROM_CLASS (gobject_class),
1554 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1556 _gtk_marshal_VOID__FLAGS,
1558 GTK_TYPE_STATE_FLAGS);
1561 * GtkWidget::parent-set:
1562 * @widget: the object on which the signal is emitted
1563 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1564 * just got its initial parent.
1566 * The ::parent-set signal is emitted when a new parent
1567 * has been set on a widget.
1569 widget_signals[PARENT_SET] =
1570 g_signal_new (I_("parent-set"),
1571 G_TYPE_FROM_CLASS (gobject_class),
1573 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1575 _gtk_marshal_VOID__OBJECT,
1580 * GtkWidget::hierarchy-changed:
1581 * @widget: the object on which the signal is emitted
1582 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1583 * if the widget was previously unanchored
1585 * The ::hierarchy-changed signal is emitted when the
1586 * anchored state of a widget changes. A widget is
1587 * <firstterm>anchored</firstterm> when its toplevel
1588 * ancestor is a #GtkWindow. This signal is emitted when
1589 * a widget changes from un-anchored to anchored or vice-versa.
1591 widget_signals[HIERARCHY_CHANGED] =
1592 g_signal_new (I_("hierarchy-changed"),
1593 G_TYPE_FROM_CLASS (gobject_class),
1595 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1597 _gtk_marshal_VOID__OBJECT,
1602 * GtkWidget::style-set:
1603 * @widget: the object on which the signal is emitted
1604 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1605 * just got its initial style
1607 * The ::style-set signal is emitted when a new style has been set
1608 * on a widget. Note that style-modifying functions like
1609 * gtk_widget_modify_base() also cause this signal to be emitted.
1611 * Note that this signal is emitted for changes to the deprecated
1612 * #GtkStyle. To track changes to the #GtkStyleContext associated
1613 * with a widget, use the #GtkWidget::style-updated signal.
1615 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1617 widget_signals[STYLE_SET] =
1618 g_signal_new (I_("style-set"),
1619 G_TYPE_FROM_CLASS (gobject_class),
1621 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1623 _gtk_marshal_VOID__OBJECT,
1628 * GtkWidget::style-updated:
1629 * @widget: the object on which the signal is emitted
1631 * The ::style-updated signal is emitted when the #GtkStyleContext
1632 * of a widget is changed. Note that style-modifying functions like
1633 * gtk_widget_override_color() also cause this signal to be emitted.
1637 widget_signals[STYLE_UPDATED] =
1638 g_signal_new (I_("style-updated"),
1639 G_TYPE_FROM_CLASS (gobject_class),
1641 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1643 g_cclosure_marshal_VOID__VOID,
1647 * GtkWidget::direction-changed:
1648 * @widget: the object on which the signal is emitted
1649 * @previous_direction: the previous text direction of @widget
1651 * The ::direction-changed signal is emitted when the text direction
1652 * of a widget changes.
1654 widget_signals[DIRECTION_CHANGED] =
1655 g_signal_new (I_("direction-changed"),
1656 G_TYPE_FROM_CLASS (gobject_class),
1658 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1660 _gtk_marshal_VOID__ENUM,
1662 GTK_TYPE_TEXT_DIRECTION);
1665 * GtkWidget::grab-notify:
1666 * @widget: the object which received the signal
1667 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1668 * if it becomes unshadowed
1670 * The ::grab-notify signal is emitted when a widget becomes
1671 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1672 * another widget, or when it becomes unshadowed due to a grab
1675 * A widget is shadowed by a gtk_grab_add() when the topmost
1676 * grab widget in the grab stack of its window group is not
1679 widget_signals[GRAB_NOTIFY] =
1680 g_signal_new (I_("grab-notify"),
1681 G_TYPE_FROM_CLASS (gobject_class),
1683 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1685 _gtk_marshal_VOID__BOOLEAN,
1690 * GtkWidget::child-notify:
1691 * @widget: the object which received the signal
1692 * @child_property: the #GParamSpec of the changed child property
1694 * The ::child-notify signal is emitted for each
1695 * <link linkend="child-properties">child property</link> that has
1696 * changed on an object. The signal's detail holds the property name.
1698 widget_signals[CHILD_NOTIFY] =
1699 g_signal_new (I_("child-notify"),
1700 G_TYPE_FROM_CLASS (gobject_class),
1701 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1702 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1704 g_cclosure_marshal_VOID__PARAM,
1710 * @widget: the object which received the signal
1711 * @cr: the cairo context to draw to
1713 * This signal is emitted when a widget is supposed to render itself.
1714 * The @widget's top left corner must be painted at the origin of
1715 * the passed in context and be sized to the values returned by
1716 * gtk_widget_get_allocated_width() and
1717 * gtk_widget_get_allocated_height().
1719 * Signal handlers connected to this signal can modify the cairo
1720 * context passed as @cr in any way they like and don't need to
1721 * restore it. The signal emission takes care of calling cairo_save()
1722 * before and cairo_restore() after invoking the handler.
1726 widget_signals[DRAW] =
1727 g_signal_new (I_("draw"),
1728 G_TYPE_FROM_CLASS (gobject_class),
1730 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1731 _gtk_boolean_handled_accumulator, NULL,
1732 gtk_widget_draw_marshaller,
1734 CAIRO_GOBJECT_TYPE_CONTEXT);
1735 g_signal_set_va_marshaller (widget_signals[DRAW], G_TYPE_FROM_CLASS (klass),
1736 gtk_widget_draw_marshallerv);
1739 * GtkWidget::mnemonic-activate:
1740 * @widget: the object which received the signal.
1743 widget_signals[MNEMONIC_ACTIVATE] =
1744 g_signal_new (I_("mnemonic-activate"),
1745 G_TYPE_FROM_CLASS (gobject_class),
1747 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1748 _gtk_boolean_handled_accumulator, NULL,
1749 _gtk_marshal_BOOLEAN__BOOLEAN,
1754 * GtkWidget::grab-focus:
1755 * @widget: the object which received the signal.
1757 widget_signals[GRAB_FOCUS] =
1758 g_signal_new (I_("grab-focus"),
1759 G_TYPE_FROM_CLASS (gobject_class),
1760 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1761 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1763 _gtk_marshal_VOID__VOID,
1768 * @widget: the object which received the signal.
1771 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1773 widget_signals[FOCUS] =
1774 g_signal_new (I_("focus"),
1775 G_TYPE_FROM_CLASS (klass),
1777 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1778 _gtk_boolean_handled_accumulator, NULL,
1779 _gtk_marshal_BOOLEAN__ENUM,
1781 GTK_TYPE_DIRECTION_TYPE);
1784 * GtkWidget::move-focus:
1785 * @widget: the object which received the signal.
1788 widget_signals[MOVE_FOCUS] =
1789 g_signal_new (I_("move-focus"),
1790 G_TYPE_FROM_CLASS (klass),
1791 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1792 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1794 _gtk_marshal_VOID__ENUM,
1797 GTK_TYPE_DIRECTION_TYPE);
1800 * GtkWidget::keynav-failed:
1801 * @widget: the object which received the signal
1802 * @direction: the direction of movement
1804 * Gets emitted if keyboard navigation fails.
1805 * See gtk_widget_keynav_failed() for details.
1807 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1808 * if the emitting widget should try to handle the keyboard
1809 * navigation attempt in its parent container(s).
1813 widget_signals[KEYNAV_FAILED] =
1814 g_signal_new (I_("keynav-failed"),
1815 G_TYPE_FROM_CLASS (klass),
1817 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1818 _gtk_boolean_handled_accumulator, NULL,
1819 _gtk_marshal_BOOLEAN__ENUM,
1821 GTK_TYPE_DIRECTION_TYPE);
1825 * @widget: the object which received the signal.
1826 * @event: the #GdkEvent which triggered this signal
1828 * The GTK+ main loop will emit three signals for each GDK event delivered
1829 * to a widget: one generic ::event signal, another, more specific,
1830 * signal that matches the type of event delivered (e.g.
1831 * #GtkWidget::key-press-event) and finally a generic
1832 * #GtkWidget::event-after signal.
1834 * Returns: %TRUE to stop other handlers from being invoked for the event
1835 * and to cancel the emission of the second specific ::event signal.
1836 * %FALSE to propagate the event further and to allow the emission of
1837 * the second signal. The ::event-after signal is emitted regardless of
1840 widget_signals[EVENT] =
1841 g_signal_new (I_("event"),
1842 G_TYPE_FROM_CLASS (klass),
1844 G_STRUCT_OFFSET (GtkWidgetClass, event),
1845 _gtk_boolean_handled_accumulator, NULL,
1846 _gtk_marshal_BOOLEAN__BOXED,
1848 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1849 g_signal_set_va_marshaller (widget_signals[EVENT], G_TYPE_FROM_CLASS (klass),
1850 _gtk_marshal_BOOLEAN__BOXEDv);
1853 * GtkWidget::event-after:
1854 * @widget: the object which received the signal.
1855 * @event: the #GdkEvent which triggered this signal
1857 * After the emission of the #GtkWidget::event signal and (optionally)
1858 * the second more specific signal, ::event-after will be emitted
1859 * regardless of the previous two signals handlers return values.
1862 widget_signals[EVENT_AFTER] =
1863 g_signal_new (I_("event-after"),
1864 G_TYPE_FROM_CLASS (klass),
1868 _gtk_marshal_VOID__BOXED,
1870 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1871 g_signal_set_va_marshaller (widget_signals[EVENT_AFTER], G_TYPE_FROM_CLASS (klass),
1872 _gtk_marshal_BOOLEAN__BOXEDv);
1875 * GtkWidget::button-press-event:
1876 * @widget: the object which received the signal.
1877 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1880 * The ::button-press-event signal will be emitted when a button
1881 * (typically from a mouse) is pressed.
1883 * To receive this signal, the #GdkWindow associated to the
1884 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1886 * This signal will be sent to the grab widget if there is one.
1888 * Returns: %TRUE to stop other handlers from being invoked for the event.
1889 * %FALSE to propagate the event further.
1891 widget_signals[BUTTON_PRESS_EVENT] =
1892 g_signal_new (I_("button-press-event"),
1893 G_TYPE_FROM_CLASS (klass),
1895 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1896 _gtk_boolean_handled_accumulator, NULL,
1897 _gtk_marshal_BOOLEAN__BOXED,
1899 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1900 g_signal_set_va_marshaller (widget_signals[BUTTON_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
1901 _gtk_marshal_BOOLEAN__BOXEDv);
1904 * GtkWidget::button-release-event:
1905 * @widget: the object which received the signal.
1906 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1909 * The ::button-release-event signal will be emitted when a button
1910 * (typically from a mouse) is released.
1912 * To receive this signal, the #GdkWindow associated to the
1913 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1915 * This signal will be sent to the grab widget if there is one.
1917 * Returns: %TRUE to stop other handlers from being invoked for the event.
1918 * %FALSE to propagate the event further.
1920 widget_signals[BUTTON_RELEASE_EVENT] =
1921 g_signal_new (I_("button-release-event"),
1922 G_TYPE_FROM_CLASS (klass),
1924 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1925 _gtk_boolean_handled_accumulator, NULL,
1926 _gtk_marshal_BOOLEAN__BOXED,
1928 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1929 g_signal_set_va_marshaller (widget_signals[BUTTON_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
1930 _gtk_marshal_BOOLEAN__BOXEDv);
1932 widget_signals[TOUCH_EVENT] =
1933 g_signal_new (I_("touch-event"),
1934 G_TYPE_FROM_CLASS (klass),
1936 G_STRUCT_OFFSET (GtkWidgetClass, touch_event),
1937 _gtk_boolean_handled_accumulator, NULL,
1938 _gtk_marshal_BOOLEAN__BOXED,
1940 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1941 g_signal_set_va_marshaller (widget_signals[TOUCH_EVENT], G_TYPE_FROM_CLASS (klass),
1942 _gtk_marshal_BOOLEAN__BOXEDv);
1945 * GtkWidget::scroll-event:
1946 * @widget: the object which received the signal.
1947 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1950 * The ::scroll-event signal is emitted when a button in the 4 to 7
1951 * range is pressed. Wheel mice are usually configured to generate
1952 * button press events for buttons 4 and 5 when the wheel is turned.
1954 * To receive this signal, the #GdkWindow associated to the widget needs
1955 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1957 * This signal will be sent to the grab widget if there is one.
1959 * Returns: %TRUE to stop other handlers from being invoked for the event.
1960 * %FALSE to propagate the event further.
1962 widget_signals[SCROLL_EVENT] =
1963 g_signal_new (I_("scroll-event"),
1964 G_TYPE_FROM_CLASS (klass),
1966 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1967 _gtk_boolean_handled_accumulator, NULL,
1968 _gtk_marshal_BOOLEAN__BOXED,
1970 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1971 g_signal_set_va_marshaller (widget_signals[SCROLL_EVENT], G_TYPE_FROM_CLASS (klass),
1972 _gtk_marshal_BOOLEAN__BOXEDv);
1975 * GtkWidget::motion-notify-event:
1976 * @widget: the object which received the signal.
1977 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1980 * The ::motion-notify-event signal is emitted when the pointer moves
1981 * over the widget's #GdkWindow.
1983 * To receive this signal, the #GdkWindow associated to the widget
1984 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1986 * This signal will be sent to the grab widget if there is one.
1988 * Returns: %TRUE to stop other handlers from being invoked for the event.
1989 * %FALSE to propagate the event further.
1991 widget_signals[MOTION_NOTIFY_EVENT] =
1992 g_signal_new (I_("motion-notify-event"),
1993 G_TYPE_FROM_CLASS (klass),
1995 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1996 _gtk_boolean_handled_accumulator, NULL,
1997 _gtk_marshal_BOOLEAN__BOXED,
1999 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2000 g_signal_set_va_marshaller (widget_signals[MOTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2001 _gtk_marshal_BOOLEAN__BOXEDv);
2004 * GtkWidget::composited-changed:
2005 * @widget: the object on which the signal is emitted
2007 * The ::composited-changed signal is emitted when the composited
2008 * status of @widget<!-- -->s screen changes.
2009 * See gdk_screen_is_composited().
2011 widget_signals[COMPOSITED_CHANGED] =
2012 g_signal_new (I_("composited-changed"),
2013 G_TYPE_FROM_CLASS (klass),
2014 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2015 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
2017 _gtk_marshal_VOID__VOID,
2021 * GtkWidget::delete-event:
2022 * @widget: the object which received the signal
2023 * @event: the event which triggered this signal
2025 * The ::delete-event signal is emitted if a user requests that
2026 * a toplevel window is closed. The default handler for this signal
2027 * destroys the window. Connecting gtk_widget_hide_on_delete() to
2028 * this signal will cause the window to be hidden instead, so that
2029 * it can later be shown again without reconstructing it.
2031 * Returns: %TRUE to stop other handlers from being invoked for the event.
2032 * %FALSE to propagate the event further.
2034 widget_signals[DELETE_EVENT] =
2035 g_signal_new (I_("delete-event"),
2036 G_TYPE_FROM_CLASS (klass),
2038 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
2039 _gtk_boolean_handled_accumulator, NULL,
2040 _gtk_marshal_BOOLEAN__BOXED,
2042 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2043 g_signal_set_va_marshaller (widget_signals[DELETE_EVENT], G_TYPE_FROM_CLASS (klass),
2044 _gtk_marshal_BOOLEAN__BOXEDv);
2047 * GtkWidget::destroy-event:
2048 * @widget: the object which received the signal.
2049 * @event: the event which triggered this signal
2051 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
2052 * You rarely get this signal, because most widgets disconnect themselves
2053 * from their window before they destroy it, so no widget owns the
2054 * window at destroy time.
2056 * To receive this signal, the #GdkWindow associated to the widget needs
2057 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2058 * automatically for all new windows.
2060 * Returns: %TRUE to stop other handlers from being invoked for the event.
2061 * %FALSE to propagate the event further.
2063 widget_signals[DESTROY_EVENT] =
2064 g_signal_new (I_("destroy-event"),
2065 G_TYPE_FROM_CLASS (klass),
2067 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
2068 _gtk_boolean_handled_accumulator, NULL,
2069 _gtk_marshal_BOOLEAN__BOXED,
2071 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2072 g_signal_set_va_marshaller (widget_signals[DESTROY_EVENT], G_TYPE_FROM_CLASS (klass),
2073 _gtk_marshal_BOOLEAN__BOXEDv);
2076 * GtkWidget::key-press-event:
2077 * @widget: the object which received the signal
2078 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2080 * The ::key-press-event signal is emitted when a key is pressed. The signal
2081 * emission will reoccur at the key-repeat rate when the key is kept pressed.
2083 * To receive this signal, the #GdkWindow associated to the widget needs
2084 * to enable the #GDK_KEY_PRESS_MASK mask.
2086 * This signal will be sent to the grab widget if there is one.
2088 * Returns: %TRUE to stop other handlers from being invoked for the event.
2089 * %FALSE to propagate the event further.
2091 widget_signals[KEY_PRESS_EVENT] =
2092 g_signal_new (I_("key-press-event"),
2093 G_TYPE_FROM_CLASS (klass),
2095 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
2096 _gtk_boolean_handled_accumulator, NULL,
2097 _gtk_marshal_BOOLEAN__BOXED,
2099 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2100 g_signal_set_va_marshaller (widget_signals[KEY_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
2101 _gtk_marshal_BOOLEAN__BOXEDv);
2104 * GtkWidget::key-release-event:
2105 * @widget: the object which received the signal
2106 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2108 * The ::key-release-event signal is emitted when a key is released.
2110 * To receive this signal, the #GdkWindow associated to the widget needs
2111 * to enable the #GDK_KEY_RELEASE_MASK mask.
2113 * This signal will be sent to the grab widget if there is one.
2115 * Returns: %TRUE to stop other handlers from being invoked for the event.
2116 * %FALSE to propagate the event further.
2118 widget_signals[KEY_RELEASE_EVENT] =
2119 g_signal_new (I_("key-release-event"),
2120 G_TYPE_FROM_CLASS (klass),
2122 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2123 _gtk_boolean_handled_accumulator, NULL,
2124 _gtk_marshal_BOOLEAN__BOXED,
2126 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2127 g_signal_set_va_marshaller (widget_signals[KEY_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
2128 _gtk_marshal_BOOLEAN__BOXEDv);
2131 * GtkWidget::enter-notify-event:
2132 * @widget: the object which received the signal
2133 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2136 * The ::enter-notify-event will be emitted when the pointer enters
2137 * the @widget's window.
2139 * To receive this signal, the #GdkWindow associated to the widget needs
2140 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2142 * This signal will be sent to the grab widget if there is one.
2144 * Returns: %TRUE to stop other handlers from being invoked for the event.
2145 * %FALSE to propagate the event further.
2147 widget_signals[ENTER_NOTIFY_EVENT] =
2148 g_signal_new (I_("enter-notify-event"),
2149 G_TYPE_FROM_CLASS (klass),
2151 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2152 _gtk_boolean_handled_accumulator, NULL,
2153 _gtk_marshal_BOOLEAN__BOXED,
2155 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2156 g_signal_set_va_marshaller (widget_signals[ENTER_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2157 _gtk_marshal_BOOLEAN__BOXEDv);
2160 * GtkWidget::leave-notify-event:
2161 * @widget: the object which received the signal
2162 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2165 * The ::leave-notify-event will be emitted when the pointer leaves
2166 * the @widget's window.
2168 * To receive this signal, the #GdkWindow associated to the widget needs
2169 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2171 * This signal will be sent to the grab widget if there is one.
2173 * Returns: %TRUE to stop other handlers from being invoked for the event.
2174 * %FALSE to propagate the event further.
2176 widget_signals[LEAVE_NOTIFY_EVENT] =
2177 g_signal_new (I_("leave-notify-event"),
2178 G_TYPE_FROM_CLASS (klass),
2180 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2181 _gtk_boolean_handled_accumulator, NULL,
2182 _gtk_marshal_BOOLEAN__BOXED,
2184 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2185 g_signal_set_va_marshaller (widget_signals[LEAVE_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2186 _gtk_marshal_BOOLEAN__BOXEDv);
2189 * GtkWidget::configure-event:
2190 * @widget: the object which received the signal
2191 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2194 * The ::configure-event signal will be emitted when the size, position or
2195 * stacking of the @widget's window has changed.
2197 * To receive this signal, the #GdkWindow associated to the widget needs
2198 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2199 * automatically for all new windows.
2201 * Returns: %TRUE to stop other handlers from being invoked for the event.
2202 * %FALSE to propagate the event further.
2204 widget_signals[CONFIGURE_EVENT] =
2205 g_signal_new (I_("configure-event"),
2206 G_TYPE_FROM_CLASS (klass),
2208 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2209 _gtk_boolean_handled_accumulator, NULL,
2210 _gtk_marshal_BOOLEAN__BOXED,
2212 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2213 g_signal_set_va_marshaller (widget_signals[CONFIGURE_EVENT], G_TYPE_FROM_CLASS (klass),
2214 _gtk_marshal_BOOLEAN__BOXEDv);
2217 * GtkWidget::focus-in-event:
2218 * @widget: the object which received the signal
2219 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2222 * The ::focus-in-event signal will be emitted when the keyboard focus
2223 * enters the @widget's window.
2225 * To receive this signal, the #GdkWindow associated to the widget needs
2226 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2228 * Returns: %TRUE to stop other handlers from being invoked for the event.
2229 * %FALSE to propagate the event further.
2231 widget_signals[FOCUS_IN_EVENT] =
2232 g_signal_new (I_("focus-in-event"),
2233 G_TYPE_FROM_CLASS (klass),
2235 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2236 _gtk_boolean_handled_accumulator, NULL,
2237 _gtk_marshal_BOOLEAN__BOXED,
2239 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2240 g_signal_set_va_marshaller (widget_signals[FOCUS_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2241 _gtk_marshal_BOOLEAN__BOXEDv);
2244 * GtkWidget::focus-out-event:
2245 * @widget: the object which received the signal
2246 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2249 * The ::focus-out-event signal will be emitted when the keyboard focus
2250 * leaves the @widget's window.
2252 * To receive this signal, the #GdkWindow associated to the widget needs
2253 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2255 * Returns: %TRUE to stop other handlers from being invoked for the event.
2256 * %FALSE to propagate the event further.
2258 widget_signals[FOCUS_OUT_EVENT] =
2259 g_signal_new (I_("focus-out-event"),
2260 G_TYPE_FROM_CLASS (klass),
2262 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2263 _gtk_boolean_handled_accumulator, NULL,
2264 _gtk_marshal_BOOLEAN__BOXED,
2266 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2267 g_signal_set_va_marshaller (widget_signals[FOCUS_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2268 _gtk_marshal_BOOLEAN__BOXEDv);
2271 * GtkWidget::map-event:
2272 * @widget: the object which received the signal
2273 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2275 * The ::map-event signal will be emitted when the @widget's window is
2276 * mapped. A window is mapped when it becomes visible on the screen.
2278 * To receive this signal, the #GdkWindow associated to the widget needs
2279 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2280 * automatically for all new windows.
2282 * Returns: %TRUE to stop other handlers from being invoked for the event.
2283 * %FALSE to propagate the event further.
2285 widget_signals[MAP_EVENT] =
2286 g_signal_new (I_("map-event"),
2287 G_TYPE_FROM_CLASS (klass),
2289 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2290 _gtk_boolean_handled_accumulator, NULL,
2291 _gtk_marshal_BOOLEAN__BOXED,
2293 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2294 g_signal_set_va_marshaller (widget_signals[MAP_EVENT], G_TYPE_FROM_CLASS (klass),
2295 _gtk_marshal_BOOLEAN__BOXEDv);
2298 * GtkWidget::unmap-event:
2299 * @widget: the object which received the signal
2300 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2302 * The ::unmap-event signal will be emitted when the @widget's window is
2303 * unmapped. A window is unmapped when it becomes invisible on the screen.
2305 * To receive this signal, the #GdkWindow associated to the widget needs
2306 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2307 * automatically for all new windows.
2309 * Returns: %TRUE to stop other handlers from being invoked for the event.
2310 * %FALSE to propagate the event further.
2312 widget_signals[UNMAP_EVENT] =
2313 g_signal_new (I_("unmap-event"),
2314 G_TYPE_FROM_CLASS (klass),
2316 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2317 _gtk_boolean_handled_accumulator, NULL,
2318 _gtk_marshal_BOOLEAN__BOXED,
2320 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2321 g_signal_set_va_marshaller (widget_signals[UNMAP_EVENT], G_TYPE_FROM_CLASS (klass),
2322 _gtk_marshal_BOOLEAN__BOXEDv);
2325 * GtkWidget::property-notify-event:
2326 * @widget: the object which received the signal
2327 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2330 * The ::property-notify-event signal will be emitted when a property on
2331 * the @widget's window has been changed or deleted.
2333 * To receive this signal, the #GdkWindow associated to the widget needs
2334 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2336 * Returns: %TRUE to stop other handlers from being invoked for the event.
2337 * %FALSE to propagate the event further.
2339 widget_signals[PROPERTY_NOTIFY_EVENT] =
2340 g_signal_new (I_("property-notify-event"),
2341 G_TYPE_FROM_CLASS (klass),
2343 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2344 _gtk_boolean_handled_accumulator, NULL,
2345 _gtk_marshal_BOOLEAN__BOXED,
2347 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2348 g_signal_set_va_marshaller (widget_signals[PROPERTY_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2349 _gtk_marshal_BOOLEAN__BOXEDv);
2352 * GtkWidget::selection-clear-event:
2353 * @widget: the object which received the signal
2354 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2357 * The ::selection-clear-event signal will be emitted when the
2358 * the @widget's window has lost ownership of a selection.
2360 * Returns: %TRUE to stop other handlers from being invoked for the event.
2361 * %FALSE to propagate the event further.
2363 widget_signals[SELECTION_CLEAR_EVENT] =
2364 g_signal_new (I_("selection-clear-event"),
2365 G_TYPE_FROM_CLASS (klass),
2367 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2368 _gtk_boolean_handled_accumulator, NULL,
2369 _gtk_marshal_BOOLEAN__BOXED,
2371 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2372 g_signal_set_va_marshaller (widget_signals[SELECTION_CLEAR_EVENT], G_TYPE_FROM_CLASS (klass),
2373 _gtk_marshal_BOOLEAN__BOXEDv);
2376 * GtkWidget::selection-request-event:
2377 * @widget: the object which received the signal
2378 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2381 * The ::selection-request-event signal will be emitted when
2382 * another client requests ownership of the selection owned by
2383 * the @widget's window.
2385 * Returns: %TRUE to stop other handlers from being invoked for the event.
2386 * %FALSE to propagate the event further.
2388 widget_signals[SELECTION_REQUEST_EVENT] =
2389 g_signal_new (I_("selection-request-event"),
2390 G_TYPE_FROM_CLASS (klass),
2392 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2393 _gtk_boolean_handled_accumulator, NULL,
2394 _gtk_marshal_BOOLEAN__BOXED,
2396 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2397 g_signal_set_va_marshaller (widget_signals[SELECTION_REQUEST_EVENT], G_TYPE_FROM_CLASS (klass),
2398 _gtk_marshal_BOOLEAN__BOXEDv);
2401 * GtkWidget::selection-notify-event:
2402 * @widget: the object which received the signal.
2403 * @event: (type Gdk.EventSelection):
2405 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2407 widget_signals[SELECTION_NOTIFY_EVENT] =
2408 g_signal_new (I_("selection-notify-event"),
2409 G_TYPE_FROM_CLASS (klass),
2411 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2412 _gtk_boolean_handled_accumulator, NULL,
2413 _gtk_marshal_BOOLEAN__BOXED,
2415 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2416 g_signal_set_va_marshaller (widget_signals[SELECTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2417 _gtk_marshal_BOOLEAN__BOXEDv);
2420 * GtkWidget::selection-received:
2421 * @widget: the object which received the signal.
2425 widget_signals[SELECTION_RECEIVED] =
2426 g_signal_new (I_("selection-received"),
2427 G_TYPE_FROM_CLASS (klass),
2429 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2431 _gtk_marshal_VOID__BOXED_UINT,
2433 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2437 * GtkWidget::selection-get:
2438 * @widget: the object which received the signal.
2443 widget_signals[SELECTION_GET] =
2444 g_signal_new (I_("selection-get"),
2445 G_TYPE_FROM_CLASS (klass),
2447 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2449 _gtk_marshal_VOID__BOXED_UINT_UINT,
2451 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2456 * GtkWidget::proximity-in-event:
2457 * @widget: the object which received the signal
2458 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2461 * To receive this signal the #GdkWindow associated to the widget needs
2462 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2464 * This signal will be sent to the grab widget if there is one.
2466 * Returns: %TRUE to stop other handlers from being invoked for the event.
2467 * %FALSE to propagate the event further.
2469 widget_signals[PROXIMITY_IN_EVENT] =
2470 g_signal_new (I_("proximity-in-event"),
2471 G_TYPE_FROM_CLASS (klass),
2473 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2474 _gtk_boolean_handled_accumulator, NULL,
2475 _gtk_marshal_BOOLEAN__BOXED,
2477 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2478 g_signal_set_va_marshaller (widget_signals[PROXIMITY_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2479 _gtk_marshal_BOOLEAN__BOXEDv);
2482 * GtkWidget::proximity-out-event:
2483 * @widget: the object which received the signal
2484 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2487 * To receive this signal the #GdkWindow associated to the widget needs
2488 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2490 * This signal will be sent to the grab widget if there is one.
2492 * Returns: %TRUE to stop other handlers from being invoked for the event.
2493 * %FALSE to propagate the event further.
2495 widget_signals[PROXIMITY_OUT_EVENT] =
2496 g_signal_new (I_("proximity-out-event"),
2497 G_TYPE_FROM_CLASS (klass),
2499 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2500 _gtk_boolean_handled_accumulator, NULL,
2501 _gtk_marshal_BOOLEAN__BOXED,
2503 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2504 g_signal_set_va_marshaller (widget_signals[PROXIMITY_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2505 _gtk_marshal_BOOLEAN__BOXEDv);
2508 * GtkWidget::drag-leave:
2509 * @widget: the object which received the signal.
2510 * @drag_context: the drag context
2511 * @time: the timestamp of the motion event
2513 * The ::drag-leave signal is emitted on the drop site when the cursor
2514 * leaves the widget. A typical reason to connect to this signal is to
2515 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2516 * with gtk_drag_unhighlight()
2518 widget_signals[DRAG_LEAVE] =
2519 g_signal_new (I_("drag-leave"),
2520 G_TYPE_FROM_CLASS (klass),
2522 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2524 _gtk_marshal_VOID__OBJECT_UINT,
2526 GDK_TYPE_DRAG_CONTEXT,
2530 * GtkWidget::drag-begin:
2531 * @widget: the object which received the signal
2532 * @drag_context: the drag context
2534 * The ::drag-begin signal is emitted on the drag source when a drag is
2535 * started. A typical reason to connect to this signal is to set up a
2536 * custom drag icon with gtk_drag_source_set_icon().
2538 * Note that some widgets set up a drag icon in the default handler of
2539 * this signal, so you may have to use g_signal_connect_after() to
2540 * override what the default handler did.
2542 widget_signals[DRAG_BEGIN] =
2543 g_signal_new (I_("drag-begin"),
2544 G_TYPE_FROM_CLASS (klass),
2546 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2548 _gtk_marshal_VOID__OBJECT,
2550 GDK_TYPE_DRAG_CONTEXT);
2553 * GtkWidget::drag-end:
2554 * @widget: the object which received the signal
2555 * @drag_context: the drag context
2557 * The ::drag-end signal is emitted on the drag source when a drag is
2558 * finished. A typical reason to connect to this signal is to undo
2559 * things done in #GtkWidget::drag-begin.
2561 widget_signals[DRAG_END] =
2562 g_signal_new (I_("drag-end"),
2563 G_TYPE_FROM_CLASS (klass),
2565 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2567 _gtk_marshal_VOID__OBJECT,
2569 GDK_TYPE_DRAG_CONTEXT);
2572 * GtkWidget::drag-data-delete:
2573 * @widget: the object which received the signal
2574 * @drag_context: the drag context
2576 * The ::drag-data-delete signal is emitted on the drag source when a drag
2577 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2578 * handler is responsible for deleting the data that has been dropped. What
2579 * "delete" means depends on the context of the drag operation.
2581 widget_signals[DRAG_DATA_DELETE] =
2582 g_signal_new (I_("drag-data-delete"),
2583 G_TYPE_FROM_CLASS (klass),
2585 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2587 _gtk_marshal_VOID__OBJECT,
2589 GDK_TYPE_DRAG_CONTEXT);
2592 * GtkWidget::drag-failed:
2593 * @widget: the object which received the signal
2594 * @drag_context: the drag context
2595 * @result: the result of the drag operation
2597 * The ::drag-failed signal is emitted on the drag source when a drag has
2598 * failed. The signal handler may hook custom code to handle a failed DND
2599 * operation based on the type of error, it returns %TRUE is the failure has
2600 * been already handled (not showing the default "drag operation failed"
2601 * animation), otherwise it returns %FALSE.
2603 * Return value: %TRUE if the failed drag operation has been already handled.
2607 widget_signals[DRAG_FAILED] =
2608 g_signal_new (I_("drag-failed"),
2609 G_TYPE_FROM_CLASS (klass),
2611 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2612 _gtk_boolean_handled_accumulator, NULL,
2613 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2615 GDK_TYPE_DRAG_CONTEXT,
2616 GTK_TYPE_DRAG_RESULT);
2619 * GtkWidget::drag-motion:
2620 * @widget: the object which received the signal
2621 * @drag_context: the drag context
2622 * @x: the x coordinate of the current cursor position
2623 * @y: the y coordinate of the current cursor position
2624 * @time: the timestamp of the motion event
2626 * The drag-motion signal is emitted on the drop site when the user
2627 * moves the cursor over the widget during a drag. The signal handler
2628 * must determine whether the cursor position is in a drop zone or not.
2629 * If it is not in a drop zone, it returns %FALSE and no further processing
2630 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2631 * handler is responsible for providing the necessary information for
2632 * displaying feedback to the user, by calling gdk_drag_status().
2634 * If the decision whether the drop will be accepted or rejected can't be
2635 * made based solely on the cursor position and the type of the data, the
2636 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2637 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2638 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2639 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2640 * when using the drag-motion signal that way.
2642 * Also note that there is no drag-enter signal. The drag receiver has to
2643 * keep track of whether he has received any drag-motion signals since the
2644 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2645 * an "enter" signal. Upon an "enter", the handler will typically highlight
2646 * the drop site with gtk_drag_highlight().
2649 * drag_motion (GtkWidget *widget,
2650 * GdkDragContext *context,
2657 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2659 * if (!private_data->drag_highlight)
2661 * private_data->drag_highlight = 1;
2662 * gtk_drag_highlight (widget);
2665 * target = gtk_drag_dest_find_target (widget, context, NULL);
2666 * if (target == GDK_NONE)
2667 * gdk_drag_status (context, 0, time);
2670 * private_data->pending_status = context->suggested_action;
2671 * gtk_drag_get_data (widget, context, target, time);
2678 * drag_data_received (GtkWidget *widget,
2679 * GdkDragContext *context,
2682 * GtkSelectionData *selection_data,
2686 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2688 * if (private_data->suggested_action)
2690 * private_data->suggested_action = 0;
2692 * /* We are getting this data due to a request in drag_motion,
2693 * * rather than due to a request in drag_drop, so we are just
2694 * * supposed to call gdk_drag_status (), not actually paste in
2697 * str = gtk_selection_data_get_text (selection_data);
2698 * if (!data_is_acceptable (str))
2699 * gdk_drag_status (context, 0, time);
2701 * gdk_drag_status (context, private_data->suggested_action, time);
2705 * /* accept the drop */
2710 * Returns: whether the cursor position is in a drop zone
2712 widget_signals[DRAG_MOTION] =
2713 g_signal_new (I_("drag-motion"),
2714 G_TYPE_FROM_CLASS (klass),
2716 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2717 _gtk_boolean_handled_accumulator, NULL,
2718 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2720 GDK_TYPE_DRAG_CONTEXT,
2726 * GtkWidget::drag-drop:
2727 * @widget: the object which received the signal
2728 * @drag_context: the drag context
2729 * @x: the x coordinate of the current cursor position
2730 * @y: the y coordinate of the current cursor position
2731 * @time: the timestamp of the motion event
2733 * The ::drag-drop signal is emitted on the drop site when the user drops
2734 * the data onto the widget. The signal handler must determine whether
2735 * the cursor position is in a drop zone or not. If it is not in a drop
2736 * zone, it returns %FALSE and no further processing is necessary.
2737 * Otherwise, the handler returns %TRUE. In this case, the handler must
2738 * ensure that gtk_drag_finish() is called to let the source know that
2739 * the drop is done. The call to gtk_drag_finish() can be done either
2740 * directly or in a #GtkWidget::drag-data-received handler which gets
2741 * triggered by calling gtk_drag_get_data() to receive the data for one
2742 * or more of the supported targets.
2744 * Returns: whether the cursor position is in a drop zone
2746 widget_signals[DRAG_DROP] =
2747 g_signal_new (I_("drag-drop"),
2748 G_TYPE_FROM_CLASS (klass),
2750 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2751 _gtk_boolean_handled_accumulator, NULL,
2752 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2754 GDK_TYPE_DRAG_CONTEXT,
2760 * GtkWidget::drag-data-get:
2761 * @widget: the object which received the signal
2762 * @drag_context: the drag context
2763 * @data: the #GtkSelectionData to be filled with the dragged data
2764 * @info: the info that has been registered with the target in the
2766 * @time: the timestamp at which the data was requested
2768 * The ::drag-data-get signal is emitted on the drag source when the drop
2769 * site requests the data which is dragged. It is the responsibility of
2770 * the signal handler to fill @data with the data in the format which
2771 * is indicated by @info. See gtk_selection_data_set() and
2772 * gtk_selection_data_set_text().
2774 widget_signals[DRAG_DATA_GET] =
2775 g_signal_new (I_("drag-data-get"),
2776 G_TYPE_FROM_CLASS (klass),
2778 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2780 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2782 GDK_TYPE_DRAG_CONTEXT,
2783 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2788 * GtkWidget::drag-data-received:
2789 * @widget: the object which received the signal
2790 * @drag_context: the drag context
2791 * @x: where the drop happened
2792 * @y: where the drop happened
2793 * @data: the received data
2794 * @info: the info that has been registered with the target in the
2796 * @time: the timestamp at which the data was received
2798 * The ::drag-data-received signal is emitted on the drop site when the
2799 * dragged data has been received. If the data was received in order to
2800 * determine whether the drop will be accepted, the handler is expected
2801 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2802 * If the data was received in response to a #GtkWidget::drag-drop signal
2803 * (and this is the last target to be received), the handler for this
2804 * signal is expected to process the received data and then call
2805 * gtk_drag_finish(), setting the @success parameter depending on whether
2806 * the data was processed successfully.
2808 * The handler may inspect and modify @drag_context->action before calling
2809 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2810 * following example:
2813 * drag_data_received (GtkWidget *widget,
2814 * GdkDragContext *drag_context,
2817 * GtkSelectionData *data,
2821 * if ((data->length >= 0) && (data->format == 8))
2823 * if (drag_context->action == GDK_ACTION_ASK)
2825 * GtkWidget *dialog;
2828 * dialog = gtk_message_dialog_new (NULL,
2829 * GTK_DIALOG_MODAL |
2830 * GTK_DIALOG_DESTROY_WITH_PARENT,
2832 * GTK_BUTTONS_YES_NO,
2833 * "Move the data ?\n");
2834 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2835 * gtk_widget_destroy (dialog);
2837 * if (response == GTK_RESPONSE_YES)
2838 * drag_context->action = GDK_ACTION_MOVE;
2840 * drag_context->action = GDK_ACTION_COPY;
2843 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2847 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2851 widget_signals[DRAG_DATA_RECEIVED] =
2852 g_signal_new (I_("drag-data-received"),
2853 G_TYPE_FROM_CLASS (klass),
2855 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2857 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2859 GDK_TYPE_DRAG_CONTEXT,
2862 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2867 * GtkWidget::visibility-notify-event:
2868 * @widget: the object which received the signal
2869 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2870 * triggered this signal.
2872 * The ::visibility-notify-event will be emitted when the @widget's window
2873 * is obscured or unobscured.
2875 * To receive this signal the #GdkWindow associated to the widget needs
2876 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2878 * Returns: %TRUE to stop other handlers from being invoked for the event.
2879 * %FALSE to propagate the event further.
2881 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2882 g_signal_new (I_("visibility-notify-event"),
2883 G_TYPE_FROM_CLASS (klass),
2885 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2886 _gtk_boolean_handled_accumulator, NULL,
2887 _gtk_marshal_BOOLEAN__BOXED,
2889 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2892 * GtkWidget::window-state-event:
2893 * @widget: the object which received the signal
2894 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2895 * triggered this signal.
2897 * The ::window-state-event will be emitted when the state of the
2898 * toplevel window associated to the @widget changes.
2900 * To receive this signal the #GdkWindow associated to the widget
2901 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2902 * this mask automatically for all new windows.
2904 * Returns: %TRUE to stop other handlers from being invoked for the
2905 * event. %FALSE to propagate the event further.
2907 widget_signals[WINDOW_STATE_EVENT] =
2908 g_signal_new (I_("window-state-event"),
2909 G_TYPE_FROM_CLASS (klass),
2911 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2912 _gtk_boolean_handled_accumulator, NULL,
2913 _gtk_marshal_BOOLEAN__BOXED,
2915 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2916 g_signal_set_va_marshaller (widget_signals[WINDOW_STATE_EVENT], G_TYPE_FROM_CLASS (klass),
2917 _gtk_marshal_BOOLEAN__BOXEDv);
2920 * GtkWidget::damage-event:
2921 * @widget: the object which received the signal
2922 * @event: (type Gdk.EventExpose): the #GdkEventExpose event
2924 * Emitted when a redirected window belonging to @widget gets drawn into.
2925 * The region/area members of the event shows what area of the redirected
2926 * drawable was drawn into.
2928 * Returns: %TRUE to stop other handlers from being invoked for the event.
2929 * %FALSE to propagate the event further.
2933 widget_signals[DAMAGE_EVENT] =
2934 g_signal_new (I_("damage-event"),
2935 G_TYPE_FROM_CLASS (klass),
2937 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2938 _gtk_boolean_handled_accumulator, NULL,
2939 _gtk_marshal_BOOLEAN__BOXED,
2941 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2942 g_signal_set_va_marshaller (widget_signals[DAMAGE_EVENT], G_TYPE_FROM_CLASS (klass),
2943 _gtk_marshal_BOOLEAN__BOXEDv);
2946 * GtkWidget::grab-broken-event:
2947 * @widget: the object which received the signal
2948 * @event: (type Gdk.EventGrabBroken): the #GdkEventGrabBroken event
2950 * Emitted when a pointer or keyboard grab on a window belonging
2951 * to @widget gets broken.
2953 * On X11, this happens when the grab window becomes unviewable
2954 * (i.e. it or one of its ancestors is unmapped), or if the same
2955 * application grabs the pointer or keyboard again.
2957 * Returns: %TRUE to stop other handlers from being invoked for
2958 * the event. %FALSE to propagate the event further.
2962 widget_signals[GRAB_BROKEN_EVENT] =
2963 g_signal_new (I_("grab-broken-event"),
2964 G_TYPE_FROM_CLASS (klass),
2966 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2967 _gtk_boolean_handled_accumulator, NULL,
2968 _gtk_marshal_BOOLEAN__BOXED,
2970 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2971 g_signal_set_va_marshaller (widget_signals[GRAB_BROKEN_EVENT], G_TYPE_FROM_CLASS (klass),
2972 _gtk_marshal_BOOLEAN__BOXEDv);
2975 * GtkWidget::query-tooltip:
2976 * @widget: the object which received the signal
2977 * @x: the x coordinate of the cursor position where the request has
2978 * been emitted, relative to @widget's left side
2979 * @y: the y coordinate of the cursor position where the request has
2980 * been emitted, relative to @widget's top
2981 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2982 * @tooltip: a #GtkTooltip
2984 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2985 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2986 * focus in keyboard mode.
2988 * Using the given coordinates, the signal handler should determine
2989 * whether a tooltip should be shown for @widget. If this is the case
2990 * %TRUE should be returned, %FALSE otherwise. Note that if
2991 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2992 * should not be used.
2994 * The signal handler is free to manipulate @tooltip with the therefore
2995 * destined function calls.
2997 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
3001 widget_signals[QUERY_TOOLTIP] =
3002 g_signal_new (I_("query-tooltip"),
3003 G_TYPE_FROM_CLASS (klass),
3005 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
3006 _gtk_boolean_handled_accumulator, NULL,
3007 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
3015 * GtkWidget::popup-menu:
3016 * @widget: the object which received the signal
3018 * This signal gets emitted whenever a widget should pop up a context
3019 * menu. This usually happens through the standard key binding mechanism;
3020 * by pressing a certain key while a widget is focused, the user can cause
3021 * the widget to pop up a menu. For example, the #GtkEntry widget creates
3022 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
3023 * for an example of how to use this signal.
3025 * Returns: %TRUE if a menu was activated
3027 widget_signals[POPUP_MENU] =
3028 g_signal_new (I_("popup-menu"),
3029 G_TYPE_FROM_CLASS (klass),
3030 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3031 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
3032 _gtk_boolean_handled_accumulator, NULL,
3033 _gtk_marshal_BOOLEAN__VOID,
3037 * GtkWidget::show-help:
3038 * @widget: the object which received the signal.
3041 widget_signals[SHOW_HELP] =
3042 g_signal_new (I_("show-help"),
3043 G_TYPE_FROM_CLASS (klass),
3044 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3045 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
3046 _gtk_boolean_handled_accumulator, NULL,
3047 _gtk_marshal_BOOLEAN__ENUM,
3049 GTK_TYPE_WIDGET_HELP_TYPE);
3052 * GtkWidget::accel-closures-changed:
3053 * @widget: the object which received the signal.
3055 widget_signals[ACCEL_CLOSURES_CHANGED] =
3056 g_signal_new (I_("accel-closures-changed"),
3057 G_TYPE_FROM_CLASS (klass),
3061 _gtk_marshal_VOID__VOID,
3065 * GtkWidget::screen-changed:
3066 * @widget: the object on which the signal is emitted
3067 * @previous_screen: (allow-none): the previous screen, or %NULL if the
3068 * widget was not associated with a screen before
3070 * The ::screen-changed signal gets emitted when the
3071 * screen of a widget has changed.
3073 widget_signals[SCREEN_CHANGED] =
3074 g_signal_new (I_("screen-changed"),
3075 G_TYPE_FROM_CLASS (klass),
3077 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
3079 _gtk_marshal_VOID__OBJECT,
3084 * GtkWidget::can-activate-accel:
3085 * @widget: the object which received the signal
3086 * @signal_id: the ID of a signal installed on @widget
3088 * Determines whether an accelerator that activates the signal
3089 * identified by @signal_id can currently be activated.
3090 * This signal is present to allow applications and derived
3091 * widgets to override the default #GtkWidget handling
3092 * for determining whether an accelerator can be activated.
3094 * Returns: %TRUE if the signal can be activated.
3096 widget_signals[CAN_ACTIVATE_ACCEL] =
3097 g_signal_new (I_("can-activate-accel"),
3098 G_TYPE_FROM_CLASS (klass),
3100 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
3101 _gtk_boolean_handled_accumulator, NULL,
3102 _gtk_marshal_BOOLEAN__UINT,
3103 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
3105 binding_set = gtk_binding_set_by_class (klass);
3106 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
3108 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
3111 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
3113 GTK_TYPE_WIDGET_HELP_TYPE,
3114 GTK_WIDGET_HELP_TOOLTIP);
3115 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
3117 GTK_TYPE_WIDGET_HELP_TYPE,
3118 GTK_WIDGET_HELP_TOOLTIP);
3119 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
3121 GTK_TYPE_WIDGET_HELP_TYPE,
3122 GTK_WIDGET_HELP_WHATS_THIS);
3123 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
3125 GTK_TYPE_WIDGET_HELP_TYPE,
3126 GTK_WIDGET_HELP_WHATS_THIS);
3128 gtk_widget_class_install_style_property (klass,
3129 g_param_spec_boolean ("interior-focus",
3130 P_("Interior Focus"),
3131 P_("Whether to draw the focus indicator inside widgets"),
3133 GTK_PARAM_READABLE));
3135 gtk_widget_class_install_style_property (klass,
3136 g_param_spec_int ("focus-line-width",
3137 P_("Focus linewidth"),
3138 P_("Width, in pixels, of the focus indicator line"),
3140 GTK_PARAM_READABLE));
3142 gtk_widget_class_install_style_property (klass,
3143 g_param_spec_string ("focus-line-pattern",
3144 P_("Focus line dash pattern"),
3145 P_("Dash pattern used to draw the focus indicator"),
3147 GTK_PARAM_READABLE));
3148 gtk_widget_class_install_style_property (klass,
3149 g_param_spec_int ("focus-padding",
3150 P_("Focus padding"),
3151 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3153 GTK_PARAM_READABLE));
3154 gtk_widget_class_install_style_property (klass,
3155 g_param_spec_boxed ("cursor-color",
3157 P_("Color with which to draw insertion cursor"),
3159 GTK_PARAM_READABLE));
3160 gtk_widget_class_install_style_property (klass,
3161 g_param_spec_boxed ("secondary-cursor-color",
3162 P_("Secondary cursor color"),
3163 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3165 GTK_PARAM_READABLE));
3166 gtk_widget_class_install_style_property (klass,
3167 g_param_spec_float ("cursor-aspect-ratio",
3168 P_("Cursor line aspect ratio"),
3169 P_("Aspect ratio with which to draw insertion cursor"),
3171 GTK_PARAM_READABLE));
3173 gtk_widget_class_install_style_property (klass,
3174 g_param_spec_boolean ("window-dragging",
3175 P_("Window dragging"),
3176 P_("Whether windows can be dragged by clicking on empty areas"),
3178 GTK_PARAM_READABLE));
3181 * GtkWidget:link-color:
3183 * The "link-color" style property defines the color of unvisited links.
3187 gtk_widget_class_install_style_property (klass,
3188 g_param_spec_boxed ("link-color",
3189 P_("Unvisited Link Color"),
3190 P_("Color of unvisited links"),
3192 GTK_PARAM_READABLE));
3195 * GtkWidget:visited-link-color:
3197 * The "visited-link-color" style property defines the color of visited links.
3201 gtk_widget_class_install_style_property (klass,
3202 g_param_spec_boxed ("visited-link-color",
3203 P_("Visited Link Color"),
3204 P_("Color of visited links"),
3206 GTK_PARAM_READABLE));
3209 * GtkWidget:wide-separators:
3211 * The "wide-separators" style property defines whether separators have
3212 * configurable width and should be drawn using a box instead of a line.
3216 gtk_widget_class_install_style_property (klass,
3217 g_param_spec_boolean ("wide-separators",
3218 P_("Wide Separators"),
3219 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3221 GTK_PARAM_READABLE));
3224 * GtkWidget:separator-width:
3226 * The "separator-width" style property defines the width of separators.
3227 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3231 gtk_widget_class_install_style_property (klass,
3232 g_param_spec_int ("separator-width",
3233 P_("Separator Width"),
3234 P_("The width of separators if wide-separators is TRUE"),
3236 GTK_PARAM_READABLE));
3239 * GtkWidget:separator-height:
3241 * The "separator-height" style property defines the height of separators.
3242 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3246 gtk_widget_class_install_style_property (klass,
3247 g_param_spec_int ("separator-height",
3248 P_("Separator Height"),
3249 P_("The height of separators if \"wide-separators\" is TRUE"),
3251 GTK_PARAM_READABLE));
3254 * GtkWidget:scroll-arrow-hlength:
3256 * The "scroll-arrow-hlength" style property defines the length of
3257 * horizontal scroll arrows.
3261 gtk_widget_class_install_style_property (klass,
3262 g_param_spec_int ("scroll-arrow-hlength",
3263 P_("Horizontal Scroll Arrow Length"),
3264 P_("The length of horizontal scroll arrows"),
3266 GTK_PARAM_READABLE));
3269 * GtkWidget:scroll-arrow-vlength:
3271 * The "scroll-arrow-vlength" style property defines the length of
3272 * vertical scroll arrows.
3276 gtk_widget_class_install_style_property (klass,
3277 g_param_spec_int ("scroll-arrow-vlength",
3278 P_("Vertical Scroll Arrow Length"),
3279 P_("The length of vertical scroll arrows"),
3281 GTK_PARAM_READABLE));
3283 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3285 gtk_widget_class_set_accessible_type (klass, GTK_TYPE_WIDGET_ACCESSIBLE);
3289 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3293 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3294 for (node = list; node; node = node->next)
3296 GParamSpec *pspec = node->data;
3298 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3299 g_param_spec_unref (pspec);
3305 gtk_widget_set_property (GObject *object,
3307 const GValue *value,
3310 GtkWidget *widget = GTK_WIDGET (object);
3315 gchar *tooltip_markup;
3316 const gchar *tooltip_text;
3317 GtkWindow *tooltip_window;
3320 gtk_widget_set_name (widget, g_value_get_string (value));
3323 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3325 case PROP_WIDTH_REQUEST:
3326 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3328 case PROP_HEIGHT_REQUEST:
3329 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3332 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3334 case PROP_SENSITIVE:
3335 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3337 case PROP_APP_PAINTABLE:
3338 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3340 case PROP_CAN_FOCUS:
3341 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3343 case PROP_HAS_FOCUS:
3344 if (g_value_get_boolean (value))
3345 gtk_widget_grab_focus (widget);
3348 if (g_value_get_boolean (value))
3349 gtk_widget_grab_focus (widget);
3351 case PROP_CAN_DEFAULT:
3352 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3354 case PROP_HAS_DEFAULT:
3355 if (g_value_get_boolean (value))
3356 gtk_widget_grab_default (widget);
3358 case PROP_RECEIVES_DEFAULT:
3359 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3362 gtk_widget_set_style (widget, g_value_get_object (value));
3365 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3366 gtk_widget_set_events (widget, g_value_get_flags (value));
3368 case PROP_NO_SHOW_ALL:
3369 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3371 case PROP_HAS_TOOLTIP:
3372 gtk_widget_real_set_has_tooltip (widget,
3373 g_value_get_boolean (value), FALSE);
3375 case PROP_TOOLTIP_MARKUP:
3376 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3377 tooltip_markup = g_value_dup_string (value);
3379 /* Treat an empty string as a NULL string,
3380 * because an empty string would be useless for a tooltip:
3382 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3384 g_free (tooltip_markup);
3385 tooltip_markup = NULL;
3388 g_object_set_qdata_full (object, quark_tooltip_markup,
3389 tooltip_markup, g_free);
3391 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3392 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3393 if (gtk_widget_get_visible (widget))
3394 gtk_widget_queue_tooltip_query (widget);
3396 case PROP_TOOLTIP_TEXT:
3397 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3399 tooltip_text = g_value_get_string (value);
3401 /* Treat an empty string as a NULL string,
3402 * because an empty string would be useless for a tooltip:
3404 if (tooltip_text && (strlen (tooltip_text) == 0))
3405 tooltip_text = NULL;
3407 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3409 g_object_set_qdata_full (object, quark_tooltip_markup,
3410 tooltip_markup, g_free);
3412 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3413 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3414 if (gtk_widget_get_visible (widget))
3415 gtk_widget_queue_tooltip_query (widget);
3417 case PROP_DOUBLE_BUFFERED:
3418 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3421 gtk_widget_set_halign (widget, g_value_get_enum (value));
3424 gtk_widget_set_valign (widget, g_value_get_enum (value));
3426 case PROP_MARGIN_LEFT:
3427 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3429 case PROP_MARGIN_RIGHT:
3430 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3432 case PROP_MARGIN_TOP:
3433 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3435 case PROP_MARGIN_BOTTOM:
3436 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3439 g_object_freeze_notify (G_OBJECT (widget));
3440 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3441 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3442 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3443 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3444 g_object_thaw_notify (G_OBJECT (widget));
3447 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3449 case PROP_HEXPAND_SET:
3450 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3453 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3455 case PROP_VEXPAND_SET:
3456 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3459 g_object_freeze_notify (G_OBJECT (widget));
3460 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3461 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3462 g_object_thaw_notify (G_OBJECT (widget));
3465 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3471 gtk_widget_get_property (GObject *object,
3476 GtkWidget *widget = GTK_WIDGET (object);
3477 GtkWidgetPrivate *priv = widget->priv;
3485 g_value_set_string (value, priv->name);
3487 g_value_set_static_string (value, "");
3490 g_value_set_object (value, priv->parent);
3492 case PROP_WIDTH_REQUEST:
3495 gtk_widget_get_size_request (widget, &w, NULL);
3496 g_value_set_int (value, w);
3499 case PROP_HEIGHT_REQUEST:
3502 gtk_widget_get_size_request (widget, NULL, &h);
3503 g_value_set_int (value, h);
3507 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3509 case PROP_SENSITIVE:
3510 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3512 case PROP_APP_PAINTABLE:
3513 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3515 case PROP_CAN_FOCUS:
3516 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3518 case PROP_HAS_FOCUS:
3519 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3522 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3524 case PROP_CAN_DEFAULT:
3525 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3527 case PROP_HAS_DEFAULT:
3528 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3530 case PROP_RECEIVES_DEFAULT:
3531 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3533 case PROP_COMPOSITE_CHILD:
3534 g_value_set_boolean (value, widget->priv->composite_child);
3537 g_value_set_object (value, gtk_widget_get_style (widget));
3540 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3541 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3543 case PROP_NO_SHOW_ALL:
3544 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3546 case PROP_HAS_TOOLTIP:
3547 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3549 case PROP_TOOLTIP_TEXT:
3551 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3554 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3555 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3557 g_value_take_string (value, text);
3560 case PROP_TOOLTIP_MARKUP:
3561 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3564 g_value_set_object (value, gtk_widget_get_window (widget));
3566 case PROP_DOUBLE_BUFFERED:
3567 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3570 g_value_set_enum (value, gtk_widget_get_halign (widget));
3573 g_value_set_enum (value, gtk_widget_get_valign (widget));
3575 case PROP_MARGIN_LEFT:
3576 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3578 case PROP_MARGIN_RIGHT:
3579 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3581 case PROP_MARGIN_TOP:
3582 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3584 case PROP_MARGIN_BOTTOM:
3585 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3589 GtkWidgetAuxInfo *aux_info = gtk_widget_get_aux_info (widget, FALSE);
3590 if (aux_info == NULL)
3592 g_value_set_int (value, 0);
3596 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3597 aux_info->margin.right),
3598 MAX (aux_info->margin.top,
3599 aux_info->margin.bottom)));
3604 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3606 case PROP_HEXPAND_SET:
3607 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3610 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3612 case PROP_VEXPAND_SET:
3613 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3616 g_value_set_boolean (value,
3617 gtk_widget_get_hexpand (widget) &&
3618 gtk_widget_get_vexpand (widget));
3621 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3627 gtk_widget_init (GtkWidget *widget)
3629 GtkWidgetPrivate *priv;
3631 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3634 priv = widget->priv;
3636 priv->child_visible = TRUE;
3638 priv->allocation.x = -1;
3639 priv->allocation.y = -1;
3640 priv->allocation.width = 1;
3641 priv->allocation.height = 1;
3642 priv->window = NULL;
3643 priv->parent = NULL;
3645 priv->sensitive = TRUE;
3646 priv->composite_child = composite_child_stack != 0;
3647 priv->double_buffered = TRUE;
3648 priv->redraw_on_alloc = TRUE;
3649 priv->width_request_needed = TRUE;
3650 priv->height_request_needed = TRUE;
3651 priv->alloc_needed = TRUE;
3653 /* this will be set to TRUE if the widget gets a child or if the
3654 * expand flag is set on the widget, but until one of those happen
3655 * we know the expand is already properly FALSE.
3657 * We really want to default FALSE here to avoid computing expand
3658 * all over the place while initially building a widget tree.
3660 priv->need_compute_expand = FALSE;
3662 priv->style = gtk_widget_get_default_style ();
3663 g_object_ref (priv->style);
3668 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3670 GParamSpec **pspecs)
3672 GtkWidgetPrivate *priv = widget->priv;
3673 GtkWidget *container = priv->parent;
3676 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3677 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3681 * gtk_widget_freeze_child_notify:
3682 * @widget: a #GtkWidget
3684 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3685 * signals are queued until gtk_widget_thaw_child_notify() is called
3688 * This is the analogue of g_object_freeze_notify() for child properties.
3691 gtk_widget_freeze_child_notify (GtkWidget *widget)
3693 g_return_if_fail (GTK_IS_WIDGET (widget));
3695 if (!G_OBJECT (widget)->ref_count)
3698 g_object_ref (widget);
3699 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3700 g_object_unref (widget);
3704 * gtk_widget_child_notify:
3705 * @widget: a #GtkWidget
3706 * @child_property: the name of a child property installed on the
3707 * class of @widget<!-- -->'s parent
3709 * Emits a #GtkWidget::child-notify signal for the
3710 * <link linkend="child-properties">child property</link> @child_property
3713 * This is the analogue of g_object_notify() for child properties.
3715 * Also see gtk_container_child_notify().
3718 gtk_widget_child_notify (GtkWidget *widget,
3719 const gchar *child_property)
3721 if (widget->priv->parent == NULL)
3724 gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
3728 * gtk_widget_thaw_child_notify:
3729 * @widget: a #GtkWidget
3731 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3732 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3736 gtk_widget_thaw_child_notify (GtkWidget *widget)
3738 GObjectNotifyQueue *nqueue;
3740 g_return_if_fail (GTK_IS_WIDGET (widget));
3742 if (!G_OBJECT (widget)->ref_count)
3745 g_object_ref (widget);
3746 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3747 if (!nqueue || !nqueue->freeze_count)
3748 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3749 G_OBJECT_TYPE_NAME (widget), widget);
3751 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3752 g_object_unref (widget);
3758 * @type: type ID of the widget to create
3759 * @first_property_name: name of first property to set
3760 * @...: value of first property, followed by more properties,
3763 * This is a convenience function for creating a widget and setting
3764 * its properties in one go. For example you might write:
3765 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3766 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3767 * g_object_new(), but returns a widget so you don't have to
3768 * cast the object yourself.
3770 * Return value: a new #GtkWidget of type @widget_type
3773 gtk_widget_new (GType type,
3774 const gchar *first_property_name,
3780 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3782 va_start (var_args, first_property_name);
3783 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3790 gtk_widget_queue_draw_child (GtkWidget *widget)
3792 GtkWidgetPrivate *priv = widget->priv;
3795 parent = priv->parent;
3796 if (parent && gtk_widget_is_drawable (parent))
3797 gtk_widget_queue_draw_area (parent,
3800 priv->allocation.width,
3801 priv->allocation.height);
3805 * gtk_widget_unparent:
3806 * @widget: a #GtkWidget
3808 * This function is only for use in widget implementations.
3809 * Should be called by implementations of the remove method
3810 * on #GtkContainer, to dissociate a child from the container.
3813 gtk_widget_unparent (GtkWidget *widget)
3815 GtkWidgetPrivate *priv;
3816 GObjectNotifyQueue *nqueue;
3817 GtkWidget *toplevel;
3818 GtkWidget *old_parent;
3820 g_return_if_fail (GTK_IS_WIDGET (widget));
3822 priv = widget->priv;
3824 if (priv->parent == NULL)
3827 /* keep this function in sync with gtk_menu_detach() */
3829 gtk_widget_push_verify_invariants (widget);
3831 g_object_freeze_notify (G_OBJECT (widget));
3832 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3834 toplevel = gtk_widget_get_toplevel (widget);
3835 if (gtk_widget_is_toplevel (toplevel))
3836 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3838 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3839 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3841 gtk_widget_queue_draw_child (widget);
3843 /* Reset the width and height here, to force reallocation if we
3844 * get added back to a new parent. This won't work if our new
3845 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3846 * (would 0x0 be OK here?)
3848 priv->allocation.width = 1;
3849 priv->allocation.height = 1;
3851 if (gtk_widget_get_realized (widget))
3853 if (priv->in_reparent)
3854 gtk_widget_unmap (widget);
3856 gtk_widget_unrealize (widget);
3859 /* If we are unanchoring the child, we save around the toplevel
3860 * to emit hierarchy changed
3862 if (priv->parent->priv->anchored)
3863 g_object_ref (toplevel);
3867 /* Removing a widget from a container restores the child visible
3868 * flag to the default state, so it doesn't affect the child
3869 * in the next parent.
3871 priv->child_visible = TRUE;
3873 old_parent = priv->parent;
3874 priv->parent = NULL;
3876 /* parent may no longer expand if the removed
3877 * child was expand=TRUE and could therefore
3880 if (gtk_widget_get_visible (widget) &&
3881 (priv->need_compute_expand ||
3882 priv->computed_hexpand ||
3883 priv->computed_vexpand))
3885 gtk_widget_queue_compute_expand (old_parent);
3888 /* Unset BACKDROP since we are no longer inside a toplevel window */
3889 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_BACKDROP);
3891 gtk_style_context_set_parent (priv->context, NULL);
3893 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3896 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3897 g_object_unref (toplevel);
3900 /* Now that the parent pointer is nullified and the hierarchy-changed
3901 * already passed, go ahead and unset the parent window, if we are unparenting
3902 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
3903 * will fire again for the new subhierarchy.
3905 gtk_widget_set_parent_window (widget, NULL);
3907 g_object_notify (G_OBJECT (widget), "parent");
3908 g_object_thaw_notify (G_OBJECT (widget));
3910 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3911 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3913 gtk_widget_pop_verify_invariants (widget);
3914 g_object_unref (widget);
3918 * gtk_widget_destroy:
3919 * @widget: a #GtkWidget
3921 * Destroys a widget.
3924 * destroyed, it will break any references it holds to other objects.
3925 * If the widget is inside a container, the widget will be removed
3926 * from the container. If the widget is a toplevel (derived from
3927 * #GtkWindow), it will be removed from the list of toplevels, and the
3928 * reference GTK+ holds to it will be removed. Removing a
3929 * widget from its container or the list of toplevels results in the
3930 * widget being finalized, unless you've added additional references
3931 * to the widget with g_object_ref().
3933 * In most cases, only toplevel widgets (windows) require explicit
3934 * destruction, because when you destroy a toplevel its children will
3935 * be destroyed as well.
3938 gtk_widget_destroy (GtkWidget *widget)
3940 g_return_if_fail (GTK_IS_WIDGET (widget));
3942 if (!widget->priv->in_destruction)
3943 g_object_run_dispose (G_OBJECT (widget));
3947 * gtk_widget_destroyed:
3948 * @widget: a #GtkWidget
3949 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3951 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3952 * %NULL. It's intended to be used as a callback connected to the
3953 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3954 * as a signal handler, and pass the address of your widget variable
3955 * as user data. Then when the widget is destroyed, the variable will
3956 * be set to %NULL. Useful for example to avoid multiple copies
3957 * of the same dialog.
3960 gtk_widget_destroyed (GtkWidget *widget,
3961 GtkWidget **widget_pointer)
3963 /* Don't make any assumptions about the
3965 * Even check widget_pointer.
3968 *widget_pointer = NULL;
3973 * @widget: a #GtkWidget
3975 * Flags a widget to be displayed. Any widget that isn't shown will
3976 * not appear on the screen. If you want to show all the widgets in a
3977 * container, it's easier to call gtk_widget_show_all() on the
3978 * container, instead of individually showing the widgets.
3980 * Remember that you have to show the containers containing a widget,
3981 * in addition to the widget itself, before it will appear onscreen.
3983 * When a toplevel container is shown, it is immediately realized and
3984 * mapped; other shown widgets are realized and mapped when their
3985 * toplevel container is realized and mapped.
3988 gtk_widget_show (GtkWidget *widget)
3990 g_return_if_fail (GTK_IS_WIDGET (widget));
3992 if (!gtk_widget_get_visible (widget))
3994 g_object_ref (widget);
3995 gtk_widget_push_verify_invariants (widget);
3997 if (!gtk_widget_is_toplevel (widget))
3998 gtk_widget_queue_resize (widget);
4000 /* see comment in set_parent() for why this should and can be
4003 if (widget->priv->need_compute_expand ||
4004 widget->priv->computed_hexpand ||
4005 widget->priv->computed_vexpand)
4007 if (widget->priv->parent != NULL)
4008 gtk_widget_queue_compute_expand (widget->priv->parent);
4011 g_signal_emit (widget, widget_signals[SHOW], 0);
4012 g_object_notify (G_OBJECT (widget), "visible");
4014 gtk_widget_pop_verify_invariants (widget);
4015 g_object_unref (widget);
4020 gtk_widget_real_show (GtkWidget *widget)
4022 GtkWidgetPrivate *priv = widget->priv;
4024 if (!gtk_widget_get_visible (widget))
4026 priv->visible = TRUE;
4029 gtk_widget_get_mapped (priv->parent) &&
4030 gtk_widget_get_child_visible (widget) &&
4031 !gtk_widget_get_mapped (widget))
4032 gtk_widget_map (widget);
4037 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
4040 g_signal_handlers_disconnect_by_func (widget,
4041 gtk_widget_show_map_callback,
4046 * gtk_widget_show_now:
4047 * @widget: a #GtkWidget
4049 * Shows a widget. If the widget is an unmapped toplevel widget
4050 * (i.e. a #GtkWindow that has not yet been shown), enter the main
4051 * loop and wait for the window to actually be mapped. Be careful;
4052 * because the main loop is running, anything can happen during
4056 gtk_widget_show_now (GtkWidget *widget)
4060 g_return_if_fail (GTK_IS_WIDGET (widget));
4062 /* make sure we will get event */
4063 if (!gtk_widget_get_mapped (widget) &&
4064 gtk_widget_is_toplevel (widget))
4066 gtk_widget_show (widget);
4068 g_signal_connect (widget, "map-event",
4069 G_CALLBACK (gtk_widget_show_map_callback),
4073 gtk_main_iteration ();
4076 gtk_widget_show (widget);
4081 * @widget: a #GtkWidget
4083 * Reverses the effects of gtk_widget_show(), causing the widget to be
4084 * hidden (invisible to the user).
4087 gtk_widget_hide (GtkWidget *widget)
4089 g_return_if_fail (GTK_IS_WIDGET (widget));
4091 if (gtk_widget_get_visible (widget))
4093 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
4095 g_object_ref (widget);
4096 gtk_widget_push_verify_invariants (widget);
4098 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
4099 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
4101 /* a parent may now be expand=FALSE since we're hidden. */
4102 if (widget->priv->need_compute_expand ||
4103 widget->priv->computed_hexpand ||
4104 widget->priv->computed_vexpand)
4106 gtk_widget_queue_compute_expand (widget);
4109 g_signal_emit (widget, widget_signals[HIDE], 0);
4110 if (!gtk_widget_is_toplevel (widget))
4111 gtk_widget_queue_resize (widget);
4112 g_object_notify (G_OBJECT (widget), "visible");
4114 gtk_widget_pop_verify_invariants (widget);
4115 g_object_unref (widget);
4120 gtk_widget_real_hide (GtkWidget *widget)
4122 if (gtk_widget_get_visible (widget))
4124 widget->priv->visible = FALSE;
4126 if (gtk_widget_get_mapped (widget))
4127 gtk_widget_unmap (widget);
4129 if (widget->priv->context)
4130 _gtk_style_context_stop_animations (widget->priv->context);
4135 * gtk_widget_hide_on_delete:
4136 * @widget: a #GtkWidget
4138 * Utility function; intended to be connected to the #GtkWidget::delete-event
4139 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4140 * argument, then returns %TRUE. If connected to ::delete-event, the
4141 * result is that clicking the close button for a window (on the
4142 * window frame, top right corner usually) will hide but not destroy
4143 * the window. By default, GTK+ destroys windows when ::delete-event
4146 * Return value: %TRUE
4149 gtk_widget_hide_on_delete (GtkWidget *widget)
4151 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4153 gtk_widget_hide (widget);
4159 * gtk_widget_show_all:
4160 * @widget: a #GtkWidget
4162 * Recursively shows a widget, and any child widgets (if the widget is
4166 gtk_widget_show_all (GtkWidget *widget)
4168 GtkWidgetClass *class;
4170 g_return_if_fail (GTK_IS_WIDGET (widget));
4172 if (gtk_widget_get_no_show_all (widget))
4175 class = GTK_WIDGET_GET_CLASS (widget);
4177 if (class->show_all)
4178 class->show_all (widget);
4183 * @widget: a #GtkWidget
4185 * This function is only for use in widget implementations. Causes
4186 * a widget to be mapped if it isn't already.
4189 gtk_widget_map (GtkWidget *widget)
4191 GtkWidgetPrivate *priv;
4193 g_return_if_fail (GTK_IS_WIDGET (widget));
4194 g_return_if_fail (gtk_widget_get_visible (widget));
4195 g_return_if_fail (gtk_widget_get_child_visible (widget));
4197 priv = widget->priv;
4199 if (!gtk_widget_get_mapped (widget))
4201 gtk_widget_push_verify_invariants (widget);
4203 if (!gtk_widget_get_realized (widget))
4204 gtk_widget_realize (widget);
4206 g_signal_emit (widget, widget_signals[MAP], 0);
4208 if (!gtk_widget_get_has_window (widget))
4209 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4211 gtk_widget_pop_verify_invariants (widget);
4217 * @widget: a #GtkWidget
4219 * This function is only for use in widget implementations. Causes
4220 * a widget to be unmapped if it's currently mapped.
4223 gtk_widget_unmap (GtkWidget *widget)
4225 GtkWidgetPrivate *priv;
4227 g_return_if_fail (GTK_IS_WIDGET (widget));
4229 priv = widget->priv;
4231 if (gtk_widget_get_mapped (widget))
4233 gtk_widget_push_verify_invariants (widget);
4235 if (!gtk_widget_get_has_window (widget))
4236 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4237 _gtk_tooltip_hide (widget);
4238 g_signal_emit (widget, widget_signals[UNMAP], 0);
4240 gtk_widget_pop_verify_invariants (widget);
4242 /* Unset pointer/window info */
4243 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4248 _gtk_widget_enable_device_events (GtkWidget *widget)
4250 GHashTable *device_events;
4251 GHashTableIter iter;
4252 gpointer key, value;
4254 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4259 g_hash_table_iter_init (&iter, device_events);
4261 while (g_hash_table_iter_next (&iter, &key, &value))
4264 GdkEventMask event_mask;
4267 event_mask = GPOINTER_TO_UINT (value);
4268 gtk_widget_add_events_internal (widget, device, event_mask);
4273 get_widget_windows (GtkWidget *widget)
4275 GList *window_list, *last, *l, *children, *ret;
4277 if (gtk_widget_get_has_window (widget))
4278 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4280 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4282 last = g_list_last (window_list);
4285 for (l = window_list; l; l = l->next)
4287 GtkWidget *window_widget = NULL;
4289 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4291 if (widget != window_widget)
4294 ret = g_list_prepend (ret, l->data);
4295 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4299 last = g_list_concat (last, children);
4300 last = g_list_last (last);
4304 g_list_free (window_list);
4310 device_enable_foreach (GtkWidget *widget,
4313 GdkDevice *device = user_data;
4314 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4318 device_disable_foreach (GtkWidget *widget,
4321 GdkDevice *device = user_data;
4322 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4326 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4331 GList *window_list, *l;
4333 window_list = get_widget_windows (widget);
4335 for (l = window_list; l; l = l->next)
4337 GdkEventMask events = 0;
4343 events = gdk_window_get_events (window);
4345 gdk_window_set_device_events (window, device, events);
4348 if (recurse && GTK_IS_CONTAINER (widget))
4351 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4353 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4356 g_list_free (window_list);
4360 gtk_widget_update_devices_mask (GtkWidget *widget,
4363 GList *enabled_devices, *l;
4365 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4367 for (l = enabled_devices; l; l = l->next)
4368 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4372 * gtk_widget_realize:
4373 * @widget: a #GtkWidget
4375 * Creates the GDK (windowing system) resources associated with a
4376 * widget. For example, @widget->window will be created when a widget
4377 * is realized. Normally realization happens implicitly; if you show
4378 * a widget and all its parent containers, then the widget will be
4379 * realized and mapped automatically.
4381 * Realizing a widget requires all
4382 * the widget's parent widgets to be realized; calling
4383 * gtk_widget_realize() realizes the widget's parents in addition to
4384 * @widget itself. If a widget is not yet inside a toplevel window
4385 * when you realize it, bad things will happen.
4387 * This function is primarily used in widget implementations, and
4388 * isn't very useful otherwise. Many times when you think you might
4389 * need it, a better approach is to connect to a signal that will be
4390 * called after the widget is realized automatically, such as
4391 * #GtkWidget::draw. Or simply g_signal_connect () to the
4392 * #GtkWidget::realize signal.
4395 gtk_widget_realize (GtkWidget *widget)
4397 GtkWidgetPrivate *priv;
4398 cairo_region_t *region;
4400 g_return_if_fail (GTK_IS_WIDGET (widget));
4401 g_return_if_fail (widget->priv->anchored ||
4402 GTK_IS_INVISIBLE (widget));
4404 priv = widget->priv;
4406 if (!gtk_widget_get_realized (widget))
4408 gtk_widget_push_verify_invariants (widget);
4411 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4412 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4415 if (priv->parent == NULL &&
4416 !gtk_widget_is_toplevel (widget))
4417 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4418 "inside a toplevel window is not going to work very well. "
4419 "Widgets must be inside a toplevel container before realizing them.");
4421 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4422 gtk_widget_realize (priv->parent);
4424 gtk_widget_ensure_style (widget);
4426 if (priv->style_update_pending)
4427 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4429 g_signal_emit (widget, widget_signals[REALIZE], 0);
4431 gtk_widget_real_set_has_tooltip (widget,
4432 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4435 if (priv->has_shape_mask)
4437 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4438 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4441 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4443 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4445 if (priv->multidevice)
4446 gdk_window_set_support_multidevice (priv->window, TRUE);
4448 _gtk_widget_enable_device_events (widget);
4449 gtk_widget_update_devices_mask (widget, TRUE);
4451 gtk_widget_pop_verify_invariants (widget);
4456 * gtk_widget_unrealize:
4457 * @widget: a #GtkWidget
4459 * This function is only useful in widget implementations.
4460 * Causes a widget to be unrealized (frees all GDK resources
4461 * associated with the widget, such as @widget->window).
4464 gtk_widget_unrealize (GtkWidget *widget)
4466 g_return_if_fail (GTK_IS_WIDGET (widget));
4468 gtk_widget_push_verify_invariants (widget);
4470 if (widget->priv->has_shape_mask)
4471 gtk_widget_shape_combine_region (widget, NULL);
4473 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4474 gtk_widget_input_shape_combine_region (widget, NULL);
4476 if (gtk_widget_get_realized (widget))
4478 g_object_ref (widget);
4480 if (widget->priv->mapped)
4481 gtk_widget_unmap (widget);
4483 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4484 g_assert (!widget->priv->mapped);
4485 gtk_widget_set_realized (widget, FALSE);
4487 g_object_unref (widget);
4490 gtk_widget_pop_verify_invariants (widget);
4493 /*****************************************
4495 *****************************************/
4498 * gtk_widget_queue_draw_region:
4499 * @widget: a #GtkWidget
4500 * @region: region to draw
4502 * Invalidates the rectangular area of @widget defined by @region by
4503 * calling gdk_window_invalidate_region() on the widget's window and
4504 * all its child windows. Once the main loop becomes idle (after the
4505 * current batch of events has been processed, roughly), the window
4506 * will receive expose events for the union of all regions that have
4509 * Normally you would only use this function in widget
4510 * implementations. You might also use it to schedule a redraw of a
4511 * #GtkDrawingArea or some portion thereof.
4516 gtk_widget_queue_draw_region (GtkWidget *widget,
4517 const cairo_region_t *region)
4519 GtkWidgetPrivate *priv;
4522 g_return_if_fail (GTK_IS_WIDGET (widget));
4524 priv = widget->priv;
4526 if (!gtk_widget_get_realized (widget))
4529 /* Just return if the widget or one of its ancestors isn't mapped */
4530 for (w = widget; w != NULL; w = w->priv->parent)
4531 if (!gtk_widget_get_mapped (w))
4534 gdk_window_invalidate_region (priv->window, region, TRUE);
4538 * gtk_widget_queue_draw_area:
4539 * @widget: a #GtkWidget
4540 * @x: x coordinate of upper-left corner of rectangle to redraw
4541 * @y: y coordinate of upper-left corner of rectangle to redraw
4542 * @width: width of region to draw
4543 * @height: height of region to draw
4545 * Convenience function that calls gtk_widget_queue_draw_region() on
4546 * the region created from the given coordinates.
4548 * The region here is specified in widget coordinates.
4549 * Widget coordinates are a bit odd; for historical reasons, they are
4550 * defined as @widget->window coordinates for widgets that are not
4551 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4552 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4555 gtk_widget_queue_draw_area (GtkWidget *widget,
4562 cairo_region_t *region;
4564 g_return_if_fail (GTK_IS_WIDGET (widget));
4569 rect.height = height;
4571 region = cairo_region_create_rectangle (&rect);
4572 gtk_widget_queue_draw_region (widget, region);
4573 cairo_region_destroy (region);
4577 * gtk_widget_queue_draw:
4578 * @widget: a #GtkWidget
4580 * Equivalent to calling gtk_widget_queue_draw_area() for the
4581 * entire area of a widget.
4584 gtk_widget_queue_draw (GtkWidget *widget)
4588 g_return_if_fail (GTK_IS_WIDGET (widget));
4590 gtk_widget_get_allocation (widget, &rect);
4592 if (!gtk_widget_get_has_window (widget))
4593 gtk_widget_queue_draw_area (widget,
4594 rect.x, rect.y, rect.width, rect.height);
4596 gtk_widget_queue_draw_area (widget,
4597 0, 0, rect.width, rect.height);
4601 * gtk_widget_queue_resize:
4602 * @widget: a #GtkWidget
4604 * This function is only for use in widget implementations.
4605 * Flags a widget to have its size renegotiated; should
4606 * be called when a widget for some reason has a new size request.
4607 * For example, when you change the text in a #GtkLabel, #GtkLabel
4608 * queues a resize to ensure there's enough space for the new text.
4610 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4611 * from inside its implementation of the GtkWidgetClass::size_allocate
4612 * virtual method. Calls to gtk_widget_queue_resize() from inside
4613 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4616 gtk_widget_queue_resize (GtkWidget *widget)
4618 g_return_if_fail (GTK_IS_WIDGET (widget));
4620 if (gtk_widget_get_realized (widget))
4621 gtk_widget_queue_shallow_draw (widget);
4623 _gtk_size_group_queue_resize (widget, 0);
4627 * gtk_widget_queue_resize_no_redraw:
4628 * @widget: a #GtkWidget
4630 * This function works like gtk_widget_queue_resize(),
4631 * except that the widget is not invalidated.
4636 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4638 g_return_if_fail (GTK_IS_WIDGET (widget));
4640 _gtk_size_group_queue_resize (widget, 0);
4644 * gtk_widget_size_request:
4645 * @widget: a #GtkWidget
4646 * @requisition: (out): a #GtkRequisition to be filled in
4648 * This function is typically used when implementing a #GtkContainer
4649 * subclass. Obtains the preferred size of a widget. The container
4650 * uses this information to arrange its child widgets and decide what
4651 * size allocations to give them with gtk_widget_size_allocate().
4653 * You can also call this function from an application, with some
4654 * caveats. Most notably, getting a size request requires the widget
4655 * to be associated with a screen, because font information may be
4656 * needed. Multihead-aware applications should keep this in mind.
4658 * Also remember that the size request is not necessarily the size
4659 * a widget will actually be allocated.
4661 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4664 gtk_widget_size_request (GtkWidget *widget,
4665 GtkRequisition *requisition)
4667 g_return_if_fail (GTK_IS_WIDGET (widget));
4669 gtk_widget_get_preferred_size (widget, requisition, NULL);
4673 * gtk_widget_get_child_requisition:
4674 * @widget: a #GtkWidget
4675 * @requisition: (out): a #GtkRequisition to be filled in
4677 * This function is only for use in widget implementations. Obtains
4678 * @widget->requisition, unless someone has forced a particular
4679 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4680 * in which case it returns that geometry instead of the widget's
4683 * This function differs from gtk_widget_size_request() in that
4684 * it retrieves the last size request value from @widget->requisition,
4685 * while gtk_widget_size_request() actually calls the "size_request" method
4686 * on @widget to compute the size request and fill in @widget->requisition,
4687 * and only then returns @widget->requisition.
4689 * Because this function does not call the "size_request" method, it
4690 * can only be used when you know that @widget->requisition is
4691 * up-to-date, that is, gtk_widget_size_request() has been called
4692 * since the last time a resize was queued. In general, only container
4693 * implementations have this information; applications should use
4694 * gtk_widget_size_request().
4697 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4700 gtk_widget_get_child_requisition (GtkWidget *widget,
4701 GtkRequisition *requisition)
4703 gtk_widget_get_preferred_size (widget, requisition, NULL);
4707 invalidate_predicate (GdkWindow *window,
4712 gdk_window_get_user_data (window, &user_data);
4714 return (user_data == data);
4717 /* Invalidate @region in widget->window and all children
4718 * of widget->window owned by widget. @region is in the
4719 * same coordinates as widget->allocation and will be
4720 * modified by this call.
4723 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4724 cairo_region_t *region)
4726 GtkWidgetPrivate *priv = widget->priv;
4728 if (!gtk_widget_get_realized (widget))
4731 if (gtk_widget_get_has_window (widget) && priv->parent)
4735 gdk_window_get_position (priv->window, &x, &y);
4736 cairo_region_translate (region, -x, -y);
4739 gdk_window_invalidate_maybe_recurse (priv->window, region,
4740 invalidate_predicate, widget);
4744 * gtk_widget_queue_shallow_draw:
4745 * @widget: a #GtkWidget
4747 * Like gtk_widget_queue_draw(), but only windows owned
4748 * by @widget are invalidated.
4751 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4754 cairo_region_t *region;
4756 if (!gtk_widget_get_realized (widget))
4759 gtk_widget_get_allocation (widget, &rect);
4761 region = cairo_region_create_rectangle (&rect);
4762 gtk_widget_invalidate_widget_windows (widget, region);
4763 cairo_region_destroy (region);
4767 * gtk_widget_size_allocate:
4768 * @widget: a #GtkWidget
4769 * @allocation: position and size to be allocated to @widget
4771 * This function is only used by #GtkContainer subclasses, to assign a size
4772 * and position to their child widgets.
4774 * In this function, the allocation may be adjusted. It will be forced
4775 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4776 * method on the child will be used to adjust the allocation. Standard
4777 * adjustments include removing the widget's margins, and applying the
4778 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4781 gtk_widget_size_allocate (GtkWidget *widget,
4782 GtkAllocation *allocation)
4784 GtkWidgetPrivate *priv;
4785 GdkRectangle real_allocation;
4786 GdkRectangle old_allocation;
4787 GdkRectangle adjusted_allocation;
4788 gboolean alloc_needed;
4789 gboolean size_changed;
4790 gboolean position_changed;
4791 gint natural_width, natural_height, dummy;
4792 gint min_width, min_height;
4794 priv = widget->priv;
4796 g_return_if_fail (GTK_IS_WIDGET (widget));
4798 gtk_widget_push_verify_invariants (widget);
4800 #ifdef G_ENABLE_DEBUG
4801 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4812 parent = gtk_widget_get_parent (parent);
4815 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4816 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4817 2 * depth, " ", name,
4818 allocation->width, allocation->height);
4820 #endif /* G_ENABLE_DEBUG */
4822 alloc_needed = priv->alloc_needed;
4823 if (!priv->width_request_needed && !priv->height_request_needed)
4824 /* Preserve request/allocate ordering */
4825 priv->alloc_needed = FALSE;
4827 old_allocation = priv->allocation;
4828 real_allocation = *allocation;
4830 adjusted_allocation = real_allocation;
4831 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4833 /* Go ahead and request the height for allocated width, note that the internals
4834 * of get_height_for_width will internally limit the for_size to natural size
4835 * when aligning implicitly.
4837 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4838 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
4842 /* Go ahead and request the width for allocated height, note that the internals
4843 * of get_width_for_height will internally limit the for_size to natural size
4844 * when aligning implicitly.
4846 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4847 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
4850 #ifdef G_ENABLE_DEBUG
4851 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4853 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
4854 !GTK_IS_SCROLLABLE (widget))
4855 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
4856 "Allocation is %dx%d, but minimum required size is %dx%d.",
4857 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
4858 G_OBJECT_TYPE_NAME (widget), widget,
4859 real_allocation.width, real_allocation.height,
4860 min_width, min_height);
4863 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4864 * allocated sizes and possibly limit them to the natural sizes */
4865 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4866 GTK_ORIENTATION_HORIZONTAL,
4869 &adjusted_allocation.x,
4870 &adjusted_allocation.width);
4871 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4872 GTK_ORIENTATION_VERTICAL,
4875 &adjusted_allocation.y,
4876 &adjusted_allocation.height);
4878 if (adjusted_allocation.x < real_allocation.x ||
4879 adjusted_allocation.y < real_allocation.y ||
4880 (adjusted_allocation.x + adjusted_allocation.width) >
4881 (real_allocation.x + real_allocation.width) ||
4882 (adjusted_allocation.y + adjusted_allocation.height >
4883 real_allocation.y + real_allocation.height))
4885 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",
4886 G_OBJECT_TYPE_NAME (widget), widget,
4887 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4888 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4889 adjusted_allocation = real_allocation; /* veto it */
4893 real_allocation = adjusted_allocation;
4896 if (real_allocation.width < 0 || real_allocation.height < 0)
4898 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4899 real_allocation.width,
4900 real_allocation.height);
4903 real_allocation.width = MAX (real_allocation.width, 1);
4904 real_allocation.height = MAX (real_allocation.height, 1);
4906 size_changed = (old_allocation.width != real_allocation.width ||
4907 old_allocation.height != real_allocation.height);
4908 position_changed = (old_allocation.x != real_allocation.x ||
4909 old_allocation.y != real_allocation.y);
4911 if (!alloc_needed && !size_changed && !position_changed)
4914 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4916 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4917 priv->width_request_needed = FALSE;
4918 priv->height_request_needed = FALSE;
4919 priv->alloc_needed = FALSE;
4921 if (gtk_widget_get_mapped (widget))
4923 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4925 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4927 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4928 cairo_region_union_rectangle (invalidate, &old_allocation);
4930 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4931 cairo_region_destroy (invalidate);
4936 if (priv->redraw_on_alloc)
4938 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4940 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4941 cairo_region_union_rectangle (invalidate, &old_allocation);
4943 gtk_widget_invalidate_widget_windows (widget, invalidate);
4944 cairo_region_destroy (invalidate);
4949 if ((size_changed || position_changed) && priv->parent &&
4950 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4952 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4953 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4954 cairo_region_destroy (invalidate);
4958 gtk_widget_pop_verify_invariants (widget);
4962 * gtk_widget_common_ancestor:
4963 * @widget_a: a #GtkWidget
4964 * @widget_b: a #GtkWidget
4966 * Find the common ancestor of @widget_a and @widget_b that
4967 * is closest to the two widgets.
4969 * Return value: the closest common ancestor of @widget_a and
4970 * @widget_b or %NULL if @widget_a and @widget_b do not
4971 * share a common ancestor.
4974 gtk_widget_common_ancestor (GtkWidget *widget_a,
4975 GtkWidget *widget_b)
4977 GtkWidget *parent_a;
4978 GtkWidget *parent_b;
4982 parent_a = widget_a;
4983 while (parent_a->priv->parent)
4985 parent_a = parent_a->priv->parent;
4989 parent_b = widget_b;
4990 while (parent_b->priv->parent)
4992 parent_b = parent_b->priv->parent;
4996 if (parent_a != parent_b)
4999 while (depth_a > depth_b)
5001 widget_a = widget_a->priv->parent;
5005 while (depth_b > depth_a)
5007 widget_b = widget_b->priv->parent;
5011 while (widget_a != widget_b)
5013 widget_a = widget_a->priv->parent;
5014 widget_b = widget_b->priv->parent;
5021 * gtk_widget_translate_coordinates:
5022 * @src_widget: a #GtkWidget
5023 * @dest_widget: a #GtkWidget
5024 * @src_x: X position relative to @src_widget
5025 * @src_y: Y position relative to @src_widget
5026 * @dest_x: (out): location to store X position relative to @dest_widget
5027 * @dest_y: (out): location to store Y position relative to @dest_widget
5029 * Translate coordinates relative to @src_widget's allocation to coordinates
5030 * relative to @dest_widget's allocations. In order to perform this
5031 * operation, both widgets must be realized, and must share a common
5034 * Return value: %FALSE if either widget was not realized, or there
5035 * was no common ancestor. In this case, nothing is stored in
5036 * *@dest_x and *@dest_y. Otherwise %TRUE.
5039 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5040 GtkWidget *dest_widget,
5046 GtkWidgetPrivate *src_priv = src_widget->priv;
5047 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5048 GtkWidget *ancestor;
5050 GList *dest_list = NULL;
5052 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5053 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5055 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5056 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5059 /* Translate from allocation relative to window relative */
5060 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5063 gdk_window_get_position (src_priv->window, &wx, &wy);
5065 src_x -= wx - src_priv->allocation.x;
5066 src_y -= wy - src_priv->allocation.y;
5070 src_x += src_priv->allocation.x;
5071 src_y += src_priv->allocation.y;
5074 /* Translate to the common ancestor */
5075 window = src_priv->window;
5076 while (window != ancestor->priv->window)
5080 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5085 window = gdk_window_get_effective_parent (window);
5087 if (!window) /* Handle GtkHandleBox */
5092 window = dest_priv->window;
5093 while (window != ancestor->priv->window)
5095 dest_list = g_list_prepend (dest_list, window);
5097 window = gdk_window_get_effective_parent (window);
5099 if (!window) /* Handle GtkHandleBox */
5101 g_list_free (dest_list);
5110 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5115 dest_list = g_list_remove (dest_list, dest_list->data);
5118 /* Translate from window relative to allocation relative */
5119 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5122 gdk_window_get_position (dest_priv->window, &wx, &wy);
5124 src_x += wx - dest_priv->allocation.x;
5125 src_y += wy - dest_priv->allocation.y;
5129 src_x -= dest_priv->allocation.x;
5130 src_y -= dest_priv->allocation.y;
5142 gtk_widget_real_size_allocate (GtkWidget *widget,
5143 GtkAllocation *allocation)
5145 GtkWidgetPrivate *priv = widget->priv;
5147 priv->allocation = *allocation;
5149 if (gtk_widget_get_realized (widget) &&
5150 gtk_widget_get_has_window (widget))
5152 gdk_window_move_resize (priv->window,
5153 allocation->x, allocation->y,
5154 allocation->width, allocation->height);
5158 /* translate initial/final into start/end */
5160 effective_align (GtkAlign align,
5161 GtkTextDirection direction)
5165 case GTK_ALIGN_START:
5166 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5168 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5175 adjust_for_align (GtkAlign align,
5177 gint *allocated_pos,
5178 gint *allocated_size)
5182 case GTK_ALIGN_FILL:
5183 /* change nothing */
5185 case GTK_ALIGN_START:
5186 /* keep *allocated_pos where it is */
5187 *allocated_size = MIN (*allocated_size, *natural_size);
5190 if (*allocated_size > *natural_size)
5192 *allocated_pos += (*allocated_size - *natural_size);
5193 *allocated_size = *natural_size;
5196 case GTK_ALIGN_CENTER:
5197 if (*allocated_size > *natural_size)
5199 *allocated_pos += (*allocated_size - *natural_size) / 2;
5200 *allocated_size = MIN (*allocated_size, *natural_size);
5207 adjust_for_margin(gint start_margin,
5211 gint *allocated_pos,
5212 gint *allocated_size)
5214 *minimum_size -= (start_margin + end_margin);
5215 *natural_size -= (start_margin + end_margin);
5216 *allocated_pos += start_margin;
5217 *allocated_size -= (start_margin + end_margin);
5221 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5222 GtkOrientation orientation,
5225 gint *allocated_pos,
5226 gint *allocated_size)
5228 const GtkWidgetAuxInfo *aux_info;
5230 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5232 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5234 adjust_for_margin (aux_info->margin.left,
5235 aux_info->margin.right,
5236 minimum_size, natural_size,
5237 allocated_pos, allocated_size);
5238 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5239 natural_size, allocated_pos, allocated_size);
5243 adjust_for_margin (aux_info->margin.top,
5244 aux_info->margin.bottom,
5245 minimum_size, natural_size,
5246 allocated_pos, allocated_size);
5247 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5248 natural_size, allocated_pos, allocated_size);
5253 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5256 GtkWidgetPrivate *priv = widget->priv;
5258 /* widgets must be onscreen for accels to take effect */
5259 return gtk_widget_is_sensitive (widget) &&
5260 gtk_widget_is_drawable (widget) &&
5261 gdk_window_is_viewable (priv->window);
5265 * gtk_widget_can_activate_accel:
5266 * @widget: a #GtkWidget
5267 * @signal_id: the ID of a signal installed on @widget
5269 * Determines whether an accelerator that activates the signal
5270 * identified by @signal_id can currently be activated.
5271 * This is done by emitting the #GtkWidget::can-activate-accel
5272 * signal on @widget; if the signal isn't overridden by a
5273 * handler or in a derived widget, then the default check is
5274 * that the widget must be sensitive, and the widget and all
5275 * its ancestors mapped.
5277 * Return value: %TRUE if the accelerator can be activated.
5282 gtk_widget_can_activate_accel (GtkWidget *widget,
5285 gboolean can_activate = FALSE;
5286 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5287 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5288 return can_activate;
5297 closure_accel_activate (GClosure *closure,
5298 GValue *return_value,
5299 guint n_param_values,
5300 const GValue *param_values,
5301 gpointer invocation_hint,
5302 gpointer marshal_data)
5304 AccelClosure *aclosure = (AccelClosure*) closure;
5305 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5308 g_signal_emit (closure->data, aclosure->signal_id, 0);
5310 /* whether accelerator was handled */
5311 g_value_set_boolean (return_value, can_activate);
5315 closures_destroy (gpointer data)
5317 GSList *slist, *closures = data;
5319 for (slist = closures; slist; slist = slist->next)
5321 g_closure_invalidate (slist->data);
5322 g_closure_unref (slist->data);
5324 g_slist_free (closures);
5328 widget_new_accel_closure (GtkWidget *widget,
5331 AccelClosure *aclosure;
5332 GClosure *closure = NULL;
5333 GSList *slist, *closures;
5335 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5336 for (slist = closures; slist; slist = slist->next)
5337 if (!gtk_accel_group_from_accel_closure (slist->data))
5339 /* reuse this closure */
5340 closure = slist->data;
5345 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5346 closures = g_slist_prepend (closures, g_closure_ref (closure));
5347 g_closure_sink (closure);
5348 g_closure_set_marshal (closure, closure_accel_activate);
5350 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5352 aclosure = (AccelClosure*) closure;
5353 g_assert (closure->data == widget);
5354 g_assert (closure->marshal == closure_accel_activate);
5355 aclosure->signal_id = signal_id;
5361 * gtk_widget_add_accelerator:
5362 * @widget: widget to install an accelerator on
5363 * @accel_signal: widget signal to emit on accelerator activation
5364 * @accel_group: accel group for this widget, added to its toplevel
5365 * @accel_key: GDK keyval of the accelerator
5366 * @accel_mods: modifier key combination of the accelerator
5367 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5369 * Installs an accelerator for this @widget in @accel_group that causes
5370 * @accel_signal to be emitted if the accelerator is activated.
5371 * The @accel_group needs to be added to the widget's toplevel via
5372 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5373 * Accelerators added through this function are not user changeable during
5374 * runtime. If you want to support accelerators that can be changed by the
5375 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5376 * gtk_menu_item_set_accel_path() instead.
5379 gtk_widget_add_accelerator (GtkWidget *widget,
5380 const gchar *accel_signal,
5381 GtkAccelGroup *accel_group,
5383 GdkModifierType accel_mods,
5384 GtkAccelFlags accel_flags)
5389 g_return_if_fail (GTK_IS_WIDGET (widget));
5390 g_return_if_fail (accel_signal != NULL);
5391 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5393 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5394 if (!query.signal_id ||
5395 !(query.signal_flags & G_SIGNAL_ACTION) ||
5396 query.return_type != G_TYPE_NONE ||
5399 /* hmm, should be elaborate enough */
5400 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5401 G_OBJECT_TYPE_NAME (widget), accel_signal);
5405 closure = widget_new_accel_closure (widget, query.signal_id);
5407 g_object_ref (widget);
5409 /* install the accelerator. since we don't map this onto an accel_path,
5410 * the accelerator will automatically be locked.
5412 gtk_accel_group_connect (accel_group,
5415 accel_flags | GTK_ACCEL_LOCKED,
5418 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5420 g_object_unref (widget);
5424 * gtk_widget_remove_accelerator:
5425 * @widget: widget to install an accelerator on
5426 * @accel_group: accel group for this widget
5427 * @accel_key: GDK keyval of the accelerator
5428 * @accel_mods: modifier key combination of the accelerator
5430 * Removes an accelerator from @widget, previously installed with
5431 * gtk_widget_add_accelerator().
5433 * Returns: whether an accelerator was installed and could be removed
5436 gtk_widget_remove_accelerator (GtkWidget *widget,
5437 GtkAccelGroup *accel_group,
5439 GdkModifierType accel_mods)
5441 GtkAccelGroupEntry *ag_entry;
5442 GList *slist, *clist;
5445 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5446 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5448 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5449 clist = gtk_widget_list_accel_closures (widget);
5450 for (slist = clist; slist; slist = slist->next)
5454 for (i = 0; i < n; i++)
5455 if (slist->data == (gpointer) ag_entry[i].closure)
5457 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5459 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5461 g_list_free (clist);
5466 g_list_free (clist);
5468 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5469 accel_key, accel_mods, accel_group,
5470 G_OBJECT_TYPE_NAME (widget), widget);
5476 * gtk_widget_list_accel_closures:
5477 * @widget: widget to list accelerator closures for
5479 * Lists the closures used by @widget for accelerator group connections
5480 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5481 * The closures can be used to monitor accelerator changes on @widget,
5482 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5483 * #GtkAccelGroup of a closure which can be found out with
5484 * gtk_accel_group_from_accel_closure().
5486 * Return value: (transfer container) (element-type GClosure):
5487 * a newly allocated #GList of closures
5490 gtk_widget_list_accel_closures (GtkWidget *widget)
5493 GList *clist = NULL;
5495 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5497 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5498 if (gtk_accel_group_from_accel_closure (slist->data))
5499 clist = g_list_prepend (clist, slist->data);
5505 GtkAccelGroup *accel_group;
5510 destroy_accel_path (gpointer data)
5512 AccelPath *apath = data;
5514 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5516 /* closures_destroy takes care of unrefing the closure */
5517 g_object_unref (apath->accel_group);
5519 g_slice_free (AccelPath, apath);
5524 * gtk_widget_set_accel_path:
5525 * @widget: a #GtkWidget
5526 * @accel_path: (allow-none): path used to look up the accelerator
5527 * @accel_group: (allow-none): a #GtkAccelGroup.
5529 * Given an accelerator group, @accel_group, and an accelerator path,
5530 * @accel_path, sets up an accelerator in @accel_group so whenever the
5531 * key binding that is defined for @accel_path is pressed, @widget
5532 * will be activated. This removes any accelerators (for any
5533 * accelerator group) installed by previous calls to
5534 * gtk_widget_set_accel_path(). Associating accelerators with
5535 * paths allows them to be modified by the user and the modifications
5536 * to be saved for future use. (See gtk_accel_map_save().)
5538 * This function is a low level function that would most likely
5539 * be used by a menu creation system like #GtkUIManager. If you
5540 * use #GtkUIManager, setting up accelerator paths will be done
5543 * Even when you you aren't using #GtkUIManager, if you only want to
5544 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5545 * provides a somewhat more convenient interface.
5547 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5548 * pass a static string, you can save some memory by interning it first with
5549 * g_intern_static_string().
5552 gtk_widget_set_accel_path (GtkWidget *widget,
5553 const gchar *accel_path,
5554 GtkAccelGroup *accel_group)
5558 g_return_if_fail (GTK_IS_WIDGET (widget));
5559 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5563 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5564 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5566 gtk_accel_map_add_entry (accel_path, 0, 0);
5567 apath = g_slice_new (AccelPath);
5568 apath->accel_group = g_object_ref (accel_group);
5569 apath->path_quark = g_quark_from_string (accel_path);
5570 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5575 /* also removes possible old settings */
5576 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5579 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5581 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5585 _gtk_widget_get_accel_path (GtkWidget *widget,
5590 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5592 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5594 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5595 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5599 * gtk_widget_mnemonic_activate:
5600 * @widget: a #GtkWidget
5601 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5603 * Emits the #GtkWidget::mnemonic-activate signal.
5605 * The default handler for this signal activates the @widget if
5606 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5609 * Returns: %TRUE if the signal has been handled
5612 gtk_widget_mnemonic_activate (GtkWidget *widget,
5613 gboolean group_cycling)
5617 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5619 group_cycling = group_cycling != FALSE;
5620 if (!gtk_widget_is_sensitive (widget))
5623 g_signal_emit (widget,
5624 widget_signals[MNEMONIC_ACTIVATE],
5632 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5633 gboolean group_cycling)
5635 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5636 gtk_widget_activate (widget);
5637 else if (gtk_widget_get_can_focus (widget))
5638 gtk_widget_grab_focus (widget);
5641 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5642 G_OBJECT_TYPE_NAME (widget));
5643 gtk_widget_error_bell (widget);
5648 static const cairo_user_data_key_t event_key;
5651 _gtk_cairo_get_event (cairo_t *cr)
5653 g_return_val_if_fail (cr != NULL, NULL);
5655 return cairo_get_user_data (cr, &event_key);
5659 gtk_cairo_set_event (cairo_t *cr,
5660 GdkEventExpose *event)
5662 cairo_set_user_data (cr, &event_key, event, NULL);
5666 * gtk_cairo_should_draw_window:
5667 * @cr: a cairo context
5668 * @window: the window to check. @window may not be an input-only
5671 * This function is supposed to be called in #GtkWidget::draw
5672 * implementations for widgets that support multiple windows.
5673 * @cr must be untransformed from invoking of the draw function.
5674 * This function will return %TRUE if the contents of the given
5675 * @window are supposed to be drawn and %FALSE otherwise. Note
5676 * that when the drawing was not initiated by the windowing
5677 * system this function will return %TRUE for all windows, so
5678 * you need to draw the bottommost window first. Also, do not
5679 * use "else if" statements to check which window should be drawn.
5681 * Returns: %TRUE if @window should be drawn
5686 gtk_cairo_should_draw_window (cairo_t *cr,
5689 GdkEventExpose *event;
5691 g_return_val_if_fail (cr != NULL, FALSE);
5692 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5694 event = _gtk_cairo_get_event (cr);
5696 return event == NULL ||
5697 event->window == window;
5701 gtk_widget_get_clip_draw (GtkWidget *widget)
5703 /* labels are not clipped, because clipping them would cause
5704 * mnemonics to not appear on characters that go beyond the
5706 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
5708 if (GTK_IS_LABEL (widget))
5714 /* code shared by gtk_container_propagate_draw() and
5718 _gtk_widget_draw_internal (GtkWidget *widget,
5720 gboolean clip_to_size)
5722 if (!gtk_widget_is_drawable (widget))
5725 clip_to_size &= gtk_widget_get_clip_draw (widget);
5729 cairo_rectangle (cr,
5731 widget->priv->allocation.width,
5732 widget->priv->allocation.height);
5736 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5740 g_signal_emit (widget, widget_signals[DRAW],
5744 if (cairo_status (cr) &&
5745 _gtk_cairo_get_event (cr))
5747 /* We check the event so we only warn about internal GTK calls.
5748 * Errors might come from PDF streams having write failures and
5749 * we don't want to spam stderr in that case.
5750 * We do want to catch errors from
5752 g_warning ("drawing failure for widget `%s': %s",
5753 G_OBJECT_TYPE_NAME (widget),
5754 cairo_status_to_string (cairo_status (cr)));
5761 * @widget: the widget to draw. It must be drawable (see
5762 * gtk_widget_is_drawable()) and a size must have been allocated.
5763 * @cr: a cairo context to draw to
5765 * Draws @widget to @cr. The top left corner of the widget will be
5766 * drawn to the currently set origin point of @cr.
5768 * You should pass a cairo context as @cr argument that is in an
5769 * original state. Otherwise the resulting drawing is undefined. For
5770 * example changing the operator using cairo_set_operator() or the
5771 * line width using cairo_set_line_width() might have unwanted side
5773 * You may however change the context's transform matrix - like with
5774 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5775 * region with cairo_clip() prior to calling this function. Also, it
5776 * is fine to modify the context with cairo_save() and
5777 * cairo_push_group() prior to calling this function.
5779 * <note><para>Special purpose widgets may contain special code for
5780 * rendering to the screen and might appear differently on screen
5781 * and when rendered using gtk_widget_draw().</para></note>
5786 gtk_widget_draw (GtkWidget *widget,
5789 GdkEventExpose *tmp_event;
5791 g_return_if_fail (GTK_IS_WIDGET (widget));
5792 g_return_if_fail (!widget->priv->alloc_needed);
5793 g_return_if_fail (cr != NULL);
5796 /* We have to reset the event here so that draw functions can call
5797 * gtk_widget_draw() on random other widgets and get the desired
5798 * effect: Drawing all contents, not just the current window.
5800 tmp_event = _gtk_cairo_get_event (cr);
5801 gtk_cairo_set_event (cr, NULL);
5803 _gtk_widget_draw_internal (widget, cr, TRUE);
5805 gtk_cairo_set_event (cr, tmp_event);
5810 gtk_widget_real_key_press_event (GtkWidget *widget,
5813 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5817 gtk_widget_real_key_release_event (GtkWidget *widget,
5820 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5824 gtk_widget_real_focus_in_event (GtkWidget *widget,
5825 GdkEventFocus *event)
5827 gtk_widget_queue_shallow_draw (widget);
5833 gtk_widget_real_focus_out_event (GtkWidget *widget,
5834 GdkEventFocus *event)
5836 gtk_widget_queue_shallow_draw (widget);
5842 gtk_widget_real_touch_event (GtkWidget *widget,
5843 GdkEventTouch *event)
5846 gboolean return_val;
5849 if (!event->emulating_pointer)
5852 if (event->type == GDK_TOUCH_BEGIN ||
5853 event->type == GDK_TOUCH_END)
5857 if (event->type == GDK_TOUCH_BEGIN)
5859 type = GDK_BUTTON_PRESS;
5860 signum = BUTTON_PRESS_EVENT;
5864 type = GDK_BUTTON_RELEASE;
5865 signum = BUTTON_RELEASE_EVENT;
5867 bevent = gdk_event_new (type);
5868 bevent->any.window = g_object_ref (event->window);
5869 bevent->any.send_event = FALSE;
5870 bevent->button.time = event->time;
5871 bevent->button.state = event->state;
5872 bevent->button.button = 1;
5873 bevent->button.x_root = event->x_root;
5874 bevent->button.y_root = event->y_root;
5875 bevent->button.x = event->x;
5876 bevent->button.y = event->y;
5877 bevent->button.device = event->device;
5878 bevent->button.axes = g_memdup (event->axes,
5879 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
5880 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
5882 else if (event->type == GDK_TOUCH_UPDATE)
5884 signum = MOTION_NOTIFY_EVENT;
5885 bevent = gdk_event_new (GDK_MOTION_NOTIFY);
5886 bevent->any.window = g_object_ref (event->window);
5887 bevent->any.send_event = FALSE;
5888 bevent->motion.time = event->time;
5889 bevent->motion.state = event->state;
5890 bevent->motion.x_root = event->x_root;
5891 bevent->motion.y_root = event->y_root;
5892 bevent->motion.x = event->x;
5893 bevent->motion.y = event->y;
5894 bevent->motion.device = event->device;
5895 bevent->motion.is_hint = FALSE;
5896 bevent->motion.axes = g_memdup (event->axes,
5897 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
5898 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
5903 g_signal_emit (widget, widget_signals[signum], 0, bevent, &return_val);
5905 gdk_event_free (bevent);
5911 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5912 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5916 * @widget: a #GtkWidget
5917 * @event: a #GdkEvent
5919 * Rarely-used function. This function is used to emit
5920 * the event signals on a widget (those signals should never
5921 * be emitted without using this function to do so).
5922 * If you want to synthesize an event though, don't use this function;
5923 * instead, use gtk_main_do_event() so the event will behave as if
5924 * it were in the event queue. Don't synthesize expose events; instead,
5925 * use gdk_window_invalidate_rect() to invalidate a region of the
5928 * Return value: return from the event signal emission (%TRUE if
5929 * the event was handled)
5932 gtk_widget_event (GtkWidget *widget,
5935 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5936 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5938 if (event->type == GDK_EXPOSE)
5940 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5941 "the same effect, call gdk_window_invalidate_rect/region(), "
5942 "followed by gdk_window_process_updates().");
5946 return gtk_widget_event_internal (widget, event);
5950 _gtk_widget_set_captured_event_handler (GtkWidget *widget,
5951 GtkCapturedEventHandler callback)
5953 g_object_set_data (G_OBJECT (widget), "captured-event-handler", callback);
5957 _gtk_widget_captured_event (GtkWidget *widget,
5960 gboolean return_val = FALSE;
5961 GtkCapturedEventHandler handler;
5963 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5964 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5966 if (event->type == GDK_EXPOSE)
5968 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5969 "the same effect, call gdk_window_invalidate_rect/region(), "
5970 "followed by gdk_window_process_updates().");
5974 if (!event_window_is_still_viewable (event))
5977 handler = g_object_get_data (G_OBJECT (widget), "captured-event-handler");
5981 g_object_ref (widget);
5983 return_val = handler (widget, event);
5984 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5986 /* The widget that was originally to receive the event
5987 * handles motion hints, but the capturing widget might
5988 * not, so ensure we get further motion events.
5991 event->type == GDK_MOTION_NOTIFY &&
5992 event->motion.is_hint &&
5993 (gdk_window_get_events (event->any.window) &
5994 GDK_POINTER_MOTION_HINT_MASK) != 0)
5995 gdk_event_request_motions (&event->motion);
5997 g_object_unref (widget);
6002 /* Returns TRUE if a translation should be done */
6004 _gtk_widget_get_translation_to_window (GtkWidget *widget,
6009 GdkWindow *w, *widget_window;
6011 if (!gtk_widget_get_has_window (widget))
6013 *x = -widget->priv->allocation.x;
6014 *y = -widget->priv->allocation.y;
6022 widget_window = gtk_widget_get_window (widget);
6024 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
6027 gdk_window_get_position (w, &wx, &wy);
6044 * gtk_cairo_transform_to_window:
6045 * @cr: the cairo context to transform
6046 * @widget: the widget the context is currently centered for
6047 * @window: the window to transform the context to
6049 * Transforms the given cairo context @cr that from @widget-relative
6050 * coordinates to @window-relative coordinates.
6051 * If the @widget's window is not an ancestor of @window, no
6052 * modification will be applied.
6054 * This is the inverse to the transformation GTK applies when
6055 * preparing an expose event to be emitted with the #GtkWidget::draw
6056 * signal. It is intended to help porting multiwindow widgets from
6057 * GTK+ 2 to the rendering architecture of GTK+ 3.
6062 gtk_cairo_transform_to_window (cairo_t *cr,
6068 g_return_if_fail (cr != NULL);
6069 g_return_if_fail (GTK_IS_WIDGET (widget));
6070 g_return_if_fail (GDK_IS_WINDOW (window));
6072 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
6073 cairo_translate (cr, x, y);
6077 * gtk_widget_send_expose:
6078 * @widget: a #GtkWidget
6079 * @event: a expose #GdkEvent
6081 * Very rarely-used function. This function is used to emit
6082 * an expose event on a widget. This function is not normally used
6083 * directly. The only time it is used is when propagating an expose
6084 * event to a child %NO_WINDOW widget, and that is normally done
6085 * using gtk_container_propagate_draw().
6087 * If you want to force an area of a window to be redrawn,
6088 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
6089 * To cause the redraw to be done immediately, follow that call
6090 * with a call to gdk_window_process_updates().
6092 * Return value: return from the event signal emission (%TRUE if
6093 * the event was handled)
6096 gtk_widget_send_expose (GtkWidget *widget,
6099 gboolean result = FALSE;
6104 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6105 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
6106 g_return_val_if_fail (event != NULL, TRUE);
6107 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
6109 cr = gdk_cairo_create (event->expose.window);
6110 gtk_cairo_set_event (cr, &event->expose);
6112 gdk_cairo_region (cr, event->expose.region);
6115 do_clip = _gtk_widget_get_translation_to_window (widget,
6116 event->expose.window,
6118 cairo_translate (cr, -x, -y);
6120 _gtk_widget_draw_internal (widget, cr, do_clip);
6122 /* unset here, so if someone keeps a reference to cr we
6123 * don't leak the window. */
6124 gtk_cairo_set_event (cr, NULL);
6131 event_window_is_still_viewable (GdkEvent *event)
6133 /* Check that we think the event's window is viewable before
6134 * delivering the event, to prevent suprises. We do this here
6135 * at the last moment, since the event may have been queued
6136 * up behind other events, held over a recursive main loop, etc.
6138 switch (event->type)
6141 case GDK_MOTION_NOTIFY:
6142 case GDK_BUTTON_PRESS:
6143 case GDK_2BUTTON_PRESS:
6144 case GDK_3BUTTON_PRESS:
6146 case GDK_ENTER_NOTIFY:
6147 case GDK_PROXIMITY_IN:
6149 return event->any.window && gdk_window_is_viewable (event->any.window);
6152 /* The following events are the second half of paired events;
6153 * we always deliver them to deal with widgets that clean up
6154 * on the second half.
6156 case GDK_BUTTON_RELEASE:
6157 case GDK_KEY_RELEASE:
6158 case GDK_LEAVE_NOTIFY:
6159 case GDK_PROXIMITY_OUT:
6163 /* Remaining events would make sense on an not-viewable window,
6164 * or don't have an associated window.
6171 gtk_widget_event_internal (GtkWidget *widget,
6174 gboolean return_val = FALSE;
6176 /* We check only once for is-still-visible; if someone
6177 * hides the window in on of the signals on the widget,
6178 * they are responsible for returning TRUE to terminate
6181 if (!event_window_is_still_viewable (event))
6184 g_object_ref (widget);
6186 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6187 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6192 switch (event->type)
6198 case GDK_BUTTON_PRESS:
6199 case GDK_2BUTTON_PRESS:
6200 case GDK_3BUTTON_PRESS:
6201 signal_num = BUTTON_PRESS_EVENT;
6203 case GDK_TOUCH_BEGIN:
6204 case GDK_TOUCH_UPDATE:
6206 case GDK_TOUCH_CANCEL:
6207 signal_num = TOUCH_EVENT;
6210 signal_num = SCROLL_EVENT;
6212 case GDK_BUTTON_RELEASE:
6213 signal_num = BUTTON_RELEASE_EVENT;
6215 case GDK_MOTION_NOTIFY:
6216 signal_num = MOTION_NOTIFY_EVENT;
6219 signal_num = DELETE_EVENT;
6222 signal_num = DESTROY_EVENT;
6223 _gtk_tooltip_hide (widget);
6226 signal_num = KEY_PRESS_EVENT;
6228 case GDK_KEY_RELEASE:
6229 signal_num = KEY_RELEASE_EVENT;
6231 case GDK_ENTER_NOTIFY:
6232 signal_num = ENTER_NOTIFY_EVENT;
6234 case GDK_LEAVE_NOTIFY:
6235 signal_num = LEAVE_NOTIFY_EVENT;
6237 case GDK_FOCUS_CHANGE:
6238 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6239 if (event->focus_change.in)
6240 _gtk_tooltip_focus_in (widget);
6242 _gtk_tooltip_focus_out (widget);
6245 signal_num = CONFIGURE_EVENT;
6248 signal_num = MAP_EVENT;
6251 signal_num = UNMAP_EVENT;
6253 case GDK_WINDOW_STATE:
6254 signal_num = WINDOW_STATE_EVENT;
6256 case GDK_PROPERTY_NOTIFY:
6257 signal_num = PROPERTY_NOTIFY_EVENT;
6259 case GDK_SELECTION_CLEAR:
6260 signal_num = SELECTION_CLEAR_EVENT;
6262 case GDK_SELECTION_REQUEST:
6263 signal_num = SELECTION_REQUEST_EVENT;
6265 case GDK_SELECTION_NOTIFY:
6266 signal_num = SELECTION_NOTIFY_EVENT;
6268 case GDK_PROXIMITY_IN:
6269 signal_num = PROXIMITY_IN_EVENT;
6271 case GDK_PROXIMITY_OUT:
6272 signal_num = PROXIMITY_OUT_EVENT;
6274 case GDK_VISIBILITY_NOTIFY:
6275 signal_num = VISIBILITY_NOTIFY_EVENT;
6277 case GDK_GRAB_BROKEN:
6278 signal_num = GRAB_BROKEN_EVENT;
6281 signal_num = DAMAGE_EVENT;
6284 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6288 if (signal_num != -1)
6289 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6291 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6292 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6296 g_object_unref (widget);
6302 * gtk_widget_activate:
6303 * @widget: a #GtkWidget that's activatable
6305 * For widgets that can be "activated" (buttons, menu items, etc.)
6306 * this function activates them. Activation is what happens when you
6307 * press Enter on a widget during key navigation. If @widget isn't
6308 * activatable, the function returns %FALSE.
6310 * Return value: %TRUE if the widget was activatable
6313 gtk_widget_activate (GtkWidget *widget)
6315 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6317 if (WIDGET_CLASS (widget)->activate_signal)
6319 /* FIXME: we should eventually check the signals signature here */
6320 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6329 gtk_widget_reparent_subwindows (GtkWidget *widget,
6330 GdkWindow *new_window)
6332 GtkWidgetPrivate *priv = widget->priv;
6334 if (!gtk_widget_get_has_window (widget))
6336 GList *children = gdk_window_get_children (priv->window);
6339 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6341 GdkWindow *window = tmp_list->data;
6344 gdk_window_get_user_data (window, &child);
6345 while (child && child != widget)
6346 child = ((GtkWidget*) child)->priv->parent;
6349 gdk_window_reparent (window, new_window, 0, 0);
6352 g_list_free (children);
6357 GList *tmp_list, *children;
6359 parent = gdk_window_get_parent (priv->window);
6362 gdk_window_reparent (priv->window, new_window, 0, 0);
6365 children = gdk_window_get_children (parent);
6367 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6369 GdkWindow *window = tmp_list->data;
6372 gdk_window_get_user_data (window, &child);
6374 if (child == widget)
6375 gdk_window_reparent (window, new_window, 0, 0);
6378 g_list_free (children);
6384 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6385 gpointer client_data)
6387 GtkWidgetPrivate *priv = widget->priv;
6389 g_assert (client_data != NULL);
6391 if (!gtk_widget_get_has_window (widget))
6394 g_object_unref (priv->window);
6395 priv->window = (GdkWindow*) client_data;
6397 g_object_ref (priv->window);
6399 if (GTK_IS_CONTAINER (widget))
6400 gtk_container_forall (GTK_CONTAINER (widget),
6401 gtk_widget_reparent_fixup_child,
6407 * gtk_widget_reparent:
6408 * @widget: a #GtkWidget
6409 * @new_parent: a #GtkContainer to move the widget into
6411 * Moves a widget from one #GtkContainer to another, handling reference
6412 * count issues to avoid destroying the widget.
6415 gtk_widget_reparent (GtkWidget *widget,
6416 GtkWidget *new_parent)
6418 GtkWidgetPrivate *priv;
6420 g_return_if_fail (GTK_IS_WIDGET (widget));
6421 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6422 priv = widget->priv;
6423 g_return_if_fail (priv->parent != NULL);
6425 if (priv->parent != new_parent)
6427 /* First try to see if we can get away without unrealizing
6428 * the widget as we reparent it. if so we set a flag so
6429 * that gtk_widget_unparent doesn't unrealize widget
6431 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6432 priv->in_reparent = TRUE;
6434 g_object_ref (widget);
6435 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6436 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6437 g_object_unref (widget);
6439 if (priv->in_reparent)
6441 priv->in_reparent = FALSE;
6443 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6444 gtk_widget_reparent_fixup_child (widget,
6445 gtk_widget_get_parent_window (widget));
6448 g_object_notify (G_OBJECT (widget), "parent");
6453 * gtk_widget_intersect:
6454 * @widget: a #GtkWidget
6455 * @area: a rectangle
6456 * @intersection: rectangle to store intersection of @widget and @area
6458 * Computes the intersection of a @widget's area and @area, storing
6459 * the intersection in @intersection, and returns %TRUE if there was
6460 * an intersection. @intersection may be %NULL if you're only
6461 * interested in whether there was an intersection.
6463 * Return value: %TRUE if there was an intersection
6466 gtk_widget_intersect (GtkWidget *widget,
6467 const GdkRectangle *area,
6468 GdkRectangle *intersection)
6470 GtkWidgetPrivate *priv;
6475 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6476 g_return_val_if_fail (area != NULL, FALSE);
6478 priv = widget->priv;
6481 dest = intersection;
6485 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6487 if (return_val && intersection && gtk_widget_get_has_window (widget))
6489 intersection->x -= priv->allocation.x;
6490 intersection->y -= priv->allocation.y;
6497 * gtk_widget_region_intersect:
6498 * @widget: a #GtkWidget
6499 * @region: a #cairo_region_t, in the same coordinate system as
6500 * @widget->allocation. That is, relative to @widget->window
6501 * for %NO_WINDOW widgets; relative to the parent window
6502 * of @widget->window for widgets with their own window.
6504 * Computes the intersection of a @widget's area and @region, returning
6505 * the intersection. The result may be empty, use cairo_region_is_empty() to
6508 * Returns: A newly allocated region holding the intersection of @widget
6509 * and @region. The coordinates of the return value are relative to
6510 * @widget->window for %NO_WINDOW widgets, and relative to the parent
6511 * window of @widget->window for widgets with their own window.
6514 gtk_widget_region_intersect (GtkWidget *widget,
6515 const cairo_region_t *region)
6518 cairo_region_t *dest;
6520 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6521 g_return_val_if_fail (region != NULL, NULL);
6523 gtk_widget_get_allocation (widget, &rect);
6525 dest = cairo_region_create_rectangle (&rect);
6527 cairo_region_intersect (dest, region);
6533 * _gtk_widget_grab_notify:
6534 * @widget: a #GtkWidget
6535 * @was_grabbed: whether a grab is now in effect
6537 * Emits the #GtkWidget::grab-notify signal on @widget.
6542 _gtk_widget_grab_notify (GtkWidget *widget,
6543 gboolean was_grabbed)
6545 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6549 * gtk_widget_grab_focus:
6550 * @widget: a #GtkWidget
6552 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6553 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6554 * something like #GtkFrame won't work.
6556 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6557 * gtk_widget_set_can_focus() to modify that flag.
6559 * The widget also needs to be realized and mapped. This is indicated by the
6560 * related signals. Grabbing the focus immediately after creating the widget
6561 * will likely fail and cause critical warnings.
6564 gtk_widget_grab_focus (GtkWidget *widget)
6566 g_return_if_fail (GTK_IS_WIDGET (widget));
6568 if (!gtk_widget_is_sensitive (widget))
6571 g_object_ref (widget);
6572 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6573 g_object_notify (G_OBJECT (widget), "has-focus");
6574 g_object_unref (widget);
6578 reset_focus_recurse (GtkWidget *widget,
6581 if (GTK_IS_CONTAINER (widget))
6583 GtkContainer *container;
6585 container = GTK_CONTAINER (widget);
6586 gtk_container_set_focus_child (container, NULL);
6588 gtk_container_foreach (container,
6589 reset_focus_recurse,
6595 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6597 if (gtk_widget_get_can_focus (focus_widget))
6599 GtkWidget *toplevel;
6602 /* clear the current focus setting, break if the current widget
6603 * is the focus widget's parent, since containers above that will
6604 * be set by the next loop.
6606 toplevel = gtk_widget_get_toplevel (focus_widget);
6607 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6609 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6611 if (widget == focus_widget)
6613 /* We call _gtk_window_internal_set_focus() here so that the
6614 * toplevel window can request the focus if necessary.
6615 * This is needed when the toplevel is a GtkPlug
6617 if (!gtk_widget_has_focus (widget))
6618 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6625 GtkWidget *common_ancestor = gtk_widget_common_ancestor (widget, focus_widget);
6627 if (widget != common_ancestor)
6629 while (widget->priv->parent && widget->priv->parent != common_ancestor)
6631 widget = widget->priv->parent;
6632 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6637 else if (toplevel != focus_widget)
6639 /* gtk_widget_grab_focus() operates on a tree without window...
6640 * actually, this is very questionable behaviour.
6643 gtk_container_foreach (GTK_CONTAINER (toplevel),
6644 reset_focus_recurse,
6648 /* now propagate the new focus up the widget tree and finally
6649 * set it on the window
6651 widget = focus_widget;
6652 while (widget->priv->parent)
6654 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6655 widget = widget->priv->parent;
6657 if (GTK_IS_WINDOW (widget))
6658 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6663 gtk_widget_real_query_tooltip (GtkWidget *widget,
6666 gboolean keyboard_tip,
6667 GtkTooltip *tooltip)
6669 gchar *tooltip_markup;
6670 gboolean has_tooltip;
6672 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6673 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6675 if (has_tooltip && tooltip_markup)
6677 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6685 gtk_widget_real_state_flags_changed (GtkWidget *widget,
6686 GtkStateFlags old_state)
6688 gtk_widget_update_pango_context (widget);
6692 gtk_widget_real_style_updated (GtkWidget *widget)
6694 GtkWidgetPrivate *priv = widget->priv;
6696 gtk_widget_update_pango_context (widget);
6698 if (priv->style != NULL &&
6699 priv->style != gtk_widget_get_default_style ())
6701 /* Trigger ::style-set for old
6702 * widgets not listening to this
6704 g_signal_emit (widget,
6705 widget_signals[STYLE_SET],
6707 widget->priv->style);
6710 if (widget->priv->context)
6712 if (gtk_widget_get_realized (widget) &&
6713 gtk_widget_get_has_window (widget) &&
6714 !gtk_widget_get_app_paintable (widget))
6715 gtk_style_context_set_background (widget->priv->context,
6716 widget->priv->window);
6719 if (widget->priv->anchored)
6720 gtk_widget_queue_resize (widget);
6724 gtk_widget_real_show_help (GtkWidget *widget,
6725 GtkWidgetHelpType help_type)
6727 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6729 _gtk_tooltip_toggle_keyboard_mode (widget);
6738 gtk_widget_real_focus (GtkWidget *widget,
6739 GtkDirectionType direction)
6741 if (!gtk_widget_get_can_focus (widget))
6744 if (!gtk_widget_is_focus (widget))
6746 gtk_widget_grab_focus (widget);
6754 gtk_widget_real_move_focus (GtkWidget *widget,
6755 GtkDirectionType direction)
6757 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6759 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6761 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6767 gtk_widget_real_keynav_failed (GtkWidget *widget,
6768 GtkDirectionType direction)
6770 gboolean cursor_only;
6774 case GTK_DIR_TAB_FORWARD:
6775 case GTK_DIR_TAB_BACKWARD:
6782 g_object_get (gtk_widget_get_settings (widget),
6783 "gtk-keynav-cursor-only", &cursor_only,
6790 gtk_widget_error_bell (widget);
6796 * gtk_widget_set_can_focus:
6797 * @widget: a #GtkWidget
6798 * @can_focus: whether or not @widget can own the input focus.
6800 * Specifies whether @widget can own the input focus. See
6801 * gtk_widget_grab_focus() for actually setting the input focus on a
6807 gtk_widget_set_can_focus (GtkWidget *widget,
6810 g_return_if_fail (GTK_IS_WIDGET (widget));
6812 if (widget->priv->can_focus != can_focus)
6814 widget->priv->can_focus = can_focus;
6816 gtk_widget_queue_resize (widget);
6817 g_object_notify (G_OBJECT (widget), "can-focus");
6822 * gtk_widget_get_can_focus:
6823 * @widget: a #GtkWidget
6825 * Determines whether @widget can own the input focus. See
6826 * gtk_widget_set_can_focus().
6828 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6833 gtk_widget_get_can_focus (GtkWidget *widget)
6835 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6837 return widget->priv->can_focus;
6841 * gtk_widget_has_focus:
6842 * @widget: a #GtkWidget
6844 * Determines if the widget has the global input focus. See
6845 * gtk_widget_is_focus() for the difference between having the global
6846 * input focus, and only having the focus within a toplevel.
6848 * Return value: %TRUE if the widget has the global input focus.
6853 gtk_widget_has_focus (GtkWidget *widget)
6855 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6857 return widget->priv->has_focus;
6861 * gtk_widget_has_visible_focus:
6862 * @widget: a #GtkWidget
6864 * Determines if the widget should show a visible indication that
6865 * it has the global input focus. This is a convenience function for
6866 * use in ::draw handlers that takes into account whether focus
6867 * indication should currently be shown in the toplevel window of
6868 * @widget. See gtk_window_get_focus_visible() for more information
6869 * about focus indication.
6871 * To find out if the widget has the global input focus, use
6872 * gtk_widget_has_focus().
6874 * Return value: %TRUE if the widget should display a 'focus rectangle'
6879 gtk_widget_has_visible_focus (GtkWidget *widget)
6881 gboolean draw_focus;
6883 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6885 if (widget->priv->has_focus)
6887 GtkWidget *toplevel;
6889 toplevel = gtk_widget_get_toplevel (widget);
6891 if (GTK_IS_WINDOW (toplevel))
6892 draw_focus = gtk_window_get_focus_visible (GTK_WINDOW (toplevel));
6903 * gtk_widget_is_focus:
6904 * @widget: a #GtkWidget
6906 * Determines if the widget is the focus widget within its
6907 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6908 * necessarily set; %HAS_FOCUS will only be set if the
6909 * toplevel widget additionally has the global input focus.)
6911 * Return value: %TRUE if the widget is the focus widget.
6914 gtk_widget_is_focus (GtkWidget *widget)
6916 GtkWidget *toplevel;
6918 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6920 toplevel = gtk_widget_get_toplevel (widget);
6922 if (GTK_IS_WINDOW (toplevel))
6923 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6929 * gtk_widget_set_can_default:
6930 * @widget: a #GtkWidget
6931 * @can_default: whether or not @widget can be a default widget.
6933 * Specifies whether @widget can be a default widget. See
6934 * gtk_widget_grab_default() for details about the meaning of
6940 gtk_widget_set_can_default (GtkWidget *widget,
6941 gboolean can_default)
6943 g_return_if_fail (GTK_IS_WIDGET (widget));
6945 if (widget->priv->can_default != can_default)
6947 widget->priv->can_default = can_default;
6949 gtk_widget_queue_resize (widget);
6950 g_object_notify (G_OBJECT (widget), "can-default");
6955 * gtk_widget_get_can_default:
6956 * @widget: a #GtkWidget
6958 * Determines whether @widget can be a default widget. See
6959 * gtk_widget_set_can_default().
6961 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6966 gtk_widget_get_can_default (GtkWidget *widget)
6968 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6970 return widget->priv->can_default;
6974 * gtk_widget_has_default:
6975 * @widget: a #GtkWidget
6977 * Determines whether @widget is the current default widget within its
6978 * toplevel. See gtk_widget_set_can_default().
6980 * Return value: %TRUE if @widget is the current default widget within
6981 * its toplevel, %FALSE otherwise
6986 gtk_widget_has_default (GtkWidget *widget)
6988 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6990 return widget->priv->has_default;
6994 _gtk_widget_set_has_default (GtkWidget *widget,
6995 gboolean has_default)
6997 GtkStyleContext *context;
6999 widget->priv->has_default = has_default;
7001 context = gtk_widget_get_style_context (widget);
7004 gtk_style_context_add_class (context, GTK_STYLE_CLASS_DEFAULT);
7006 gtk_style_context_remove_class (context, GTK_STYLE_CLASS_DEFAULT);
7010 * gtk_widget_grab_default:
7011 * @widget: a #GtkWidget
7013 * Causes @widget to become the default widget. @widget must have the
7014 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
7015 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
7016 * %TRUE)</literal>. The default widget is activated when
7017 * the user presses Enter in a window. Default widgets must be
7018 * activatable, that is, gtk_widget_activate() should affect them. Note
7019 * that #GtkEntry widgets require the "activates-default" property
7020 * set to %TRUE before they activate the default widget when Enter
7021 * is pressed and the #GtkEntry is focused.
7024 gtk_widget_grab_default (GtkWidget *widget)
7028 g_return_if_fail (GTK_IS_WIDGET (widget));
7029 g_return_if_fail (gtk_widget_get_can_default (widget));
7031 window = gtk_widget_get_toplevel (widget);
7033 if (window && gtk_widget_is_toplevel (window))
7034 gtk_window_set_default (GTK_WINDOW (window), widget);
7036 g_warning (G_STRLOC ": widget not within a GtkWindow");
7040 * gtk_widget_set_receives_default:
7041 * @widget: a #GtkWidget
7042 * @receives_default: whether or not @widget can be a default widget.
7044 * Specifies whether @widget will be treated as the default widget
7045 * within its toplevel when it has the focus, even if another widget
7048 * See gtk_widget_grab_default() for details about the meaning of
7054 gtk_widget_set_receives_default (GtkWidget *widget,
7055 gboolean receives_default)
7057 g_return_if_fail (GTK_IS_WIDGET (widget));
7059 if (widget->priv->receives_default != receives_default)
7061 widget->priv->receives_default = receives_default;
7063 g_object_notify (G_OBJECT (widget), "receives-default");
7068 * gtk_widget_get_receives_default:
7069 * @widget: a #GtkWidget
7071 * Determines whether @widget is alyways treated as default widget
7072 * withing its toplevel when it has the focus, even if another widget
7075 * See gtk_widget_set_receives_default().
7077 * Return value: %TRUE if @widget acts as default widget when focussed,
7083 gtk_widget_get_receives_default (GtkWidget *widget)
7085 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7087 return widget->priv->receives_default;
7091 * gtk_widget_has_grab:
7092 * @widget: a #GtkWidget
7094 * Determines whether the widget is currently grabbing events, so it
7095 * is the only widget receiving input events (keyboard and mouse).
7097 * See also gtk_grab_add().
7099 * Return value: %TRUE if the widget is in the grab_widgets stack
7104 gtk_widget_has_grab (GtkWidget *widget)
7106 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7108 return widget->priv->has_grab;
7112 _gtk_widget_set_has_grab (GtkWidget *widget,
7115 widget->priv->has_grab = has_grab;
7119 * gtk_widget_device_is_shadowed:
7120 * @widget: a #GtkWidget
7121 * @device: a #GdkDevice
7123 * Returns %TRUE if @device has been shadowed by a GTK+
7124 * device grab on another widget, so it would stop sending
7125 * events to @widget. This may be used in the
7126 * #GtkWidget::grab-notify signal to check for specific
7127 * devices. See gtk_device_grab_add().
7129 * Returns: %TRUE if there is an ongoing grab on @device
7130 * by another #GtkWidget than @widget.
7135 gtk_widget_device_is_shadowed (GtkWidget *widget,
7138 GtkWindowGroup *group;
7139 GtkWidget *grab_widget, *toplevel;
7141 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7142 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
7144 if (!gtk_widget_get_realized (widget))
7147 toplevel = gtk_widget_get_toplevel (widget);
7149 if (GTK_IS_WINDOW (toplevel))
7150 group = gtk_window_get_group (GTK_WINDOW (toplevel));
7152 group = gtk_window_get_group (NULL);
7154 grab_widget = gtk_window_group_get_current_device_grab (group, device);
7156 /* Widget not inside the hierarchy of grab_widget */
7158 widget != grab_widget &&
7159 !gtk_widget_is_ancestor (widget, grab_widget))
7162 grab_widget = gtk_window_group_get_current_grab (group);
7163 if (grab_widget && widget != grab_widget &&
7164 !gtk_widget_is_ancestor (widget, grab_widget))
7171 * gtk_widget_set_name:
7172 * @widget: a #GtkWidget
7173 * @name: name for the widget
7175 * Widgets can be named, which allows you to refer to them from a
7176 * CSS file. You can apply a style to widgets with a particular name
7177 * in the CSS file. See the documentation for the CSS syntax (on the
7178 * same page as the docs for #GtkStyleContext).
7180 * Note that the CSS syntax has certain special characters to delimit
7181 * and represent elements in a selector (period, #, >, *...),
7182 * so using these will make your widget impossible to match by name.
7183 * Any combination of alphanumeric symbols, dashes and underscores will
7187 gtk_widget_set_name (GtkWidget *widget,
7190 GtkWidgetPrivate *priv;
7193 g_return_if_fail (GTK_IS_WIDGET (widget));
7195 priv = widget->priv;
7197 new_name = g_strdup (name);
7198 g_free (priv->name);
7199 priv->name = new_name;
7201 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_NAME);
7203 g_object_notify (G_OBJECT (widget), "name");
7207 * gtk_widget_get_name:
7208 * @widget: a #GtkWidget
7210 * Retrieves the name of a widget. See gtk_widget_set_name() for the
7211 * significance of widget names.
7213 * Return value: name of the widget. This string is owned by GTK+ and
7214 * should not be modified or freed
7217 gtk_widget_get_name (GtkWidget *widget)
7219 GtkWidgetPrivate *priv;
7221 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7223 priv = widget->priv;
7227 return G_OBJECT_TYPE_NAME (widget);
7231 _gtk_widget_update_state_flags (GtkWidget *widget,
7232 GtkStateFlags flags,
7235 GtkWidgetPrivate *priv;
7237 priv = widget->priv;
7239 /* Handle insensitive first, since it is propagated
7240 * differently throughout the widget hierarchy.
7242 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_UNSET))
7243 gtk_widget_set_sensitive (widget, TRUE);
7244 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation != STATE_CHANGE_UNSET))
7245 gtk_widget_set_sensitive (widget, FALSE);
7246 else if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && !(flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_REPLACE))
7247 gtk_widget_set_sensitive (widget, TRUE);
7249 if (operation != STATE_CHANGE_REPLACE)
7250 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
7253 operation == STATE_CHANGE_REPLACE)
7258 data.operation = operation;
7260 gtk_widget_propagate_state (widget, &data);
7262 gtk_widget_queue_resize (widget);
7267 * gtk_widget_set_state_flags:
7268 * @widget: a #GtkWidget
7269 * @flags: State flags to turn on
7270 * @clear: Whether to clear state before turning on @flags
7272 * This function is for use in widget implementations. Turns on flag
7273 * values in the current widget state (insensitive, prelighted, etc.).
7275 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7276 * will be propagated down to all non-internal children if @widget is a
7277 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7278 * down to all #GtkContainer children by different means than turning on the
7279 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7280 * gtk_widget_is_sensitive() will make use of these.
7285 gtk_widget_set_state_flags (GtkWidget *widget,
7286 GtkStateFlags flags,
7289 g_return_if_fail (GTK_IS_WIDGET (widget));
7291 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7292 (clear && widget->priv->state_flags == flags))
7296 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7298 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
7302 * gtk_widget_unset_state_flags:
7303 * @widget: a #GtkWidget
7304 * @flags: State flags to turn off
7306 * This function is for use in widget implementations. Turns off flag
7307 * values for the current widget state (insensitive, prelighted, etc.).
7308 * See gtk_widget_set_state_flags().
7313 gtk_widget_unset_state_flags (GtkWidget *widget,
7314 GtkStateFlags flags)
7316 g_return_if_fail (GTK_IS_WIDGET (widget));
7318 if ((widget->priv->state_flags & flags) == 0)
7321 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
7325 * gtk_widget_get_state_flags:
7326 * @widget: a #GtkWidget
7328 * Returns the widget state as a flag set. It is worth mentioning
7329 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7330 * returned, that is, also based on parent insensitivity, even if
7331 * @widget itself is sensitive.
7333 * Returns: The state flags for widget
7338 gtk_widget_get_state_flags (GtkWidget *widget)
7340 GtkStateFlags flags;
7342 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7344 flags = widget->priv->state_flags;
7346 if (gtk_widget_has_focus (widget))
7347 flags |= GTK_STATE_FLAG_FOCUSED;
7353 * gtk_widget_set_state:
7354 * @widget: a #GtkWidget
7355 * @state: new state for @widget
7357 * This function is for use in widget implementations. Sets the state
7358 * of a widget (insensitive, prelighted, etc.) Usually you should set
7359 * the state using wrapper functions such as gtk_widget_set_sensitive().
7361 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7364 gtk_widget_set_state (GtkWidget *widget,
7367 GtkStateFlags flags;
7369 if (state == gtk_widget_get_state (widget))
7374 case GTK_STATE_ACTIVE:
7375 flags = GTK_STATE_FLAG_ACTIVE;
7377 case GTK_STATE_PRELIGHT:
7378 flags = GTK_STATE_FLAG_PRELIGHT;
7380 case GTK_STATE_SELECTED:
7381 flags = GTK_STATE_FLAG_SELECTED;
7383 case GTK_STATE_INSENSITIVE:
7384 flags = GTK_STATE_FLAG_INSENSITIVE;
7386 case GTK_STATE_INCONSISTENT:
7387 flags = GTK_STATE_FLAG_INCONSISTENT;
7389 case GTK_STATE_FOCUSED:
7390 flags = GTK_STATE_FLAG_FOCUSED;
7392 case GTK_STATE_NORMAL:
7398 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7402 * gtk_widget_get_state:
7403 * @widget: a #GtkWidget
7405 * Returns the widget's state. See gtk_widget_set_state().
7407 * Returns: the state of @widget.
7411 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7414 gtk_widget_get_state (GtkWidget *widget)
7416 GtkStateFlags flags;
7418 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7420 flags = gtk_widget_get_state_flags (widget);
7422 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7423 return GTK_STATE_INSENSITIVE;
7424 else if (flags & GTK_STATE_FLAG_ACTIVE)
7425 return GTK_STATE_ACTIVE;
7426 else if (flags & GTK_STATE_FLAG_SELECTED)
7427 return GTK_STATE_SELECTED;
7428 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7429 return GTK_STATE_PRELIGHT;
7431 return GTK_STATE_NORMAL;
7435 * gtk_widget_set_visible:
7436 * @widget: a #GtkWidget
7437 * @visible: whether the widget should be shown or not
7439 * Sets the visibility state of @widget. Note that setting this to
7440 * %TRUE doesn't mean the widget is actually viewable, see
7441 * gtk_widget_get_visible().
7443 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7444 * but is nicer to use when the visibility of the widget depends on
7450 gtk_widget_set_visible (GtkWidget *widget,
7453 g_return_if_fail (GTK_IS_WIDGET (widget));
7455 if (visible != gtk_widget_get_visible (widget))
7458 gtk_widget_show (widget);
7460 gtk_widget_hide (widget);
7465 _gtk_widget_set_visible_flag (GtkWidget *widget,
7468 widget->priv->visible = visible;
7472 * gtk_widget_get_visible:
7473 * @widget: a #GtkWidget
7475 * Determines whether the widget is visible. Note that this doesn't
7476 * take into account whether the widget's parent is also visible
7477 * or the widget is obscured in any way.
7479 * See gtk_widget_set_visible().
7481 * Return value: %TRUE if the widget is visible
7486 gtk_widget_get_visible (GtkWidget *widget)
7488 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7490 return widget->priv->visible;
7494 * gtk_widget_set_has_window:
7495 * @widget: a #GtkWidget
7496 * @has_window: whether or not @widget has a window.
7498 * Specifies whether @widget has a #GdkWindow of its own. Note that
7499 * all realized widgets have a non-%NULL "window" pointer
7500 * (gtk_widget_get_window() never returns a %NULL window when a widget
7501 * is realized), but for many of them it's actually the #GdkWindow of
7502 * one of its parent widgets. Widgets that do not create a %window for
7503 * themselves in #GtkWidget::realize must announce this by
7504 * calling this function with @has_window = %FALSE.
7506 * This function should only be called by widget implementations,
7507 * and they should call it in their init() function.
7512 gtk_widget_set_has_window (GtkWidget *widget,
7513 gboolean has_window)
7515 g_return_if_fail (GTK_IS_WIDGET (widget));
7517 widget->priv->no_window = !has_window;
7521 * gtk_widget_get_has_window:
7522 * @widget: a #GtkWidget
7524 * Determines whether @widget has a #GdkWindow of its own. See
7525 * gtk_widget_set_has_window().
7527 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7532 gtk_widget_get_has_window (GtkWidget *widget)
7534 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7536 return ! widget->priv->no_window;
7540 * gtk_widget_is_toplevel:
7541 * @widget: a #GtkWidget
7543 * Determines whether @widget is a toplevel widget.
7545 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7546 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7549 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7554 gtk_widget_is_toplevel (GtkWidget *widget)
7556 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7558 return widget->priv->toplevel;
7562 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7563 gboolean is_toplevel)
7565 widget->priv->toplevel = is_toplevel;
7569 * gtk_widget_is_drawable:
7570 * @widget: a #GtkWidget
7572 * Determines whether @widget can be drawn to. A widget can be drawn
7573 * to if it is mapped and visible.
7575 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7580 gtk_widget_is_drawable (GtkWidget *widget)
7582 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7584 return (gtk_widget_get_visible (widget) &&
7585 gtk_widget_get_mapped (widget));
7589 * gtk_widget_get_realized:
7590 * @widget: a #GtkWidget
7592 * Determines whether @widget is realized.
7594 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7599 gtk_widget_get_realized (GtkWidget *widget)
7601 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7603 return widget->priv->realized;
7607 * gtk_widget_set_realized:
7608 * @widget: a #GtkWidget
7609 * @realized: %TRUE to mark the widget as realized
7611 * Marks the widget as being realized.
7613 * This function should only ever be called in a derived widget's
7614 * "realize" or "unrealize" implementation.
7619 gtk_widget_set_realized (GtkWidget *widget,
7622 g_return_if_fail (GTK_IS_WIDGET (widget));
7624 widget->priv->realized = realized;
7628 * gtk_widget_get_mapped:
7629 * @widget: a #GtkWidget
7631 * Whether the widget is mapped.
7633 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7638 gtk_widget_get_mapped (GtkWidget *widget)
7640 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7642 return widget->priv->mapped;
7646 * gtk_widget_set_mapped:
7647 * @widget: a #GtkWidget
7648 * @mapped: %TRUE to mark the widget as mapped
7650 * Marks the widget as being realized.
7652 * This function should only ever be called in a derived widget's
7653 * "map" or "unmap" implementation.
7658 gtk_widget_set_mapped (GtkWidget *widget,
7661 g_return_if_fail (GTK_IS_WIDGET (widget));
7663 widget->priv->mapped = mapped;
7667 * gtk_widget_set_app_paintable:
7668 * @widget: a #GtkWidget
7669 * @app_paintable: %TRUE if the application will paint on the widget
7671 * Sets whether the application intends to draw on the widget in
7672 * an #GtkWidget::draw handler.
7674 * This is a hint to the widget and does not affect the behavior of
7675 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7676 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7677 * the effect is to suppress default themed drawing of the widget's
7678 * background. (Children of the widget will still be drawn.) The application
7679 * is then entirely responsible for drawing the widget background.
7681 * Note that the background is still drawn when the widget is mapped.
7684 gtk_widget_set_app_paintable (GtkWidget *widget,
7685 gboolean app_paintable)
7687 g_return_if_fail (GTK_IS_WIDGET (widget));
7689 app_paintable = (app_paintable != FALSE);
7691 if (widget->priv->app_paintable != app_paintable)
7693 widget->priv->app_paintable = app_paintable;
7695 if (gtk_widget_is_drawable (widget))
7696 gtk_widget_queue_draw (widget);
7698 g_object_notify (G_OBJECT (widget), "app-paintable");
7703 * gtk_widget_get_app_paintable:
7704 * @widget: a #GtkWidget
7706 * Determines whether the application intends to draw on the widget in
7707 * an #GtkWidget::draw handler.
7709 * See gtk_widget_set_app_paintable()
7711 * Return value: %TRUE if the widget is app paintable
7716 gtk_widget_get_app_paintable (GtkWidget *widget)
7718 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7720 return widget->priv->app_paintable;
7724 * gtk_widget_set_double_buffered:
7725 * @widget: a #GtkWidget
7726 * @double_buffered: %TRUE to double-buffer a widget
7728 * Widgets are double buffered by default; you can use this function
7729 * to turn off the buffering. "Double buffered" simply means that
7730 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7731 * automatically around expose events sent to the
7732 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7733 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7734 * buffer to the screen. The result is that users see the window
7735 * update in one smooth step, and don't see individual graphics
7736 * primitives being rendered.
7738 * In very simple terms, double buffered widgets don't flicker,
7739 * so you would only use this function to turn off double buffering
7740 * if you had special needs and really knew what you were doing.
7742 * Note: if you turn off double-buffering, you have to handle
7743 * expose events, since even the clearing to the background color or
7744 * pixmap will not happen automatically (as it is done in
7745 * gdk_window_begin_paint()).
7748 gtk_widget_set_double_buffered (GtkWidget *widget,
7749 gboolean double_buffered)
7751 g_return_if_fail (GTK_IS_WIDGET (widget));
7753 double_buffered = (double_buffered != FALSE);
7755 if (widget->priv->double_buffered != double_buffered)
7757 widget->priv->double_buffered = double_buffered;
7759 g_object_notify (G_OBJECT (widget), "double-buffered");
7764 * gtk_widget_get_double_buffered:
7765 * @widget: a #GtkWidget
7767 * Determines whether the widget is double buffered.
7769 * See gtk_widget_set_double_buffered()
7771 * Return value: %TRUE if the widget is double buffered
7776 gtk_widget_get_double_buffered (GtkWidget *widget)
7778 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7780 return widget->priv->double_buffered;
7784 * gtk_widget_set_redraw_on_allocate:
7785 * @widget: a #GtkWidget
7786 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7787 * when it is allocated to a new size. Otherwise, only the
7788 * new portion of the widget will be redrawn.
7790 * Sets whether the entire widget is queued for drawing when its size
7791 * allocation changes. By default, this setting is %TRUE and
7792 * the entire widget is redrawn on every size change. If your widget
7793 * leaves the upper left unchanged when made bigger, turning this
7794 * setting off will improve performance.
7796 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7797 * off all allocation on resizing: the widget will not even redraw if
7798 * its position changes; this is to allow containers that don't draw
7799 * anything to avoid excess invalidations. If you set this flag on a
7800 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7801 * you are responsible for invalidating both the old and new allocation
7802 * of the widget when the widget is moved and responsible for invalidating
7803 * regions newly when the widget increases size.
7806 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7807 gboolean redraw_on_allocate)
7809 g_return_if_fail (GTK_IS_WIDGET (widget));
7811 widget->priv->redraw_on_alloc = redraw_on_allocate;
7815 * gtk_widget_set_sensitive:
7816 * @widget: a #GtkWidget
7817 * @sensitive: %TRUE to make the widget sensitive
7819 * Sets the sensitivity of a widget. A widget is sensitive if the user
7820 * can interact with it. Insensitive widgets are "grayed out" and the
7821 * user can't interact with them. Insensitive widgets are known as
7822 * "inactive", "disabled", or "ghosted" in some other toolkits.
7825 gtk_widget_set_sensitive (GtkWidget *widget,
7828 GtkWidgetPrivate *priv;
7830 g_return_if_fail (GTK_IS_WIDGET (widget));
7832 priv = widget->priv;
7834 sensitive = (sensitive != FALSE);
7836 if (priv->sensitive == sensitive)
7839 priv->sensitive = sensitive;
7841 if (priv->parent == NULL
7842 || gtk_widget_is_sensitive (priv->parent))
7846 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7849 data.operation = STATE_CHANGE_UNSET;
7851 data.operation = STATE_CHANGE_SET;
7853 gtk_widget_propagate_state (widget, &data);
7855 gtk_widget_queue_resize (widget);
7858 g_object_notify (G_OBJECT (widget), "sensitive");
7862 * gtk_widget_get_sensitive:
7863 * @widget: a #GtkWidget
7865 * Returns the widget's sensitivity (in the sense of returning
7866 * the value that has been set using gtk_widget_set_sensitive()).
7868 * The effective sensitivity of a widget is however determined by both its
7869 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7871 * Returns: %TRUE if the widget is sensitive
7876 gtk_widget_get_sensitive (GtkWidget *widget)
7878 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7880 return widget->priv->sensitive;
7884 * gtk_widget_is_sensitive:
7885 * @widget: a #GtkWidget
7887 * Returns the widget's effective sensitivity, which means
7888 * it is sensitive itself and also its parent widget is sensitive
7890 * Returns: %TRUE if the widget is effectively sensitive
7895 gtk_widget_is_sensitive (GtkWidget *widget)
7897 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7899 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
7903 * gtk_widget_set_parent:
7904 * @widget: a #GtkWidget
7905 * @parent: parent container
7907 * This function is useful only when implementing subclasses of
7909 * Sets the container as the parent of @widget, and takes care of
7910 * some details such as updating the state and style of the child
7911 * to reflect its new location. The opposite function is
7912 * gtk_widget_unparent().
7915 gtk_widget_set_parent (GtkWidget *widget,
7918 GtkStateFlags parent_flags;
7919 GtkWidgetPrivate *priv;
7922 g_return_if_fail (GTK_IS_WIDGET (widget));
7923 g_return_if_fail (GTK_IS_WIDGET (parent));
7924 g_return_if_fail (widget != parent);
7926 priv = widget->priv;
7928 if (priv->parent != NULL)
7930 g_warning ("Can't set a parent on widget which has a parent\n");
7933 if (gtk_widget_is_toplevel (widget))
7935 g_warning ("Can't set a parent on a toplevel widget\n");
7939 /* keep this function in sync with gtk_menu_attach_to_widget()
7942 g_object_ref_sink (widget);
7944 gtk_widget_push_verify_invariants (widget);
7946 priv->parent = parent;
7948 parent_flags = gtk_widget_get_state_flags (parent);
7950 /* Merge both old state and current parent state,
7951 * making sure to only propagate the right states */
7952 data.flags = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
7953 data.flags |= priv->state_flags;
7955 data.operation = STATE_CHANGE_REPLACE;
7956 gtk_widget_propagate_state (widget, &data);
7959 gtk_style_context_set_parent (priv->context,
7960 gtk_widget_get_style_context (parent));
7962 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7963 if (priv->parent->priv->anchored)
7964 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7965 g_object_notify (G_OBJECT (widget), "parent");
7967 /* Enforce realized/mapped invariants
7969 if (gtk_widget_get_realized (priv->parent))
7970 gtk_widget_realize (widget);
7972 if (gtk_widget_get_visible (priv->parent) &&
7973 gtk_widget_get_visible (widget))
7975 if (gtk_widget_get_child_visible (widget) &&
7976 gtk_widget_get_mapped (priv->parent))
7977 gtk_widget_map (widget);
7979 gtk_widget_queue_resize (widget);
7982 /* child may cause parent's expand to change, if the child is
7983 * expanded. If child is not expanded, then it can't modify the
7984 * parent's expand. If the child becomes expanded later then it will
7985 * queue compute_expand then. This optimization plus defaulting
7986 * newly-constructed widgets to need_compute_expand=FALSE should
7987 * mean that initially building a widget tree doesn't have to keep
7988 * walking up setting need_compute_expand on parents over and over.
7990 * We can't change a parent to need to expand unless we're visible.
7992 if (gtk_widget_get_visible (widget) &&
7993 (priv->need_compute_expand ||
7994 priv->computed_hexpand ||
7995 priv->computed_vexpand))
7997 gtk_widget_queue_compute_expand (parent);
8000 gtk_widget_pop_verify_invariants (widget);
8004 * gtk_widget_get_parent:
8005 * @widget: a #GtkWidget
8007 * Returns the parent container of @widget.
8009 * Return value: (transfer none): the parent container of @widget, or %NULL
8012 gtk_widget_get_parent (GtkWidget *widget)
8014 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8016 return widget->priv->parent;
8020 modifier_style_changed (GtkModifierStyle *style,
8023 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8026 static GtkModifierStyle *
8027 _gtk_widget_get_modifier_properties (GtkWidget *widget)
8029 GtkModifierStyle *style;
8031 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
8033 if (G_UNLIKELY (!style))
8035 GtkStyleContext *context;
8037 style = _gtk_modifier_style_new ();
8038 g_object_set_qdata_full (G_OBJECT (widget),
8039 quark_modifier_style,
8041 (GDestroyNotify) g_object_unref);
8043 g_signal_connect (style, "changed",
8044 G_CALLBACK (modifier_style_changed), widget);
8046 context = gtk_widget_get_style_context (widget);
8048 gtk_style_context_add_provider (context,
8049 GTK_STYLE_PROVIDER (style),
8050 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
8057 * gtk_widget_override_color:
8058 * @widget: a #GtkWidget
8059 * @state: the state for which to set the color
8060 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8061 * of previous calls to gtk_widget_override_color()
8063 * Sets the color to use for a widget.
8065 * All other style values are left untouched.
8068 * This API is mostly meant as a quick way for applications to
8069 * change a widget appearance. If you are developing a widgets
8070 * library and intend this change to be themeable, it is better
8071 * done by setting meaningful CSS classes and regions in your
8072 * widget/container implementation through gtk_style_context_add_class()
8073 * and gtk_style_context_add_region().
8075 * This way, your widget library can install a #GtkCssProvider
8076 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
8077 * to provide a default styling for those widgets that need so, and
8078 * this theming may fully overridden by the user's theme.
8081 * Note that for complex widgets this may bring in undesired
8082 * results (such as uniform background color everywhere), in
8083 * these cases it is better to fully style such widgets through a
8084 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8091 gtk_widget_override_color (GtkWidget *widget,
8092 GtkStateFlags state,
8093 const GdkRGBA *color)
8095 GtkModifierStyle *style;
8097 g_return_if_fail (GTK_IS_WIDGET (widget));
8099 style = _gtk_widget_get_modifier_properties (widget);
8100 _gtk_modifier_style_set_color (style, state, color);
8104 * gtk_widget_override_background_color:
8105 * @widget: a #GtkWidget
8106 * @state: the state for which to set the background color
8107 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8108 * of previous calls to gtk_widget_override_background_color()
8110 * Sets the background color to use for a widget.
8112 * All other style values are left untouched.
8113 * See gtk_widget_override_color().
8118 gtk_widget_override_background_color (GtkWidget *widget,
8119 GtkStateFlags state,
8120 const GdkRGBA *color)
8122 GtkModifierStyle *style;
8124 g_return_if_fail (GTK_IS_WIDGET (widget));
8126 style = _gtk_widget_get_modifier_properties (widget);
8127 _gtk_modifier_style_set_background_color (style, state, color);
8131 * gtk_widget_override_font:
8132 * @widget: a #GtkWidget
8133 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
8134 * the effect of previous calls to gtk_widget_override_font()
8136 * Sets the font to use for a widget. All other style values are
8137 * left untouched. See gtk_widget_override_color().
8142 gtk_widget_override_font (GtkWidget *widget,
8143 const PangoFontDescription *font_desc)
8145 GtkModifierStyle *style;
8147 g_return_if_fail (GTK_IS_WIDGET (widget));
8149 style = _gtk_widget_get_modifier_properties (widget);
8150 _gtk_modifier_style_set_font (style, font_desc);
8154 * gtk_widget_override_symbolic_color:
8155 * @widget: a #GtkWidget
8156 * @name: the name of the symbolic color to modify
8157 * @color: (allow-none): the color to assign (does not need
8158 * to be allocated), or %NULL to undo the effect of previous
8159 * calls to gtk_widget_override_symbolic_color()
8161 * Sets a symbolic color for a widget.
8163 * All other style values are left untouched.
8164 * See gtk_widget_override_color() for overriding the foreground
8165 * or background color.
8170 gtk_widget_override_symbolic_color (GtkWidget *widget,
8172 const GdkRGBA *color)
8174 GtkModifierStyle *style;
8176 g_return_if_fail (GTK_IS_WIDGET (widget));
8178 style = _gtk_widget_get_modifier_properties (widget);
8179 _gtk_modifier_style_map_color (style, name, color);
8183 * gtk_widget_override_cursor:
8184 * @widget: a #GtkWidget
8185 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8186 * allocated), or %NULL to undo the effect of previous calls to
8187 * of gtk_widget_override_cursor().
8188 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8189 * need to be allocated), or %NULL to undo the effect of previous
8190 * calls to of gtk_widget_override_cursor().
8192 * Sets the cursor color to use in a widget, overriding the
8193 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8194 * style properties. All other style values are left untouched.
8195 * See also gtk_widget_modify_style().
8197 * Note that the underlying properties have the #GdkColor type,
8198 * so the alpha value in @primary and @secondary will be ignored.
8203 gtk_widget_override_cursor (GtkWidget *widget,
8204 const GdkRGBA *cursor,
8205 const GdkRGBA *secondary_cursor)
8207 GtkModifierStyle *style;
8209 g_return_if_fail (GTK_IS_WIDGET (widget));
8211 style = _gtk_widget_get_modifier_properties (widget);
8212 _gtk_modifier_style_set_color_property (style,
8214 "cursor-color", cursor);
8215 _gtk_modifier_style_set_color_property (style,
8217 "secondary-cursor-color",
8222 gtk_widget_real_direction_changed (GtkWidget *widget,
8223 GtkTextDirection previous_direction)
8225 gtk_widget_queue_resize (widget);
8229 gtk_widget_real_style_set (GtkWidget *widget,
8230 GtkStyle *previous_style)
8235 GtkWidget *previous_toplevel;
8236 GdkScreen *previous_screen;
8237 GdkScreen *new_screen;
8238 } HierarchyChangedInfo;
8241 do_screen_change (GtkWidget *widget,
8242 GdkScreen *old_screen,
8243 GdkScreen *new_screen)
8245 if (old_screen != new_screen)
8247 GtkWidgetPrivate *priv = widget->priv;
8251 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8253 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8256 _gtk_tooltip_hide (widget);
8258 if (new_screen && priv->context)
8259 gtk_style_context_set_screen (priv->context, new_screen);
8261 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8266 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8267 gpointer client_data)
8269 GtkWidgetPrivate *priv = widget->priv;
8270 HierarchyChangedInfo *info = client_data;
8271 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8272 (priv->parent && priv->parent->priv->anchored);
8274 if (priv->anchored != new_anchored)
8276 g_object_ref (widget);
8278 priv->anchored = new_anchored;
8280 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8281 do_screen_change (widget, info->previous_screen, info->new_screen);
8283 if (GTK_IS_CONTAINER (widget))
8284 gtk_container_forall (GTK_CONTAINER (widget),
8285 gtk_widget_propagate_hierarchy_changed_recurse,
8288 g_object_unref (widget);
8293 * _gtk_widget_propagate_hierarchy_changed:
8294 * @widget: a #GtkWidget
8295 * @previous_toplevel: Previous toplevel
8297 * Propagates changes in the anchored state to a widget and all
8298 * children, unsetting or setting the %ANCHORED flag, and
8299 * emitting #GtkWidget::hierarchy-changed.
8302 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8303 GtkWidget *previous_toplevel)
8305 GtkWidgetPrivate *priv = widget->priv;
8306 HierarchyChangedInfo info;
8308 info.previous_toplevel = previous_toplevel;
8309 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8311 if (gtk_widget_is_toplevel (widget) ||
8312 (priv->parent && priv->parent->priv->anchored))
8313 info.new_screen = gtk_widget_get_screen (widget);
8315 info.new_screen = NULL;
8317 if (info.previous_screen)
8318 g_object_ref (info.previous_screen);
8319 if (previous_toplevel)
8320 g_object_ref (previous_toplevel);
8322 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8324 if (previous_toplevel)
8325 g_object_unref (previous_toplevel);
8326 if (info.previous_screen)
8327 g_object_unref (info.previous_screen);
8331 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8332 gpointer client_data)
8334 HierarchyChangedInfo *info = client_data;
8336 g_object_ref (widget);
8338 do_screen_change (widget, info->previous_screen, info->new_screen);
8340 if (GTK_IS_CONTAINER (widget))
8341 gtk_container_forall (GTK_CONTAINER (widget),
8342 gtk_widget_propagate_screen_changed_recurse,
8345 g_object_unref (widget);
8349 * gtk_widget_is_composited:
8350 * @widget: a #GtkWidget
8352 * Whether @widget can rely on having its alpha channel
8353 * drawn correctly. On X11 this function returns whether a
8354 * compositing manager is running for @widget's screen.
8356 * Please note that the semantics of this call will change
8357 * in the future if used on a widget that has a composited
8358 * window in its hierarchy (as set by gdk_window_set_composited()).
8360 * Return value: %TRUE if the widget can rely on its alpha
8361 * channel being drawn correctly.
8366 gtk_widget_is_composited (GtkWidget *widget)
8370 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8372 screen = gtk_widget_get_screen (widget);
8374 return gdk_screen_is_composited (screen);
8378 propagate_composited_changed (GtkWidget *widget,
8381 if (GTK_IS_CONTAINER (widget))
8383 gtk_container_forall (GTK_CONTAINER (widget),
8384 propagate_composited_changed,
8388 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8392 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8394 propagate_composited_changed (widget, NULL);
8398 * _gtk_widget_propagate_screen_changed:
8399 * @widget: a #GtkWidget
8400 * @previous_screen: Previous screen
8402 * Propagates changes in the screen for a widget to all
8403 * children, emitting #GtkWidget::screen-changed.
8406 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8407 GdkScreen *previous_screen)
8409 HierarchyChangedInfo info;
8411 info.previous_screen = previous_screen;
8412 info.new_screen = gtk_widget_get_screen (widget);
8414 if (previous_screen)
8415 g_object_ref (previous_screen);
8417 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8419 if (previous_screen)
8420 g_object_unref (previous_screen);
8424 reset_style_recurse (GtkWidget *widget, gpointer data)
8426 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8428 if (GTK_IS_CONTAINER (widget))
8429 gtk_container_forall (GTK_CONTAINER (widget),
8430 reset_style_recurse,
8435 * gtk_widget_reset_style:
8436 * @widget: a #GtkWidget
8438 * Updates the style context of @widget and all descendents
8439 * by updating its widget path. #GtkContainer<!-- -->s may want
8440 * to use this on a child when reordering it in a way that a different
8441 * style might apply to it. See also gtk_container_get_path_for_child().
8446 gtk_widget_reset_style (GtkWidget *widget)
8448 g_return_if_fail (GTK_IS_WIDGET (widget));
8450 reset_style_recurse (widget, NULL);
8452 g_list_foreach (widget->priv->attached_windows,
8453 (GFunc) reset_style_recurse, NULL);
8456 #ifdef G_ENABLE_DEBUG
8458 /* Verify invariants, see docs/widget_system.txt for notes on much of
8459 * this. Invariants may be temporarily broken while we're in the
8460 * process of updating state, of course, so you can only
8461 * verify_invariants() after a given operation is complete.
8462 * Use push/pop_verify_invariants to help with that.
8465 gtk_widget_verify_invariants (GtkWidget *widget)
8469 if (widget->priv->verifying_invariants_count > 0)
8472 parent = widget->priv->parent;
8474 if (widget->priv->mapped)
8476 /* Mapped implies ... */
8478 if (!widget->priv->realized)
8479 g_warning ("%s %p is mapped but not realized",
8480 G_OBJECT_TYPE_NAME (widget), widget);
8482 if (!widget->priv->visible)
8483 g_warning ("%s %p is mapped but not visible",
8484 G_OBJECT_TYPE_NAME (widget), widget);
8486 if (!widget->priv->toplevel)
8488 if (!widget->priv->child_visible)
8489 g_warning ("%s %p is mapped but not child_visible",
8490 G_OBJECT_TYPE_NAME (widget), widget);
8495 /* Not mapped implies... */
8498 /* This check makes sense for normal toplevels, but for
8499 * something like a toplevel that is embedded within a clutter
8500 * state, mapping may depend on external factors.
8502 if (widget->priv->toplevel)
8504 if (widget->priv->visible)
8505 g_warning ("%s %p toplevel is visible but not mapped",
8506 G_OBJECT_TYPE_NAME (widget), widget);
8511 /* Parent related checks aren't possible if parent has
8512 * verifying_invariants_count > 0 because parent needs to recurse
8513 * children first before the invariants will hold.
8515 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8518 parent->priv->realized)
8520 /* Parent realized implies... */
8523 /* This is in widget_system.txt but appears to fail
8524 * because there's no gtk_container_realize() that
8525 * realizes all children... instead we just lazily
8526 * wait for map to fix things up.
8528 if (!widget->priv->realized)
8529 g_warning ("%s %p is realized but child %s %p is not realized",
8530 G_OBJECT_TYPE_NAME (parent), parent,
8531 G_OBJECT_TYPE_NAME (widget), widget);
8534 else if (!widget->priv->toplevel)
8536 /* No parent or parent not realized on non-toplevel implies... */
8538 if (widget->priv->realized && !widget->priv->in_reparent)
8539 g_warning ("%s %p is not realized but child %s %p is realized",
8540 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8541 G_OBJECT_TYPE_NAME (widget), widget);
8545 parent->priv->mapped &&
8546 widget->priv->visible &&
8547 widget->priv->child_visible)
8549 /* Parent mapped and we are visible implies... */
8551 if (!widget->priv->mapped)
8552 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8553 G_OBJECT_TYPE_NAME (parent), parent,
8554 G_OBJECT_TYPE_NAME (widget), widget);
8556 else if (!widget->priv->toplevel)
8558 /* No parent or parent not mapped on non-toplevel implies... */
8560 if (widget->priv->mapped && !widget->priv->in_reparent)
8561 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8562 G_OBJECT_TYPE_NAME (widget), widget,
8563 widget->priv->visible,
8564 widget->priv->child_visible,
8565 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8566 parent ? parent->priv->mapped : FALSE);
8570 if (!widget->priv->realized)
8572 /* Not realized implies... */
8575 /* widget_system.txt says these hold, but they don't. */
8576 if (widget->priv->alloc_needed)
8577 g_warning ("%s %p alloc needed but not realized",
8578 G_OBJECT_TYPE_NAME (widget), widget);
8580 if (widget->priv->width_request_needed)
8581 g_warning ("%s %p width request needed but not realized",
8582 G_OBJECT_TYPE_NAME (widget), widget);
8584 if (widget->priv->height_request_needed)
8585 g_warning ("%s %p height request needed but not realized",
8586 G_OBJECT_TYPE_NAME (widget), widget);
8591 /* The point of this push/pop is that invariants may not hold while
8592 * we're busy making changes. So we only check at the outermost call
8593 * on the call stack, after we finish updating everything.
8596 gtk_widget_push_verify_invariants (GtkWidget *widget)
8598 widget->priv->verifying_invariants_count += 1;
8602 gtk_widget_verify_child_invariants (GtkWidget *widget,
8603 gpointer client_data)
8605 /* We don't recurse further; this is a one-level check. */
8606 gtk_widget_verify_invariants (widget);
8610 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8612 g_assert (widget->priv->verifying_invariants_count > 0);
8614 widget->priv->verifying_invariants_count -= 1;
8616 if (widget->priv->verifying_invariants_count == 0)
8618 gtk_widget_verify_invariants (widget);
8620 if (GTK_IS_CONTAINER (widget))
8622 /* Check one level of children, because our
8623 * push_verify_invariants() will have prevented some of the
8624 * checks. This does not recurse because if recursion is
8625 * needed, it will happen naturally as each child has a
8626 * push/pop on that child. For example if we're recursively
8627 * mapping children, we'll push/pop on each child as we map
8630 gtk_container_forall (GTK_CONTAINER (widget),
8631 gtk_widget_verify_child_invariants,
8636 #endif /* G_ENABLE_DEBUG */
8638 static PangoContext *
8639 gtk_widget_peek_pango_context (GtkWidget *widget)
8641 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8645 * gtk_widget_get_pango_context:
8646 * @widget: a #GtkWidget
8648 * Gets a #PangoContext with the appropriate font map, font description,
8649 * and base direction for this widget. Unlike the context returned
8650 * by gtk_widget_create_pango_context(), this context is owned by
8651 * the widget (it can be used until the screen for the widget changes
8652 * or the widget is removed from its toplevel), and will be updated to
8653 * match any changes to the widget's attributes.
8655 * If you create and keep a #PangoLayout using this context, you must
8656 * deal with changes to the context by calling pango_layout_context_changed()
8657 * on the layout in response to the #GtkWidget::style-updated and
8658 * #GtkWidget::direction-changed signals for the widget.
8660 * Return value: (transfer none): the #PangoContext for the widget.
8663 gtk_widget_get_pango_context (GtkWidget *widget)
8665 PangoContext *context;
8667 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8669 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8672 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8673 g_object_set_qdata_full (G_OBJECT (widget),
8674 quark_pango_context,
8683 update_pango_context (GtkWidget *widget,
8684 PangoContext *context)
8686 const PangoFontDescription *font_desc;
8687 GtkStyleContext *style_context;
8689 style_context = gtk_widget_get_style_context (widget);
8691 font_desc = gtk_style_context_get_font (style_context,
8692 gtk_widget_get_state_flags (widget));
8694 pango_context_set_font_description (context, font_desc);
8695 pango_context_set_base_dir (context,
8696 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8697 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8701 gtk_widget_update_pango_context (GtkWidget *widget)
8703 PangoContext *context = gtk_widget_peek_pango_context (widget);
8709 update_pango_context (widget, context);
8711 screen = gtk_widget_get_screen_unchecked (widget);
8714 pango_cairo_context_set_resolution (context,
8715 gdk_screen_get_resolution (screen));
8716 pango_cairo_context_set_font_options (context,
8717 gdk_screen_get_font_options (screen));
8723 * gtk_widget_create_pango_context:
8724 * @widget: a #GtkWidget
8726 * Creates a new #PangoContext with the appropriate font map,
8727 * font description, and base direction for drawing text for
8728 * this widget. See also gtk_widget_get_pango_context().
8730 * Return value: (transfer full): the new #PangoContext
8733 gtk_widget_create_pango_context (GtkWidget *widget)
8736 PangoContext *context;
8738 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8740 screen = gtk_widget_get_screen_unchecked (widget);
8743 GTK_NOTE (MULTIHEAD,
8744 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8746 screen = gdk_screen_get_default ();
8749 context = gdk_pango_context_get_for_screen (screen);
8751 update_pango_context (widget, context);
8752 pango_context_set_language (context, gtk_get_default_language ());
8758 * gtk_widget_create_pango_layout:
8759 * @widget: a #GtkWidget
8760 * @text: text to set on the layout (can be %NULL)
8762 * Creates a new #PangoLayout with the appropriate font map,
8763 * font description, and base direction for drawing text for
8766 * If you keep a #PangoLayout created in this way around, in order to
8767 * notify the layout of changes to the base direction or font of this
8768 * widget, you must call pango_layout_context_changed() in response to
8769 * the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
8772 * Return value: (transfer full): the new #PangoLayout
8775 gtk_widget_create_pango_layout (GtkWidget *widget,
8778 PangoLayout *layout;
8779 PangoContext *context;
8781 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8783 context = gtk_widget_get_pango_context (widget);
8784 layout = pango_layout_new (context);
8787 pango_layout_set_text (layout, text, -1);
8793 * gtk_widget_render_icon_pixbuf:
8794 * @widget: a #GtkWidget
8795 * @stock_id: a stock ID
8796 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8797 * render at the size of the source and don't scale (if there are
8798 * multiple source sizes, GTK+ picks one of the available sizes).
8800 * A convenience function that uses the theme engine and style
8801 * settings for @widget to look up @stock_id and render it to
8802 * a pixbuf. @stock_id should be a stock icon ID such as
8803 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8804 * such as #GTK_ICON_SIZE_MENU.
8806 * The pixels in the returned #GdkPixbuf are shared with the rest of
8807 * the application and should not be modified. The pixbuf should be freed
8808 * after use with g_object_unref().
8810 * Return value: (transfer full): a new pixbuf, or %NULL if the
8811 * stock ID wasn't known
8816 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
8817 const gchar *stock_id,
8820 GtkStyleContext *context;
8821 GtkIconSet *icon_set;
8823 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8824 g_return_val_if_fail (stock_id != NULL, NULL);
8825 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8827 context = gtk_widget_get_style_context (widget);
8828 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
8830 if (icon_set == NULL)
8833 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
8837 * gtk_widget_set_parent_window:
8838 * @widget: a #GtkWidget.
8839 * @parent_window: the new parent window.
8841 * Sets a non default parent window for @widget.
8843 * For GtkWindow classes, setting a @parent_window effects whether
8844 * the window is a toplevel window or can be embedded into other
8848 * For GtkWindow classes, this needs to be called before the
8849 * window is realized.
8854 gtk_widget_set_parent_window (GtkWidget *widget,
8855 GdkWindow *parent_window)
8857 GdkWindow *old_parent_window;
8859 g_return_if_fail (GTK_IS_WIDGET (widget));
8861 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8862 quark_parent_window);
8864 if (parent_window != old_parent_window)
8868 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8870 if (old_parent_window)
8871 g_object_unref (old_parent_window);
8873 g_object_ref (parent_window);
8875 /* Unset toplevel flag when adding a parent window to a widget,
8876 * this is the primary entry point to allow toplevels to be
8879 #ifdef GDK_WINDOWING_X11
8880 is_plug = GTK_IS_PLUG (widget);
8884 if (GTK_IS_WINDOW (widget) && !is_plug)
8885 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
8890 * gtk_widget_get_parent_window:
8891 * @widget: a #GtkWidget.
8893 * Gets @widget's parent window.
8895 * Returns: (transfer none): the parent window of @widget.
8898 gtk_widget_get_parent_window (GtkWidget *widget)
8900 GtkWidgetPrivate *priv;
8901 GdkWindow *parent_window;
8903 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8905 priv = widget->priv;
8907 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8909 return (parent_window != NULL) ? parent_window :
8910 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8915 * gtk_widget_set_child_visible:
8916 * @widget: a #GtkWidget
8917 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8919 * Sets whether @widget should be mapped along with its when its parent
8920 * is mapped and @widget has been shown with gtk_widget_show().
8922 * The child visibility can be set for widget before it is added to
8923 * a container with gtk_widget_set_parent(), to avoid mapping
8924 * children unnecessary before immediately unmapping them. However
8925 * it will be reset to its default state of %TRUE when the widget
8926 * is removed from a container.
8928 * Note that changing the child visibility of a widget does not
8929 * queue a resize on the widget. Most of the time, the size of
8930 * a widget is computed from all visible children, whether or
8931 * not they are mapped. If this is not the case, the container
8932 * can queue a resize itself.
8934 * This function is only useful for container implementations and
8935 * never should be called by an application.
8938 gtk_widget_set_child_visible (GtkWidget *widget,
8939 gboolean is_visible)
8941 GtkWidgetPrivate *priv;
8943 g_return_if_fail (GTK_IS_WIDGET (widget));
8944 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8946 priv = widget->priv;
8948 g_object_ref (widget);
8949 gtk_widget_verify_invariants (widget);
8952 priv->child_visible = TRUE;
8955 GtkWidget *toplevel;
8957 priv->child_visible = FALSE;
8959 toplevel = gtk_widget_get_toplevel (widget);
8960 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8961 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8964 if (priv->parent && gtk_widget_get_realized (priv->parent))
8966 if (gtk_widget_get_mapped (priv->parent) &&
8967 priv->child_visible &&
8968 gtk_widget_get_visible (widget))
8969 gtk_widget_map (widget);
8971 gtk_widget_unmap (widget);
8974 gtk_widget_verify_invariants (widget);
8975 g_object_unref (widget);
8979 * gtk_widget_get_child_visible:
8980 * @widget: a #GtkWidget
8982 * Gets the value set with gtk_widget_set_child_visible().
8983 * If you feel a need to use this function, your code probably
8984 * needs reorganization.
8986 * This function is only useful for container implementations and
8987 * never should be called by an application.
8989 * Return value: %TRUE if the widget is mapped with the parent.
8992 gtk_widget_get_child_visible (GtkWidget *widget)
8994 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8996 return widget->priv->child_visible;
9000 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9002 GtkWidget *toplevel;
9004 toplevel = gtk_widget_get_toplevel (widget);
9006 if (gtk_widget_is_toplevel (toplevel))
9008 if (GTK_IS_WINDOW (toplevel))
9009 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9010 else if (GTK_IS_INVISIBLE (toplevel))
9011 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9018 * gtk_widget_get_screen:
9019 * @widget: a #GtkWidget
9021 * Get the #GdkScreen from the toplevel window associated with
9022 * this widget. This function can only be called after the widget
9023 * has been added to a widget hierarchy with a #GtkWindow
9026 * In general, you should only create screen specific
9027 * resources when a widget has been realized, and you should
9028 * free those resources when the widget is unrealized.
9030 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9035 gtk_widget_get_screen (GtkWidget *widget)
9039 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9041 screen = gtk_widget_get_screen_unchecked (widget);
9048 g_warning (G_STRLOC ": Can't get associated screen"
9049 " for a widget unless it is inside a toplevel GtkWindow\n"
9050 " widget type is %s associated top level type is %s",
9051 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9052 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9054 return gdk_screen_get_default ();
9059 * gtk_widget_has_screen:
9060 * @widget: a #GtkWidget
9062 * Checks whether there is a #GdkScreen is associated with
9063 * this widget. All toplevel widgets have an associated
9064 * screen, and all widgets added into a hierarchy with a toplevel
9065 * window at the top.
9067 * Return value: %TRUE if there is a #GdkScreen associcated
9073 gtk_widget_has_screen (GtkWidget *widget)
9075 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9077 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9081 * gtk_widget_get_display:
9082 * @widget: a #GtkWidget
9084 * Get the #GdkDisplay for the toplevel window associated with
9085 * this widget. This function can only be called after the widget
9086 * has been added to a widget hierarchy with a #GtkWindow at the top.
9088 * In general, you should only create display specific
9089 * resources when a widget has been realized, and you should
9090 * free those resources when the widget is unrealized.
9092 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9097 gtk_widget_get_display (GtkWidget *widget)
9099 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9101 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9105 * gtk_widget_get_root_window:
9106 * @widget: a #GtkWidget
9108 * Get the root window where this widget is located. This function can
9109 * only be called after the widget has been added to a widget
9110 * hierarchy with #GtkWindow at the top.
9112 * The root window is useful for such purposes as creating a popup
9113 * #GdkWindow associated with the window. In general, you should only
9114 * create display specific resources when a widget has been realized,
9115 * and you should free those resources when the widget is unrealized.
9117 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9122 gtk_widget_get_root_window (GtkWidget *widget)
9124 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9126 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9130 * gtk_widget_child_focus:
9131 * @widget: a #GtkWidget
9132 * @direction: direction of focus movement
9134 * This function is used by custom widget implementations; if you're
9135 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9136 * to a particular widget, and gtk_container_set_focus_chain() to
9137 * change the focus tab order. So you may want to investigate those
9138 * functions instead.
9140 * gtk_widget_child_focus() is called by containers as the user moves
9141 * around the window using keyboard shortcuts. @direction indicates
9142 * what kind of motion is taking place (up, down, left, right, tab
9143 * forward, tab backward). gtk_widget_child_focus() emits the
9144 * #GtkWidget::focus signal; widgets override the default handler
9145 * for this signal in order to implement appropriate focus behavior.
9147 * The default ::focus handler for a widget should return %TRUE if
9148 * moving in @direction left the focus on a focusable location inside
9149 * that widget, and %FALSE if moving in @direction moved the focus
9150 * outside the widget. If returning %TRUE, widgets normally
9151 * call gtk_widget_grab_focus() to place the focus accordingly;
9152 * if returning %FALSE, they don't modify the current focus location.
9154 * Return value: %TRUE if focus ended up inside @widget
9157 gtk_widget_child_focus (GtkWidget *widget,
9158 GtkDirectionType direction)
9160 gboolean return_val;
9162 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9164 if (!gtk_widget_get_visible (widget) ||
9165 !gtk_widget_is_sensitive (widget))
9168 /* child widgets must set CAN_FOCUS, containers
9169 * don't have to though.
9171 if (!GTK_IS_CONTAINER (widget) &&
9172 !gtk_widget_get_can_focus (widget))
9175 g_signal_emit (widget,
9176 widget_signals[FOCUS],
9178 direction, &return_val);
9184 * gtk_widget_keynav_failed:
9185 * @widget: a #GtkWidget
9186 * @direction: direction of focus movement
9188 * This function should be called whenever keyboard navigation within
9189 * a single widget hits a boundary. The function emits the
9190 * #GtkWidget::keynav-failed signal on the widget and its return
9191 * value should be interpreted in a way similar to the return value of
9192 * gtk_widget_child_focus():
9194 * When %TRUE is returned, stay in the widget, the failed keyboard
9195 * navigation is Ok and/or there is nowhere we can/should move the
9198 * When %FALSE is returned, the caller should continue with keyboard
9199 * navigation outside the widget, e.g. by calling
9200 * gtk_widget_child_focus() on the widget's toplevel.
9202 * The default ::keynav-failed handler returns %TRUE for
9203 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9204 * values of #GtkDirectionType, it looks at the
9205 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9206 * if the setting is %TRUE. This way the entire user interface
9207 * becomes cursor-navigatable on input devices such as mobile phones
9208 * which only have cursor keys but no tab key.
9210 * Whenever the default handler returns %TRUE, it also calls
9211 * gtk_widget_error_bell() to notify the user of the failed keyboard
9214 * A use case for providing an own implementation of ::keynav-failed
9215 * (either by connecting to it or by overriding it) would be a row of
9216 * #GtkEntry widgets where the user should be able to navigate the
9217 * entire row with the cursor keys, as e.g. known from user interfaces
9218 * that require entering license keys.
9220 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9221 * if the emitting widget should try to handle the keyboard
9222 * navigation attempt in its parent container(s).
9227 gtk_widget_keynav_failed (GtkWidget *widget,
9228 GtkDirectionType direction)
9230 gboolean return_val;
9232 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9234 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9235 direction, &return_val);
9241 * gtk_widget_error_bell:
9242 * @widget: a #GtkWidget
9244 * Notifies the user about an input-related error on this widget.
9245 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9246 * gdk_window_beep(), otherwise it does nothing.
9248 * Note that the effect of gdk_window_beep() can be configured in many
9249 * ways, depending on the windowing backend and the desktop environment
9250 * or window manager that is used.
9255 gtk_widget_error_bell (GtkWidget *widget)
9257 GtkWidgetPrivate *priv;
9258 GtkSettings* settings;
9261 g_return_if_fail (GTK_IS_WIDGET (widget));
9263 priv = widget->priv;
9265 settings = gtk_widget_get_settings (widget);
9269 g_object_get (settings,
9270 "gtk-error-bell", &beep,
9273 if (beep && priv->window)
9274 gdk_window_beep (priv->window);
9278 gtk_widget_set_usize_internal (GtkWidget *widget,
9281 GtkQueueResizeFlags flags)
9283 GtkWidgetAuxInfo *aux_info;
9284 gboolean changed = FALSE;
9286 g_object_freeze_notify (G_OBJECT (widget));
9288 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9290 if (width > -2 && aux_info->width != width)
9292 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9293 g_object_notify (G_OBJECT (widget), "width-request");
9294 aux_info->width = width;
9297 if (height > -2 && aux_info->height != height)
9299 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9300 g_object_notify (G_OBJECT (widget), "height-request");
9301 aux_info->height = height;
9305 if (gtk_widget_get_visible (widget) && changed)
9307 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9308 gtk_widget_queue_resize (widget);
9310 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9313 g_object_thaw_notify (G_OBJECT (widget));
9317 * gtk_widget_set_size_request:
9318 * @widget: a #GtkWidget
9319 * @width: width @widget should request, or -1 to unset
9320 * @height: height @widget should request, or -1 to unset
9322 * Sets the minimum size of a widget; that is, the widget's size
9323 * request will be @width by @height. You can use this function to
9324 * force a widget to be either larger or smaller than it normally
9327 * In most cases, gtk_window_set_default_size() is a better choice for
9328 * toplevel windows than this function; setting the default size will
9329 * still allow users to shrink the window. Setting the size request
9330 * will force them to leave the window at least as large as the size
9331 * request. When dealing with window sizes,
9332 * gtk_window_set_geometry_hints() can be a useful function as well.
9334 * Note the inherent danger of setting any fixed size - themes,
9335 * translations into other languages, different fonts, and user action
9336 * can all change the appropriate size for a given widget. So, it's
9337 * basically impossible to hardcode a size that will always be
9340 * The size request of a widget is the smallest size a widget can
9341 * accept while still functioning well and drawing itself correctly.
9342 * However in some strange cases a widget may be allocated less than
9343 * its requested size, and in many cases a widget may be allocated more
9344 * space than it requested.
9346 * If the size request in a given direction is -1 (unset), then
9347 * the "natural" size request of the widget will be used instead.
9349 * Widgets can't actually be allocated a size less than 1 by 1, but
9350 * you can pass 0,0 to this function to mean "as small as possible."
9352 * The size request set here does not include any margin from the
9353 * #GtkWidget properties margin-left, margin-right, margin-top, and
9354 * margin-bottom, but it does include pretty much all other padding
9355 * or border properties set by any subclass of #GtkWidget.
9358 gtk_widget_set_size_request (GtkWidget *widget,
9362 g_return_if_fail (GTK_IS_WIDGET (widget));
9363 g_return_if_fail (width >= -1);
9364 g_return_if_fail (height >= -1);
9371 gtk_widget_set_usize_internal (widget, width, height, 0);
9376 * gtk_widget_get_size_request:
9377 * @widget: a #GtkWidget
9378 * @width: (out) (allow-none): return location for width, or %NULL
9379 * @height: (out) (allow-none): return location for height, or %NULL
9381 * Gets the size request that was explicitly set for the widget using
9382 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9383 * @height indicates that that dimension has not been set explicitly
9384 * and the natural requisition of the widget will be used intead. See
9385 * gtk_widget_set_size_request(). To get the size a widget will
9386 * actually request, call gtk_widget_get_preferred_size() instead of
9390 gtk_widget_get_size_request (GtkWidget *widget,
9394 const GtkWidgetAuxInfo *aux_info;
9396 g_return_if_fail (GTK_IS_WIDGET (widget));
9398 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9401 *width = aux_info->width;
9404 *height = aux_info->height;
9408 * _gtk_widget_override_size_request:
9409 * @widget: a #GtkWidget
9410 * @width: new forced minimum width
9411 * @height: new forced minimum height
9412 * @old_width: location to store previous forced minimum width
9413 * @old_height: location to store previous forced minumum height
9415 * Temporarily establishes a forced minimum size for a widget; this
9416 * is used by GtkWindow when calculating the size to add to the
9417 * window's geometry widget. Cached sizes for the widget and its
9418 * parents are invalidated, so that subsequent calls to the size
9419 * negotiation machinery produce the overriden result, but the
9420 * widget is not queued for relayout or redraw. The old size must
9421 * be restored with _gtk_widget_restore_size_request() or things
9425 _gtk_widget_override_size_request (GtkWidget *widget,
9431 gtk_widget_get_size_request (widget, old_width, old_height);
9432 gtk_widget_set_usize_internal (widget, width, height,
9433 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9437 * _gtk_widget_restore_size_request:
9438 * @widget: a #GtkWidget
9439 * @old_width: saved forced minimum size
9440 * @old_height: saved forced minimum size
9442 * Undoes the operation of_gtk_widget_override_size_request().
9445 _gtk_widget_restore_size_request (GtkWidget *widget,
9449 gtk_widget_set_usize_internal (widget, old_width, old_height,
9450 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9454 * gtk_widget_set_events:
9455 * @widget: a #GtkWidget
9456 * @events: event mask
9458 * Sets the event mask (see #GdkEventMask) for a widget. The event
9459 * mask determines which events a widget will receive. Keep in mind
9460 * that different widgets have different default event masks, and by
9461 * changing the event mask you may disrupt a widget's functionality,
9462 * so be careful. This function must be called while a widget is
9463 * unrealized. Consider gtk_widget_add_events() for widgets that are
9464 * already realized, or if you want to preserve the existing event
9465 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9466 * to get events on those widgets, place them inside a #GtkEventBox
9467 * and receive events on the event box.
9470 gtk_widget_set_events (GtkWidget *widget,
9473 g_return_if_fail (GTK_IS_WIDGET (widget));
9474 g_return_if_fail (!gtk_widget_get_realized (widget));
9476 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9477 GINT_TO_POINTER (events));
9478 g_object_notify (G_OBJECT (widget), "events");
9482 * gtk_widget_set_device_events:
9483 * @widget: a #GtkWidget
9484 * @device: a #GdkDevice
9485 * @events: event mask
9487 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9488 * mask determines which events a widget will receive from @device. Keep
9489 * in mind 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_device_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.
9501 gtk_widget_set_device_events (GtkWidget *widget,
9503 GdkEventMask events)
9505 GHashTable *device_events;
9507 g_return_if_fail (GTK_IS_WIDGET (widget));
9508 g_return_if_fail (GDK_IS_DEVICE (device));
9509 g_return_if_fail (!gtk_widget_get_realized (widget));
9511 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9513 if (G_UNLIKELY (!device_events))
9515 device_events = g_hash_table_new (NULL, NULL);
9516 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9517 (GDestroyNotify) g_hash_table_unref);
9520 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9524 * gtk_widget_set_device_enabled:
9525 * @widget: a #GtkWidget
9526 * @device: a #GdkDevice
9527 * @enabled: whether to enable the device
9529 * Enables or disables a #GdkDevice to interact with @widget
9530 * and all its children.
9532 * It does so by descending through the #GdkWindow hierarchy
9533 * and enabling the same mask that is has for core events
9534 * (i.e. the one that gdk_window_get_events() returns).
9539 gtk_widget_set_device_enabled (GtkWidget *widget,
9543 GList *enabled_devices;
9545 g_return_if_fail (GTK_IS_WIDGET (widget));
9546 g_return_if_fail (GDK_IS_DEVICE (device));
9548 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9549 enabled_devices = g_list_append (enabled_devices, device);
9551 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9552 enabled_devices, (GDestroyNotify) g_list_free);;
9554 if (gtk_widget_get_realized (widget))
9555 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9559 * gtk_widget_get_device_enabled:
9560 * @widget: a #GtkWidget
9561 * @device: a #GdkDevice
9563 * Returns whether @device can interact with @widget and its
9564 * children. See gtk_widget_set_device_enabled().
9566 * Return value: %TRUE is @device is enabled for @widget
9571 gtk_widget_get_device_enabled (GtkWidget *widget,
9574 GList *enabled_devices;
9576 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9577 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9579 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9581 return g_list_find (enabled_devices, device) != NULL;
9585 gtk_widget_add_events_internal_list (GtkWidget *widget,
9592 for (l = window_list; l != NULL; l = l->next)
9594 GdkWindow *window = l->data;
9597 gdk_window_get_user_data (window, &user_data);
9598 if (user_data == widget)
9603 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9605 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9607 children = gdk_window_get_children (window);
9608 gtk_widget_add_events_internal_list (widget, device, events, children);
9609 g_list_free (children);
9615 gtk_widget_add_events_internal (GtkWidget *widget,
9619 GtkWidgetPrivate *priv = widget->priv;
9622 if (!gtk_widget_get_has_window (widget))
9623 window_list = gdk_window_get_children (priv->window);
9625 window_list = g_list_prepend (NULL, priv->window);
9627 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9629 g_list_free (window_list);
9633 * gtk_widget_add_events:
9634 * @widget: a #GtkWidget
9635 * @events: an event mask, see #GdkEventMask
9637 * Adds the events in the bitfield @events to the event mask for
9638 * @widget. See gtk_widget_set_events() for details.
9641 gtk_widget_add_events (GtkWidget *widget,
9646 g_return_if_fail (GTK_IS_WIDGET (widget));
9648 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9649 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9650 GINT_TO_POINTER (old_events | events));
9652 if (gtk_widget_get_realized (widget))
9654 gtk_widget_add_events_internal (widget, NULL, events);
9655 gtk_widget_update_devices_mask (widget, FALSE);
9658 g_object_notify (G_OBJECT (widget), "events");
9662 * gtk_widget_add_device_events:
9663 * @widget: a #GtkWidget
9664 * @device: a #GdkDevice
9665 * @events: an event mask, see #GdkEventMask
9667 * Adds the device events in the bitfield @events to the event mask for
9668 * @widget. See gtk_widget_set_device_events() for details.
9673 gtk_widget_add_device_events (GtkWidget *widget,
9675 GdkEventMask events)
9677 GdkEventMask old_events;
9678 GHashTable *device_events;
9680 g_return_if_fail (GTK_IS_WIDGET (widget));
9681 g_return_if_fail (GDK_IS_DEVICE (device));
9683 old_events = gtk_widget_get_device_events (widget, device);
9685 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9687 if (G_UNLIKELY (!device_events))
9689 device_events = g_hash_table_new (NULL, NULL);
9690 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9691 (GDestroyNotify) g_hash_table_unref);
9694 g_hash_table_insert (device_events, device,
9695 GUINT_TO_POINTER (old_events | events));
9697 if (gtk_widget_get_realized (widget))
9698 gtk_widget_add_events_internal (widget, device, events);
9700 g_object_notify (G_OBJECT (widget), "events");
9704 * gtk_widget_get_toplevel:
9705 * @widget: a #GtkWidget
9707 * This function returns the topmost widget in the container hierarchy
9708 * @widget is a part of. If @widget has no parent widgets, it will be
9709 * returned as the topmost widget. No reference will be added to the
9710 * returned widget; it should not be unreferenced.
9712 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9713 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9715 * %NULL if @widget wasn't inside a toplevel window, and if the
9716 * window was inside a #GtkWindow-derived widget which was in turn
9717 * inside the toplevel #GtkWindow. While the second case may
9718 * seem unlikely, it actually happens when a #GtkPlug is embedded
9719 * inside a #GtkSocket within the same application.
9721 * To reliably find the toplevel #GtkWindow, use
9722 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9723 * is set on the result.
9725 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9726 * if (gtk_widget_is_toplevel (toplevel))
9728 * /* Perform action on toplevel. */
9732 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9733 * if there's no ancestor.
9736 gtk_widget_get_toplevel (GtkWidget *widget)
9738 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9740 while (widget->priv->parent)
9741 widget = widget->priv->parent;
9747 * gtk_widget_get_ancestor:
9748 * @widget: a #GtkWidget
9749 * @widget_type: ancestor type
9751 * Gets the first ancestor of @widget with type @widget_type. For example,
9752 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9753 * the first #GtkBox that's an ancestor of @widget. No reference will be
9754 * added to the returned widget; it should not be unreferenced. See note
9755 * about checking for a toplevel #GtkWindow in the docs for
9756 * gtk_widget_get_toplevel().
9758 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9759 * considers @widget to be an ancestor of itself.
9761 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9764 gtk_widget_get_ancestor (GtkWidget *widget,
9767 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9769 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9770 widget = widget->priv->parent;
9772 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9779 * gtk_widget_set_visual:
9780 * @widget: a #GtkWidget
9781 * @visual: visual to be used or %NULL to unset a previous one
9783 * Sets the visual that should be used for by widget and its children for
9784 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9785 * returned by gdk_widget_get_screen(), so handling the
9786 * #GtkWidget::screen-changed signal is necessary.
9788 * Setting a new @visual will not cause @widget to recreate its windows,
9789 * so you should call this function before @widget is realized.
9792 gtk_widget_set_visual (GtkWidget *widget,
9795 g_return_if_fail (GTK_IS_WIDGET (widget));
9796 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9799 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9802 g_object_set_qdata_full (G_OBJECT (widget),
9804 g_object_ref (visual),
9809 * gtk_widget_get_visual:
9810 * @widget: a #GtkWidget
9812 * Gets the visual that will be used to render @widget.
9814 * Return value: (transfer none): the visual for @widget
9817 gtk_widget_get_visual (GtkWidget *widget)
9823 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9825 if (gtk_widget_get_has_window (widget) &&
9826 widget->priv->window)
9827 return gdk_window_get_visual (widget->priv->window);
9829 screen = gtk_widget_get_screen (widget);
9831 for (w = widget; w != NULL; w = w->priv->parent)
9833 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9836 if (gdk_visual_get_screen (visual) == screen)
9839 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9840 gtk_widget_get_name (widget));
9844 return gdk_screen_get_system_visual (screen);
9848 * gtk_widget_get_settings:
9849 * @widget: a #GtkWidget
9851 * Gets the settings object holding the settings used for this widget.
9853 * Note that this function can only be called when the #GtkWidget
9854 * is attached to a toplevel, since the settings object is specific
9855 * to a particular #GdkScreen.
9857 * Return value: (transfer none): the relevant #GtkSettings object
9860 gtk_widget_get_settings (GtkWidget *widget)
9862 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9864 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9868 * gtk_widget_get_events:
9869 * @widget: a #GtkWidget
9871 * Returns the event mask for the widget (a bitfield containing flags
9872 * from the #GdkEventMask enumeration). These are the events that the widget
9875 * Return value: event mask for @widget
9878 gtk_widget_get_events (GtkWidget *widget)
9880 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9882 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9886 * gtk_widget_get_device_events:
9887 * @widget: a #GtkWidget
9888 * @device: a #GdkDevice
9890 * Returns the events mask for the widget corresponding to an specific device. These
9891 * are the events that the widget will receive when @device operates on it.
9893 * Returns: device event mask for @widget
9898 gtk_widget_get_device_events (GtkWidget *widget,
9901 GHashTable *device_events;
9903 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9904 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9906 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9911 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9915 * gtk_widget_get_pointer:
9916 * @widget: a #GtkWidget
9917 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9918 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9920 * Obtains the location of the mouse pointer in widget coordinates.
9921 * Widget coordinates are a bit odd; for historical reasons, they are
9922 * defined as @widget->window coordinates for widgets that are not
9923 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9924 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9926 * Deprecated: 3.4: Use gdk_window_get_device_position() instead.
9929 gtk_widget_get_pointer (GtkWidget *widget,
9933 GtkWidgetPrivate *priv;
9935 g_return_if_fail (GTK_IS_WIDGET (widget));
9937 priv = widget->priv;
9944 if (gtk_widget_get_realized (widget))
9946 gdk_window_get_device_position (priv->window,
9947 gdk_device_manager_get_client_pointer (
9948 gdk_display_get_device_manager (
9949 gtk_widget_get_display (widget))),
9952 if (!gtk_widget_get_has_window (widget))
9955 *x -= priv->allocation.x;
9957 *y -= priv->allocation.y;
9963 * gtk_widget_is_ancestor:
9964 * @widget: a #GtkWidget
9965 * @ancestor: another #GtkWidget
9967 * Determines whether @widget is somewhere inside @ancestor, possibly with
9968 * intermediate containers.
9970 * Return value: %TRUE if @ancestor contains @widget as a child,
9971 * grandchild, great grandchild, etc.
9974 gtk_widget_is_ancestor (GtkWidget *widget,
9975 GtkWidget *ancestor)
9977 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9978 g_return_val_if_fail (ancestor != NULL, FALSE);
9982 if (widget->priv->parent == ancestor)
9984 widget = widget->priv->parent;
9990 static GQuark quark_composite_name = 0;
9993 * gtk_widget_set_composite_name:
9994 * @widget: a #GtkWidget.
9995 * @name: the name to set
9997 * Sets a widgets composite name. The widget must be
9998 * a composite child of its parent; see gtk_widget_push_composite_child().
10001 gtk_widget_set_composite_name (GtkWidget *widget,
10004 g_return_if_fail (GTK_IS_WIDGET (widget));
10005 g_return_if_fail (widget->priv->composite_child);
10006 g_return_if_fail (name != NULL);
10008 if (!quark_composite_name)
10009 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10011 g_object_set_qdata_full (G_OBJECT (widget),
10012 quark_composite_name,
10018 * gtk_widget_get_composite_name:
10019 * @widget: a #GtkWidget
10021 * Obtains the composite name of a widget.
10023 * Returns: the composite name of @widget, or %NULL if @widget is not
10024 * a composite child. The string should be freed when it is no
10028 gtk_widget_get_composite_name (GtkWidget *widget)
10030 GtkWidgetPrivate *priv;
10032 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10034 priv = widget->priv;
10036 if (widget->priv->composite_child && priv->parent)
10037 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10044 * gtk_widget_push_composite_child:
10046 * Makes all newly-created widgets as composite children until
10047 * the corresponding gtk_widget_pop_composite_child() call.
10049 * A composite child is a child that's an implementation detail of the
10050 * container it's inside and should not be visible to people using the
10051 * container. Composite children aren't treated differently by GTK (but
10052 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10053 * builders might want to treat them in a different way.
10055 * Here is a simple example:
10057 * gtk_widget_push_composite_child ();
10058 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10059 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10060 * gtk_widget_pop_composite_child ();
10061 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10062 * GTK_WIDGET (scrolled_window));
10063 * g_object_ref (scrolled_window->hscrollbar);
10067 gtk_widget_push_composite_child (void)
10069 composite_child_stack++;
10073 * gtk_widget_pop_composite_child:
10075 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10078 gtk_widget_pop_composite_child (void)
10080 if (composite_child_stack)
10081 composite_child_stack--;
10085 gtk_widget_emit_direction_changed (GtkWidget *widget,
10086 GtkTextDirection old_dir)
10088 gtk_widget_update_pango_context (widget);
10090 if (widget->priv->context)
10091 gtk_style_context_set_direction (widget->priv->context,
10092 gtk_widget_get_direction (widget));
10094 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10098 * gtk_widget_set_direction:
10099 * @widget: a #GtkWidget
10100 * @dir: the new direction
10102 * Sets the reading direction on a particular widget. This direction
10103 * controls the primary direction for widgets containing text,
10104 * and also the direction in which the children of a container are
10105 * packed. The ability to set the direction is present in order
10106 * so that correct localization into languages with right-to-left
10107 * reading directions can be done. Generally, applications will
10108 * let the default reading direction present, except for containers
10109 * where the containers are arranged in an order that is explicitely
10110 * visual rather than logical (such as buttons for text justification).
10112 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10113 * set by gtk_widget_set_default_direction() will be used.
10116 gtk_widget_set_direction (GtkWidget *widget,
10117 GtkTextDirection dir)
10119 GtkTextDirection old_dir;
10121 g_return_if_fail (GTK_IS_WIDGET (widget));
10122 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10124 old_dir = gtk_widget_get_direction (widget);
10126 widget->priv->direction = dir;
10128 if (old_dir != gtk_widget_get_direction (widget))
10129 gtk_widget_emit_direction_changed (widget, old_dir);
10133 * gtk_widget_get_direction:
10134 * @widget: a #GtkWidget
10136 * Gets the reading direction for a particular widget. See
10137 * gtk_widget_set_direction().
10139 * Return value: the reading direction for the widget.
10142 gtk_widget_get_direction (GtkWidget *widget)
10144 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10146 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10147 return gtk_default_direction;
10149 return widget->priv->direction;
10153 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10155 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10157 g_object_ref (widget);
10159 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10160 gtk_widget_emit_direction_changed (widget, old_dir);
10162 if (GTK_IS_CONTAINER (widget))
10163 gtk_container_forall (GTK_CONTAINER (widget),
10164 gtk_widget_set_default_direction_recurse,
10167 g_object_unref (widget);
10171 * gtk_widget_set_default_direction:
10172 * @dir: the new default direction. This cannot be
10173 * %GTK_TEXT_DIR_NONE.
10175 * Sets the default reading direction for widgets where the
10176 * direction has not been explicitly set by gtk_widget_set_direction().
10179 gtk_widget_set_default_direction (GtkTextDirection dir)
10181 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10183 if (dir != gtk_default_direction)
10185 GList *toplevels, *tmp_list;
10186 GtkTextDirection old_dir = gtk_default_direction;
10188 gtk_default_direction = dir;
10190 tmp_list = toplevels = gtk_window_list_toplevels ();
10191 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10195 gtk_widget_set_default_direction_recurse (tmp_list->data,
10196 GUINT_TO_POINTER (old_dir));
10197 g_object_unref (tmp_list->data);
10198 tmp_list = tmp_list->next;
10201 g_list_free (toplevels);
10206 * gtk_widget_get_default_direction:
10208 * Obtains the current default reading direction. See
10209 * gtk_widget_set_default_direction().
10211 * Return value: the current default direction.
10214 gtk_widget_get_default_direction (void)
10216 return gtk_default_direction;
10220 gtk_widget_constructed (GObject *object)
10222 GtkWidget *widget = GTK_WIDGET (object);
10223 GtkWidgetPrivate *priv = widget->priv;
10225 /* As strange as it may seem, this may happen on object construction.
10226 * init() implementations of parent types may eventually call this function,
10227 * each with its corresponding GType, which could leave a child
10228 * implementation with a wrong widget type in the widget path
10231 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (priv->path))
10233 gtk_widget_path_free (priv->path);
10237 G_OBJECT_CLASS (gtk_widget_parent_class)->constructed (object);
10241 gtk_widget_dispose (GObject *object)
10243 GtkWidget *widget = GTK_WIDGET (object);
10244 GtkWidgetPrivate *priv = widget->priv;
10247 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10248 else if (gtk_widget_get_visible (widget))
10249 gtk_widget_hide (widget);
10251 priv->visible = FALSE;
10252 if (gtk_widget_get_realized (widget))
10253 gtk_widget_unrealize (widget);
10255 if (!priv->in_destruction)
10257 priv->in_destruction = TRUE;
10258 g_signal_emit (object, widget_signals[DESTROY], 0);
10259 priv->in_destruction = FALSE;
10262 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10266 gtk_widget_real_destroy (GtkWidget *object)
10268 /* gtk_object_destroy() will already hold a refcount on object */
10269 GtkWidget *widget = GTK_WIDGET (object);
10270 GtkWidgetPrivate *priv = widget->priv;
10272 if (GTK_WIDGET_GET_CLASS (widget)->priv->accessible_type != GTK_TYPE_ACCESSIBLE)
10274 GtkAccessible *accessible = g_object_steal_qdata (G_OBJECT (widget), quark_accessible_object);
10278 gtk_accessible_set_widget (accessible, NULL);
10279 g_object_unref (accessible);
10283 /* wipe accelerator closures (keep order) */
10284 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10285 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10287 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10288 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10290 gtk_grab_remove (widget);
10293 g_object_unref (priv->style);
10294 priv->style = gtk_widget_get_default_style ();
10295 g_object_ref (priv->style);
10299 gtk_widget_finalize (GObject *object)
10301 GtkWidget *widget = GTK_WIDGET (object);
10302 GtkWidgetPrivate *priv = widget->priv;
10303 GtkWidgetAuxInfo *aux_info;
10304 GtkAccessible *accessible;
10306 gtk_grab_remove (widget);
10308 g_object_unref (priv->style);
10309 priv->style = NULL;
10311 g_free (priv->name);
10313 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10315 gtk_widget_aux_info_destroy (aux_info);
10317 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10319 g_object_unref (accessible);
10322 gtk_widget_path_free (priv->path);
10326 _gtk_style_context_set_widget (priv->context, NULL);
10327 g_object_unref (priv->context);
10330 _gtk_widget_free_cached_sizes (widget);
10332 if (g_object_is_floating (object))
10333 g_warning ("A floating object was finalized. This means that someone\n"
10334 "called g_object_unref() on an object that had only a floating\n"
10335 "reference; the initial floating reference is not owned by anyone\n"
10336 "and must be removed with g_object_ref_sink().");
10338 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10341 /*****************************************
10342 * gtk_widget_real_map:
10347 *****************************************/
10350 gtk_widget_real_map (GtkWidget *widget)
10352 GtkWidgetPrivate *priv = widget->priv;
10354 g_assert (gtk_widget_get_realized (widget));
10356 if (!gtk_widget_get_mapped (widget))
10358 gtk_widget_set_mapped (widget, TRUE);
10360 if (gtk_widget_get_has_window (widget))
10361 gdk_window_show (priv->window);
10365 /*****************************************
10366 * gtk_widget_real_unmap:
10371 *****************************************/
10374 gtk_widget_real_unmap (GtkWidget *widget)
10376 GtkWidgetPrivate *priv = widget->priv;
10378 if (gtk_widget_get_mapped (widget))
10380 gtk_widget_set_mapped (widget, FALSE);
10382 if (gtk_widget_get_has_window (widget))
10383 gdk_window_hide (priv->window);
10387 /*****************************************
10388 * gtk_widget_real_realize:
10393 *****************************************/
10396 gtk_widget_real_realize (GtkWidget *widget)
10398 GtkWidgetPrivate *priv = widget->priv;
10400 g_assert (!gtk_widget_get_has_window (widget));
10402 gtk_widget_set_realized (widget, TRUE);
10405 priv->window = gtk_widget_get_parent_window (widget);
10406 g_object_ref (priv->window);
10410 /*****************************************
10411 * gtk_widget_real_unrealize:
10416 *****************************************/
10419 gtk_widget_real_unrealize (GtkWidget *widget)
10421 GtkWidgetPrivate *priv = widget->priv;
10423 g_assert (!widget->priv->mapped);
10425 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10428 /* We must do unrealize child widget BEFORE container widget.
10429 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10430 * So, unrealizing container widget bofore its children causes the problem
10431 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10434 if (GTK_IS_CONTAINER (widget))
10435 gtk_container_forall (GTK_CONTAINER (widget),
10436 (GtkCallback) gtk_widget_unrealize,
10439 if (gtk_widget_get_has_window (widget))
10441 gdk_window_set_user_data (priv->window, NULL);
10442 gdk_window_destroy (priv->window);
10443 priv->window = NULL;
10447 g_object_unref (priv->window);
10448 priv->window = NULL;
10451 gtk_selection_remove_all (widget);
10453 gtk_widget_set_realized (widget, FALSE);
10457 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10458 GtkOrientation orientation,
10459 gint *minimum_size,
10460 gint *natural_size)
10462 const GtkWidgetAuxInfo *aux_info;
10464 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10466 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10467 aux_info->width > 0)
10469 *minimum_size = MAX (*minimum_size, aux_info->width);
10471 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10472 aux_info->height > 0)
10474 *minimum_size = MAX (*minimum_size, aux_info->height);
10477 /* Fix it if set_size_request made natural size smaller than min size.
10478 * This would also silently fix broken widgets, but we warn about them
10479 * in gtksizerequest.c when calling their size request vfuncs.
10481 *natural_size = MAX (*natural_size, *minimum_size);
10483 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10485 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10486 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10490 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10491 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10496 * _gtk_widget_peek_request_cache:
10498 * Returns the address of the widget's request cache (strictly for
10499 * internal use in gtksizerequest.c)
10501 * Return value: the address of @widget's size request cache.
10504 _gtk_widget_peek_request_cache (GtkWidget *widget)
10506 /* Don't bother slowing things down with the return_if_fail guards here */
10507 return &widget->priv->requests;
10511 * _gtk_widget_set_device_window:
10512 * @widget: a #GtkWidget
10513 * @device: a #GdkDevice
10514 * @window: the new device window
10516 * Sets pointer window for @widget and @device.
10517 * Does not ref @window.
10520 _gtk_widget_set_device_window (GtkWidget *widget,
10524 GHashTable *device_window;
10526 g_return_if_fail (GTK_IS_WIDGET (widget));
10527 g_return_if_fail (GDK_IS_DEVICE (device));
10528 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10530 if (!gtk_widget_get_mapped (widget))
10533 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10535 if (!device_window && window)
10537 device_window = g_hash_table_new (NULL, NULL);
10538 g_object_set_qdata_full (G_OBJECT (widget),
10539 quark_pointer_window,
10541 (GDestroyNotify) g_hash_table_destroy);
10545 g_hash_table_insert (device_window, device, window);
10546 else if (device_window)
10548 g_hash_table_remove (device_window, device);
10550 if (g_hash_table_size (device_window) == 0)
10551 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10556 * _gtk_widget_get_device_window:
10557 * @widget: a #GtkWidget
10558 * @device: a #GdkDevice
10560 * Return value: the device window set on @widget, or %NULL
10563 _gtk_widget_get_device_window (GtkWidget *widget,
10566 GHashTable *device_window;
10568 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10569 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10571 if (!gtk_widget_get_mapped (widget))
10574 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10576 if (!device_window)
10579 return g_hash_table_lookup (device_window, device);
10583 * _gtk_widget_list_devices:
10584 * @widget: a #GtkWidget
10586 * Returns the list of #GdkDevices that is currently on top
10587 * of any window belonging to @widget.
10588 * Free the list with g_list_free(), the elements are owned
10589 * by GTK+ and must not be freed.
10592 _gtk_widget_list_devices (GtkWidget *widget)
10594 GHashTableIter iter;
10595 GHashTable *device_window;
10596 GList *devices = NULL;
10597 gpointer key, value;
10599 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10601 if (!gtk_widget_get_mapped (widget))
10604 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10606 if (G_UNLIKELY (!device_window))
10609 g_hash_table_iter_init (&iter, device_window);
10611 while (g_hash_table_iter_next (&iter, &key, &value))
10612 devices = g_list_prepend (devices, key);
10618 synth_crossing (GtkWidget *widget,
10622 GdkCrossingMode mode,
10623 GdkNotifyType detail)
10627 event = gdk_event_new (type);
10629 event->crossing.window = g_object_ref (window);
10630 event->crossing.send_event = TRUE;
10631 event->crossing.subwindow = g_object_ref (window);
10632 event->crossing.time = GDK_CURRENT_TIME;
10633 event->crossing.x = event->crossing.y = 0;
10634 event->crossing.x_root = event->crossing.y_root = 0;
10635 event->crossing.mode = mode;
10636 event->crossing.detail = detail;
10637 event->crossing.focus = FALSE;
10638 event->crossing.state = 0;
10639 gdk_event_set_device (event, device);
10642 widget = gtk_get_event_widget (event);
10645 gtk_widget_event_internal (widget, event);
10647 gdk_event_free (event);
10651 * _gtk_widget_synthesize_crossing:
10652 * @from: the #GtkWidget the virtual pointer is leaving.
10653 * @to: the #GtkWidget the virtual pointer is moving to.
10654 * @mode: the #GdkCrossingMode to place on the synthesized events.
10656 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10658 * The real pointer window is the window that most recently received an enter notify
10659 * event. Windows that don't select for crossing events can't become the real
10660 * poiner window. The real pointer widget that owns the real pointer window. The
10661 * effective pointer window is the same as the real pointer window unless the real
10662 * pointer widget is either insensitive or there is a grab on a widget that is not
10663 * an ancestor of the real pointer widget (in which case the effective pointer
10664 * window should be the root window).
10666 * When the effective pointer window is the same as the real poiner window, we
10667 * receive crossing events from the windowing system. When the effective pointer
10668 * window changes to become different from the real pointer window we synthesize
10669 * crossing events, attempting to follow X protocol rules:
10671 * When the root window becomes the effective pointer window:
10672 * - leave notify on real pointer window, detail Ancestor
10673 * - leave notify on all of its ancestors, detail Virtual
10674 * - enter notify on root window, detail Inferior
10676 * When the root window ceases to be the effective pointer window:
10677 * - leave notify on root window, detail Inferior
10678 * - enter notify on all ancestors of real pointer window, detail Virtual
10679 * - enter notify on real pointer window, detail Ancestor
10682 _gtk_widget_synthesize_crossing (GtkWidget *from,
10685 GdkCrossingMode mode)
10687 GdkWindow *from_window = NULL, *to_window = NULL;
10689 g_return_if_fail (from != NULL || to != NULL);
10693 from_window = _gtk_widget_get_device_window (from, device);
10696 from_window = from->priv->window;
10701 to_window = _gtk_widget_get_device_window (to, device);
10704 to_window = to->priv->window;
10707 if (from_window == NULL && to_window == NULL)
10709 else if (from_window != NULL && to_window == NULL)
10711 GList *from_ancestors = NULL, *list;
10712 GdkWindow *from_ancestor = from_window;
10714 while (from_ancestor != NULL)
10716 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10717 if (from_ancestor == NULL)
10719 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10722 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10723 device, mode, GDK_NOTIFY_ANCESTOR);
10724 for (list = g_list_last (from_ancestors); list; list = list->prev)
10726 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10727 device, mode, GDK_NOTIFY_VIRTUAL);
10730 /* XXX: enter/inferior on root window? */
10732 g_list_free (from_ancestors);
10734 else if (from_window == NULL && to_window != NULL)
10736 GList *to_ancestors = NULL, *list;
10737 GdkWindow *to_ancestor = to_window;
10739 while (to_ancestor != NULL)
10741 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10742 if (to_ancestor == NULL)
10744 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10747 /* XXX: leave/inferior on root window? */
10749 for (list = to_ancestors; list; list = list->next)
10751 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10752 device, mode, GDK_NOTIFY_VIRTUAL);
10754 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10755 device, mode, GDK_NOTIFY_ANCESTOR);
10757 g_list_free (to_ancestors);
10759 else if (from_window == to_window)
10763 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10764 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10766 while (from_ancestor != NULL || to_ancestor != NULL)
10768 if (from_ancestor != NULL)
10770 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10771 if (from_ancestor == to_window)
10774 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10776 if (to_ancestor != NULL)
10778 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10779 if (to_ancestor == from_window)
10782 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10785 if (to_ancestor == from_window)
10787 if (mode != GDK_CROSSING_GTK_UNGRAB)
10788 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10789 device, mode, GDK_NOTIFY_INFERIOR);
10790 for (list = to_ancestors; list; list = list->next)
10791 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10792 device, mode, GDK_NOTIFY_VIRTUAL);
10793 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10794 device, mode, GDK_NOTIFY_ANCESTOR);
10796 else if (from_ancestor == to_window)
10798 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10799 device, mode, GDK_NOTIFY_ANCESTOR);
10800 for (list = g_list_last (from_ancestors); list; list = list->prev)
10802 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10803 device, mode, GDK_NOTIFY_VIRTUAL);
10805 if (mode != GDK_CROSSING_GTK_GRAB)
10806 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10807 device, mode, GDK_NOTIFY_INFERIOR);
10811 while (from_ancestors != NULL && to_ancestors != NULL
10812 && from_ancestors->data == to_ancestors->data)
10814 from_ancestors = g_list_delete_link (from_ancestors,
10816 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10819 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10820 device, mode, GDK_NOTIFY_NONLINEAR);
10822 for (list = g_list_last (from_ancestors); list; list = list->prev)
10824 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10825 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10827 for (list = to_ancestors; list; list = list->next)
10829 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10830 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10832 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10833 device, mode, GDK_NOTIFY_NONLINEAR);
10835 g_list_free (from_ancestors);
10836 g_list_free (to_ancestors);
10841 gtk_widget_propagate_state (GtkWidget *widget,
10842 GtkStateData *data)
10844 GtkWidgetPrivate *priv = widget->priv;
10845 GtkStateFlags new_flags, old_flags = priv->state_flags;
10846 GtkStateType old_state;
10848 old_state = gtk_widget_get_state (widget);
10850 switch (data->operation)
10852 case STATE_CHANGE_REPLACE:
10853 priv->state_flags = data->flags;
10855 case STATE_CHANGE_SET:
10856 priv->state_flags |= data->flags;
10858 case STATE_CHANGE_UNSET:
10859 priv->state_flags &= ~(data->flags);
10863 /* make insensitivity unoverridable */
10864 if (!priv->sensitive)
10865 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
10867 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10871 window = gtk_widget_get_toplevel (widget);
10873 if (window && gtk_widget_is_toplevel (window))
10874 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10877 new_flags = priv->state_flags;
10879 if (old_flags != new_flags)
10881 g_object_ref (widget);
10883 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10884 gtk_grab_remove (widget);
10886 gtk_style_context_set_state (gtk_widget_get_style_context (widget), new_flags);
10888 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10889 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
10891 if (!priv->shadowed &&
10892 (new_flags & GTK_STATE_FLAG_INSENSITIVE) != (old_flags & GTK_STATE_FLAG_INSENSITIVE))
10894 GList *event_windows = NULL;
10895 GList *devices, *d;
10897 devices = _gtk_widget_list_devices (widget);
10899 for (d = devices; d; d = d->next)
10905 window = _gtk_widget_get_device_window (widget, device);
10907 /* Do not propagate more than once to the
10908 * same window if non-multidevice aware.
10910 if (!gdk_window_get_support_multidevice (window) &&
10911 g_list_find (event_windows, window))
10914 if (!gtk_widget_is_sensitive (widget))
10915 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10916 GDK_CROSSING_STATE_CHANGED);
10918 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10919 GDK_CROSSING_STATE_CHANGED);
10921 event_windows = g_list_prepend (event_windows, window);
10924 g_list_free (event_windows);
10925 g_list_free (devices);
10928 if (GTK_IS_CONTAINER (widget))
10930 GtkStateData child_data = *data;
10932 /* Make sure to only propate the right states further */
10933 child_data.flags &= GTK_STATE_FLAGS_DO_PROPAGATE;
10935 gtk_container_forall (GTK_CONTAINER (widget),
10936 (GtkCallback) gtk_widget_propagate_state,
10940 g_object_unref (widget);
10944 static const GtkWidgetAuxInfo default_aux_info = {
10952 * gtk_widget_get_aux_info:
10953 * @widget: a #GtkWidget
10954 * @create: if %TRUE, create the structure if it doesn't exist
10956 * Get the #GtkWidgetAuxInfo structure for the widget.
10958 * Return value: the #GtkAuxInfo structure for the widget, or
10959 * %NULL if @create is %FALSE and one doesn't already exist.
10961 static GtkWidgetAuxInfo *
10962 gtk_widget_get_aux_info (GtkWidget *widget,
10965 GtkWidgetAuxInfo *aux_info;
10967 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
10968 if (!aux_info && create)
10970 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
10972 *aux_info = default_aux_info;
10974 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
10980 static const GtkWidgetAuxInfo*
10981 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
10983 GtkWidgetAuxInfo *aux_info;
10985 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10986 if (aux_info == NULL)
10988 return &default_aux_info;
10996 /*****************************************
10997 * gtk_widget_aux_info_destroy:
11002 *****************************************/
11005 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11007 g_slice_free (GtkWidgetAuxInfo, aux_info);
11011 * gtk_widget_shape_combine_region:
11012 * @widget: a #GtkWidget
11013 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11015 * Sets a shape for this widget's GDK window. This allows for
11016 * transparent windows etc., see gdk_window_shape_combine_region()
11017 * for more information.
11022 gtk_widget_shape_combine_region (GtkWidget *widget,
11023 cairo_region_t *region)
11025 GtkWidgetPrivate *priv;
11027 g_return_if_fail (GTK_IS_WIDGET (widget));
11028 /* set_shape doesn't work on widgets without gdk window */
11029 g_return_if_fail (gtk_widget_get_has_window (widget));
11031 priv = widget->priv;
11033 if (region == NULL)
11035 priv->has_shape_mask = FALSE;
11038 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11040 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11044 priv->has_shape_mask = TRUE;
11046 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11047 cairo_region_copy (region),
11048 (GDestroyNotify) cairo_region_destroy);
11050 /* set shape if widget has a gdk window already.
11051 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11054 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11059 * gtk_widget_input_shape_combine_region:
11060 * @widget: a #GtkWidget
11061 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11063 * Sets an input shape for this widget's GDK window. This allows for
11064 * windows which react to mouse click in a nonrectangular region, see
11065 * gdk_window_input_shape_combine_region() for more information.
11070 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11071 cairo_region_t *region)
11073 GtkWidgetPrivate *priv;
11075 g_return_if_fail (GTK_IS_WIDGET (widget));
11076 /* set_shape doesn't work on widgets without gdk window */
11077 g_return_if_fail (gtk_widget_get_has_window (widget));
11079 priv = widget->priv;
11081 if (region == NULL)
11084 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11086 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11090 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11091 cairo_region_copy (region),
11092 (GDestroyNotify) cairo_region_destroy);
11094 /* set shape if widget has a gdk window already.
11095 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11098 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11103 /* style properties
11107 * gtk_widget_class_install_style_property_parser: (skip)
11108 * @klass: a #GtkWidgetClass
11109 * @pspec: the #GParamSpec for the style property
11110 * @parser: the parser for the style property
11112 * Installs a style property on a widget class.
11115 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11117 GtkRcPropertyParser parser)
11119 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11120 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11121 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11122 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11124 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11126 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11127 G_OBJECT_CLASS_NAME (klass),
11132 g_param_spec_ref_sink (pspec);
11133 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11134 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11138 * gtk_widget_class_install_style_property:
11139 * @klass: a #GtkWidgetClass
11140 * @pspec: the #GParamSpec for the property
11142 * Installs a style property on a widget class. The parser for the
11143 * style property is determined by the value type of @pspec.
11146 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11149 GtkRcPropertyParser parser;
11151 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11152 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11154 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11156 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11160 * gtk_widget_class_find_style_property:
11161 * @klass: a #GtkWidgetClass
11162 * @property_name: the name of the style property to find
11164 * Finds a style property of a widget class by name.
11166 * Returns: (transfer none): the #GParamSpec of the style property or
11167 * %NULL if @class has no style property with that name.
11172 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11173 const gchar *property_name)
11175 g_return_val_if_fail (property_name != NULL, NULL);
11177 return g_param_spec_pool_lookup (style_property_spec_pool,
11179 G_OBJECT_CLASS_TYPE (klass),
11184 * gtk_widget_class_list_style_properties:
11185 * @klass: a #GtkWidgetClass
11186 * @n_properties: location to return the number of style properties found
11188 * Returns all style properties of a widget class.
11190 * Returns: (array length=n_properties) (transfer container): a
11191 * newly allocated array of #GParamSpec*. The array must be
11192 * freed with g_free().
11197 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11198 guint *n_properties)
11200 GParamSpec **pspecs;
11203 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11204 G_OBJECT_CLASS_TYPE (klass),
11213 * gtk_widget_style_get_property:
11214 * @widget: a #GtkWidget
11215 * @property_name: the name of a style property
11216 * @value: location to return the property value
11218 * Gets the value of a style property of @widget.
11221 gtk_widget_style_get_property (GtkWidget *widget,
11222 const gchar *property_name,
11227 g_return_if_fail (GTK_IS_WIDGET (widget));
11228 g_return_if_fail (property_name != NULL);
11229 g_return_if_fail (G_IS_VALUE (value));
11231 g_object_ref (widget);
11232 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11234 G_OBJECT_TYPE (widget),
11237 g_warning ("%s: widget class `%s' has no property named `%s'",
11239 G_OBJECT_TYPE_NAME (widget),
11243 GtkStyleContext *context;
11244 const GValue *peek_value;
11245 GtkStateFlags state;
11247 context = gtk_widget_get_style_context (widget);
11248 state = gtk_widget_get_state_flags (widget);
11250 peek_value = _gtk_style_context_peek_style_property (context,
11251 G_OBJECT_TYPE (widget),
11254 /* auto-conversion of the caller's value type
11256 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11257 g_value_copy (peek_value, value);
11258 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11259 g_value_transform (peek_value, value);
11261 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11263 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11264 G_VALUE_TYPE_NAME (value));
11266 g_object_unref (widget);
11270 * gtk_widget_style_get_valist:
11271 * @widget: a #GtkWidget
11272 * @first_property_name: the name of the first property to get
11273 * @var_args: a <type>va_list</type> of pairs of property names and
11274 * locations to return the property values, starting with the location
11275 * for @first_property_name.
11277 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11281 gtk_widget_style_get_valist (GtkWidget *widget,
11282 const gchar *first_property_name,
11285 GtkStyleContext *context;
11286 GtkStateFlags state;
11289 g_return_if_fail (GTK_IS_WIDGET (widget));
11291 g_object_ref (widget);
11292 context = gtk_widget_get_style_context (widget);
11293 state = gtk_widget_get_state_flags (widget);
11295 name = first_property_name;
11298 const GValue *peek_value;
11302 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11304 G_OBJECT_TYPE (widget),
11308 g_warning ("%s: widget class `%s' has no property named `%s'",
11310 G_OBJECT_TYPE_NAME (widget),
11314 /* style pspecs are always readable so we can spare that check here */
11316 peek_value = _gtk_style_context_peek_style_property (context,
11317 G_OBJECT_TYPE (widget),
11320 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11323 g_warning ("%s: %s", G_STRLOC, error);
11328 name = va_arg (var_args, gchar*);
11331 g_object_unref (widget);
11335 * gtk_widget_style_get:
11336 * @widget: a #GtkWidget
11337 * @first_property_name: the name of the first property to get
11338 * @...: pairs of property names and locations to return the
11339 * property values, starting with the location for
11340 * @first_property_name, terminated by %NULL.
11342 * Gets the values of a multiple style properties of @widget.
11345 gtk_widget_style_get (GtkWidget *widget,
11346 const gchar *first_property_name,
11351 g_return_if_fail (GTK_IS_WIDGET (widget));
11353 va_start (var_args, first_property_name);
11354 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11359 * gtk_requisition_new:
11361 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11363 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11364 * be freed with gtk_requisition_free().
11369 gtk_requisition_new (void)
11371 return g_slice_new0 (GtkRequisition);
11375 * gtk_requisition_copy:
11376 * @requisition: a #GtkRequisition
11378 * Copies a #GtkRequisition.
11380 * Returns: a copy of @requisition
11383 gtk_requisition_copy (const GtkRequisition *requisition)
11385 return g_slice_dup (GtkRequisition, requisition);
11389 * gtk_requisition_free:
11390 * @requisition: a #GtkRequisition
11392 * Frees a #GtkRequisition.
11395 gtk_requisition_free (GtkRequisition *requisition)
11397 g_slice_free (GtkRequisition, requisition);
11400 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11401 gtk_requisition_copy,
11402 gtk_requisition_free)
11405 * gtk_widget_class_set_accessible_type:
11406 * @widget_class: class to set the accessible type for
11407 * @type: The object type that implements the accessible for @widget_class
11409 * Sets the type to be used for creating accessibles for widgets of
11410 * @widget_class. The given @type must be a subtype of the type used for
11411 * accessibles of the parent class.
11413 * This function should only be called from class init functions of widgets.
11418 gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class,
11421 GtkWidgetClassPrivate *priv;
11423 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11424 g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type));
11426 priv = widget_class->priv;
11428 priv->accessible_type = type;
11429 /* reset this - honoring the type's role is better. */
11430 priv->accessible_role = ATK_ROLE_INVALID;
11434 * gtk_widget_class_set_accessible_role:
11435 * @widget_class: class to set the accessible role for
11436 * @role: The role to use for accessibles created for @widget_class
11438 * Sets the default #AtkRole to be set on accessibles created for
11439 * widgets of @widget_class. Accessibles may decide to not honor this
11440 * setting if their role reporting is more refined. Calls to
11441 * gtk_widget_class_set_accessible_type() will reset this value.
11443 * In cases where you want more fine-grained control over the role of
11444 * accessibles created for @widget_class, you should provide your own
11445 * accessible type and use gtk_widget_class_set_accessible_type()
11448 * If @role is #ATK_ROLE_INVALID, the default role will not be changed
11449 * and the accessible's default role will be used instead.
11451 * This function should only be called from class init functions of widgets.
11456 gtk_widget_class_set_accessible_role (GtkWidgetClass *widget_class,
11459 GtkWidgetClassPrivate *priv;
11461 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11463 priv = widget_class->priv;
11465 priv->accessible_role = role;
11469 * _gtk_widget_peek_accessible:
11470 * @widget: a #GtkWidget
11472 * Gets the accessible for @widget, if it has been created yet.
11473 * Otherwise, this function returns %NULL. If the @widget's implementation
11474 * does not use the default way to create accessibles, %NULL will always be
11477 * Returns: the accessible for @widget or %NULL if none has been
11481 _gtk_widget_peek_accessible (GtkWidget *widget)
11483 return g_object_get_qdata (G_OBJECT (widget),
11484 quark_accessible_object);
11488 * gtk_widget_get_accessible:
11489 * @widget: a #GtkWidget
11491 * Returns the accessible object that describes the widget to an
11492 * assistive technology.
11494 * If accessibility support is not available, this #AtkObject
11495 * instance may be a no-op. Likewise, if no class-specific #AtkObject
11496 * implementation is available for the widget instance in question,
11497 * it will inherit an #AtkObject implementation from the first ancestor
11498 * class for which such an implementation is defined.
11500 * The documentation of the
11501 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
11502 * library contains more information about accessible objects and their uses.
11504 * Returns: (transfer none): the #AtkObject associated with @widget
11507 gtk_widget_get_accessible (GtkWidget *widget)
11509 GtkWidgetClass *klass;
11511 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11513 klass = GTK_WIDGET_GET_CLASS (widget);
11515 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11517 return klass->get_accessible (widget);
11521 gtk_widget_real_get_accessible (GtkWidget *widget)
11523 AtkObject* accessible;
11525 accessible = g_object_get_qdata (G_OBJECT (widget),
11526 quark_accessible_object);
11529 GtkWidgetClass *widget_class;
11530 GtkWidgetClassPrivate *priv;
11531 AtkObjectFactory *factory;
11532 AtkRegistry *default_registry;
11534 widget_class = GTK_WIDGET_GET_CLASS (widget);
11535 priv = widget_class->priv;
11537 if (priv->accessible_type == GTK_TYPE_ACCESSIBLE)
11539 default_registry = atk_get_default_registry ();
11540 factory = atk_registry_get_factory (default_registry,
11541 G_TYPE_FROM_INSTANCE (widget));
11543 atk_object_factory_create_accessible (factory,
11544 G_OBJECT (widget));
11546 if (priv->accessible_role != ATK_ROLE_INVALID)
11547 atk_object_set_role (accessible, priv->accessible_role);
11549 g_object_set_qdata (G_OBJECT (widget),
11550 quark_accessible_object,
11555 accessible = g_object_new (priv->accessible_type,
11558 if (priv->accessible_role != ATK_ROLE_INVALID)
11559 atk_object_set_role (accessible, priv->accessible_role);
11561 g_object_set_qdata (G_OBJECT (widget),
11562 quark_accessible_object,
11565 atk_object_initialize (accessible, widget);
11567 /* Set the role again, since we don't want a role set
11568 * in some parent initialize() function to override
11571 if (priv->accessible_role != ATK_ROLE_INVALID)
11572 atk_object_set_role (accessible, priv->accessible_role);
11579 * Initialize a AtkImplementorIface instance's virtual pointers as
11580 * appropriate to this implementor's class (GtkWidget).
11583 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11585 iface->ref_accessible = gtk_widget_ref_accessible;
11589 gtk_widget_ref_accessible (AtkImplementor *implementor)
11591 AtkObject *accessible;
11593 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11595 g_object_ref (accessible);
11600 * Expand flag management
11604 gtk_widget_update_computed_expand (GtkWidget *widget)
11606 GtkWidgetPrivate *priv;
11608 priv = widget->priv;
11610 if (priv->need_compute_expand)
11614 if (priv->hexpand_set)
11619 if (priv->vexpand_set)
11624 /* we don't need to use compute_expand if both expands are
11625 * forced by the app
11627 if (!(priv->hexpand_set && priv->vexpand_set))
11629 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11633 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11634 priv->hexpand_set ? &ignored : &h,
11635 priv->vexpand_set ? &ignored : &v);
11639 priv->need_compute_expand = FALSE;
11640 priv->computed_hexpand = h != FALSE;
11641 priv->computed_vexpand = v != FALSE;
11646 * gtk_widget_queue_compute_expand:
11647 * @widget: a #GtkWidget
11649 * Mark @widget as needing to recompute its expand flags. Call
11650 * this function when setting legacy expand child properties
11651 * on the child of a container.
11653 * See gtk_widget_compute_expand().
11656 gtk_widget_queue_compute_expand (GtkWidget *widget)
11659 gboolean changed_anything;
11661 if (widget->priv->need_compute_expand)
11664 changed_anything = FALSE;
11666 while (parent != NULL)
11668 if (!parent->priv->need_compute_expand)
11670 parent->priv->need_compute_expand = TRUE;
11671 changed_anything = TRUE;
11674 /* Note: if we had an invariant that "if a child needs to
11675 * compute expand, its parents also do" then we could stop going
11676 * up when we got to a parent that already needed to
11677 * compute. However, in general we compute expand lazily (as
11678 * soon as we see something in a subtree that is expand, we know
11679 * we're expanding) and so this invariant does not hold and we
11680 * have to always walk all the way up in case some ancestor
11681 * is not currently need_compute_expand.
11684 parent = parent->priv->parent;
11687 /* recomputing expand always requires
11688 * a relayout as well
11690 if (changed_anything)
11691 gtk_widget_queue_resize (widget);
11695 * gtk_widget_compute_expand:
11696 * @widget: the widget
11697 * @orientation: expand direction
11699 * Computes whether a container should give this widget extra space
11700 * when possible. Containers should check this, rather than
11701 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11703 * This function already checks whether the widget is visible, so
11704 * visibility does not need to be checked separately. Non-visible
11705 * widgets are not expanded.
11707 * The computed expand value uses either the expand setting explicitly
11708 * set on the widget itself, or, if none has been explicitly set,
11709 * the widget may expand if some of its children do.
11711 * Return value: whether widget tree rooted here should be expanded
11714 gtk_widget_compute_expand (GtkWidget *widget,
11715 GtkOrientation orientation)
11717 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11719 /* We never make a widget expand if not even showing. */
11720 if (!gtk_widget_get_visible (widget))
11723 gtk_widget_update_computed_expand (widget);
11725 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11727 return widget->priv->computed_hexpand;
11731 return widget->priv->computed_vexpand;
11736 gtk_widget_set_expand (GtkWidget *widget,
11737 GtkOrientation orientation,
11740 const char *expand_prop;
11741 const char *expand_set_prop;
11743 GtkWidgetPrivate *priv;
11745 g_return_if_fail (GTK_IS_WIDGET (widget));
11747 priv = widget->priv;
11749 expand = expand != FALSE;
11751 was_both = priv->hexpand && priv->vexpand;
11753 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11755 if (priv->hexpand_set &&
11756 priv->hexpand == expand)
11759 priv->hexpand_set = TRUE;
11760 priv->hexpand = expand;
11762 expand_prop = "hexpand";
11763 expand_set_prop = "hexpand-set";
11767 if (priv->vexpand_set &&
11768 priv->vexpand == expand)
11771 priv->vexpand_set = TRUE;
11772 priv->vexpand = expand;
11774 expand_prop = "vexpand";
11775 expand_set_prop = "vexpand-set";
11778 gtk_widget_queue_compute_expand (widget);
11780 g_object_freeze_notify (G_OBJECT (widget));
11781 g_object_notify (G_OBJECT (widget), expand_prop);
11782 g_object_notify (G_OBJECT (widget), expand_set_prop);
11783 if (was_both != (priv->hexpand && priv->vexpand))
11784 g_object_notify (G_OBJECT (widget), "expand");
11785 g_object_thaw_notify (G_OBJECT (widget));
11789 gtk_widget_set_expand_set (GtkWidget *widget,
11790 GtkOrientation orientation,
11793 GtkWidgetPrivate *priv;
11796 priv = widget->priv;
11798 set = set != FALSE;
11800 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11802 if (set == priv->hexpand_set)
11805 priv->hexpand_set = set;
11806 prop = "hexpand-set";
11810 if (set == priv->vexpand_set)
11813 priv->vexpand_set = set;
11814 prop = "vexpand-set";
11817 gtk_widget_queue_compute_expand (widget);
11819 g_object_notify (G_OBJECT (widget), prop);
11823 * gtk_widget_get_hexpand:
11824 * @widget: the widget
11826 * Gets whether the widget would like any available extra horizontal
11827 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11828 * generally receive the extra space. For example, a list or
11829 * scrollable area or document in your window would often be set to
11832 * Containers should use gtk_widget_compute_expand() rather than
11833 * this function, to see whether a widget, or any of its children,
11834 * has the expand flag set. If any child of a widget wants to
11835 * expand, the parent may ask to expand also.
11837 * This function only looks at the widget's own hexpand flag, rather
11838 * than computing whether the entire widget tree rooted at this widget
11841 * Return value: whether hexpand flag is set
11844 gtk_widget_get_hexpand (GtkWidget *widget)
11846 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11848 return widget->priv->hexpand;
11852 * gtk_widget_set_hexpand:
11853 * @widget: the widget
11854 * @expand: whether to expand
11856 * Sets whether the widget would like any available extra horizontal
11857 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11858 * generally receive the extra space. For example, a list or
11859 * scrollable area or document in your window would often be set to
11862 * Call this function to set the expand flag if you would like your
11863 * widget to become larger horizontally when the window has extra
11866 * By default, widgets automatically expand if any of their children
11867 * want to expand. (To see if a widget will automatically expand given
11868 * its current children and state, call gtk_widget_compute_expand(). A
11869 * container can decide how the expandability of children affects the
11870 * expansion of the container by overriding the compute_expand virtual
11871 * method on #GtkWidget.).
11873 * Setting hexpand explicitly with this function will override the
11874 * automatic expand behavior.
11876 * This function forces the widget to expand or not to expand,
11877 * regardless of children. The override occurs because
11878 * gtk_widget_set_hexpand() sets the hexpand-set property (see
11879 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
11880 * value to be used, rather than looking at children and widget state.
11883 gtk_widget_set_hexpand (GtkWidget *widget,
11886 g_return_if_fail (GTK_IS_WIDGET (widget));
11888 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
11892 * gtk_widget_get_hexpand_set:
11893 * @widget: the widget
11895 * Gets whether gtk_widget_set_hexpand() has been used to
11896 * explicitly set the expand flag on this widget.
11898 * If hexpand is set, then it overrides any computed
11899 * expand value based on child widgets. If hexpand is not
11900 * set, then the expand value depends on whether any
11901 * children of the widget would like to expand.
11903 * There are few reasons to use this function, but it's here
11904 * for completeness and consistency.
11906 * Return value: whether hexpand has been explicitly set
11909 gtk_widget_get_hexpand_set (GtkWidget *widget)
11911 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11913 return widget->priv->hexpand_set;
11917 * gtk_widget_set_hexpand_set:
11918 * @widget: the widget
11919 * @set: value for hexpand-set property
11921 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
11924 * The hexpand-set property will be set automatically when you call
11925 * gtk_widget_set_hexpand() to set hexpand, so the most likely
11926 * reason to use this function would be to unset an explicit expand
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.
11938 gtk_widget_set_hexpand_set (GtkWidget *widget,
11941 g_return_if_fail (GTK_IS_WIDGET (widget));
11943 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
11948 * gtk_widget_get_vexpand:
11949 * @widget: the widget
11951 * Gets whether the widget would like any available extra vertical
11954 * See gtk_widget_get_hexpand() for more detail.
11956 * Return value: whether vexpand flag is set
11959 gtk_widget_get_vexpand (GtkWidget *widget)
11961 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11963 return widget->priv->vexpand;
11967 * gtk_widget_set_vexpand:
11968 * @widget: the widget
11969 * @expand: whether to expand
11971 * Sets whether the widget would like any available extra vertical
11974 * See gtk_widget_set_hexpand() for more detail.
11977 gtk_widget_set_vexpand (GtkWidget *widget,
11980 g_return_if_fail (GTK_IS_WIDGET (widget));
11982 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
11986 * gtk_widget_get_vexpand_set:
11987 * @widget: the widget
11989 * Gets whether gtk_widget_set_vexpand() has been used to
11990 * explicitly set the expand flag on this widget.
11992 * See gtk_widget_get_hexpand_set() for more detail.
11994 * Return value: whether vexpand has been explicitly set
11997 gtk_widget_get_vexpand_set (GtkWidget *widget)
11999 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12001 return widget->priv->vexpand_set;
12005 * gtk_widget_set_vexpand_set:
12006 * @widget: the widget
12007 * @set: value for vexpand-set property
12009 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12012 * See gtk_widget_set_hexpand_set() for more detail.
12015 gtk_widget_set_vexpand_set (GtkWidget *widget,
12018 g_return_if_fail (GTK_IS_WIDGET (widget));
12020 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12024 * GtkBuildable implementation
12026 static GQuark quark_builder_has_default = 0;
12027 static GQuark quark_builder_has_focus = 0;
12028 static GQuark quark_builder_atk_relations = 0;
12029 static GQuark quark_builder_set_name = 0;
12032 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12034 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12035 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12036 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12037 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12039 iface->set_name = gtk_widget_buildable_set_name;
12040 iface->get_name = gtk_widget_buildable_get_name;
12041 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12042 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12043 iface->parser_finished = gtk_widget_buildable_parser_finished;
12044 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12045 iface->custom_finished = gtk_widget_buildable_custom_finished;
12049 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12052 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12053 g_strdup (name), g_free);
12056 static const gchar *
12057 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12059 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12063 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12064 GtkBuilder *builder,
12065 const gchar *childname)
12067 if (strcmp (childname, "accessible") == 0)
12068 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12074 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12075 GtkBuilder *builder,
12077 const GValue *value)
12079 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12080 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12081 GINT_TO_POINTER (TRUE));
12082 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12083 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12084 GINT_TO_POINTER (TRUE));
12086 g_object_set_property (G_OBJECT (buildable), name, value);
12091 gchar *action_name;
12092 GString *description;
12094 gboolean translatable;
12104 free_action (AtkActionData *data, gpointer user_data)
12106 g_free (data->action_name);
12107 g_string_free (data->description, TRUE);
12108 g_free (data->context);
12109 g_slice_free (AtkActionData, data);
12113 free_relation (AtkRelationData *data, gpointer user_data)
12115 g_free (data->target);
12116 g_free (data->type);
12117 g_slice_free (AtkRelationData, data);
12121 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12122 GtkBuilder *builder)
12124 GSList *atk_relations;
12126 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12127 gtk_widget_grab_default (GTK_WIDGET (buildable));
12128 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12129 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12131 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12132 quark_builder_atk_relations);
12135 AtkObject *accessible;
12136 AtkRelationSet *relation_set;
12139 AtkRelationType relation_type;
12140 AtkObject *target_accessible;
12142 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12143 relation_set = atk_object_ref_relation_set (accessible);
12145 for (l = atk_relations; l; l = l->next)
12147 AtkRelationData *relation = (AtkRelationData*)l->data;
12149 target = gtk_builder_get_object (builder, relation->target);
12152 g_warning ("Target object %s in <relation> does not exist",
12156 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12157 g_assert (target_accessible != NULL);
12159 relation_type = atk_relation_type_for_name (relation->type);
12160 if (relation_type == ATK_RELATION_NULL)
12162 g_warning ("<relation> type %s not found",
12166 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12167 target_accessible);
12169 g_object_unref (relation_set);
12171 g_slist_free_full (atk_relations, (GDestroyNotify) free_relation);
12172 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12181 } AccessibilitySubParserData;
12184 accessibility_start_element (GMarkupParseContext *context,
12185 const gchar *element_name,
12186 const gchar **names,
12187 const gchar **values,
12188 gpointer user_data,
12191 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12193 gint line_number, char_number;
12195 if (strcmp (element_name, "relation") == 0)
12197 gchar *target = NULL;
12198 gchar *type = NULL;
12199 AtkRelationData *relation;
12201 for (i = 0; names[i]; i++)
12203 if (strcmp (names[i], "target") == 0)
12204 target = g_strdup (values[i]);
12205 else if (strcmp (names[i], "type") == 0)
12206 type = g_strdup (values[i]);
12209 g_markup_parse_context_get_position (context,
12212 g_set_error (error,
12214 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12215 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12217 line_number, char_number, names[i], "relation");
12224 if (!target || !type)
12226 g_markup_parse_context_get_position (context,
12229 g_set_error (error,
12231 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12232 "%s:%d:%d <%s> requires attribute \"%s\"",
12234 line_number, char_number, "relation",
12235 type ? "target" : "type");
12241 relation = g_slice_new (AtkRelationData);
12242 relation->target = target;
12243 relation->type = type;
12245 data->relations = g_slist_prepend (data->relations, relation);
12247 else if (strcmp (element_name, "action") == 0)
12249 const gchar *action_name = NULL;
12250 const gchar *description = NULL;
12251 const gchar *msg_context = NULL;
12252 gboolean translatable = FALSE;
12253 AtkActionData *action;
12255 for (i = 0; names[i]; i++)
12257 if (strcmp (names[i], "action_name") == 0)
12258 action_name = values[i];
12259 else if (strcmp (names[i], "description") == 0)
12260 description = values[i];
12261 else if (strcmp (names[i], "translatable") == 0)
12263 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12266 else if (strcmp (names[i], "comments") == 0)
12268 /* do nothing, comments are for translators */
12270 else if (strcmp (names[i], "context") == 0)
12271 msg_context = values[i];
12274 g_markup_parse_context_get_position (context,
12277 g_set_error (error,
12279 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12280 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12282 line_number, char_number, names[i], "action");
12289 g_markup_parse_context_get_position (context,
12292 g_set_error (error,
12294 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12295 "%s:%d:%d <%s> requires attribute \"%s\"",
12297 line_number, char_number, "action",
12302 action = g_slice_new (AtkActionData);
12303 action->action_name = g_strdup (action_name);
12304 action->description = g_string_new (description);
12305 action->context = g_strdup (msg_context);
12306 action->translatable = translatable;
12308 data->actions = g_slist_prepend (data->actions, action);
12310 else if (strcmp (element_name, "accessibility") == 0)
12313 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12317 accessibility_text (GMarkupParseContext *context,
12320 gpointer user_data,
12323 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12325 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12327 AtkActionData *action = data->actions->data;
12329 g_string_append_len (action->description, text, text_len);
12333 static const GMarkupParser accessibility_parser =
12335 accessibility_start_element,
12337 accessibility_text,
12346 } AccelGroupParserData;
12349 accel_group_start_element (GMarkupParseContext *context,
12350 const gchar *element_name,
12351 const gchar **names,
12352 const gchar **values,
12353 gpointer user_data,
12358 guint modifiers = 0;
12359 gchar *signal = NULL;
12360 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12362 for (i = 0; names[i]; i++)
12364 if (strcmp (names[i], "key") == 0)
12365 key = gdk_keyval_from_name (values[i]);
12366 else if (strcmp (names[i], "modifiers") == 0)
12368 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12374 else if (strcmp (names[i], "signal") == 0)
12375 signal = g_strdup (values[i]);
12378 if (key == 0 || signal == NULL)
12380 g_warning ("<accelerator> requires key and signal attributes");
12383 parser_data->key = key;
12384 parser_data->modifiers = modifiers;
12385 parser_data->signal = signal;
12388 static const GMarkupParser accel_group_parser =
12390 accel_group_start_element,
12399 style_start_element (GMarkupParseContext *context,
12400 const gchar *element_name,
12401 const gchar **names,
12402 const gchar **values,
12403 gpointer user_data,
12406 StyleParserData *style_data = (StyleParserData *)user_data;
12409 if (strcmp (element_name, "class") == 0)
12411 if (g_markup_collect_attributes (element_name,
12415 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12416 G_MARKUP_COLLECT_INVALID))
12418 style_data->classes = g_slist_append (style_data->classes, class_name);
12421 else if (strcmp (element_name, "style") == 0)
12424 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12427 static const GMarkupParser style_parser =
12429 style_start_element,
12433 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12434 GtkBuilder *builder,
12436 const gchar *tagname,
12437 GMarkupParser *parser,
12440 g_assert (buildable);
12442 if (strcmp (tagname, "accelerator") == 0)
12444 AccelGroupParserData *parser_data;
12446 parser_data = g_slice_new0 (AccelGroupParserData);
12447 parser_data->object = g_object_ref (buildable);
12448 *parser = accel_group_parser;
12449 *data = parser_data;
12452 if (strcmp (tagname, "accessibility") == 0)
12454 AccessibilitySubParserData *parser_data;
12456 parser_data = g_slice_new0 (AccessibilitySubParserData);
12457 *parser = accessibility_parser;
12458 *data = parser_data;
12461 if (strcmp (tagname, "style") == 0)
12463 StyleParserData *parser_data;
12465 parser_data = g_slice_new0 (StyleParserData);
12466 *parser = style_parser;
12467 *data = parser_data;
12475 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12476 GtkWidget *toplevel,
12477 gpointer user_data)
12479 AccelGroupParserData *accel_data;
12480 GSList *accel_groups;
12481 GtkAccelGroup *accel_group;
12483 g_return_if_fail (GTK_IS_WIDGET (widget));
12484 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12485 g_return_if_fail (user_data != NULL);
12487 accel_data = (AccelGroupParserData*)user_data;
12488 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12489 if (g_slist_length (accel_groups) == 0)
12491 accel_group = gtk_accel_group_new ();
12492 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12496 g_assert (g_slist_length (accel_groups) == 1);
12497 accel_group = g_slist_nth_data (accel_groups, 0);
12500 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12501 accel_data->signal,
12504 accel_data->modifiers,
12505 GTK_ACCEL_VISIBLE);
12507 g_object_unref (accel_data->object);
12508 g_free (accel_data->signal);
12509 g_slice_free (AccelGroupParserData, accel_data);
12513 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12514 GtkBuilder *builder,
12516 const gchar *tagname,
12517 gpointer user_data)
12519 if (strcmp (tagname, "accelerator") == 0)
12521 AccelGroupParserData *accel_data;
12522 GtkWidget *toplevel;
12524 accel_data = (AccelGroupParserData*)user_data;
12525 g_assert (accel_data->object);
12527 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12529 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12531 else if (strcmp (tagname, "accessibility") == 0)
12533 AccessibilitySubParserData *a11y_data;
12535 a11y_data = (AccessibilitySubParserData*)user_data;
12537 if (a11y_data->actions)
12539 AtkObject *accessible;
12544 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12546 if (ATK_IS_ACTION (accessible))
12548 action = ATK_ACTION (accessible);
12549 n_actions = atk_action_get_n_actions (action);
12551 for (l = a11y_data->actions; l; l = l->next)
12553 AtkActionData *action_data = (AtkActionData*)l->data;
12555 for (i = 0; i < n_actions; i++)
12556 if (strcmp (atk_action_get_name (action, i),
12557 action_data->action_name) == 0)
12562 gchar *description;
12564 if (action_data->translatable && action_data->description->len)
12565 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12566 action_data->context,
12567 action_data->description->str);
12569 description = action_data->description->str;
12571 atk_action_set_description (action, i, description);
12576 g_warning ("accessibility action on a widget that does not implement AtkAction");
12578 g_slist_free_full (a11y_data->actions, (GDestroyNotify) free_action);
12581 if (a11y_data->relations)
12582 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12583 a11y_data->relations);
12585 g_slice_free (AccessibilitySubParserData, a11y_data);
12587 else if (strcmp (tagname, "style") == 0)
12589 StyleParserData *style_data = (StyleParserData *)user_data;
12590 GtkStyleContext *context;
12593 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
12595 for (l = style_data->classes; l; l = l->next)
12596 gtk_style_context_add_class (context, (const gchar *)l->data);
12598 gtk_widget_reset_style (GTK_WIDGET (buildable));
12600 g_slist_free_full (style_data->classes, g_free);
12601 g_slice_free (StyleParserData, style_data);
12605 static GtkSizeRequestMode
12606 gtk_widget_real_get_request_mode (GtkWidget *widget)
12608 /* By default widgets dont trade size at all. */
12609 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
12613 gtk_widget_real_get_width (GtkWidget *widget,
12614 gint *minimum_size,
12615 gint *natural_size)
12625 gtk_widget_real_get_height (GtkWidget *widget,
12626 gint *minimum_size,
12627 gint *natural_size)
12637 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12639 gint *minimum_height,
12640 gint *natural_height)
12642 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12646 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12648 gint *minimum_width,
12649 gint *natural_width)
12651 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12655 * gtk_widget_get_halign:
12656 * @widget: a #GtkWidget
12658 * Gets the value of the #GtkWidget:halign property.
12660 * Returns: the horizontal alignment of @widget
12663 gtk_widget_get_halign (GtkWidget *widget)
12665 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12666 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12670 * gtk_widget_set_halign:
12671 * @widget: a #GtkWidget
12672 * @align: the horizontal alignment
12674 * Sets the horizontal alignment of @widget.
12675 * See the #GtkWidget:halign property.
12678 gtk_widget_set_halign (GtkWidget *widget,
12681 GtkWidgetAuxInfo *aux_info;
12683 g_return_if_fail (GTK_IS_WIDGET (widget));
12685 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12687 if (aux_info->halign == align)
12690 aux_info->halign = align;
12691 gtk_widget_queue_resize (widget);
12692 g_object_notify (G_OBJECT (widget), "halign");
12696 * gtk_widget_get_valign:
12697 * @widget: a #GtkWidget
12699 * Gets the value of the #GtkWidget:valign property.
12701 * Returns: the vertical alignment of @widget
12704 gtk_widget_get_valign (GtkWidget *widget)
12706 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12707 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12711 * gtk_widget_set_valign:
12712 * @widget: a #GtkWidget
12713 * @align: the vertical alignment
12715 * Sets the vertical alignment of @widget.
12716 * See the #GtkWidget:valign property.
12719 gtk_widget_set_valign (GtkWidget *widget,
12722 GtkWidgetAuxInfo *aux_info;
12724 g_return_if_fail (GTK_IS_WIDGET (widget));
12726 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12728 if (aux_info->valign == align)
12731 aux_info->valign = align;
12732 gtk_widget_queue_resize (widget);
12733 g_object_notify (G_OBJECT (widget), "valign");
12737 * gtk_widget_get_margin_left:
12738 * @widget: a #GtkWidget
12740 * Gets the value of the #GtkWidget:margin-left property.
12742 * Returns: The left margin of @widget
12747 gtk_widget_get_margin_left (GtkWidget *widget)
12749 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12751 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12755 * gtk_widget_set_margin_left:
12756 * @widget: a #GtkWidget
12757 * @margin: the left margin
12759 * Sets the left margin of @widget.
12760 * See the #GtkWidget:margin-left property.
12765 gtk_widget_set_margin_left (GtkWidget *widget,
12768 GtkWidgetAuxInfo *aux_info;
12770 g_return_if_fail (GTK_IS_WIDGET (widget));
12771 g_return_if_fail (margin <= G_MAXINT16);
12773 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12775 if (aux_info->margin.left == margin)
12778 aux_info->margin.left = margin;
12779 gtk_widget_queue_resize (widget);
12780 g_object_notify (G_OBJECT (widget), "margin-left");
12784 * gtk_widget_get_margin_right:
12785 * @widget: a #GtkWidget
12787 * Gets the value of the #GtkWidget:margin-right property.
12789 * Returns: The right margin of @widget
12794 gtk_widget_get_margin_right (GtkWidget *widget)
12796 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12798 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12802 * gtk_widget_set_margin_right:
12803 * @widget: a #GtkWidget
12804 * @margin: the right margin
12806 * Sets the right margin of @widget.
12807 * See the #GtkWidget:margin-right property.
12812 gtk_widget_set_margin_right (GtkWidget *widget,
12815 GtkWidgetAuxInfo *aux_info;
12817 g_return_if_fail (GTK_IS_WIDGET (widget));
12818 g_return_if_fail (margin <= G_MAXINT16);
12820 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12822 if (aux_info->margin.right == margin)
12825 aux_info->margin.right = margin;
12826 gtk_widget_queue_resize (widget);
12827 g_object_notify (G_OBJECT (widget), "margin-right");
12831 * gtk_widget_get_margin_top:
12832 * @widget: a #GtkWidget
12834 * Gets the value of the #GtkWidget:margin-top property.
12836 * Returns: The top margin of @widget
12841 gtk_widget_get_margin_top (GtkWidget *widget)
12843 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12845 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12849 * gtk_widget_set_margin_top:
12850 * @widget: a #GtkWidget
12851 * @margin: the top margin
12853 * Sets the top margin of @widget.
12854 * See the #GtkWidget:margin-top property.
12859 gtk_widget_set_margin_top (GtkWidget *widget,
12862 GtkWidgetAuxInfo *aux_info;
12864 g_return_if_fail (GTK_IS_WIDGET (widget));
12865 g_return_if_fail (margin <= G_MAXINT16);
12867 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12869 if (aux_info->margin.top == margin)
12872 aux_info->margin.top = margin;
12873 gtk_widget_queue_resize (widget);
12874 g_object_notify (G_OBJECT (widget), "margin-top");
12878 * gtk_widget_get_margin_bottom:
12879 * @widget: a #GtkWidget
12881 * Gets the value of the #GtkWidget:margin-bottom property.
12883 * Returns: The bottom margin of @widget
12888 gtk_widget_get_margin_bottom (GtkWidget *widget)
12890 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12892 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
12896 * gtk_widget_set_margin_bottom:
12897 * @widget: a #GtkWidget
12898 * @margin: the bottom margin
12900 * Sets the bottom margin of @widget.
12901 * See the #GtkWidget:margin-bottom property.
12906 gtk_widget_set_margin_bottom (GtkWidget *widget,
12909 GtkWidgetAuxInfo *aux_info;
12911 g_return_if_fail (GTK_IS_WIDGET (widget));
12912 g_return_if_fail (margin <= G_MAXINT16);
12914 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12916 if (aux_info->margin.bottom == margin)
12919 aux_info->margin.bottom = margin;
12920 gtk_widget_queue_resize (widget);
12921 g_object_notify (G_OBJECT (widget), "margin-bottom");
12925 * gtk_widget_get_clipboard:
12926 * @widget: a #GtkWidget
12927 * @selection: a #GdkAtom which identifies the clipboard
12928 * to use. %GDK_SELECTION_CLIPBOARD gives the
12929 * default clipboard. Another common value
12930 * is %GDK_SELECTION_PRIMARY, which gives
12931 * the primary X selection.
12933 * Returns the clipboard object for the given selection to
12934 * be used with @widget. @widget must have a #GdkDisplay
12935 * associated with it, so must be attached to a toplevel
12938 * Return value: (transfer none): the appropriate clipboard object. If no
12939 * clipboard already exists, a new one will
12940 * be created. Once a clipboard object has
12941 * been created, it is persistent for all time.
12946 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
12948 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12949 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
12951 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
12956 * gtk_widget_list_mnemonic_labels:
12957 * @widget: a #GtkWidget
12959 * Returns a newly allocated list of the widgets, normally labels, for
12960 * which this widget is the target of a mnemonic (see for example,
12961 * gtk_label_set_mnemonic_widget()).
12963 * The widgets in the list are not individually referenced. If you
12964 * want to iterate through the list and perform actions involving
12965 * callbacks that might destroy the widgets, you
12966 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
12967 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
12968 * widgets afterwards.
12970 * Return value: (element-type GtkWidget) (transfer container): the list of
12971 * mnemonic labels; free this list
12972 * with g_list_free() when you are done with it.
12977 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
12979 GList *list = NULL;
12982 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12984 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
12985 list = g_list_prepend (list, l->data);
12991 * gtk_widget_add_mnemonic_label:
12992 * @widget: a #GtkWidget
12993 * @label: a #GtkWidget that acts as a mnemonic label for @widget
12995 * Adds a widget to the list of mnemonic labels for
12996 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
12997 * list of mnemonic labels for the widget is cleared when the
12998 * widget is destroyed, so the caller must make sure to update
12999 * its internal state at this point as well, by using a connection
13000 * to the #GtkWidget::destroy signal or a weak notifier.
13005 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13008 GSList *old_list, *new_list;
13010 g_return_if_fail (GTK_IS_WIDGET (widget));
13011 g_return_if_fail (GTK_IS_WIDGET (label));
13013 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13014 new_list = g_slist_prepend (old_list, label);
13016 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13017 new_list, (GDestroyNotify) g_slist_free);
13021 * gtk_widget_remove_mnemonic_label:
13022 * @widget: a #GtkWidget
13023 * @label: a #GtkWidget that was previously set as a mnemnic label for
13024 * @widget with gtk_widget_add_mnemonic_label().
13026 * Removes a widget from the list of mnemonic labels for
13027 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13028 * must have previously been added to the list with
13029 * gtk_widget_add_mnemonic_label().
13034 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13037 GSList *old_list, *new_list;
13039 g_return_if_fail (GTK_IS_WIDGET (widget));
13040 g_return_if_fail (GTK_IS_WIDGET (label));
13042 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13043 new_list = g_slist_remove (old_list, label);
13046 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13047 new_list, (GDestroyNotify) g_slist_free);
13051 * gtk_widget_get_no_show_all:
13052 * @widget: a #GtkWidget
13054 * Returns the current value of the #GtkWidget:no-show-all property,
13055 * which determines whether calls to gtk_widget_show_all()
13056 * will affect this widget.
13058 * Return value: the current value of the "no-show-all" property.
13063 gtk_widget_get_no_show_all (GtkWidget *widget)
13065 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13067 return widget->priv->no_show_all;
13071 * gtk_widget_set_no_show_all:
13072 * @widget: a #GtkWidget
13073 * @no_show_all: the new value for the "no-show-all" property
13075 * Sets the #GtkWidget:no-show-all property, which determines whether
13076 * calls to gtk_widget_show_all() will affect this widget.
13078 * This is mostly for use in constructing widget hierarchies with externally
13079 * controlled visibility, see #GtkUIManager.
13084 gtk_widget_set_no_show_all (GtkWidget *widget,
13085 gboolean no_show_all)
13087 g_return_if_fail (GTK_IS_WIDGET (widget));
13089 no_show_all = (no_show_all != FALSE);
13091 if (widget->priv->no_show_all != no_show_all)
13093 widget->priv->no_show_all = no_show_all;
13095 g_object_notify (G_OBJECT (widget), "no-show-all");
13101 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13102 gboolean has_tooltip,
13105 GtkWidgetPrivate *priv = widget->priv;
13106 gboolean priv_has_tooltip;
13108 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13109 quark_has_tooltip));
13111 if (priv_has_tooltip != has_tooltip || force)
13113 priv_has_tooltip = has_tooltip;
13115 if (priv_has_tooltip)
13117 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13118 gdk_window_set_events (priv->window,
13119 gdk_window_get_events (priv->window) |
13120 GDK_LEAVE_NOTIFY_MASK |
13121 GDK_POINTER_MOTION_MASK |
13122 GDK_POINTER_MOTION_HINT_MASK);
13124 if (gtk_widget_get_has_window (widget))
13125 gtk_widget_add_events (widget,
13126 GDK_LEAVE_NOTIFY_MASK |
13127 GDK_POINTER_MOTION_MASK |
13128 GDK_POINTER_MOTION_HINT_MASK);
13131 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13132 GUINT_TO_POINTER (priv_has_tooltip));
13137 * gtk_widget_set_tooltip_window:
13138 * @widget: a #GtkWidget
13139 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13141 * Replaces the default, usually yellow, window used for displaying
13142 * tooltips with @custom_window. GTK+ will take care of showing and
13143 * hiding @custom_window at the right moment, to behave likewise as
13144 * the default tooltip window. If @custom_window is %NULL, the default
13145 * tooltip window will be used.
13147 * If the custom window should have the default theming it needs to
13148 * have the name "gtk-tooltip", see gtk_widget_set_name().
13153 gtk_widget_set_tooltip_window (GtkWidget *widget,
13154 GtkWindow *custom_window)
13156 gboolean has_tooltip;
13157 gchar *tooltip_markup;
13159 g_return_if_fail (GTK_IS_WIDGET (widget));
13160 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13162 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13165 g_object_ref (custom_window);
13167 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13168 custom_window, g_object_unref);
13170 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13171 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13173 if (has_tooltip && gtk_widget_get_visible (widget))
13174 gtk_widget_queue_tooltip_query (widget);
13178 * gtk_widget_get_tooltip_window:
13179 * @widget: a #GtkWidget
13181 * Returns the #GtkWindow of the current tooltip. This can be the
13182 * GtkWindow created by default, or the custom tooltip window set
13183 * using gtk_widget_set_tooltip_window().
13185 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13190 gtk_widget_get_tooltip_window (GtkWidget *widget)
13192 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13194 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13198 * gtk_widget_trigger_tooltip_query:
13199 * @widget: a #GtkWidget
13201 * Triggers a tooltip query on the display where the toplevel of @widget
13202 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13208 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13210 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13213 static guint tooltip_query_id;
13214 static GSList *tooltip_query_displays;
13217 tooltip_query_idle (gpointer data)
13219 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13220 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13221 g_slist_free (tooltip_query_displays);
13223 tooltip_query_displays = NULL;
13224 tooltip_query_id = 0;
13230 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13232 GdkDisplay *display;
13234 display = gtk_widget_get_display (widget);
13236 if (!g_slist_find (tooltip_query_displays, display))
13237 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13239 if (tooltip_query_id == 0)
13240 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13244 * gtk_widget_set_tooltip_text:
13245 * @widget: a #GtkWidget
13246 * @text: the contents of the tooltip for @widget
13248 * Sets @text as the contents of the tooltip. This function will take
13249 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13250 * handler for the #GtkWidget::query-tooltip signal.
13252 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13257 gtk_widget_set_tooltip_text (GtkWidget *widget,
13260 g_return_if_fail (GTK_IS_WIDGET (widget));
13262 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13266 * gtk_widget_get_tooltip_text:
13267 * @widget: a #GtkWidget
13269 * Gets the contents of the tooltip for @widget.
13271 * Return value: the tooltip text, or %NULL. You should free the
13272 * returned string with g_free() when done.
13277 gtk_widget_get_tooltip_text (GtkWidget *widget)
13279 gchar *text = NULL;
13281 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13283 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13289 * gtk_widget_set_tooltip_markup:
13290 * @widget: a #GtkWidget
13291 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13293 * Sets @markup as the contents of the tooltip, which is marked up with
13294 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13296 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13297 * and of the default handler for the #GtkWidget::query-tooltip signal.
13299 * See also the #GtkWidget:tooltip-markup property and
13300 * gtk_tooltip_set_markup().
13305 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13306 const gchar *markup)
13308 g_return_if_fail (GTK_IS_WIDGET (widget));
13310 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13314 * gtk_widget_get_tooltip_markup:
13315 * @widget: a #GtkWidget
13317 * Gets the contents of the tooltip for @widget.
13319 * Return value: the tooltip text, or %NULL. You should free the
13320 * returned string with g_free() when done.
13325 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13327 gchar *text = NULL;
13329 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13331 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13337 * gtk_widget_set_has_tooltip:
13338 * @widget: a #GtkWidget
13339 * @has_tooltip: whether or not @widget has a tooltip.
13341 * Sets the has-tooltip property on @widget to @has_tooltip. See
13342 * #GtkWidget:has-tooltip for more information.
13347 gtk_widget_set_has_tooltip (GtkWidget *widget,
13348 gboolean has_tooltip)
13350 g_return_if_fail (GTK_IS_WIDGET (widget));
13352 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13356 * gtk_widget_get_has_tooltip:
13357 * @widget: a #GtkWidget
13359 * Returns the current value of the has-tooltip property. See
13360 * #GtkWidget:has-tooltip for more information.
13362 * Return value: current value of has-tooltip on @widget.
13367 gtk_widget_get_has_tooltip (GtkWidget *widget)
13369 gboolean has_tooltip = FALSE;
13371 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13373 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13375 return has_tooltip;
13379 * gtk_widget_get_allocation:
13380 * @widget: a #GtkWidget
13381 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13383 * Retrieves the widget's allocation.
13385 * Note, when implementing a #GtkContainer: a widget's allocation will
13386 * be its "adjusted" allocation, that is, the widget's parent
13387 * container typically calls gtk_widget_size_allocate() with an
13388 * allocation, and that allocation is then adjusted (to handle margin
13389 * and alignment for example) before assignment to the widget.
13390 * gtk_widget_get_allocation() returns the adjusted allocation that
13391 * was actually assigned to the widget. The adjusted allocation is
13392 * guaranteed to be completely contained within the
13393 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13394 * is guaranteed that its children stay inside the assigned bounds,
13395 * but not that they have exactly the bounds the container assigned.
13396 * There is no way to get the original allocation assigned by
13397 * gtk_widget_size_allocate(), since it isn't stored; if a container
13398 * implementation needs that information it will have to track it itself.
13403 gtk_widget_get_allocation (GtkWidget *widget,
13404 GtkAllocation *allocation)
13406 GtkWidgetPrivate *priv;
13408 g_return_if_fail (GTK_IS_WIDGET (widget));
13409 g_return_if_fail (allocation != NULL);
13411 priv = widget->priv;
13413 *allocation = priv->allocation;
13417 * gtk_widget_set_allocation:
13418 * @widget: a #GtkWidget
13419 * @allocation: a pointer to a #GtkAllocation to copy from
13421 * Sets the widget's allocation. This should not be used
13422 * directly, but from within a widget's size_allocate method.
13424 * The allocation set should be the "adjusted" or actual
13425 * allocation. If you're implementing a #GtkContainer, you want to use
13426 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13427 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13428 * allocation inside gtk_widget_size_allocate() to create an adjusted
13434 gtk_widget_set_allocation (GtkWidget *widget,
13435 const 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 priv->allocation = *allocation;
13448 * gtk_widget_get_allocated_width:
13449 * @widget: the widget to query
13451 * Returns the width that has currently been allocated to @widget.
13452 * This function is intended to be used when implementing handlers
13453 * for the #GtkWidget::draw function.
13455 * Returns: the width of the @widget
13458 gtk_widget_get_allocated_width (GtkWidget *widget)
13460 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13462 return widget->priv->allocation.width;
13466 * gtk_widget_get_allocated_height:
13467 * @widget: the widget to query
13469 * Returns the height that has currently been allocated to @widget.
13470 * This function is intended to be used when implementing handlers
13471 * for the #GtkWidget::draw function.
13473 * Returns: the height of the @widget
13476 gtk_widget_get_allocated_height (GtkWidget *widget)
13478 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13480 return widget->priv->allocation.height;
13484 * gtk_widget_get_requisition:
13485 * @widget: a #GtkWidget
13486 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13488 * Retrieves the widget's requisition.
13490 * This function should only be used by widget implementations in
13491 * order to figure whether the widget's requisition has actually
13492 * changed after some internal state change (so that they can call
13493 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13495 * Normally, gtk_widget_size_request() should be used.
13499 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13500 * removed, If you need to cache sizes across requests and allocations,
13501 * add an explicit cache to the widget in question instead.
13504 gtk_widget_get_requisition (GtkWidget *widget,
13505 GtkRequisition *requisition)
13507 g_return_if_fail (GTK_IS_WIDGET (widget));
13508 g_return_if_fail (requisition != NULL);
13510 gtk_widget_get_preferred_size (widget, requisition, NULL);
13514 * gtk_widget_set_window:
13515 * @widget: a #GtkWidget
13516 * @window: (transfer full): a #GdkWindow
13518 * Sets a widget's window. This function should only be used in a
13519 * widget's #GtkWidget::realize implementation. The %window passed is
13520 * usually either new window created with gdk_window_new(), or the
13521 * window of its parent widget as returned by
13522 * gtk_widget_get_parent_window().
13524 * Widgets must indicate whether they will create their own #GdkWindow
13525 * by calling gtk_widget_set_has_window(). This is usually done in the
13526 * widget's init() function.
13528 * <note><para>This function does not add any reference to @window.</para></note>
13533 gtk_widget_set_window (GtkWidget *widget,
13536 GtkWidgetPrivate *priv;
13538 g_return_if_fail (GTK_IS_WIDGET (widget));
13539 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13541 priv = widget->priv;
13543 if (priv->window != window)
13545 priv->window = window;
13546 g_object_notify (G_OBJECT (widget), "window");
13551 * gtk_widget_get_window:
13552 * @widget: a #GtkWidget
13554 * Returns the widget's window if it is realized, %NULL otherwise
13556 * Return value: (transfer none): @widget's window.
13561 gtk_widget_get_window (GtkWidget *widget)
13563 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13565 return widget->priv->window;
13569 * gtk_widget_get_support_multidevice:
13570 * @widget: a #GtkWidget
13572 * Returns %TRUE if @widget is multiple pointer aware. See
13573 * gtk_widget_set_support_multidevice() for more information.
13575 * Returns: %TRUE if @widget is multidevice aware.
13578 gtk_widget_get_support_multidevice (GtkWidget *widget)
13580 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13582 return widget->priv->multidevice;
13586 * gtk_widget_set_support_multidevice:
13587 * @widget: a #GtkWidget
13588 * @support_multidevice: %TRUE to support input from multiple devices.
13590 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13591 * @widget will start receiving multiple, per device enter/leave events. Note
13592 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13593 * gdk_window_set_support_multidevice() will have to be called manually on them.
13598 gtk_widget_set_support_multidevice (GtkWidget *widget,
13599 gboolean support_multidevice)
13601 GtkWidgetPrivate *priv;
13603 g_return_if_fail (GTK_IS_WIDGET (widget));
13605 priv = widget->priv;
13606 priv->multidevice = (support_multidevice == TRUE);
13608 if (gtk_widget_get_realized (widget))
13609 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13613 _gtk_widget_set_has_focus (GtkWidget *widget,
13614 gboolean has_focus)
13616 widget->priv->has_focus = has_focus;
13619 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
13621 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
13625 * gtk_widget_send_focus_change:
13626 * @widget: a #GtkWidget
13627 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13629 * Sends the focus change @event to @widget
13631 * This function is not meant to be used by applications. The only time it
13632 * should be used is when it is necessary for a #GtkWidget to assign focus
13633 * to a widget that is semantically owned by the first widget even though
13634 * it's not a direct child - for instance, a search entry in a floating
13635 * window similar to the quick search in #GtkTreeView.
13637 * An example of its usage is:
13640 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13642 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13643 * fevent->focus_change.in = TRUE;
13644 * fevent->focus_change.window = gtk_widget_get_window (widget);
13645 * if (fevent->focus_change.window != NULL)
13646 * g_object_ref (fevent->focus_change.window);
13648 * gtk_widget_send_focus_change (widget, fevent);
13650 * gdk_event_free (event);
13653 * Return value: the return value from the event signal emission: %TRUE
13654 * if the event was handled, and %FALSE otherwise
13659 gtk_widget_send_focus_change (GtkWidget *widget,
13664 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13665 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13667 g_object_ref (widget);
13669 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13671 res = gtk_widget_event (widget, event);
13673 g_object_notify (G_OBJECT (widget), "has-focus");
13675 g_object_unref (widget);
13681 * gtk_widget_in_destruction:
13682 * @widget: a #GtkWidget
13684 * Returns whether the widget is currently being destroyed.
13685 * This information can sometimes be used to avoid doing
13686 * unnecessary work.
13688 * Returns: %TRUE if @widget is being destroyed
13691 gtk_widget_in_destruction (GtkWidget *widget)
13693 return widget->priv->in_destruction;
13697 _gtk_widget_get_in_reparent (GtkWidget *widget)
13699 return widget->priv->in_reparent;
13703 _gtk_widget_set_in_reparent (GtkWidget *widget,
13704 gboolean in_reparent)
13706 widget->priv->in_reparent = in_reparent;
13710 _gtk_widget_get_anchored (GtkWidget *widget)
13712 return widget->priv->anchored;
13716 _gtk_widget_set_anchored (GtkWidget *widget,
13719 widget->priv->anchored = anchored;
13723 _gtk_widget_get_shadowed (GtkWidget *widget)
13725 return widget->priv->shadowed;
13729 _gtk_widget_set_shadowed (GtkWidget *widget,
13732 widget->priv->shadowed = shadowed;
13736 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13738 return widget->priv->alloc_needed;
13742 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13743 gboolean alloc_needed)
13745 widget->priv->alloc_needed = alloc_needed;
13749 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13751 return widget->priv->width_request_needed;
13755 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13756 gboolean width_request_needed)
13758 widget->priv->width_request_needed = width_request_needed;
13762 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13764 return widget->priv->height_request_needed;
13768 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13769 gboolean height_request_needed)
13771 widget->priv->height_request_needed = height_request_needed;
13775 _gtk_widget_get_sizegroup_visited (GtkWidget *widget)
13777 return widget->priv->sizegroup_visited;
13781 _gtk_widget_set_sizegroup_visited (GtkWidget *widget,
13784 widget->priv->sizegroup_visited = visited;
13788 _gtk_widget_get_sizegroup_bumping (GtkWidget *widget)
13790 return widget->priv->sizegroup_bumping;
13794 _gtk_widget_set_sizegroup_bumping (GtkWidget *widget,
13797 widget->priv->sizegroup_bumping = bumping;
13801 _gtk_widget_add_sizegroup (GtkWidget *widget,
13806 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13807 groups = g_slist_prepend (groups, group);
13808 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13810 widget->priv->have_size_groups = TRUE;
13814 _gtk_widget_remove_sizegroup (GtkWidget *widget,
13819 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13820 groups = g_slist_remove (groups, group);
13821 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13823 widget->priv->have_size_groups = groups != NULL;
13827 _gtk_widget_get_sizegroups (GtkWidget *widget)
13829 if (widget->priv->have_size_groups)
13830 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13836 _gtk_widget_add_attached_window (GtkWidget *widget,
13839 widget->priv->attached_windows = g_list_prepend (widget->priv->attached_windows, window);
13843 _gtk_widget_remove_attached_window (GtkWidget *widget,
13846 widget->priv->attached_windows = g_list_remove (widget->priv->attached_windows, window);
13850 * gtk_widget_path_append_for_widget:
13851 * @path: a widget path
13852 * @widget: the widget to append to the widget path
13854 * Appends the data from @widget to the widget hierarchy represented
13855 * by @path. This function is a shortcut for adding information from
13856 * @widget to the given @path. This includes setting the name or
13857 * adding the style classes from @widget.
13859 * Returns: the position where the data was inserted
13864 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
13869 g_return_val_if_fail (path != NULL, 0);
13870 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13872 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
13874 if (widget->priv->name)
13875 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
13877 if (widget->priv->context)
13879 GList *classes, *l;
13881 /* Also add any persistent classes in
13882 * the style context the widget path
13884 classes = gtk_style_context_list_classes (widget->priv->context);
13886 for (l = classes; l; l = l->next)
13887 gtk_widget_path_iter_add_class (path, pos, l->data);
13889 g_list_free (classes);
13896 _gtk_widget_create_path (GtkWidget *widget)
13900 parent = widget->priv->parent;
13903 return gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
13906 /* Widget is either toplevel or unparented, treat both
13907 * as toplevels style wise, since there are situations
13908 * where style properties might be retrieved on that
13911 GtkWidget *attach_widget = NULL;
13912 GtkWidgetPath *result;
13914 if (GTK_IS_WINDOW (widget))
13915 attach_widget = gtk_window_get_attached_to (GTK_WINDOW (widget));
13917 if (attach_widget != NULL)
13918 result = gtk_widget_path_copy (gtk_widget_get_path (attach_widget));
13920 result = gtk_widget_path_new ();
13922 gtk_widget_path_append_for_widget (result, widget);
13929 * gtk_widget_get_path:
13930 * @widget: a #GtkWidget
13932 * Returns the #GtkWidgetPath representing @widget, if the widget
13933 * is not connected to a toplevel widget, a partial path will be
13936 * Returns: (transfer none): The #GtkWidgetPath representing @widget
13939 gtk_widget_get_path (GtkWidget *widget)
13941 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13943 if (!widget->priv->path)
13944 widget->priv->path = _gtk_widget_create_path (widget);
13946 return widget->priv->path;
13950 _gtk_widget_style_context_invalidated (GtkWidget *widget)
13952 if (widget->priv->path)
13954 gtk_widget_path_free (widget->priv->path);
13955 widget->priv->path = NULL;
13958 if (gtk_widget_get_realized (widget))
13959 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
13962 /* Compress all style updates so it
13963 * is only emitted once pre-realize.
13965 widget->priv->style_update_pending = TRUE;
13968 if (widget->priv->anchored)
13969 gtk_widget_queue_resize (widget);
13973 * gtk_widget_get_style_context:
13974 * @widget: a #GtkWidget
13976 * Returns the style context associated to @widget.
13978 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
13979 * must not be freed.
13982 gtk_widget_get_style_context (GtkWidget *widget)
13984 GtkWidgetPrivate *priv;
13986 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13988 priv = widget->priv;
13990 if (G_UNLIKELY (priv->context == NULL))
13994 priv->context = gtk_style_context_new ();
13996 gtk_style_context_set_direction (priv->context, gtk_widget_get_direction (widget));
13998 screen = gtk_widget_get_screen (widget);
14000 gtk_style_context_set_screen (priv->context, screen);
14003 gtk_style_context_set_parent (priv->context,
14004 gtk_widget_get_style_context (priv->parent));
14006 _gtk_style_context_set_widget (priv->context, widget);
14009 return widget->priv->context;
14013 _gtk_widget_invalidate_style_context (GtkWidget *widget,
14014 GtkCssChange change)
14016 GtkWidgetPrivate *priv;
14018 priv = widget->priv;
14020 if (priv->context == NULL)
14023 _gtk_style_context_queue_invalidate (priv->context, change);
14027 * gtk_widget_get_modifier_mask:
14028 * @widget: a #GtkWidget
14029 * @intent: the use case for the modifier mask
14031 * Returns the modifier mask the @widget's windowing system backend
14032 * uses for a particular purpose.
14034 * See gdk_keymap_get_modifier_mask().
14036 * Returns: the modifier mask used for @intent.
14041 gtk_widget_get_modifier_mask (GtkWidget *widget,
14042 GdkModifierIntent intent)
14044 GdkDisplay *display;
14046 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14048 display = gtk_widget_get_display (widget);
14050 return gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
14055 _gtk_widget_get_style (GtkWidget *widget)
14057 return widget->priv->style;
14061 _gtk_widget_set_style (GtkWidget *widget,
14064 widget->priv->style = style;