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 resize_pending : 1;
346 guint alloc_needed : 1;
347 guint width_request_needed : 1;
348 guint height_request_needed : 1;
350 /* Expand-related flags */
351 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
352 guint computed_hexpand : 1; /* computed results (composite of child flags) */
353 guint computed_vexpand : 1;
354 guint hexpand : 1; /* application-forced expand */
356 guint hexpand_set : 1; /* whether to use application-forced */
357 guint vexpand_set : 1; /* instead of computing from children */
359 /* SizeGroup related flags */
360 guint sizegroup_visited : 1;
361 guint sizegroup_bumping : 1;
362 guint have_size_groups : 1;
364 /* The widget's name. If the widget does not have a name
365 * (the name is NULL), then its name (as returned by
366 * "gtk_widget_get_name") is its class's name.
367 * Among other things, the widget name is used to determine
368 * the style to use for a widget.
372 /* The list of attached windows to this widget.
373 * We keep a list in order to call reset_style to all of them,
375 GList *attached_windows;
377 /* The style for the widget. The style contains the
378 * colors the widget should be drawn in for each state
379 * along with graphics contexts used to draw with and
380 * the font to use for text.
383 GtkStyleContext *context;
385 /* Widget's path for styling */
388 /* The widget's allocated size */
389 GtkAllocation allocation;
391 /* The widget's requested sizes */
392 SizeRequestCache requests;
394 /* The widget's window or its parent window if it does
395 * not have a window. (Which will be indicated by the
396 * GTK_NO_WINDOW flag being set).
400 /* The widget's parent */
403 #ifdef G_ENABLE_DEBUG
404 /* Number of gtk_widget_push_verify_invariants () */
405 guint verifying_invariants_count;
406 #endif /* G_ENABLE_DEBUG */
409 struct _GtkWidgetClassPrivate
411 GType accessible_type;
412 AtkRole accessible_role;
441 BUTTON_RELEASE_EVENT,
455 PROPERTY_NOTIFY_EVENT,
456 SELECTION_CLEAR_EVENT,
457 SELECTION_REQUEST_EVENT,
458 SELECTION_NOTIFY_EVENT,
463 VISIBILITY_NOTIFY_EVENT,
477 ACCEL_CLOSURES_CHANGED,
502 PROP_RECEIVES_DEFAULT,
503 PROP_COMPOSITE_CHILD,
511 PROP_DOUBLE_BUFFERED,
526 typedef struct _GtkStateData GtkStateData;
529 STATE_CHANGE_REPLACE,
536 guint flags : GTK_STATE_FLAGS_BITS;
540 /* --- prototypes --- */
541 static void gtk_widget_base_class_init (gpointer g_class);
542 static void gtk_widget_class_init (GtkWidgetClass *klass);
543 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
544 static void gtk_widget_init (GtkWidget *widget);
545 static void gtk_widget_set_property (GObject *object,
549 static void gtk_widget_get_property (GObject *object,
553 static void gtk_widget_constructed (GObject *object);
554 static void gtk_widget_dispose (GObject *object);
555 static void gtk_widget_real_destroy (GtkWidget *object);
556 static void gtk_widget_finalize (GObject *object);
557 static void gtk_widget_real_show (GtkWidget *widget);
558 static void gtk_widget_real_hide (GtkWidget *widget);
559 static void gtk_widget_real_map (GtkWidget *widget);
560 static void gtk_widget_real_unmap (GtkWidget *widget);
561 static void gtk_widget_real_realize (GtkWidget *widget);
562 static void gtk_widget_real_unrealize (GtkWidget *widget);
563 static void gtk_widget_real_size_allocate (GtkWidget *widget,
564 GtkAllocation *allocation);
565 static void gtk_widget_real_style_set (GtkWidget *widget,
566 GtkStyle *previous_style);
567 static void gtk_widget_real_direction_changed(GtkWidget *widget,
568 GtkTextDirection previous_direction);
570 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
571 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
574 gboolean keyboard_tip,
575 GtkTooltip *tooltip);
576 static void gtk_widget_real_style_updated (GtkWidget *widget);
577 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
578 GtkWidgetHelpType help_type);
580 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
582 GParamSpec **pspecs);
583 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
585 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
587 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
588 GdkEventFocus *event);
589 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
590 GdkEventFocus *event);
591 static gboolean gtk_widget_real_touch_event (GtkWidget *widget,
592 GdkEventTouch *event);
593 static gboolean gtk_widget_real_focus (GtkWidget *widget,
594 GtkDirectionType direction);
595 static void gtk_widget_real_move_focus (GtkWidget *widget,
596 GtkDirectionType direction);
597 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
598 GtkDirectionType direction);
599 #ifdef G_ENABLE_DEBUG
600 static void gtk_widget_verify_invariants (GtkWidget *widget);
601 static void gtk_widget_push_verify_invariants (GtkWidget *widget);
602 static void gtk_widget_pop_verify_invariants (GtkWidget *widget);
604 #define gtk_widget_verify_invariants(widget)
605 #define gtk_widget_push_verify_invariants(widget)
606 #define gtk_widget_pop_verify_invariants(widget)
608 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
609 static void gtk_widget_update_pango_context (GtkWidget *widget);
610 static void gtk_widget_propagate_state (GtkWidget *widget,
613 static gint gtk_widget_event_internal (GtkWidget *widget,
615 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
616 gboolean group_cycling);
617 static void gtk_widget_real_get_width (GtkWidget *widget,
620 static void gtk_widget_real_get_height (GtkWidget *widget,
623 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
625 gint *minimum_height,
626 gint *natural_height);
627 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
630 gint *natural_width);
631 static void gtk_widget_real_state_flags_changed (GtkWidget *widget,
632 GtkStateFlags old_state);
633 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
634 static GtkWidgetAuxInfo* gtk_widget_get_aux_info (GtkWidget *widget,
636 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
637 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
638 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
639 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
640 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
641 cairo_region_t *region);
642 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
643 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
644 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
647 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
648 gboolean has_tooltip,
650 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
651 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
653 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
654 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
656 const gchar *childname);
657 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
660 const GValue *value);
661 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
664 const gchar *tagname,
665 GMarkupParser *parser,
667 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
670 const gchar *tagname,
672 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
673 GtkBuilder *builder);
675 static GtkSizeRequestMode gtk_widget_real_get_request_mode (GtkWidget *widget);
676 static void gtk_widget_real_get_width (GtkWidget *widget,
679 static void gtk_widget_real_get_height (GtkWidget *widget,
683 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
686 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
687 GtkOrientation orientation,
690 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
691 GtkOrientation orientation,
695 gint *allocated_size);
697 static void gtk_widget_set_usize_internal (GtkWidget *widget,
700 GtkQueueResizeFlags flags);
702 static void gtk_widget_add_events_internal (GtkWidget *widget,
705 static void gtk_widget_set_device_enabled_internal (GtkWidget *widget,
709 static gboolean event_window_is_still_viewable (GdkEvent *event);
711 /* --- variables --- */
712 static gpointer gtk_widget_parent_class = NULL;
713 static guint widget_signals[LAST_SIGNAL] = { 0 };
714 static guint composite_child_stack = 0;
715 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
716 static GParamSpecPool *style_property_spec_pool = NULL;
718 static GQuark quark_property_parser = 0;
719 static GQuark quark_aux_info = 0;
720 static GQuark quark_accel_path = 0;
721 static GQuark quark_accel_closures = 0;
722 static GQuark quark_event_mask = 0;
723 static GQuark quark_device_event_mask = 0;
724 static GQuark quark_parent_window = 0;
725 static GQuark quark_pointer_window = 0;
726 static GQuark quark_shape_info = 0;
727 static GQuark quark_input_shape_info = 0;
728 static GQuark quark_pango_context = 0;
729 static GQuark quark_accessible_object = 0;
730 static GQuark quark_mnemonic_labels = 0;
731 static GQuark quark_tooltip_markup = 0;
732 static GQuark quark_has_tooltip = 0;
733 static GQuark quark_tooltip_window = 0;
734 static GQuark quark_visual = 0;
735 static GQuark quark_modifier_style = 0;
736 static GQuark quark_enabled_devices = 0;
737 static GQuark quark_size_groups = 0;
738 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
739 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
741 /* --- functions --- */
743 gtk_widget_get_type (void)
745 static GType widget_type = 0;
747 if (G_UNLIKELY (widget_type == 0))
749 const GTypeInfo widget_info =
751 sizeof (GtkWidgetClass),
752 gtk_widget_base_class_init,
753 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
754 (GClassInitFunc) gtk_widget_class_init,
755 NULL, /* class_finalize */
756 NULL, /* class_init */
759 (GInstanceInitFunc) gtk_widget_init,
760 NULL, /* value_table */
763 const GInterfaceInfo accessibility_info =
765 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
766 (GInterfaceFinalizeFunc) NULL,
767 NULL /* interface data */
770 const GInterfaceInfo buildable_info =
772 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
773 (GInterfaceFinalizeFunc) NULL,
774 NULL /* interface data */
777 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
778 &widget_info, G_TYPE_FLAG_ABSTRACT);
780 g_type_add_class_private (widget_type, sizeof (GtkWidgetClassPrivate));
782 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
783 &accessibility_info) ;
784 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
792 gtk_widget_base_class_init (gpointer g_class)
794 GtkWidgetClass *klass = g_class;
796 klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
800 child_property_notify_dispatcher (GObject *object,
804 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
807 /* We guard against the draw signal callbacks modifying the state of the
808 * cairo context by surounding it with save/restore.
809 * Maybe we should also cairo_new_path() just to be sure?
812 gtk_widget_draw_marshaller (GClosure *closure,
813 GValue *return_value,
814 guint n_param_values,
815 const GValue *param_values,
816 gpointer invocation_hint,
817 gpointer marshal_data)
819 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
823 _gtk_marshal_BOOLEAN__BOXED (closure,
834 gtk_widget_draw_marshallerv (GClosure *closure,
835 GValue *return_value,
838 gpointer marshal_data,
845 G_VA_COPY (args_copy, args);
846 cr = va_arg (args_copy, gpointer);
850 _gtk_marshal_BOOLEAN__BOXEDv (closure,
862 gtk_widget_class_init (GtkWidgetClass *klass)
864 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
865 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
866 GtkBindingSet *binding_set;
868 gtk_widget_parent_class = g_type_class_peek_parent (klass);
870 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
871 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
872 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
873 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
874 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
875 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
876 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
877 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
878 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
879 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
880 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
881 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
882 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
883 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
884 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
885 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
886 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
887 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
888 quark_enabled_devices = g_quark_from_static_string ("gtk-widget-enabled-devices");
889 quark_size_groups = g_quark_from_static_string ("gtk-widget-size-groups");
891 style_property_spec_pool = g_param_spec_pool_new (FALSE);
892 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
893 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
894 cpn_context.dispatcher = child_property_notify_dispatcher;
895 _gtk_widget_child_property_notify_context = &cpn_context;
897 gobject_class->constructed = gtk_widget_constructed;
898 gobject_class->dispose = gtk_widget_dispose;
899 gobject_class->finalize = gtk_widget_finalize;
900 gobject_class->set_property = gtk_widget_set_property;
901 gobject_class->get_property = gtk_widget_get_property;
903 klass->destroy = gtk_widget_real_destroy;
905 klass->activate_signal = 0;
906 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
907 klass->show = gtk_widget_real_show;
908 klass->show_all = gtk_widget_show;
909 klass->hide = gtk_widget_real_hide;
910 klass->map = gtk_widget_real_map;
911 klass->unmap = gtk_widget_real_unmap;
912 klass->realize = gtk_widget_real_realize;
913 klass->unrealize = gtk_widget_real_unrealize;
914 klass->size_allocate = gtk_widget_real_size_allocate;
915 klass->get_request_mode = gtk_widget_real_get_request_mode;
916 klass->get_preferred_width = gtk_widget_real_get_width;
917 klass->get_preferred_height = gtk_widget_real_get_height;
918 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
919 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
920 klass->state_changed = NULL;
921 klass->state_flags_changed = gtk_widget_real_state_flags_changed;
922 klass->parent_set = NULL;
923 klass->hierarchy_changed = NULL;
924 klass->style_set = gtk_widget_real_style_set;
925 klass->direction_changed = gtk_widget_real_direction_changed;
926 klass->grab_notify = NULL;
927 klass->child_notify = NULL;
929 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
930 klass->grab_focus = gtk_widget_real_grab_focus;
931 klass->focus = gtk_widget_real_focus;
932 klass->move_focus = gtk_widget_real_move_focus;
933 klass->keynav_failed = gtk_widget_real_keynav_failed;
935 klass->button_press_event = NULL;
936 klass->button_release_event = NULL;
937 klass->motion_notify_event = NULL;
938 klass->touch_event = gtk_widget_real_touch_event;
939 klass->delete_event = NULL;
940 klass->destroy_event = NULL;
941 klass->key_press_event = gtk_widget_real_key_press_event;
942 klass->key_release_event = gtk_widget_real_key_release_event;
943 klass->enter_notify_event = NULL;
944 klass->leave_notify_event = NULL;
945 klass->configure_event = NULL;
946 klass->focus_in_event = gtk_widget_real_focus_in_event;
947 klass->focus_out_event = gtk_widget_real_focus_out_event;
948 klass->map_event = NULL;
949 klass->unmap_event = NULL;
950 klass->window_state_event = NULL;
951 klass->property_notify_event = _gtk_selection_property_notify;
952 klass->selection_clear_event = _gtk_selection_clear;
953 klass->selection_request_event = _gtk_selection_request;
954 klass->selection_notify_event = _gtk_selection_notify;
955 klass->selection_received = NULL;
956 klass->proximity_in_event = NULL;
957 klass->proximity_out_event = NULL;
958 klass->drag_begin = NULL;
959 klass->drag_end = NULL;
960 klass->drag_data_delete = NULL;
961 klass->drag_leave = NULL;
962 klass->drag_motion = NULL;
963 klass->drag_drop = NULL;
964 klass->drag_data_received = NULL;
965 klass->screen_changed = NULL;
966 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
967 klass->grab_broken_event = NULL;
968 klass->query_tooltip = gtk_widget_real_query_tooltip;
969 klass->style_updated = gtk_widget_real_style_updated;
971 klass->show_help = gtk_widget_real_show_help;
973 /* Accessibility support */
974 klass->priv->accessible_type = GTK_TYPE_ACCESSIBLE;
975 klass->priv->accessible_role = ATK_ROLE_INVALID;
976 klass->get_accessible = gtk_widget_real_get_accessible;
978 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
979 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
981 g_object_class_install_property (gobject_class,
983 g_param_spec_string ("name",
985 P_("The name of the widget"),
987 GTK_PARAM_READWRITE));
988 g_object_class_install_property (gobject_class,
990 g_param_spec_object ("parent",
992 P_("The parent widget of this widget. Must be a Container widget"),
994 GTK_PARAM_READWRITE));
996 g_object_class_install_property (gobject_class,
998 g_param_spec_int ("width-request",
1000 P_("Override for width request of the widget, or -1 if natural request should be used"),
1004 GTK_PARAM_READWRITE));
1005 g_object_class_install_property (gobject_class,
1006 PROP_HEIGHT_REQUEST,
1007 g_param_spec_int ("height-request",
1008 P_("Height request"),
1009 P_("Override for height request of the widget, or -1 if natural request should be used"),
1013 GTK_PARAM_READWRITE));
1014 g_object_class_install_property (gobject_class,
1016 g_param_spec_boolean ("visible",
1018 P_("Whether the widget is visible"),
1020 GTK_PARAM_READWRITE));
1021 g_object_class_install_property (gobject_class,
1023 g_param_spec_boolean ("sensitive",
1025 P_("Whether the widget responds to input"),
1027 GTK_PARAM_READWRITE));
1028 g_object_class_install_property (gobject_class,
1030 g_param_spec_boolean ("app-paintable",
1031 P_("Application paintable"),
1032 P_("Whether the application will paint directly on the widget"),
1034 GTK_PARAM_READWRITE));
1035 g_object_class_install_property (gobject_class,
1037 g_param_spec_boolean ("can-focus",
1039 P_("Whether the widget can accept the input focus"),
1041 GTK_PARAM_READWRITE));
1042 g_object_class_install_property (gobject_class,
1044 g_param_spec_boolean ("has-focus",
1046 P_("Whether the widget has the input focus"),
1048 GTK_PARAM_READWRITE));
1049 g_object_class_install_property (gobject_class,
1051 g_param_spec_boolean ("is-focus",
1053 P_("Whether the widget is the focus widget within the toplevel"),
1055 GTK_PARAM_READWRITE));
1056 g_object_class_install_property (gobject_class,
1058 g_param_spec_boolean ("can-default",
1060 P_("Whether the widget can be the default widget"),
1062 GTK_PARAM_READWRITE));
1063 g_object_class_install_property (gobject_class,
1065 g_param_spec_boolean ("has-default",
1067 P_("Whether the widget is the default widget"),
1069 GTK_PARAM_READWRITE));
1070 g_object_class_install_property (gobject_class,
1071 PROP_RECEIVES_DEFAULT,
1072 g_param_spec_boolean ("receives-default",
1073 P_("Receives default"),
1074 P_("If TRUE, the widget will receive the default action when it is focused"),
1076 GTK_PARAM_READWRITE));
1077 g_object_class_install_property (gobject_class,
1078 PROP_COMPOSITE_CHILD,
1079 g_param_spec_boolean ("composite-child",
1080 P_("Composite child"),
1081 P_("Whether the widget is part of a composite widget"),
1083 GTK_PARAM_READABLE));
1084 g_object_class_install_property (gobject_class,
1086 g_param_spec_object ("style",
1088 P_("The style of the widget, which contains information about how it will look (colors etc)"),
1090 GTK_PARAM_READWRITE));
1091 g_object_class_install_property (gobject_class,
1093 g_param_spec_flags ("events",
1095 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1096 GDK_TYPE_EVENT_MASK,
1098 GTK_PARAM_READWRITE));
1099 g_object_class_install_property (gobject_class,
1101 g_param_spec_boolean ("no-show-all",
1103 P_("Whether gtk_widget_show_all() should not affect this widget"),
1105 GTK_PARAM_READWRITE));
1108 * GtkWidget:has-tooltip:
1110 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1111 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1112 * the widget will be queried using #GtkWidget::query-tooltip to determine
1113 * whether it will provide a tooltip or not.
1115 * Note that setting this property to %TRUE for the first time will change
1116 * the event masks of the GdkWindows of this widget to include leave-notify
1117 * and motion-notify events. This cannot and will not be undone when the
1118 * property is set to %FALSE again.
1122 g_object_class_install_property (gobject_class,
1124 g_param_spec_boolean ("has-tooltip",
1126 P_("Whether this widget has a tooltip"),
1128 GTK_PARAM_READWRITE));
1130 * GtkWidget:tooltip-text:
1132 * Sets the text of tooltip to be the given string.
1134 * Also see gtk_tooltip_set_text().
1136 * This is a convenience property which will take care of getting the
1137 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1138 * will automatically be set to %TRUE and there will be taken care of
1139 * #GtkWidget::query-tooltip in the default signal handler.
1143 g_object_class_install_property (gobject_class,
1145 g_param_spec_string ("tooltip-text",
1147 P_("The contents of the tooltip for this widget"),
1149 GTK_PARAM_READWRITE));
1151 * GtkWidget:tooltip-markup:
1153 * Sets the text of tooltip to be the given string, which is marked up
1154 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1155 * Also see gtk_tooltip_set_markup().
1157 * This is a convenience property which will take care of getting the
1158 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1159 * will automatically be set to %TRUE and there will be taken care of
1160 * #GtkWidget::query-tooltip in the default signal handler.
1164 g_object_class_install_property (gobject_class,
1165 PROP_TOOLTIP_MARKUP,
1166 g_param_spec_string ("tooltip-markup",
1167 P_("Tooltip markup"),
1168 P_("The contents of the tooltip for this widget"),
1170 GTK_PARAM_READWRITE));
1175 * The widget's window if it is realized, %NULL otherwise.
1179 g_object_class_install_property (gobject_class,
1181 g_param_spec_object ("window",
1183 P_("The widget's window if it is realized"),
1185 GTK_PARAM_READABLE));
1188 * GtkWidget:double-buffered:
1190 * Whether the widget is double buffered.
1194 g_object_class_install_property (gobject_class,
1195 PROP_DOUBLE_BUFFERED,
1196 g_param_spec_boolean ("double-buffered",
1197 P_("Double Buffered"),
1198 P_("Whether the widget is double buffered"),
1200 GTK_PARAM_READWRITE));
1205 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1209 g_object_class_install_property (gobject_class,
1211 g_param_spec_enum ("halign",
1212 P_("Horizontal Alignment"),
1213 P_("How to position in extra horizontal space"),
1216 GTK_PARAM_READWRITE));
1221 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1225 g_object_class_install_property (gobject_class,
1227 g_param_spec_enum ("valign",
1228 P_("Vertical Alignment"),
1229 P_("How to position in extra vertical space"),
1232 GTK_PARAM_READWRITE));
1235 * GtkWidget:margin-left:
1237 * Margin on left side of widget.
1239 * This property adds margin outside of the widget's normal size
1240 * request, the margin will be added in addition to the size from
1241 * gtk_widget_set_size_request() for example.
1245 g_object_class_install_property (gobject_class,
1247 g_param_spec_int ("margin-left",
1248 P_("Margin on Left"),
1249 P_("Pixels of extra space on the left side"),
1253 GTK_PARAM_READWRITE));
1256 * GtkWidget:margin-right:
1258 * Margin on right side of widget.
1260 * This property adds margin outside of the widget's normal size
1261 * request, the margin will be added in addition to the size from
1262 * gtk_widget_set_size_request() for example.
1266 g_object_class_install_property (gobject_class,
1268 g_param_spec_int ("margin-right",
1269 P_("Margin on Right"),
1270 P_("Pixels of extra space on the right side"),
1274 GTK_PARAM_READWRITE));
1277 * GtkWidget:margin-top:
1279 * Margin on top side of widget.
1281 * This property adds margin outside of the widget's normal size
1282 * request, the margin will be added in addition to the size from
1283 * gtk_widget_set_size_request() for example.
1287 g_object_class_install_property (gobject_class,
1289 g_param_spec_int ("margin-top",
1290 P_("Margin on Top"),
1291 P_("Pixels of extra space on the top side"),
1295 GTK_PARAM_READWRITE));
1298 * GtkWidget:margin-bottom:
1300 * Margin on bottom side of widget.
1302 * This property adds margin outside of the widget's normal size
1303 * request, the margin will be added in addition to the size from
1304 * gtk_widget_set_size_request() for example.
1308 g_object_class_install_property (gobject_class,
1310 g_param_spec_int ("margin-bottom",
1311 P_("Margin on Bottom"),
1312 P_("Pixels of extra space on the bottom side"),
1316 GTK_PARAM_READWRITE));
1321 * Sets all four sides' margin at once. If read, returns max
1322 * margin on any side.
1326 g_object_class_install_property (gobject_class,
1328 g_param_spec_int ("margin",
1330 P_("Pixels of extra space on all four sides"),
1334 GTK_PARAM_READWRITE));
1337 * GtkWidget::destroy:
1338 * @object: the object which received the signal
1340 * Signals that all holders of a reference to the widget should release
1341 * the reference that they hold. May result in finalization of the widget
1342 * if all references are released.
1344 widget_signals[DESTROY] =
1345 g_signal_new (I_("destroy"),
1346 G_TYPE_FROM_CLASS (gobject_class),
1347 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1348 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1350 _gtk_marshal_VOID__VOID,
1354 * GtkWidget:hexpand:
1356 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1360 g_object_class_install_property (gobject_class,
1362 g_param_spec_boolean ("hexpand",
1363 P_("Horizontal Expand"),
1364 P_("Whether widget wants more horizontal space"),
1366 GTK_PARAM_READWRITE));
1369 * GtkWidget:hexpand-set:
1371 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1375 g_object_class_install_property (gobject_class,
1377 g_param_spec_boolean ("hexpand-set",
1378 P_("Horizontal Expand Set"),
1379 P_("Whether to use the hexpand property"),
1381 GTK_PARAM_READWRITE));
1384 * GtkWidget:vexpand:
1386 * Whether to expand vertically. See gtk_widget_set_vexpand().
1390 g_object_class_install_property (gobject_class,
1392 g_param_spec_boolean ("vexpand",
1393 P_("Vertical Expand"),
1394 P_("Whether widget wants more vertical space"),
1396 GTK_PARAM_READWRITE));
1399 * GtkWidget:vexpand-set:
1401 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1405 g_object_class_install_property (gobject_class,
1407 g_param_spec_boolean ("vexpand-set",
1408 P_("Vertical Expand Set"),
1409 P_("Whether to use the vexpand property"),
1411 GTK_PARAM_READWRITE));
1416 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1420 g_object_class_install_property (gobject_class,
1422 g_param_spec_boolean ("expand",
1424 P_("Whether widget wants to expand in both directions"),
1426 GTK_PARAM_READWRITE));
1430 * @widget: the object which received the signal.
1432 widget_signals[SHOW] =
1433 g_signal_new (I_("show"),
1434 G_TYPE_FROM_CLASS (gobject_class),
1436 G_STRUCT_OFFSET (GtkWidgetClass, show),
1438 _gtk_marshal_VOID__VOID,
1443 * @widget: the object which received the signal.
1445 widget_signals[HIDE] =
1446 g_signal_new (I_("hide"),
1447 G_TYPE_FROM_CLASS (gobject_class),
1449 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1451 _gtk_marshal_VOID__VOID,
1456 * @widget: the object which received the signal.
1458 widget_signals[MAP] =
1459 g_signal_new (I_("map"),
1460 G_TYPE_FROM_CLASS (gobject_class),
1462 G_STRUCT_OFFSET (GtkWidgetClass, map),
1464 _gtk_marshal_VOID__VOID,
1469 * @widget: the object which received the signal.
1471 widget_signals[UNMAP] =
1472 g_signal_new (I_("unmap"),
1473 G_TYPE_FROM_CLASS (gobject_class),
1475 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1477 _gtk_marshal_VOID__VOID,
1481 * GtkWidget::realize:
1482 * @widget: the object which received the signal.
1484 widget_signals[REALIZE] =
1485 g_signal_new (I_("realize"),
1486 G_TYPE_FROM_CLASS (gobject_class),
1488 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1490 _gtk_marshal_VOID__VOID,
1494 * GtkWidget::unrealize:
1495 * @widget: the object which received the signal.
1497 widget_signals[UNREALIZE] =
1498 g_signal_new (I_("unrealize"),
1499 G_TYPE_FROM_CLASS (gobject_class),
1501 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1503 _gtk_marshal_VOID__VOID,
1507 * GtkWidget::size-allocate:
1508 * @widget: the object which received the signal.
1511 widget_signals[SIZE_ALLOCATE] =
1512 g_signal_new (I_("size-allocate"),
1513 G_TYPE_FROM_CLASS (gobject_class),
1515 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1517 _gtk_marshal_VOID__BOXED,
1519 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1522 * GtkWidget::state-changed:
1523 * @widget: the object which received the signal.
1524 * @state: the previous state
1526 * The ::state-changed signal is emitted when the widget state changes.
1527 * See gtk_widget_get_state().
1529 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1531 widget_signals[STATE_CHANGED] =
1532 g_signal_new (I_("state-changed"),
1533 G_TYPE_FROM_CLASS (gobject_class),
1535 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1537 _gtk_marshal_VOID__ENUM,
1539 GTK_TYPE_STATE_TYPE);
1542 * GtkWidget::state-flags-changed:
1543 * @widget: the object which received the signal.
1544 * @flags: The previous state flags.
1546 * The ::state-flags-changed signal is emitted when the widget state
1547 * changes, see gtk_widget_get_state_flags().
1551 widget_signals[STATE_FLAGS_CHANGED] =
1552 g_signal_new (I_("state-flags-changed"),
1553 G_TYPE_FROM_CLASS (gobject_class),
1555 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1557 _gtk_marshal_VOID__FLAGS,
1559 GTK_TYPE_STATE_FLAGS);
1562 * GtkWidget::parent-set:
1563 * @widget: the object on which the signal is emitted
1564 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1565 * just got its initial parent.
1567 * The ::parent-set signal is emitted when a new parent
1568 * has been set on a widget.
1570 widget_signals[PARENT_SET] =
1571 g_signal_new (I_("parent-set"),
1572 G_TYPE_FROM_CLASS (gobject_class),
1574 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1576 _gtk_marshal_VOID__OBJECT,
1581 * GtkWidget::hierarchy-changed:
1582 * @widget: the object on which the signal is emitted
1583 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1584 * if the widget was previously unanchored
1586 * The ::hierarchy-changed signal is emitted when the
1587 * anchored state of a widget changes. A widget is
1588 * <firstterm>anchored</firstterm> when its toplevel
1589 * ancestor is a #GtkWindow. This signal is emitted when
1590 * a widget changes from un-anchored to anchored or vice-versa.
1592 widget_signals[HIERARCHY_CHANGED] =
1593 g_signal_new (I_("hierarchy-changed"),
1594 G_TYPE_FROM_CLASS (gobject_class),
1596 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1598 _gtk_marshal_VOID__OBJECT,
1603 * GtkWidget::style-set:
1604 * @widget: the object on which the signal is emitted
1605 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1606 * just got its initial style
1608 * The ::style-set signal is emitted when a new style has been set
1609 * on a widget. Note that style-modifying functions like
1610 * gtk_widget_modify_base() also cause this signal to be emitted.
1612 * Note that this signal is emitted for changes to the deprecated
1613 * #GtkStyle. To track changes to the #GtkStyleContext associated
1614 * with a widget, use the #GtkWidget::style-updated signal.
1616 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1618 widget_signals[STYLE_SET] =
1619 g_signal_new (I_("style-set"),
1620 G_TYPE_FROM_CLASS (gobject_class),
1622 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1624 _gtk_marshal_VOID__OBJECT,
1629 * GtkWidget::style-updated:
1630 * @widget: the object on which the signal is emitted
1632 * The ::style-updated signal is emitted when the #GtkStyleContext
1633 * of a widget is changed. Note that style-modifying functions like
1634 * gtk_widget_override_color() also cause this signal to be emitted.
1638 widget_signals[STYLE_UPDATED] =
1639 g_signal_new (I_("style-updated"),
1640 G_TYPE_FROM_CLASS (gobject_class),
1642 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1644 g_cclosure_marshal_VOID__VOID,
1648 * GtkWidget::direction-changed:
1649 * @widget: the object on which the signal is emitted
1650 * @previous_direction: the previous text direction of @widget
1652 * The ::direction-changed signal is emitted when the text direction
1653 * of a widget changes.
1655 widget_signals[DIRECTION_CHANGED] =
1656 g_signal_new (I_("direction-changed"),
1657 G_TYPE_FROM_CLASS (gobject_class),
1659 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1661 _gtk_marshal_VOID__ENUM,
1663 GTK_TYPE_TEXT_DIRECTION);
1666 * GtkWidget::grab-notify:
1667 * @widget: the object which received the signal
1668 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1669 * if it becomes unshadowed
1671 * The ::grab-notify signal is emitted when a widget becomes
1672 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1673 * another widget, or when it becomes unshadowed due to a grab
1676 * A widget is shadowed by a gtk_grab_add() when the topmost
1677 * grab widget in the grab stack of its window group is not
1680 widget_signals[GRAB_NOTIFY] =
1681 g_signal_new (I_("grab-notify"),
1682 G_TYPE_FROM_CLASS (gobject_class),
1684 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1686 _gtk_marshal_VOID__BOOLEAN,
1691 * GtkWidget::child-notify:
1692 * @widget: the object which received the signal
1693 * @pspec: the #GParamSpec of the changed child property
1695 * The ::child-notify signal is emitted for each
1696 * <link linkend="child-properties">child property</link> that has
1697 * changed on an object. The signal's detail holds the property name.
1699 widget_signals[CHILD_NOTIFY] =
1700 g_signal_new (I_("child-notify"),
1701 G_TYPE_FROM_CLASS (gobject_class),
1702 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1703 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1705 g_cclosure_marshal_VOID__PARAM,
1711 * @widget: the object which received the signal
1712 * @cr: the cairo context to draw to
1714 * This signal is emitted when a widget is supposed to render itself.
1715 * The @widget's top left corner must be painted at the origin of
1716 * the passed in context and be sized to the values returned by
1717 * gtk_widget_get_allocated_width() and
1718 * gtk_widget_get_allocated_height().
1720 * Signal handlers connected to this signal can modify the cairo
1721 * context passed as @cr in any way they like and don't need to
1722 * restore it. The signal emission takes care of calling cairo_save()
1723 * before and cairo_restore() after invoking the handler.
1727 widget_signals[DRAW] =
1728 g_signal_new (I_("draw"),
1729 G_TYPE_FROM_CLASS (gobject_class),
1731 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1732 _gtk_boolean_handled_accumulator, NULL,
1733 gtk_widget_draw_marshaller,
1735 CAIRO_GOBJECT_TYPE_CONTEXT);
1736 g_signal_set_va_marshaller (widget_signals[DRAW], G_TYPE_FROM_CLASS (klass),
1737 gtk_widget_draw_marshallerv);
1740 * GtkWidget::mnemonic-activate:
1741 * @widget: the object which received the signal.
1744 widget_signals[MNEMONIC_ACTIVATE] =
1745 g_signal_new (I_("mnemonic-activate"),
1746 G_TYPE_FROM_CLASS (gobject_class),
1748 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1749 _gtk_boolean_handled_accumulator, NULL,
1750 _gtk_marshal_BOOLEAN__BOOLEAN,
1755 * GtkWidget::grab-focus:
1756 * @widget: the object which received the signal.
1758 widget_signals[GRAB_FOCUS] =
1759 g_signal_new (I_("grab-focus"),
1760 G_TYPE_FROM_CLASS (gobject_class),
1761 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1762 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1764 _gtk_marshal_VOID__VOID,
1769 * @widget: the object which received the signal.
1772 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1774 widget_signals[FOCUS] =
1775 g_signal_new (I_("focus"),
1776 G_TYPE_FROM_CLASS (klass),
1778 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1779 _gtk_boolean_handled_accumulator, NULL,
1780 _gtk_marshal_BOOLEAN__ENUM,
1782 GTK_TYPE_DIRECTION_TYPE);
1785 * GtkWidget::move-focus:
1786 * @widget: the object which received the signal.
1789 widget_signals[MOVE_FOCUS] =
1790 g_signal_new (I_("move-focus"),
1791 G_TYPE_FROM_CLASS (klass),
1792 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1793 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1795 _gtk_marshal_VOID__ENUM,
1798 GTK_TYPE_DIRECTION_TYPE);
1801 * GtkWidget::keynav-failed:
1802 * @widget: the object which received the signal
1803 * @direction: the direction of movement
1805 * Gets emitted if keyboard navigation fails.
1806 * See gtk_widget_keynav_failed() for details.
1808 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1809 * if the emitting widget should try to handle the keyboard
1810 * navigation attempt in its parent container(s).
1814 widget_signals[KEYNAV_FAILED] =
1815 g_signal_new (I_("keynav-failed"),
1816 G_TYPE_FROM_CLASS (klass),
1818 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1819 _gtk_boolean_handled_accumulator, NULL,
1820 _gtk_marshal_BOOLEAN__ENUM,
1822 GTK_TYPE_DIRECTION_TYPE);
1826 * @widget: the object which received the signal.
1827 * @event: the #GdkEvent which triggered this signal
1829 * The GTK+ main loop will emit three signals for each GDK event delivered
1830 * to a widget: one generic ::event signal, another, more specific,
1831 * signal that matches the type of event delivered (e.g.
1832 * #GtkWidget::key-press-event) and finally a generic
1833 * #GtkWidget::event-after signal.
1835 * Returns: %TRUE to stop other handlers from being invoked for the event
1836 * and to cancel the emission of the second specific ::event signal.
1837 * %FALSE to propagate the event further and to allow the emission of
1838 * the second signal. The ::event-after signal is emitted regardless of
1841 widget_signals[EVENT] =
1842 g_signal_new (I_("event"),
1843 G_TYPE_FROM_CLASS (klass),
1845 G_STRUCT_OFFSET (GtkWidgetClass, event),
1846 _gtk_boolean_handled_accumulator, NULL,
1847 _gtk_marshal_BOOLEAN__BOXED,
1849 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1850 g_signal_set_va_marshaller (widget_signals[EVENT], G_TYPE_FROM_CLASS (klass),
1851 _gtk_marshal_BOOLEAN__BOXEDv);
1854 * GtkWidget::event-after:
1855 * @widget: the object which received the signal.
1856 * @event: the #GdkEvent which triggered this signal
1858 * After the emission of the #GtkWidget::event signal and (optionally)
1859 * the second more specific signal, ::event-after will be emitted
1860 * regardless of the previous two signals handlers return values.
1863 widget_signals[EVENT_AFTER] =
1864 g_signal_new (I_("event-after"),
1865 G_TYPE_FROM_CLASS (klass),
1869 _gtk_marshal_VOID__BOXED,
1871 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1872 g_signal_set_va_marshaller (widget_signals[EVENT_AFTER], G_TYPE_FROM_CLASS (klass),
1873 _gtk_marshal_BOOLEAN__BOXEDv);
1876 * GtkWidget::button-press-event:
1877 * @widget: the object which received the signal.
1878 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1881 * The ::button-press-event signal will be emitted when a button
1882 * (typically from a mouse) is pressed.
1884 * To receive this signal, the #GdkWindow associated to the
1885 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1887 * This signal will be sent to the grab widget if there is one.
1889 * Returns: %TRUE to stop other handlers from being invoked for the event.
1890 * %FALSE to propagate the event further.
1892 widget_signals[BUTTON_PRESS_EVENT] =
1893 g_signal_new (I_("button-press-event"),
1894 G_TYPE_FROM_CLASS (klass),
1896 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1897 _gtk_boolean_handled_accumulator, NULL,
1898 _gtk_marshal_BOOLEAN__BOXED,
1900 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1901 g_signal_set_va_marshaller (widget_signals[BUTTON_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
1902 _gtk_marshal_BOOLEAN__BOXEDv);
1905 * GtkWidget::button-release-event:
1906 * @widget: the object which received the signal.
1907 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1910 * The ::button-release-event signal will be emitted when a button
1911 * (typically from a mouse) is released.
1913 * To receive this signal, the #GdkWindow associated to the
1914 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1916 * This signal will be sent to the grab widget if there is one.
1918 * Returns: %TRUE to stop other handlers from being invoked for the event.
1919 * %FALSE to propagate the event further.
1921 widget_signals[BUTTON_RELEASE_EVENT] =
1922 g_signal_new (I_("button-release-event"),
1923 G_TYPE_FROM_CLASS (klass),
1925 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1926 _gtk_boolean_handled_accumulator, NULL,
1927 _gtk_marshal_BOOLEAN__BOXED,
1929 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1930 g_signal_set_va_marshaller (widget_signals[BUTTON_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
1931 _gtk_marshal_BOOLEAN__BOXEDv);
1933 widget_signals[TOUCH_EVENT] =
1934 g_signal_new (I_("touch-event"),
1935 G_TYPE_FROM_CLASS (klass),
1937 G_STRUCT_OFFSET (GtkWidgetClass, touch_event),
1938 _gtk_boolean_handled_accumulator, NULL,
1939 _gtk_marshal_BOOLEAN__BOXED,
1941 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1942 g_signal_set_va_marshaller (widget_signals[TOUCH_EVENT], G_TYPE_FROM_CLASS (klass),
1943 _gtk_marshal_BOOLEAN__BOXEDv);
1946 * GtkWidget::scroll-event:
1947 * @widget: the object which received the signal.
1948 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1951 * The ::scroll-event signal is emitted when a button in the 4 to 7
1952 * range is pressed. Wheel mice are usually configured to generate
1953 * button press events for buttons 4 and 5 when the wheel is turned.
1955 * To receive this signal, the #GdkWindow associated to the widget needs
1956 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1958 * This signal will be sent to the grab widget if there is one.
1960 * Returns: %TRUE to stop other handlers from being invoked for the event.
1961 * %FALSE to propagate the event further.
1963 widget_signals[SCROLL_EVENT] =
1964 g_signal_new (I_("scroll-event"),
1965 G_TYPE_FROM_CLASS (klass),
1967 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1968 _gtk_boolean_handled_accumulator, NULL,
1969 _gtk_marshal_BOOLEAN__BOXED,
1971 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1972 g_signal_set_va_marshaller (widget_signals[SCROLL_EVENT], G_TYPE_FROM_CLASS (klass),
1973 _gtk_marshal_BOOLEAN__BOXEDv);
1976 * GtkWidget::motion-notify-event:
1977 * @widget: the object which received the signal.
1978 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1981 * The ::motion-notify-event signal is emitted when the pointer moves
1982 * over the widget's #GdkWindow.
1984 * To receive this signal, the #GdkWindow associated to the widget
1985 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1987 * This signal will be sent to the grab widget if there is one.
1989 * Returns: %TRUE to stop other handlers from being invoked for the event.
1990 * %FALSE to propagate the event further.
1992 widget_signals[MOTION_NOTIFY_EVENT] =
1993 g_signal_new (I_("motion-notify-event"),
1994 G_TYPE_FROM_CLASS (klass),
1996 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1997 _gtk_boolean_handled_accumulator, NULL,
1998 _gtk_marshal_BOOLEAN__BOXED,
2000 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2001 g_signal_set_va_marshaller (widget_signals[MOTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2002 _gtk_marshal_BOOLEAN__BOXEDv);
2005 * GtkWidget::composited-changed:
2006 * @widget: the object on which the signal is emitted
2008 * The ::composited-changed signal is emitted when the composited
2009 * status of @widget<!-- -->s screen changes.
2010 * See gdk_screen_is_composited().
2012 widget_signals[COMPOSITED_CHANGED] =
2013 g_signal_new (I_("composited-changed"),
2014 G_TYPE_FROM_CLASS (klass),
2015 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2016 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
2018 _gtk_marshal_VOID__VOID,
2022 * GtkWidget::delete-event:
2023 * @widget: the object which received the signal
2024 * @event: the event which triggered this signal
2026 * The ::delete-event signal is emitted if a user requests that
2027 * a toplevel window is closed. The default handler for this signal
2028 * destroys the window. Connecting gtk_widget_hide_on_delete() to
2029 * this signal will cause the window to be hidden instead, so that
2030 * it can later be shown again without reconstructing it.
2032 * Returns: %TRUE to stop other handlers from being invoked for the event.
2033 * %FALSE to propagate the event further.
2035 widget_signals[DELETE_EVENT] =
2036 g_signal_new (I_("delete-event"),
2037 G_TYPE_FROM_CLASS (klass),
2039 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
2040 _gtk_boolean_handled_accumulator, NULL,
2041 _gtk_marshal_BOOLEAN__BOXED,
2043 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2044 g_signal_set_va_marshaller (widget_signals[DELETE_EVENT], G_TYPE_FROM_CLASS (klass),
2045 _gtk_marshal_BOOLEAN__BOXEDv);
2048 * GtkWidget::destroy-event:
2049 * @widget: the object which received the signal.
2050 * @event: the event which triggered this signal
2052 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
2053 * You rarely get this signal, because most widgets disconnect themselves
2054 * from their window before they destroy it, so no widget owns the
2055 * window at destroy time.
2057 * To receive this signal, the #GdkWindow associated to the widget needs
2058 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2059 * automatically for all new windows.
2061 * Returns: %TRUE to stop other handlers from being invoked for the event.
2062 * %FALSE to propagate the event further.
2064 widget_signals[DESTROY_EVENT] =
2065 g_signal_new (I_("destroy-event"),
2066 G_TYPE_FROM_CLASS (klass),
2068 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
2069 _gtk_boolean_handled_accumulator, NULL,
2070 _gtk_marshal_BOOLEAN__BOXED,
2072 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2073 g_signal_set_va_marshaller (widget_signals[DESTROY_EVENT], G_TYPE_FROM_CLASS (klass),
2074 _gtk_marshal_BOOLEAN__BOXEDv);
2077 * GtkWidget::key-press-event:
2078 * @widget: the object which received the signal
2079 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2081 * The ::key-press-event signal is emitted when a key is pressed. The signal
2082 * emission will reoccur at the key-repeat rate when the key is kept pressed.
2084 * To receive this signal, the #GdkWindow associated to the widget needs
2085 * to enable the #GDK_KEY_PRESS_MASK mask.
2087 * This signal will be sent to the grab widget if there is one.
2089 * Returns: %TRUE to stop other handlers from being invoked for the event.
2090 * %FALSE to propagate the event further.
2092 widget_signals[KEY_PRESS_EVENT] =
2093 g_signal_new (I_("key-press-event"),
2094 G_TYPE_FROM_CLASS (klass),
2096 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
2097 _gtk_boolean_handled_accumulator, NULL,
2098 _gtk_marshal_BOOLEAN__BOXED,
2100 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2101 g_signal_set_va_marshaller (widget_signals[KEY_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
2102 _gtk_marshal_BOOLEAN__BOXEDv);
2105 * GtkWidget::key-release-event:
2106 * @widget: the object which received the signal
2107 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2109 * The ::key-release-event signal is emitted when a key is released.
2111 * To receive this signal, the #GdkWindow associated to the widget needs
2112 * to enable the #GDK_KEY_RELEASE_MASK mask.
2114 * This signal will be sent to the grab widget if there is one.
2116 * Returns: %TRUE to stop other handlers from being invoked for the event.
2117 * %FALSE to propagate the event further.
2119 widget_signals[KEY_RELEASE_EVENT] =
2120 g_signal_new (I_("key-release-event"),
2121 G_TYPE_FROM_CLASS (klass),
2123 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2124 _gtk_boolean_handled_accumulator, NULL,
2125 _gtk_marshal_BOOLEAN__BOXED,
2127 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2128 g_signal_set_va_marshaller (widget_signals[KEY_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
2129 _gtk_marshal_BOOLEAN__BOXEDv);
2132 * GtkWidget::enter-notify-event:
2133 * @widget: the object which received the signal
2134 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2137 * The ::enter-notify-event will be emitted when the pointer enters
2138 * the @widget's window.
2140 * To receive this signal, the #GdkWindow associated to the widget needs
2141 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2143 * This signal will be sent to the grab widget if there is one.
2145 * Returns: %TRUE to stop other handlers from being invoked for the event.
2146 * %FALSE to propagate the event further.
2148 widget_signals[ENTER_NOTIFY_EVENT] =
2149 g_signal_new (I_("enter-notify-event"),
2150 G_TYPE_FROM_CLASS (klass),
2152 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2153 _gtk_boolean_handled_accumulator, NULL,
2154 _gtk_marshal_BOOLEAN__BOXED,
2156 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2157 g_signal_set_va_marshaller (widget_signals[ENTER_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2158 _gtk_marshal_BOOLEAN__BOXEDv);
2161 * GtkWidget::leave-notify-event:
2162 * @widget: the object which received the signal
2163 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2166 * The ::leave-notify-event will be emitted when the pointer leaves
2167 * the @widget's window.
2169 * To receive this signal, the #GdkWindow associated to the widget needs
2170 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2172 * This signal will be sent to the grab widget if there is one.
2174 * Returns: %TRUE to stop other handlers from being invoked for the event.
2175 * %FALSE to propagate the event further.
2177 widget_signals[LEAVE_NOTIFY_EVENT] =
2178 g_signal_new (I_("leave-notify-event"),
2179 G_TYPE_FROM_CLASS (klass),
2181 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2182 _gtk_boolean_handled_accumulator, NULL,
2183 _gtk_marshal_BOOLEAN__BOXED,
2185 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2186 g_signal_set_va_marshaller (widget_signals[LEAVE_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2187 _gtk_marshal_BOOLEAN__BOXEDv);
2190 * GtkWidget::configure-event:
2191 * @widget: the object which received the signal
2192 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2195 * The ::configure-event signal will be emitted when the size, position or
2196 * stacking of the @widget's window has changed.
2198 * To receive this signal, the #GdkWindow associated to the widget needs
2199 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2200 * automatically for all new windows.
2202 * Returns: %TRUE to stop other handlers from being invoked for the event.
2203 * %FALSE to propagate the event further.
2205 widget_signals[CONFIGURE_EVENT] =
2206 g_signal_new (I_("configure-event"),
2207 G_TYPE_FROM_CLASS (klass),
2209 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2210 _gtk_boolean_handled_accumulator, NULL,
2211 _gtk_marshal_BOOLEAN__BOXED,
2213 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2214 g_signal_set_va_marshaller (widget_signals[CONFIGURE_EVENT], G_TYPE_FROM_CLASS (klass),
2215 _gtk_marshal_BOOLEAN__BOXEDv);
2218 * GtkWidget::focus-in-event:
2219 * @widget: the object which received the signal
2220 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2223 * The ::focus-in-event signal will be emitted when the keyboard focus
2224 * enters the @widget's window.
2226 * To receive this signal, the #GdkWindow associated to the widget needs
2227 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2229 * Returns: %TRUE to stop other handlers from being invoked for the event.
2230 * %FALSE to propagate the event further.
2232 widget_signals[FOCUS_IN_EVENT] =
2233 g_signal_new (I_("focus-in-event"),
2234 G_TYPE_FROM_CLASS (klass),
2236 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2237 _gtk_boolean_handled_accumulator, NULL,
2238 _gtk_marshal_BOOLEAN__BOXED,
2240 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2241 g_signal_set_va_marshaller (widget_signals[FOCUS_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2242 _gtk_marshal_BOOLEAN__BOXEDv);
2245 * GtkWidget::focus-out-event:
2246 * @widget: the object which received the signal
2247 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2250 * The ::focus-out-event signal will be emitted when the keyboard focus
2251 * leaves the @widget's window.
2253 * To receive this signal, the #GdkWindow associated to the widget needs
2254 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2256 * Returns: %TRUE to stop other handlers from being invoked for the event.
2257 * %FALSE to propagate the event further.
2259 widget_signals[FOCUS_OUT_EVENT] =
2260 g_signal_new (I_("focus-out-event"),
2261 G_TYPE_FROM_CLASS (klass),
2263 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2264 _gtk_boolean_handled_accumulator, NULL,
2265 _gtk_marshal_BOOLEAN__BOXED,
2267 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2268 g_signal_set_va_marshaller (widget_signals[FOCUS_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2269 _gtk_marshal_BOOLEAN__BOXEDv);
2272 * GtkWidget::map-event:
2273 * @widget: the object which received the signal
2274 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2276 * The ::map-event signal will be emitted when the @widget's window is
2277 * mapped. A window is mapped when it becomes visible on the screen.
2279 * To receive this signal, the #GdkWindow associated to the widget needs
2280 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2281 * automatically for all new windows.
2283 * Returns: %TRUE to stop other handlers from being invoked for the event.
2284 * %FALSE to propagate the event further.
2286 widget_signals[MAP_EVENT] =
2287 g_signal_new (I_("map-event"),
2288 G_TYPE_FROM_CLASS (klass),
2290 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2291 _gtk_boolean_handled_accumulator, NULL,
2292 _gtk_marshal_BOOLEAN__BOXED,
2294 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2295 g_signal_set_va_marshaller (widget_signals[MAP_EVENT], G_TYPE_FROM_CLASS (klass),
2296 _gtk_marshal_BOOLEAN__BOXEDv);
2299 * GtkWidget::unmap-event:
2300 * @widget: the object which received the signal
2301 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2303 * The ::unmap-event signal will be emitted when the @widget's window is
2304 * unmapped. A window is unmapped when it becomes invisible on the screen.
2306 * To receive this signal, the #GdkWindow associated to the widget needs
2307 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2308 * automatically for all new windows.
2310 * Returns: %TRUE to stop other handlers from being invoked for the event.
2311 * %FALSE to propagate the event further.
2313 widget_signals[UNMAP_EVENT] =
2314 g_signal_new (I_("unmap-event"),
2315 G_TYPE_FROM_CLASS (klass),
2317 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2318 _gtk_boolean_handled_accumulator, NULL,
2319 _gtk_marshal_BOOLEAN__BOXED,
2321 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2322 g_signal_set_va_marshaller (widget_signals[UNMAP_EVENT], G_TYPE_FROM_CLASS (klass),
2323 _gtk_marshal_BOOLEAN__BOXEDv);
2326 * GtkWidget::property-notify-event:
2327 * @widget: the object which received the signal
2328 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2331 * The ::property-notify-event signal will be emitted when a property on
2332 * the @widget's window has been changed or deleted.
2334 * To receive this signal, the #GdkWindow associated to the widget needs
2335 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2337 * Returns: %TRUE to stop other handlers from being invoked for the event.
2338 * %FALSE to propagate the event further.
2340 widget_signals[PROPERTY_NOTIFY_EVENT] =
2341 g_signal_new (I_("property-notify-event"),
2342 G_TYPE_FROM_CLASS (klass),
2344 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2345 _gtk_boolean_handled_accumulator, NULL,
2346 _gtk_marshal_BOOLEAN__BOXED,
2348 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2349 g_signal_set_va_marshaller (widget_signals[PROPERTY_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2350 _gtk_marshal_BOOLEAN__BOXEDv);
2353 * GtkWidget::selection-clear-event:
2354 * @widget: the object which received the signal
2355 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2358 * The ::selection-clear-event signal will be emitted when the
2359 * the @widget's window has lost ownership of a selection.
2361 * Returns: %TRUE to stop other handlers from being invoked for the event.
2362 * %FALSE to propagate the event further.
2364 widget_signals[SELECTION_CLEAR_EVENT] =
2365 g_signal_new (I_("selection-clear-event"),
2366 G_TYPE_FROM_CLASS (klass),
2368 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2369 _gtk_boolean_handled_accumulator, NULL,
2370 _gtk_marshal_BOOLEAN__BOXED,
2372 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2373 g_signal_set_va_marshaller (widget_signals[SELECTION_CLEAR_EVENT], G_TYPE_FROM_CLASS (klass),
2374 _gtk_marshal_BOOLEAN__BOXEDv);
2377 * GtkWidget::selection-request-event:
2378 * @widget: the object which received the signal
2379 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2382 * The ::selection-request-event signal will be emitted when
2383 * another client requests ownership of the selection owned by
2384 * the @widget's window.
2386 * Returns: %TRUE to stop other handlers from being invoked for the event.
2387 * %FALSE to propagate the event further.
2389 widget_signals[SELECTION_REQUEST_EVENT] =
2390 g_signal_new (I_("selection-request-event"),
2391 G_TYPE_FROM_CLASS (klass),
2393 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2394 _gtk_boolean_handled_accumulator, NULL,
2395 _gtk_marshal_BOOLEAN__BOXED,
2397 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2398 g_signal_set_va_marshaller (widget_signals[SELECTION_REQUEST_EVENT], G_TYPE_FROM_CLASS (klass),
2399 _gtk_marshal_BOOLEAN__BOXEDv);
2402 * GtkWidget::selection-notify-event:
2403 * @widget: the object which received the signal.
2404 * @event: (type Gdk.EventSelection):
2406 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2408 widget_signals[SELECTION_NOTIFY_EVENT] =
2409 g_signal_new (I_("selection-notify-event"),
2410 G_TYPE_FROM_CLASS (klass),
2412 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2413 _gtk_boolean_handled_accumulator, NULL,
2414 _gtk_marshal_BOOLEAN__BOXED,
2416 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2417 g_signal_set_va_marshaller (widget_signals[SELECTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2418 _gtk_marshal_BOOLEAN__BOXEDv);
2421 * GtkWidget::selection-received:
2422 * @widget: the object which received the signal.
2426 widget_signals[SELECTION_RECEIVED] =
2427 g_signal_new (I_("selection-received"),
2428 G_TYPE_FROM_CLASS (klass),
2430 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2432 _gtk_marshal_VOID__BOXED_UINT,
2434 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2438 * GtkWidget::selection-get:
2439 * @widget: the object which received the signal.
2444 widget_signals[SELECTION_GET] =
2445 g_signal_new (I_("selection-get"),
2446 G_TYPE_FROM_CLASS (klass),
2448 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2450 _gtk_marshal_VOID__BOXED_UINT_UINT,
2452 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2457 * GtkWidget::proximity-in-event:
2458 * @widget: the object which received the signal
2459 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2462 * To receive this signal the #GdkWindow associated to the widget needs
2463 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2465 * This signal will be sent to the grab widget if there is one.
2467 * Returns: %TRUE to stop other handlers from being invoked for the event.
2468 * %FALSE to propagate the event further.
2470 widget_signals[PROXIMITY_IN_EVENT] =
2471 g_signal_new (I_("proximity-in-event"),
2472 G_TYPE_FROM_CLASS (klass),
2474 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2475 _gtk_boolean_handled_accumulator, NULL,
2476 _gtk_marshal_BOOLEAN__BOXED,
2478 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2479 g_signal_set_va_marshaller (widget_signals[PROXIMITY_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2480 _gtk_marshal_BOOLEAN__BOXEDv);
2483 * GtkWidget::proximity-out-event:
2484 * @widget: the object which received the signal
2485 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2488 * To receive this signal the #GdkWindow associated to the widget needs
2489 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2491 * This signal will be sent to the grab widget if there is one.
2493 * Returns: %TRUE to stop other handlers from being invoked for the event.
2494 * %FALSE to propagate the event further.
2496 widget_signals[PROXIMITY_OUT_EVENT] =
2497 g_signal_new (I_("proximity-out-event"),
2498 G_TYPE_FROM_CLASS (klass),
2500 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2501 _gtk_boolean_handled_accumulator, NULL,
2502 _gtk_marshal_BOOLEAN__BOXED,
2504 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2505 g_signal_set_va_marshaller (widget_signals[PROXIMITY_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2506 _gtk_marshal_BOOLEAN__BOXEDv);
2509 * GtkWidget::drag-leave:
2510 * @widget: the object which received the signal.
2511 * @drag_context: the drag context
2512 * @time: the timestamp of the motion event
2514 * The ::drag-leave signal is emitted on the drop site when the cursor
2515 * leaves the widget. A typical reason to connect to this signal is to
2516 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2517 * with gtk_drag_unhighlight()
2519 widget_signals[DRAG_LEAVE] =
2520 g_signal_new (I_("drag-leave"),
2521 G_TYPE_FROM_CLASS (klass),
2523 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2525 _gtk_marshal_VOID__OBJECT_UINT,
2527 GDK_TYPE_DRAG_CONTEXT,
2531 * GtkWidget::drag-begin:
2532 * @widget: the object which received the signal
2533 * @drag_context: the drag context
2535 * The ::drag-begin signal is emitted on the drag source when a drag is
2536 * started. A typical reason to connect to this signal is to set up a
2537 * custom drag icon with gtk_drag_source_set_icon().
2539 * Note that some widgets set up a drag icon in the default handler of
2540 * this signal, so you may have to use g_signal_connect_after() to
2541 * override what the default handler did.
2543 widget_signals[DRAG_BEGIN] =
2544 g_signal_new (I_("drag-begin"),
2545 G_TYPE_FROM_CLASS (klass),
2547 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2549 _gtk_marshal_VOID__OBJECT,
2551 GDK_TYPE_DRAG_CONTEXT);
2554 * GtkWidget::drag-end:
2555 * @widget: the object which received the signal
2556 * @drag_context: the drag context
2558 * The ::drag-end signal is emitted on the drag source when a drag is
2559 * finished. A typical reason to connect to this signal is to undo
2560 * things done in #GtkWidget::drag-begin.
2562 widget_signals[DRAG_END] =
2563 g_signal_new (I_("drag-end"),
2564 G_TYPE_FROM_CLASS (klass),
2566 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2568 _gtk_marshal_VOID__OBJECT,
2570 GDK_TYPE_DRAG_CONTEXT);
2573 * GtkWidget::drag-data-delete:
2574 * @widget: the object which received the signal
2575 * @drag_context: the drag context
2577 * The ::drag-data-delete signal is emitted on the drag source when a drag
2578 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2579 * handler is responsible for deleting the data that has been dropped. What
2580 * "delete" means depends on the context of the drag operation.
2582 widget_signals[DRAG_DATA_DELETE] =
2583 g_signal_new (I_("drag-data-delete"),
2584 G_TYPE_FROM_CLASS (klass),
2586 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2588 _gtk_marshal_VOID__OBJECT,
2590 GDK_TYPE_DRAG_CONTEXT);
2593 * GtkWidget::drag-failed:
2594 * @widget: the object which received the signal
2595 * @drag_context: the drag context
2596 * @result: the result of the drag operation
2598 * The ::drag-failed signal is emitted on the drag source when a drag has
2599 * failed. The signal handler may hook custom code to handle a failed DND
2600 * operation based on the type of error, it returns %TRUE is the failure has
2601 * been already handled (not showing the default "drag operation failed"
2602 * animation), otherwise it returns %FALSE.
2604 * Return value: %TRUE if the failed drag operation has been already handled.
2608 widget_signals[DRAG_FAILED] =
2609 g_signal_new (I_("drag-failed"),
2610 G_TYPE_FROM_CLASS (klass),
2612 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2613 _gtk_boolean_handled_accumulator, NULL,
2614 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2616 GDK_TYPE_DRAG_CONTEXT,
2617 GTK_TYPE_DRAG_RESULT);
2620 * GtkWidget::drag-motion:
2621 * @widget: the object which received the signal
2622 * @drag_context: the drag context
2623 * @x: the x coordinate of the current cursor position
2624 * @y: the y coordinate of the current cursor position
2625 * @time: the timestamp of the motion event
2627 * The drag-motion signal is emitted on the drop site when the user
2628 * moves the cursor over the widget during a drag. The signal handler
2629 * must determine whether the cursor position is in a drop zone or not.
2630 * If it is not in a drop zone, it returns %FALSE and no further processing
2631 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2632 * handler is responsible for providing the necessary information for
2633 * displaying feedback to the user, by calling gdk_drag_status().
2635 * If the decision whether the drop will be accepted or rejected can't be
2636 * made based solely on the cursor position and the type of the data, the
2637 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2638 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2639 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2640 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2641 * when using the drag-motion signal that way.
2643 * Also note that there is no drag-enter signal. The drag receiver has to
2644 * keep track of whether he has received any drag-motion signals since the
2645 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2646 * an "enter" signal. Upon an "enter", the handler will typically highlight
2647 * the drop site with gtk_drag_highlight().
2650 * drag_motion (GtkWidget *widget,
2651 * GdkDragContext *context,
2658 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2660 * if (!private_data->drag_highlight)
2662 * private_data->drag_highlight = 1;
2663 * gtk_drag_highlight (widget);
2666 * target = gtk_drag_dest_find_target (widget, context, NULL);
2667 * if (target == GDK_NONE)
2668 * gdk_drag_status (context, 0, time);
2671 * private_data->pending_status = context->suggested_action;
2672 * gtk_drag_get_data (widget, context, target, time);
2679 * drag_data_received (GtkWidget *widget,
2680 * GdkDragContext *context,
2683 * GtkSelectionData *selection_data,
2687 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2689 * if (private_data->suggested_action)
2691 * private_data->suggested_action = 0;
2693 * /* We are getting this data due to a request in drag_motion,
2694 * * rather than due to a request in drag_drop, so we are just
2695 * * supposed to call gdk_drag_status (), not actually paste in
2698 * str = gtk_selection_data_get_text (selection_data);
2699 * if (!data_is_acceptable (str))
2700 * gdk_drag_status (context, 0, time);
2702 * gdk_drag_status (context, private_data->suggested_action, time);
2706 * /* accept the drop */
2711 * Returns: whether the cursor position is in a drop zone
2713 widget_signals[DRAG_MOTION] =
2714 g_signal_new (I_("drag-motion"),
2715 G_TYPE_FROM_CLASS (klass),
2717 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2718 _gtk_boolean_handled_accumulator, NULL,
2719 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2721 GDK_TYPE_DRAG_CONTEXT,
2727 * GtkWidget::drag-drop:
2728 * @widget: the object which received the signal
2729 * @drag_context: the drag context
2730 * @x: the x coordinate of the current cursor position
2731 * @y: the y coordinate of the current cursor position
2732 * @time: the timestamp of the motion event
2734 * The ::drag-drop signal is emitted on the drop site when the user drops
2735 * the data onto the widget. The signal handler must determine whether
2736 * the cursor position is in a drop zone or not. If it is not in a drop
2737 * zone, it returns %FALSE and no further processing is necessary.
2738 * Otherwise, the handler returns %TRUE. In this case, the handler must
2739 * ensure that gtk_drag_finish() is called to let the source know that
2740 * the drop is done. The call to gtk_drag_finish() can be done either
2741 * directly or in a #GtkWidget::drag-data-received handler which gets
2742 * triggered by calling gtk_drag_get_data() to receive the data for one
2743 * or more of the supported targets.
2745 * Returns: whether the cursor position is in a drop zone
2747 widget_signals[DRAG_DROP] =
2748 g_signal_new (I_("drag-drop"),
2749 G_TYPE_FROM_CLASS (klass),
2751 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2752 _gtk_boolean_handled_accumulator, NULL,
2753 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2755 GDK_TYPE_DRAG_CONTEXT,
2761 * GtkWidget::drag-data-get:
2762 * @widget: the object which received the signal
2763 * @drag_context: the drag context
2764 * @data: the #GtkSelectionData to be filled with the dragged data
2765 * @info: the info that has been registered with the target in the
2767 * @time: the timestamp at which the data was requested
2769 * The ::drag-data-get signal is emitted on the drag source when the drop
2770 * site requests the data which is dragged. It is the responsibility of
2771 * the signal handler to fill @data with the data in the format which
2772 * is indicated by @info. See gtk_selection_data_set() and
2773 * gtk_selection_data_set_text().
2775 widget_signals[DRAG_DATA_GET] =
2776 g_signal_new (I_("drag-data-get"),
2777 G_TYPE_FROM_CLASS (klass),
2779 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2781 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2783 GDK_TYPE_DRAG_CONTEXT,
2784 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2789 * GtkWidget::drag-data-received:
2790 * @widget: the object which received the signal
2791 * @drag_context: the drag context
2792 * @x: where the drop happened
2793 * @y: where the drop happened
2794 * @data: the received data
2795 * @info: the info that has been registered with the target in the
2797 * @time: the timestamp at which the data was received
2799 * The ::drag-data-received signal is emitted on the drop site when the
2800 * dragged data has been received. If the data was received in order to
2801 * determine whether the drop will be accepted, the handler is expected
2802 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2803 * If the data was received in response to a #GtkWidget::drag-drop signal
2804 * (and this is the last target to be received), the handler for this
2805 * signal is expected to process the received data and then call
2806 * gtk_drag_finish(), setting the @success parameter depending on whether
2807 * the data was processed successfully.
2809 * The handler may inspect and modify @drag_context->action before calling
2810 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2811 * following example:
2814 * drag_data_received (GtkWidget *widget,
2815 * GdkDragContext *drag_context,
2818 * GtkSelectionData *data,
2822 * if ((data->length >= 0) && (data->format == 8))
2824 * if (drag_context->action == GDK_ACTION_ASK)
2826 * GtkWidget *dialog;
2829 * dialog = gtk_message_dialog_new (NULL,
2830 * GTK_DIALOG_MODAL |
2831 * GTK_DIALOG_DESTROY_WITH_PARENT,
2833 * GTK_BUTTONS_YES_NO,
2834 * "Move the data ?\n");
2835 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2836 * gtk_widget_destroy (dialog);
2838 * if (response == GTK_RESPONSE_YES)
2839 * drag_context->action = GDK_ACTION_MOVE;
2841 * drag_context->action = GDK_ACTION_COPY;
2844 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2848 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2852 widget_signals[DRAG_DATA_RECEIVED] =
2853 g_signal_new (I_("drag-data-received"),
2854 G_TYPE_FROM_CLASS (klass),
2856 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2858 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2860 GDK_TYPE_DRAG_CONTEXT,
2863 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2868 * GtkWidget::visibility-notify-event:
2869 * @widget: the object which received the signal
2870 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2871 * triggered this signal.
2873 * The ::visibility-notify-event will be emitted when the @widget's window
2874 * is obscured or unobscured.
2876 * To receive this signal the #GdkWindow associated to the widget needs
2877 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2879 * Returns: %TRUE to stop other handlers from being invoked for the event.
2880 * %FALSE to propagate the event further.
2882 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2883 g_signal_new (I_("visibility-notify-event"),
2884 G_TYPE_FROM_CLASS (klass),
2886 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2887 _gtk_boolean_handled_accumulator, NULL,
2888 _gtk_marshal_BOOLEAN__BOXED,
2890 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2893 * GtkWidget::window-state-event:
2894 * @widget: the object which received the signal
2895 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2896 * triggered this signal.
2898 * The ::window-state-event will be emitted when the state of the
2899 * toplevel window associated to the @widget changes.
2901 * To receive this signal the #GdkWindow associated to the widget
2902 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2903 * this mask automatically for all new windows.
2905 * Returns: %TRUE to stop other handlers from being invoked for the
2906 * event. %FALSE to propagate the event further.
2908 widget_signals[WINDOW_STATE_EVENT] =
2909 g_signal_new (I_("window-state-event"),
2910 G_TYPE_FROM_CLASS (klass),
2912 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2913 _gtk_boolean_handled_accumulator, NULL,
2914 _gtk_marshal_BOOLEAN__BOXED,
2916 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2917 g_signal_set_va_marshaller (widget_signals[WINDOW_STATE_EVENT], G_TYPE_FROM_CLASS (klass),
2918 _gtk_marshal_BOOLEAN__BOXEDv);
2921 * GtkWidget::damage-event:
2922 * @widget: the object which received the signal
2923 * @event: (type Gdk.EventExpose): the #GdkEventExpose event
2925 * Emitted when a redirected window belonging to @widget gets drawn into.
2926 * The region/area members of the event shows what area of the redirected
2927 * drawable was drawn into.
2929 * Returns: %TRUE to stop other handlers from being invoked for the event.
2930 * %FALSE to propagate the event further.
2934 widget_signals[DAMAGE_EVENT] =
2935 g_signal_new (I_("damage-event"),
2936 G_TYPE_FROM_CLASS (klass),
2938 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2939 _gtk_boolean_handled_accumulator, NULL,
2940 _gtk_marshal_BOOLEAN__BOXED,
2942 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2943 g_signal_set_va_marshaller (widget_signals[DAMAGE_EVENT], G_TYPE_FROM_CLASS (klass),
2944 _gtk_marshal_BOOLEAN__BOXEDv);
2947 * GtkWidget::grab-broken-event:
2948 * @widget: the object which received the signal
2949 * @event: (type Gdk.EventGrabBroken): the #GdkEventGrabBroken event
2951 * Emitted when a pointer or keyboard grab on a window belonging
2952 * to @widget gets broken.
2954 * On X11, this happens when the grab window becomes unviewable
2955 * (i.e. it or one of its ancestors is unmapped), or if the same
2956 * application grabs the pointer or keyboard again.
2958 * Returns: %TRUE to stop other handlers from being invoked for
2959 * the event. %FALSE to propagate the event further.
2963 widget_signals[GRAB_BROKEN_EVENT] =
2964 g_signal_new (I_("grab-broken-event"),
2965 G_TYPE_FROM_CLASS (klass),
2967 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2968 _gtk_boolean_handled_accumulator, NULL,
2969 _gtk_marshal_BOOLEAN__BOXED,
2971 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2972 g_signal_set_va_marshaller (widget_signals[GRAB_BROKEN_EVENT], G_TYPE_FROM_CLASS (klass),
2973 _gtk_marshal_BOOLEAN__BOXEDv);
2976 * GtkWidget::query-tooltip:
2977 * @widget: the object which received the signal
2978 * @x: the x coordinate of the cursor position where the request has
2979 * been emitted, relative to @widget's left side
2980 * @y: the y coordinate of the cursor position where the request has
2981 * been emitted, relative to @widget's top
2982 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2983 * @tooltip: a #GtkTooltip
2985 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2986 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2987 * focus in keyboard mode.
2989 * Using the given coordinates, the signal handler should determine
2990 * whether a tooltip should be shown for @widget. If this is the case
2991 * %TRUE should be returned, %FALSE otherwise. Note that if
2992 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2993 * should not be used.
2995 * The signal handler is free to manipulate @tooltip with the therefore
2996 * destined function calls.
2998 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
3002 widget_signals[QUERY_TOOLTIP] =
3003 g_signal_new (I_("query-tooltip"),
3004 G_TYPE_FROM_CLASS (klass),
3006 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
3007 _gtk_boolean_handled_accumulator, NULL,
3008 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
3016 * GtkWidget::popup-menu:
3017 * @widget: the object which received the signal
3019 * This signal gets emitted whenever a widget should pop up a context
3020 * menu. This usually happens through the standard key binding mechanism;
3021 * by pressing a certain key while a widget is focused, the user can cause
3022 * the widget to pop up a menu. For example, the #GtkEntry widget creates
3023 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
3024 * for an example of how to use this signal.
3026 * Returns: %TRUE if a menu was activated
3028 widget_signals[POPUP_MENU] =
3029 g_signal_new (I_("popup-menu"),
3030 G_TYPE_FROM_CLASS (klass),
3031 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3032 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
3033 _gtk_boolean_handled_accumulator, NULL,
3034 _gtk_marshal_BOOLEAN__VOID,
3038 * GtkWidget::show-help:
3039 * @widget: the object which received the signal.
3042 widget_signals[SHOW_HELP] =
3043 g_signal_new (I_("show-help"),
3044 G_TYPE_FROM_CLASS (klass),
3045 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3046 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
3047 _gtk_boolean_handled_accumulator, NULL,
3048 _gtk_marshal_BOOLEAN__ENUM,
3050 GTK_TYPE_WIDGET_HELP_TYPE);
3053 * GtkWidget::accel-closures-changed:
3054 * @widget: the object which received the signal.
3056 widget_signals[ACCEL_CLOSURES_CHANGED] =
3057 g_signal_new (I_("accel-closures-changed"),
3058 G_TYPE_FROM_CLASS (klass),
3062 _gtk_marshal_VOID__VOID,
3066 * GtkWidget::screen-changed:
3067 * @widget: the object on which the signal is emitted
3068 * @previous_screen: (allow-none): the previous screen, or %NULL if the
3069 * widget was not associated with a screen before
3071 * The ::screen-changed signal gets emitted when the
3072 * screen of a widget has changed.
3074 widget_signals[SCREEN_CHANGED] =
3075 g_signal_new (I_("screen-changed"),
3076 G_TYPE_FROM_CLASS (klass),
3078 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
3080 _gtk_marshal_VOID__OBJECT,
3085 * GtkWidget::can-activate-accel:
3086 * @widget: the object which received the signal
3087 * @signal_id: the ID of a signal installed on @widget
3089 * Determines whether an accelerator that activates the signal
3090 * identified by @signal_id can currently be activated.
3091 * This signal is present to allow applications and derived
3092 * widgets to override the default #GtkWidget handling
3093 * for determining whether an accelerator can be activated.
3095 * Returns: %TRUE if the signal can be activated.
3097 widget_signals[CAN_ACTIVATE_ACCEL] =
3098 g_signal_new (I_("can-activate-accel"),
3099 G_TYPE_FROM_CLASS (klass),
3101 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
3102 _gtk_boolean_handled_accumulator, NULL,
3103 _gtk_marshal_BOOLEAN__UINT,
3104 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
3106 binding_set = gtk_binding_set_by_class (klass);
3107 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
3109 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
3112 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
3114 GTK_TYPE_WIDGET_HELP_TYPE,
3115 GTK_WIDGET_HELP_TOOLTIP);
3116 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
3118 GTK_TYPE_WIDGET_HELP_TYPE,
3119 GTK_WIDGET_HELP_TOOLTIP);
3120 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
3122 GTK_TYPE_WIDGET_HELP_TYPE,
3123 GTK_WIDGET_HELP_WHATS_THIS);
3124 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
3126 GTK_TYPE_WIDGET_HELP_TYPE,
3127 GTK_WIDGET_HELP_WHATS_THIS);
3129 gtk_widget_class_install_style_property (klass,
3130 g_param_spec_boolean ("interior-focus",
3131 P_("Interior Focus"),
3132 P_("Whether to draw the focus indicator inside widgets"),
3134 GTK_PARAM_READABLE));
3136 gtk_widget_class_install_style_property (klass,
3137 g_param_spec_int ("focus-line-width",
3138 P_("Focus linewidth"),
3139 P_("Width, in pixels, of the focus indicator line"),
3141 GTK_PARAM_READABLE));
3143 gtk_widget_class_install_style_property (klass,
3144 g_param_spec_string ("focus-line-pattern",
3145 P_("Focus line dash pattern"),
3146 P_("Dash pattern used to draw the focus indicator"),
3148 GTK_PARAM_READABLE));
3149 gtk_widget_class_install_style_property (klass,
3150 g_param_spec_int ("focus-padding",
3151 P_("Focus padding"),
3152 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3154 GTK_PARAM_READABLE));
3155 gtk_widget_class_install_style_property (klass,
3156 g_param_spec_boxed ("cursor-color",
3158 P_("Color with which to draw insertion cursor"),
3160 GTK_PARAM_READABLE));
3161 gtk_widget_class_install_style_property (klass,
3162 g_param_spec_boxed ("secondary-cursor-color",
3163 P_("Secondary cursor color"),
3164 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3166 GTK_PARAM_READABLE));
3167 gtk_widget_class_install_style_property (klass,
3168 g_param_spec_float ("cursor-aspect-ratio",
3169 P_("Cursor line aspect ratio"),
3170 P_("Aspect ratio with which to draw insertion cursor"),
3172 GTK_PARAM_READABLE));
3174 gtk_widget_class_install_style_property (klass,
3175 g_param_spec_boolean ("window-dragging",
3176 P_("Window dragging"),
3177 P_("Whether windows can be dragged by clicking on empty areas"),
3179 GTK_PARAM_READABLE));
3182 * GtkWidget:link-color:
3184 * The "link-color" style property defines the color of unvisited links.
3188 gtk_widget_class_install_style_property (klass,
3189 g_param_spec_boxed ("link-color",
3190 P_("Unvisited Link Color"),
3191 P_("Color of unvisited links"),
3193 GTK_PARAM_READABLE));
3196 * GtkWidget:visited-link-color:
3198 * The "visited-link-color" style property defines the color of visited links.
3202 gtk_widget_class_install_style_property (klass,
3203 g_param_spec_boxed ("visited-link-color",
3204 P_("Visited Link Color"),
3205 P_("Color of visited links"),
3207 GTK_PARAM_READABLE));
3210 * GtkWidget:wide-separators:
3212 * The "wide-separators" style property defines whether separators have
3213 * configurable width and should be drawn using a box instead of a line.
3217 gtk_widget_class_install_style_property (klass,
3218 g_param_spec_boolean ("wide-separators",
3219 P_("Wide Separators"),
3220 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3222 GTK_PARAM_READABLE));
3225 * GtkWidget:separator-width:
3227 * The "separator-width" style property defines the width of separators.
3228 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3232 gtk_widget_class_install_style_property (klass,
3233 g_param_spec_int ("separator-width",
3234 P_("Separator Width"),
3235 P_("The width of separators if wide-separators is TRUE"),
3237 GTK_PARAM_READABLE));
3240 * GtkWidget:separator-height:
3242 * The "separator-height" style property defines the height of separators.
3243 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3247 gtk_widget_class_install_style_property (klass,
3248 g_param_spec_int ("separator-height",
3249 P_("Separator Height"),
3250 P_("The height of separators if \"wide-separators\" is TRUE"),
3252 GTK_PARAM_READABLE));
3255 * GtkWidget:scroll-arrow-hlength:
3257 * The "scroll-arrow-hlength" style property defines the length of
3258 * horizontal scroll arrows.
3262 gtk_widget_class_install_style_property (klass,
3263 g_param_spec_int ("scroll-arrow-hlength",
3264 P_("Horizontal Scroll Arrow Length"),
3265 P_("The length of horizontal scroll arrows"),
3267 GTK_PARAM_READABLE));
3270 * GtkWidget:scroll-arrow-vlength:
3272 * The "scroll-arrow-vlength" style property defines the length of
3273 * vertical scroll arrows.
3277 gtk_widget_class_install_style_property (klass,
3278 g_param_spec_int ("scroll-arrow-vlength",
3279 P_("Vertical Scroll Arrow Length"),
3280 P_("The length of vertical scroll arrows"),
3282 GTK_PARAM_READABLE));
3284 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3286 gtk_widget_class_set_accessible_type (klass, GTK_TYPE_WIDGET_ACCESSIBLE);
3290 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3294 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3295 for (node = list; node; node = node->next)
3297 GParamSpec *pspec = node->data;
3299 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3300 g_param_spec_unref (pspec);
3306 gtk_widget_set_property (GObject *object,
3308 const GValue *value,
3311 GtkWidget *widget = GTK_WIDGET (object);
3316 gchar *tooltip_markup;
3317 const gchar *tooltip_text;
3318 GtkWindow *tooltip_window;
3321 gtk_widget_set_name (widget, g_value_get_string (value));
3324 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3326 case PROP_WIDTH_REQUEST:
3327 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3329 case PROP_HEIGHT_REQUEST:
3330 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3333 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3335 case PROP_SENSITIVE:
3336 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3338 case PROP_APP_PAINTABLE:
3339 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3341 case PROP_CAN_FOCUS:
3342 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3344 case PROP_HAS_FOCUS:
3345 if (g_value_get_boolean (value))
3346 gtk_widget_grab_focus (widget);
3349 if (g_value_get_boolean (value))
3350 gtk_widget_grab_focus (widget);
3352 case PROP_CAN_DEFAULT:
3353 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3355 case PROP_HAS_DEFAULT:
3356 if (g_value_get_boolean (value))
3357 gtk_widget_grab_default (widget);
3359 case PROP_RECEIVES_DEFAULT:
3360 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3363 gtk_widget_set_style (widget, g_value_get_object (value));
3366 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3367 gtk_widget_set_events (widget, g_value_get_flags (value));
3369 case PROP_NO_SHOW_ALL:
3370 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3372 case PROP_HAS_TOOLTIP:
3373 gtk_widget_real_set_has_tooltip (widget,
3374 g_value_get_boolean (value), FALSE);
3376 case PROP_TOOLTIP_MARKUP:
3377 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3378 tooltip_markup = g_value_dup_string (value);
3380 /* Treat an empty string as a NULL string,
3381 * because an empty string would be useless for a tooltip:
3383 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3385 g_free (tooltip_markup);
3386 tooltip_markup = NULL;
3389 g_object_set_qdata_full (object, quark_tooltip_markup,
3390 tooltip_markup, g_free);
3392 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3393 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3394 if (gtk_widget_get_visible (widget))
3395 gtk_widget_queue_tooltip_query (widget);
3397 case PROP_TOOLTIP_TEXT:
3398 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3400 tooltip_text = g_value_get_string (value);
3402 /* Treat an empty string as a NULL string,
3403 * because an empty string would be useless for a tooltip:
3405 if (tooltip_text && (strlen (tooltip_text) == 0))
3406 tooltip_text = NULL;
3408 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3410 g_object_set_qdata_full (object, quark_tooltip_markup,
3411 tooltip_markup, g_free);
3413 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3414 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3415 if (gtk_widget_get_visible (widget))
3416 gtk_widget_queue_tooltip_query (widget);
3418 case PROP_DOUBLE_BUFFERED:
3419 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3422 gtk_widget_set_halign (widget, g_value_get_enum (value));
3425 gtk_widget_set_valign (widget, g_value_get_enum (value));
3427 case PROP_MARGIN_LEFT:
3428 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3430 case PROP_MARGIN_RIGHT:
3431 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3433 case PROP_MARGIN_TOP:
3434 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3436 case PROP_MARGIN_BOTTOM:
3437 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3440 g_object_freeze_notify (G_OBJECT (widget));
3441 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3442 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3443 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3444 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3445 g_object_thaw_notify (G_OBJECT (widget));
3448 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3450 case PROP_HEXPAND_SET:
3451 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3454 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3456 case PROP_VEXPAND_SET:
3457 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3460 g_object_freeze_notify (G_OBJECT (widget));
3461 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3462 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3463 g_object_thaw_notify (G_OBJECT (widget));
3466 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3472 gtk_widget_get_property (GObject *object,
3477 GtkWidget *widget = GTK_WIDGET (object);
3478 GtkWidgetPrivate *priv = widget->priv;
3486 g_value_set_string (value, priv->name);
3488 g_value_set_static_string (value, "");
3491 g_value_set_object (value, priv->parent);
3493 case PROP_WIDTH_REQUEST:
3496 gtk_widget_get_size_request (widget, &w, NULL);
3497 g_value_set_int (value, w);
3500 case PROP_HEIGHT_REQUEST:
3503 gtk_widget_get_size_request (widget, NULL, &h);
3504 g_value_set_int (value, h);
3508 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3510 case PROP_SENSITIVE:
3511 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3513 case PROP_APP_PAINTABLE:
3514 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3516 case PROP_CAN_FOCUS:
3517 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3519 case PROP_HAS_FOCUS:
3520 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3523 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3525 case PROP_CAN_DEFAULT:
3526 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3528 case PROP_HAS_DEFAULT:
3529 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3531 case PROP_RECEIVES_DEFAULT:
3532 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3534 case PROP_COMPOSITE_CHILD:
3535 g_value_set_boolean (value, widget->priv->composite_child);
3538 g_value_set_object (value, gtk_widget_get_style (widget));
3541 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3542 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3544 case PROP_NO_SHOW_ALL:
3545 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3547 case PROP_HAS_TOOLTIP:
3548 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3550 case PROP_TOOLTIP_TEXT:
3552 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3555 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3556 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3558 g_value_take_string (value, text);
3561 case PROP_TOOLTIP_MARKUP:
3562 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3565 g_value_set_object (value, gtk_widget_get_window (widget));
3567 case PROP_DOUBLE_BUFFERED:
3568 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3571 g_value_set_enum (value, gtk_widget_get_halign (widget));
3574 g_value_set_enum (value, gtk_widget_get_valign (widget));
3576 case PROP_MARGIN_LEFT:
3577 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3579 case PROP_MARGIN_RIGHT:
3580 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3582 case PROP_MARGIN_TOP:
3583 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3585 case PROP_MARGIN_BOTTOM:
3586 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3590 GtkWidgetAuxInfo *aux_info = gtk_widget_get_aux_info (widget, FALSE);
3591 if (aux_info == NULL)
3593 g_value_set_int (value, 0);
3597 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3598 aux_info->margin.right),
3599 MAX (aux_info->margin.top,
3600 aux_info->margin.bottom)));
3605 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3607 case PROP_HEXPAND_SET:
3608 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3611 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3613 case PROP_VEXPAND_SET:
3614 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3617 g_value_set_boolean (value,
3618 gtk_widget_get_hexpand (widget) &&
3619 gtk_widget_get_vexpand (widget));
3622 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3628 gtk_widget_init (GtkWidget *widget)
3630 GtkWidgetPrivate *priv;
3632 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3635 priv = widget->priv;
3637 priv->child_visible = TRUE;
3639 priv->allocation.x = -1;
3640 priv->allocation.y = -1;
3641 priv->allocation.width = 1;
3642 priv->allocation.height = 1;
3643 priv->window = NULL;
3644 priv->parent = NULL;
3646 priv->sensitive = TRUE;
3647 priv->composite_child = composite_child_stack != 0;
3648 priv->double_buffered = TRUE;
3649 priv->redraw_on_alloc = TRUE;
3650 priv->width_request_needed = TRUE;
3651 priv->height_request_needed = TRUE;
3652 priv->alloc_needed = TRUE;
3654 /* this will be set to TRUE if the widget gets a child or if the
3655 * expand flag is set on the widget, but until one of those happen
3656 * we know the expand is already properly FALSE.
3658 * We really want to default FALSE here to avoid computing expand
3659 * all over the place while initially building a widget tree.
3661 priv->need_compute_expand = FALSE;
3663 priv->style = gtk_widget_get_default_style ();
3664 g_object_ref (priv->style);
3669 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3671 GParamSpec **pspecs)
3673 GtkWidgetPrivate *priv = widget->priv;
3674 GtkWidget *container = priv->parent;
3677 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3678 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3682 * gtk_widget_freeze_child_notify:
3683 * @widget: a #GtkWidget
3685 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3686 * signals are queued until gtk_widget_thaw_child_notify() is called
3689 * This is the analogue of g_object_freeze_notify() for child properties.
3692 gtk_widget_freeze_child_notify (GtkWidget *widget)
3694 g_return_if_fail (GTK_IS_WIDGET (widget));
3696 if (!G_OBJECT (widget)->ref_count)
3699 g_object_ref (widget);
3700 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3701 g_object_unref (widget);
3705 * gtk_widget_child_notify:
3706 * @widget: a #GtkWidget
3707 * @child_property: the name of a child property installed on the
3708 * class of @widget<!-- -->'s parent
3710 * Emits a #GtkWidget::child-notify signal for the
3711 * <link linkend="child-properties">child property</link> @child_property
3714 * This is the analogue of g_object_notify() for child properties.
3716 * Also see gtk_container_child_notify().
3719 gtk_widget_child_notify (GtkWidget *widget,
3720 const gchar *child_property)
3722 if (widget->priv->parent == NULL)
3725 gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
3729 * gtk_widget_thaw_child_notify:
3730 * @widget: a #GtkWidget
3732 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3733 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3737 gtk_widget_thaw_child_notify (GtkWidget *widget)
3739 GObjectNotifyQueue *nqueue;
3741 g_return_if_fail (GTK_IS_WIDGET (widget));
3743 if (!G_OBJECT (widget)->ref_count)
3746 g_object_ref (widget);
3747 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3748 if (!nqueue || !nqueue->freeze_count)
3749 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3750 G_OBJECT_TYPE_NAME (widget), widget);
3752 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3753 g_object_unref (widget);
3759 * @type: type ID of the widget to create
3760 * @first_property_name: name of first property to set
3761 * @...: value of first property, followed by more properties,
3764 * This is a convenience function for creating a widget and setting
3765 * its properties in one go. For example you might write:
3766 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3767 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3768 * g_object_new(), but returns a widget so you don't have to
3769 * cast the object yourself.
3771 * Return value: a new #GtkWidget of type @widget_type
3774 gtk_widget_new (GType type,
3775 const gchar *first_property_name,
3781 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3783 va_start (var_args, first_property_name);
3784 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3791 gtk_widget_queue_draw_child (GtkWidget *widget)
3793 GtkWidgetPrivate *priv = widget->priv;
3796 parent = priv->parent;
3797 if (parent && gtk_widget_is_drawable (parent))
3798 gtk_widget_queue_draw_area (parent,
3801 priv->allocation.width,
3802 priv->allocation.height);
3806 * gtk_widget_unparent:
3807 * @widget: a #GtkWidget
3809 * This function is only for use in widget implementations.
3810 * Should be called by implementations of the remove method
3811 * on #GtkContainer, to dissociate a child from the container.
3814 gtk_widget_unparent (GtkWidget *widget)
3816 GtkWidgetPrivate *priv;
3817 GObjectNotifyQueue *nqueue;
3818 GtkWidget *toplevel;
3819 GtkWidget *old_parent;
3821 g_return_if_fail (GTK_IS_WIDGET (widget));
3823 priv = widget->priv;
3825 if (priv->parent == NULL)
3828 /* keep this function in sync with gtk_menu_detach() */
3830 gtk_widget_push_verify_invariants (widget);
3832 g_object_freeze_notify (G_OBJECT (widget));
3833 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3835 toplevel = gtk_widget_get_toplevel (widget);
3836 if (gtk_widget_is_toplevel (toplevel))
3837 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3839 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3840 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3842 gtk_widget_queue_draw_child (widget);
3844 /* Reset the width and height here, to force reallocation if we
3845 * get added back to a new parent. This won't work if our new
3846 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3847 * (would 0x0 be OK here?)
3849 priv->allocation.width = 1;
3850 priv->allocation.height = 1;
3852 if (gtk_widget_get_realized (widget))
3854 if (priv->in_reparent)
3855 gtk_widget_unmap (widget);
3857 gtk_widget_unrealize (widget);
3860 /* If we are unanchoring the child, we save around the toplevel
3861 * to emit hierarchy changed
3863 if (priv->parent->priv->anchored)
3864 g_object_ref (toplevel);
3868 /* Removing a widget from a container restores the child visible
3869 * flag to the default state, so it doesn't affect the child
3870 * in the next parent.
3872 priv->child_visible = TRUE;
3874 old_parent = priv->parent;
3875 priv->parent = NULL;
3877 /* parent may no longer expand if the removed
3878 * child was expand=TRUE and could therefore
3881 if (gtk_widget_get_visible (widget) &&
3882 (priv->need_compute_expand ||
3883 priv->computed_hexpand ||
3884 priv->computed_vexpand))
3886 gtk_widget_queue_compute_expand (old_parent);
3889 /* Unset BACKDROP since we are no longer inside a toplevel window */
3890 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_BACKDROP);
3892 gtk_style_context_set_parent (priv->context, NULL);
3894 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3897 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3898 g_object_unref (toplevel);
3901 /* Now that the parent pointer is nullified and the hierarchy-changed
3902 * already passed, go ahead and unset the parent window, if we are unparenting
3903 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
3904 * will fire again for the new subhierarchy.
3906 gtk_widget_set_parent_window (widget, NULL);
3908 g_object_notify (G_OBJECT (widget), "parent");
3909 g_object_thaw_notify (G_OBJECT (widget));
3911 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3912 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3914 gtk_widget_pop_verify_invariants (widget);
3915 g_object_unref (widget);
3919 * gtk_widget_destroy:
3920 * @widget: a #GtkWidget
3922 * Destroys a widget.
3925 * destroyed, it will break any references it holds to other objects.
3926 * If the widget is inside a container, the widget will be removed
3927 * from the container. If the widget is a toplevel (derived from
3928 * #GtkWindow), it will be removed from the list of toplevels, and the
3929 * reference GTK+ holds to it will be removed. Removing a
3930 * widget from its container or the list of toplevels results in the
3931 * widget being finalized, unless you've added additional references
3932 * to the widget with g_object_ref().
3934 * In most cases, only toplevel widgets (windows) require explicit
3935 * destruction, because when you destroy a toplevel its children will
3936 * be destroyed as well.
3939 gtk_widget_destroy (GtkWidget *widget)
3941 g_return_if_fail (GTK_IS_WIDGET (widget));
3943 if (!widget->priv->in_destruction)
3944 g_object_run_dispose (G_OBJECT (widget));
3948 * gtk_widget_destroyed:
3949 * @widget: a #GtkWidget
3950 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3952 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3953 * %NULL. It's intended to be used as a callback connected to the
3954 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3955 * as a signal handler, and pass the address of your widget variable
3956 * as user data. Then when the widget is destroyed, the variable will
3957 * be set to %NULL. Useful for example to avoid multiple copies
3958 * of the same dialog.
3961 gtk_widget_destroyed (GtkWidget *widget,
3962 GtkWidget **widget_pointer)
3964 /* Don't make any assumptions about the
3966 * Even check widget_pointer.
3969 *widget_pointer = NULL;
3974 * @widget: a #GtkWidget
3976 * Flags a widget to be displayed. Any widget that isn't shown will
3977 * not appear on the screen. If you want to show all the widgets in a
3978 * container, it's easier to call gtk_widget_show_all() on the
3979 * container, instead of individually showing the widgets.
3981 * Remember that you have to show the containers containing a widget,
3982 * in addition to the widget itself, before it will appear onscreen.
3984 * When a toplevel container is shown, it is immediately realized and
3985 * mapped; other shown widgets are realized and mapped when their
3986 * toplevel container is realized and mapped.
3989 gtk_widget_show (GtkWidget *widget)
3991 g_return_if_fail (GTK_IS_WIDGET (widget));
3993 if (!gtk_widget_get_visible (widget))
3995 g_object_ref (widget);
3996 gtk_widget_push_verify_invariants (widget);
3998 if (!gtk_widget_is_toplevel (widget))
3999 gtk_widget_queue_resize (widget);
4001 /* see comment in set_parent() for why this should and can be
4004 if (widget->priv->need_compute_expand ||
4005 widget->priv->computed_hexpand ||
4006 widget->priv->computed_vexpand)
4008 if (widget->priv->parent != NULL)
4009 gtk_widget_queue_compute_expand (widget->priv->parent);
4012 g_signal_emit (widget, widget_signals[SHOW], 0);
4013 g_object_notify (G_OBJECT (widget), "visible");
4015 gtk_widget_pop_verify_invariants (widget);
4016 g_object_unref (widget);
4021 gtk_widget_real_show (GtkWidget *widget)
4023 GtkWidgetPrivate *priv = widget->priv;
4025 if (!gtk_widget_get_visible (widget))
4027 priv->visible = TRUE;
4030 gtk_widget_get_mapped (priv->parent) &&
4031 gtk_widget_get_child_visible (widget) &&
4032 !gtk_widget_get_mapped (widget))
4033 gtk_widget_map (widget);
4038 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
4041 g_signal_handlers_disconnect_by_func (widget,
4042 gtk_widget_show_map_callback,
4047 * gtk_widget_show_now:
4048 * @widget: a #GtkWidget
4050 * Shows a widget. If the widget is an unmapped toplevel widget
4051 * (i.e. a #GtkWindow that has not yet been shown), enter the main
4052 * loop and wait for the window to actually be mapped. Be careful;
4053 * because the main loop is running, anything can happen during
4057 gtk_widget_show_now (GtkWidget *widget)
4061 g_return_if_fail (GTK_IS_WIDGET (widget));
4063 /* make sure we will get event */
4064 if (!gtk_widget_get_mapped (widget) &&
4065 gtk_widget_is_toplevel (widget))
4067 gtk_widget_show (widget);
4069 g_signal_connect (widget, "map-event",
4070 G_CALLBACK (gtk_widget_show_map_callback),
4074 gtk_main_iteration ();
4077 gtk_widget_show (widget);
4082 * @widget: a #GtkWidget
4084 * Reverses the effects of gtk_widget_show(), causing the widget to be
4085 * hidden (invisible to the user).
4088 gtk_widget_hide (GtkWidget *widget)
4090 g_return_if_fail (GTK_IS_WIDGET (widget));
4092 if (gtk_widget_get_visible (widget))
4094 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
4096 g_object_ref (widget);
4097 gtk_widget_push_verify_invariants (widget);
4099 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
4100 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
4102 /* a parent may now be expand=FALSE since we're hidden. */
4103 if (widget->priv->need_compute_expand ||
4104 widget->priv->computed_hexpand ||
4105 widget->priv->computed_vexpand)
4107 gtk_widget_queue_compute_expand (widget);
4110 g_signal_emit (widget, widget_signals[HIDE], 0);
4111 if (!gtk_widget_is_toplevel (widget))
4112 gtk_widget_queue_resize (widget);
4113 g_object_notify (G_OBJECT (widget), "visible");
4115 gtk_widget_pop_verify_invariants (widget);
4116 g_object_unref (widget);
4121 gtk_widget_real_hide (GtkWidget *widget)
4123 if (gtk_widget_get_visible (widget))
4125 widget->priv->visible = FALSE;
4127 if (gtk_widget_get_mapped (widget))
4128 gtk_widget_unmap (widget);
4133 * gtk_widget_hide_on_delete:
4134 * @widget: a #GtkWidget
4136 * Utility function; intended to be connected to the #GtkWidget::delete-event
4137 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4138 * argument, then returns %TRUE. If connected to ::delete-event, the
4139 * result is that clicking the close button for a window (on the
4140 * window frame, top right corner usually) will hide but not destroy
4141 * the window. By default, GTK+ destroys windows when ::delete-event
4144 * Return value: %TRUE
4147 gtk_widget_hide_on_delete (GtkWidget *widget)
4149 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4151 gtk_widget_hide (widget);
4157 * gtk_widget_show_all:
4158 * @widget: a #GtkWidget
4160 * Recursively shows a widget, and any child widgets (if the widget is
4164 gtk_widget_show_all (GtkWidget *widget)
4166 GtkWidgetClass *class;
4168 g_return_if_fail (GTK_IS_WIDGET (widget));
4170 if (gtk_widget_get_no_show_all (widget))
4173 class = GTK_WIDGET_GET_CLASS (widget);
4175 if (class->show_all)
4176 class->show_all (widget);
4181 * @widget: a #GtkWidget
4183 * This function is only for use in widget implementations. Causes
4184 * a widget to be mapped if it isn't already.
4187 gtk_widget_map (GtkWidget *widget)
4189 GtkWidgetPrivate *priv;
4191 g_return_if_fail (GTK_IS_WIDGET (widget));
4192 g_return_if_fail (gtk_widget_get_visible (widget));
4193 g_return_if_fail (gtk_widget_get_child_visible (widget));
4195 priv = widget->priv;
4197 if (!gtk_widget_get_mapped (widget))
4199 gtk_widget_push_verify_invariants (widget);
4201 if (!gtk_widget_get_realized (widget))
4202 gtk_widget_realize (widget);
4204 g_signal_emit (widget, widget_signals[MAP], 0);
4206 if (!gtk_widget_get_has_window (widget))
4207 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4209 gtk_widget_pop_verify_invariants (widget);
4215 * @widget: a #GtkWidget
4217 * This function is only for use in widget implementations. Causes
4218 * a widget to be unmapped if it's currently mapped.
4221 gtk_widget_unmap (GtkWidget *widget)
4223 GtkWidgetPrivate *priv;
4225 g_return_if_fail (GTK_IS_WIDGET (widget));
4227 priv = widget->priv;
4229 if (gtk_widget_get_mapped (widget))
4231 gtk_widget_push_verify_invariants (widget);
4233 if (!gtk_widget_get_has_window (widget))
4234 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4235 _gtk_tooltip_hide (widget);
4236 g_signal_emit (widget, widget_signals[UNMAP], 0);
4238 gtk_widget_pop_verify_invariants (widget);
4240 /* Unset pointer/window info */
4241 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4246 _gtk_widget_enable_device_events (GtkWidget *widget)
4248 GHashTable *device_events;
4249 GHashTableIter iter;
4250 gpointer key, value;
4252 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4257 g_hash_table_iter_init (&iter, device_events);
4259 while (g_hash_table_iter_next (&iter, &key, &value))
4262 GdkEventMask event_mask;
4265 event_mask = GPOINTER_TO_UINT (value);
4266 gtk_widget_add_events_internal (widget, device, event_mask);
4271 get_widget_windows (GtkWidget *widget)
4273 GList *window_list, *last, *l, *children, *ret;
4275 if (gtk_widget_get_has_window (widget))
4276 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4278 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4280 last = g_list_last (window_list);
4283 for (l = window_list; l; l = l->next)
4285 GtkWidget *window_widget = NULL;
4287 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4289 if (widget != window_widget)
4292 ret = g_list_prepend (ret, l->data);
4293 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4297 last = g_list_concat (last, children);
4298 last = g_list_last (last);
4302 g_list_free (window_list);
4308 device_enable_foreach (GtkWidget *widget,
4311 GdkDevice *device = user_data;
4312 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4316 device_disable_foreach (GtkWidget *widget,
4319 GdkDevice *device = user_data;
4320 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4324 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4329 GList *window_list, *l;
4331 window_list = get_widget_windows (widget);
4333 for (l = window_list; l; l = l->next)
4335 GdkEventMask events = 0;
4341 events = gdk_window_get_events (window);
4343 gdk_window_set_device_events (window, device, events);
4346 if (recurse && GTK_IS_CONTAINER (widget))
4349 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4351 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4354 g_list_free (window_list);
4358 gtk_widget_update_devices_mask (GtkWidget *widget,
4361 GList *enabled_devices, *l;
4363 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4365 for (l = enabled_devices; l; l = l->next)
4366 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4370 * gtk_widget_realize:
4371 * @widget: a #GtkWidget
4373 * Creates the GDK (windowing system) resources associated with a
4374 * widget. For example, @widget->window will be created when a widget
4375 * is realized. Normally realization happens implicitly; if you show
4376 * a widget and all its parent containers, then the widget will be
4377 * realized and mapped automatically.
4379 * Realizing a widget requires all
4380 * the widget's parent widgets to be realized; calling
4381 * gtk_widget_realize() realizes the widget's parents in addition to
4382 * @widget itself. If a widget is not yet inside a toplevel window
4383 * when you realize it, bad things will happen.
4385 * This function is primarily used in widget implementations, and
4386 * isn't very useful otherwise. Many times when you think you might
4387 * need it, a better approach is to connect to a signal that will be
4388 * called after the widget is realized automatically, such as
4389 * #GtkWidget::draw. Or simply g_signal_connect () to the
4390 * #GtkWidget::realize signal.
4393 gtk_widget_realize (GtkWidget *widget)
4395 GtkWidgetPrivate *priv;
4396 cairo_region_t *region;
4398 g_return_if_fail (GTK_IS_WIDGET (widget));
4399 g_return_if_fail (widget->priv->anchored ||
4400 GTK_IS_INVISIBLE (widget));
4402 priv = widget->priv;
4404 if (!gtk_widget_get_realized (widget))
4406 gtk_widget_push_verify_invariants (widget);
4409 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4410 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4413 if (priv->parent == NULL &&
4414 !gtk_widget_is_toplevel (widget))
4415 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4416 "inside a toplevel window is not going to work very well. "
4417 "Widgets must be inside a toplevel container before realizing them.");
4419 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4420 gtk_widget_realize (priv->parent);
4422 gtk_widget_ensure_style (widget);
4424 if (priv->style_update_pending)
4425 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4427 g_signal_emit (widget, widget_signals[REALIZE], 0);
4429 gtk_widget_real_set_has_tooltip (widget,
4430 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4433 if (priv->has_shape_mask)
4435 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4436 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4439 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4441 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4443 if (priv->multidevice)
4444 gdk_window_set_support_multidevice (priv->window, TRUE);
4446 _gtk_widget_enable_device_events (widget);
4447 gtk_widget_update_devices_mask (widget, TRUE);
4449 gtk_widget_pop_verify_invariants (widget);
4454 * gtk_widget_unrealize:
4455 * @widget: a #GtkWidget
4457 * This function is only useful in widget implementations.
4458 * Causes a widget to be unrealized (frees all GDK resources
4459 * associated with the widget, such as @widget->window).
4462 gtk_widget_unrealize (GtkWidget *widget)
4464 g_return_if_fail (GTK_IS_WIDGET (widget));
4466 gtk_widget_push_verify_invariants (widget);
4468 if (widget->priv->has_shape_mask)
4469 gtk_widget_shape_combine_region (widget, NULL);
4471 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4472 gtk_widget_input_shape_combine_region (widget, NULL);
4474 if (gtk_widget_get_realized (widget))
4476 g_object_ref (widget);
4478 if (widget->priv->mapped)
4479 gtk_widget_unmap (widget);
4481 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4482 g_assert (!widget->priv->mapped);
4483 gtk_widget_set_realized (widget, FALSE);
4485 g_object_unref (widget);
4488 gtk_widget_pop_verify_invariants (widget);
4491 /*****************************************
4493 *****************************************/
4496 * gtk_widget_queue_draw_region:
4497 * @widget: a #GtkWidget
4498 * @region: region to draw
4500 * Invalidates the rectangular area of @widget defined by @region by
4501 * calling gdk_window_invalidate_region() on the widget's window and
4502 * all its child windows. Once the main loop becomes idle (after the
4503 * current batch of events has been processed, roughly), the window
4504 * will receive expose events for the union of all regions that have
4507 * Normally you would only use this function in widget
4508 * implementations. You might also use it to schedule a redraw of a
4509 * #GtkDrawingArea or some portion thereof.
4514 gtk_widget_queue_draw_region (GtkWidget *widget,
4515 const cairo_region_t *region)
4517 GtkWidgetPrivate *priv;
4520 g_return_if_fail (GTK_IS_WIDGET (widget));
4522 priv = widget->priv;
4524 if (!gtk_widget_get_realized (widget))
4527 /* Just return if the widget or one of its ancestors isn't mapped */
4528 for (w = widget; w != NULL; w = w->priv->parent)
4529 if (!gtk_widget_get_mapped (w))
4532 gdk_window_invalidate_region (priv->window, region, TRUE);
4536 * gtk_widget_queue_draw_area:
4537 * @widget: a #GtkWidget
4538 * @x: x coordinate of upper-left corner of rectangle to redraw
4539 * @y: y coordinate of upper-left corner of rectangle to redraw
4540 * @width: width of region to draw
4541 * @height: height of region to draw
4543 * Convenience function that calls gtk_widget_queue_draw_region() on
4544 * the region created from the given coordinates.
4546 * The region here is specified in widget coordinates.
4547 * Widget coordinates are a bit odd; for historical reasons, they are
4548 * defined as @widget->window coordinates for widgets that are not
4549 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4550 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4553 gtk_widget_queue_draw_area (GtkWidget *widget,
4560 cairo_region_t *region;
4562 g_return_if_fail (GTK_IS_WIDGET (widget));
4567 rect.height = height;
4569 region = cairo_region_create_rectangle (&rect);
4570 gtk_widget_queue_draw_region (widget, region);
4571 cairo_region_destroy (region);
4575 * gtk_widget_queue_draw:
4576 * @widget: a #GtkWidget
4578 * Equivalent to calling gtk_widget_queue_draw_area() for the
4579 * entire area of a widget.
4582 gtk_widget_queue_draw (GtkWidget *widget)
4586 g_return_if_fail (GTK_IS_WIDGET (widget));
4588 gtk_widget_get_allocation (widget, &rect);
4590 if (!gtk_widget_get_has_window (widget))
4591 gtk_widget_queue_draw_area (widget,
4592 rect.x, rect.y, rect.width, rect.height);
4594 gtk_widget_queue_draw_area (widget,
4595 0, 0, rect.width, rect.height);
4599 * gtk_widget_queue_resize:
4600 * @widget: a #GtkWidget
4602 * This function is only for use in widget implementations.
4603 * Flags a widget to have its size renegotiated; should
4604 * be called when a widget for some reason has a new size request.
4605 * For example, when you change the text in a #GtkLabel, #GtkLabel
4606 * queues a resize to ensure there's enough space for the new text.
4608 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4609 * from inside its implementation of the GtkWidgetClass::size_allocate
4610 * virtual method. Calls to gtk_widget_queue_resize() from inside
4611 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4614 gtk_widget_queue_resize (GtkWidget *widget)
4616 g_return_if_fail (GTK_IS_WIDGET (widget));
4618 if (gtk_widget_get_realized (widget))
4619 gtk_widget_queue_shallow_draw (widget);
4621 _gtk_size_group_queue_resize (widget, 0);
4625 * gtk_widget_queue_resize_no_redraw:
4626 * @widget: a #GtkWidget
4628 * This function works like gtk_widget_queue_resize(),
4629 * except that the widget is not invalidated.
4634 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4636 g_return_if_fail (GTK_IS_WIDGET (widget));
4638 _gtk_size_group_queue_resize (widget, 0);
4642 * gtk_widget_size_request:
4643 * @widget: a #GtkWidget
4644 * @requisition: (out): a #GtkRequisition to be filled in
4646 * This function is typically used when implementing a #GtkContainer
4647 * subclass. Obtains the preferred size of a widget. The container
4648 * uses this information to arrange its child widgets and decide what
4649 * size allocations to give them with gtk_widget_size_allocate().
4651 * You can also call this function from an application, with some
4652 * caveats. Most notably, getting a size request requires the widget
4653 * to be associated with a screen, because font information may be
4654 * needed. Multihead-aware applications should keep this in mind.
4656 * Also remember that the size request is not necessarily the size
4657 * a widget will actually be allocated.
4659 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4662 gtk_widget_size_request (GtkWidget *widget,
4663 GtkRequisition *requisition)
4665 g_return_if_fail (GTK_IS_WIDGET (widget));
4667 gtk_widget_get_preferred_size (widget, requisition, NULL);
4671 * gtk_widget_get_child_requisition:
4672 * @widget: a #GtkWidget
4673 * @requisition: (out): a #GtkRequisition to be filled in
4675 * This function is only for use in widget implementations. Obtains
4676 * @widget->requisition, unless someone has forced a particular
4677 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4678 * in which case it returns that geometry instead of the widget's
4681 * This function differs from gtk_widget_size_request() in that
4682 * it retrieves the last size request value from @widget->requisition,
4683 * while gtk_widget_size_request() actually calls the "size_request" method
4684 * on @widget to compute the size request and fill in @widget->requisition,
4685 * and only then returns @widget->requisition.
4687 * Because this function does not call the "size_request" method, it
4688 * can only be used when you know that @widget->requisition is
4689 * up-to-date, that is, gtk_widget_size_request() has been called
4690 * since the last time a resize was queued. In general, only container
4691 * implementations have this information; applications should use
4692 * gtk_widget_size_request().
4695 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4698 gtk_widget_get_child_requisition (GtkWidget *widget,
4699 GtkRequisition *requisition)
4701 gtk_widget_get_preferred_size (widget, requisition, NULL);
4705 invalidate_predicate (GdkWindow *window,
4710 gdk_window_get_user_data (window, &user_data);
4712 return (user_data == data);
4715 /* Invalidate @region in widget->window and all children
4716 * of widget->window owned by widget. @region is in the
4717 * same coordinates as widget->allocation and will be
4718 * modified by this call.
4721 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4722 cairo_region_t *region)
4724 GtkWidgetPrivate *priv = widget->priv;
4726 if (!gtk_widget_get_realized (widget))
4729 if (gtk_widget_get_has_window (widget) && priv->parent)
4733 gdk_window_get_position (priv->window, &x, &y);
4734 cairo_region_translate (region, -x, -y);
4737 gdk_window_invalidate_maybe_recurse (priv->window, region,
4738 invalidate_predicate, widget);
4742 * gtk_widget_queue_shallow_draw:
4743 * @widget: a #GtkWidget
4745 * Like gtk_widget_queue_draw(), but only windows owned
4746 * by @widget are invalidated.
4749 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4752 cairo_region_t *region;
4754 if (!gtk_widget_get_realized (widget))
4757 gtk_widget_get_allocation (widget, &rect);
4759 region = cairo_region_create_rectangle (&rect);
4760 gtk_widget_invalidate_widget_windows (widget, region);
4761 cairo_region_destroy (region);
4765 * gtk_widget_size_allocate:
4766 * @widget: a #GtkWidget
4767 * @allocation: position and size to be allocated to @widget
4769 * This function is only used by #GtkContainer subclasses, to assign a size
4770 * and position to their child widgets.
4772 * In this function, the allocation may be adjusted. It will be forced
4773 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4774 * method on the child will be used to adjust the allocation. Standard
4775 * adjustments include removing the widget's margins, and applying the
4776 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4779 gtk_widget_size_allocate (GtkWidget *widget,
4780 GtkAllocation *allocation)
4782 GtkWidgetPrivate *priv;
4783 GdkRectangle real_allocation;
4784 GdkRectangle old_allocation;
4785 GdkRectangle adjusted_allocation;
4786 gboolean alloc_needed;
4787 gboolean size_changed;
4788 gboolean position_changed;
4789 gint natural_width, natural_height, dummy;
4790 gint min_width, min_height;
4792 priv = widget->priv;
4794 g_return_if_fail (GTK_IS_WIDGET (widget));
4796 gtk_widget_push_verify_invariants (widget);
4798 #ifdef G_ENABLE_DEBUG
4799 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4810 parent = gtk_widget_get_parent (parent);
4813 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4814 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4815 2 * depth, " ", name,
4816 allocation->width, allocation->height);
4818 #endif /* G_ENABLE_DEBUG */
4820 alloc_needed = priv->alloc_needed;
4821 if (!priv->width_request_needed && !priv->height_request_needed)
4822 /* Preserve request/allocate ordering */
4823 priv->alloc_needed = FALSE;
4825 old_allocation = priv->allocation;
4826 real_allocation = *allocation;
4828 adjusted_allocation = real_allocation;
4829 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4831 /* Go ahead and request the height for allocated width, note that the internals
4832 * of get_height_for_width will internally limit the for_size to natural size
4833 * when aligning implicitly.
4835 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4836 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
4840 /* Go ahead and request the width for allocated height, note that the internals
4841 * of get_width_for_height will internally limit the for_size to natural size
4842 * when aligning implicitly.
4844 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4845 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
4848 #ifdef G_ENABLE_DEBUG
4849 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4851 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
4852 !GTK_IS_SCROLLABLE (widget))
4853 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
4854 "Allocation is %dx%d, but minimum required size is %dx%d.",
4855 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
4856 G_OBJECT_TYPE_NAME (widget), widget,
4857 real_allocation.width, real_allocation.height,
4858 min_width, min_height);
4861 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4862 * allocated sizes and possibly limit them to the natural sizes */
4863 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4864 GTK_ORIENTATION_HORIZONTAL,
4867 &adjusted_allocation.x,
4868 &adjusted_allocation.width);
4869 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4870 GTK_ORIENTATION_VERTICAL,
4873 &adjusted_allocation.y,
4874 &adjusted_allocation.height);
4876 if (adjusted_allocation.x < real_allocation.x ||
4877 adjusted_allocation.y < real_allocation.y ||
4878 (adjusted_allocation.x + adjusted_allocation.width) >
4879 (real_allocation.x + real_allocation.width) ||
4880 (adjusted_allocation.y + adjusted_allocation.height >
4881 real_allocation.y + real_allocation.height))
4883 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",
4884 G_OBJECT_TYPE_NAME (widget), widget,
4885 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4886 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4887 adjusted_allocation = real_allocation; /* veto it */
4891 real_allocation = adjusted_allocation;
4894 if (real_allocation.width < 0 || real_allocation.height < 0)
4896 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4897 real_allocation.width,
4898 real_allocation.height);
4901 real_allocation.width = MAX (real_allocation.width, 1);
4902 real_allocation.height = MAX (real_allocation.height, 1);
4904 size_changed = (old_allocation.width != real_allocation.width ||
4905 old_allocation.height != real_allocation.height);
4906 position_changed = (old_allocation.x != real_allocation.x ||
4907 old_allocation.y != real_allocation.y);
4909 if (!alloc_needed && !size_changed && !position_changed)
4912 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4914 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4915 priv->width_request_needed = FALSE;
4916 priv->height_request_needed = FALSE;
4917 priv->alloc_needed = FALSE;
4919 if (gtk_widget_get_mapped (widget))
4921 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4923 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4925 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4926 cairo_region_union_rectangle (invalidate, &old_allocation);
4928 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4929 cairo_region_destroy (invalidate);
4934 if (priv->redraw_on_alloc)
4936 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4938 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4939 cairo_region_union_rectangle (invalidate, &old_allocation);
4941 gtk_widget_invalidate_widget_windows (widget, invalidate);
4942 cairo_region_destroy (invalidate);
4947 if ((size_changed || position_changed) && priv->parent &&
4948 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4950 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4951 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4952 cairo_region_destroy (invalidate);
4956 gtk_widget_pop_verify_invariants (widget);
4960 * gtk_widget_common_ancestor:
4961 * @widget_a: a #GtkWidget
4962 * @widget_b: a #GtkWidget
4964 * Find the common ancestor of @widget_a and @widget_b that
4965 * is closest to the two widgets.
4967 * Return value: the closest common ancestor of @widget_a and
4968 * @widget_b or %NULL if @widget_a and @widget_b do not
4969 * share a common ancestor.
4972 gtk_widget_common_ancestor (GtkWidget *widget_a,
4973 GtkWidget *widget_b)
4975 GtkWidget *parent_a;
4976 GtkWidget *parent_b;
4980 parent_a = widget_a;
4981 while (parent_a->priv->parent)
4983 parent_a = parent_a->priv->parent;
4987 parent_b = widget_b;
4988 while (parent_b->priv->parent)
4990 parent_b = parent_b->priv->parent;
4994 if (parent_a != parent_b)
4997 while (depth_a > depth_b)
4999 widget_a = widget_a->priv->parent;
5003 while (depth_b > depth_a)
5005 widget_b = widget_b->priv->parent;
5009 while (widget_a != widget_b)
5011 widget_a = widget_a->priv->parent;
5012 widget_b = widget_b->priv->parent;
5019 * gtk_widget_translate_coordinates:
5020 * @src_widget: a #GtkWidget
5021 * @dest_widget: a #GtkWidget
5022 * @src_x: X position relative to @src_widget
5023 * @src_y: Y position relative to @src_widget
5024 * @dest_x: (out): location to store X position relative to @dest_widget
5025 * @dest_y: (out): location to store Y position relative to @dest_widget
5027 * Translate coordinates relative to @src_widget's allocation to coordinates
5028 * relative to @dest_widget's allocations. In order to perform this
5029 * operation, both widgets must be realized, and must share a common
5032 * Return value: %FALSE if either widget was not realized, or there
5033 * was no common ancestor. In this case, nothing is stored in
5034 * *@dest_x and *@dest_y. Otherwise %TRUE.
5037 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5038 GtkWidget *dest_widget,
5044 GtkWidgetPrivate *src_priv = src_widget->priv;
5045 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5046 GtkWidget *ancestor;
5048 GList *dest_list = NULL;
5050 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5051 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5053 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5054 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5057 /* Translate from allocation relative to window relative */
5058 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5061 gdk_window_get_position (src_priv->window, &wx, &wy);
5063 src_x -= wx - src_priv->allocation.x;
5064 src_y -= wy - src_priv->allocation.y;
5068 src_x += src_priv->allocation.x;
5069 src_y += src_priv->allocation.y;
5072 /* Translate to the common ancestor */
5073 window = src_priv->window;
5074 while (window != ancestor->priv->window)
5078 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5083 window = gdk_window_get_effective_parent (window);
5085 if (!window) /* Handle GtkHandleBox */
5090 window = dest_priv->window;
5091 while (window != ancestor->priv->window)
5093 dest_list = g_list_prepend (dest_list, window);
5095 window = gdk_window_get_effective_parent (window);
5097 if (!window) /* Handle GtkHandleBox */
5099 g_list_free (dest_list);
5108 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5113 dest_list = g_list_remove (dest_list, dest_list->data);
5116 /* Translate from window relative to allocation relative */
5117 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5120 gdk_window_get_position (dest_priv->window, &wx, &wy);
5122 src_x += wx - dest_priv->allocation.x;
5123 src_y += wy - dest_priv->allocation.y;
5127 src_x -= dest_priv->allocation.x;
5128 src_y -= dest_priv->allocation.y;
5140 gtk_widget_real_size_allocate (GtkWidget *widget,
5141 GtkAllocation *allocation)
5143 GtkWidgetPrivate *priv = widget->priv;
5145 priv->allocation = *allocation;
5147 if (gtk_widget_get_realized (widget) &&
5148 gtk_widget_get_has_window (widget))
5150 gdk_window_move_resize (priv->window,
5151 allocation->x, allocation->y,
5152 allocation->width, allocation->height);
5156 /* translate initial/final into start/end */
5158 effective_align (GtkAlign align,
5159 GtkTextDirection direction)
5163 case GTK_ALIGN_START:
5164 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5166 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5173 adjust_for_align (GtkAlign align,
5175 gint *allocated_pos,
5176 gint *allocated_size)
5180 case GTK_ALIGN_FILL:
5181 /* change nothing */
5183 case GTK_ALIGN_START:
5184 /* keep *allocated_pos where it is */
5185 *allocated_size = MIN (*allocated_size, *natural_size);
5188 if (*allocated_size > *natural_size)
5190 *allocated_pos += (*allocated_size - *natural_size);
5191 *allocated_size = *natural_size;
5194 case GTK_ALIGN_CENTER:
5195 if (*allocated_size > *natural_size)
5197 *allocated_pos += (*allocated_size - *natural_size) / 2;
5198 *allocated_size = MIN (*allocated_size, *natural_size);
5205 adjust_for_margin(gint start_margin,
5209 gint *allocated_pos,
5210 gint *allocated_size)
5212 *minimum_size -= (start_margin + end_margin);
5213 *natural_size -= (start_margin + end_margin);
5214 *allocated_pos += start_margin;
5215 *allocated_size -= (start_margin + end_margin);
5219 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5220 GtkOrientation orientation,
5223 gint *allocated_pos,
5224 gint *allocated_size)
5226 const GtkWidgetAuxInfo *aux_info;
5228 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5230 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5232 adjust_for_margin (aux_info->margin.left,
5233 aux_info->margin.right,
5234 minimum_size, natural_size,
5235 allocated_pos, allocated_size);
5236 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5237 natural_size, allocated_pos, allocated_size);
5241 adjust_for_margin (aux_info->margin.top,
5242 aux_info->margin.bottom,
5243 minimum_size, natural_size,
5244 allocated_pos, allocated_size);
5245 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5246 natural_size, allocated_pos, allocated_size);
5251 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5254 GtkWidgetPrivate *priv = widget->priv;
5256 /* widgets must be onscreen for accels to take effect */
5257 return gtk_widget_is_sensitive (widget) &&
5258 gtk_widget_is_drawable (widget) &&
5259 gdk_window_is_viewable (priv->window);
5263 * gtk_widget_can_activate_accel:
5264 * @widget: a #GtkWidget
5265 * @signal_id: the ID of a signal installed on @widget
5267 * Determines whether an accelerator that activates the signal
5268 * identified by @signal_id can currently be activated.
5269 * This is done by emitting the #GtkWidget::can-activate-accel
5270 * signal on @widget; if the signal isn't overridden by a
5271 * handler or in a derived widget, then the default check is
5272 * that the widget must be sensitive, and the widget and all
5273 * its ancestors mapped.
5275 * Return value: %TRUE if the accelerator can be activated.
5280 gtk_widget_can_activate_accel (GtkWidget *widget,
5283 gboolean can_activate = FALSE;
5284 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5285 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5286 return can_activate;
5295 closure_accel_activate (GClosure *closure,
5296 GValue *return_value,
5297 guint n_param_values,
5298 const GValue *param_values,
5299 gpointer invocation_hint,
5300 gpointer marshal_data)
5302 AccelClosure *aclosure = (AccelClosure*) closure;
5303 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5306 g_signal_emit (closure->data, aclosure->signal_id, 0);
5308 /* whether accelerator was handled */
5309 g_value_set_boolean (return_value, can_activate);
5313 closures_destroy (gpointer data)
5315 GSList *slist, *closures = data;
5317 for (slist = closures; slist; slist = slist->next)
5319 g_closure_invalidate (slist->data);
5320 g_closure_unref (slist->data);
5322 g_slist_free (closures);
5326 widget_new_accel_closure (GtkWidget *widget,
5329 AccelClosure *aclosure;
5330 GClosure *closure = NULL;
5331 GSList *slist, *closures;
5333 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5334 for (slist = closures; slist; slist = slist->next)
5335 if (!gtk_accel_group_from_accel_closure (slist->data))
5337 /* reuse this closure */
5338 closure = slist->data;
5343 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5344 closures = g_slist_prepend (closures, g_closure_ref (closure));
5345 g_closure_sink (closure);
5346 g_closure_set_marshal (closure, closure_accel_activate);
5348 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5350 aclosure = (AccelClosure*) closure;
5351 g_assert (closure->data == widget);
5352 g_assert (closure->marshal == closure_accel_activate);
5353 aclosure->signal_id = signal_id;
5359 * gtk_widget_add_accelerator:
5360 * @widget: widget to install an accelerator on
5361 * @accel_signal: widget signal to emit on accelerator activation
5362 * @accel_group: accel group for this widget, added to its toplevel
5363 * @accel_key: GDK keyval of the accelerator
5364 * @accel_mods: modifier key combination of the accelerator
5365 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5367 * Installs an accelerator for this @widget in @accel_group that causes
5368 * @accel_signal to be emitted if the accelerator is activated.
5369 * The @accel_group needs to be added to the widget's toplevel via
5370 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5371 * Accelerators added through this function are not user changeable during
5372 * runtime. If you want to support accelerators that can be changed by the
5373 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5374 * gtk_menu_item_set_accel_path() instead.
5377 gtk_widget_add_accelerator (GtkWidget *widget,
5378 const gchar *accel_signal,
5379 GtkAccelGroup *accel_group,
5381 GdkModifierType accel_mods,
5382 GtkAccelFlags accel_flags)
5387 g_return_if_fail (GTK_IS_WIDGET (widget));
5388 g_return_if_fail (accel_signal != NULL);
5389 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5391 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5392 if (!query.signal_id ||
5393 !(query.signal_flags & G_SIGNAL_ACTION) ||
5394 query.return_type != G_TYPE_NONE ||
5397 /* hmm, should be elaborate enough */
5398 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5399 G_OBJECT_TYPE_NAME (widget), accel_signal);
5403 closure = widget_new_accel_closure (widget, query.signal_id);
5405 g_object_ref (widget);
5407 /* install the accelerator. since we don't map this onto an accel_path,
5408 * the accelerator will automatically be locked.
5410 gtk_accel_group_connect (accel_group,
5413 accel_flags | GTK_ACCEL_LOCKED,
5416 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5418 g_object_unref (widget);
5422 * gtk_widget_remove_accelerator:
5423 * @widget: widget to install an accelerator on
5424 * @accel_group: accel group for this widget
5425 * @accel_key: GDK keyval of the accelerator
5426 * @accel_mods: modifier key combination of the accelerator
5428 * Removes an accelerator from @widget, previously installed with
5429 * gtk_widget_add_accelerator().
5431 * Returns: whether an accelerator was installed and could be removed
5434 gtk_widget_remove_accelerator (GtkWidget *widget,
5435 GtkAccelGroup *accel_group,
5437 GdkModifierType accel_mods)
5439 GtkAccelGroupEntry *ag_entry;
5440 GList *slist, *clist;
5443 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5444 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5446 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5447 clist = gtk_widget_list_accel_closures (widget);
5448 for (slist = clist; slist; slist = slist->next)
5452 for (i = 0; i < n; i++)
5453 if (slist->data == (gpointer) ag_entry[i].closure)
5455 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5457 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5459 g_list_free (clist);
5464 g_list_free (clist);
5466 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5467 accel_key, accel_mods, accel_group,
5468 G_OBJECT_TYPE_NAME (widget), widget);
5474 * gtk_widget_list_accel_closures:
5475 * @widget: widget to list accelerator closures for
5477 * Lists the closures used by @widget for accelerator group connections
5478 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5479 * The closures can be used to monitor accelerator changes on @widget,
5480 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5481 * #GtkAccelGroup of a closure which can be found out with
5482 * gtk_accel_group_from_accel_closure().
5484 * Return value: (transfer container) (element-type GClosure):
5485 * a newly allocated #GList of closures
5488 gtk_widget_list_accel_closures (GtkWidget *widget)
5491 GList *clist = NULL;
5493 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5495 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5496 if (gtk_accel_group_from_accel_closure (slist->data))
5497 clist = g_list_prepend (clist, slist->data);
5503 GtkAccelGroup *accel_group;
5508 destroy_accel_path (gpointer data)
5510 AccelPath *apath = data;
5512 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5514 /* closures_destroy takes care of unrefing the closure */
5515 g_object_unref (apath->accel_group);
5517 g_slice_free (AccelPath, apath);
5522 * gtk_widget_set_accel_path:
5523 * @widget: a #GtkWidget
5524 * @accel_path: (allow-none): path used to look up the accelerator
5525 * @accel_group: (allow-none): a #GtkAccelGroup.
5527 * Given an accelerator group, @accel_group, and an accelerator path,
5528 * @accel_path, sets up an accelerator in @accel_group so whenever the
5529 * key binding that is defined for @accel_path is pressed, @widget
5530 * will be activated. This removes any accelerators (for any
5531 * accelerator group) installed by previous calls to
5532 * gtk_widget_set_accel_path(). Associating accelerators with
5533 * paths allows them to be modified by the user and the modifications
5534 * to be saved for future use. (See gtk_accel_map_save().)
5536 * This function is a low level function that would most likely
5537 * be used by a menu creation system like #GtkUIManager. If you
5538 * use #GtkUIManager, setting up accelerator paths will be done
5541 * Even when you you aren't using #GtkUIManager, if you only want to
5542 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5543 * provides a somewhat more convenient interface.
5545 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5546 * pass a static string, you can save some memory by interning it first with
5547 * g_intern_static_string().
5550 gtk_widget_set_accel_path (GtkWidget *widget,
5551 const gchar *accel_path,
5552 GtkAccelGroup *accel_group)
5556 g_return_if_fail (GTK_IS_WIDGET (widget));
5557 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5561 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5562 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5564 gtk_accel_map_add_entry (accel_path, 0, 0);
5565 apath = g_slice_new (AccelPath);
5566 apath->accel_group = g_object_ref (accel_group);
5567 apath->path_quark = g_quark_from_string (accel_path);
5568 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5573 /* also removes possible old settings */
5574 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5577 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5579 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5583 _gtk_widget_get_accel_path (GtkWidget *widget,
5588 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5590 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5592 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5593 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5597 * gtk_widget_mnemonic_activate:
5598 * @widget: a #GtkWidget
5599 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5601 * Emits the #GtkWidget::mnemonic-activate signal.
5603 * The default handler for this signal activates the @widget if
5604 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5607 * Returns: %TRUE if the signal has been handled
5610 gtk_widget_mnemonic_activate (GtkWidget *widget,
5611 gboolean group_cycling)
5615 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5617 group_cycling = group_cycling != FALSE;
5618 if (!gtk_widget_is_sensitive (widget))
5621 g_signal_emit (widget,
5622 widget_signals[MNEMONIC_ACTIVATE],
5630 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5631 gboolean group_cycling)
5633 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5634 gtk_widget_activate (widget);
5635 else if (gtk_widget_get_can_focus (widget))
5636 gtk_widget_grab_focus (widget);
5639 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5640 G_OBJECT_TYPE_NAME (widget));
5641 gtk_widget_error_bell (widget);
5646 static const cairo_user_data_key_t event_key;
5649 _gtk_cairo_get_event (cairo_t *cr)
5651 g_return_val_if_fail (cr != NULL, NULL);
5653 return cairo_get_user_data (cr, &event_key);
5657 gtk_cairo_set_event (cairo_t *cr,
5658 GdkEventExpose *event)
5660 cairo_set_user_data (cr, &event_key, event, NULL);
5664 * gtk_cairo_should_draw_window:
5665 * @cr: a cairo context
5666 * @window: the window to check. @window may not be an input-only
5669 * This function is supposed to be called in #GtkWidget::draw
5670 * implementations for widgets that support multiple windows.
5671 * @cr must be untransformed from invoking of the draw function.
5672 * This function will return %TRUE if the contents of the given
5673 * @window are supposed to be drawn and %FALSE otherwise. Note
5674 * that when the drawing was not initiated by the windowing
5675 * system this function will return %TRUE for all windows, so
5676 * you need to draw the bottommost window first. Also, do not
5677 * use "else if" statements to check which window should be drawn.
5679 * Returns: %TRUE if @window should be drawn
5684 gtk_cairo_should_draw_window (cairo_t *cr,
5687 GdkEventExpose *event;
5689 g_return_val_if_fail (cr != NULL, FALSE);
5690 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5692 event = _gtk_cairo_get_event (cr);
5694 return event == NULL ||
5695 event->window == window;
5699 gtk_widget_get_clip_draw (GtkWidget *widget)
5701 /* labels are not clipped, because clipping them would cause
5702 * mnemonics to not appear on characters that go beyond the
5704 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
5706 if (GTK_IS_LABEL (widget))
5712 /* code shared by gtk_container_propagate_draw() and
5716 _gtk_widget_draw_internal (GtkWidget *widget,
5718 gboolean clip_to_size)
5720 if (!gtk_widget_is_drawable (widget))
5723 clip_to_size &= gtk_widget_get_clip_draw (widget);
5727 cairo_rectangle (cr,
5729 widget->priv->allocation.width,
5730 widget->priv->allocation.height);
5734 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5738 g_signal_emit (widget, widget_signals[DRAW],
5742 if (cairo_status (cr) &&
5743 _gtk_cairo_get_event (cr))
5745 /* We check the event so we only warn about internal GTK calls.
5746 * Errors might come from PDF streams having write failures and
5747 * we don't want to spam stderr in that case.
5748 * We do want to catch errors from
5750 g_warning ("drawing failure for widget `%s': %s",
5751 G_OBJECT_TYPE_NAME (widget),
5752 cairo_status_to_string (cairo_status (cr)));
5759 * @widget: the widget to draw. It must be drawable (see
5760 * gtk_widget_is_drawable()) and a size must have been allocated.
5761 * @cr: a cairo context to draw to
5763 * Draws @widget to @cr. The top left corner of the widget will be
5764 * drawn to the currently set origin point of @cr.
5766 * You should pass a cairo context as @cr argument that is in an
5767 * original state. Otherwise the resulting drawing is undefined. For
5768 * example changing the operator using cairo_set_operator() or the
5769 * line width using cairo_set_line_width() might have unwanted side
5771 * You may however change the context's transform matrix - like with
5772 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5773 * region with cairo_clip() prior to calling this function. Also, it
5774 * is fine to modify the context with cairo_save() and
5775 * cairo_push_group() prior to calling this function.
5777 * <note><para>Special purpose widgets may contain special code for
5778 * rendering to the screen and might appear differently on screen
5779 * and when rendered using gtk_widget_draw().</para></note>
5784 gtk_widget_draw (GtkWidget *widget,
5787 GdkEventExpose *tmp_event;
5789 g_return_if_fail (GTK_IS_WIDGET (widget));
5790 g_return_if_fail (!widget->priv->alloc_needed);
5791 g_return_if_fail (cr != NULL);
5794 /* We have to reset the event here so that draw functions can call
5795 * gtk_widget_draw() on random other widgets and get the desired
5796 * effect: Drawing all contents, not just the current window.
5798 tmp_event = _gtk_cairo_get_event (cr);
5799 gtk_cairo_set_event (cr, NULL);
5801 _gtk_widget_draw_internal (widget, cr, TRUE);
5803 gtk_cairo_set_event (cr, tmp_event);
5808 gtk_widget_real_key_press_event (GtkWidget *widget,
5811 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5815 gtk_widget_real_key_release_event (GtkWidget *widget,
5818 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5822 gtk_widget_real_focus_in_event (GtkWidget *widget,
5823 GdkEventFocus *event)
5825 gtk_widget_queue_shallow_draw (widget);
5831 gtk_widget_real_focus_out_event (GtkWidget *widget,
5832 GdkEventFocus *event)
5834 gtk_widget_queue_shallow_draw (widget);
5840 gtk_widget_real_touch_event (GtkWidget *widget,
5841 GdkEventTouch *event)
5844 gboolean return_val;
5847 if (!event->emulating_pointer)
5850 if (event->type == GDK_TOUCH_BEGIN ||
5851 event->type == GDK_TOUCH_END)
5855 if (event->type == GDK_TOUCH_BEGIN)
5857 type = GDK_BUTTON_PRESS;
5858 signum = BUTTON_PRESS_EVENT;
5862 type = GDK_BUTTON_RELEASE;
5863 signum = BUTTON_RELEASE_EVENT;
5865 bevent = gdk_event_new (type);
5866 bevent->any.window = g_object_ref (event->window);
5867 bevent->any.send_event = FALSE;
5868 bevent->button.time = event->time;
5869 bevent->button.state = event->state;
5870 bevent->button.button = 1;
5871 bevent->button.x_root = event->x_root;
5872 bevent->button.y_root = event->y_root;
5873 bevent->button.x = event->x;
5874 bevent->button.y = event->y;
5875 bevent->button.device = event->device;
5876 bevent->button.axes = g_memdup (event->axes,
5877 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
5878 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
5880 else if (event->type == GDK_TOUCH_UPDATE)
5882 signum = MOTION_NOTIFY_EVENT;
5883 bevent = gdk_event_new (GDK_MOTION_NOTIFY);
5884 bevent->any.window = g_object_ref (event->window);
5885 bevent->any.send_event = FALSE;
5886 bevent->motion.time = event->time;
5887 bevent->motion.state = event->state;
5888 bevent->motion.x_root = event->x_root;
5889 bevent->motion.y_root = event->y_root;
5890 bevent->motion.x = event->x;
5891 bevent->motion.y = event->y;
5892 bevent->motion.device = event->device;
5893 bevent->motion.is_hint = FALSE;
5894 bevent->motion.axes = g_memdup (event->axes,
5895 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
5896 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
5901 g_signal_emit (widget, widget_signals[signum], 0, bevent, &return_val);
5903 gdk_event_free (bevent);
5909 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5910 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5914 * @widget: a #GtkWidget
5915 * @event: a #GdkEvent
5917 * Rarely-used function. This function is used to emit
5918 * the event signals on a widget (those signals should never
5919 * be emitted without using this function to do so).
5920 * If you want to synthesize an event though, don't use this function;
5921 * instead, use gtk_main_do_event() so the event will behave as if
5922 * it were in the event queue. Don't synthesize expose events; instead,
5923 * use gdk_window_invalidate_rect() to invalidate a region of the
5926 * Return value: return from the event signal emission (%TRUE if
5927 * the event was handled)
5930 gtk_widget_event (GtkWidget *widget,
5933 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5934 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5936 if (event->type == GDK_EXPOSE)
5938 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5939 "the same effect, call gdk_window_invalidate_rect/region(), "
5940 "followed by gdk_window_process_updates().");
5944 return gtk_widget_event_internal (widget, event);
5948 _gtk_widget_set_captured_event_handler (GtkWidget *widget,
5949 GtkCapturedEventHandler callback)
5951 g_object_set_data (G_OBJECT (widget), "captured-event-handler", callback);
5955 _gtk_widget_captured_event (GtkWidget *widget,
5958 gboolean return_val = FALSE;
5959 GtkCapturedEventHandler handler;
5961 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5962 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5964 if (event->type == GDK_EXPOSE)
5966 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5967 "the same effect, call gdk_window_invalidate_rect/region(), "
5968 "followed by gdk_window_process_updates().");
5972 if (!event_window_is_still_viewable (event))
5975 handler = g_object_get_data (G_OBJECT (widget), "captured-event-handler");
5979 g_object_ref (widget);
5981 return_val = handler (widget, event);
5982 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5984 /* The widget that was originally to receive the event
5985 * handles motion hints, but the capturing widget might
5986 * not, so ensure we get further motion events.
5989 event->type == GDK_MOTION_NOTIFY &&
5990 event->motion.is_hint &&
5991 (gdk_window_get_events (event->any.window) &
5992 GDK_POINTER_MOTION_HINT_MASK) != 0)
5993 gdk_event_request_motions (&event->motion);
5995 g_object_unref (widget);
6000 /* Returns TRUE if a translation should be done */
6002 _gtk_widget_get_translation_to_window (GtkWidget *widget,
6007 GdkWindow *w, *widget_window;
6009 if (!gtk_widget_get_has_window (widget))
6011 *x = -widget->priv->allocation.x;
6012 *y = -widget->priv->allocation.y;
6020 widget_window = gtk_widget_get_window (widget);
6022 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
6025 gdk_window_get_position (w, &wx, &wy);
6042 * gtk_cairo_transform_to_window:
6043 * @cr: the cairo context to transform
6044 * @widget: the widget the context is currently centered for
6045 * @window: the window to transform the context to
6047 * Transforms the given cairo context @cr that from @widget-relative
6048 * coordinates to @window-relative coordinates.
6049 * If the @widget's window is not an ancestor of @window, no
6050 * modification will be applied.
6052 * This is the inverse to the transformation GTK applies when
6053 * preparing an expose event to be emitted with the #GtkWidget::draw
6054 * signal. It is intended to help porting multiwindow widgets from
6055 * GTK+ 2 to the rendering architecture of GTK+ 3.
6060 gtk_cairo_transform_to_window (cairo_t *cr,
6066 g_return_if_fail (cr != NULL);
6067 g_return_if_fail (GTK_IS_WIDGET (widget));
6068 g_return_if_fail (GDK_IS_WINDOW (window));
6070 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
6071 cairo_translate (cr, x, y);
6075 * gtk_widget_send_expose:
6076 * @widget: a #GtkWidget
6077 * @event: a expose #GdkEvent
6079 * Very rarely-used function. This function is used to emit
6080 * an expose event on a widget. This function is not normally used
6081 * directly. The only time it is used is when propagating an expose
6082 * event to a child %NO_WINDOW widget, and that is normally done
6083 * using gtk_container_propagate_draw().
6085 * If you want to force an area of a window to be redrawn,
6086 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
6087 * To cause the redraw to be done immediately, follow that call
6088 * with a call to gdk_window_process_updates().
6090 * Return value: return from the event signal emission (%TRUE if
6091 * the event was handled)
6094 gtk_widget_send_expose (GtkWidget *widget,
6097 gboolean result = FALSE;
6102 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6103 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
6104 g_return_val_if_fail (event != NULL, TRUE);
6105 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
6107 cr = gdk_cairo_create (event->expose.window);
6108 gtk_cairo_set_event (cr, &event->expose);
6110 gdk_cairo_region (cr, event->expose.region);
6113 do_clip = _gtk_widget_get_translation_to_window (widget,
6114 event->expose.window,
6116 cairo_translate (cr, -x, -y);
6118 _gtk_widget_draw_internal (widget, cr, do_clip);
6120 /* unset here, so if someone keeps a reference to cr we
6121 * don't leak the window. */
6122 gtk_cairo_set_event (cr, NULL);
6129 event_window_is_still_viewable (GdkEvent *event)
6131 /* Check that we think the event's window is viewable before
6132 * delivering the event, to prevent suprises. We do this here
6133 * at the last moment, since the event may have been queued
6134 * up behind other events, held over a recursive main loop, etc.
6136 switch (event->type)
6139 case GDK_MOTION_NOTIFY:
6140 case GDK_BUTTON_PRESS:
6141 case GDK_2BUTTON_PRESS:
6142 case GDK_3BUTTON_PRESS:
6144 case GDK_ENTER_NOTIFY:
6145 case GDK_PROXIMITY_IN:
6147 return event->any.window && gdk_window_is_viewable (event->any.window);
6150 /* The following events are the second half of paired events;
6151 * we always deliver them to deal with widgets that clean up
6152 * on the second half.
6154 case GDK_BUTTON_RELEASE:
6155 case GDK_KEY_RELEASE:
6156 case GDK_LEAVE_NOTIFY:
6157 case GDK_PROXIMITY_OUT:
6161 /* Remaining events would make sense on an not-viewable window,
6162 * or don't have an associated window.
6169 gtk_widget_event_internal (GtkWidget *widget,
6172 gboolean return_val = FALSE;
6174 /* We check only once for is-still-visible; if someone
6175 * hides the window in on of the signals on the widget,
6176 * they are responsible for returning TRUE to terminate
6179 if (!event_window_is_still_viewable (event))
6182 g_object_ref (widget);
6184 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6185 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6190 switch (event->type)
6196 case GDK_BUTTON_PRESS:
6197 case GDK_2BUTTON_PRESS:
6198 case GDK_3BUTTON_PRESS:
6199 signal_num = BUTTON_PRESS_EVENT;
6201 case GDK_TOUCH_BEGIN:
6202 case GDK_TOUCH_UPDATE:
6204 case GDK_TOUCH_CANCEL:
6205 signal_num = TOUCH_EVENT;
6208 signal_num = SCROLL_EVENT;
6210 case GDK_BUTTON_RELEASE:
6211 signal_num = BUTTON_RELEASE_EVENT;
6213 case GDK_MOTION_NOTIFY:
6214 signal_num = MOTION_NOTIFY_EVENT;
6217 signal_num = DELETE_EVENT;
6220 signal_num = DESTROY_EVENT;
6221 _gtk_tooltip_hide (widget);
6224 signal_num = KEY_PRESS_EVENT;
6226 case GDK_KEY_RELEASE:
6227 signal_num = KEY_RELEASE_EVENT;
6229 case GDK_ENTER_NOTIFY:
6230 signal_num = ENTER_NOTIFY_EVENT;
6232 case GDK_LEAVE_NOTIFY:
6233 signal_num = LEAVE_NOTIFY_EVENT;
6235 case GDK_FOCUS_CHANGE:
6236 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6237 if (event->focus_change.in)
6238 _gtk_tooltip_focus_in (widget);
6240 _gtk_tooltip_focus_out (widget);
6243 signal_num = CONFIGURE_EVENT;
6246 signal_num = MAP_EVENT;
6249 signal_num = UNMAP_EVENT;
6251 case GDK_WINDOW_STATE:
6252 signal_num = WINDOW_STATE_EVENT;
6254 case GDK_PROPERTY_NOTIFY:
6255 signal_num = PROPERTY_NOTIFY_EVENT;
6257 case GDK_SELECTION_CLEAR:
6258 signal_num = SELECTION_CLEAR_EVENT;
6260 case GDK_SELECTION_REQUEST:
6261 signal_num = SELECTION_REQUEST_EVENT;
6263 case GDK_SELECTION_NOTIFY:
6264 signal_num = SELECTION_NOTIFY_EVENT;
6266 case GDK_PROXIMITY_IN:
6267 signal_num = PROXIMITY_IN_EVENT;
6269 case GDK_PROXIMITY_OUT:
6270 signal_num = PROXIMITY_OUT_EVENT;
6272 case GDK_VISIBILITY_NOTIFY:
6273 signal_num = VISIBILITY_NOTIFY_EVENT;
6275 case GDK_GRAB_BROKEN:
6276 signal_num = GRAB_BROKEN_EVENT;
6279 signal_num = DAMAGE_EVENT;
6282 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6286 if (signal_num != -1)
6287 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6289 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6290 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6294 g_object_unref (widget);
6300 * gtk_widget_activate:
6301 * @widget: a #GtkWidget that's activatable
6303 * For widgets that can be "activated" (buttons, menu items, etc.)
6304 * this function activates them. Activation is what happens when you
6305 * press Enter on a widget during key navigation. If @widget isn't
6306 * activatable, the function returns %FALSE.
6308 * Return value: %TRUE if the widget was activatable
6311 gtk_widget_activate (GtkWidget *widget)
6313 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6315 if (WIDGET_CLASS (widget)->activate_signal)
6317 /* FIXME: we should eventually check the signals signature here */
6318 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6327 gtk_widget_reparent_subwindows (GtkWidget *widget,
6328 GdkWindow *new_window)
6330 GtkWidgetPrivate *priv = widget->priv;
6332 if (!gtk_widget_get_has_window (widget))
6334 GList *children = gdk_window_get_children (priv->window);
6337 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6339 GdkWindow *window = tmp_list->data;
6342 gdk_window_get_user_data (window, &child);
6343 while (child && child != widget)
6344 child = ((GtkWidget*) child)->priv->parent;
6347 gdk_window_reparent (window, new_window, 0, 0);
6350 g_list_free (children);
6355 GList *tmp_list, *children;
6357 parent = gdk_window_get_parent (priv->window);
6360 gdk_window_reparent (priv->window, new_window, 0, 0);
6363 children = gdk_window_get_children (parent);
6365 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6367 GdkWindow *window = tmp_list->data;
6370 gdk_window_get_user_data (window, &child);
6372 if (child == widget)
6373 gdk_window_reparent (window, new_window, 0, 0);
6376 g_list_free (children);
6382 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6383 gpointer client_data)
6385 GtkWidgetPrivate *priv = widget->priv;
6387 g_assert (client_data != NULL);
6389 if (!gtk_widget_get_has_window (widget))
6392 g_object_unref (priv->window);
6393 priv->window = (GdkWindow*) client_data;
6395 g_object_ref (priv->window);
6397 if (GTK_IS_CONTAINER (widget))
6398 gtk_container_forall (GTK_CONTAINER (widget),
6399 gtk_widget_reparent_fixup_child,
6405 * gtk_widget_reparent:
6406 * @widget: a #GtkWidget
6407 * @new_parent: a #GtkContainer to move the widget into
6409 * Moves a widget from one #GtkContainer to another, handling reference
6410 * count issues to avoid destroying the widget.
6413 gtk_widget_reparent (GtkWidget *widget,
6414 GtkWidget *new_parent)
6416 GtkWidgetPrivate *priv;
6418 g_return_if_fail (GTK_IS_WIDGET (widget));
6419 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6420 priv = widget->priv;
6421 g_return_if_fail (priv->parent != NULL);
6423 if (priv->parent != new_parent)
6425 /* First try to see if we can get away without unrealizing
6426 * the widget as we reparent it. if so we set a flag so
6427 * that gtk_widget_unparent doesn't unrealize widget
6429 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6430 priv->in_reparent = TRUE;
6432 g_object_ref (widget);
6433 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6434 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6435 g_object_unref (widget);
6437 if (priv->in_reparent)
6439 priv->in_reparent = FALSE;
6441 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6442 gtk_widget_reparent_fixup_child (widget,
6443 gtk_widget_get_parent_window (widget));
6446 g_object_notify (G_OBJECT (widget), "parent");
6451 * gtk_widget_intersect:
6452 * @widget: a #GtkWidget
6453 * @area: a rectangle
6454 * @intersection: rectangle to store intersection of @widget and @area
6456 * Computes the intersection of a @widget's area and @area, storing
6457 * the intersection in @intersection, and returns %TRUE if there was
6458 * an intersection. @intersection may be %NULL if you're only
6459 * interested in whether there was an intersection.
6461 * Return value: %TRUE if there was an intersection
6464 gtk_widget_intersect (GtkWidget *widget,
6465 const GdkRectangle *area,
6466 GdkRectangle *intersection)
6468 GtkWidgetPrivate *priv;
6473 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6474 g_return_val_if_fail (area != NULL, FALSE);
6476 priv = widget->priv;
6479 dest = intersection;
6483 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6485 if (return_val && intersection && gtk_widget_get_has_window (widget))
6487 intersection->x -= priv->allocation.x;
6488 intersection->y -= priv->allocation.y;
6495 * gtk_widget_region_intersect:
6496 * @widget: a #GtkWidget
6497 * @region: a #cairo_region_t, in the same coordinate system as
6498 * @widget->allocation. That is, relative to @widget->window
6499 * for %NO_WINDOW widgets; relative to the parent window
6500 * of @widget->window for widgets with their own window.
6502 * Computes the intersection of a @widget's area and @region, returning
6503 * the intersection. The result may be empty, use cairo_region_is_empty() to
6506 * Returns: A newly allocated region holding the intersection of @widget
6507 * and @region. The coordinates of the return value are relative to
6508 * @widget->window for %NO_WINDOW widgets, and relative to the parent
6509 * window of @widget->window for widgets with their own window.
6512 gtk_widget_region_intersect (GtkWidget *widget,
6513 const cairo_region_t *region)
6516 cairo_region_t *dest;
6518 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6519 g_return_val_if_fail (region != NULL, NULL);
6521 gtk_widget_get_allocation (widget, &rect);
6523 dest = cairo_region_create_rectangle (&rect);
6525 cairo_region_intersect (dest, region);
6531 * _gtk_widget_grab_notify:
6532 * @widget: a #GtkWidget
6533 * @was_grabbed: whether a grab is now in effect
6535 * Emits the #GtkWidget::grab-notify signal on @widget.
6540 _gtk_widget_grab_notify (GtkWidget *widget,
6541 gboolean was_grabbed)
6543 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6547 * gtk_widget_grab_focus:
6548 * @widget: a #GtkWidget
6550 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6551 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6552 * something like #GtkFrame won't work.
6554 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6555 * gtk_widget_set_can_focus() to modify that flag.
6557 * The widget also needs to be realized and mapped. This is indicated by the
6558 * related signals. Grabbing the focus immediately after creating the widget
6559 * will likely fail and cause critical warnings.
6562 gtk_widget_grab_focus (GtkWidget *widget)
6564 g_return_if_fail (GTK_IS_WIDGET (widget));
6566 if (!gtk_widget_is_sensitive (widget))
6569 g_object_ref (widget);
6570 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6571 g_object_notify (G_OBJECT (widget), "has-focus");
6572 g_object_unref (widget);
6576 reset_focus_recurse (GtkWidget *widget,
6579 if (GTK_IS_CONTAINER (widget))
6581 GtkContainer *container;
6583 container = GTK_CONTAINER (widget);
6584 gtk_container_set_focus_child (container, NULL);
6586 gtk_container_foreach (container,
6587 reset_focus_recurse,
6593 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6595 if (gtk_widget_get_can_focus (focus_widget))
6597 GtkWidget *toplevel;
6600 /* clear the current focus setting, break if the current widget
6601 * is the focus widget's parent, since containers above that will
6602 * be set by the next loop.
6604 toplevel = gtk_widget_get_toplevel (focus_widget);
6605 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6607 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6609 if (widget == focus_widget)
6611 /* We call _gtk_window_internal_set_focus() here so that the
6612 * toplevel window can request the focus if necessary.
6613 * This is needed when the toplevel is a GtkPlug
6615 if (!gtk_widget_has_focus (widget))
6616 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6623 GtkWidget *common_ancestor = gtk_widget_common_ancestor (widget, focus_widget);
6625 if (widget != common_ancestor)
6627 while (widget->priv->parent && widget->priv->parent != common_ancestor)
6629 widget = widget->priv->parent;
6630 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6635 else if (toplevel != focus_widget)
6637 /* gtk_widget_grab_focus() operates on a tree without window...
6638 * actually, this is very questionable behaviour.
6641 gtk_container_foreach (GTK_CONTAINER (toplevel),
6642 reset_focus_recurse,
6646 /* now propagate the new focus up the widget tree and finally
6647 * set it on the window
6649 widget = focus_widget;
6650 while (widget->priv->parent)
6652 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6653 widget = widget->priv->parent;
6655 if (GTK_IS_WINDOW (widget))
6656 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6661 gtk_widget_real_query_tooltip (GtkWidget *widget,
6664 gboolean keyboard_tip,
6665 GtkTooltip *tooltip)
6667 gchar *tooltip_markup;
6668 gboolean has_tooltip;
6670 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6671 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6673 if (has_tooltip && tooltip_markup)
6675 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6683 gtk_widget_real_state_flags_changed (GtkWidget *widget,
6684 GtkStateFlags old_state)
6686 gtk_widget_update_pango_context (widget);
6690 gtk_widget_real_style_updated (GtkWidget *widget)
6692 GtkWidgetPrivate *priv = widget->priv;
6694 gtk_widget_update_pango_context (widget);
6696 if (priv->style != NULL &&
6697 priv->style != gtk_widget_get_default_style ())
6699 /* Trigger ::style-set for old
6700 * widgets not listening to this
6702 g_signal_emit (widget,
6703 widget_signals[STYLE_SET],
6705 widget->priv->style);
6708 if (widget->priv->context)
6710 if (gtk_widget_get_realized (widget) &&
6711 gtk_widget_get_has_window (widget))
6712 gtk_style_context_set_background (widget->priv->context,
6713 widget->priv->window);
6716 if (widget->priv->anchored)
6717 gtk_widget_queue_resize (widget);
6721 gtk_widget_real_show_help (GtkWidget *widget,
6722 GtkWidgetHelpType help_type)
6724 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6726 _gtk_tooltip_toggle_keyboard_mode (widget);
6735 gtk_widget_real_focus (GtkWidget *widget,
6736 GtkDirectionType direction)
6738 if (!gtk_widget_get_can_focus (widget))
6741 if (!gtk_widget_is_focus (widget))
6743 gtk_widget_grab_focus (widget);
6751 gtk_widget_real_move_focus (GtkWidget *widget,
6752 GtkDirectionType direction)
6754 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6756 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6758 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6764 gtk_widget_real_keynav_failed (GtkWidget *widget,
6765 GtkDirectionType direction)
6767 gboolean cursor_only;
6771 case GTK_DIR_TAB_FORWARD:
6772 case GTK_DIR_TAB_BACKWARD:
6779 g_object_get (gtk_widget_get_settings (widget),
6780 "gtk-keynav-cursor-only", &cursor_only,
6787 gtk_widget_error_bell (widget);
6793 * gtk_widget_set_can_focus:
6794 * @widget: a #GtkWidget
6795 * @can_focus: whether or not @widget can own the input focus.
6797 * Specifies whether @widget can own the input focus. See
6798 * gtk_widget_grab_focus() for actually setting the input focus on a
6804 gtk_widget_set_can_focus (GtkWidget *widget,
6807 g_return_if_fail (GTK_IS_WIDGET (widget));
6809 if (widget->priv->can_focus != can_focus)
6811 widget->priv->can_focus = can_focus;
6813 gtk_widget_queue_resize (widget);
6814 g_object_notify (G_OBJECT (widget), "can-focus");
6819 * gtk_widget_get_can_focus:
6820 * @widget: a #GtkWidget
6822 * Determines whether @widget can own the input focus. See
6823 * gtk_widget_set_can_focus().
6825 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6830 gtk_widget_get_can_focus (GtkWidget *widget)
6832 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6834 return widget->priv->can_focus;
6838 * gtk_widget_has_focus:
6839 * @widget: a #GtkWidget
6841 * Determines if the widget has the global input focus. See
6842 * gtk_widget_is_focus() for the difference between having the global
6843 * input focus, and only having the focus within a toplevel.
6845 * Return value: %TRUE if the widget has the global input focus.
6850 gtk_widget_has_focus (GtkWidget *widget)
6852 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6854 return widget->priv->has_focus;
6858 * gtk_widget_has_visible_focus:
6859 * @widget: a #GtkWidget
6861 * Determines if the widget should show a visible indication that
6862 * it has the global input focus. This is a convenience function for
6863 * use in ::draw handlers that takes into account whether focus
6864 * indication should currently be shown in the toplevel window of
6865 * @widget. See gtk_window_get_focus_visible() for more information
6866 * about focus indication.
6868 * To find out if the widget has the global input focus, use
6869 * gtk_widget_has_focus().
6871 * Return value: %TRUE if the widget should display a 'focus rectangle'
6876 gtk_widget_has_visible_focus (GtkWidget *widget)
6878 gboolean draw_focus;
6880 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6882 if (widget->priv->has_focus)
6884 GtkWidget *toplevel;
6886 toplevel = gtk_widget_get_toplevel (widget);
6888 if (GTK_IS_WINDOW (toplevel))
6889 draw_focus = gtk_window_get_focus_visible (GTK_WINDOW (toplevel));
6900 * gtk_widget_is_focus:
6901 * @widget: a #GtkWidget
6903 * Determines if the widget is the focus widget within its
6904 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6905 * necessarily set; %HAS_FOCUS will only be set if the
6906 * toplevel widget additionally has the global input focus.)
6908 * Return value: %TRUE if the widget is the focus widget.
6911 gtk_widget_is_focus (GtkWidget *widget)
6913 GtkWidget *toplevel;
6915 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6917 toplevel = gtk_widget_get_toplevel (widget);
6919 if (GTK_IS_WINDOW (toplevel))
6920 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6926 * gtk_widget_set_can_default:
6927 * @widget: a #GtkWidget
6928 * @can_default: whether or not @widget can be a default widget.
6930 * Specifies whether @widget can be a default widget. See
6931 * gtk_widget_grab_default() for details about the meaning of
6937 gtk_widget_set_can_default (GtkWidget *widget,
6938 gboolean can_default)
6940 g_return_if_fail (GTK_IS_WIDGET (widget));
6942 if (widget->priv->can_default != can_default)
6944 widget->priv->can_default = can_default;
6946 gtk_widget_queue_resize (widget);
6947 g_object_notify (G_OBJECT (widget), "can-default");
6952 * gtk_widget_get_can_default:
6953 * @widget: a #GtkWidget
6955 * Determines whether @widget can be a default widget. See
6956 * gtk_widget_set_can_default().
6958 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6963 gtk_widget_get_can_default (GtkWidget *widget)
6965 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6967 return widget->priv->can_default;
6971 * gtk_widget_has_default:
6972 * @widget: a #GtkWidget
6974 * Determines whether @widget is the current default widget within its
6975 * toplevel. See gtk_widget_set_can_default().
6977 * Return value: %TRUE if @widget is the current default widget within
6978 * its toplevel, %FALSE otherwise
6983 gtk_widget_has_default (GtkWidget *widget)
6985 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6987 return widget->priv->has_default;
6991 _gtk_widget_set_has_default (GtkWidget *widget,
6992 gboolean has_default)
6994 widget->priv->has_default = has_default;
6998 * gtk_widget_grab_default:
6999 * @widget: a #GtkWidget
7001 * Causes @widget to become the default widget. @widget must have the
7002 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
7003 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
7004 * %TRUE)</literal>. The default widget is activated when
7005 * the user presses Enter in a window. Default widgets must be
7006 * activatable, that is, gtk_widget_activate() should affect them. Note
7007 * that #GtkEntry widgets require the "activates-default" property
7008 * set to %TRUE before they activate the default widget when Enter
7009 * is pressed and the #GtkEntry is focused.
7012 gtk_widget_grab_default (GtkWidget *widget)
7016 g_return_if_fail (GTK_IS_WIDGET (widget));
7017 g_return_if_fail (gtk_widget_get_can_default (widget));
7019 window = gtk_widget_get_toplevel (widget);
7021 if (window && gtk_widget_is_toplevel (window))
7022 gtk_window_set_default (GTK_WINDOW (window), widget);
7024 g_warning (G_STRLOC ": widget not within a GtkWindow");
7028 * gtk_widget_set_receives_default:
7029 * @widget: a #GtkWidget
7030 * @receives_default: whether or not @widget can be a default widget.
7032 * Specifies whether @widget will be treated as the default widget
7033 * within its toplevel when it has the focus, even if another widget
7036 * See gtk_widget_grab_default() for details about the meaning of
7042 gtk_widget_set_receives_default (GtkWidget *widget,
7043 gboolean receives_default)
7045 g_return_if_fail (GTK_IS_WIDGET (widget));
7047 if (widget->priv->receives_default != receives_default)
7049 widget->priv->receives_default = receives_default;
7051 g_object_notify (G_OBJECT (widget), "receives-default");
7056 * gtk_widget_get_receives_default:
7057 * @widget: a #GtkWidget
7059 * Determines whether @widget is alyways treated as default widget
7060 * withing its toplevel when it has the focus, even if another widget
7063 * See gtk_widget_set_receives_default().
7065 * Return value: %TRUE if @widget acts as default widget when focussed,
7071 gtk_widget_get_receives_default (GtkWidget *widget)
7073 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7075 return widget->priv->receives_default;
7079 * gtk_widget_has_grab:
7080 * @widget: a #GtkWidget
7082 * Determines whether the widget is currently grabbing events, so it
7083 * is the only widget receiving input events (keyboard and mouse).
7085 * See also gtk_grab_add().
7087 * Return value: %TRUE if the widget is in the grab_widgets stack
7092 gtk_widget_has_grab (GtkWidget *widget)
7094 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7096 return widget->priv->has_grab;
7100 _gtk_widget_set_has_grab (GtkWidget *widget,
7103 widget->priv->has_grab = has_grab;
7107 * gtk_widget_device_is_shadowed:
7108 * @widget: a #GtkWidget
7109 * @device: a #GdkDevice
7111 * Returns %TRUE if @device has been shadowed by a GTK+
7112 * device grab on another widget, so it would stop sending
7113 * events to @widget. This may be used in the
7114 * #GtkWidget::grab-notify signal to check for specific
7115 * devices. See gtk_device_grab_add().
7117 * Returns: %TRUE if there is an ongoing grab on @device
7118 * by another #GtkWidget than @widget.
7123 gtk_widget_device_is_shadowed (GtkWidget *widget,
7126 GtkWindowGroup *group;
7127 GtkWidget *grab_widget, *toplevel;
7129 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7130 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
7132 if (!gtk_widget_get_realized (widget))
7135 toplevel = gtk_widget_get_toplevel (widget);
7137 if (GTK_IS_WINDOW (toplevel))
7138 group = gtk_window_get_group (GTK_WINDOW (toplevel));
7140 group = gtk_window_get_group (NULL);
7142 grab_widget = gtk_window_group_get_current_device_grab (group, device);
7144 /* Widget not inside the hierarchy of grab_widget */
7146 widget != grab_widget &&
7147 !gtk_widget_is_ancestor (widget, grab_widget))
7150 grab_widget = gtk_window_group_get_current_grab (group);
7151 if (grab_widget && widget != grab_widget &&
7152 !gtk_widget_is_ancestor (widget, grab_widget))
7159 * gtk_widget_set_name:
7160 * @widget: a #GtkWidget
7161 * @name: name for the widget
7163 * Widgets can be named, which allows you to refer to them from a
7164 * CSS file. You can apply a style to widgets with a particular name
7165 * in the CSS file. See the documentation for the CSS syntax (on the
7166 * same page as the docs for #GtkStyleContext).
7168 * Note that the CSS syntax has certain special characters to delimit
7169 * and represent elements in a selector (period, #, >, *...),
7170 * so using these will make your widget impossible to match by name.
7171 * Any combination of alphanumeric symbols, dashes and underscores will
7175 gtk_widget_set_name (GtkWidget *widget,
7178 GtkWidgetPrivate *priv;
7181 g_return_if_fail (GTK_IS_WIDGET (widget));
7183 priv = widget->priv;
7185 new_name = g_strdup (name);
7186 g_free (priv->name);
7187 priv->name = new_name;
7189 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_NAME);
7191 g_object_notify (G_OBJECT (widget), "name");
7195 * gtk_widget_get_name:
7196 * @widget: a #GtkWidget
7198 * Retrieves the name of a widget. See gtk_widget_set_name() for the
7199 * significance of widget names.
7201 * Return value: name of the widget. This string is owned by GTK+ and
7202 * should not be modified or freed
7205 gtk_widget_get_name (GtkWidget *widget)
7207 GtkWidgetPrivate *priv;
7209 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7211 priv = widget->priv;
7215 return G_OBJECT_TYPE_NAME (widget);
7219 _gtk_widget_update_state_flags (GtkWidget *widget,
7220 GtkStateFlags flags,
7223 GtkWidgetPrivate *priv;
7225 priv = widget->priv;
7227 /* Handle insensitive first, since it is propagated
7228 * differently throughout the widget hierarchy.
7230 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_UNSET))
7231 gtk_widget_set_sensitive (widget, TRUE);
7232 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation != STATE_CHANGE_UNSET))
7233 gtk_widget_set_sensitive (widget, FALSE);
7234 else if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && !(flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_REPLACE))
7235 gtk_widget_set_sensitive (widget, TRUE);
7237 if (operation != STATE_CHANGE_REPLACE)
7238 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
7241 operation == STATE_CHANGE_REPLACE)
7246 data.operation = operation;
7248 gtk_widget_propagate_state (widget, &data);
7250 gtk_widget_queue_resize (widget);
7255 * gtk_widget_set_state_flags:
7256 * @widget: a #GtkWidget
7257 * @flags: State flags to turn on
7258 * @clear: Whether to clear state before turning on @flags
7260 * This function is for use in widget implementations. Turns on flag
7261 * values in the current widget state (insensitive, prelighted, etc.).
7263 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7264 * will be propagated down to all non-internal children if @widget is a
7265 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7266 * down to all #GtkContainer children by different means than turning on the
7267 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7268 * gtk_widget_is_sensitive() will make use of these.
7273 gtk_widget_set_state_flags (GtkWidget *widget,
7274 GtkStateFlags flags,
7277 g_return_if_fail (GTK_IS_WIDGET (widget));
7279 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7280 (clear && widget->priv->state_flags == flags))
7284 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7286 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
7290 * gtk_widget_unset_state_flags:
7291 * @widget: a #GtkWidget
7292 * @flags: State flags to turn off
7294 * This function is for use in widget implementations. Turns off flag
7295 * values for the current widget state (insensitive, prelighted, etc.).
7296 * See gtk_widget_set_state_flags().
7301 gtk_widget_unset_state_flags (GtkWidget *widget,
7302 GtkStateFlags flags)
7304 g_return_if_fail (GTK_IS_WIDGET (widget));
7306 if ((widget->priv->state_flags & flags) == 0)
7309 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
7313 * gtk_widget_get_state_flags:
7314 * @widget: a #GtkWidget
7316 * Returns the widget state as a flag set. It is worth mentioning
7317 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7318 * returned, that is, also based on parent insensitivity, even if
7319 * @widget itself is sensitive.
7321 * Returns: The state flags for widget
7326 gtk_widget_get_state_flags (GtkWidget *widget)
7328 GtkStateFlags flags;
7330 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7332 flags = widget->priv->state_flags;
7334 if (gtk_widget_has_focus (widget))
7335 flags |= GTK_STATE_FLAG_FOCUSED;
7341 * gtk_widget_set_state:
7342 * @widget: a #GtkWidget
7343 * @state: new state for @widget
7345 * This function is for use in widget implementations. Sets the state
7346 * of a widget (insensitive, prelighted, etc.) Usually you should set
7347 * the state using wrapper functions such as gtk_widget_set_sensitive().
7349 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7352 gtk_widget_set_state (GtkWidget *widget,
7355 GtkStateFlags flags;
7357 if (state == gtk_widget_get_state (widget))
7362 case GTK_STATE_ACTIVE:
7363 flags = GTK_STATE_FLAG_ACTIVE;
7365 case GTK_STATE_PRELIGHT:
7366 flags = GTK_STATE_FLAG_PRELIGHT;
7368 case GTK_STATE_SELECTED:
7369 flags = GTK_STATE_FLAG_SELECTED;
7371 case GTK_STATE_INSENSITIVE:
7372 flags = GTK_STATE_FLAG_INSENSITIVE;
7374 case GTK_STATE_INCONSISTENT:
7375 flags = GTK_STATE_FLAG_INCONSISTENT;
7377 case GTK_STATE_FOCUSED:
7378 flags = GTK_STATE_FLAG_FOCUSED;
7380 case GTK_STATE_NORMAL:
7386 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7390 * gtk_widget_get_state:
7391 * @widget: a #GtkWidget
7393 * Returns the widget's state. See gtk_widget_set_state().
7395 * Returns: the state of @widget.
7399 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7402 gtk_widget_get_state (GtkWidget *widget)
7404 GtkStateFlags flags;
7406 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7408 flags = gtk_widget_get_state_flags (widget);
7410 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7411 return GTK_STATE_INSENSITIVE;
7412 else if (flags & GTK_STATE_FLAG_ACTIVE)
7413 return GTK_STATE_ACTIVE;
7414 else if (flags & GTK_STATE_FLAG_SELECTED)
7415 return GTK_STATE_SELECTED;
7416 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7417 return GTK_STATE_PRELIGHT;
7419 return GTK_STATE_NORMAL;
7423 * gtk_widget_set_visible:
7424 * @widget: a #GtkWidget
7425 * @visible: whether the widget should be shown or not
7427 * Sets the visibility state of @widget. Note that setting this to
7428 * %TRUE doesn't mean the widget is actually viewable, see
7429 * gtk_widget_get_visible().
7431 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7432 * but is nicer to use when the visibility of the widget depends on
7438 gtk_widget_set_visible (GtkWidget *widget,
7441 g_return_if_fail (GTK_IS_WIDGET (widget));
7443 if (visible != gtk_widget_get_visible (widget))
7446 gtk_widget_show (widget);
7448 gtk_widget_hide (widget);
7453 _gtk_widget_set_visible_flag (GtkWidget *widget,
7456 widget->priv->visible = visible;
7460 * gtk_widget_get_visible:
7461 * @widget: a #GtkWidget
7463 * Determines whether the widget is visible. Note that this doesn't
7464 * take into account whether the widget's parent is also visible
7465 * or the widget is obscured in any way.
7467 * See gtk_widget_set_visible().
7469 * Return value: %TRUE if the widget is visible
7474 gtk_widget_get_visible (GtkWidget *widget)
7476 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7478 return widget->priv->visible;
7482 * gtk_widget_set_has_window:
7483 * @widget: a #GtkWidget
7484 * @has_window: whether or not @widget has a window.
7486 * Specifies whether @widget has a #GdkWindow of its own. Note that
7487 * all realized widgets have a non-%NULL "window" pointer
7488 * (gtk_widget_get_window() never returns a %NULL window when a widget
7489 * is realized), but for many of them it's actually the #GdkWindow of
7490 * one of its parent widgets. Widgets that do not create a %window for
7491 * themselves in #GtkWidget::realize must announce this by
7492 * calling this function with @has_window = %FALSE.
7494 * This function should only be called by widget implementations,
7495 * and they should call it in their init() function.
7500 gtk_widget_set_has_window (GtkWidget *widget,
7501 gboolean has_window)
7503 g_return_if_fail (GTK_IS_WIDGET (widget));
7505 widget->priv->no_window = !has_window;
7509 * gtk_widget_get_has_window:
7510 * @widget: a #GtkWidget
7512 * Determines whether @widget has a #GdkWindow of its own. See
7513 * gtk_widget_set_has_window().
7515 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7520 gtk_widget_get_has_window (GtkWidget *widget)
7522 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7524 return ! widget->priv->no_window;
7528 * gtk_widget_is_toplevel:
7529 * @widget: a #GtkWidget
7531 * Determines whether @widget is a toplevel widget.
7533 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7534 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7537 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7542 gtk_widget_is_toplevel (GtkWidget *widget)
7544 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7546 return widget->priv->toplevel;
7550 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7551 gboolean is_toplevel)
7553 widget->priv->toplevel = is_toplevel;
7557 * gtk_widget_is_drawable:
7558 * @widget: a #GtkWidget
7560 * Determines whether @widget can be drawn to. A widget can be drawn
7561 * to if it is mapped and visible.
7563 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7568 gtk_widget_is_drawable (GtkWidget *widget)
7570 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7572 return (gtk_widget_get_visible (widget) &&
7573 gtk_widget_get_mapped (widget));
7577 * gtk_widget_get_realized:
7578 * @widget: a #GtkWidget
7580 * Determines whether @widget is realized.
7582 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7587 gtk_widget_get_realized (GtkWidget *widget)
7589 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7591 return widget->priv->realized;
7595 * gtk_widget_set_realized:
7596 * @widget: a #GtkWidget
7597 * @realized: %TRUE to mark the widget as realized
7599 * Marks the widget as being realized.
7601 * This function should only ever be called in a derived widget's
7602 * "realize" or "unrealize" implementation.
7607 gtk_widget_set_realized (GtkWidget *widget,
7610 g_return_if_fail (GTK_IS_WIDGET (widget));
7612 widget->priv->realized = realized;
7616 * gtk_widget_get_mapped:
7617 * @widget: a #GtkWidget
7619 * Whether the widget is mapped.
7621 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7626 gtk_widget_get_mapped (GtkWidget *widget)
7628 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7630 return widget->priv->mapped;
7634 * gtk_widget_set_mapped:
7635 * @widget: a #GtkWidget
7636 * @mapped: %TRUE to mark the widget as mapped
7638 * Marks the widget as being realized.
7640 * This function should only ever be called in a derived widget's
7641 * "map" or "unmap" implementation.
7646 gtk_widget_set_mapped (GtkWidget *widget,
7649 g_return_if_fail (GTK_IS_WIDGET (widget));
7651 widget->priv->mapped = mapped;
7655 * gtk_widget_set_app_paintable:
7656 * @widget: a #GtkWidget
7657 * @app_paintable: %TRUE if the application will paint on the widget
7659 * Sets whether the application intends to draw on the widget in
7660 * an #GtkWidget::draw handler.
7662 * This is a hint to the widget and does not affect the behavior of
7663 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7664 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7665 * the effect is to suppress default themed drawing of the widget's
7666 * background. (Children of the widget will still be drawn.) The application
7667 * is then entirely responsible for drawing the widget background.
7669 * Note that the background is still drawn when the widget is mapped.
7672 gtk_widget_set_app_paintable (GtkWidget *widget,
7673 gboolean app_paintable)
7675 g_return_if_fail (GTK_IS_WIDGET (widget));
7677 app_paintable = (app_paintable != FALSE);
7679 if (widget->priv->app_paintable != app_paintable)
7681 widget->priv->app_paintable = app_paintable;
7683 if (gtk_widget_is_drawable (widget))
7684 gtk_widget_queue_draw (widget);
7686 g_object_notify (G_OBJECT (widget), "app-paintable");
7691 * gtk_widget_get_app_paintable:
7692 * @widget: a #GtkWidget
7694 * Determines whether the application intends to draw on the widget in
7695 * an #GtkWidget::draw handler.
7697 * See gtk_widget_set_app_paintable()
7699 * Return value: %TRUE if the widget is app paintable
7704 gtk_widget_get_app_paintable (GtkWidget *widget)
7706 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7708 return widget->priv->app_paintable;
7712 * gtk_widget_set_double_buffered:
7713 * @widget: a #GtkWidget
7714 * @double_buffered: %TRUE to double-buffer a widget
7716 * Widgets are double buffered by default; you can use this function
7717 * to turn off the buffering. "Double buffered" simply means that
7718 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7719 * automatically around expose events sent to the
7720 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7721 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7722 * buffer to the screen. The result is that users see the window
7723 * update in one smooth step, and don't see individual graphics
7724 * primitives being rendered.
7726 * In very simple terms, double buffered widgets don't flicker,
7727 * so you would only use this function to turn off double buffering
7728 * if you had special needs and really knew what you were doing.
7730 * Note: if you turn off double-buffering, you have to handle
7731 * expose events, since even the clearing to the background color or
7732 * pixmap will not happen automatically (as it is done in
7733 * gdk_window_begin_paint()).
7736 gtk_widget_set_double_buffered (GtkWidget *widget,
7737 gboolean double_buffered)
7739 g_return_if_fail (GTK_IS_WIDGET (widget));
7741 double_buffered = (double_buffered != FALSE);
7743 if (widget->priv->double_buffered != double_buffered)
7745 widget->priv->double_buffered = double_buffered;
7747 g_object_notify (G_OBJECT (widget), "double-buffered");
7752 * gtk_widget_get_double_buffered:
7753 * @widget: a #GtkWidget
7755 * Determines whether the widget is double buffered.
7757 * See gtk_widget_set_double_buffered()
7759 * Return value: %TRUE if the widget is double buffered
7764 gtk_widget_get_double_buffered (GtkWidget *widget)
7766 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7768 return widget->priv->double_buffered;
7772 * gtk_widget_set_redraw_on_allocate:
7773 * @widget: a #GtkWidget
7774 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7775 * when it is allocated to a new size. Otherwise, only the
7776 * new portion of the widget will be redrawn.
7778 * Sets whether the entire widget is queued for drawing when its size
7779 * allocation changes. By default, this setting is %TRUE and
7780 * the entire widget is redrawn on every size change. If your widget
7781 * leaves the upper left unchanged when made bigger, turning this
7782 * setting off will improve performance.
7784 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7785 * off all allocation on resizing: the widget will not even redraw if
7786 * its position changes; this is to allow containers that don't draw
7787 * anything to avoid excess invalidations. If you set this flag on a
7788 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7789 * you are responsible for invalidating both the old and new allocation
7790 * of the widget when the widget is moved and responsible for invalidating
7791 * regions newly when the widget increases size.
7794 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7795 gboolean redraw_on_allocate)
7797 g_return_if_fail (GTK_IS_WIDGET (widget));
7799 widget->priv->redraw_on_alloc = redraw_on_allocate;
7803 * gtk_widget_set_sensitive:
7804 * @widget: a #GtkWidget
7805 * @sensitive: %TRUE to make the widget sensitive
7807 * Sets the sensitivity of a widget. A widget is sensitive if the user
7808 * can interact with it. Insensitive widgets are "grayed out" and the
7809 * user can't interact with them. Insensitive widgets are known as
7810 * "inactive", "disabled", or "ghosted" in some other toolkits.
7813 gtk_widget_set_sensitive (GtkWidget *widget,
7816 GtkWidgetPrivate *priv;
7818 g_return_if_fail (GTK_IS_WIDGET (widget));
7820 priv = widget->priv;
7822 sensitive = (sensitive != FALSE);
7824 if (priv->sensitive == sensitive)
7827 priv->sensitive = sensitive;
7829 if (priv->parent == NULL
7830 || gtk_widget_is_sensitive (priv->parent))
7834 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7837 data.operation = STATE_CHANGE_UNSET;
7839 data.operation = STATE_CHANGE_SET;
7841 gtk_widget_propagate_state (widget, &data);
7843 gtk_widget_queue_resize (widget);
7846 g_object_notify (G_OBJECT (widget), "sensitive");
7850 * gtk_widget_get_sensitive:
7851 * @widget: a #GtkWidget
7853 * Returns the widget's sensitivity (in the sense of returning
7854 * the value that has been set using gtk_widget_set_sensitive()).
7856 * The effective sensitivity of a widget is however determined by both its
7857 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7859 * Returns: %TRUE if the widget is sensitive
7864 gtk_widget_get_sensitive (GtkWidget *widget)
7866 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7868 return widget->priv->sensitive;
7872 * gtk_widget_is_sensitive:
7873 * @widget: a #GtkWidget
7875 * Returns the widget's effective sensitivity, which means
7876 * it is sensitive itself and also its parent widget is sensitive
7878 * Returns: %TRUE if the widget is effectively sensitive
7883 gtk_widget_is_sensitive (GtkWidget *widget)
7885 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7887 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
7891 * gtk_widget_set_parent:
7892 * @widget: a #GtkWidget
7893 * @parent: parent container
7895 * This function is useful only when implementing subclasses of
7897 * Sets the container as the parent of @widget, and takes care of
7898 * some details such as updating the state and style of the child
7899 * to reflect its new location. The opposite function is
7900 * gtk_widget_unparent().
7903 gtk_widget_set_parent (GtkWidget *widget,
7906 GtkStateFlags parent_flags;
7907 GtkWidgetPrivate *priv;
7910 g_return_if_fail (GTK_IS_WIDGET (widget));
7911 g_return_if_fail (GTK_IS_WIDGET (parent));
7912 g_return_if_fail (widget != parent);
7914 priv = widget->priv;
7916 if (priv->parent != NULL)
7918 g_warning ("Can't set a parent on widget which has a parent\n");
7921 if (gtk_widget_is_toplevel (widget))
7923 g_warning ("Can't set a parent on a toplevel widget\n");
7927 /* keep this function in sync with gtk_menu_attach_to_widget()
7930 g_object_ref_sink (widget);
7932 gtk_widget_push_verify_invariants (widget);
7934 priv->parent = parent;
7936 parent_flags = gtk_widget_get_state_flags (parent);
7938 /* Merge both old state and current parent state,
7939 * making sure to only propagate the right states */
7940 data.flags = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
7941 data.flags |= priv->state_flags;
7943 data.operation = STATE_CHANGE_REPLACE;
7944 gtk_widget_propagate_state (widget, &data);
7947 gtk_style_context_set_parent (priv->context,
7948 gtk_widget_get_style_context (parent));
7950 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7951 if (priv->parent->priv->anchored)
7952 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7953 g_object_notify (G_OBJECT (widget), "parent");
7955 /* Enforce realized/mapped invariants
7957 if (gtk_widget_get_realized (priv->parent))
7958 gtk_widget_realize (widget);
7960 if (gtk_widget_get_visible (priv->parent) &&
7961 gtk_widget_get_visible (widget))
7963 if (gtk_widget_get_child_visible (widget) &&
7964 gtk_widget_get_mapped (priv->parent))
7965 gtk_widget_map (widget);
7967 gtk_widget_queue_resize (widget);
7970 /* child may cause parent's expand to change, if the child is
7971 * expanded. If child is not expanded, then it can't modify the
7972 * parent's expand. If the child becomes expanded later then it will
7973 * queue compute_expand then. This optimization plus defaulting
7974 * newly-constructed widgets to need_compute_expand=FALSE should
7975 * mean that initially building a widget tree doesn't have to keep
7976 * walking up setting need_compute_expand on parents over and over.
7978 * We can't change a parent to need to expand unless we're visible.
7980 if (gtk_widget_get_visible (widget) &&
7981 (priv->need_compute_expand ||
7982 priv->computed_hexpand ||
7983 priv->computed_vexpand))
7985 gtk_widget_queue_compute_expand (parent);
7988 gtk_widget_pop_verify_invariants (widget);
7992 * gtk_widget_get_parent:
7993 * @widget: a #GtkWidget
7995 * Returns the parent container of @widget.
7997 * Return value: (transfer none): the parent container of @widget, or %NULL
8000 gtk_widget_get_parent (GtkWidget *widget)
8002 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8004 return widget->priv->parent;
8008 modifier_style_changed (GtkModifierStyle *style,
8011 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8014 static GtkModifierStyle *
8015 _gtk_widget_get_modifier_properties (GtkWidget *widget)
8017 GtkModifierStyle *style;
8019 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
8021 if (G_UNLIKELY (!style))
8023 GtkStyleContext *context;
8025 style = _gtk_modifier_style_new ();
8026 g_object_set_qdata_full (G_OBJECT (widget),
8027 quark_modifier_style,
8029 (GDestroyNotify) g_object_unref);
8031 g_signal_connect (style, "changed",
8032 G_CALLBACK (modifier_style_changed), widget);
8034 context = gtk_widget_get_style_context (widget);
8036 gtk_style_context_add_provider (context,
8037 GTK_STYLE_PROVIDER (style),
8038 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
8045 * gtk_widget_override_color:
8046 * @widget: a #GtkWidget
8047 * @state: the state for which to set the color
8048 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8049 * of previous calls to gtk_widget_override_color()
8051 * Sets the color to use for a widget.
8053 * All other style values are left untouched.
8056 * This API is mostly meant as a quick way for applications to
8057 * change a widget appearance. If you are developing a widgets
8058 * library and intend this change to be themeable, it is better
8059 * done by setting meaningful CSS classes and regions in your
8060 * widget/container implementation through gtk_style_context_add_class()
8061 * and gtk_style_context_add_region().
8063 * This way, your widget library can install a #GtkCssProvider
8064 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
8065 * to provide a default styling for those widgets that need so, and
8066 * this theming may fully overridden by the user's theme.
8069 * Note that for complex widgets this may bring in undesired
8070 * results (such as uniform background color everywhere), in
8071 * these cases it is better to fully style such widgets through a
8072 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8079 gtk_widget_override_color (GtkWidget *widget,
8080 GtkStateFlags state,
8081 const GdkRGBA *color)
8083 GtkModifierStyle *style;
8085 g_return_if_fail (GTK_IS_WIDGET (widget));
8087 style = _gtk_widget_get_modifier_properties (widget);
8088 _gtk_modifier_style_set_color (style, state, color);
8092 * gtk_widget_override_background_color:
8093 * @widget: a #GtkWidget
8094 * @state: the state for which to set the background color
8095 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8096 * of previous calls to gtk_widget_override_background_color()
8098 * Sets the background color to use for a widget.
8100 * All other style values are left untouched.
8101 * See gtk_widget_override_color().
8106 gtk_widget_override_background_color (GtkWidget *widget,
8107 GtkStateFlags state,
8108 const GdkRGBA *color)
8110 GtkModifierStyle *style;
8112 g_return_if_fail (GTK_IS_WIDGET (widget));
8114 style = _gtk_widget_get_modifier_properties (widget);
8115 _gtk_modifier_style_set_background_color (style, state, color);
8119 * gtk_widget_override_font:
8120 * @widget: a #GtkWidget
8121 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
8122 * the effect of previous calls to gtk_widget_override_font()
8124 * Sets the font to use for a widget. All other style values are
8125 * left untouched. See gtk_widget_override_color().
8130 gtk_widget_override_font (GtkWidget *widget,
8131 const PangoFontDescription *font_desc)
8133 GtkModifierStyle *style;
8135 g_return_if_fail (GTK_IS_WIDGET (widget));
8137 style = _gtk_widget_get_modifier_properties (widget);
8138 _gtk_modifier_style_set_font (style, font_desc);
8142 * gtk_widget_override_symbolic_color:
8143 * @widget: a #GtkWidget
8144 * @name: the name of the symbolic color to modify
8145 * @color: (allow-none): the color to assign (does not need
8146 * to be allocated), or %NULL to undo the effect of previous
8147 * calls to gtk_widget_override_symbolic_color()
8149 * Sets a symbolic color for a widget.
8151 * All other style values are left untouched.
8152 * See gtk_widget_override_color() for overriding the foreground
8153 * or background color.
8158 gtk_widget_override_symbolic_color (GtkWidget *widget,
8160 const GdkRGBA *color)
8162 GtkModifierStyle *style;
8164 g_return_if_fail (GTK_IS_WIDGET (widget));
8166 style = _gtk_widget_get_modifier_properties (widget);
8167 _gtk_modifier_style_map_color (style, name, color);
8171 * gtk_widget_override_cursor:
8172 * @widget: a #GtkWidget
8173 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8174 * allocated), or %NULL to undo the effect of previous calls to
8175 * of gtk_widget_override_cursor().
8176 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8177 * need to be allocated), or %NULL to undo the effect of previous
8178 * calls to of gtk_widget_override_cursor().
8180 * Sets the cursor color to use in a widget, overriding the
8181 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8182 * style properties. All other style values are left untouched.
8183 * See also gtk_widget_modify_style().
8185 * Note that the underlying properties have the #GdkColor type,
8186 * so the alpha value in @primary and @secondary will be ignored.
8191 gtk_widget_override_cursor (GtkWidget *widget,
8192 const GdkRGBA *cursor,
8193 const GdkRGBA *secondary_cursor)
8195 GtkModifierStyle *style;
8197 g_return_if_fail (GTK_IS_WIDGET (widget));
8199 style = _gtk_widget_get_modifier_properties (widget);
8200 _gtk_modifier_style_set_color_property (style,
8202 "cursor-color", cursor);
8203 _gtk_modifier_style_set_color_property (style,
8205 "secondary-cursor-color",
8210 gtk_widget_real_direction_changed (GtkWidget *widget,
8211 GtkTextDirection previous_direction)
8213 gtk_widget_queue_resize (widget);
8217 gtk_widget_real_style_set (GtkWidget *widget,
8218 GtkStyle *previous_style)
8223 GtkWidget *previous_toplevel;
8224 GdkScreen *previous_screen;
8225 GdkScreen *new_screen;
8226 } HierarchyChangedInfo;
8229 do_screen_change (GtkWidget *widget,
8230 GdkScreen *old_screen,
8231 GdkScreen *new_screen)
8233 if (old_screen != new_screen)
8235 GtkWidgetPrivate *priv = widget->priv;
8239 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8241 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8244 _gtk_tooltip_hide (widget);
8246 if (new_screen && priv->context)
8247 gtk_style_context_set_screen (priv->context, new_screen);
8249 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8254 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8255 gpointer client_data)
8257 GtkWidgetPrivate *priv = widget->priv;
8258 HierarchyChangedInfo *info = client_data;
8259 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8260 (priv->parent && priv->parent->priv->anchored);
8262 if (priv->anchored != new_anchored)
8264 g_object_ref (widget);
8266 priv->anchored = new_anchored;
8268 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8269 do_screen_change (widget, info->previous_screen, info->new_screen);
8271 if (GTK_IS_CONTAINER (widget))
8272 gtk_container_forall (GTK_CONTAINER (widget),
8273 gtk_widget_propagate_hierarchy_changed_recurse,
8276 g_object_unref (widget);
8281 * _gtk_widget_propagate_hierarchy_changed:
8282 * @widget: a #GtkWidget
8283 * @previous_toplevel: Previous toplevel
8285 * Propagates changes in the anchored state to a widget and all
8286 * children, unsetting or setting the %ANCHORED flag, and
8287 * emitting #GtkWidget::hierarchy-changed.
8290 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8291 GtkWidget *previous_toplevel)
8293 GtkWidgetPrivate *priv = widget->priv;
8294 HierarchyChangedInfo info;
8296 info.previous_toplevel = previous_toplevel;
8297 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8299 if (gtk_widget_is_toplevel (widget) ||
8300 (priv->parent && priv->parent->priv->anchored))
8301 info.new_screen = gtk_widget_get_screen (widget);
8303 info.new_screen = NULL;
8305 if (info.previous_screen)
8306 g_object_ref (info.previous_screen);
8307 if (previous_toplevel)
8308 g_object_ref (previous_toplevel);
8310 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8312 if (previous_toplevel)
8313 g_object_unref (previous_toplevel);
8314 if (info.previous_screen)
8315 g_object_unref (info.previous_screen);
8319 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8320 gpointer client_data)
8322 HierarchyChangedInfo *info = client_data;
8324 g_object_ref (widget);
8326 do_screen_change (widget, info->previous_screen, info->new_screen);
8328 if (GTK_IS_CONTAINER (widget))
8329 gtk_container_forall (GTK_CONTAINER (widget),
8330 gtk_widget_propagate_screen_changed_recurse,
8333 g_object_unref (widget);
8337 * gtk_widget_is_composited:
8338 * @widget: a #GtkWidget
8340 * Whether @widget can rely on having its alpha channel
8341 * drawn correctly. On X11 this function returns whether a
8342 * compositing manager is running for @widget's screen.
8344 * Please note that the semantics of this call will change
8345 * in the future if used on a widget that has a composited
8346 * window in its hierarchy (as set by gdk_window_set_composited()).
8348 * Return value: %TRUE if the widget can rely on its alpha
8349 * channel being drawn correctly.
8354 gtk_widget_is_composited (GtkWidget *widget)
8358 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8360 screen = gtk_widget_get_screen (widget);
8362 return gdk_screen_is_composited (screen);
8366 propagate_composited_changed (GtkWidget *widget,
8369 if (GTK_IS_CONTAINER (widget))
8371 gtk_container_forall (GTK_CONTAINER (widget),
8372 propagate_composited_changed,
8376 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8380 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8382 propagate_composited_changed (widget, NULL);
8386 * _gtk_widget_propagate_screen_changed:
8387 * @widget: a #GtkWidget
8388 * @previous_screen: Previous screen
8390 * Propagates changes in the screen for a widget to all
8391 * children, emitting #GtkWidget::screen-changed.
8394 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8395 GdkScreen *previous_screen)
8397 HierarchyChangedInfo info;
8399 info.previous_screen = previous_screen;
8400 info.new_screen = gtk_widget_get_screen (widget);
8402 if (previous_screen)
8403 g_object_ref (previous_screen);
8405 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8407 if (previous_screen)
8408 g_object_unref (previous_screen);
8412 reset_style_recurse (GtkWidget *widget, gpointer data)
8414 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8416 if (GTK_IS_CONTAINER (widget))
8417 gtk_container_forall (GTK_CONTAINER (widget),
8418 reset_style_recurse,
8423 * gtk_widget_reset_style:
8424 * @widget: a #GtkWidget
8426 * Updates the style context of @widget and all descendents
8427 * by updating its widget path. #GtkContainer<!-- -->s may want
8428 * to use this on a child when reordering it in a way that a different
8429 * style might apply to it. See also gtk_container_get_path_for_child().
8434 gtk_widget_reset_style (GtkWidget *widget)
8436 g_return_if_fail (GTK_IS_WIDGET (widget));
8438 reset_style_recurse (widget, NULL);
8440 g_list_foreach (widget->priv->attached_windows,
8441 (GFunc) reset_style_recurse, NULL);
8444 #ifdef G_ENABLE_DEBUG
8446 /* Verify invariants, see docs/widget_system.txt for notes on much of
8447 * this. Invariants may be temporarily broken while we're in the
8448 * process of updating state, of course, so you can only
8449 * verify_invariants() after a given operation is complete.
8450 * Use push/pop_verify_invariants to help with that.
8453 gtk_widget_verify_invariants (GtkWidget *widget)
8457 if (widget->priv->verifying_invariants_count > 0)
8460 parent = widget->priv->parent;
8462 if (widget->priv->mapped)
8464 /* Mapped implies ... */
8466 if (!widget->priv->realized)
8467 g_warning ("%s %p is mapped but not realized",
8468 G_OBJECT_TYPE_NAME (widget), widget);
8470 if (!widget->priv->visible)
8471 g_warning ("%s %p is mapped but not visible",
8472 G_OBJECT_TYPE_NAME (widget), widget);
8474 if (!widget->priv->toplevel)
8476 if (!widget->priv->child_visible)
8477 g_warning ("%s %p is mapped but not child_visible",
8478 G_OBJECT_TYPE_NAME (widget), widget);
8483 /* Not mapped implies... */
8486 /* This check makes sense for normal toplevels, but for
8487 * something like a toplevel that is embedded within a clutter
8488 * state, mapping may depend on external factors.
8490 if (widget->priv->toplevel)
8492 if (widget->priv->visible)
8493 g_warning ("%s %p toplevel is visible but not mapped",
8494 G_OBJECT_TYPE_NAME (widget), widget);
8499 /* Parent related checks aren't possible if parent has
8500 * verifying_invariants_count > 0 because parent needs to recurse
8501 * children first before the invariants will hold.
8503 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8506 parent->priv->realized)
8508 /* Parent realized implies... */
8511 /* This is in widget_system.txt but appears to fail
8512 * because there's no gtk_container_realize() that
8513 * realizes all children... instead we just lazily
8514 * wait for map to fix things up.
8516 if (!widget->priv->realized)
8517 g_warning ("%s %p is realized but child %s %p is not realized",
8518 G_OBJECT_TYPE_NAME (parent), parent,
8519 G_OBJECT_TYPE_NAME (widget), widget);
8522 else if (!widget->priv->toplevel)
8524 /* No parent or parent not realized on non-toplevel implies... */
8526 if (widget->priv->realized && !widget->priv->in_reparent)
8527 g_warning ("%s %p is not realized but child %s %p is realized",
8528 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8529 G_OBJECT_TYPE_NAME (widget), widget);
8533 parent->priv->mapped &&
8534 widget->priv->visible &&
8535 widget->priv->child_visible)
8537 /* Parent mapped and we are visible implies... */
8539 if (!widget->priv->mapped)
8540 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8541 G_OBJECT_TYPE_NAME (parent), parent,
8542 G_OBJECT_TYPE_NAME (widget), widget);
8544 else if (!widget->priv->toplevel)
8546 /* No parent or parent not mapped on non-toplevel implies... */
8548 if (widget->priv->mapped && !widget->priv->in_reparent)
8549 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8550 G_OBJECT_TYPE_NAME (widget), widget,
8551 widget->priv->visible,
8552 widget->priv->child_visible,
8553 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8554 parent ? parent->priv->mapped : FALSE);
8558 if (!widget->priv->realized)
8560 /* Not realized implies... */
8563 /* widget_system.txt says these hold, but they don't. */
8564 if (widget->priv->resize_pending)
8565 g_warning ("%s %p resize pending but not realized",
8566 G_OBJECT_TYPE_NAME (widget), widget);
8568 if (widget->priv->alloc_needed)
8569 g_warning ("%s %p alloc needed but not realized",
8570 G_OBJECT_TYPE_NAME (widget), widget);
8572 if (widget->priv->width_request_needed)
8573 g_warning ("%s %p width request needed but not realized",
8574 G_OBJECT_TYPE_NAME (widget), widget);
8576 if (widget->priv->height_request_needed)
8577 g_warning ("%s %p height request needed but not realized",
8578 G_OBJECT_TYPE_NAME (widget), widget);
8583 /* The point of this push/pop is that invariants may not hold while
8584 * we're busy making changes. So we only check at the outermost call
8585 * on the call stack, after we finish updating everything.
8588 gtk_widget_push_verify_invariants (GtkWidget *widget)
8590 widget->priv->verifying_invariants_count += 1;
8594 gtk_widget_verify_child_invariants (GtkWidget *widget,
8595 gpointer client_data)
8597 /* We don't recurse further; this is a one-level check. */
8598 gtk_widget_verify_invariants (widget);
8602 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8604 g_assert (widget->priv->verifying_invariants_count > 0);
8606 widget->priv->verifying_invariants_count -= 1;
8608 if (widget->priv->verifying_invariants_count == 0)
8610 gtk_widget_verify_invariants (widget);
8612 if (GTK_IS_CONTAINER (widget))
8614 /* Check one level of children, because our
8615 * push_verify_invariants() will have prevented some of the
8616 * checks. This does not recurse because if recursion is
8617 * needed, it will happen naturally as each child has a
8618 * push/pop on that child. For example if we're recursively
8619 * mapping children, we'll push/pop on each child as we map
8622 gtk_container_forall (GTK_CONTAINER (widget),
8623 gtk_widget_verify_child_invariants,
8628 #endif /* G_ENABLE_DEBUG */
8630 static PangoContext *
8631 gtk_widget_peek_pango_context (GtkWidget *widget)
8633 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8637 * gtk_widget_get_pango_context:
8638 * @widget: a #GtkWidget
8640 * Gets a #PangoContext with the appropriate font map, font description,
8641 * and base direction for this widget. Unlike the context returned
8642 * by gtk_widget_create_pango_context(), this context is owned by
8643 * the widget (it can be used until the screen for the widget changes
8644 * or the widget is removed from its toplevel), and will be updated to
8645 * match any changes to the widget's attributes.
8647 * If you create and keep a #PangoLayout using this context, you must
8648 * deal with changes to the context by calling pango_layout_context_changed()
8649 * on the layout in response to the #GtkWidget::style-updated and
8650 * #GtkWidget::direction-changed signals for the widget.
8652 * Return value: (transfer none): the #PangoContext for the widget.
8655 gtk_widget_get_pango_context (GtkWidget *widget)
8657 PangoContext *context;
8659 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8661 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8664 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8665 g_object_set_qdata_full (G_OBJECT (widget),
8666 quark_pango_context,
8675 update_pango_context (GtkWidget *widget,
8676 PangoContext *context)
8678 const PangoFontDescription *font_desc;
8679 GtkStyleContext *style_context;
8681 style_context = gtk_widget_get_style_context (widget);
8683 font_desc = gtk_style_context_get_font (style_context,
8684 gtk_widget_get_state_flags (widget));
8686 pango_context_set_font_description (context, font_desc);
8687 pango_context_set_base_dir (context,
8688 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8689 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8693 gtk_widget_update_pango_context (GtkWidget *widget)
8695 PangoContext *context = gtk_widget_peek_pango_context (widget);
8701 update_pango_context (widget, context);
8703 screen = gtk_widget_get_screen_unchecked (widget);
8706 pango_cairo_context_set_resolution (context,
8707 gdk_screen_get_resolution (screen));
8708 pango_cairo_context_set_font_options (context,
8709 gdk_screen_get_font_options (screen));
8715 * gtk_widget_create_pango_context:
8716 * @widget: a #GtkWidget
8718 * Creates a new #PangoContext with the appropriate font map,
8719 * font description, and base direction for drawing text for
8720 * this widget. See also gtk_widget_get_pango_context().
8722 * Return value: (transfer full): the new #PangoContext
8725 gtk_widget_create_pango_context (GtkWidget *widget)
8728 PangoContext *context;
8730 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8732 screen = gtk_widget_get_screen_unchecked (widget);
8735 GTK_NOTE (MULTIHEAD,
8736 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8738 screen = gdk_screen_get_default ();
8741 context = gdk_pango_context_get_for_screen (screen);
8743 update_pango_context (widget, context);
8744 pango_context_set_language (context, gtk_get_default_language ());
8750 * gtk_widget_create_pango_layout:
8751 * @widget: a #GtkWidget
8752 * @text: text to set on the layout (can be %NULL)
8754 * Creates a new #PangoLayout with the appropriate font map,
8755 * font description, and base direction for drawing text for
8758 * If you keep a #PangoLayout created in this way around, in order to
8759 * notify the layout of changes to the base direction or font of this
8760 * widget, you must call pango_layout_context_changed() in response to
8761 * the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
8764 * Return value: (transfer full): the new #PangoLayout
8767 gtk_widget_create_pango_layout (GtkWidget *widget,
8770 PangoLayout *layout;
8771 PangoContext *context;
8773 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8775 context = gtk_widget_get_pango_context (widget);
8776 layout = pango_layout_new (context);
8779 pango_layout_set_text (layout, text, -1);
8785 * gtk_widget_render_icon_pixbuf:
8786 * @widget: a #GtkWidget
8787 * @stock_id: a stock ID
8788 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8789 * render at the size of the source and don't scale (if there are
8790 * multiple source sizes, GTK+ picks one of the available sizes).
8792 * A convenience function that uses the theme engine and style
8793 * settings for @widget to look up @stock_id and render it to
8794 * a pixbuf. @stock_id should be a stock icon ID such as
8795 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8796 * such as #GTK_ICON_SIZE_MENU.
8798 * The pixels in the returned #GdkPixbuf are shared with the rest of
8799 * the application and should not be modified. The pixbuf should be freed
8800 * after use with g_object_unref().
8802 * Return value: (transfer full): a new pixbuf, or %NULL if the
8803 * stock ID wasn't known
8808 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
8809 const gchar *stock_id,
8812 GtkStyleContext *context;
8813 GtkIconSet *icon_set;
8815 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8816 g_return_val_if_fail (stock_id != NULL, NULL);
8817 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8819 context = gtk_widget_get_style_context (widget);
8820 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
8822 if (icon_set == NULL)
8825 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
8829 * gtk_widget_set_parent_window:
8830 * @widget: a #GtkWidget.
8831 * @parent_window: the new parent window.
8833 * Sets a non default parent window for @widget.
8835 * For GtkWindow classes, setting a @parent_window effects whether
8836 * the window is a toplevel window or can be embedded into other
8840 * For GtkWindow classes, this needs to be called before the
8841 * window is realized.
8846 gtk_widget_set_parent_window (GtkWidget *widget,
8847 GdkWindow *parent_window)
8849 GdkWindow *old_parent_window;
8851 g_return_if_fail (GTK_IS_WIDGET (widget));
8853 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8854 quark_parent_window);
8856 if (parent_window != old_parent_window)
8860 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8862 if (old_parent_window)
8863 g_object_unref (old_parent_window);
8865 g_object_ref (parent_window);
8867 /* Unset toplevel flag when adding a parent window to a widget,
8868 * this is the primary entry point to allow toplevels to be
8871 #ifdef GDK_WINDOWING_X11
8872 is_plug = GTK_IS_PLUG (widget);
8876 if (GTK_IS_WINDOW (widget) && !is_plug)
8877 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
8882 * gtk_widget_get_parent_window:
8883 * @widget: a #GtkWidget.
8885 * Gets @widget's parent window.
8887 * Returns: (transfer none): the parent window of @widget.
8890 gtk_widget_get_parent_window (GtkWidget *widget)
8892 GtkWidgetPrivate *priv;
8893 GdkWindow *parent_window;
8895 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8897 priv = widget->priv;
8899 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8901 return (parent_window != NULL) ? parent_window :
8902 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8907 * gtk_widget_set_child_visible:
8908 * @widget: a #GtkWidget
8909 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8911 * Sets whether @widget should be mapped along with its when its parent
8912 * is mapped and @widget has been shown with gtk_widget_show().
8914 * The child visibility can be set for widget before it is added to
8915 * a container with gtk_widget_set_parent(), to avoid mapping
8916 * children unnecessary before immediately unmapping them. However
8917 * it will be reset to its default state of %TRUE when the widget
8918 * is removed from a container.
8920 * Note that changing the child visibility of a widget does not
8921 * queue a resize on the widget. Most of the time, the size of
8922 * a widget is computed from all visible children, whether or
8923 * not they are mapped. If this is not the case, the container
8924 * can queue a resize itself.
8926 * This function is only useful for container implementations and
8927 * never should be called by an application.
8930 gtk_widget_set_child_visible (GtkWidget *widget,
8931 gboolean is_visible)
8933 GtkWidgetPrivate *priv;
8935 g_return_if_fail (GTK_IS_WIDGET (widget));
8936 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8938 priv = widget->priv;
8940 g_object_ref (widget);
8941 gtk_widget_verify_invariants (widget);
8944 priv->child_visible = TRUE;
8947 GtkWidget *toplevel;
8949 priv->child_visible = FALSE;
8951 toplevel = gtk_widget_get_toplevel (widget);
8952 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8953 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8956 if (priv->parent && gtk_widget_get_realized (priv->parent))
8958 if (gtk_widget_get_mapped (priv->parent) &&
8959 priv->child_visible &&
8960 gtk_widget_get_visible (widget))
8961 gtk_widget_map (widget);
8963 gtk_widget_unmap (widget);
8966 gtk_widget_verify_invariants (widget);
8967 g_object_unref (widget);
8971 * gtk_widget_get_child_visible:
8972 * @widget: a #GtkWidget
8974 * Gets the value set with gtk_widget_set_child_visible().
8975 * If you feel a need to use this function, your code probably
8976 * needs reorganization.
8978 * This function is only useful for container implementations and
8979 * never should be called by an application.
8981 * Return value: %TRUE if the widget is mapped with the parent.
8984 gtk_widget_get_child_visible (GtkWidget *widget)
8986 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8988 return widget->priv->child_visible;
8992 gtk_widget_get_screen_unchecked (GtkWidget *widget)
8994 GtkWidget *toplevel;
8996 toplevel = gtk_widget_get_toplevel (widget);
8998 if (gtk_widget_is_toplevel (toplevel))
9000 if (GTK_IS_WINDOW (toplevel))
9001 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9002 else if (GTK_IS_INVISIBLE (toplevel))
9003 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9010 * gtk_widget_get_screen:
9011 * @widget: a #GtkWidget
9013 * Get the #GdkScreen from the toplevel window associated with
9014 * this widget. This function can only be called after the widget
9015 * has been added to a widget hierarchy with a #GtkWindow
9018 * In general, you should only create screen specific
9019 * resources when a widget has been realized, and you should
9020 * free those resources when the widget is unrealized.
9022 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9027 gtk_widget_get_screen (GtkWidget *widget)
9031 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9033 screen = gtk_widget_get_screen_unchecked (widget);
9040 g_warning (G_STRLOC ": Can't get associated screen"
9041 " for a widget unless it is inside a toplevel GtkWindow\n"
9042 " widget type is %s associated top level type is %s",
9043 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9044 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9046 return gdk_screen_get_default ();
9051 * gtk_widget_has_screen:
9052 * @widget: a #GtkWidget
9054 * Checks whether there is a #GdkScreen is associated with
9055 * this widget. All toplevel widgets have an associated
9056 * screen, and all widgets added into a hierarchy with a toplevel
9057 * window at the top.
9059 * Return value: %TRUE if there is a #GdkScreen associcated
9065 gtk_widget_has_screen (GtkWidget *widget)
9067 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9069 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9073 * gtk_widget_get_display:
9074 * @widget: a #GtkWidget
9076 * Get the #GdkDisplay for the toplevel window associated with
9077 * this widget. This function can only be called after the widget
9078 * has been added to a widget hierarchy with a #GtkWindow at the top.
9080 * In general, you should only create display specific
9081 * resources when a widget has been realized, and you should
9082 * free those resources when the widget is unrealized.
9084 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9089 gtk_widget_get_display (GtkWidget *widget)
9091 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9093 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9097 * gtk_widget_get_root_window:
9098 * @widget: a #GtkWidget
9100 * Get the root window where this widget is located. This function can
9101 * only be called after the widget has been added to a widget
9102 * hierarchy with #GtkWindow at the top.
9104 * The root window is useful for such purposes as creating a popup
9105 * #GdkWindow associated with the window. In general, you should only
9106 * create display specific resources when a widget has been realized,
9107 * and you should free those resources when the widget is unrealized.
9109 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9114 gtk_widget_get_root_window (GtkWidget *widget)
9116 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9118 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9122 * gtk_widget_child_focus:
9123 * @widget: a #GtkWidget
9124 * @direction: direction of focus movement
9126 * This function is used by custom widget implementations; if you're
9127 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9128 * to a particular widget, and gtk_container_set_focus_chain() to
9129 * change the focus tab order. So you may want to investigate those
9130 * functions instead.
9132 * gtk_widget_child_focus() is called by containers as the user moves
9133 * around the window using keyboard shortcuts. @direction indicates
9134 * what kind of motion is taking place (up, down, left, right, tab
9135 * forward, tab backward). gtk_widget_child_focus() emits the
9136 * #GtkWidget::focus signal; widgets override the default handler
9137 * for this signal in order to implement appropriate focus behavior.
9139 * The default ::focus handler for a widget should return %TRUE if
9140 * moving in @direction left the focus on a focusable location inside
9141 * that widget, and %FALSE if moving in @direction moved the focus
9142 * outside the widget. If returning %TRUE, widgets normally
9143 * call gtk_widget_grab_focus() to place the focus accordingly;
9144 * if returning %FALSE, they don't modify the current focus location.
9146 * Return value: %TRUE if focus ended up inside @widget
9149 gtk_widget_child_focus (GtkWidget *widget,
9150 GtkDirectionType direction)
9152 gboolean return_val;
9154 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9156 if (!gtk_widget_get_visible (widget) ||
9157 !gtk_widget_is_sensitive (widget))
9160 /* child widgets must set CAN_FOCUS, containers
9161 * don't have to though.
9163 if (!GTK_IS_CONTAINER (widget) &&
9164 !gtk_widget_get_can_focus (widget))
9167 g_signal_emit (widget,
9168 widget_signals[FOCUS],
9170 direction, &return_val);
9176 * gtk_widget_keynav_failed:
9177 * @widget: a #GtkWidget
9178 * @direction: direction of focus movement
9180 * This function should be called whenever keyboard navigation within
9181 * a single widget hits a boundary. The function emits the
9182 * #GtkWidget::keynav-failed signal on the widget and its return
9183 * value should be interpreted in a way similar to the return value of
9184 * gtk_widget_child_focus():
9186 * When %TRUE is returned, stay in the widget, the failed keyboard
9187 * navigation is Ok and/or there is nowhere we can/should move the
9190 * When %FALSE is returned, the caller should continue with keyboard
9191 * navigation outside the widget, e.g. by calling
9192 * gtk_widget_child_focus() on the widget's toplevel.
9194 * The default ::keynav-failed handler returns %TRUE for
9195 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9196 * values of #GtkDirectionType, it looks at the
9197 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9198 * if the setting is %TRUE. This way the entire user interface
9199 * becomes cursor-navigatable on input devices such as mobile phones
9200 * which only have cursor keys but no tab key.
9202 * Whenever the default handler returns %TRUE, it also calls
9203 * gtk_widget_error_bell() to notify the user of the failed keyboard
9206 * A use case for providing an own implementation of ::keynav-failed
9207 * (either by connecting to it or by overriding it) would be a row of
9208 * #GtkEntry widgets where the user should be able to navigate the
9209 * entire row with the cursor keys, as e.g. known from user interfaces
9210 * that require entering license keys.
9212 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9213 * if the emitting widget should try to handle the keyboard
9214 * navigation attempt in its parent container(s).
9219 gtk_widget_keynav_failed (GtkWidget *widget,
9220 GtkDirectionType direction)
9222 gboolean return_val;
9224 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9226 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9227 direction, &return_val);
9233 * gtk_widget_error_bell:
9234 * @widget: a #GtkWidget
9236 * Notifies the user about an input-related error on this widget.
9237 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9238 * gdk_window_beep(), otherwise it does nothing.
9240 * Note that the effect of gdk_window_beep() can be configured in many
9241 * ways, depending on the windowing backend and the desktop environment
9242 * or window manager that is used.
9247 gtk_widget_error_bell (GtkWidget *widget)
9249 GtkWidgetPrivate *priv;
9250 GtkSettings* settings;
9253 g_return_if_fail (GTK_IS_WIDGET (widget));
9255 priv = widget->priv;
9257 settings = gtk_widget_get_settings (widget);
9261 g_object_get (settings,
9262 "gtk-error-bell", &beep,
9265 if (beep && priv->window)
9266 gdk_window_beep (priv->window);
9270 gtk_widget_set_usize_internal (GtkWidget *widget,
9273 GtkQueueResizeFlags flags)
9275 GtkWidgetAuxInfo *aux_info;
9276 gboolean changed = FALSE;
9278 g_object_freeze_notify (G_OBJECT (widget));
9280 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9282 if (width > -2 && aux_info->width != width)
9284 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9285 g_object_notify (G_OBJECT (widget), "width-request");
9286 aux_info->width = width;
9289 if (height > -2 && aux_info->height != height)
9291 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9292 g_object_notify (G_OBJECT (widget), "height-request");
9293 aux_info->height = height;
9297 if (gtk_widget_get_visible (widget) && changed)
9299 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9300 gtk_widget_queue_resize (widget);
9302 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9305 g_object_thaw_notify (G_OBJECT (widget));
9309 * gtk_widget_set_size_request:
9310 * @widget: a #GtkWidget
9311 * @width: width @widget should request, or -1 to unset
9312 * @height: height @widget should request, or -1 to unset
9314 * Sets the minimum size of a widget; that is, the widget's size
9315 * request will be @width by @height. You can use this function to
9316 * force a widget to be either larger or smaller than it normally
9319 * In most cases, gtk_window_set_default_size() is a better choice for
9320 * toplevel windows than this function; setting the default size will
9321 * still allow users to shrink the window. Setting the size request
9322 * will force them to leave the window at least as large as the size
9323 * request. When dealing with window sizes,
9324 * gtk_window_set_geometry_hints() can be a useful function as well.
9326 * Note the inherent danger of setting any fixed size - themes,
9327 * translations into other languages, different fonts, and user action
9328 * can all change the appropriate size for a given widget. So, it's
9329 * basically impossible to hardcode a size that will always be
9332 * The size request of a widget is the smallest size a widget can
9333 * accept while still functioning well and drawing itself correctly.
9334 * However in some strange cases a widget may be allocated less than
9335 * its requested size, and in many cases a widget may be allocated more
9336 * space than it requested.
9338 * If the size request in a given direction is -1 (unset), then
9339 * the "natural" size request of the widget will be used instead.
9341 * Widgets can't actually be allocated a size less than 1 by 1, but
9342 * you can pass 0,0 to this function to mean "as small as possible."
9344 * The size request set here does not include any margin from the
9345 * #GtkWidget properties margin-left, margin-right, margin-top, and
9346 * margin-bottom, but it does include pretty much all other padding
9347 * or border properties set by any subclass of #GtkWidget.
9350 gtk_widget_set_size_request (GtkWidget *widget,
9354 g_return_if_fail (GTK_IS_WIDGET (widget));
9355 g_return_if_fail (width >= -1);
9356 g_return_if_fail (height >= -1);
9363 gtk_widget_set_usize_internal (widget, width, height, 0);
9368 * gtk_widget_get_size_request:
9369 * @widget: a #GtkWidget
9370 * @width: (out) (allow-none): return location for width, or %NULL
9371 * @height: (out) (allow-none): return location for height, or %NULL
9373 * Gets the size request that was explicitly set for the widget using
9374 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9375 * @height indicates that that dimension has not been set explicitly
9376 * and the natural requisition of the widget will be used intead. See
9377 * gtk_widget_set_size_request(). To get the size a widget will
9378 * actually request, call gtk_widget_get_preferred_size() instead of
9382 gtk_widget_get_size_request (GtkWidget *widget,
9386 const GtkWidgetAuxInfo *aux_info;
9388 g_return_if_fail (GTK_IS_WIDGET (widget));
9390 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9393 *width = aux_info->width;
9396 *height = aux_info->height;
9400 * _gtk_widget_override_size_request:
9401 * @widget: a #GtkWidget
9402 * @width: new forced minimum width
9403 * @height: new forced minimum height
9404 * @old_width: location to store previous forced minimum width
9405 * @old_height: location to store previous forced minumum height
9407 * Temporarily establishes a forced minimum size for a widget; this
9408 * is used by GtkWindow when calculating the size to add to the
9409 * window's geometry widget. Cached sizes for the widget and its
9410 * parents are invalidated, so that subsequent calls to the size
9411 * negotiation machinery produce the overriden result, but the
9412 * widget is not queued for relayout or redraw. The old size must
9413 * be restored with _gtk_widget_restore_size_request() or things
9417 _gtk_widget_override_size_request (GtkWidget *widget,
9423 gtk_widget_get_size_request (widget, old_width, old_height);
9424 gtk_widget_set_usize_internal (widget, width, height,
9425 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9429 * _gtk_widget_restore_size_request:
9430 * @widget: a #GtkWidget
9431 * @old_width: saved forced minimum size
9432 * @old_height: saved forced minimum size
9434 * Undoes the operation of_gtk_widget_override_size_request().
9437 _gtk_widget_restore_size_request (GtkWidget *widget,
9441 gtk_widget_set_usize_internal (widget, old_width, old_height,
9442 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9446 * gtk_widget_set_events:
9447 * @widget: a #GtkWidget
9448 * @events: event mask
9450 * Sets the event mask (see #GdkEventMask) for a widget. The event
9451 * mask determines which events a widget will receive. Keep in mind
9452 * that different widgets have different default event masks, and by
9453 * changing the event mask you may disrupt a widget's functionality,
9454 * so be careful. This function must be called while a widget is
9455 * unrealized. Consider gtk_widget_add_events() for widgets that are
9456 * already realized, or if you want to preserve the existing event
9457 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9458 * to get events on those widgets, place them inside a #GtkEventBox
9459 * and receive events on the event box.
9462 gtk_widget_set_events (GtkWidget *widget,
9465 g_return_if_fail (GTK_IS_WIDGET (widget));
9466 g_return_if_fail (!gtk_widget_get_realized (widget));
9468 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9469 GINT_TO_POINTER (events));
9470 g_object_notify (G_OBJECT (widget), "events");
9474 * gtk_widget_set_device_events:
9475 * @widget: a #GtkWidget
9476 * @device: a #GdkDevice
9477 * @events: event mask
9479 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9480 * mask determines which events a widget will receive from @device. Keep
9481 * in mind that different widgets have different default event masks, and by
9482 * changing the event mask you may disrupt a widget's functionality,
9483 * so be careful. This function must be called while a widget is
9484 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9485 * already realized, or if you want to preserve the existing event
9486 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9487 * to get events on those widgets, place them inside a #GtkEventBox
9488 * and receive events on the event box.
9493 gtk_widget_set_device_events (GtkWidget *widget,
9495 GdkEventMask events)
9497 GHashTable *device_events;
9499 g_return_if_fail (GTK_IS_WIDGET (widget));
9500 g_return_if_fail (GDK_IS_DEVICE (device));
9501 g_return_if_fail (!gtk_widget_get_realized (widget));
9503 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9505 if (G_UNLIKELY (!device_events))
9507 device_events = g_hash_table_new (NULL, NULL);
9508 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9509 (GDestroyNotify) g_hash_table_unref);
9512 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9516 * gtk_widget_set_device_enabled:
9517 * @widget: a #GtkWidget
9518 * @device: a #GdkDevice
9519 * @enabled: whether to enable the device
9521 * Enables or disables a #GdkDevice to interact with @widget
9522 * and all its children.
9524 * It does so by descending through the #GdkWindow hierarchy
9525 * and enabling the same mask that is has for core events
9526 * (i.e. the one that gdk_window_get_events() returns).
9531 gtk_widget_set_device_enabled (GtkWidget *widget,
9535 GList *enabled_devices;
9537 g_return_if_fail (GTK_IS_WIDGET (widget));
9538 g_return_if_fail (GDK_IS_DEVICE (device));
9540 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9541 enabled_devices = g_list_append (enabled_devices, device);
9543 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9544 enabled_devices, (GDestroyNotify) g_list_free);;
9546 if (gtk_widget_get_realized (widget))
9547 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9551 * gtk_widget_get_device_enabled:
9552 * @widget: a #GtkWidget
9553 * @device: a #GdkDevice
9555 * Returns whether @device can interact with @widget and its
9556 * children. See gtk_widget_set_device_enabled().
9558 * Return value: %TRUE is @device is enabled for @widget
9563 gtk_widget_get_device_enabled (GtkWidget *widget,
9566 GList *enabled_devices;
9568 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9569 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9571 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9573 return g_list_find (enabled_devices, device) != NULL;
9577 gtk_widget_add_events_internal_list (GtkWidget *widget,
9584 for (l = window_list; l != NULL; l = l->next)
9586 GdkWindow *window = l->data;
9589 gdk_window_get_user_data (window, &user_data);
9590 if (user_data == widget)
9595 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9597 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9599 children = gdk_window_get_children (window);
9600 gtk_widget_add_events_internal_list (widget, device, events, children);
9601 g_list_free (children);
9607 gtk_widget_add_events_internal (GtkWidget *widget,
9611 GtkWidgetPrivate *priv = widget->priv;
9614 if (!gtk_widget_get_has_window (widget))
9615 window_list = gdk_window_get_children (priv->window);
9617 window_list = g_list_prepend (NULL, priv->window);
9619 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9621 g_list_free (window_list);
9625 * gtk_widget_add_events:
9626 * @widget: a #GtkWidget
9627 * @events: an event mask, see #GdkEventMask
9629 * Adds the events in the bitfield @events to the event mask for
9630 * @widget. See gtk_widget_set_events() for details.
9633 gtk_widget_add_events (GtkWidget *widget,
9638 g_return_if_fail (GTK_IS_WIDGET (widget));
9640 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9641 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9642 GINT_TO_POINTER (old_events | events));
9644 if (gtk_widget_get_realized (widget))
9646 gtk_widget_add_events_internal (widget, NULL, events);
9647 gtk_widget_update_devices_mask (widget, FALSE);
9650 g_object_notify (G_OBJECT (widget), "events");
9654 * gtk_widget_add_device_events:
9655 * @widget: a #GtkWidget
9656 * @device: a #GdkDevice
9657 * @events: an event mask, see #GdkEventMask
9659 * Adds the device events in the bitfield @events to the event mask for
9660 * @widget. See gtk_widget_set_device_events() for details.
9665 gtk_widget_add_device_events (GtkWidget *widget,
9667 GdkEventMask events)
9669 GdkEventMask old_events;
9670 GHashTable *device_events;
9672 g_return_if_fail (GTK_IS_WIDGET (widget));
9673 g_return_if_fail (GDK_IS_DEVICE (device));
9675 old_events = gtk_widget_get_device_events (widget, device);
9677 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9679 if (G_UNLIKELY (!device_events))
9681 device_events = g_hash_table_new (NULL, NULL);
9682 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9683 (GDestroyNotify) g_hash_table_unref);
9686 g_hash_table_insert (device_events, device,
9687 GUINT_TO_POINTER (old_events | events));
9689 if (gtk_widget_get_realized (widget))
9690 gtk_widget_add_events_internal (widget, device, events);
9692 g_object_notify (G_OBJECT (widget), "events");
9696 * gtk_widget_get_toplevel:
9697 * @widget: a #GtkWidget
9699 * This function returns the topmost widget in the container hierarchy
9700 * @widget is a part of. If @widget has no parent widgets, it will be
9701 * returned as the topmost widget. No reference will be added to the
9702 * returned widget; it should not be unreferenced.
9704 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9705 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9707 * %NULL if @widget wasn't inside a toplevel window, and if the
9708 * window was inside a #GtkWindow-derived widget which was in turn
9709 * inside the toplevel #GtkWindow. While the second case may
9710 * seem unlikely, it actually happens when a #GtkPlug is embedded
9711 * inside a #GtkSocket within the same application.
9713 * To reliably find the toplevel #GtkWindow, use
9714 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9715 * is set on the result.
9717 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9718 * if (gtk_widget_is_toplevel (toplevel))
9720 * /* Perform action on toplevel. */
9724 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9725 * if there's no ancestor.
9728 gtk_widget_get_toplevel (GtkWidget *widget)
9730 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9732 while (widget->priv->parent)
9733 widget = widget->priv->parent;
9739 * gtk_widget_get_ancestor:
9740 * @widget: a #GtkWidget
9741 * @widget_type: ancestor type
9743 * Gets the first ancestor of @widget with type @widget_type. For example,
9744 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9745 * the first #GtkBox that's an ancestor of @widget. No reference will be
9746 * added to the returned widget; it should not be unreferenced. See note
9747 * about checking for a toplevel #GtkWindow in the docs for
9748 * gtk_widget_get_toplevel().
9750 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9751 * considers @widget to be an ancestor of itself.
9753 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9756 gtk_widget_get_ancestor (GtkWidget *widget,
9759 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9761 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9762 widget = widget->priv->parent;
9764 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9771 * gtk_widget_set_visual:
9772 * @widget: a #GtkWidget
9773 * @visual: visual to be used or %NULL to unset a previous one
9775 * Sets the visual that should be used for by widget and its children for
9776 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9777 * returned by gdk_widget_get_screen(), so handling the
9778 * #GtkWidget::screen-changed signal is necessary.
9780 * Setting a new @visual will not cause @widget to recreate its windows,
9781 * so you should call this function before @widget is realized.
9784 gtk_widget_set_visual (GtkWidget *widget,
9787 g_return_if_fail (GTK_IS_WIDGET (widget));
9788 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9791 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9794 g_object_set_qdata_full (G_OBJECT (widget),
9796 g_object_ref (visual),
9801 * gtk_widget_get_visual:
9802 * @widget: a #GtkWidget
9804 * Gets the visual that will be used to render @widget.
9806 * Return value: (transfer none): the visual for @widget
9809 gtk_widget_get_visual (GtkWidget *widget)
9815 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9817 if (gtk_widget_get_has_window (widget) &&
9818 widget->priv->window)
9819 return gdk_window_get_visual (widget->priv->window);
9821 screen = gtk_widget_get_screen (widget);
9823 for (w = widget; w != NULL; w = w->priv->parent)
9825 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9828 if (gdk_visual_get_screen (visual) == screen)
9831 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9832 gtk_widget_get_name (widget));
9836 return gdk_screen_get_system_visual (screen);
9840 * gtk_widget_get_settings:
9841 * @widget: a #GtkWidget
9843 * Gets the settings object holding the settings used for this widget.
9845 * Note that this function can only be called when the #GtkWidget
9846 * is attached to a toplevel, since the settings object is specific
9847 * to a particular #GdkScreen.
9849 * Return value: (transfer none): the relevant #GtkSettings object
9852 gtk_widget_get_settings (GtkWidget *widget)
9854 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9856 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9860 * gtk_widget_get_events:
9861 * @widget: a #GtkWidget
9863 * Returns the event mask for the widget (a bitfield containing flags
9864 * from the #GdkEventMask enumeration). These are the events that the widget
9867 * Return value: event mask for @widget
9870 gtk_widget_get_events (GtkWidget *widget)
9872 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9874 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9878 * gtk_widget_get_device_events:
9879 * @widget: a #GtkWidget
9880 * @device: a #GdkDevice
9882 * Returns the events mask for the widget corresponding to an specific device. These
9883 * are the events that the widget will receive when @device operates on it.
9885 * Returns: device event mask for @widget
9890 gtk_widget_get_device_events (GtkWidget *widget,
9893 GHashTable *device_events;
9895 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9896 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9898 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9903 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9907 * gtk_widget_get_pointer:
9908 * @widget: a #GtkWidget
9909 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9910 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9912 * Obtains the location of the mouse pointer in widget coordinates.
9913 * Widget coordinates are a bit odd; for historical reasons, they are
9914 * defined as @widget->window coordinates for widgets that are not
9915 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9916 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9918 * Deprecated: 3.4: Use gdk_window_get_device_position() instead.
9921 gtk_widget_get_pointer (GtkWidget *widget,
9925 GtkWidgetPrivate *priv;
9927 g_return_if_fail (GTK_IS_WIDGET (widget));
9929 priv = widget->priv;
9936 if (gtk_widget_get_realized (widget))
9938 gdk_window_get_device_position (priv->window,
9939 gdk_device_manager_get_client_pointer (
9940 gdk_display_get_device_manager (
9941 gtk_widget_get_display (widget))),
9944 if (!gtk_widget_get_has_window (widget))
9947 *x -= priv->allocation.x;
9949 *y -= priv->allocation.y;
9955 * gtk_widget_is_ancestor:
9956 * @widget: a #GtkWidget
9957 * @ancestor: another #GtkWidget
9959 * Determines whether @widget is somewhere inside @ancestor, possibly with
9960 * intermediate containers.
9962 * Return value: %TRUE if @ancestor contains @widget as a child,
9963 * grandchild, great grandchild, etc.
9966 gtk_widget_is_ancestor (GtkWidget *widget,
9967 GtkWidget *ancestor)
9969 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9970 g_return_val_if_fail (ancestor != NULL, FALSE);
9974 if (widget->priv->parent == ancestor)
9976 widget = widget->priv->parent;
9982 static GQuark quark_composite_name = 0;
9985 * gtk_widget_set_composite_name:
9986 * @widget: a #GtkWidget.
9987 * @name: the name to set
9989 * Sets a widgets composite name. The widget must be
9990 * a composite child of its parent; see gtk_widget_push_composite_child().
9993 gtk_widget_set_composite_name (GtkWidget *widget,
9996 g_return_if_fail (GTK_IS_WIDGET (widget));
9997 g_return_if_fail (widget->priv->composite_child);
9998 g_return_if_fail (name != NULL);
10000 if (!quark_composite_name)
10001 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10003 g_object_set_qdata_full (G_OBJECT (widget),
10004 quark_composite_name,
10010 * gtk_widget_get_composite_name:
10011 * @widget: a #GtkWidget
10013 * Obtains the composite name of a widget.
10015 * Returns: the composite name of @widget, or %NULL if @widget is not
10016 * a composite child. The string should be freed when it is no
10020 gtk_widget_get_composite_name (GtkWidget *widget)
10022 GtkWidgetPrivate *priv;
10024 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10026 priv = widget->priv;
10028 if (widget->priv->composite_child && priv->parent)
10029 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10036 * gtk_widget_push_composite_child:
10038 * Makes all newly-created widgets as composite children until
10039 * the corresponding gtk_widget_pop_composite_child() call.
10041 * A composite child is a child that's an implementation detail of the
10042 * container it's inside and should not be visible to people using the
10043 * container. Composite children aren't treated differently by GTK (but
10044 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10045 * builders might want to treat them in a different way.
10047 * Here is a simple example:
10049 * gtk_widget_push_composite_child ();
10050 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10051 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10052 * gtk_widget_pop_composite_child ();
10053 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10054 * GTK_WIDGET (scrolled_window));
10055 * g_object_ref (scrolled_window->hscrollbar);
10059 gtk_widget_push_composite_child (void)
10061 composite_child_stack++;
10065 * gtk_widget_pop_composite_child:
10067 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10070 gtk_widget_pop_composite_child (void)
10072 if (composite_child_stack)
10073 composite_child_stack--;
10077 gtk_widget_emit_direction_changed (GtkWidget *widget,
10078 GtkTextDirection old_dir)
10080 gtk_widget_update_pango_context (widget);
10082 if (widget->priv->context)
10083 gtk_style_context_set_direction (widget->priv->context,
10084 gtk_widget_get_direction (widget));
10086 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10090 * gtk_widget_set_direction:
10091 * @widget: a #GtkWidget
10092 * @dir: the new direction
10094 * Sets the reading direction on a particular widget. This direction
10095 * controls the primary direction for widgets containing text,
10096 * and also the direction in which the children of a container are
10097 * packed. The ability to set the direction is present in order
10098 * so that correct localization into languages with right-to-left
10099 * reading directions can be done. Generally, applications will
10100 * let the default reading direction present, except for containers
10101 * where the containers are arranged in an order that is explicitely
10102 * visual rather than logical (such as buttons for text justification).
10104 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10105 * set by gtk_widget_set_default_direction() will be used.
10108 gtk_widget_set_direction (GtkWidget *widget,
10109 GtkTextDirection dir)
10111 GtkTextDirection old_dir;
10113 g_return_if_fail (GTK_IS_WIDGET (widget));
10114 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10116 old_dir = gtk_widget_get_direction (widget);
10118 widget->priv->direction = dir;
10120 if (old_dir != gtk_widget_get_direction (widget))
10121 gtk_widget_emit_direction_changed (widget, old_dir);
10125 * gtk_widget_get_direction:
10126 * @widget: a #GtkWidget
10128 * Gets the reading direction for a particular widget. See
10129 * gtk_widget_set_direction().
10131 * Return value: the reading direction for the widget.
10134 gtk_widget_get_direction (GtkWidget *widget)
10136 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10138 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10139 return gtk_default_direction;
10141 return widget->priv->direction;
10145 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10147 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10149 g_object_ref (widget);
10151 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10152 gtk_widget_emit_direction_changed (widget, old_dir);
10154 if (GTK_IS_CONTAINER (widget))
10155 gtk_container_forall (GTK_CONTAINER (widget),
10156 gtk_widget_set_default_direction_recurse,
10159 g_object_unref (widget);
10163 * gtk_widget_set_default_direction:
10164 * @dir: the new default direction. This cannot be
10165 * %GTK_TEXT_DIR_NONE.
10167 * Sets the default reading direction for widgets where the
10168 * direction has not been explicitly set by gtk_widget_set_direction().
10171 gtk_widget_set_default_direction (GtkTextDirection dir)
10173 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10175 if (dir != gtk_default_direction)
10177 GList *toplevels, *tmp_list;
10178 GtkTextDirection old_dir = gtk_default_direction;
10180 gtk_default_direction = dir;
10182 tmp_list = toplevels = gtk_window_list_toplevels ();
10183 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10187 gtk_widget_set_default_direction_recurse (tmp_list->data,
10188 GUINT_TO_POINTER (old_dir));
10189 g_object_unref (tmp_list->data);
10190 tmp_list = tmp_list->next;
10193 g_list_free (toplevels);
10198 * gtk_widget_get_default_direction:
10200 * Obtains the current default reading direction. See
10201 * gtk_widget_set_default_direction().
10203 * Return value: the current default direction.
10206 gtk_widget_get_default_direction (void)
10208 return gtk_default_direction;
10212 gtk_widget_constructed (GObject *object)
10214 GtkWidget *widget = GTK_WIDGET (object);
10215 GtkWidgetPrivate *priv = widget->priv;
10217 /* As strange as it may seem, this may happen on object construction.
10218 * init() implementations of parent types may eventually call this function,
10219 * each with its corresponding GType, which could leave a child
10220 * implementation with a wrong widget type in the widget path
10223 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (priv->path))
10225 gtk_widget_path_free (priv->path);
10229 G_OBJECT_CLASS (gtk_widget_parent_class)->constructed (object);
10233 gtk_widget_dispose (GObject *object)
10235 GtkWidget *widget = GTK_WIDGET (object);
10236 GtkWidgetPrivate *priv = widget->priv;
10239 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10240 else if (gtk_widget_get_visible (widget))
10241 gtk_widget_hide (widget);
10243 priv->visible = FALSE;
10244 if (gtk_widget_get_realized (widget))
10245 gtk_widget_unrealize (widget);
10247 if (!priv->in_destruction)
10249 priv->in_destruction = TRUE;
10250 g_signal_emit (object, widget_signals[DESTROY], 0);
10251 priv->in_destruction = FALSE;
10254 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10258 gtk_widget_real_destroy (GtkWidget *object)
10260 /* gtk_object_destroy() will already hold a refcount on object */
10261 GtkWidget *widget = GTK_WIDGET (object);
10262 GtkWidgetPrivate *priv = widget->priv;
10264 if (GTK_WIDGET_GET_CLASS (widget)->priv->accessible_type != GTK_TYPE_ACCESSIBLE)
10266 GtkAccessible *accessible = g_object_steal_qdata (G_OBJECT (widget), quark_accessible_object);
10270 gtk_accessible_set_widget (accessible, NULL);
10271 g_object_unref (accessible);
10275 /* wipe accelerator closures (keep order) */
10276 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10277 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10279 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10280 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10282 gtk_grab_remove (widget);
10285 g_object_unref (priv->style);
10286 priv->style = gtk_widget_get_default_style ();
10287 g_object_ref (priv->style);
10291 gtk_widget_finalize (GObject *object)
10293 GtkWidget *widget = GTK_WIDGET (object);
10294 GtkWidgetPrivate *priv = widget->priv;
10295 GtkWidgetAuxInfo *aux_info;
10296 GtkAccessible *accessible;
10298 gtk_grab_remove (widget);
10300 g_object_unref (priv->style);
10301 priv->style = NULL;
10303 g_free (priv->name);
10305 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10307 gtk_widget_aux_info_destroy (aux_info);
10309 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10311 g_object_unref (accessible);
10314 gtk_widget_path_free (priv->path);
10318 _gtk_style_context_set_widget (priv->context, NULL);
10319 g_object_unref (priv->context);
10322 _gtk_widget_free_cached_sizes (widget);
10324 if (g_object_is_floating (object))
10325 g_warning ("A floating object was finalized. This means that someone\n"
10326 "called g_object_unref() on an object that had only a floating\n"
10327 "reference; the initial floating reference is not owned by anyone\n"
10328 "and must be removed with g_object_ref_sink().");
10330 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10333 /*****************************************
10334 * gtk_widget_real_map:
10339 *****************************************/
10342 gtk_widget_real_map (GtkWidget *widget)
10344 GtkWidgetPrivate *priv = widget->priv;
10346 g_assert (gtk_widget_get_realized (widget));
10348 if (!gtk_widget_get_mapped (widget))
10350 gtk_widget_set_mapped (widget, TRUE);
10352 if (gtk_widget_get_has_window (widget))
10353 gdk_window_show (priv->window);
10357 /*****************************************
10358 * gtk_widget_real_unmap:
10363 *****************************************/
10366 gtk_widget_real_unmap (GtkWidget *widget)
10368 GtkWidgetPrivate *priv = widget->priv;
10370 if (gtk_widget_get_mapped (widget))
10372 gtk_widget_set_mapped (widget, FALSE);
10374 if (gtk_widget_get_has_window (widget))
10375 gdk_window_hide (priv->window);
10379 /*****************************************
10380 * gtk_widget_real_realize:
10385 *****************************************/
10388 gtk_widget_real_realize (GtkWidget *widget)
10390 GtkWidgetPrivate *priv = widget->priv;
10392 g_assert (!gtk_widget_get_has_window (widget));
10394 gtk_widget_set_realized (widget, TRUE);
10397 priv->window = gtk_widget_get_parent_window (widget);
10398 g_object_ref (priv->window);
10402 /*****************************************
10403 * gtk_widget_real_unrealize:
10408 *****************************************/
10411 gtk_widget_real_unrealize (GtkWidget *widget)
10413 GtkWidgetPrivate *priv = widget->priv;
10415 g_assert (!widget->priv->mapped);
10417 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10420 /* We must do unrealize child widget BEFORE container widget.
10421 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10422 * So, unrealizing container widget bofore its children causes the problem
10423 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10426 if (GTK_IS_CONTAINER (widget))
10427 gtk_container_forall (GTK_CONTAINER (widget),
10428 (GtkCallback) gtk_widget_unrealize,
10431 if (gtk_widget_get_has_window (widget))
10433 gdk_window_set_user_data (priv->window, NULL);
10434 gdk_window_destroy (priv->window);
10435 priv->window = NULL;
10439 g_object_unref (priv->window);
10440 priv->window = NULL;
10443 gtk_selection_remove_all (widget);
10445 gtk_widget_set_realized (widget, FALSE);
10449 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10450 GtkOrientation orientation,
10451 gint *minimum_size,
10452 gint *natural_size)
10454 const GtkWidgetAuxInfo *aux_info;
10456 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10458 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10459 aux_info->width > 0)
10461 *minimum_size = MAX (*minimum_size, aux_info->width);
10463 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10464 aux_info->height > 0)
10466 *minimum_size = MAX (*minimum_size, aux_info->height);
10469 /* Fix it if set_size_request made natural size smaller than min size.
10470 * This would also silently fix broken widgets, but we warn about them
10471 * in gtksizerequest.c when calling their size request vfuncs.
10473 *natural_size = MAX (*natural_size, *minimum_size);
10475 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10477 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10478 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10482 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10483 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10488 * _gtk_widget_peek_request_cache:
10490 * Returns the address of the widget's request cache (strictly for
10491 * internal use in gtksizerequest.c)
10493 * Return value: the address of @widget's size request cache.
10496 _gtk_widget_peek_request_cache (GtkWidget *widget)
10498 /* Don't bother slowing things down with the return_if_fail guards here */
10499 return &widget->priv->requests;
10503 * _gtk_widget_set_device_window:
10504 * @widget: a #GtkWidget
10505 * @device: a #GdkDevice
10506 * @window: the new device window
10508 * Sets pointer window for @widget and @device.
10509 * Does not ref @window.
10512 _gtk_widget_set_device_window (GtkWidget *widget,
10516 GHashTable *device_window;
10518 g_return_if_fail (GTK_IS_WIDGET (widget));
10519 g_return_if_fail (GDK_IS_DEVICE (device));
10520 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10522 if (!gtk_widget_get_mapped (widget))
10525 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10527 if (!device_window && window)
10529 device_window = g_hash_table_new (NULL, NULL);
10530 g_object_set_qdata_full (G_OBJECT (widget),
10531 quark_pointer_window,
10533 (GDestroyNotify) g_hash_table_destroy);
10537 g_hash_table_insert (device_window, device, window);
10538 else if (device_window)
10540 g_hash_table_remove (device_window, device);
10542 if (g_hash_table_size (device_window) == 0)
10543 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10548 * _gtk_widget_get_device_window:
10549 * @widget: a #GtkWidget
10550 * @device: a #GdkDevice
10552 * Return value: the device window set on @widget, or %NULL
10555 _gtk_widget_get_device_window (GtkWidget *widget,
10558 GHashTable *device_window;
10560 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10561 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10563 if (!gtk_widget_get_mapped (widget))
10566 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10568 if (!device_window)
10571 return g_hash_table_lookup (device_window, device);
10575 * _gtk_widget_list_devices:
10576 * @widget: a #GtkWidget
10578 * Returns the list of #GdkDevices that is currently on top
10579 * of any window belonging to @widget.
10580 * Free the list with g_list_free(), the elements are owned
10581 * by GTK+ and must not be freed.
10584 _gtk_widget_list_devices (GtkWidget *widget)
10586 GHashTableIter iter;
10587 GHashTable *device_window;
10588 GList *devices = NULL;
10589 gpointer key, value;
10591 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10593 if (!gtk_widget_get_mapped (widget))
10596 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10598 if (G_UNLIKELY (!device_window))
10601 g_hash_table_iter_init (&iter, device_window);
10603 while (g_hash_table_iter_next (&iter, &key, &value))
10604 devices = g_list_prepend (devices, key);
10610 synth_crossing (GtkWidget *widget,
10614 GdkCrossingMode mode,
10615 GdkNotifyType detail)
10619 event = gdk_event_new (type);
10621 event->crossing.window = g_object_ref (window);
10622 event->crossing.send_event = TRUE;
10623 event->crossing.subwindow = g_object_ref (window);
10624 event->crossing.time = GDK_CURRENT_TIME;
10625 event->crossing.x = event->crossing.y = 0;
10626 event->crossing.x_root = event->crossing.y_root = 0;
10627 event->crossing.mode = mode;
10628 event->crossing.detail = detail;
10629 event->crossing.focus = FALSE;
10630 event->crossing.state = 0;
10631 gdk_event_set_device (event, device);
10634 widget = gtk_get_event_widget (event);
10637 gtk_widget_event_internal (widget, event);
10639 gdk_event_free (event);
10643 * _gtk_widget_synthesize_crossing:
10644 * @from: the #GtkWidget the virtual pointer is leaving.
10645 * @to: the #GtkWidget the virtual pointer is moving to.
10646 * @mode: the #GdkCrossingMode to place on the synthesized events.
10648 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10650 * The real pointer window is the window that most recently received an enter notify
10651 * event. Windows that don't select for crossing events can't become the real
10652 * poiner window. The real pointer widget that owns the real pointer window. The
10653 * effective pointer window is the same as the real pointer window unless the real
10654 * pointer widget is either insensitive or there is a grab on a widget that is not
10655 * an ancestor of the real pointer widget (in which case the effective pointer
10656 * window should be the root window).
10658 * When the effective pointer window is the same as the real poiner window, we
10659 * receive crossing events from the windowing system. When the effective pointer
10660 * window changes to become different from the real pointer window we synthesize
10661 * crossing events, attempting to follow X protocol rules:
10663 * When the root window becomes the effective pointer window:
10664 * - leave notify on real pointer window, detail Ancestor
10665 * - leave notify on all of its ancestors, detail Virtual
10666 * - enter notify on root window, detail Inferior
10668 * When the root window ceases to be the effective pointer window:
10669 * - leave notify on root window, detail Inferior
10670 * - enter notify on all ancestors of real pointer window, detail Virtual
10671 * - enter notify on real pointer window, detail Ancestor
10674 _gtk_widget_synthesize_crossing (GtkWidget *from,
10677 GdkCrossingMode mode)
10679 GdkWindow *from_window = NULL, *to_window = NULL;
10681 g_return_if_fail (from != NULL || to != NULL);
10685 from_window = _gtk_widget_get_device_window (from, device);
10688 from_window = from->priv->window;
10693 to_window = _gtk_widget_get_device_window (to, device);
10696 to_window = to->priv->window;
10699 if (from_window == NULL && to_window == NULL)
10701 else if (from_window != NULL && to_window == NULL)
10703 GList *from_ancestors = NULL, *list;
10704 GdkWindow *from_ancestor = from_window;
10706 while (from_ancestor != NULL)
10708 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10709 if (from_ancestor == NULL)
10711 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10714 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10715 device, mode, GDK_NOTIFY_ANCESTOR);
10716 for (list = g_list_last (from_ancestors); list; list = list->prev)
10718 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10719 device, mode, GDK_NOTIFY_VIRTUAL);
10722 /* XXX: enter/inferior on root window? */
10724 g_list_free (from_ancestors);
10726 else if (from_window == NULL && to_window != NULL)
10728 GList *to_ancestors = NULL, *list;
10729 GdkWindow *to_ancestor = to_window;
10731 while (to_ancestor != NULL)
10733 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10734 if (to_ancestor == NULL)
10736 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10739 /* XXX: leave/inferior on root window? */
10741 for (list = to_ancestors; list; list = list->next)
10743 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10744 device, mode, GDK_NOTIFY_VIRTUAL);
10746 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10747 device, mode, GDK_NOTIFY_ANCESTOR);
10749 g_list_free (to_ancestors);
10751 else if (from_window == to_window)
10755 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10756 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10758 while (from_ancestor != NULL || to_ancestor != NULL)
10760 if (from_ancestor != NULL)
10762 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10763 if (from_ancestor == to_window)
10766 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10768 if (to_ancestor != NULL)
10770 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10771 if (to_ancestor == from_window)
10774 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10777 if (to_ancestor == from_window)
10779 if (mode != GDK_CROSSING_GTK_UNGRAB)
10780 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10781 device, mode, GDK_NOTIFY_INFERIOR);
10782 for (list = to_ancestors; list; list = list->next)
10783 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10784 device, mode, GDK_NOTIFY_VIRTUAL);
10785 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10786 device, mode, GDK_NOTIFY_ANCESTOR);
10788 else if (from_ancestor == to_window)
10790 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10791 device, mode, GDK_NOTIFY_ANCESTOR);
10792 for (list = g_list_last (from_ancestors); list; list = list->prev)
10794 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10795 device, mode, GDK_NOTIFY_VIRTUAL);
10797 if (mode != GDK_CROSSING_GTK_GRAB)
10798 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10799 device, mode, GDK_NOTIFY_INFERIOR);
10803 while (from_ancestors != NULL && to_ancestors != NULL
10804 && from_ancestors->data == to_ancestors->data)
10806 from_ancestors = g_list_delete_link (from_ancestors,
10808 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10811 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10812 device, mode, GDK_NOTIFY_NONLINEAR);
10814 for (list = g_list_last (from_ancestors); list; list = list->prev)
10816 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10817 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10819 for (list = to_ancestors; list; list = list->next)
10821 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10822 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10824 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10825 device, mode, GDK_NOTIFY_NONLINEAR);
10827 g_list_free (from_ancestors);
10828 g_list_free (to_ancestors);
10833 gtk_widget_propagate_state (GtkWidget *widget,
10834 GtkStateData *data)
10836 GtkWidgetPrivate *priv = widget->priv;
10837 GtkStateFlags new_flags, old_flags = priv->state_flags;
10838 GtkStateType old_state;
10840 old_state = gtk_widget_get_state (widget);
10842 switch (data->operation)
10844 case STATE_CHANGE_REPLACE:
10845 priv->state_flags = data->flags;
10847 case STATE_CHANGE_SET:
10848 priv->state_flags |= data->flags;
10850 case STATE_CHANGE_UNSET:
10851 priv->state_flags &= ~(data->flags);
10855 /* make insensitivity unoverridable */
10856 if (!priv->sensitive)
10857 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
10859 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10863 window = gtk_widget_get_toplevel (widget);
10865 if (window && gtk_widget_is_toplevel (window))
10866 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10869 new_flags = priv->state_flags;
10871 if (old_flags != new_flags)
10873 g_object_ref (widget);
10875 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10876 gtk_grab_remove (widget);
10878 gtk_style_context_set_state (gtk_widget_get_style_context (widget), new_flags);
10880 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10881 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
10883 if (!priv->shadowed &&
10884 (new_flags & GTK_STATE_FLAG_INSENSITIVE) != (old_flags & GTK_STATE_FLAG_INSENSITIVE))
10886 GList *event_windows = NULL;
10887 GList *devices, *d;
10889 devices = _gtk_widget_list_devices (widget);
10891 for (d = devices; d; d = d->next)
10897 window = _gtk_widget_get_device_window (widget, device);
10899 /* Do not propagate more than once to the
10900 * same window if non-multidevice aware.
10902 if (!gdk_window_get_support_multidevice (window) &&
10903 g_list_find (event_windows, window))
10906 if (!gtk_widget_is_sensitive (widget))
10907 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10908 GDK_CROSSING_STATE_CHANGED);
10910 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10911 GDK_CROSSING_STATE_CHANGED);
10913 event_windows = g_list_prepend (event_windows, window);
10916 g_list_free (event_windows);
10917 g_list_free (devices);
10920 if (GTK_IS_CONTAINER (widget))
10922 GtkStateData child_data = *data;
10924 /* Make sure to only propate the right states further */
10925 child_data.flags &= GTK_STATE_FLAGS_DO_PROPAGATE;
10927 gtk_container_forall (GTK_CONTAINER (widget),
10928 (GtkCallback) gtk_widget_propagate_state,
10932 g_object_unref (widget);
10936 static const GtkWidgetAuxInfo default_aux_info = {
10944 * gtk_widget_get_aux_info:
10945 * @widget: a #GtkWidget
10946 * @create: if %TRUE, create the structure if it doesn't exist
10948 * Get the #GtkWidgetAuxInfo structure for the widget.
10950 * Return value: the #GtkAuxInfo structure for the widget, or
10951 * %NULL if @create is %FALSE and one doesn't already exist.
10953 static GtkWidgetAuxInfo *
10954 gtk_widget_get_aux_info (GtkWidget *widget,
10957 GtkWidgetAuxInfo *aux_info;
10959 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
10960 if (!aux_info && create)
10962 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
10964 *aux_info = default_aux_info;
10966 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
10972 static const GtkWidgetAuxInfo*
10973 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
10975 GtkWidgetAuxInfo *aux_info;
10977 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10978 if (aux_info == NULL)
10980 return &default_aux_info;
10988 /*****************************************
10989 * gtk_widget_aux_info_destroy:
10994 *****************************************/
10997 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
10999 g_slice_free (GtkWidgetAuxInfo, aux_info);
11003 * gtk_widget_shape_combine_region:
11004 * @widget: a #GtkWidget
11005 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11007 * Sets a shape for this widget's GDK window. This allows for
11008 * transparent windows etc., see gdk_window_shape_combine_region()
11009 * for more information.
11014 gtk_widget_shape_combine_region (GtkWidget *widget,
11015 cairo_region_t *region)
11017 GtkWidgetPrivate *priv;
11019 g_return_if_fail (GTK_IS_WIDGET (widget));
11020 /* set_shape doesn't work on widgets without gdk window */
11021 g_return_if_fail (gtk_widget_get_has_window (widget));
11023 priv = widget->priv;
11025 if (region == NULL)
11027 priv->has_shape_mask = FALSE;
11030 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11032 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11036 priv->has_shape_mask = TRUE;
11038 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11039 cairo_region_copy (region),
11040 (GDestroyNotify) cairo_region_destroy);
11042 /* set shape if widget has a gdk window already.
11043 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11046 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11051 * gtk_widget_input_shape_combine_region:
11052 * @widget: a #GtkWidget
11053 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11055 * Sets an input shape for this widget's GDK window. This allows for
11056 * windows which react to mouse click in a nonrectangular region, see
11057 * gdk_window_input_shape_combine_region() for more information.
11062 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11063 cairo_region_t *region)
11065 GtkWidgetPrivate *priv;
11067 g_return_if_fail (GTK_IS_WIDGET (widget));
11068 /* set_shape doesn't work on widgets without gdk window */
11069 g_return_if_fail (gtk_widget_get_has_window (widget));
11071 priv = widget->priv;
11073 if (region == NULL)
11076 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11078 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11082 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11083 cairo_region_copy (region),
11084 (GDestroyNotify) cairo_region_destroy);
11086 /* set shape if widget has a gdk window already.
11087 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11090 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11095 /* style properties
11099 * gtk_widget_class_install_style_property_parser: (skip)
11100 * @klass: a #GtkWidgetClass
11101 * @pspec: the #GParamSpec for the style property
11102 * @parser: the parser for the style property
11104 * Installs a style property on a widget class.
11107 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11109 GtkRcPropertyParser parser)
11111 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11112 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11113 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11114 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11116 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11118 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11119 G_OBJECT_CLASS_NAME (klass),
11124 g_param_spec_ref_sink (pspec);
11125 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11126 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11130 * gtk_widget_class_install_style_property:
11131 * @klass: a #GtkWidgetClass
11132 * @pspec: the #GParamSpec for the property
11134 * Installs a style property on a widget class. The parser for the
11135 * style property is determined by the value type of @pspec.
11138 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11141 GtkRcPropertyParser parser;
11143 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11144 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11146 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11148 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11152 * gtk_widget_class_find_style_property:
11153 * @klass: a #GtkWidgetClass
11154 * @property_name: the name of the style property to find
11156 * Finds a style property of a widget class by name.
11158 * Returns: (transfer none): the #GParamSpec of the style property or
11159 * %NULL if @class has no style property with that name.
11164 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11165 const gchar *property_name)
11167 g_return_val_if_fail (property_name != NULL, NULL);
11169 return g_param_spec_pool_lookup (style_property_spec_pool,
11171 G_OBJECT_CLASS_TYPE (klass),
11176 * gtk_widget_class_list_style_properties:
11177 * @klass: a #GtkWidgetClass
11178 * @n_properties: location to return the number of style properties found
11180 * Returns all style properties of a widget class.
11182 * Returns: (array length=n_properties) (transfer container): a
11183 * newly allocated array of #GParamSpec*. The array must be
11184 * freed with g_free().
11189 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11190 guint *n_properties)
11192 GParamSpec **pspecs;
11195 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11196 G_OBJECT_CLASS_TYPE (klass),
11205 * gtk_widget_style_get_property:
11206 * @widget: a #GtkWidget
11207 * @property_name: the name of a style property
11208 * @value: location to return the property value
11210 * Gets the value of a style property of @widget.
11213 gtk_widget_style_get_property (GtkWidget *widget,
11214 const gchar *property_name,
11219 g_return_if_fail (GTK_IS_WIDGET (widget));
11220 g_return_if_fail (property_name != NULL);
11221 g_return_if_fail (G_IS_VALUE (value));
11223 g_object_ref (widget);
11224 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11226 G_OBJECT_TYPE (widget),
11229 g_warning ("%s: widget class `%s' has no property named `%s'",
11231 G_OBJECT_TYPE_NAME (widget),
11235 GtkStyleContext *context;
11236 const GValue *peek_value;
11237 GtkStateFlags state;
11239 context = gtk_widget_get_style_context (widget);
11240 state = gtk_widget_get_state_flags (widget);
11242 peek_value = _gtk_style_context_peek_style_property (context,
11243 G_OBJECT_TYPE (widget),
11246 /* auto-conversion of the caller's value type
11248 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11249 g_value_copy (peek_value, value);
11250 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11251 g_value_transform (peek_value, value);
11253 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11255 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11256 G_VALUE_TYPE_NAME (value));
11258 g_object_unref (widget);
11262 * gtk_widget_style_get_valist:
11263 * @widget: a #GtkWidget
11264 * @first_property_name: the name of the first property to get
11265 * @var_args: a <type>va_list</type> of pairs of property names and
11266 * locations to return the property values, starting with the location
11267 * for @first_property_name.
11269 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11273 gtk_widget_style_get_valist (GtkWidget *widget,
11274 const gchar *first_property_name,
11277 GtkStyleContext *context;
11278 GtkStateFlags state;
11281 g_return_if_fail (GTK_IS_WIDGET (widget));
11283 g_object_ref (widget);
11284 context = gtk_widget_get_style_context (widget);
11285 state = gtk_widget_get_state_flags (widget);
11287 name = first_property_name;
11290 const GValue *peek_value;
11294 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11296 G_OBJECT_TYPE (widget),
11300 g_warning ("%s: widget class `%s' has no property named `%s'",
11302 G_OBJECT_TYPE_NAME (widget),
11306 /* style pspecs are always readable so we can spare that check here */
11308 peek_value = _gtk_style_context_peek_style_property (context,
11309 G_OBJECT_TYPE (widget),
11312 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11315 g_warning ("%s: %s", G_STRLOC, error);
11320 name = va_arg (var_args, gchar*);
11323 g_object_unref (widget);
11327 * gtk_widget_style_get:
11328 * @widget: a #GtkWidget
11329 * @first_property_name: the name of the first property to get
11330 * @...: pairs of property names and locations to return the
11331 * property values, starting with the location for
11332 * @first_property_name, terminated by %NULL.
11334 * Gets the values of a multiple style properties of @widget.
11337 gtk_widget_style_get (GtkWidget *widget,
11338 const gchar *first_property_name,
11343 g_return_if_fail (GTK_IS_WIDGET (widget));
11345 va_start (var_args, first_property_name);
11346 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11351 * gtk_requisition_new:
11353 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11355 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11356 * be freed with gtk_requisition_free().
11361 gtk_requisition_new (void)
11363 return g_slice_new0 (GtkRequisition);
11367 * gtk_requisition_copy:
11368 * @requisition: a #GtkRequisition
11370 * Copies a #GtkRequisition.
11372 * Returns: a copy of @requisition
11375 gtk_requisition_copy (const GtkRequisition *requisition)
11377 return g_slice_dup (GtkRequisition, requisition);
11381 * gtk_requisition_free:
11382 * @requisition: a #GtkRequisition
11384 * Frees a #GtkRequisition.
11387 gtk_requisition_free (GtkRequisition *requisition)
11389 g_slice_free (GtkRequisition, requisition);
11392 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11393 gtk_requisition_copy,
11394 gtk_requisition_free)
11397 * gtk_widget_class_set_accessible_type:
11398 * @widget_class: class to set the accessible type for
11399 * @type: The object type that implements the accessible for @widget_class
11401 * Sets the type to be used for creating accessibles for widgets of
11402 * @widget_class. The given @type must be a subtype of the type used for
11403 * accessibles of the parent class.
11405 * This function should only be called from class init functions of widgets.
11410 gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class,
11413 GtkWidgetClassPrivate *priv;
11415 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11416 g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type));
11418 priv = widget_class->priv;
11420 priv->accessible_type = type;
11421 /* reset this - honoring the type's role is better. */
11422 priv->accessible_role = ATK_ROLE_INVALID;
11426 * gtk_widget_class_set_accessible_role:
11427 * @widget_class: class to set the accessible role for
11428 * @role: The role to use for accessibles created for @widget_class
11430 * Sets the default #AtkRole to be set on accessibles created for
11431 * widgets of @widget_class. Accessibles may decide to not honor this
11432 * setting if their role reporting is more refined. Calls to
11433 * gtk_widget_class_set_accessible_type() will reset this value.
11435 * In cases where you want more fine-grained control over the role of
11436 * accessibles created for @widget_class, you should provide your own
11437 * accessible type and use gtk_widget_class_set_accessible_type()
11440 * If @role is #ATK_ROLE_INVALID, the default role will not be changed
11441 * and the accessible's default role will be used instead.
11443 * This function should only be called from class init functions of widgets.
11448 gtk_widget_class_set_accessible_role (GtkWidgetClass *widget_class,
11451 GtkWidgetClassPrivate *priv;
11453 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11455 priv = widget_class->priv;
11457 priv->accessible_role = role;
11461 * _gtk_widget_peek_accessible:
11462 * @widget: a #GtkWidget
11464 * Gets the accessible for @widget, if it has been created yet.
11465 * Otherwise, this function returns %NULL. If the @widget's implementation
11466 * does not use the default way to create accessibles, %NULL will always be
11469 * Returns: the accessible for @widget or %NULL if none has been
11473 _gtk_widget_peek_accessible (GtkWidget *widget)
11475 return g_object_get_qdata (G_OBJECT (widget),
11476 quark_accessible_object);
11480 * gtk_widget_get_accessible:
11481 * @widget: a #GtkWidget
11483 * Returns the accessible object that describes the widget to an
11484 * assistive technology.
11486 * If accessibility support is not available, this #AtkObject
11487 * instance may be a no-op. Likewise, if no class-specific #AtkObject
11488 * implementation is available for the widget instance in question,
11489 * it will inherit an #AtkObject implementation from the first ancestor
11490 * class for which such an implementation is defined.
11492 * The documentation of the
11493 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
11494 * library contains more information about accessible objects and their uses.
11496 * Returns: (transfer none): the #AtkObject associated with @widget
11499 gtk_widget_get_accessible (GtkWidget *widget)
11501 GtkWidgetClass *klass;
11503 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11505 klass = GTK_WIDGET_GET_CLASS (widget);
11507 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11509 return klass->get_accessible (widget);
11513 gtk_widget_real_get_accessible (GtkWidget *widget)
11515 AtkObject* accessible;
11517 accessible = g_object_get_qdata (G_OBJECT (widget),
11518 quark_accessible_object);
11521 GtkWidgetClass *widget_class;
11522 GtkWidgetClassPrivate *priv;
11523 AtkObjectFactory *factory;
11524 AtkRegistry *default_registry;
11526 widget_class = GTK_WIDGET_GET_CLASS (widget);
11527 priv = widget_class->priv;
11529 if (priv->accessible_type == GTK_TYPE_ACCESSIBLE)
11531 default_registry = atk_get_default_registry ();
11532 factory = atk_registry_get_factory (default_registry,
11533 G_TYPE_FROM_INSTANCE (widget));
11535 atk_object_factory_create_accessible (factory,
11536 G_OBJECT (widget));
11538 if (priv->accessible_role != ATK_ROLE_INVALID)
11539 atk_object_set_role (accessible, priv->accessible_role);
11541 g_object_set_qdata (G_OBJECT (widget),
11542 quark_accessible_object,
11547 accessible = g_object_new (priv->accessible_type,
11550 if (priv->accessible_role != ATK_ROLE_INVALID)
11551 atk_object_set_role (accessible, priv->accessible_role);
11553 g_object_set_qdata (G_OBJECT (widget),
11554 quark_accessible_object,
11557 atk_object_initialize (accessible, widget);
11559 /* Set the role again, since we don't want a role set
11560 * in some parent initialize() function to override
11563 if (priv->accessible_role != ATK_ROLE_INVALID)
11564 atk_object_set_role (accessible, priv->accessible_role);
11571 * Initialize a AtkImplementorIface instance's virtual pointers as
11572 * appropriate to this implementor's class (GtkWidget).
11575 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11577 iface->ref_accessible = gtk_widget_ref_accessible;
11581 gtk_widget_ref_accessible (AtkImplementor *implementor)
11583 AtkObject *accessible;
11585 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11587 g_object_ref (accessible);
11592 * Expand flag management
11596 gtk_widget_update_computed_expand (GtkWidget *widget)
11598 GtkWidgetPrivate *priv;
11600 priv = widget->priv;
11602 if (priv->need_compute_expand)
11606 if (priv->hexpand_set)
11611 if (priv->vexpand_set)
11616 /* we don't need to use compute_expand if both expands are
11617 * forced by the app
11619 if (!(priv->hexpand_set && priv->vexpand_set))
11621 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11625 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11626 priv->hexpand_set ? &ignored : &h,
11627 priv->vexpand_set ? &ignored : &v);
11631 priv->need_compute_expand = FALSE;
11632 priv->computed_hexpand = h != FALSE;
11633 priv->computed_vexpand = v != FALSE;
11638 * gtk_widget_queue_compute_expand:
11639 * @widget: a #GtkWidget
11641 * Mark @widget as needing to recompute its expand flags. Call
11642 * this function when setting legacy expand child properties
11643 * on the child of a container.
11645 * See gtk_widget_compute_expand().
11648 gtk_widget_queue_compute_expand (GtkWidget *widget)
11651 gboolean changed_anything;
11653 if (widget->priv->need_compute_expand)
11656 changed_anything = FALSE;
11658 while (parent != NULL)
11660 if (!parent->priv->need_compute_expand)
11662 parent->priv->need_compute_expand = TRUE;
11663 changed_anything = TRUE;
11666 /* Note: if we had an invariant that "if a child needs to
11667 * compute expand, its parents also do" then we could stop going
11668 * up when we got to a parent that already needed to
11669 * compute. However, in general we compute expand lazily (as
11670 * soon as we see something in a subtree that is expand, we know
11671 * we're expanding) and so this invariant does not hold and we
11672 * have to always walk all the way up in case some ancestor
11673 * is not currently need_compute_expand.
11676 parent = parent->priv->parent;
11679 /* recomputing expand always requires
11680 * a relayout as well
11682 if (changed_anything)
11683 gtk_widget_queue_resize (widget);
11687 * gtk_widget_compute_expand:
11688 * @widget: the widget
11689 * @orientation: expand direction
11691 * Computes whether a container should give this widget extra space
11692 * when possible. Containers should check this, rather than
11693 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11695 * This function already checks whether the widget is visible, so
11696 * visibility does not need to be checked separately. Non-visible
11697 * widgets are not expanded.
11699 * The computed expand value uses either the expand setting explicitly
11700 * set on the widget itself, or, if none has been explicitly set,
11701 * the widget may expand if some of its children do.
11703 * Return value: whether widget tree rooted here should be expanded
11706 gtk_widget_compute_expand (GtkWidget *widget,
11707 GtkOrientation orientation)
11709 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11711 /* We never make a widget expand if not even showing. */
11712 if (!gtk_widget_get_visible (widget))
11715 gtk_widget_update_computed_expand (widget);
11717 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11719 return widget->priv->computed_hexpand;
11723 return widget->priv->computed_vexpand;
11728 gtk_widget_set_expand (GtkWidget *widget,
11729 GtkOrientation orientation,
11732 const char *expand_prop;
11733 const char *expand_set_prop;
11735 GtkWidgetPrivate *priv;
11737 g_return_if_fail (GTK_IS_WIDGET (widget));
11739 priv = widget->priv;
11741 expand = expand != FALSE;
11743 was_both = priv->hexpand && priv->vexpand;
11745 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11747 if (priv->hexpand_set &&
11748 priv->hexpand == expand)
11751 priv->hexpand_set = TRUE;
11752 priv->hexpand = expand;
11754 expand_prop = "hexpand";
11755 expand_set_prop = "hexpand-set";
11759 if (priv->vexpand_set &&
11760 priv->vexpand == expand)
11763 priv->vexpand_set = TRUE;
11764 priv->vexpand = expand;
11766 expand_prop = "vexpand";
11767 expand_set_prop = "vexpand-set";
11770 gtk_widget_queue_compute_expand (widget);
11772 g_object_freeze_notify (G_OBJECT (widget));
11773 g_object_notify (G_OBJECT (widget), expand_prop);
11774 g_object_notify (G_OBJECT (widget), expand_set_prop);
11775 if (was_both != (priv->hexpand && priv->vexpand))
11776 g_object_notify (G_OBJECT (widget), "expand");
11777 g_object_thaw_notify (G_OBJECT (widget));
11781 gtk_widget_set_expand_set (GtkWidget *widget,
11782 GtkOrientation orientation,
11785 GtkWidgetPrivate *priv;
11788 priv = widget->priv;
11790 set = set != FALSE;
11792 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11794 if (set == priv->hexpand_set)
11797 priv->hexpand_set = set;
11798 prop = "hexpand-set";
11802 if (set == priv->vexpand_set)
11805 priv->vexpand_set = set;
11806 prop = "vexpand-set";
11809 gtk_widget_queue_compute_expand (widget);
11811 g_object_notify (G_OBJECT (widget), prop);
11815 * gtk_widget_get_hexpand:
11816 * @widget: the widget
11818 * Gets whether the widget would like any available extra horizontal
11819 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11820 * generally receive the extra space. For example, a list or
11821 * scrollable area or document in your window would often be set to
11824 * Containers should use gtk_widget_compute_expand() rather than
11825 * this function, to see whether a widget, or any of its children,
11826 * has the expand flag set. If any child of a widget wants to
11827 * expand, the parent may ask to expand also.
11829 * This function only looks at the widget's own hexpand flag, rather
11830 * than computing whether the entire widget tree rooted at this widget
11833 * Return value: whether hexpand flag is set
11836 gtk_widget_get_hexpand (GtkWidget *widget)
11838 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11840 return widget->priv->hexpand;
11844 * gtk_widget_set_hexpand:
11845 * @widget: the widget
11846 * @expand: whether to expand
11848 * Sets whether the widget would like any available extra horizontal
11849 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11850 * generally receive the extra space. For example, a list or
11851 * scrollable area or document in your window would often be set to
11854 * Call this function to set the expand flag if you would like your
11855 * widget to become larger horizontally when the window has extra
11858 * By default, widgets automatically expand if any of their children
11859 * want to expand. (To see if a widget will automatically expand given
11860 * its current children and state, call gtk_widget_compute_expand(). A
11861 * container can decide how the expandability of children affects the
11862 * expansion of the container by overriding the compute_expand virtual
11863 * method on #GtkWidget.).
11865 * Setting hexpand explicitly with this function will override the
11866 * automatic expand behavior.
11868 * This function forces the widget to expand or not to expand,
11869 * regardless of children. The override occurs because
11870 * gtk_widget_set_hexpand() sets the hexpand-set property (see
11871 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
11872 * value to be used, rather than looking at children and widget state.
11875 gtk_widget_set_hexpand (GtkWidget *widget,
11878 g_return_if_fail (GTK_IS_WIDGET (widget));
11880 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
11884 * gtk_widget_get_hexpand_set:
11885 * @widget: the widget
11887 * Gets whether gtk_widget_set_hexpand() has been used to
11888 * explicitly set the expand flag on this widget.
11890 * If hexpand is set, then it overrides any computed
11891 * expand value based on child widgets. If hexpand is not
11892 * set, then the expand value depends on whether any
11893 * children of the widget would like to expand.
11895 * There are few reasons to use this function, but it's here
11896 * for completeness and consistency.
11898 * Return value: whether hexpand has been explicitly set
11901 gtk_widget_get_hexpand_set (GtkWidget *widget)
11903 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11905 return widget->priv->hexpand_set;
11909 * gtk_widget_set_hexpand_set:
11910 * @widget: the widget
11911 * @set: value for hexpand-set property
11913 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
11916 * The hexpand-set property will be set automatically when you call
11917 * gtk_widget_set_hexpand() to set hexpand, so the most likely
11918 * reason to use this function would be to unset an explicit expand
11921 * If hexpand is set, then it overrides any computed
11922 * expand value based on child widgets. If hexpand is not
11923 * set, then the expand value depends on whether any
11924 * children of the widget would like to expand.
11926 * There are few reasons to use this function, but it's here
11927 * for completeness and consistency.
11930 gtk_widget_set_hexpand_set (GtkWidget *widget,
11933 g_return_if_fail (GTK_IS_WIDGET (widget));
11935 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
11940 * gtk_widget_get_vexpand:
11941 * @widget: the widget
11943 * Gets whether the widget would like any available extra vertical
11946 * See gtk_widget_get_hexpand() for more detail.
11948 * Return value: whether vexpand flag is set
11951 gtk_widget_get_vexpand (GtkWidget *widget)
11953 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11955 return widget->priv->vexpand;
11959 * gtk_widget_set_vexpand:
11960 * @widget: the widget
11961 * @expand: whether to expand
11963 * Sets whether the widget would like any available extra vertical
11966 * See gtk_widget_set_hexpand() for more detail.
11969 gtk_widget_set_vexpand (GtkWidget *widget,
11972 g_return_if_fail (GTK_IS_WIDGET (widget));
11974 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
11978 * gtk_widget_get_vexpand_set:
11979 * @widget: the widget
11981 * Gets whether gtk_widget_set_vexpand() has been used to
11982 * explicitly set the expand flag on this widget.
11984 * See gtk_widget_get_hexpand_set() for more detail.
11986 * Return value: whether vexpand has been explicitly set
11989 gtk_widget_get_vexpand_set (GtkWidget *widget)
11991 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11993 return widget->priv->vexpand_set;
11997 * gtk_widget_set_vexpand_set:
11998 * @widget: the widget
11999 * @set: value for vexpand-set property
12001 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12004 * See gtk_widget_set_hexpand_set() for more detail.
12007 gtk_widget_set_vexpand_set (GtkWidget *widget,
12010 g_return_if_fail (GTK_IS_WIDGET (widget));
12012 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12016 * GtkBuildable implementation
12018 static GQuark quark_builder_has_default = 0;
12019 static GQuark quark_builder_has_focus = 0;
12020 static GQuark quark_builder_atk_relations = 0;
12021 static GQuark quark_builder_set_name = 0;
12024 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12026 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12027 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12028 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12029 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12031 iface->set_name = gtk_widget_buildable_set_name;
12032 iface->get_name = gtk_widget_buildable_get_name;
12033 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12034 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12035 iface->parser_finished = gtk_widget_buildable_parser_finished;
12036 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12037 iface->custom_finished = gtk_widget_buildable_custom_finished;
12041 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12044 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12045 g_strdup (name), g_free);
12048 static const gchar *
12049 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12051 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12055 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12056 GtkBuilder *builder,
12057 const gchar *childname)
12059 if (strcmp (childname, "accessible") == 0)
12060 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12066 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12067 GtkBuilder *builder,
12069 const GValue *value)
12071 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12072 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12073 GINT_TO_POINTER (TRUE));
12074 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12075 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12076 GINT_TO_POINTER (TRUE));
12078 g_object_set_property (G_OBJECT (buildable), name, value);
12083 gchar *action_name;
12084 GString *description;
12086 gboolean translatable;
12096 free_action (AtkActionData *data, gpointer user_data)
12098 g_free (data->action_name);
12099 g_string_free (data->description, TRUE);
12100 g_free (data->context);
12101 g_slice_free (AtkActionData, data);
12105 free_relation (AtkRelationData *data, gpointer user_data)
12107 g_free (data->target);
12108 g_free (data->type);
12109 g_slice_free (AtkRelationData, data);
12113 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12114 GtkBuilder *builder)
12116 GSList *atk_relations;
12118 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12119 gtk_widget_grab_default (GTK_WIDGET (buildable));
12120 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12121 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12123 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12124 quark_builder_atk_relations);
12127 AtkObject *accessible;
12128 AtkRelationSet *relation_set;
12131 AtkRelationType relation_type;
12132 AtkObject *target_accessible;
12134 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12135 relation_set = atk_object_ref_relation_set (accessible);
12137 for (l = atk_relations; l; l = l->next)
12139 AtkRelationData *relation = (AtkRelationData*)l->data;
12141 target = gtk_builder_get_object (builder, relation->target);
12144 g_warning ("Target object %s in <relation> does not exist",
12148 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12149 g_assert (target_accessible != NULL);
12151 relation_type = atk_relation_type_for_name (relation->type);
12152 if (relation_type == ATK_RELATION_NULL)
12154 g_warning ("<relation> type %s not found",
12158 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12159 target_accessible);
12161 g_object_unref (relation_set);
12163 g_slist_free_full (atk_relations, (GDestroyNotify) free_relation);
12164 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12173 } AccessibilitySubParserData;
12176 accessibility_start_element (GMarkupParseContext *context,
12177 const gchar *element_name,
12178 const gchar **names,
12179 const gchar **values,
12180 gpointer user_data,
12183 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12185 gint line_number, char_number;
12187 if (strcmp (element_name, "relation") == 0)
12189 gchar *target = NULL;
12190 gchar *type = NULL;
12191 AtkRelationData *relation;
12193 for (i = 0; names[i]; i++)
12195 if (strcmp (names[i], "target") == 0)
12196 target = g_strdup (values[i]);
12197 else if (strcmp (names[i], "type") == 0)
12198 type = g_strdup (values[i]);
12201 g_markup_parse_context_get_position (context,
12204 g_set_error (error,
12206 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12207 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12209 line_number, char_number, names[i], "relation");
12216 if (!target || !type)
12218 g_markup_parse_context_get_position (context,
12221 g_set_error (error,
12223 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12224 "%s:%d:%d <%s> requires attribute \"%s\"",
12226 line_number, char_number, "relation",
12227 type ? "target" : "type");
12233 relation = g_slice_new (AtkRelationData);
12234 relation->target = target;
12235 relation->type = type;
12237 data->relations = g_slist_prepend (data->relations, relation);
12239 else if (strcmp (element_name, "action") == 0)
12241 const gchar *action_name = NULL;
12242 const gchar *description = NULL;
12243 const gchar *msg_context = NULL;
12244 gboolean translatable = FALSE;
12245 AtkActionData *action;
12247 for (i = 0; names[i]; i++)
12249 if (strcmp (names[i], "action_name") == 0)
12250 action_name = values[i];
12251 else if (strcmp (names[i], "description") == 0)
12252 description = values[i];
12253 else if (strcmp (names[i], "translatable") == 0)
12255 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12258 else if (strcmp (names[i], "comments") == 0)
12260 /* do nothing, comments are for translators */
12262 else if (strcmp (names[i], "context") == 0)
12263 msg_context = values[i];
12266 g_markup_parse_context_get_position (context,
12269 g_set_error (error,
12271 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12272 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12274 line_number, char_number, names[i], "action");
12281 g_markup_parse_context_get_position (context,
12284 g_set_error (error,
12286 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12287 "%s:%d:%d <%s> requires attribute \"%s\"",
12289 line_number, char_number, "action",
12294 action = g_slice_new (AtkActionData);
12295 action->action_name = g_strdup (action_name);
12296 action->description = g_string_new (description);
12297 action->context = g_strdup (msg_context);
12298 action->translatable = translatable;
12300 data->actions = g_slist_prepend (data->actions, action);
12302 else if (strcmp (element_name, "accessibility") == 0)
12305 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12309 accessibility_text (GMarkupParseContext *context,
12312 gpointer user_data,
12315 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12317 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12319 AtkActionData *action = data->actions->data;
12321 g_string_append_len (action->description, text, text_len);
12325 static const GMarkupParser accessibility_parser =
12327 accessibility_start_element,
12329 accessibility_text,
12338 } AccelGroupParserData;
12341 accel_group_start_element (GMarkupParseContext *context,
12342 const gchar *element_name,
12343 const gchar **names,
12344 const gchar **values,
12345 gpointer user_data,
12350 guint modifiers = 0;
12351 gchar *signal = NULL;
12352 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12354 for (i = 0; names[i]; i++)
12356 if (strcmp (names[i], "key") == 0)
12357 key = gdk_keyval_from_name (values[i]);
12358 else if (strcmp (names[i], "modifiers") == 0)
12360 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12366 else if (strcmp (names[i], "signal") == 0)
12367 signal = g_strdup (values[i]);
12370 if (key == 0 || signal == NULL)
12372 g_warning ("<accelerator> requires key and signal attributes");
12375 parser_data->key = key;
12376 parser_data->modifiers = modifiers;
12377 parser_data->signal = signal;
12380 static const GMarkupParser accel_group_parser =
12382 accel_group_start_element,
12391 style_start_element (GMarkupParseContext *context,
12392 const gchar *element_name,
12393 const gchar **names,
12394 const gchar **values,
12395 gpointer user_data,
12398 StyleParserData *style_data = (StyleParserData *)user_data;
12401 if (strcmp (element_name, "class") == 0)
12403 if (g_markup_collect_attributes (element_name,
12407 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12408 G_MARKUP_COLLECT_INVALID))
12410 style_data->classes = g_slist_append (style_data->classes, class_name);
12413 else if (strcmp (element_name, "style") == 0)
12416 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12419 static const GMarkupParser style_parser =
12421 style_start_element,
12425 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12426 GtkBuilder *builder,
12428 const gchar *tagname,
12429 GMarkupParser *parser,
12432 g_assert (buildable);
12434 if (strcmp (tagname, "accelerator") == 0)
12436 AccelGroupParserData *parser_data;
12438 parser_data = g_slice_new0 (AccelGroupParserData);
12439 parser_data->object = g_object_ref (buildable);
12440 *parser = accel_group_parser;
12441 *data = parser_data;
12444 if (strcmp (tagname, "accessibility") == 0)
12446 AccessibilitySubParserData *parser_data;
12448 parser_data = g_slice_new0 (AccessibilitySubParserData);
12449 *parser = accessibility_parser;
12450 *data = parser_data;
12453 if (strcmp (tagname, "style") == 0)
12455 StyleParserData *parser_data;
12457 parser_data = g_slice_new0 (StyleParserData);
12458 *parser = style_parser;
12459 *data = parser_data;
12467 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12468 GtkWidget *toplevel,
12469 gpointer user_data)
12471 AccelGroupParserData *accel_data;
12472 GSList *accel_groups;
12473 GtkAccelGroup *accel_group;
12475 g_return_if_fail (GTK_IS_WIDGET (widget));
12476 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12477 g_return_if_fail (user_data != NULL);
12479 accel_data = (AccelGroupParserData*)user_data;
12480 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12481 if (g_slist_length (accel_groups) == 0)
12483 accel_group = gtk_accel_group_new ();
12484 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12488 g_assert (g_slist_length (accel_groups) == 1);
12489 accel_group = g_slist_nth_data (accel_groups, 0);
12492 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12493 accel_data->signal,
12496 accel_data->modifiers,
12497 GTK_ACCEL_VISIBLE);
12499 g_object_unref (accel_data->object);
12500 g_free (accel_data->signal);
12501 g_slice_free (AccelGroupParserData, accel_data);
12505 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12506 GtkBuilder *builder,
12508 const gchar *tagname,
12509 gpointer user_data)
12511 if (strcmp (tagname, "accelerator") == 0)
12513 AccelGroupParserData *accel_data;
12514 GtkWidget *toplevel;
12516 accel_data = (AccelGroupParserData*)user_data;
12517 g_assert (accel_data->object);
12519 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12521 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12523 else if (strcmp (tagname, "accessibility") == 0)
12525 AccessibilitySubParserData *a11y_data;
12527 a11y_data = (AccessibilitySubParserData*)user_data;
12529 if (a11y_data->actions)
12531 AtkObject *accessible;
12536 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12538 if (ATK_IS_ACTION (accessible))
12540 action = ATK_ACTION (accessible);
12541 n_actions = atk_action_get_n_actions (action);
12543 for (l = a11y_data->actions; l; l = l->next)
12545 AtkActionData *action_data = (AtkActionData*)l->data;
12547 for (i = 0; i < n_actions; i++)
12548 if (strcmp (atk_action_get_name (action, i),
12549 action_data->action_name) == 0)
12554 gchar *description;
12556 if (action_data->translatable && action_data->description->len)
12557 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12558 action_data->context,
12559 action_data->description->str);
12561 description = action_data->description->str;
12563 atk_action_set_description (action, i, description);
12568 g_warning ("accessibility action on a widget that does not implement AtkAction");
12570 g_slist_free_full (a11y_data->actions, (GDestroyNotify) free_action);
12573 if (a11y_data->relations)
12574 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12575 a11y_data->relations);
12577 g_slice_free (AccessibilitySubParserData, a11y_data);
12579 else if (strcmp (tagname, "style") == 0)
12581 StyleParserData *style_data = (StyleParserData *)user_data;
12582 GtkStyleContext *context;
12585 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
12587 for (l = style_data->classes; l; l = l->next)
12588 gtk_style_context_add_class (context, (const gchar *)l->data);
12590 gtk_widget_reset_style (GTK_WIDGET (buildable));
12592 g_slist_free_full (style_data->classes, g_free);
12593 g_slice_free (StyleParserData, style_data);
12597 static GtkSizeRequestMode
12598 gtk_widget_real_get_request_mode (GtkWidget *widget)
12600 /* By default widgets dont trade size at all. */
12601 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
12605 gtk_widget_real_get_width (GtkWidget *widget,
12606 gint *minimum_size,
12607 gint *natural_size)
12617 gtk_widget_real_get_height (GtkWidget *widget,
12618 gint *minimum_size,
12619 gint *natural_size)
12629 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12631 gint *minimum_height,
12632 gint *natural_height)
12634 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12638 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12640 gint *minimum_width,
12641 gint *natural_width)
12643 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12647 * gtk_widget_get_halign:
12648 * @widget: a #GtkWidget
12650 * Gets the value of the #GtkWidget:halign property.
12652 * Returns: the horizontal alignment of @widget
12655 gtk_widget_get_halign (GtkWidget *widget)
12657 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12658 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12662 * gtk_widget_set_halign:
12663 * @widget: a #GtkWidget
12664 * @align: the horizontal alignment
12666 * Sets the horizontal alignment of @widget.
12667 * See the #GtkWidget:halign property.
12670 gtk_widget_set_halign (GtkWidget *widget,
12673 GtkWidgetAuxInfo *aux_info;
12675 g_return_if_fail (GTK_IS_WIDGET (widget));
12677 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12679 if (aux_info->halign == align)
12682 aux_info->halign = align;
12683 gtk_widget_queue_resize (widget);
12684 g_object_notify (G_OBJECT (widget), "halign");
12688 * gtk_widget_get_valign:
12689 * @widget: a #GtkWidget
12691 * Gets the value of the #GtkWidget:valign property.
12693 * Returns: the vertical alignment of @widget
12696 gtk_widget_get_valign (GtkWidget *widget)
12698 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12699 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12703 * gtk_widget_set_valign:
12704 * @widget: a #GtkWidget
12705 * @align: the vertical alignment
12707 * Sets the vertical alignment of @widget.
12708 * See the #GtkWidget:valign property.
12711 gtk_widget_set_valign (GtkWidget *widget,
12714 GtkWidgetAuxInfo *aux_info;
12716 g_return_if_fail (GTK_IS_WIDGET (widget));
12718 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12720 if (aux_info->valign == align)
12723 aux_info->valign = align;
12724 gtk_widget_queue_resize (widget);
12725 g_object_notify (G_OBJECT (widget), "valign");
12729 * gtk_widget_get_margin_left:
12730 * @widget: a #GtkWidget
12732 * Gets the value of the #GtkWidget:margin-left property.
12734 * Returns: The left margin of @widget
12739 gtk_widget_get_margin_left (GtkWidget *widget)
12741 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12743 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12747 * gtk_widget_set_margin_left:
12748 * @widget: a #GtkWidget
12749 * @margin: the left margin
12751 * Sets the left margin of @widget.
12752 * See the #GtkWidget:margin-left property.
12757 gtk_widget_set_margin_left (GtkWidget *widget,
12760 GtkWidgetAuxInfo *aux_info;
12762 g_return_if_fail (GTK_IS_WIDGET (widget));
12763 g_return_if_fail (margin <= G_MAXINT16);
12765 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12767 if (aux_info->margin.left == margin)
12770 aux_info->margin.left = margin;
12771 gtk_widget_queue_resize (widget);
12772 g_object_notify (G_OBJECT (widget), "margin-left");
12776 * gtk_widget_get_margin_right:
12777 * @widget: a #GtkWidget
12779 * Gets the value of the #GtkWidget:margin-right property.
12781 * Returns: The right margin of @widget
12786 gtk_widget_get_margin_right (GtkWidget *widget)
12788 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12790 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12794 * gtk_widget_set_margin_right:
12795 * @widget: a #GtkWidget
12796 * @margin: the right margin
12798 * Sets the right margin of @widget.
12799 * See the #GtkWidget:margin-right property.
12804 gtk_widget_set_margin_right (GtkWidget *widget,
12807 GtkWidgetAuxInfo *aux_info;
12809 g_return_if_fail (GTK_IS_WIDGET (widget));
12810 g_return_if_fail (margin <= G_MAXINT16);
12812 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12814 if (aux_info->margin.right == margin)
12817 aux_info->margin.right = margin;
12818 gtk_widget_queue_resize (widget);
12819 g_object_notify (G_OBJECT (widget), "margin-right");
12823 * gtk_widget_get_margin_top:
12824 * @widget: a #GtkWidget
12826 * Gets the value of the #GtkWidget:margin-top property.
12828 * Returns: The top margin of @widget
12833 gtk_widget_get_margin_top (GtkWidget *widget)
12835 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12837 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12841 * gtk_widget_set_margin_top:
12842 * @widget: a #GtkWidget
12843 * @margin: the top margin
12845 * Sets the top margin of @widget.
12846 * See the #GtkWidget:margin-top property.
12851 gtk_widget_set_margin_top (GtkWidget *widget,
12854 GtkWidgetAuxInfo *aux_info;
12856 g_return_if_fail (GTK_IS_WIDGET (widget));
12857 g_return_if_fail (margin <= G_MAXINT16);
12859 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12861 if (aux_info->margin.top == margin)
12864 aux_info->margin.top = margin;
12865 gtk_widget_queue_resize (widget);
12866 g_object_notify (G_OBJECT (widget), "margin-top");
12870 * gtk_widget_get_margin_bottom:
12871 * @widget: a #GtkWidget
12873 * Gets the value of the #GtkWidget:margin-bottom property.
12875 * Returns: The bottom margin of @widget
12880 gtk_widget_get_margin_bottom (GtkWidget *widget)
12882 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12884 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
12888 * gtk_widget_set_margin_bottom:
12889 * @widget: a #GtkWidget
12890 * @margin: the bottom margin
12892 * Sets the bottom margin of @widget.
12893 * See the #GtkWidget:margin-bottom property.
12898 gtk_widget_set_margin_bottom (GtkWidget *widget,
12901 GtkWidgetAuxInfo *aux_info;
12903 g_return_if_fail (GTK_IS_WIDGET (widget));
12904 g_return_if_fail (margin <= G_MAXINT16);
12906 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12908 if (aux_info->margin.bottom == margin)
12911 aux_info->margin.bottom = margin;
12912 gtk_widget_queue_resize (widget);
12913 g_object_notify (G_OBJECT (widget), "margin-bottom");
12917 * gtk_widget_get_clipboard:
12918 * @widget: a #GtkWidget
12919 * @selection: a #GdkAtom which identifies the clipboard
12920 * to use. %GDK_SELECTION_CLIPBOARD gives the
12921 * default clipboard. Another common value
12922 * is %GDK_SELECTION_PRIMARY, which gives
12923 * the primary X selection.
12925 * Returns the clipboard object for the given selection to
12926 * be used with @widget. @widget must have a #GdkDisplay
12927 * associated with it, so must be attached to a toplevel
12930 * Return value: (transfer none): the appropriate clipboard object. If no
12931 * clipboard already exists, a new one will
12932 * be created. Once a clipboard object has
12933 * been created, it is persistent for all time.
12938 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
12940 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12941 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
12943 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
12948 * gtk_widget_list_mnemonic_labels:
12949 * @widget: a #GtkWidget
12951 * Returns a newly allocated list of the widgets, normally labels, for
12952 * which this widget is the target of a mnemonic (see for example,
12953 * gtk_label_set_mnemonic_widget()).
12955 * The widgets in the list are not individually referenced. If you
12956 * want to iterate through the list and perform actions involving
12957 * callbacks that might destroy the widgets, you
12958 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
12959 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
12960 * widgets afterwards.
12962 * Return value: (element-type GtkWidget) (transfer container): the list of
12963 * mnemonic labels; free this list
12964 * with g_list_free() when you are done with it.
12969 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
12971 GList *list = NULL;
12974 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12976 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
12977 list = g_list_prepend (list, l->data);
12983 * gtk_widget_add_mnemonic_label:
12984 * @widget: a #GtkWidget
12985 * @label: a #GtkWidget that acts as a mnemonic label for @widget
12987 * Adds a widget to the list of mnemonic labels for
12988 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
12989 * list of mnemonic labels for the widget is cleared when the
12990 * widget is destroyed, so the caller must make sure to update
12991 * its internal state at this point as well, by using a connection
12992 * to the #GtkWidget::destroy signal or a weak notifier.
12997 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13000 GSList *old_list, *new_list;
13002 g_return_if_fail (GTK_IS_WIDGET (widget));
13003 g_return_if_fail (GTK_IS_WIDGET (label));
13005 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13006 new_list = g_slist_prepend (old_list, label);
13008 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13009 new_list, (GDestroyNotify) g_slist_free);
13013 * gtk_widget_remove_mnemonic_label:
13014 * @widget: a #GtkWidget
13015 * @label: a #GtkWidget that was previously set as a mnemnic label for
13016 * @widget with gtk_widget_add_mnemonic_label().
13018 * Removes a widget from the list of mnemonic labels for
13019 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13020 * must have previously been added to the list with
13021 * gtk_widget_add_mnemonic_label().
13026 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13029 GSList *old_list, *new_list;
13031 g_return_if_fail (GTK_IS_WIDGET (widget));
13032 g_return_if_fail (GTK_IS_WIDGET (label));
13034 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13035 new_list = g_slist_remove (old_list, label);
13038 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13039 new_list, (GDestroyNotify) g_slist_free);
13043 * gtk_widget_get_no_show_all:
13044 * @widget: a #GtkWidget
13046 * Returns the current value of the #GtkWidget:no-show-all property,
13047 * which determines whether calls to gtk_widget_show_all()
13048 * will affect this widget.
13050 * Return value: the current value of the "no-show-all" property.
13055 gtk_widget_get_no_show_all (GtkWidget *widget)
13057 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13059 return widget->priv->no_show_all;
13063 * gtk_widget_set_no_show_all:
13064 * @widget: a #GtkWidget
13065 * @no_show_all: the new value for the "no-show-all" property
13067 * Sets the #GtkWidget:no-show-all property, which determines whether
13068 * calls to gtk_widget_show_all() will affect this widget.
13070 * This is mostly for use in constructing widget hierarchies with externally
13071 * controlled visibility, see #GtkUIManager.
13076 gtk_widget_set_no_show_all (GtkWidget *widget,
13077 gboolean no_show_all)
13079 g_return_if_fail (GTK_IS_WIDGET (widget));
13081 no_show_all = (no_show_all != FALSE);
13083 if (widget->priv->no_show_all != no_show_all)
13085 widget->priv->no_show_all = no_show_all;
13087 g_object_notify (G_OBJECT (widget), "no-show-all");
13093 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13094 gboolean has_tooltip,
13097 GtkWidgetPrivate *priv = widget->priv;
13098 gboolean priv_has_tooltip;
13100 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13101 quark_has_tooltip));
13103 if (priv_has_tooltip != has_tooltip || force)
13105 priv_has_tooltip = has_tooltip;
13107 if (priv_has_tooltip)
13109 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13110 gdk_window_set_events (priv->window,
13111 gdk_window_get_events (priv->window) |
13112 GDK_LEAVE_NOTIFY_MASK |
13113 GDK_POINTER_MOTION_MASK |
13114 GDK_POINTER_MOTION_HINT_MASK);
13116 if (gtk_widget_get_has_window (widget))
13117 gtk_widget_add_events (widget,
13118 GDK_LEAVE_NOTIFY_MASK |
13119 GDK_POINTER_MOTION_MASK |
13120 GDK_POINTER_MOTION_HINT_MASK);
13123 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13124 GUINT_TO_POINTER (priv_has_tooltip));
13129 * gtk_widget_set_tooltip_window:
13130 * @widget: a #GtkWidget
13131 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13133 * Replaces the default, usually yellow, window used for displaying
13134 * tooltips with @custom_window. GTK+ will take care of showing and
13135 * hiding @custom_window at the right moment, to behave likewise as
13136 * the default tooltip window. If @custom_window is %NULL, the default
13137 * tooltip window will be used.
13139 * If the custom window should have the default theming it needs to
13140 * have the name "gtk-tooltip", see gtk_widget_set_name().
13145 gtk_widget_set_tooltip_window (GtkWidget *widget,
13146 GtkWindow *custom_window)
13148 gboolean has_tooltip;
13149 gchar *tooltip_markup;
13151 g_return_if_fail (GTK_IS_WIDGET (widget));
13152 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13154 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13157 g_object_ref (custom_window);
13159 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13160 custom_window, g_object_unref);
13162 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13163 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13165 if (has_tooltip && gtk_widget_get_visible (widget))
13166 gtk_widget_queue_tooltip_query (widget);
13170 * gtk_widget_get_tooltip_window:
13171 * @widget: a #GtkWidget
13173 * Returns the #GtkWindow of the current tooltip. This can be the
13174 * GtkWindow created by default, or the custom tooltip window set
13175 * using gtk_widget_set_tooltip_window().
13177 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13182 gtk_widget_get_tooltip_window (GtkWidget *widget)
13184 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13186 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13190 * gtk_widget_trigger_tooltip_query:
13191 * @widget: a #GtkWidget
13193 * Triggers a tooltip query on the display where the toplevel of @widget
13194 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13200 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13202 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13205 static guint tooltip_query_id;
13206 static GSList *tooltip_query_displays;
13209 tooltip_query_idle (gpointer data)
13211 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13212 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13213 g_slist_free (tooltip_query_displays);
13215 tooltip_query_displays = NULL;
13216 tooltip_query_id = 0;
13222 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13224 GdkDisplay *display;
13226 display = gtk_widget_get_display (widget);
13228 if (!g_slist_find (tooltip_query_displays, display))
13229 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13231 if (tooltip_query_id == 0)
13232 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13236 * gtk_widget_set_tooltip_text:
13237 * @widget: a #GtkWidget
13238 * @text: the contents of the tooltip for @widget
13240 * Sets @text as the contents of the tooltip. This function will take
13241 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13242 * handler for the #GtkWidget::query-tooltip signal.
13244 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13249 gtk_widget_set_tooltip_text (GtkWidget *widget,
13252 g_return_if_fail (GTK_IS_WIDGET (widget));
13254 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13258 * gtk_widget_get_tooltip_text:
13259 * @widget: a #GtkWidget
13261 * Gets the contents of the tooltip for @widget.
13263 * Return value: the tooltip text, or %NULL. You should free the
13264 * returned string with g_free() when done.
13269 gtk_widget_get_tooltip_text (GtkWidget *widget)
13271 gchar *text = NULL;
13273 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13275 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13281 * gtk_widget_set_tooltip_markup:
13282 * @widget: a #GtkWidget
13283 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13285 * Sets @markup as the contents of the tooltip, which is marked up with
13286 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13288 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13289 * and of the default handler for the #GtkWidget::query-tooltip signal.
13291 * See also the #GtkWidget:tooltip-markup property and
13292 * gtk_tooltip_set_markup().
13297 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13298 const gchar *markup)
13300 g_return_if_fail (GTK_IS_WIDGET (widget));
13302 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13306 * gtk_widget_get_tooltip_markup:
13307 * @widget: a #GtkWidget
13309 * Gets the contents of the tooltip for @widget.
13311 * Return value: the tooltip text, or %NULL. You should free the
13312 * returned string with g_free() when done.
13317 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13319 gchar *text = NULL;
13321 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13323 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13329 * gtk_widget_set_has_tooltip:
13330 * @widget: a #GtkWidget
13331 * @has_tooltip: whether or not @widget has a tooltip.
13333 * Sets the has-tooltip property on @widget to @has_tooltip. See
13334 * #GtkWidget:has-tooltip for more information.
13339 gtk_widget_set_has_tooltip (GtkWidget *widget,
13340 gboolean has_tooltip)
13342 g_return_if_fail (GTK_IS_WIDGET (widget));
13344 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13348 * gtk_widget_get_has_tooltip:
13349 * @widget: a #GtkWidget
13351 * Returns the current value of the has-tooltip property. See
13352 * #GtkWidget:has-tooltip for more information.
13354 * Return value: current value of has-tooltip on @widget.
13359 gtk_widget_get_has_tooltip (GtkWidget *widget)
13361 gboolean has_tooltip = FALSE;
13363 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13365 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13367 return has_tooltip;
13371 * gtk_widget_get_allocation:
13372 * @widget: a #GtkWidget
13373 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13375 * Retrieves the widget's allocation.
13377 * Note, when implementing a #GtkContainer: a widget's allocation will
13378 * be its "adjusted" allocation, that is, the widget's parent
13379 * container typically calls gtk_widget_size_allocate() with an
13380 * allocation, and that allocation is then adjusted (to handle margin
13381 * and alignment for example) before assignment to the widget.
13382 * gtk_widget_get_allocation() returns the adjusted allocation that
13383 * was actually assigned to the widget. The adjusted allocation is
13384 * guaranteed to be completely contained within the
13385 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13386 * is guaranteed that its children stay inside the assigned bounds,
13387 * but not that they have exactly the bounds the container assigned.
13388 * There is no way to get the original allocation assigned by
13389 * gtk_widget_size_allocate(), since it isn't stored; if a container
13390 * implementation needs that information it will have to track it itself.
13395 gtk_widget_get_allocation (GtkWidget *widget,
13396 GtkAllocation *allocation)
13398 GtkWidgetPrivate *priv;
13400 g_return_if_fail (GTK_IS_WIDGET (widget));
13401 g_return_if_fail (allocation != NULL);
13403 priv = widget->priv;
13405 *allocation = priv->allocation;
13409 * gtk_widget_set_allocation:
13410 * @widget: a #GtkWidget
13411 * @allocation: a pointer to a #GtkAllocation to copy from
13413 * Sets the widget's allocation. This should not be used
13414 * directly, but from within a widget's size_allocate method.
13416 * The allocation set should be the "adjusted" or actual
13417 * allocation. If you're implementing a #GtkContainer, you want to use
13418 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13419 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13420 * allocation inside gtk_widget_size_allocate() to create an adjusted
13426 gtk_widget_set_allocation (GtkWidget *widget,
13427 const GtkAllocation *allocation)
13429 GtkWidgetPrivate *priv;
13431 g_return_if_fail (GTK_IS_WIDGET (widget));
13432 g_return_if_fail (allocation != NULL);
13434 priv = widget->priv;
13436 priv->allocation = *allocation;
13440 * gtk_widget_get_allocated_width:
13441 * @widget: the widget to query
13443 * Returns the width that has currently been allocated to @widget.
13444 * This function is intended to be used when implementing handlers
13445 * for the #GtkWidget::draw function.
13447 * Returns: the width of the @widget
13450 gtk_widget_get_allocated_width (GtkWidget *widget)
13452 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13454 return widget->priv->allocation.width;
13458 * gtk_widget_get_allocated_height:
13459 * @widget: the widget to query
13461 * Returns the height that has currently been allocated to @widget.
13462 * This function is intended to be used when implementing handlers
13463 * for the #GtkWidget::draw function.
13465 * Returns: the height of the @widget
13468 gtk_widget_get_allocated_height (GtkWidget *widget)
13470 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13472 return widget->priv->allocation.height;
13476 * gtk_widget_get_requisition:
13477 * @widget: a #GtkWidget
13478 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13480 * Retrieves the widget's requisition.
13482 * This function should only be used by widget implementations in
13483 * order to figure whether the widget's requisition has actually
13484 * changed after some internal state change (so that they can call
13485 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13487 * Normally, gtk_widget_size_request() should be used.
13491 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13492 * removed, If you need to cache sizes across requests and allocations,
13493 * add an explicit cache to the widget in question instead.
13496 gtk_widget_get_requisition (GtkWidget *widget,
13497 GtkRequisition *requisition)
13499 g_return_if_fail (GTK_IS_WIDGET (widget));
13500 g_return_if_fail (requisition != NULL);
13502 gtk_widget_get_preferred_size (widget, requisition, NULL);
13506 * gtk_widget_set_window:
13507 * @widget: a #GtkWidget
13508 * @window: (transfer full): a #GdkWindow
13510 * Sets a widget's window. This function should only be used in a
13511 * widget's #GtkWidget::realize implementation. The %window passed is
13512 * usually either new window created with gdk_window_new(), or the
13513 * window of its parent widget as returned by
13514 * gtk_widget_get_parent_window().
13516 * Widgets must indicate whether they will create their own #GdkWindow
13517 * by calling gtk_widget_set_has_window(). This is usually done in the
13518 * widget's init() function.
13520 * <note><para>This function does not add any reference to @window.</para></note>
13525 gtk_widget_set_window (GtkWidget *widget,
13528 GtkWidgetPrivate *priv;
13530 g_return_if_fail (GTK_IS_WIDGET (widget));
13531 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13533 priv = widget->priv;
13535 if (priv->window != window)
13537 priv->window = window;
13538 g_object_notify (G_OBJECT (widget), "window");
13543 * gtk_widget_get_window:
13544 * @widget: a #GtkWidget
13546 * Returns the widget's window if it is realized, %NULL otherwise
13548 * Return value: (transfer none): @widget's window.
13553 gtk_widget_get_window (GtkWidget *widget)
13555 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13557 return widget->priv->window;
13561 * gtk_widget_get_support_multidevice:
13562 * @widget: a #GtkWidget
13564 * Returns %TRUE if @widget is multiple pointer aware. See
13565 * gtk_widget_set_support_multidevice() for more information.
13567 * Returns: %TRUE if @widget is multidevice aware.
13570 gtk_widget_get_support_multidevice (GtkWidget *widget)
13572 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13574 return widget->priv->multidevice;
13578 * gtk_widget_set_support_multidevice:
13579 * @widget: a #GtkWidget
13580 * @support_multidevice: %TRUE to support input from multiple devices.
13582 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13583 * @widget will start receiving multiple, per device enter/leave events. Note
13584 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13585 * gdk_window_set_support_multidevice() will have to be called manually on them.
13590 gtk_widget_set_support_multidevice (GtkWidget *widget,
13591 gboolean support_multidevice)
13593 GtkWidgetPrivate *priv;
13595 g_return_if_fail (GTK_IS_WIDGET (widget));
13597 priv = widget->priv;
13598 priv->multidevice = (support_multidevice == TRUE);
13600 if (gtk_widget_get_realized (widget))
13601 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13605 _gtk_widget_set_has_focus (GtkWidget *widget,
13606 gboolean has_focus)
13608 widget->priv->has_focus = has_focus;
13611 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
13613 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
13617 * gtk_widget_send_focus_change:
13618 * @widget: a #GtkWidget
13619 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13621 * Sends the focus change @event to @widget
13623 * This function is not meant to be used by applications. The only time it
13624 * should be used is when it is necessary for a #GtkWidget to assign focus
13625 * to a widget that is semantically owned by the first widget even though
13626 * it's not a direct child - for instance, a search entry in a floating
13627 * window similar to the quick search in #GtkTreeView.
13629 * An example of its usage is:
13632 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13634 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13635 * fevent->focus_change.in = TRUE;
13636 * fevent->focus_change.window = gtk_widget_get_window (widget);
13637 * if (fevent->focus_change.window != NULL)
13638 * g_object_ref (fevent->focus_change.window);
13640 * gtk_widget_send_focus_change (widget, fevent);
13642 * gdk_event_free (event);
13645 * Return value: the return value from the event signal emission: %TRUE
13646 * if the event was handled, and %FALSE otherwise
13651 gtk_widget_send_focus_change (GtkWidget *widget,
13656 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13657 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13659 g_object_ref (widget);
13661 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13663 res = gtk_widget_event (widget, event);
13665 g_object_notify (G_OBJECT (widget), "has-focus");
13667 g_object_unref (widget);
13673 * gtk_widget_in_destruction:
13674 * @widget: a #GtkWidget
13676 * Returns whether the widget is currently being destroyed.
13677 * This information can sometimes be used to avoid doing
13678 * unnecessary work.
13680 * Returns: %TRUE if @widget is being destroyed
13683 gtk_widget_in_destruction (GtkWidget *widget)
13685 return widget->priv->in_destruction;
13689 _gtk_widget_get_resize_pending (GtkWidget *widget)
13691 return widget->priv->resize_pending;
13695 _gtk_widget_set_resize_pending (GtkWidget *widget,
13696 gboolean resize_pending)
13698 widget->priv->resize_pending = resize_pending;
13702 _gtk_widget_get_in_reparent (GtkWidget *widget)
13704 return widget->priv->in_reparent;
13708 _gtk_widget_set_in_reparent (GtkWidget *widget,
13709 gboolean in_reparent)
13711 widget->priv->in_reparent = in_reparent;
13715 _gtk_widget_get_anchored (GtkWidget *widget)
13717 return widget->priv->anchored;
13721 _gtk_widget_set_anchored (GtkWidget *widget,
13724 widget->priv->anchored = anchored;
13728 _gtk_widget_get_shadowed (GtkWidget *widget)
13730 return widget->priv->shadowed;
13734 _gtk_widget_set_shadowed (GtkWidget *widget,
13737 widget->priv->shadowed = shadowed;
13741 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13743 return widget->priv->alloc_needed;
13747 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13748 gboolean alloc_needed)
13750 widget->priv->alloc_needed = alloc_needed;
13754 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13756 return widget->priv->width_request_needed;
13760 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13761 gboolean width_request_needed)
13763 widget->priv->width_request_needed = width_request_needed;
13767 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13769 return widget->priv->height_request_needed;
13773 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13774 gboolean height_request_needed)
13776 widget->priv->height_request_needed = height_request_needed;
13780 _gtk_widget_get_sizegroup_visited (GtkWidget *widget)
13782 return widget->priv->sizegroup_visited;
13786 _gtk_widget_set_sizegroup_visited (GtkWidget *widget,
13789 widget->priv->sizegroup_visited = visited;
13793 _gtk_widget_get_sizegroup_bumping (GtkWidget *widget)
13795 return widget->priv->sizegroup_bumping;
13799 _gtk_widget_set_sizegroup_bumping (GtkWidget *widget,
13802 widget->priv->sizegroup_bumping = bumping;
13806 _gtk_widget_add_sizegroup (GtkWidget *widget,
13811 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13812 groups = g_slist_prepend (groups, group);
13813 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13815 widget->priv->have_size_groups = TRUE;
13819 _gtk_widget_remove_sizegroup (GtkWidget *widget,
13824 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13825 groups = g_slist_remove (groups, group);
13826 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13828 widget->priv->have_size_groups = groups != NULL;
13832 _gtk_widget_get_sizegroups (GtkWidget *widget)
13834 if (widget->priv->have_size_groups)
13835 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13841 _gtk_widget_add_attached_window (GtkWidget *widget,
13844 widget->priv->attached_windows = g_list_prepend (widget->priv->attached_windows, window);
13848 _gtk_widget_remove_attached_window (GtkWidget *widget,
13851 widget->priv->attached_windows = g_list_remove (widget->priv->attached_windows, window);
13855 * gtk_widget_path_append_for_widget:
13856 * @path: a widget path
13857 * @widget: the widget to append to the widget path
13859 * Appends the data from @widget to the widget hierarchy represented
13860 * by @path. This function is a shortcut for adding information from
13861 * @widget to the given @path. This includes setting the name or
13862 * adding the style classes from @widget.
13864 * Returns: the position where the data was inserted
13869 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
13874 g_return_val_if_fail (path != NULL, 0);
13875 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13877 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
13879 if (widget->priv->name)
13880 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
13882 if (widget->priv->context)
13884 GList *classes, *l;
13886 /* Also add any persistent classes in
13887 * the style context the widget path
13889 classes = gtk_style_context_list_classes (widget->priv->context);
13891 for (l = classes; l; l = l->next)
13892 gtk_widget_path_iter_add_class (path, pos, l->data);
13894 g_list_free (classes);
13901 _gtk_widget_create_path (GtkWidget *widget)
13905 parent = widget->priv->parent;
13908 return gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
13911 /* Widget is either toplevel or unparented, treat both
13912 * as toplevels style wise, since there are situations
13913 * where style properties might be retrieved on that
13916 GtkWidget *attach_widget = NULL;
13917 GtkWidgetPath *result;
13919 if (GTK_IS_WINDOW (widget))
13920 attach_widget = gtk_window_get_attached_to (GTK_WINDOW (widget));
13922 if (attach_widget != NULL)
13923 result = gtk_widget_path_copy (gtk_widget_get_path (attach_widget));
13925 result = gtk_widget_path_new ();
13927 gtk_widget_path_append_for_widget (result, widget);
13934 * gtk_widget_get_path:
13935 * @widget: a #GtkWidget
13937 * Returns the #GtkWidgetPath representing @widget, if the widget
13938 * is not connected to a toplevel widget, a partial path will be
13941 * Returns: (transfer none): The #GtkWidgetPath representing @widget
13944 gtk_widget_get_path (GtkWidget *widget)
13946 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13948 if (!widget->priv->path)
13949 widget->priv->path = _gtk_widget_create_path (widget);
13951 return widget->priv->path;
13955 _gtk_widget_style_context_invalidated (GtkWidget *widget)
13957 if (widget->priv->path)
13959 gtk_widget_path_free (widget->priv->path);
13960 widget->priv->path = NULL;
13963 if (gtk_widget_get_realized (widget))
13964 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
13967 /* Compress all style updates so it
13968 * is only emitted once pre-realize.
13970 widget->priv->style_update_pending = TRUE;
13973 if (widget->priv->anchored)
13974 gtk_widget_queue_resize (widget);
13978 * gtk_widget_get_style_context:
13979 * @widget: a #GtkWidget
13981 * Returns the style context associated to @widget.
13983 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
13984 * must not be freed.
13987 gtk_widget_get_style_context (GtkWidget *widget)
13989 GtkWidgetPrivate *priv;
13991 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13993 priv = widget->priv;
13995 if (G_UNLIKELY (priv->context == NULL))
13999 priv->context = gtk_style_context_new ();
14001 gtk_style_context_set_direction (priv->context, gtk_widget_get_direction (widget));
14003 screen = gtk_widget_get_screen (widget);
14005 gtk_style_context_set_screen (priv->context, screen);
14008 gtk_style_context_set_parent (priv->context,
14009 gtk_widget_get_style_context (priv->parent));
14011 _gtk_style_context_set_widget (priv->context, widget);
14014 return widget->priv->context;
14018 _gtk_widget_invalidate_style_context (GtkWidget *widget,
14019 GtkCssChange change)
14021 GtkWidgetPrivate *priv;
14023 priv = widget->priv;
14025 if (priv->context == NULL)
14028 _gtk_style_context_queue_invalidate (priv->context, change);
14032 * gtk_widget_get_modifier_mask:
14033 * @widget: a #GtkWidget
14034 * @intent: the use case for the modifier mask
14036 * Returns the modifier mask the @widget's windowing system backend
14037 * uses for a particular purpose.
14039 * See gdk_keymap_get_modifier_mask().
14041 * Returns: the modifier mask used for @intent.
14046 gtk_widget_get_modifier_mask (GtkWidget *widget,
14047 GdkModifierIntent intent)
14049 GdkDisplay *display;
14051 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14053 display = gtk_widget_get_display (widget);
14055 return gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
14060 _gtk_widget_get_style (GtkWidget *widget)
14062 return widget->priv->style;
14066 _gtk_widget_set_style (GtkWidget *widget,
14069 widget->priv->style = style;