1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
33 #include <gobject/gvaluecollector.h>
34 #include <gobject/gobjectnotifyqueue.c>
35 #include <cairo-gobject.h>
37 #include "gtkcontainer.h"
38 #include "gtkaccelmap.h"
39 #include "gtkclipboard.h"
40 #include "gtkiconfactory.h"
42 #include "gtkmainprivate.h"
43 #include "gtkmarshalers.h"
45 #include "gtkselectionprivate.h"
46 #include "gtksettingsprivate.h"
47 #include "gtksizegroup-private.h"
48 #include "gtkwidget.h"
49 #include "gtkwidgetprivate.h"
50 #include "gtkwindowprivate.h"
51 #include "gtkcontainerprivate.h"
52 #include "gtkbindings.h"
53 #include "gtkprivate.h"
54 #include "gtkaccessible.h"
55 #include "gtktooltip.h"
56 #include "gtkinvisible.h"
57 #include "gtkbuildable.h"
58 #include "gtkbuilderprivate.h"
59 #include "gtksizerequest.h"
60 #include "gtkstylecontextprivate.h"
61 #include "gtksymboliccolor.h"
62 #include "gtkcssprovider.h"
63 #include "gtkanimationdescription.h"
64 #include "gtkmodifierstyle.h"
65 #include "gtkversion.h"
68 #include "gtktypebuiltins.h"
73 * @Short_description: Base class for all widgets
76 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
77 * widget lifecycle, states and style.
79 * <refsect2 id="geometry-management">
80 * <title>Height-for-width Geometry Management</title>
82 * GTK+ uses a height-for-width (and width-for-height) geometry management
83 * system. Height-for-width means that a widget can change how much
84 * vertical space it needs, depending on the amount of horizontal space
85 * that it is given (and similar for width-for-height). The most common
86 * example is a label that reflows to fill up the available width, wraps
87 * to fewer lines, and therefore needs less height.
89 * Height-for-width geometry management is implemented in GTK+ by way
90 * of five virtual methods:
92 * <listitem>#GtkWidgetClass.get_request_mode()</listitem>
93 * <listitem>#GtkWidgetClass.get_preferred_width()</listitem>
94 * <listitem>#GtkWidgetClass.get_preferred_height()</listitem>
95 * <listitem>#GtkWidgetClass.get_preferred_height_for_width()</listitem>
96 * <listitem>#GtkWidgetClass.get_preferred_width_for_height()</listitem>
99 * There are some important things to keep in mind when implementing
100 * height-for-width and when using it in container implementations.
102 * The geometry management system will query a widget hierarchy in
103 * only one orientation at a time. When widgets are initially queried
104 * for their minimum sizes it is generally done in two initial passes
105 * in the #GtkSizeRequestMode chosen by the toplevel.
107 * For example, when queried in the normal
108 * %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode:
109 * First, the default minimum and natural width for each widget
110 * in the interface will be computed using gtk_widget_get_preferred_width().
111 * Because the preferred widths for each container depend on the preferred
112 * widths of their children, this information propagates up the hierarchy,
113 * and finally a minimum and natural width is determined for the entire
114 * toplevel. Next, the toplevel will use the minimum width to query for the
115 * minimum height contextual to that width using
116 * gtk_widget_get_preferred_height_for_width(), which will also be a highly
117 * recursive operation. The minimum height for the minimum width is normally
118 * used to set the minimum size constraint on the toplevel
119 * (unless gtk_window_set_geometry_hints() is explicitly used instead).
121 * After the toplevel window has initially requested its size in both
122 * dimensions it can go on to allocate itself a reasonable size (or a size
123 * previously specified with gtk_window_set_default_size()). During the
124 * recursive allocation process it's important to note that request cycles
125 * will be recursively executed while container widgets allocate their children.
126 * Each container widget, once allocated a size, will go on to first share the
127 * space in one orientation among its children and then request each child's
128 * height for its target allocated width or its width for allocated height,
129 * depending. In this way a #GtkWidget will typically be requested its size
130 * a number of times before actually being allocated a size. The size a
131 * widget is finally allocated can of course differ from the size it has
132 * requested. For this reason, #GtkWidget caches a small number of results
133 * to avoid re-querying for the same sizes in one allocation cycle.
135 * See <link linkend="container-geometry-management">GtkContainer's
136 * geometry management section</link>
137 * to learn more about how height-for-width allocations are performed
138 * by container widgets.
140 * If a widget does move content around to intelligently use up the
141 * allocated size then it must support the request in both
142 * #GtkSizeRequestModes even if the widget in question only
143 * trades sizes in a single orientation.
145 * For instance, a #GtkLabel that does height-for-width word wrapping
146 * will not expect to have #GtkWidgetClass.get_preferred_height() called
147 * because that call is specific to a width-for-height request. In this
148 * case the label must return the height required for its own minimum
149 * possible width. By following this rule any widget that handles
150 * height-for-width or width-for-height requests will always be allocated
151 * at least enough space to fit its own content.
153 * Here are some examples of how a %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH widget
154 * generally deals with width-for-height requests, for #GtkWidgetClass.get_preferred_height()
156 * <programlisting><![CDATA[
158 * foo_widget_get_preferred_height (GtkWidget *widget, gint *min_height, gint *nat_height)
160 * if (i_am_in_height_for_width_mode)
164 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
165 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width,
166 * min_height, nat_height);
170 * ... some widgets do both. For instance, if a GtkLabel is rotated to 90 degrees
171 * it will return the minimum and natural height for the rotated label here.
174 * ]]></programlisting>
176 * And in #GtkWidgetClass.get_preferred_width_for_height() it will simply return
177 * the minimum and natural width:
179 * <programlisting><![CDATA[
181 * foo_widget_get_preferred_width_for_height (GtkWidget *widget, gint for_height,
182 * gint *min_width, gint *nat_width)
184 * if (i_am_in_height_for_width_mode)
186 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, min_width, nat_width);
190 * ... again if a widget is sometimes operating in width-for-height mode
191 * (like a rotated GtkLabel) it can go ahead and do its real width for
192 * height calculation here.
195 * ]]></programlisting>
197 * Often a widget needs to get its own request during size request or
198 * allocation. For example, when computing height it may need to also
199 * compute width. Or when deciding how to use an allocation, the widget
200 * may need to know its natural size. In these cases, the widget should
201 * be careful to call its virtual methods directly, like this:
203 * <title>Widget calling its own size request method.</title>
205 * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget),
210 * It will not work to use the wrapper functions, such as
211 * gtk_widget_get_preferred_width() inside your own size request
212 * implementation. These return a request adjusted by #GtkSizeGroup
213 * and by the #GtkWidgetClass.adjust_size_request() virtual method. If a
214 * widget used the wrappers inside its virtual method implementations,
215 * then the adjustments (such as widget margins) would be applied
216 * twice. GTK+ therefore does not allow this and will warn if you try
219 * Of course if you are getting the size request for
220 * <emphasis>another</emphasis> widget, such as a child of a
221 * container, you <emphasis>must</emphasis> use the wrapper APIs.
222 * Otherwise, you would not properly consider widget margins,
223 * #GtkSizeGroup, and so forth.
226 * <refsect2 id="style-properties">
227 * <title>Style Properties</title>
229 * <structname>GtkWidget</structname> introduces <firstterm>style
230 * properties</firstterm> - these are basically object properties that are stored
231 * not on the object, but in the style object associated to the widget. Style
232 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
233 * This mechanism is used for configuring such things as the location of the
234 * scrollbar arrows through the theme, giving theme authors more control over the
235 * look of applications without the need to write a theme engine in C.
238 * Use gtk_widget_class_install_style_property() to install style properties for
239 * a widget class, gtk_widget_class_find_style_property() or
240 * gtk_widget_class_list_style_properties() to get information about existing
241 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
242 * gtk_widget_style_get_valist() to obtain the value of a style property.
245 * <refsect2 id="GtkWidget-BUILDER-UI">
246 * <title>GtkWidget as GtkBuildable</title>
248 * The GtkWidget implementation of the GtkBuildable interface supports a
249 * custom <accelerator> element, which has attributes named key,
250 * modifiers and signal and allows to specify accelerators.
253 * <title>A UI definition fragment specifying an accelerator</title>
254 * <programlisting><![CDATA[
255 * <object class="GtkButton">
256 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
258 * ]]></programlisting>
261 * In addition to accelerators, <structname>GtkWidget</structname> also support a
262 * custom <accessible> element, which supports actions and relations.
263 * Properties on the accessible implementation of an object can be set by accessing the
264 * internal child "accessible" of a <structname>GtkWidget</structname>.
267 * <title>A UI definition fragment specifying an accessible</title>
268 * <programlisting><![CDATA[
269 * <object class="GtkButton" id="label1"/>
270 * <property name="label">I am a Label for a Button</property>
272 * <object class="GtkButton" id="button1">
274 * <action action_name="click" translatable="yes">Click the button.</action>
275 * <relation target="label1" type="labelled-by"/>
277 * <child internal-child="accessible">
278 * <object class="AtkObject" id="a11y-button1">
279 * <property name="AtkObject::name">Clickable Button</property>
283 * ]]></programlisting>
286 * Finally, GtkWidget allows style information such as style classes to
287 * be associated with widgets, using the custom <style> element:
289 * <title>A UI definition fragment specifying an style class</title>
290 * <programlisting><![CDATA[
291 * <object class="GtkButton" id="button1">
293 * <class name="my-special-button-class"/>
294 * <class name="dark-button"/>
297 * ]]></programlisting>
303 /* Add flags here that should not be propagated to children. By default,
304 * all flags will be set on children (think prelight or active), but we
305 * might want to not do this for some.
307 #define GTK_STATE_FLAGS_DONT_PROPAGATE (GTK_STATE_FLAG_FOCUSED)
308 #define GTK_STATE_FLAGS_DO_PROPAGATE (~GTK_STATE_FLAGS_DONT_PROPAGATE)
310 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
311 #define INIT_PATH_SIZE (512)
313 struct _GtkWidgetPrivate
315 /* The state of the widget. There are actually only
316 * 5 widget states (defined in "gtkenums.h")
319 guint state_flags : 6;
323 guint in_destruction : 1;
326 guint composite_child : 1;
334 guint can_default : 1;
335 guint has_default : 1;
336 guint receives_default : 1;
340 guint style_update_pending : 1;
341 guint app_paintable : 1;
342 guint double_buffered : 1;
343 guint redraw_on_alloc : 1;
344 guint no_show_all : 1;
345 guint child_visible : 1;
346 guint multidevice : 1;
347 guint has_shape_mask : 1;
348 guint in_reparent : 1;
350 /* Queue-resize related flags */
351 guint resize_pending : 1;
352 guint alloc_needed : 1;
353 guint width_request_needed : 1;
354 guint height_request_needed : 1;
356 /* Expand-related flags */
357 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
358 guint computed_hexpand : 1; /* computed results (composite of child flags) */
359 guint computed_vexpand : 1;
360 guint hexpand : 1; /* application-forced expand */
362 guint hexpand_set : 1; /* whether to use application-forced */
363 guint vexpand_set : 1; /* instead of computing from children */
365 /* SizeGroup related flags */
366 guint sizegroup_visited : 1;
367 guint sizegroup_bumping : 1;
368 guint have_size_groups : 1;
370 /* The widget's name. If the widget does not have a name
371 * (the name is NULL), then its name (as returned by
372 * "gtk_widget_get_name") is its class's name.
373 * Among other things, the widget name is used to determine
374 * the style to use for a widget.
378 /* The style for the widget. The style contains the
379 * colors the widget should be drawn in for each state
380 * along with graphics contexts used to draw with and
381 * the font to use for text.
384 GtkStyleContext *context;
386 /* Widget's path for styling */
389 /* The widget's allocated size */
390 GtkAllocation allocation;
392 /* The widget's requested sizes */
393 SizeRequestCache requests;
395 /* The widget's window or its parent window if it does
396 * not have a window. (Which will be indicated by the
397 * GTK_NO_WINDOW flag being set).
401 /* The widget's parent */
404 #ifdef G_ENABLE_DEBUG
405 /* Number of gtk_widget_push_verify_invariants () */
406 guint verifying_invariants_count;
407 #endif /* G_ENABLE_DEBUG */
436 BUTTON_RELEASE_EVENT,
450 PROPERTY_NOTIFY_EVENT,
451 SELECTION_CLEAR_EVENT,
452 SELECTION_REQUEST_EVENT,
453 SELECTION_NOTIFY_EVENT,
458 VISIBILITY_NOTIFY_EVENT,
472 ACCEL_CLOSURES_CHANGED,
496 PROP_RECEIVES_DEFAULT,
497 PROP_COMPOSITE_CHILD,
505 PROP_DOUBLE_BUFFERED,
520 typedef struct _GtkStateData GtkStateData;
523 STATE_CHANGE_REPLACE,
532 guint use_forall : 1;
535 /* --- prototypes --- */
536 static void gtk_widget_class_init (GtkWidgetClass *klass);
537 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
538 static void gtk_widget_init (GtkWidget *widget);
539 static void gtk_widget_set_property (GObject *object,
543 static void gtk_widget_get_property (GObject *object,
547 static void gtk_widget_dispose (GObject *object);
548 static void gtk_widget_real_destroy (GtkWidget *object);
549 static void gtk_widget_finalize (GObject *object);
550 static void gtk_widget_real_show (GtkWidget *widget);
551 static void gtk_widget_real_hide (GtkWidget *widget);
552 static void gtk_widget_real_map (GtkWidget *widget);
553 static void gtk_widget_real_unmap (GtkWidget *widget);
554 static void gtk_widget_real_realize (GtkWidget *widget);
555 static void gtk_widget_real_unrealize (GtkWidget *widget);
556 static void gtk_widget_real_size_allocate (GtkWidget *widget,
557 GtkAllocation *allocation);
558 static void gtk_widget_real_style_set (GtkWidget *widget,
559 GtkStyle *previous_style);
560 static void gtk_widget_real_direction_changed(GtkWidget *widget,
561 GtkTextDirection previous_direction);
563 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
564 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
567 gboolean keyboard_tip,
568 GtkTooltip *tooltip);
569 static void gtk_widget_real_style_updated (GtkWidget *widget);
570 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
571 GtkWidgetHelpType help_type);
573 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
575 GParamSpec **pspecs);
576 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
578 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
580 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
581 GdkEventFocus *event);
582 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
583 GdkEventFocus *event);
584 static gboolean gtk_widget_real_focus (GtkWidget *widget,
585 GtkDirectionType direction);
586 static void gtk_widget_real_move_focus (GtkWidget *widget,
587 GtkDirectionType direction);
588 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
589 GtkDirectionType direction);
590 #ifdef G_ENABLE_DEBUG
591 static void gtk_widget_verify_invariants (GtkWidget *widget);
592 static void gtk_widget_push_verify_invariants (GtkWidget *widget);
593 static void gtk_widget_pop_verify_invariants (GtkWidget *widget);
595 #define gtk_widget_verify_invariants(widget)
596 #define gtk_widget_push_verify_invariants(widget)
597 #define gtk_widget_pop_verify_invariants(widget)
599 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
600 static void gtk_widget_update_pango_context (GtkWidget *widget);
601 static void gtk_widget_propagate_state (GtkWidget *widget,
604 static gint gtk_widget_event_internal (GtkWidget *widget,
606 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
607 gboolean group_cycling);
608 static void gtk_widget_real_get_width (GtkWidget *widget,
611 static void gtk_widget_real_get_height (GtkWidget *widget,
614 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
616 gint *minimum_height,
617 gint *natural_height);
618 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
621 gint *natural_width);
622 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
623 static GtkWidgetAuxInfo* gtk_widget_get_aux_info (GtkWidget *widget,
625 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
626 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
627 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
628 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
629 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
630 cairo_region_t *region);
631 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
632 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
633 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
636 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
637 gboolean has_tooltip,
639 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
640 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
642 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
643 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
645 const gchar *childname);
646 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
649 const GValue *value);
650 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
653 const gchar *tagname,
654 GMarkupParser *parser,
656 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
659 const gchar *tagname,
661 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
662 GtkBuilder *builder);
664 static GtkSizeRequestMode gtk_widget_real_get_request_mode (GtkWidget *widget);
665 static void gtk_widget_real_get_width (GtkWidget *widget,
668 static void gtk_widget_real_get_height (GtkWidget *widget,
672 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
675 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
676 GtkOrientation orientation,
679 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
680 GtkOrientation orientation,
684 gint *allocated_size);
686 static void gtk_widget_set_usize_internal (GtkWidget *widget,
689 GtkQueueResizeFlags flags);
691 static void gtk_widget_add_events_internal (GtkWidget *widget,
694 static void gtk_widget_set_device_enabled_internal (GtkWidget *widget,
699 /* --- variables --- */
700 static gpointer gtk_widget_parent_class = NULL;
701 static guint widget_signals[LAST_SIGNAL] = { 0 };
702 static GtkStyle *gtk_default_style = NULL;
703 static guint composite_child_stack = 0;
704 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
705 static GParamSpecPool *style_property_spec_pool = NULL;
707 static GQuark quark_property_parser = 0;
708 static GQuark quark_aux_info = 0;
709 static GQuark quark_accel_path = 0;
710 static GQuark quark_accel_closures = 0;
711 static GQuark quark_event_mask = 0;
712 static GQuark quark_device_event_mask = 0;
713 static GQuark quark_parent_window = 0;
714 static GQuark quark_pointer_window = 0;
715 static GQuark quark_shape_info = 0;
716 static GQuark quark_input_shape_info = 0;
717 static GQuark quark_pango_context = 0;
718 static GQuark quark_rc_style = 0;
719 static GQuark quark_accessible_object = 0;
720 static GQuark quark_mnemonic_labels = 0;
721 static GQuark quark_tooltip_markup = 0;
722 static GQuark quark_has_tooltip = 0;
723 static GQuark quark_tooltip_window = 0;
724 static GQuark quark_visual = 0;
725 static GQuark quark_modifier_style = 0;
726 static GQuark quark_enabled_devices = 0;
727 static GQuark quark_size_groups = 0;
728 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
729 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
731 /* --- functions --- */
733 gtk_widget_get_type (void)
735 static GType widget_type = 0;
737 if (G_UNLIKELY (widget_type == 0))
739 const GTypeInfo widget_info =
741 sizeof (GtkWidgetClass),
742 NULL, /* base_init */
743 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
744 (GClassInitFunc) gtk_widget_class_init,
745 NULL, /* class_finalize */
746 NULL, /* class_init */
749 (GInstanceInitFunc) gtk_widget_init,
750 NULL, /* value_table */
753 const GInterfaceInfo accessibility_info =
755 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
756 (GInterfaceFinalizeFunc) NULL,
757 NULL /* interface data */
760 const GInterfaceInfo buildable_info =
762 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
763 (GInterfaceFinalizeFunc) NULL,
764 NULL /* interface data */
767 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
768 &widget_info, G_TYPE_FLAG_ABSTRACT);
770 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
771 &accessibility_info) ;
772 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
780 child_property_notify_dispatcher (GObject *object,
784 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
787 /* We guard against the draw signal callbacks modifying the state of the
788 * cairo context by surounding it with save/restore.
789 * Maybe we should also cairo_new_path() just to be sure?
792 gtk_widget_draw_marshaller (GClosure *closure,
793 GValue *return_value,
794 guint n_param_values,
795 const GValue *param_values,
796 gpointer invocation_hint,
797 gpointer marshal_data)
799 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
803 _gtk_marshal_BOOLEAN__BOXED (closure,
814 gtk_widget_class_init (GtkWidgetClass *klass)
816 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
817 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
818 GtkBindingSet *binding_set;
820 gtk_widget_parent_class = g_type_class_peek_parent (klass);
822 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
823 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
824 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
825 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
826 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
827 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
828 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
829 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
830 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
831 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
832 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
833 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
834 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
835 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
836 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
837 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
838 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
839 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
840 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
841 quark_enabled_devices = g_quark_from_static_string ("gtk-widget-enabled-devices");
842 quark_size_groups = g_quark_from_static_string ("gtk-widget-size-groups");
844 style_property_spec_pool = g_param_spec_pool_new (FALSE);
845 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
846 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
847 cpn_context.dispatcher = child_property_notify_dispatcher;
848 _gtk_widget_child_property_notify_context = &cpn_context;
850 gobject_class->dispose = gtk_widget_dispose;
851 gobject_class->finalize = gtk_widget_finalize;
852 gobject_class->set_property = gtk_widget_set_property;
853 gobject_class->get_property = gtk_widget_get_property;
855 klass->destroy = gtk_widget_real_destroy;
857 klass->activate_signal = 0;
858 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
859 klass->show = gtk_widget_real_show;
860 klass->show_all = gtk_widget_show;
861 klass->hide = gtk_widget_real_hide;
862 klass->map = gtk_widget_real_map;
863 klass->unmap = gtk_widget_real_unmap;
864 klass->realize = gtk_widget_real_realize;
865 klass->unrealize = gtk_widget_real_unrealize;
866 klass->size_allocate = gtk_widget_real_size_allocate;
867 klass->get_request_mode = gtk_widget_real_get_request_mode;
868 klass->get_preferred_width = gtk_widget_real_get_width;
869 klass->get_preferred_height = gtk_widget_real_get_height;
870 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
871 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
872 klass->state_changed = NULL;
873 klass->parent_set = NULL;
874 klass->hierarchy_changed = NULL;
875 klass->style_set = gtk_widget_real_style_set;
876 klass->direction_changed = gtk_widget_real_direction_changed;
877 klass->grab_notify = NULL;
878 klass->child_notify = NULL;
880 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
881 klass->grab_focus = gtk_widget_real_grab_focus;
882 klass->focus = gtk_widget_real_focus;
883 klass->move_focus = gtk_widget_real_move_focus;
884 klass->keynav_failed = gtk_widget_real_keynav_failed;
886 klass->button_press_event = NULL;
887 klass->button_release_event = NULL;
888 klass->motion_notify_event = NULL;
889 klass->delete_event = NULL;
890 klass->destroy_event = NULL;
891 klass->key_press_event = gtk_widget_real_key_press_event;
892 klass->key_release_event = gtk_widget_real_key_release_event;
893 klass->enter_notify_event = NULL;
894 klass->leave_notify_event = NULL;
895 klass->configure_event = NULL;
896 klass->focus_in_event = gtk_widget_real_focus_in_event;
897 klass->focus_out_event = gtk_widget_real_focus_out_event;
898 klass->map_event = NULL;
899 klass->unmap_event = NULL;
900 klass->window_state_event = NULL;
901 klass->property_notify_event = _gtk_selection_property_notify;
902 klass->selection_clear_event = _gtk_selection_clear;
903 klass->selection_request_event = _gtk_selection_request;
904 klass->selection_notify_event = _gtk_selection_notify;
905 klass->selection_received = NULL;
906 klass->proximity_in_event = NULL;
907 klass->proximity_out_event = NULL;
908 klass->drag_begin = NULL;
909 klass->drag_end = NULL;
910 klass->drag_data_delete = NULL;
911 klass->drag_leave = NULL;
912 klass->drag_motion = NULL;
913 klass->drag_drop = NULL;
914 klass->drag_data_received = NULL;
915 klass->screen_changed = NULL;
916 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
917 klass->grab_broken_event = NULL;
918 klass->query_tooltip = gtk_widget_real_query_tooltip;
919 klass->style_updated = gtk_widget_real_style_updated;
921 klass->show_help = gtk_widget_real_show_help;
923 /* Accessibility support */
924 klass->get_accessible = gtk_widget_real_get_accessible;
926 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
927 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
929 g_object_class_install_property (gobject_class,
931 g_param_spec_string ("name",
933 P_("The name of the widget"),
935 GTK_PARAM_READWRITE));
936 g_object_class_install_property (gobject_class,
938 g_param_spec_object ("parent",
940 P_("The parent widget of this widget. Must be a Container widget"),
942 GTK_PARAM_READWRITE));
944 g_object_class_install_property (gobject_class,
946 g_param_spec_int ("width-request",
948 P_("Override for width request of the widget, or -1 if natural request should be used"),
952 GTK_PARAM_READWRITE));
953 g_object_class_install_property (gobject_class,
955 g_param_spec_int ("height-request",
956 P_("Height request"),
957 P_("Override for height request of the widget, or -1 if natural request should be used"),
961 GTK_PARAM_READWRITE));
962 g_object_class_install_property (gobject_class,
964 g_param_spec_boolean ("visible",
966 P_("Whether the widget is visible"),
968 GTK_PARAM_READWRITE));
969 g_object_class_install_property (gobject_class,
971 g_param_spec_boolean ("sensitive",
973 P_("Whether the widget responds to input"),
975 GTK_PARAM_READWRITE));
976 g_object_class_install_property (gobject_class,
978 g_param_spec_boolean ("app-paintable",
979 P_("Application paintable"),
980 P_("Whether the application will paint directly on the widget"),
982 GTK_PARAM_READWRITE));
983 g_object_class_install_property (gobject_class,
985 g_param_spec_boolean ("can-focus",
987 P_("Whether the widget can accept the input focus"),
989 GTK_PARAM_READWRITE));
990 g_object_class_install_property (gobject_class,
992 g_param_spec_boolean ("has-focus",
994 P_("Whether the widget has the input focus"),
996 GTK_PARAM_READWRITE));
997 g_object_class_install_property (gobject_class,
999 g_param_spec_boolean ("is-focus",
1001 P_("Whether the widget is the focus widget within the toplevel"),
1003 GTK_PARAM_READWRITE));
1004 g_object_class_install_property (gobject_class,
1006 g_param_spec_boolean ("can-default",
1008 P_("Whether the widget can be the default widget"),
1010 GTK_PARAM_READWRITE));
1011 g_object_class_install_property (gobject_class,
1013 g_param_spec_boolean ("has-default",
1015 P_("Whether the widget is the default widget"),
1017 GTK_PARAM_READWRITE));
1018 g_object_class_install_property (gobject_class,
1019 PROP_RECEIVES_DEFAULT,
1020 g_param_spec_boolean ("receives-default",
1021 P_("Receives default"),
1022 P_("If TRUE, the widget will receive the default action when it is focused"),
1024 GTK_PARAM_READWRITE));
1025 g_object_class_install_property (gobject_class,
1026 PROP_COMPOSITE_CHILD,
1027 g_param_spec_boolean ("composite-child",
1028 P_("Composite child"),
1029 P_("Whether the widget is part of a composite widget"),
1031 GTK_PARAM_READABLE));
1032 g_object_class_install_property (gobject_class,
1034 g_param_spec_object ("style",
1036 P_("The style of the widget, which contains information about how it will look (colors etc)"),
1038 GTK_PARAM_READWRITE));
1039 g_object_class_install_property (gobject_class,
1041 g_param_spec_flags ("events",
1043 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1044 GDK_TYPE_EVENT_MASK,
1046 GTK_PARAM_READWRITE));
1047 g_object_class_install_property (gobject_class,
1049 g_param_spec_boolean ("no-show-all",
1051 P_("Whether gtk_widget_show_all() should not affect this widget"),
1053 GTK_PARAM_READWRITE));
1056 * GtkWidget:has-tooltip:
1058 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1059 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1060 * the widget will be queried using #GtkWidget::query-tooltip to determine
1061 * whether it will provide a tooltip or not.
1063 * Note that setting this property to %TRUE for the first time will change
1064 * the event masks of the GdkWindows of this widget to include leave-notify
1065 * and motion-notify events. This cannot and will not be undone when the
1066 * property is set to %FALSE again.
1070 g_object_class_install_property (gobject_class,
1072 g_param_spec_boolean ("has-tooltip",
1074 P_("Whether this widget has a tooltip"),
1076 GTK_PARAM_READWRITE));
1078 * GtkWidget:tooltip-text:
1080 * Sets the text of tooltip to be the given string.
1082 * Also see gtk_tooltip_set_text().
1084 * This is a convenience property which will take care of getting the
1085 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1086 * will automatically be set to %TRUE and there will be taken care of
1087 * #GtkWidget::query-tooltip in the default signal handler.
1091 g_object_class_install_property (gobject_class,
1093 g_param_spec_string ("tooltip-text",
1095 P_("The contents of the tooltip for this widget"),
1097 GTK_PARAM_READWRITE));
1099 * GtkWidget:tooltip-markup:
1101 * Sets the text of tooltip to be the given string, which is marked up
1102 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1103 * Also see gtk_tooltip_set_markup().
1105 * This is a convenience property which will take care of getting the
1106 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1107 * will automatically be set to %TRUE and there will be taken care of
1108 * #GtkWidget::query-tooltip in the default signal handler.
1112 g_object_class_install_property (gobject_class,
1113 PROP_TOOLTIP_MARKUP,
1114 g_param_spec_string ("tooltip-markup",
1115 P_("Tooltip markup"),
1116 P_("The contents of the tooltip for this widget"),
1118 GTK_PARAM_READWRITE));
1123 * The widget's window if it is realized, %NULL otherwise.
1127 g_object_class_install_property (gobject_class,
1129 g_param_spec_object ("window",
1131 P_("The widget's window if it is realized"),
1133 GTK_PARAM_READABLE));
1136 * GtkWidget:double-buffered
1138 * Whether the widget is double buffered.
1142 g_object_class_install_property (gobject_class,
1143 PROP_DOUBLE_BUFFERED,
1144 g_param_spec_boolean ("double-buffered",
1145 P_("Double Buffered"),
1146 P_("Whether the widget is double buffered"),
1148 GTK_PARAM_READWRITE));
1153 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1157 g_object_class_install_property (gobject_class,
1159 g_param_spec_enum ("halign",
1160 P_("Horizontal Alignment"),
1161 P_("How to position in extra horizontal space"),
1164 GTK_PARAM_READWRITE));
1169 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1173 g_object_class_install_property (gobject_class,
1175 g_param_spec_enum ("valign",
1176 P_("Vertical Alignment"),
1177 P_("How to position in extra vertical space"),
1180 GTK_PARAM_READWRITE));
1183 * GtkWidget:margin-left
1185 * Margin on left side of widget.
1187 * This property adds margin outside of the widget's normal size
1188 * request, the margin will be added in addition to the size from
1189 * gtk_widget_set_size_request() for example.
1193 g_object_class_install_property (gobject_class,
1195 g_param_spec_int ("margin-left",
1196 P_("Margin on Left"),
1197 P_("Pixels of extra space on the left side"),
1201 GTK_PARAM_READWRITE));
1204 * GtkWidget:margin-right
1206 * Margin on right side of widget.
1208 * This property adds margin outside of the widget's normal size
1209 * request, the margin will be added in addition to the size from
1210 * gtk_widget_set_size_request() for example.
1214 g_object_class_install_property (gobject_class,
1216 g_param_spec_int ("margin-right",
1217 P_("Margin on Right"),
1218 P_("Pixels of extra space on the right side"),
1222 GTK_PARAM_READWRITE));
1225 * GtkWidget:margin-top
1227 * Margin on top side of widget.
1229 * This property adds margin outside of the widget's normal size
1230 * request, the margin will be added in addition to the size from
1231 * gtk_widget_set_size_request() for example.
1235 g_object_class_install_property (gobject_class,
1237 g_param_spec_int ("margin-top",
1238 P_("Margin on Top"),
1239 P_("Pixels of extra space on the top side"),
1243 GTK_PARAM_READWRITE));
1246 * GtkWidget:margin-bottom
1248 * Margin on bottom side of widget.
1250 * This property adds margin outside of the widget's normal size
1251 * request, the margin will be added in addition to the size from
1252 * gtk_widget_set_size_request() for example.
1256 g_object_class_install_property (gobject_class,
1258 g_param_spec_int ("margin-bottom",
1259 P_("Margin on Bottom"),
1260 P_("Pixels of extra space on the bottom side"),
1264 GTK_PARAM_READWRITE));
1269 * Sets all four sides' margin at once. If read, returns max
1270 * margin on any side.
1274 g_object_class_install_property (gobject_class,
1276 g_param_spec_int ("margin",
1278 P_("Pixels of extra space on all four sides"),
1282 GTK_PARAM_READWRITE));
1285 * GtkWidget::destroy:
1286 * @object: the object which received the signal
1288 * Signals that all holders of a reference to the widget should release
1289 * the reference that they hold. May result in finalization of the widget
1290 * if all references are released.
1292 widget_signals[DESTROY] =
1293 g_signal_new (I_("destroy"),
1294 G_TYPE_FROM_CLASS (gobject_class),
1295 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1296 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1298 _gtk_marshal_VOID__VOID,
1304 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1308 g_object_class_install_property (gobject_class,
1310 g_param_spec_boolean ("hexpand",
1311 P_("Horizontal Expand"),
1312 P_("Whether widget wants more horizontal space"),
1314 GTK_PARAM_READWRITE));
1317 * GtkWidget:hexpand-set
1319 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1323 g_object_class_install_property (gobject_class,
1325 g_param_spec_boolean ("hexpand-set",
1326 P_("Horizontal Expand Set"),
1327 P_("Whether to use the hexpand property"),
1329 GTK_PARAM_READWRITE));
1334 * Whether to expand vertically. See gtk_widget_set_vexpand().
1338 g_object_class_install_property (gobject_class,
1340 g_param_spec_boolean ("vexpand",
1341 P_("Vertical Expand"),
1342 P_("Whether widget wants more vertical space"),
1344 GTK_PARAM_READWRITE));
1347 * GtkWidget:vexpand-set
1349 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1353 g_object_class_install_property (gobject_class,
1355 g_param_spec_boolean ("vexpand-set",
1356 P_("Vertical Expand Set"),
1357 P_("Whether to use the vexpand property"),
1359 GTK_PARAM_READWRITE));
1364 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1368 g_object_class_install_property (gobject_class,
1370 g_param_spec_boolean ("expand",
1372 P_("Whether widget wants to expand in both directions"),
1374 GTK_PARAM_READWRITE));
1378 * @widget: the object which received the signal.
1380 widget_signals[SHOW] =
1381 g_signal_new (I_("show"),
1382 G_TYPE_FROM_CLASS (gobject_class),
1384 G_STRUCT_OFFSET (GtkWidgetClass, show),
1386 _gtk_marshal_VOID__VOID,
1391 * @widget: the object which received the signal.
1393 widget_signals[HIDE] =
1394 g_signal_new (I_("hide"),
1395 G_TYPE_FROM_CLASS (gobject_class),
1397 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1399 _gtk_marshal_VOID__VOID,
1404 * @widget: the object which received the signal.
1406 widget_signals[MAP] =
1407 g_signal_new (I_("map"),
1408 G_TYPE_FROM_CLASS (gobject_class),
1410 G_STRUCT_OFFSET (GtkWidgetClass, map),
1412 _gtk_marshal_VOID__VOID,
1417 * @widget: the object which received the signal.
1419 widget_signals[UNMAP] =
1420 g_signal_new (I_("unmap"),
1421 G_TYPE_FROM_CLASS (gobject_class),
1423 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1425 _gtk_marshal_VOID__VOID,
1429 * GtkWidget::realize:
1430 * @widget: the object which received the signal.
1432 widget_signals[REALIZE] =
1433 g_signal_new (I_("realize"),
1434 G_TYPE_FROM_CLASS (gobject_class),
1436 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1438 _gtk_marshal_VOID__VOID,
1442 * GtkWidget::unrealize:
1443 * @widget: the object which received the signal.
1445 widget_signals[UNREALIZE] =
1446 g_signal_new (I_("unrealize"),
1447 G_TYPE_FROM_CLASS (gobject_class),
1449 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1451 _gtk_marshal_VOID__VOID,
1455 * GtkWidget::size-allocate:
1456 * @widget: the object which received the signal.
1459 widget_signals[SIZE_ALLOCATE] =
1460 g_signal_new (I_("size-allocate"),
1461 G_TYPE_FROM_CLASS (gobject_class),
1463 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1465 _gtk_marshal_VOID__BOXED,
1467 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1470 * GtkWidget::state-changed:
1471 * @widget: the object which received the signal.
1472 * @state: the previous state
1474 * The ::state-changed signal is emitted when the widget state changes.
1475 * See gtk_widget_get_state().
1477 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1479 widget_signals[STATE_CHANGED] =
1480 g_signal_new (I_("state-changed"),
1481 G_TYPE_FROM_CLASS (gobject_class),
1483 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1485 _gtk_marshal_VOID__ENUM,
1487 GTK_TYPE_STATE_TYPE);
1490 * GtkWidget::state-flags-changed:
1491 * @widget: the object which received the signal.
1492 * @flags: The previous state flags.
1494 * The ::state-flags-changed signal is emitted when the widget state
1495 * changes, see gtk_widget_get_state_flags().
1499 widget_signals[STATE_FLAGS_CHANGED] =
1500 g_signal_new (I_("state-flags-changed"),
1501 G_TYPE_FROM_CLASS (gobject_class),
1503 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1505 _gtk_marshal_VOID__FLAGS,
1507 GTK_TYPE_STATE_FLAGS);
1510 * GtkWidget::parent-set:
1511 * @widget: the object on which the signal is emitted
1512 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1513 * just got its initial parent.
1515 * The ::parent-set signal is emitted when a new parent
1516 * has been set on a widget.
1518 widget_signals[PARENT_SET] =
1519 g_signal_new (I_("parent-set"),
1520 G_TYPE_FROM_CLASS (gobject_class),
1522 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1524 _gtk_marshal_VOID__OBJECT,
1529 * GtkWidget::hierarchy-changed:
1530 * @widget: the object on which the signal is emitted
1531 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1532 * if the widget was previously unanchored
1534 * The ::hierarchy-changed signal is emitted when the
1535 * anchored state of a widget changes. A widget is
1536 * <firstterm>anchored</firstterm> when its toplevel
1537 * ancestor is a #GtkWindow. This signal is emitted when
1538 * a widget changes from un-anchored to anchored or vice-versa.
1540 widget_signals[HIERARCHY_CHANGED] =
1541 g_signal_new (I_("hierarchy-changed"),
1542 G_TYPE_FROM_CLASS (gobject_class),
1544 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1546 _gtk_marshal_VOID__OBJECT,
1551 * GtkWidget::style-set:
1552 * @widget: the object on which the signal is emitted
1553 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1554 * just got its initial style
1556 * The ::style-set signal is emitted when a new style has been set
1557 * on a widget. Note that style-modifying functions like
1558 * gtk_widget_modify_base() also cause this signal to be emitted.
1560 * Note that this signal is emitted for changes to the deprecated
1561 * #GtkStyle. To track changes to the #GtkStyleContext associated
1562 * with a widget, use the #GtkWidget::style-updated signal.
1564 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1566 widget_signals[STYLE_SET] =
1567 g_signal_new (I_("style-set"),
1568 G_TYPE_FROM_CLASS (gobject_class),
1570 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1572 _gtk_marshal_VOID__OBJECT,
1577 * GtkWidget::style-updated:
1578 * @widget: the object on which the signal is emitted
1580 * The ::style-updated signal is emitted when the #GtkStyleContext
1581 * of a widget is changed. Note that style-modifying functions like
1582 * gtk_widget_override_color() also cause this signal to be emitted.
1586 widget_signals[STYLE_UPDATED] =
1587 g_signal_new (I_("style-updated"),
1588 G_TYPE_FROM_CLASS (gobject_class),
1590 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1592 g_cclosure_marshal_VOID__VOID,
1596 * GtkWidget::direction-changed:
1597 * @widget: the object on which the signal is emitted
1598 * @previous_direction: the previous text direction of @widget
1600 * The ::direction-changed signal is emitted when the text direction
1601 * of a widget changes.
1603 widget_signals[DIRECTION_CHANGED] =
1604 g_signal_new (I_("direction-changed"),
1605 G_TYPE_FROM_CLASS (gobject_class),
1607 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1609 _gtk_marshal_VOID__ENUM,
1611 GTK_TYPE_TEXT_DIRECTION);
1614 * GtkWidget::grab-notify:
1615 * @widget: the object which received the signal
1616 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1617 * if it becomes unshadowed
1619 * The ::grab-notify signal is emitted when a widget becomes
1620 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1621 * another widget, or when it becomes unshadowed due to a grab
1624 * A widget is shadowed by a gtk_grab_add() when the topmost
1625 * grab widget in the grab stack of its window group is not
1628 widget_signals[GRAB_NOTIFY] =
1629 g_signal_new (I_("grab-notify"),
1630 G_TYPE_FROM_CLASS (gobject_class),
1632 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1634 _gtk_marshal_VOID__BOOLEAN,
1639 * GtkWidget::child-notify:
1640 * @widget: the object which received the signal
1641 * @pspec: the #GParamSpec of the changed child property
1643 * The ::child-notify signal is emitted for each
1644 * <link linkend="child-properties">child property</link> that has
1645 * changed on an object. The signal's detail holds the property name.
1647 widget_signals[CHILD_NOTIFY] =
1648 g_signal_new (I_("child-notify"),
1649 G_TYPE_FROM_CLASS (gobject_class),
1650 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1651 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1653 g_cclosure_marshal_VOID__PARAM,
1659 * @widget: the object which received the signal
1660 * @cr: the cairo context to draw to
1662 * This signal is emitted when a widget is supposed to render itself.
1663 * The @widget's top left corner must be painted at the origin of
1664 * the passed in context and be sized to the values returned by
1665 * gtk_widget_get_allocated_width() and
1666 * gtk_widget_get_allocated_height().
1668 * Signal handlers connected to this signal can modify the cairo
1669 * context passed as @cr in any way they like and don't need to
1670 * restore it. The signal emission takes care of calling cairo_save()
1671 * before and cairo_restore() after invoking the handler.
1673 widget_signals[DRAW] =
1674 g_signal_new (I_("draw"),
1675 G_TYPE_FROM_CLASS (gobject_class),
1677 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1678 _gtk_boolean_handled_accumulator, NULL,
1679 gtk_widget_draw_marshaller,
1681 CAIRO_GOBJECT_TYPE_CONTEXT);
1684 * GtkWidget::mnemonic-activate:
1685 * @widget: the object which received the signal.
1688 widget_signals[MNEMONIC_ACTIVATE] =
1689 g_signal_new (I_("mnemonic-activate"),
1690 G_TYPE_FROM_CLASS (gobject_class),
1692 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1693 _gtk_boolean_handled_accumulator, NULL,
1694 _gtk_marshal_BOOLEAN__BOOLEAN,
1699 * GtkWidget::grab-focus:
1700 * @widget: the object which received the signal.
1702 widget_signals[GRAB_FOCUS] =
1703 g_signal_new (I_("grab-focus"),
1704 G_TYPE_FROM_CLASS (gobject_class),
1705 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1706 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1708 _gtk_marshal_VOID__VOID,
1713 * @widget: the object which received the signal.
1716 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1718 widget_signals[FOCUS] =
1719 g_signal_new (I_("focus"),
1720 G_TYPE_FROM_CLASS (klass),
1722 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1723 _gtk_boolean_handled_accumulator, NULL,
1724 _gtk_marshal_BOOLEAN__ENUM,
1726 GTK_TYPE_DIRECTION_TYPE);
1729 * GtkWidget::move-focus:
1730 * @widget: the object which received the signal.
1733 widget_signals[MOVE_FOCUS] =
1734 g_signal_new (I_("move-focus"),
1735 G_TYPE_FROM_CLASS (klass),
1736 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1737 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1739 _gtk_marshal_VOID__ENUM,
1742 GTK_TYPE_DIRECTION_TYPE);
1745 * GtkWidget::keynav-failed:
1746 * @widget: the object which received the signal
1747 * @direction: the direction of movement
1749 * Gets emitted if keyboard navigation fails.
1750 * See gtk_widget_keynav_failed() for details.
1752 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1753 * if the emitting widget should try to handle the keyboard
1754 * navigation attempt in its parent container(s).
1758 widget_signals[KEYNAV_FAILED] =
1759 g_signal_new (I_("keynav-failed"),
1760 G_TYPE_FROM_CLASS (klass),
1762 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1763 _gtk_boolean_handled_accumulator, NULL,
1764 _gtk_marshal_BOOLEAN__ENUM,
1766 GTK_TYPE_DIRECTION_TYPE);
1770 * @widget: the object which received the signal.
1771 * @event: the #GdkEvent which triggered this signal
1773 * The GTK+ main loop will emit three signals for each GDK event delivered
1774 * to a widget: one generic ::event signal, another, more specific,
1775 * signal that matches the type of event delivered (e.g.
1776 * #GtkWidget::key-press-event) and finally a generic
1777 * #GtkWidget::event-after signal.
1779 * Returns: %TRUE to stop other handlers from being invoked for the event
1780 * and to cancel the emission of the second specific ::event signal.
1781 * %FALSE to propagate the event further and to allow the emission of
1782 * the second signal. The ::event-after signal is emitted regardless of
1785 widget_signals[EVENT] =
1786 g_signal_new (I_("event"),
1787 G_TYPE_FROM_CLASS (klass),
1789 G_STRUCT_OFFSET (GtkWidgetClass, event),
1790 _gtk_boolean_handled_accumulator, NULL,
1791 _gtk_marshal_BOOLEAN__BOXED,
1793 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1796 * GtkWidget::event-after:
1797 * @widget: the object which received the signal.
1798 * @event: the #GdkEvent which triggered this signal
1800 * After the emission of the #GtkWidget::event signal and (optionally)
1801 * the second more specific signal, ::event-after will be emitted
1802 * regardless of the previous two signals handlers return values.
1805 widget_signals[EVENT_AFTER] =
1806 g_signal_new (I_("event-after"),
1807 G_TYPE_FROM_CLASS (klass),
1811 _gtk_marshal_VOID__BOXED,
1813 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1816 * GtkWidget::button-press-event:
1817 * @widget: the object which received the signal.
1818 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1821 * The ::button-press-event signal will be emitted when a button
1822 * (typically from a mouse) is pressed.
1824 * To receive this signal, the #GdkWindow associated to the
1825 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1827 * This signal will be sent to the grab widget if there is one.
1829 * Returns: %TRUE to stop other handlers from being invoked for the event.
1830 * %FALSE to propagate the event further.
1832 widget_signals[BUTTON_PRESS_EVENT] =
1833 g_signal_new (I_("button-press-event"),
1834 G_TYPE_FROM_CLASS (klass),
1836 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1837 _gtk_boolean_handled_accumulator, NULL,
1838 _gtk_marshal_BOOLEAN__BOXED,
1840 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1843 * GtkWidget::button-release-event:
1844 * @widget: the object which received the signal.
1845 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1848 * The ::button-release-event signal will be emitted when a button
1849 * (typically from a mouse) is released.
1851 * To receive this signal, the #GdkWindow associated to the
1852 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1854 * This signal will be sent to the grab widget if there is one.
1856 * Returns: %TRUE to stop other handlers from being invoked for the event.
1857 * %FALSE to propagate the event further.
1859 widget_signals[BUTTON_RELEASE_EVENT] =
1860 g_signal_new (I_("button-release-event"),
1861 G_TYPE_FROM_CLASS (klass),
1863 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1864 _gtk_boolean_handled_accumulator, NULL,
1865 _gtk_marshal_BOOLEAN__BOXED,
1867 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1870 * GtkWidget::scroll-event:
1871 * @widget: the object which received the signal.
1872 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1875 * The ::scroll-event signal is emitted when a button in the 4 to 7
1876 * range is pressed. Wheel mice are usually configured to generate
1877 * button press events for buttons 4 and 5 when the wheel is turned.
1879 * To receive this signal, the #GdkWindow associated to the widget needs
1880 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1882 * This signal will be sent to the grab widget if there is one.
1884 * Returns: %TRUE to stop other handlers from being invoked for the event.
1885 * %FALSE to propagate the event further.
1887 widget_signals[SCROLL_EVENT] =
1888 g_signal_new (I_("scroll-event"),
1889 G_TYPE_FROM_CLASS (klass),
1891 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1892 _gtk_boolean_handled_accumulator, NULL,
1893 _gtk_marshal_BOOLEAN__BOXED,
1895 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1898 * GtkWidget::motion-notify-event:
1899 * @widget: the object which received the signal.
1900 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1903 * The ::motion-notify-event signal is emitted when the pointer moves
1904 * over the widget's #GdkWindow.
1906 * To receive this signal, the #GdkWindow associated to the widget
1907 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1909 * This signal will be sent to the grab widget if there is one.
1911 * Returns: %TRUE to stop other handlers from being invoked for the event.
1912 * %FALSE to propagate the event further.
1914 widget_signals[MOTION_NOTIFY_EVENT] =
1915 g_signal_new (I_("motion-notify-event"),
1916 G_TYPE_FROM_CLASS (klass),
1918 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1919 _gtk_boolean_handled_accumulator, NULL,
1920 _gtk_marshal_BOOLEAN__BOXED,
1922 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1925 * GtkWidget::composited-changed:
1926 * @widget: the object on which the signal is emitted
1928 * The ::composited-changed signal is emitted when the composited
1929 * status of @widget<!-- -->s screen changes.
1930 * See gdk_screen_is_composited().
1932 widget_signals[COMPOSITED_CHANGED] =
1933 g_signal_new (I_("composited-changed"),
1934 G_TYPE_FROM_CLASS (klass),
1935 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1936 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1938 _gtk_marshal_VOID__VOID,
1942 * GtkWidget::delete-event:
1943 * @widget: the object which received the signal
1944 * @event: the event which triggered this signal
1946 * The ::delete-event signal is emitted if a user requests that
1947 * a toplevel window is closed. The default handler for this signal
1948 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1949 * this signal will cause the window to be hidden instead, so that
1950 * it can later be shown again without reconstructing it.
1952 * Returns: %TRUE to stop other handlers from being invoked for the event.
1953 * %FALSE to propagate the event further.
1955 widget_signals[DELETE_EVENT] =
1956 g_signal_new (I_("delete-event"),
1957 G_TYPE_FROM_CLASS (klass),
1959 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1960 _gtk_boolean_handled_accumulator, NULL,
1961 _gtk_marshal_BOOLEAN__BOXED,
1963 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1966 * GtkWidget::destroy-event:
1967 * @widget: the object which received the signal.
1968 * @event: the event which triggered this signal
1970 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1971 * You rarely get this signal, because most widgets disconnect themselves
1972 * from their window before they destroy it, so no widget owns the
1973 * window at destroy time.
1975 * To receive this signal, the #GdkWindow associated to the widget needs
1976 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1977 * automatically for all new windows.
1979 * Returns: %TRUE to stop other handlers from being invoked for the event.
1980 * %FALSE to propagate the event further.
1982 widget_signals[DESTROY_EVENT] =
1983 g_signal_new (I_("destroy-event"),
1984 G_TYPE_FROM_CLASS (klass),
1986 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1987 _gtk_boolean_handled_accumulator, NULL,
1988 _gtk_marshal_BOOLEAN__BOXED,
1990 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1993 * GtkWidget::key-press-event:
1994 * @widget: the object which received the signal
1995 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1997 * The ::key-press-event signal is emitted when a key is pressed. The signal
1998 * emission will reoccur at the key-repeat rate when the key is kept pressed.
2000 * To receive this signal, the #GdkWindow associated to the widget needs
2001 * to enable the #GDK_KEY_PRESS_MASK mask.
2003 * This signal will be sent to the grab widget if there is one.
2005 * Returns: %TRUE to stop other handlers from being invoked for the event.
2006 * %FALSE to propagate the event further.
2008 widget_signals[KEY_PRESS_EVENT] =
2009 g_signal_new (I_("key-press-event"),
2010 G_TYPE_FROM_CLASS (klass),
2012 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
2013 _gtk_boolean_handled_accumulator, NULL,
2014 _gtk_marshal_BOOLEAN__BOXED,
2016 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2019 * GtkWidget::key-release-event:
2020 * @widget: the object which received the signal
2021 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2023 * The ::key-release-event signal is emitted when a key is released.
2025 * To receive this signal, the #GdkWindow associated to the widget needs
2026 * to enable the #GDK_KEY_RELEASE_MASK mask.
2028 * This signal will be sent to the grab widget if there is one.
2030 * Returns: %TRUE to stop other handlers from being invoked for the event.
2031 * %FALSE to propagate the event further.
2033 widget_signals[KEY_RELEASE_EVENT] =
2034 g_signal_new (I_("key-release-event"),
2035 G_TYPE_FROM_CLASS (klass),
2037 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2038 _gtk_boolean_handled_accumulator, NULL,
2039 _gtk_marshal_BOOLEAN__BOXED,
2041 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2044 * GtkWidget::enter-notify-event:
2045 * @widget: the object which received the signal
2046 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2049 * The ::enter-notify-event will be emitted when the pointer enters
2050 * the @widget's window.
2052 * To receive this signal, the #GdkWindow associated to the widget needs
2053 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2055 * This signal will be sent to the grab widget if there is one.
2057 * Returns: %TRUE to stop other handlers from being invoked for the event.
2058 * %FALSE to propagate the event further.
2060 widget_signals[ENTER_NOTIFY_EVENT] =
2061 g_signal_new (I_("enter-notify-event"),
2062 G_TYPE_FROM_CLASS (klass),
2064 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2065 _gtk_boolean_handled_accumulator, NULL,
2066 _gtk_marshal_BOOLEAN__BOXED,
2068 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2071 * GtkWidget::leave-notify-event:
2072 * @widget: the object which received the signal
2073 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2076 * The ::leave-notify-event will be emitted when the pointer leaves
2077 * the @widget's window.
2079 * To receive this signal, the #GdkWindow associated to the widget needs
2080 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2082 * This signal will be sent to the grab widget if there is one.
2084 * Returns: %TRUE to stop other handlers from being invoked for the event.
2085 * %FALSE to propagate the event further.
2087 widget_signals[LEAVE_NOTIFY_EVENT] =
2088 g_signal_new (I_("leave-notify-event"),
2089 G_TYPE_FROM_CLASS (klass),
2091 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2092 _gtk_boolean_handled_accumulator, NULL,
2093 _gtk_marshal_BOOLEAN__BOXED,
2095 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2098 * GtkWidget::configure-event:
2099 * @widget: the object which received the signal
2100 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2103 * The ::configure-event signal will be emitted when the size, position or
2104 * stacking of the @widget's window has changed.
2106 * To receive this signal, the #GdkWindow associated to the widget needs
2107 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2108 * automatically for all new windows.
2110 * Returns: %TRUE to stop other handlers from being invoked for the event.
2111 * %FALSE to propagate the event further.
2113 widget_signals[CONFIGURE_EVENT] =
2114 g_signal_new (I_("configure-event"),
2115 G_TYPE_FROM_CLASS (klass),
2117 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2118 _gtk_boolean_handled_accumulator, NULL,
2119 _gtk_marshal_BOOLEAN__BOXED,
2121 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2124 * GtkWidget::focus-in-event:
2125 * @widget: the object which received the signal
2126 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2129 * The ::focus-in-event signal will be emitted when the keyboard focus
2130 * enters the @widget's window.
2132 * To receive this signal, the #GdkWindow associated to the widget needs
2133 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2135 * Returns: %TRUE to stop other handlers from being invoked for the event.
2136 * %FALSE to propagate the event further.
2138 widget_signals[FOCUS_IN_EVENT] =
2139 g_signal_new (I_("focus-in-event"),
2140 G_TYPE_FROM_CLASS (klass),
2142 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2143 _gtk_boolean_handled_accumulator, NULL,
2144 _gtk_marshal_BOOLEAN__BOXED,
2146 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2149 * GtkWidget::focus-out-event:
2150 * @widget: the object which received the signal
2151 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2154 * The ::focus-out-event signal will be emitted when the keyboard focus
2155 * leaves the @widget's window.
2157 * To receive this signal, the #GdkWindow associated to the widget needs
2158 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2160 * Returns: %TRUE to stop other handlers from being invoked for the event.
2161 * %FALSE to propagate the event further.
2163 widget_signals[FOCUS_OUT_EVENT] =
2164 g_signal_new (I_("focus-out-event"),
2165 G_TYPE_FROM_CLASS (klass),
2167 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2168 _gtk_boolean_handled_accumulator, NULL,
2169 _gtk_marshal_BOOLEAN__BOXED,
2171 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2174 * GtkWidget::map-event:
2175 * @widget: the object which received the signal
2176 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2178 * The ::map-event signal will be emitted when the @widget's window is
2179 * mapped. A window is mapped when it becomes visible on the screen.
2181 * To receive this signal, the #GdkWindow associated to the widget needs
2182 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2183 * automatically for all new windows.
2185 * Returns: %TRUE to stop other handlers from being invoked for the event.
2186 * %FALSE to propagate the event further.
2188 widget_signals[MAP_EVENT] =
2189 g_signal_new (I_("map-event"),
2190 G_TYPE_FROM_CLASS (klass),
2192 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2193 _gtk_boolean_handled_accumulator, NULL,
2194 _gtk_marshal_BOOLEAN__BOXED,
2196 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2199 * GtkWidget::unmap-event:
2200 * @widget: the object which received the signal
2201 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2203 * The ::unmap-event signal will be emitted when the @widget's window is
2204 * unmapped. A window is unmapped when it becomes invisible on the screen.
2206 * To receive this signal, the #GdkWindow associated to the widget needs
2207 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2208 * automatically for all new windows.
2210 * Returns: %TRUE to stop other handlers from being invoked for the event.
2211 * %FALSE to propagate the event further.
2213 widget_signals[UNMAP_EVENT] =
2214 g_signal_new (I_("unmap-event"),
2215 G_TYPE_FROM_CLASS (klass),
2217 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2218 _gtk_boolean_handled_accumulator, NULL,
2219 _gtk_marshal_BOOLEAN__BOXED,
2221 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2224 * GtkWidget::property-notify-event:
2225 * @widget: the object which received the signal
2226 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2229 * The ::property-notify-event signal will be emitted when a property on
2230 * the @widget's window has been changed or deleted.
2232 * To receive this signal, the #GdkWindow associated to the widget needs
2233 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2235 * Returns: %TRUE to stop other handlers from being invoked for the event.
2236 * %FALSE to propagate the event further.
2238 widget_signals[PROPERTY_NOTIFY_EVENT] =
2239 g_signal_new (I_("property-notify-event"),
2240 G_TYPE_FROM_CLASS (klass),
2242 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2243 _gtk_boolean_handled_accumulator, NULL,
2244 _gtk_marshal_BOOLEAN__BOXED,
2246 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2249 * GtkWidget::selection-clear-event:
2250 * @widget: the object which received the signal
2251 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2254 * The ::selection-clear-event signal will be emitted when the
2255 * the @widget's window has lost ownership of a selection.
2257 * Returns: %TRUE to stop other handlers from being invoked for the event.
2258 * %FALSE to propagate the event further.
2260 widget_signals[SELECTION_CLEAR_EVENT] =
2261 g_signal_new (I_("selection-clear-event"),
2262 G_TYPE_FROM_CLASS (klass),
2264 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2265 _gtk_boolean_handled_accumulator, NULL,
2266 _gtk_marshal_BOOLEAN__BOXED,
2268 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2271 * GtkWidget::selection-request-event:
2272 * @widget: the object which received the signal
2273 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2276 * The ::selection-request-event signal will be emitted when
2277 * another client requests ownership of the selection owned by
2278 * the @widget's window.
2280 * Returns: %TRUE to stop other handlers from being invoked for the event.
2281 * %FALSE to propagate the event further.
2283 widget_signals[SELECTION_REQUEST_EVENT] =
2284 g_signal_new (I_("selection-request-event"),
2285 G_TYPE_FROM_CLASS (klass),
2287 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2288 _gtk_boolean_handled_accumulator, NULL,
2289 _gtk_marshal_BOOLEAN__BOXED,
2291 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2294 * GtkWidget::selection-notify-event:
2295 * @widget: the object which received the signal.
2296 * @event: (type Gdk.EventSelection):
2298 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2300 widget_signals[SELECTION_NOTIFY_EVENT] =
2301 g_signal_new (I_("selection-notify-event"),
2302 G_TYPE_FROM_CLASS (klass),
2304 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2305 _gtk_boolean_handled_accumulator, NULL,
2306 _gtk_marshal_BOOLEAN__BOXED,
2308 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2311 * GtkWidget::selection-received:
2312 * @widget: the object which received the signal.
2316 widget_signals[SELECTION_RECEIVED] =
2317 g_signal_new (I_("selection-received"),
2318 G_TYPE_FROM_CLASS (klass),
2320 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2322 _gtk_marshal_VOID__BOXED_UINT,
2324 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2328 * GtkWidget::selection-get:
2329 * @widget: the object which received the signal.
2334 widget_signals[SELECTION_GET] =
2335 g_signal_new (I_("selection-get"),
2336 G_TYPE_FROM_CLASS (klass),
2338 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2340 _gtk_marshal_VOID__BOXED_UINT_UINT,
2342 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2347 * GtkWidget::proximity-in-event:
2348 * @widget: the object which received the signal
2349 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2352 * To receive this signal the #GdkWindow associated to the widget needs
2353 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2355 * This signal will be sent to the grab widget if there is one.
2357 * Returns: %TRUE to stop other handlers from being invoked for the event.
2358 * %FALSE to propagate the event further.
2360 widget_signals[PROXIMITY_IN_EVENT] =
2361 g_signal_new (I_("proximity-in-event"),
2362 G_TYPE_FROM_CLASS (klass),
2364 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2365 _gtk_boolean_handled_accumulator, NULL,
2366 _gtk_marshal_BOOLEAN__BOXED,
2368 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2371 * GtkWidget::proximity-out-event:
2372 * @widget: the object which received the signal
2373 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2376 * To receive this signal the #GdkWindow associated to the widget needs
2377 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2379 * This signal will be sent to the grab widget if there is one.
2381 * Returns: %TRUE to stop other handlers from being invoked for the event.
2382 * %FALSE to propagate the event further.
2384 widget_signals[PROXIMITY_OUT_EVENT] =
2385 g_signal_new (I_("proximity-out-event"),
2386 G_TYPE_FROM_CLASS (klass),
2388 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2389 _gtk_boolean_handled_accumulator, NULL,
2390 _gtk_marshal_BOOLEAN__BOXED,
2392 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2395 * GtkWidget::drag-leave:
2396 * @widget: the object which received the signal.
2397 * @drag_context: the drag context
2398 * @time: the timestamp of the motion event
2400 * The ::drag-leave signal is emitted on the drop site when the cursor
2401 * leaves the widget. A typical reason to connect to this signal is to
2402 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2403 * with gtk_drag_unhighlight()
2405 widget_signals[DRAG_LEAVE] =
2406 g_signal_new (I_("drag-leave"),
2407 G_TYPE_FROM_CLASS (klass),
2409 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2411 _gtk_marshal_VOID__OBJECT_UINT,
2413 GDK_TYPE_DRAG_CONTEXT,
2417 * GtkWidget::drag-begin:
2418 * @widget: the object which received the signal
2419 * @drag_context: the drag context
2421 * The ::drag-begin signal is emitted on the drag source when a drag is
2422 * started. A typical reason to connect to this signal is to set up a
2423 * custom drag icon with gtk_drag_source_set_icon().
2425 * Note that some widgets set up a drag icon in the default handler of
2426 * this signal, so you may have to use g_signal_connect_after() to
2427 * override what the default handler did.
2429 widget_signals[DRAG_BEGIN] =
2430 g_signal_new (I_("drag-begin"),
2431 G_TYPE_FROM_CLASS (klass),
2433 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2435 _gtk_marshal_VOID__OBJECT,
2437 GDK_TYPE_DRAG_CONTEXT);
2440 * GtkWidget::drag-end:
2441 * @widget: the object which received the signal
2442 * @drag_context: the drag context
2444 * The ::drag-end signal is emitted on the drag source when a drag is
2445 * finished. A typical reason to connect to this signal is to undo
2446 * things done in #GtkWidget::drag-begin.
2448 widget_signals[DRAG_END] =
2449 g_signal_new (I_("drag-end"),
2450 G_TYPE_FROM_CLASS (klass),
2452 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2454 _gtk_marshal_VOID__OBJECT,
2456 GDK_TYPE_DRAG_CONTEXT);
2459 * GtkWidget::drag-data-delete:
2460 * @widget: the object which received the signal
2461 * @drag_context: the drag context
2463 * The ::drag-data-delete signal is emitted on the drag source when a drag
2464 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2465 * handler is responsible for deleting the data that has been dropped. What
2466 * "delete" means depends on the context of the drag operation.
2468 widget_signals[DRAG_DATA_DELETE] =
2469 g_signal_new (I_("drag-data-delete"),
2470 G_TYPE_FROM_CLASS (klass),
2472 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2474 _gtk_marshal_VOID__OBJECT,
2476 GDK_TYPE_DRAG_CONTEXT);
2479 * GtkWidget::drag-failed:
2480 * @widget: the object which received the signal
2481 * @drag_context: the drag context
2482 * @result: the result of the drag operation
2484 * The ::drag-failed signal is emitted on the drag source when a drag has
2485 * failed. The signal handler may hook custom code to handle a failed DND
2486 * operation based on the type of error, it returns %TRUE is the failure has
2487 * been already handled (not showing the default "drag operation failed"
2488 * animation), otherwise it returns %FALSE.
2490 * Return value: %TRUE if the failed drag operation has been already handled.
2494 widget_signals[DRAG_FAILED] =
2495 g_signal_new (I_("drag-failed"),
2496 G_TYPE_FROM_CLASS (klass),
2498 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2499 _gtk_boolean_handled_accumulator, NULL,
2500 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2502 GDK_TYPE_DRAG_CONTEXT,
2503 GTK_TYPE_DRAG_RESULT);
2506 * GtkWidget::drag-motion:
2507 * @widget: the object which received the signal
2508 * @drag_context: the drag context
2509 * @x: the x coordinate of the current cursor position
2510 * @y: the y coordinate of the current cursor position
2511 * @time: the timestamp of the motion event
2512 * @returns: whether the cursor position is in a drop zone
2514 * The drag-motion signal is emitted on the drop site when the user
2515 * moves the cursor over the widget during a drag. The signal handler
2516 * must determine whether the cursor position is in a drop zone or not.
2517 * If it is not in a drop zone, it returns %FALSE and no further processing
2518 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2519 * handler is responsible for providing the necessary information for
2520 * displaying feedback to the user, by calling gdk_drag_status().
2522 * If the decision whether the drop will be accepted or rejected can't be
2523 * made based solely on the cursor position and the type of the data, the
2524 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2525 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2526 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2527 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2528 * when using the drag-motion signal that way.
2530 * Also note that there is no drag-enter signal. The drag receiver has to
2531 * keep track of whether he has received any drag-motion signals since the
2532 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2533 * an "enter" signal. Upon an "enter", the handler will typically highlight
2534 * the drop site with gtk_drag_highlight().
2537 * drag_motion (GtkWidget *widget,
2538 * GdkDragContext *context,
2545 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2547 * if (!private_data->drag_highlight)
2549 * private_data->drag_highlight = 1;
2550 * gtk_drag_highlight (widget);
2553 * target = gtk_drag_dest_find_target (widget, context, NULL);
2554 * if (target == GDK_NONE)
2555 * gdk_drag_status (context, 0, time);
2558 * private_data->pending_status = context->suggested_action;
2559 * gtk_drag_get_data (widget, context, target, time);
2566 * drag_data_received (GtkWidget *widget,
2567 * GdkDragContext *context,
2570 * GtkSelectionData *selection_data,
2574 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2576 * if (private_data->suggested_action)
2578 * private_data->suggested_action = 0;
2580 * /* We are getting this data due to a request in drag_motion,
2581 * * rather than due to a request in drag_drop, so we are just
2582 * * supposed to call gdk_drag_status (), not actually paste in
2585 * str = gtk_selection_data_get_text (selection_data);
2586 * if (!data_is_acceptable (str))
2587 * gdk_drag_status (context, 0, time);
2589 * gdk_drag_status (context, private_data->suggested_action, time);
2593 * /* accept the drop */
2598 widget_signals[DRAG_MOTION] =
2599 g_signal_new (I_("drag-motion"),
2600 G_TYPE_FROM_CLASS (klass),
2602 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2603 _gtk_boolean_handled_accumulator, NULL,
2604 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2606 GDK_TYPE_DRAG_CONTEXT,
2612 * GtkWidget::drag-drop:
2613 * @widget: the object which received the signal
2614 * @drag_context: the drag context
2615 * @x: the x coordinate of the current cursor position
2616 * @y: the y coordinate of the current cursor position
2617 * @time: the timestamp of the motion event
2618 * @returns: whether the cursor position is in a drop zone
2620 * The ::drag-drop signal is emitted on the drop site when the user drops
2621 * the data onto the widget. The signal handler must determine whether
2622 * the cursor position is in a drop zone or not. If it is not in a drop
2623 * zone, it returns %FALSE and no further processing is necessary.
2624 * Otherwise, the handler returns %TRUE. In this case, the handler must
2625 * ensure that gtk_drag_finish() is called to let the source know that
2626 * the drop is done. The call to gtk_drag_finish() can be done either
2627 * directly or in a #GtkWidget::drag-data-received handler which gets
2628 * triggered by calling gtk_drag_get_data() to receive the data for one
2629 * or more of the supported targets.
2631 widget_signals[DRAG_DROP] =
2632 g_signal_new (I_("drag-drop"),
2633 G_TYPE_FROM_CLASS (klass),
2635 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2636 _gtk_boolean_handled_accumulator, NULL,
2637 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2639 GDK_TYPE_DRAG_CONTEXT,
2645 * GtkWidget::drag-data-get:
2646 * @widget: the object which received the signal
2647 * @drag_context: the drag context
2648 * @data: the #GtkSelectionData to be filled with the dragged data
2649 * @info: the info that has been registered with the target in the
2651 * @time: the timestamp at which the data was requested
2653 * The ::drag-data-get signal is emitted on the drag source when the drop
2654 * site requests the data which is dragged. It is the responsibility of
2655 * the signal handler to fill @data with the data in the format which
2656 * is indicated by @info. See gtk_selection_data_set() and
2657 * gtk_selection_data_set_text().
2659 widget_signals[DRAG_DATA_GET] =
2660 g_signal_new (I_("drag-data-get"),
2661 G_TYPE_FROM_CLASS (klass),
2663 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2665 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2667 GDK_TYPE_DRAG_CONTEXT,
2668 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2673 * GtkWidget::drag-data-received:
2674 * @widget: the object which received the signal
2675 * @drag_context: the drag context
2676 * @x: where the drop happened
2677 * @y: where the drop happened
2678 * @data: the received data
2679 * @info: the info that has been registered with the target in the
2681 * @time: the timestamp at which the data was received
2683 * The ::drag-data-received signal is emitted on the drop site when the
2684 * dragged data has been received. If the data was received in order to
2685 * determine whether the drop will be accepted, the handler is expected
2686 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2687 * If the data was received in response to a #GtkWidget::drag-drop signal
2688 * (and this is the last target to be received), the handler for this
2689 * signal is expected to process the received data and then call
2690 * gtk_drag_finish(), setting the @success parameter depending on whether
2691 * the data was processed successfully.
2693 * The handler may inspect and modify @drag_context->action before calling
2694 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2695 * following example:
2698 * drag_data_received (GtkWidget *widget,
2699 * GdkDragContext *drag_context,
2702 * GtkSelectionData *data,
2706 * if ((data->length >= 0) && (data->format == 8))
2708 * if (drag_context->action == GDK_ACTION_ASK)
2710 * GtkWidget *dialog;
2713 * dialog = gtk_message_dialog_new (NULL,
2714 * GTK_DIALOG_MODAL |
2715 * GTK_DIALOG_DESTROY_WITH_PARENT,
2717 * GTK_BUTTONS_YES_NO,
2718 * "Move the data ?\n");
2719 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2720 * gtk_widget_destroy (dialog);
2722 * if (response == GTK_RESPONSE_YES)
2723 * drag_context->action = GDK_ACTION_MOVE;
2725 * drag_context->action = GDK_ACTION_COPY;
2728 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2732 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2736 widget_signals[DRAG_DATA_RECEIVED] =
2737 g_signal_new (I_("drag-data-received"),
2738 G_TYPE_FROM_CLASS (klass),
2740 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2742 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2744 GDK_TYPE_DRAG_CONTEXT,
2747 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2752 * GtkWidget::visibility-notify-event:
2753 * @widget: the object which received the signal
2754 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2755 * triggered this signal.
2757 * The ::visibility-notify-event will be emitted when the @widget's window
2758 * is obscured or unobscured.
2760 * To receive this signal the #GdkWindow associated to the widget needs
2761 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2763 * Returns: %TRUE to stop other handlers from being invoked for the event.
2764 * %FALSE to propagate the event further.
2766 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2767 g_signal_new (I_("visibility-notify-event"),
2768 G_TYPE_FROM_CLASS (klass),
2770 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2771 _gtk_boolean_handled_accumulator, NULL,
2772 _gtk_marshal_BOOLEAN__BOXED,
2774 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2777 * GtkWidget::window-state-event:
2778 * @widget: the object which received the signal
2779 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2780 * triggered this signal.
2782 * The ::window-state-event will be emitted when the state of the
2783 * toplevel window associated to the @widget changes.
2785 * To receive this signal the #GdkWindow associated to the widget
2786 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2787 * this mask automatically for all new windows.
2789 * Returns: %TRUE to stop other handlers from being invoked for the
2790 * event. %FALSE to propagate the event further.
2792 widget_signals[WINDOW_STATE_EVENT] =
2793 g_signal_new (I_("window-state-event"),
2794 G_TYPE_FROM_CLASS (klass),
2796 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2797 _gtk_boolean_handled_accumulator, NULL,
2798 _gtk_marshal_BOOLEAN__BOXED,
2800 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2803 * GtkWidget::damage-event:
2804 * @widget: the object which received the signal
2805 * @event: (type Gdk.EventExpose): the #GdkEventExpose event
2807 * Emitted when a redirected window belonging to @widget gets drawn into.
2808 * The region/area members of the event shows what area of the redirected
2809 * drawable was drawn into.
2811 * Returns: %TRUE to stop other handlers from being invoked for the event.
2812 * %FALSE to propagate the event further.
2816 widget_signals[DAMAGE_EVENT] =
2817 g_signal_new (I_("damage-event"),
2818 G_TYPE_FROM_CLASS (klass),
2820 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2821 _gtk_boolean_handled_accumulator, NULL,
2822 _gtk_marshal_BOOLEAN__BOXED,
2824 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2827 * GtkWidget::grab-broken-event:
2828 * @widget: the object which received the signal
2829 * @event: (type Gdk.EventGrabBroken): the #GdkEventGrabBroken event
2831 * Emitted when a pointer or keyboard grab on a window belonging
2832 * to @widget gets broken.
2834 * On X11, this happens when the grab window becomes unviewable
2835 * (i.e. it or one of its ancestors is unmapped), or if the same
2836 * application grabs the pointer or keyboard again.
2838 * Returns: %TRUE to stop other handlers from being invoked for
2839 * the event. %FALSE to propagate the event further.
2843 widget_signals[GRAB_BROKEN_EVENT] =
2844 g_signal_new (I_("grab-broken-event"),
2845 G_TYPE_FROM_CLASS (klass),
2847 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2848 _gtk_boolean_handled_accumulator, NULL,
2849 _gtk_marshal_BOOLEAN__BOXED,
2851 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2854 * GtkWidget::query-tooltip:
2855 * @widget: the object which received the signal
2856 * @x: the x coordinate of the cursor position where the request has
2857 * been emitted, relative to @widget's left side
2858 * @y: the y coordinate of the cursor position where the request has
2859 * been emitted, relative to @widget's top
2860 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2861 * @tooltip: a #GtkTooltip
2863 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2864 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2865 * focus in keyboard mode.
2867 * Using the given coordinates, the signal handler should determine
2868 * whether a tooltip should be shown for @widget. If this is the case
2869 * %TRUE should be returned, %FALSE otherwise. Note that if
2870 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2871 * should not be used.
2873 * The signal handler is free to manipulate @tooltip with the therefore
2874 * destined function calls.
2876 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2880 widget_signals[QUERY_TOOLTIP] =
2881 g_signal_new (I_("query-tooltip"),
2882 G_TYPE_FROM_CLASS (klass),
2884 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2885 _gtk_boolean_handled_accumulator, NULL,
2886 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2894 * GtkWidget::popup-menu
2895 * @widget: the object which received the signal
2897 * This signal gets emitted whenever a widget should pop up a context
2898 * menu. This usually happens through the standard key binding mechanism;
2899 * by pressing a certain key while a widget is focused, the user can cause
2900 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2901 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2902 * for an example of how to use this signal.
2904 * Returns: %TRUE if a menu was activated
2906 widget_signals[POPUP_MENU] =
2907 g_signal_new (I_("popup-menu"),
2908 G_TYPE_FROM_CLASS (klass),
2909 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2910 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2911 _gtk_boolean_handled_accumulator, NULL,
2912 _gtk_marshal_BOOLEAN__VOID,
2916 * GtkWidget::show-help:
2917 * @widget: the object which received the signal.
2920 widget_signals[SHOW_HELP] =
2921 g_signal_new (I_("show-help"),
2922 G_TYPE_FROM_CLASS (klass),
2923 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2924 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2925 _gtk_boolean_handled_accumulator, NULL,
2926 _gtk_marshal_BOOLEAN__ENUM,
2928 GTK_TYPE_WIDGET_HELP_TYPE);
2931 * GtkWidget::accel-closures-changed:
2932 * @widget: the object which received the signal.
2934 widget_signals[ACCEL_CLOSURES_CHANGED] =
2935 g_signal_new (I_("accel-closures-changed"),
2936 G_TYPE_FROM_CLASS (klass),
2940 _gtk_marshal_VOID__VOID,
2944 * GtkWidget::screen-changed:
2945 * @widget: the object on which the signal is emitted
2946 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2947 * widget was not associated with a screen before
2949 * The ::screen-changed signal gets emitted when the
2950 * screen of a widget has changed.
2952 widget_signals[SCREEN_CHANGED] =
2953 g_signal_new (I_("screen-changed"),
2954 G_TYPE_FROM_CLASS (klass),
2956 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2958 _gtk_marshal_VOID__OBJECT,
2963 * GtkWidget::can-activate-accel:
2964 * @widget: the object which received the signal
2965 * @signal_id: the ID of a signal installed on @widget
2967 * Determines whether an accelerator that activates the signal
2968 * identified by @signal_id can currently be activated.
2969 * This signal is present to allow applications and derived
2970 * widgets to override the default #GtkWidget handling
2971 * for determining whether an accelerator can be activated.
2973 * Returns: %TRUE if the signal can be activated.
2975 widget_signals[CAN_ACTIVATE_ACCEL] =
2976 g_signal_new (I_("can-activate-accel"),
2977 G_TYPE_FROM_CLASS (klass),
2979 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2980 _gtk_boolean_handled_accumulator, NULL,
2981 _gtk_marshal_BOOLEAN__UINT,
2982 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2984 binding_set = gtk_binding_set_by_class (klass);
2985 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
2987 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
2990 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
2992 GTK_TYPE_WIDGET_HELP_TYPE,
2993 GTK_WIDGET_HELP_TOOLTIP);
2994 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
2996 GTK_TYPE_WIDGET_HELP_TYPE,
2997 GTK_WIDGET_HELP_TOOLTIP);
2998 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
3000 GTK_TYPE_WIDGET_HELP_TYPE,
3001 GTK_WIDGET_HELP_WHATS_THIS);
3002 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
3004 GTK_TYPE_WIDGET_HELP_TYPE,
3005 GTK_WIDGET_HELP_WHATS_THIS);
3007 gtk_widget_class_install_style_property (klass,
3008 g_param_spec_boolean ("interior-focus",
3009 P_("Interior Focus"),
3010 P_("Whether to draw the focus indicator inside widgets"),
3012 GTK_PARAM_READABLE));
3014 gtk_widget_class_install_style_property (klass,
3015 g_param_spec_int ("focus-line-width",
3016 P_("Focus linewidth"),
3017 P_("Width, in pixels, of the focus indicator line"),
3019 GTK_PARAM_READABLE));
3021 gtk_widget_class_install_style_property (klass,
3022 g_param_spec_string ("focus-line-pattern",
3023 P_("Focus line dash pattern"),
3024 P_("Dash pattern used to draw the focus indicator"),
3026 GTK_PARAM_READABLE));
3027 gtk_widget_class_install_style_property (klass,
3028 g_param_spec_int ("focus-padding",
3029 P_("Focus padding"),
3030 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3032 GTK_PARAM_READABLE));
3033 gtk_widget_class_install_style_property (klass,
3034 g_param_spec_boxed ("cursor-color",
3036 P_("Color with which to draw insertion cursor"),
3038 GTK_PARAM_READABLE));
3039 gtk_widget_class_install_style_property (klass,
3040 g_param_spec_boxed ("secondary-cursor-color",
3041 P_("Secondary cursor color"),
3042 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3044 GTK_PARAM_READABLE));
3045 gtk_widget_class_install_style_property (klass,
3046 g_param_spec_float ("cursor-aspect-ratio",
3047 P_("Cursor line aspect ratio"),
3048 P_("Aspect ratio with which to draw insertion cursor"),
3050 GTK_PARAM_READABLE));
3052 gtk_widget_class_install_style_property (klass,
3053 g_param_spec_boolean ("window-dragging",
3054 P_("Window dragging"),
3055 P_("Whether windows can be dragged by clicking on empty areas"),
3057 GTK_PARAM_READABLE));
3060 * GtkWidget:link-color:
3062 * The "link-color" style property defines the color of unvisited links.
3066 gtk_widget_class_install_style_property (klass,
3067 g_param_spec_boxed ("link-color",
3068 P_("Unvisited Link Color"),
3069 P_("Color of unvisited links"),
3071 GTK_PARAM_READABLE));
3074 * GtkWidget:visited-link-color:
3076 * The "visited-link-color" style property defines the color of visited links.
3080 gtk_widget_class_install_style_property (klass,
3081 g_param_spec_boxed ("visited-link-color",
3082 P_("Visited Link Color"),
3083 P_("Color of visited links"),
3085 GTK_PARAM_READABLE));
3088 * GtkWidget:wide-separators:
3090 * The "wide-separators" style property defines whether separators have
3091 * configurable width and should be drawn using a box instead of a line.
3095 gtk_widget_class_install_style_property (klass,
3096 g_param_spec_boolean ("wide-separators",
3097 P_("Wide Separators"),
3098 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3100 GTK_PARAM_READABLE));
3103 * GtkWidget:separator-width:
3105 * The "separator-width" style property defines the width of separators.
3106 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3110 gtk_widget_class_install_style_property (klass,
3111 g_param_spec_int ("separator-width",
3112 P_("Separator Width"),
3113 P_("The width of separators if wide-separators is TRUE"),
3115 GTK_PARAM_READABLE));
3118 * GtkWidget:separator-height:
3120 * The "separator-height" style property defines the height of separators.
3121 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3125 gtk_widget_class_install_style_property (klass,
3126 g_param_spec_int ("separator-height",
3127 P_("Separator Height"),
3128 P_("The height of separators if \"wide-separators\" is TRUE"),
3130 GTK_PARAM_READABLE));
3133 * GtkWidget:scroll-arrow-hlength:
3135 * The "scroll-arrow-hlength" style property defines the length of
3136 * horizontal scroll arrows.
3140 gtk_widget_class_install_style_property (klass,
3141 g_param_spec_int ("scroll-arrow-hlength",
3142 P_("Horizontal Scroll Arrow Length"),
3143 P_("The length of horizontal scroll arrows"),
3145 GTK_PARAM_READABLE));
3148 * GtkWidget:scroll-arrow-vlength:
3150 * The "scroll-arrow-vlength" style property defines the length of
3151 * vertical scroll arrows.
3155 gtk_widget_class_install_style_property (klass,
3156 g_param_spec_int ("scroll-arrow-vlength",
3157 P_("Vertical Scroll Arrow Length"),
3158 P_("The length of vertical scroll arrows"),
3160 GTK_PARAM_READABLE));
3162 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3166 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3170 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3171 for (node = list; node; node = node->next)
3173 GParamSpec *pspec = node->data;
3175 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3176 g_param_spec_unref (pspec);
3182 gtk_widget_set_property (GObject *object,
3184 const GValue *value,
3187 GtkWidget *widget = GTK_WIDGET (object);
3192 gchar *tooltip_markup;
3193 const gchar *tooltip_text;
3194 GtkWindow *tooltip_window;
3197 gtk_widget_set_name (widget, g_value_get_string (value));
3200 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3202 case PROP_WIDTH_REQUEST:
3203 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3205 case PROP_HEIGHT_REQUEST:
3206 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3209 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3211 case PROP_SENSITIVE:
3212 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3214 case PROP_APP_PAINTABLE:
3215 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3217 case PROP_CAN_FOCUS:
3218 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3220 case PROP_HAS_FOCUS:
3221 if (g_value_get_boolean (value))
3222 gtk_widget_grab_focus (widget);
3225 if (g_value_get_boolean (value))
3226 gtk_widget_grab_focus (widget);
3228 case PROP_CAN_DEFAULT:
3229 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3231 case PROP_HAS_DEFAULT:
3232 if (g_value_get_boolean (value))
3233 gtk_widget_grab_default (widget);
3235 case PROP_RECEIVES_DEFAULT:
3236 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3239 gtk_widget_set_style (widget, g_value_get_object (value));
3242 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3243 gtk_widget_set_events (widget, g_value_get_flags (value));
3245 case PROP_NO_SHOW_ALL:
3246 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3248 case PROP_HAS_TOOLTIP:
3249 gtk_widget_real_set_has_tooltip (widget,
3250 g_value_get_boolean (value), FALSE);
3252 case PROP_TOOLTIP_MARKUP:
3253 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3254 tooltip_markup = g_value_dup_string (value);
3256 /* Treat an empty string as a NULL string,
3257 * because an empty string would be useless for a tooltip:
3259 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3261 g_free (tooltip_markup);
3262 tooltip_markup = NULL;
3265 g_object_set_qdata_full (object, quark_tooltip_markup,
3266 tooltip_markup, g_free);
3268 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3269 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3270 if (gtk_widget_get_visible (widget))
3271 gtk_widget_queue_tooltip_query (widget);
3273 case PROP_TOOLTIP_TEXT:
3274 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3276 tooltip_text = g_value_get_string (value);
3278 /* Treat an empty string as a NULL string,
3279 * because an empty string would be useless for a tooltip:
3281 if (tooltip_text && (strlen (tooltip_text) == 0))
3282 tooltip_text = NULL;
3284 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3286 g_object_set_qdata_full (object, quark_tooltip_markup,
3287 tooltip_markup, g_free);
3289 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3290 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3291 if (gtk_widget_get_visible (widget))
3292 gtk_widget_queue_tooltip_query (widget);
3294 case PROP_DOUBLE_BUFFERED:
3295 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3298 gtk_widget_set_halign (widget, g_value_get_enum (value));
3301 gtk_widget_set_valign (widget, g_value_get_enum (value));
3303 case PROP_MARGIN_LEFT:
3304 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3306 case PROP_MARGIN_RIGHT:
3307 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3309 case PROP_MARGIN_TOP:
3310 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3312 case PROP_MARGIN_BOTTOM:
3313 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3316 g_object_freeze_notify (G_OBJECT (widget));
3317 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3318 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3319 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3320 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3321 g_object_thaw_notify (G_OBJECT (widget));
3324 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3326 case PROP_HEXPAND_SET:
3327 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3330 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3332 case PROP_VEXPAND_SET:
3333 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3336 g_object_freeze_notify (G_OBJECT (widget));
3337 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3338 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3339 g_object_thaw_notify (G_OBJECT (widget));
3342 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3348 gtk_widget_get_property (GObject *object,
3353 GtkWidget *widget = GTK_WIDGET (object);
3354 GtkWidgetPrivate *priv = widget->priv;
3362 g_value_set_string (value, priv->name);
3364 g_value_set_static_string (value, "");
3367 g_value_set_object (value, priv->parent);
3369 case PROP_WIDTH_REQUEST:
3372 gtk_widget_get_size_request (widget, &w, NULL);
3373 g_value_set_int (value, w);
3376 case PROP_HEIGHT_REQUEST:
3379 gtk_widget_get_size_request (widget, NULL, &h);
3380 g_value_set_int (value, h);
3384 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3386 case PROP_SENSITIVE:
3387 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3389 case PROP_APP_PAINTABLE:
3390 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3392 case PROP_CAN_FOCUS:
3393 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3395 case PROP_HAS_FOCUS:
3396 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3399 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3401 case PROP_CAN_DEFAULT:
3402 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3404 case PROP_HAS_DEFAULT:
3405 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3407 case PROP_RECEIVES_DEFAULT:
3408 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3410 case PROP_COMPOSITE_CHILD:
3411 g_value_set_boolean (value, widget->priv->composite_child);
3414 g_value_set_object (value, gtk_widget_get_style (widget));
3417 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3418 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3420 case PROP_NO_SHOW_ALL:
3421 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3423 case PROP_HAS_TOOLTIP:
3424 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3426 case PROP_TOOLTIP_TEXT:
3428 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3431 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3432 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3434 g_value_take_string (value, text);
3437 case PROP_TOOLTIP_MARKUP:
3438 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3441 g_value_set_object (value, gtk_widget_get_window (widget));
3443 case PROP_DOUBLE_BUFFERED:
3444 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3447 g_value_set_enum (value, gtk_widget_get_halign (widget));
3450 g_value_set_enum (value, gtk_widget_get_valign (widget));
3452 case PROP_MARGIN_LEFT:
3453 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3455 case PROP_MARGIN_RIGHT:
3456 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3458 case PROP_MARGIN_TOP:
3459 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3461 case PROP_MARGIN_BOTTOM:
3462 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3466 GtkWidgetAuxInfo *aux_info = gtk_widget_get_aux_info (widget, FALSE);
3467 if (aux_info == NULL)
3469 g_value_set_int (value, 0);
3473 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3474 aux_info->margin.right),
3475 MAX (aux_info->margin.top,
3476 aux_info->margin.bottom)));
3481 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3483 case PROP_HEXPAND_SET:
3484 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3487 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3489 case PROP_VEXPAND_SET:
3490 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3493 g_value_set_boolean (value,
3494 gtk_widget_get_hexpand (widget) &&
3495 gtk_widget_get_vexpand (widget));
3498 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3504 gtk_widget_init (GtkWidget *widget)
3506 GtkWidgetPrivate *priv;
3508 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3511 priv = widget->priv;
3513 priv->child_visible = TRUE;
3515 priv->allocation.x = -1;
3516 priv->allocation.y = -1;
3517 priv->allocation.width = 1;
3518 priv->allocation.height = 1;
3519 priv->window = NULL;
3520 priv->parent = NULL;
3522 priv->sensitive = TRUE;
3523 priv->composite_child = composite_child_stack != 0;
3524 priv->double_buffered = TRUE;
3525 priv->redraw_on_alloc = TRUE;
3526 priv->width_request_needed = TRUE;
3527 priv->height_request_needed = TRUE;
3528 priv->alloc_needed = TRUE;
3530 /* this will be set to TRUE if the widget gets a child or if the
3531 * expand flag is set on the widget, but until one of those happen
3532 * we know the expand is already properly FALSE.
3534 * We really want to default FALSE here to avoid computing expand
3535 * all over the place while initially building a widget tree.
3537 priv->need_compute_expand = FALSE;
3539 priv->style = gtk_widget_get_default_style ();
3540 g_object_ref (priv->style);
3545 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3547 GParamSpec **pspecs)
3549 GtkWidgetPrivate *priv = widget->priv;
3550 GtkWidget *container = priv->parent;
3553 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3554 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3558 * gtk_widget_freeze_child_notify:
3559 * @widget: a #GtkWidget
3561 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3562 * signals are queued until gtk_widget_thaw_child_notify() is called
3565 * This is the analogue of g_object_freeze_notify() for child properties.
3568 gtk_widget_freeze_child_notify (GtkWidget *widget)
3570 g_return_if_fail (GTK_IS_WIDGET (widget));
3572 if (!G_OBJECT (widget)->ref_count)
3575 g_object_ref (widget);
3576 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3577 g_object_unref (widget);
3581 * gtk_widget_child_notify:
3582 * @widget: a #GtkWidget
3583 * @child_property: the name of a child property installed on the
3584 * class of @widget<!-- -->'s parent
3586 * Emits a #GtkWidget::child-notify signal for the
3587 * <link linkend="child-properties">child property</link> @child_property
3590 * This is the analogue of g_object_notify() for child properties.
3592 * Also see gtk_container_child_notify().
3595 gtk_widget_child_notify (GtkWidget *widget,
3596 const gchar *child_property)
3598 if (widget->priv->parent == NULL)
3601 gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
3605 * gtk_widget_thaw_child_notify:
3606 * @widget: a #GtkWidget
3608 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3609 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3613 gtk_widget_thaw_child_notify (GtkWidget *widget)
3615 GObjectNotifyQueue *nqueue;
3617 g_return_if_fail (GTK_IS_WIDGET (widget));
3619 if (!G_OBJECT (widget)->ref_count)
3622 g_object_ref (widget);
3623 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3624 if (!nqueue || !nqueue->freeze_count)
3625 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3626 G_OBJECT_TYPE_NAME (widget), widget);
3628 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3629 g_object_unref (widget);
3635 * @type: type ID of the widget to create
3636 * @first_property_name: name of first property to set
3637 * @Varargs: value of first property, followed by more properties,
3640 * This is a convenience function for creating a widget and setting
3641 * its properties in one go. For example you might write:
3642 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3643 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3644 * g_object_new(), but returns a widget so you don't have to
3645 * cast the object yourself.
3647 * Return value: a new #GtkWidget of type @widget_type
3650 gtk_widget_new (GType type,
3651 const gchar *first_property_name,
3657 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3659 va_start (var_args, first_property_name);
3660 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3667 gtk_widget_queue_draw_child (GtkWidget *widget)
3669 GtkWidgetPrivate *priv = widget->priv;
3672 parent = priv->parent;
3673 if (parent && gtk_widget_is_drawable (parent))
3674 gtk_widget_queue_draw_area (parent,
3677 priv->allocation.width,
3678 priv->allocation.height);
3682 * gtk_widget_unparent:
3683 * @widget: a #GtkWidget
3685 * This function is only for use in widget implementations.
3686 * Should be called by implementations of the remove method
3687 * on #GtkContainer, to dissociate a child from the container.
3690 gtk_widget_unparent (GtkWidget *widget)
3692 GtkWidgetPrivate *priv;
3693 GObjectNotifyQueue *nqueue;
3694 GtkWidget *toplevel;
3695 GtkWidget *old_parent;
3697 g_return_if_fail (GTK_IS_WIDGET (widget));
3699 priv = widget->priv;
3701 if (priv->parent == NULL)
3704 /* keep this function in sync with gtk_menu_detach() */
3706 gtk_widget_push_verify_invariants (widget);
3708 g_object_freeze_notify (G_OBJECT (widget));
3709 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3711 toplevel = gtk_widget_get_toplevel (widget);
3712 if (gtk_widget_is_toplevel (toplevel))
3713 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3715 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3716 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3718 gtk_widget_queue_draw_child (widget);
3720 /* Reset the width and height here, to force reallocation if we
3721 * get added back to a new parent. This won't work if our new
3722 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3723 * (would 0x0 be OK here?)
3725 priv->allocation.width = 1;
3726 priv->allocation.height = 1;
3728 if (gtk_widget_get_realized (widget))
3730 if (priv->in_reparent)
3731 gtk_widget_unmap (widget);
3733 gtk_widget_unrealize (widget);
3736 /* If we are unanchoring the child, we save around the toplevel
3737 * to emit hierarchy changed
3739 if (priv->parent->priv->anchored)
3740 g_object_ref (toplevel);
3744 /* Removing a widget from a container restores the child visible
3745 * flag to the default state, so it doesn't affect the child
3746 * in the next parent.
3748 priv->child_visible = TRUE;
3750 old_parent = priv->parent;
3751 priv->parent = NULL;
3753 /* parent may no longer expand if the removed
3754 * child was expand=TRUE and could therefore
3757 if (gtk_widget_get_visible (widget) &&
3758 (priv->need_compute_expand ||
3759 priv->computed_hexpand ||
3760 priv->computed_vexpand))
3762 gtk_widget_queue_compute_expand (old_parent);
3765 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3768 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3769 g_object_unref (toplevel);
3772 /* Now that the parent pointer is nullified and the hierarchy-changed
3773 * already passed, go ahead and unset the parent window, if we are unparenting
3774 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
3775 * will fire again for the new subhierarchy.
3777 gtk_widget_set_parent_window (widget, NULL);
3779 g_object_notify (G_OBJECT (widget), "parent");
3780 g_object_thaw_notify (G_OBJECT (widget));
3782 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3783 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3785 gtk_widget_pop_verify_invariants (widget);
3786 g_object_unref (widget);
3790 * gtk_widget_destroy:
3791 * @widget: a #GtkWidget
3793 * Destroys a widget.
3796 * destroyed, it will break any references it holds to other objects.
3797 * If the widget is inside a container, the widget will be removed
3798 * from the container. If the widget is a toplevel (derived from
3799 * #GtkWindow), it will be removed from the list of toplevels, and the
3800 * reference GTK+ holds to it will be removed. Removing a
3801 * widget from its container or the list of toplevels results in the
3802 * widget being finalized, unless you've added additional references
3803 * to the widget with g_object_ref().
3805 * In most cases, only toplevel widgets (windows) require explicit
3806 * destruction, because when you destroy a toplevel its children will
3807 * be destroyed as well.
3810 gtk_widget_destroy (GtkWidget *widget)
3812 g_return_if_fail (GTK_IS_WIDGET (widget));
3814 if (!widget->priv->in_destruction)
3815 g_object_run_dispose (G_OBJECT (widget));
3819 * gtk_widget_destroyed:
3820 * @widget: a #GtkWidget
3821 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3823 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3824 * %NULL. It's intended to be used as a callback connected to the
3825 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3826 * as a signal handler, and pass the address of your widget variable
3827 * as user data. Then when the widget is destroyed, the variable will
3828 * be set to %NULL. Useful for example to avoid multiple copies
3829 * of the same dialog.
3832 gtk_widget_destroyed (GtkWidget *widget,
3833 GtkWidget **widget_pointer)
3835 /* Don't make any assumptions about the
3837 * Even check widget_pointer.
3840 *widget_pointer = NULL;
3845 * @widget: a #GtkWidget
3847 * Flags a widget to be displayed. Any widget that isn't shown will
3848 * not appear on the screen. If you want to show all the widgets in a
3849 * container, it's easier to call gtk_widget_show_all() on the
3850 * container, instead of individually showing the widgets.
3852 * Remember that you have to show the containers containing a widget,
3853 * in addition to the widget itself, before it will appear onscreen.
3855 * When a toplevel container is shown, it is immediately realized and
3856 * mapped; other shown widgets are realized and mapped when their
3857 * toplevel container is realized and mapped.
3860 gtk_widget_show (GtkWidget *widget)
3862 g_return_if_fail (GTK_IS_WIDGET (widget));
3864 if (!gtk_widget_get_visible (widget))
3866 g_object_ref (widget);
3867 gtk_widget_push_verify_invariants (widget);
3869 if (!gtk_widget_is_toplevel (widget))
3870 gtk_widget_queue_resize (widget);
3872 /* see comment in set_parent() for why this should and can be
3875 if (widget->priv->need_compute_expand ||
3876 widget->priv->computed_hexpand ||
3877 widget->priv->computed_vexpand)
3879 if (widget->priv->parent != NULL)
3880 gtk_widget_queue_compute_expand (widget->priv->parent);
3883 g_signal_emit (widget, widget_signals[SHOW], 0);
3884 g_object_notify (G_OBJECT (widget), "visible");
3886 gtk_widget_pop_verify_invariants (widget);
3887 g_object_unref (widget);
3892 gtk_widget_real_show (GtkWidget *widget)
3894 GtkWidgetPrivate *priv = widget->priv;
3896 if (!gtk_widget_get_visible (widget))
3898 priv->visible = TRUE;
3901 gtk_widget_get_mapped (priv->parent) &&
3902 gtk_widget_get_child_visible (widget) &&
3903 !gtk_widget_get_mapped (widget))
3904 gtk_widget_map (widget);
3909 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3912 g_signal_handlers_disconnect_by_func (widget,
3913 gtk_widget_show_map_callback,
3918 * gtk_widget_show_now:
3919 * @widget: a #GtkWidget
3921 * Shows a widget. If the widget is an unmapped toplevel widget
3922 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3923 * loop and wait for the window to actually be mapped. Be careful;
3924 * because the main loop is running, anything can happen during
3928 gtk_widget_show_now (GtkWidget *widget)
3932 g_return_if_fail (GTK_IS_WIDGET (widget));
3934 /* make sure we will get event */
3935 if (!gtk_widget_get_mapped (widget) &&
3936 gtk_widget_is_toplevel (widget))
3938 gtk_widget_show (widget);
3940 g_signal_connect (widget, "map-event",
3941 G_CALLBACK (gtk_widget_show_map_callback),
3945 gtk_main_iteration ();
3948 gtk_widget_show (widget);
3953 * @widget: a #GtkWidget
3955 * Reverses the effects of gtk_widget_show(), causing the widget to be
3956 * hidden (invisible to the user).
3959 gtk_widget_hide (GtkWidget *widget)
3961 g_return_if_fail (GTK_IS_WIDGET (widget));
3963 if (gtk_widget_get_visible (widget))
3965 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3967 g_object_ref (widget);
3968 gtk_widget_push_verify_invariants (widget);
3970 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3971 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3973 /* a parent may now be expand=FALSE since we're hidden. */
3974 if (widget->priv->need_compute_expand ||
3975 widget->priv->computed_hexpand ||
3976 widget->priv->computed_vexpand)
3978 gtk_widget_queue_compute_expand (widget);
3981 g_signal_emit (widget, widget_signals[HIDE], 0);
3982 if (!gtk_widget_is_toplevel (widget))
3983 gtk_widget_queue_resize (widget);
3984 g_object_notify (G_OBJECT (widget), "visible");
3986 gtk_widget_pop_verify_invariants (widget);
3987 g_object_unref (widget);
3992 gtk_widget_real_hide (GtkWidget *widget)
3994 if (gtk_widget_get_visible (widget))
3996 widget->priv->visible = FALSE;
3998 if (gtk_widget_get_mapped (widget))
3999 gtk_widget_unmap (widget);
4004 * gtk_widget_hide_on_delete:
4005 * @widget: a #GtkWidget
4007 * Utility function; intended to be connected to the #GtkWidget::delete-event
4008 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4009 * argument, then returns %TRUE. If connected to ::delete-event, the
4010 * result is that clicking the close button for a window (on the
4011 * window frame, top right corner usually) will hide but not destroy
4012 * the window. By default, GTK+ destroys windows when ::delete-event
4015 * Return value: %TRUE
4018 gtk_widget_hide_on_delete (GtkWidget *widget)
4020 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4022 gtk_widget_hide (widget);
4028 * gtk_widget_show_all:
4029 * @widget: a #GtkWidget
4031 * Recursively shows a widget, and any child widgets (if the widget is
4035 gtk_widget_show_all (GtkWidget *widget)
4037 GtkWidgetClass *class;
4039 g_return_if_fail (GTK_IS_WIDGET (widget));
4041 if (gtk_widget_get_no_show_all (widget))
4044 class = GTK_WIDGET_GET_CLASS (widget);
4046 if (class->show_all)
4047 class->show_all (widget);
4051 _gtk_widget_notify_state_change (GtkWidget *widget,
4059 case GTK_STATE_FLAG_ACTIVE:
4060 state = GTK_STATE_ACTIVE;
4062 case GTK_STATE_FLAG_PRELIGHT:
4063 state = GTK_STATE_PRELIGHT;
4065 case GTK_STATE_FLAG_SELECTED:
4066 state = GTK_STATE_SELECTED;
4068 case GTK_STATE_FLAG_INSENSITIVE:
4069 state = GTK_STATE_INSENSITIVE;
4071 case GTK_STATE_FLAG_INCONSISTENT:
4072 state = GTK_STATE_INCONSISTENT;
4074 case GTK_STATE_FLAG_FOCUSED:
4075 state = GTK_STATE_FOCUSED;
4081 gtk_style_context_notify_state_change (widget->priv->context,
4082 gtk_widget_get_window (widget),
4083 NULL, state, target);
4086 /* Initializes state transitions for those states that
4087 * were enabled before mapping and have a looping animation.
4090 _gtk_widget_start_state_transitions (GtkWidget *widget)
4092 GtkStateFlags state, flag;
4094 if (!widget->priv->context)
4097 state = gtk_widget_get_state_flags (widget);
4098 flag = GTK_STATE_FLAG_FOCUSED;
4102 GtkAnimationDescription *animation_desc;
4104 if ((state & flag) == 0)
4110 gtk_style_context_get (widget->priv->context, state,
4111 "transition", &animation_desc,
4116 if (_gtk_animation_description_get_loop (animation_desc))
4117 _gtk_widget_notify_state_change (widget, flag, TRUE);
4119 _gtk_animation_description_unref (animation_desc);
4128 * @widget: a #GtkWidget
4130 * This function is only for use in widget implementations. Causes
4131 * a widget to be mapped if it isn't already.
4134 gtk_widget_map (GtkWidget *widget)
4136 GtkWidgetPrivate *priv;
4138 g_return_if_fail (GTK_IS_WIDGET (widget));
4139 g_return_if_fail (gtk_widget_get_visible (widget));
4140 g_return_if_fail (gtk_widget_get_child_visible (widget));
4142 priv = widget->priv;
4144 if (!gtk_widget_get_mapped (widget))
4146 gtk_widget_push_verify_invariants (widget);
4148 if (!gtk_widget_get_realized (widget))
4149 gtk_widget_realize (widget);
4151 g_signal_emit (widget, widget_signals[MAP], 0);
4153 if (!gtk_widget_get_has_window (widget))
4154 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4156 gtk_widget_pop_verify_invariants (widget);
4158 _gtk_widget_start_state_transitions (widget);
4164 * @widget: a #GtkWidget
4166 * This function is only for use in widget implementations. Causes
4167 * a widget to be unmapped if it's currently mapped.
4170 gtk_widget_unmap (GtkWidget *widget)
4172 GtkWidgetPrivate *priv;
4174 g_return_if_fail (GTK_IS_WIDGET (widget));
4176 priv = widget->priv;
4178 if (gtk_widget_get_mapped (widget))
4180 gtk_widget_push_verify_invariants (widget);
4182 if (!gtk_widget_get_has_window (widget))
4183 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4184 _gtk_tooltip_hide (widget);
4185 g_signal_emit (widget, widget_signals[UNMAP], 0);
4187 gtk_widget_pop_verify_invariants (widget);
4190 gtk_style_context_cancel_animations (priv->context, NULL);
4192 /* Unset pointer/window info */
4193 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4198 _gtk_widget_enable_device_events (GtkWidget *widget)
4200 GHashTable *device_events;
4201 GHashTableIter iter;
4202 gpointer key, value;
4204 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4209 g_hash_table_iter_init (&iter, device_events);
4211 while (g_hash_table_iter_next (&iter, &key, &value))
4214 GdkEventMask event_mask;
4217 event_mask = GPOINTER_TO_UINT (value);
4218 gtk_widget_add_events_internal (widget, device, event_mask);
4223 get_widget_windows (GtkWidget *widget)
4225 GList *window_list, *last, *l, *children, *ret;
4227 if (gtk_widget_get_has_window (widget))
4228 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4230 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4232 last = g_list_last (window_list);
4235 for (l = window_list; l; l = l->next)
4237 GtkWidget *window_widget = NULL;
4239 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4241 if (widget != window_widget)
4244 ret = g_list_prepend (ret, l->data);
4245 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4249 last = g_list_concat (last, children);
4250 last = g_list_last (last);
4254 g_list_free (window_list);
4260 device_enable_foreach (GtkWidget *widget,
4263 GdkDevice *device = user_data;
4264 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4268 device_disable_foreach (GtkWidget *widget,
4271 GdkDevice *device = user_data;
4272 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4276 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4281 GList *window_list, *l;
4283 window_list = get_widget_windows (widget);
4285 for (l = window_list; l; l = l->next)
4287 GdkEventMask events = 0;
4293 events = gdk_window_get_events (window);
4295 gdk_window_set_device_events (window, device, events);
4298 if (recurse && GTK_IS_CONTAINER (widget))
4301 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4303 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4306 g_list_free (window_list);
4310 gtk_widget_update_devices_mask (GtkWidget *widget,
4313 GList *enabled_devices, *l;
4315 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4317 for (l = enabled_devices; l; l = l->next)
4318 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4322 * gtk_widget_realize:
4323 * @widget: a #GtkWidget
4325 * Creates the GDK (windowing system) resources associated with a
4326 * widget. For example, @widget->window will be created when a widget
4327 * is realized. Normally realization happens implicitly; if you show
4328 * a widget and all its parent containers, then the widget will be
4329 * realized and mapped automatically.
4331 * Realizing a widget requires all
4332 * the widget's parent widgets to be realized; calling
4333 * gtk_widget_realize() realizes the widget's parents in addition to
4334 * @widget itself. If a widget is not yet inside a toplevel window
4335 * when you realize it, bad things will happen.
4337 * This function is primarily used in widget implementations, and
4338 * isn't very useful otherwise. Many times when you think you might
4339 * need it, a better approach is to connect to a signal that will be
4340 * called after the widget is realized automatically, such as
4341 * #GtkWidget::draw. Or simply g_signal_connect () to the
4342 * #GtkWidget::realize signal.
4345 gtk_widget_realize (GtkWidget *widget)
4347 GtkWidgetPrivate *priv;
4348 cairo_region_t *region;
4350 g_return_if_fail (GTK_IS_WIDGET (widget));
4351 g_return_if_fail (widget->priv->anchored ||
4352 GTK_IS_INVISIBLE (widget));
4354 priv = widget->priv;
4356 if (!gtk_widget_get_realized (widget))
4358 gtk_widget_push_verify_invariants (widget);
4361 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4362 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4365 if (priv->parent == NULL &&
4366 !gtk_widget_is_toplevel (widget))
4367 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4368 "inside a toplevel window is not going to work very well. "
4369 "Widgets must be inside a toplevel container before realizing them.");
4371 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4372 gtk_widget_realize (priv->parent);
4374 gtk_widget_ensure_style (widget);
4376 if (priv->style_update_pending)
4377 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4379 g_signal_emit (widget, widget_signals[REALIZE], 0);
4381 gtk_widget_real_set_has_tooltip (widget,
4382 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4385 if (priv->has_shape_mask)
4387 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4388 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4391 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4393 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4395 if (priv->multidevice)
4396 gdk_window_set_support_multidevice (priv->window, TRUE);
4398 _gtk_widget_enable_device_events (widget);
4399 gtk_widget_update_devices_mask (widget, TRUE);
4401 gtk_widget_pop_verify_invariants (widget);
4406 * gtk_widget_unrealize:
4407 * @widget: a #GtkWidget
4409 * This function is only useful in widget implementations.
4410 * Causes a widget to be unrealized (frees all GDK resources
4411 * associated with the widget, such as @widget->window).
4414 gtk_widget_unrealize (GtkWidget *widget)
4416 g_return_if_fail (GTK_IS_WIDGET (widget));
4418 gtk_widget_push_verify_invariants (widget);
4420 if (widget->priv->has_shape_mask)
4421 gtk_widget_shape_combine_region (widget, NULL);
4423 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4424 gtk_widget_input_shape_combine_region (widget, NULL);
4426 if (gtk_widget_get_realized (widget))
4428 g_object_ref (widget);
4430 if (widget->priv->mapped)
4431 gtk_widget_unmap (widget);
4433 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4434 g_assert (!widget->priv->mapped);
4435 gtk_widget_set_realized (widget, FALSE);
4437 g_object_unref (widget);
4440 gtk_widget_pop_verify_invariants (widget);
4443 /*****************************************
4445 *****************************************/
4448 * gtk_widget_queue_draw_region:
4449 * @widget: a #GtkWidget
4450 * @region: region to draw
4452 * Invalidates the rectangular area of @widget defined by @region by
4453 * calling gdk_window_invalidate_region() on the widget's window and
4454 * all its child windows. Once the main loop becomes idle (after the
4455 * current batch of events has been processed, roughly), the window
4456 * will receive expose events for the union of all regions that have
4459 * Normally you would only use this function in widget
4460 * implementations. You might also use it to schedule a redraw of a
4461 * #GtkDrawingArea or some portion thereof.
4466 gtk_widget_queue_draw_region (GtkWidget *widget,
4467 const cairo_region_t *region)
4469 GtkWidgetPrivate *priv;
4472 g_return_if_fail (GTK_IS_WIDGET (widget));
4474 priv = widget->priv;
4476 if (!gtk_widget_get_realized (widget))
4479 /* Just return if the widget or one of its ancestors isn't mapped */
4480 for (w = widget; w != NULL; w = w->priv->parent)
4481 if (!gtk_widget_get_mapped (w))
4484 gdk_window_invalidate_region (priv->window, region, TRUE);
4488 * gtk_widget_queue_draw_area:
4489 * @widget: a #GtkWidget
4490 * @x: x coordinate of upper-left corner of rectangle to redraw
4491 * @y: y coordinate of upper-left corner of rectangle to redraw
4492 * @width: width of region to draw
4493 * @height: height of region to draw
4495 * Convenience function that calls gtk_widget_queue_draw_region() on
4496 * the region created from the given coordinates.
4498 * The region here is specified in widget coordinates.
4499 * Widget coordinates are a bit odd; for historical reasons, they are
4500 * defined as @widget->window coordinates for widgets that are not
4501 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4502 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4505 gtk_widget_queue_draw_area (GtkWidget *widget,
4512 cairo_region_t *region;
4514 g_return_if_fail (GTK_IS_WIDGET (widget));
4519 rect.height = height;
4521 region = cairo_region_create_rectangle (&rect);
4522 gtk_widget_queue_draw_region (widget, region);
4523 cairo_region_destroy (region);
4527 * gtk_widget_queue_draw:
4528 * @widget: a #GtkWidget
4530 * Equivalent to calling gtk_widget_queue_draw_area() for the
4531 * entire area of a widget.
4534 gtk_widget_queue_draw (GtkWidget *widget)
4538 g_return_if_fail (GTK_IS_WIDGET (widget));
4540 gtk_widget_get_allocation (widget, &rect);
4542 if (!gtk_widget_get_has_window (widget))
4543 gtk_widget_queue_draw_area (widget,
4544 rect.x, rect.y, rect.width, rect.height);
4546 gtk_widget_queue_draw_area (widget,
4547 0, 0, rect.width, rect.height);
4551 * gtk_widget_queue_resize:
4552 * @widget: a #GtkWidget
4554 * This function is only for use in widget implementations.
4555 * Flags a widget to have its size renegotiated; should
4556 * be called when a widget for some reason has a new size request.
4557 * For example, when you change the text in a #GtkLabel, #GtkLabel
4558 * queues a resize to ensure there's enough space for the new text.
4560 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4561 * from inside its implementation of the GtkWidgetClass::size_allocate
4562 * virtual method. Calls to gtk_widget_queue_resize() from inside
4563 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4566 gtk_widget_queue_resize (GtkWidget *widget)
4568 g_return_if_fail (GTK_IS_WIDGET (widget));
4570 if (gtk_widget_get_realized (widget))
4571 gtk_widget_queue_shallow_draw (widget);
4573 _gtk_size_group_queue_resize (widget, 0);
4577 * gtk_widget_queue_resize_no_redraw:
4578 * @widget: a #GtkWidget
4580 * This function works like gtk_widget_queue_resize(),
4581 * except that the widget is not invalidated.
4586 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4588 g_return_if_fail (GTK_IS_WIDGET (widget));
4590 _gtk_size_group_queue_resize (widget, 0);
4594 * gtk_widget_size_request:
4595 * @widget: a #GtkWidget
4596 * @requisition: (out): a #GtkRequisition to be filled in
4598 * This function is typically used when implementing a #GtkContainer
4599 * subclass. Obtains the preferred size of a widget. The container
4600 * uses this information to arrange its child widgets and decide what
4601 * size allocations to give them with gtk_widget_size_allocate().
4603 * You can also call this function from an application, with some
4604 * caveats. Most notably, getting a size request requires the widget
4605 * to be associated with a screen, because font information may be
4606 * needed. Multihead-aware applications should keep this in mind.
4608 * Also remember that the size request is not necessarily the size
4609 * a widget will actually be allocated.
4611 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4614 gtk_widget_size_request (GtkWidget *widget,
4615 GtkRequisition *requisition)
4617 g_return_if_fail (GTK_IS_WIDGET (widget));
4619 gtk_widget_get_preferred_size (widget, requisition, NULL);
4623 * gtk_widget_get_child_requisition:
4624 * @widget: a #GtkWidget
4625 * @requisition: (out): a #GtkRequisition to be filled in
4627 * This function is only for use in widget implementations. Obtains
4628 * @widget->requisition, unless someone has forced a particular
4629 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4630 * in which case it returns that geometry instead of the widget's
4633 * This function differs from gtk_widget_size_request() in that
4634 * it retrieves the last size request value from @widget->requisition,
4635 * while gtk_widget_size_request() actually calls the "size_request" method
4636 * on @widget to compute the size request and fill in @widget->requisition,
4637 * and only then returns @widget->requisition.
4639 * Because this function does not call the "size_request" method, it
4640 * can only be used when you know that @widget->requisition is
4641 * up-to-date, that is, gtk_widget_size_request() has been called
4642 * since the last time a resize was queued. In general, only container
4643 * implementations have this information; applications should use
4644 * gtk_widget_size_request().
4647 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4650 gtk_widget_get_child_requisition (GtkWidget *widget,
4651 GtkRequisition *requisition)
4653 gtk_widget_get_preferred_size (widget, requisition, NULL);
4657 invalidate_predicate (GdkWindow *window,
4662 gdk_window_get_user_data (window, &user_data);
4664 return (user_data == data);
4667 /* Invalidate @region in widget->window and all children
4668 * of widget->window owned by widget. @region is in the
4669 * same coordinates as widget->allocation and will be
4670 * modified by this call.
4673 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4674 cairo_region_t *region)
4676 GtkWidgetPrivate *priv = widget->priv;
4678 if (!gtk_widget_get_realized (widget))
4681 if (gtk_widget_get_has_window (widget) && priv->parent)
4685 gdk_window_get_position (priv->window, &x, &y);
4686 cairo_region_translate (region, -x, -y);
4689 gdk_window_invalidate_maybe_recurse (priv->window, region,
4690 invalidate_predicate, widget);
4694 * gtk_widget_queue_shallow_draw:
4695 * @widget: a #GtkWidget
4697 * Like gtk_widget_queue_draw(), but only windows owned
4698 * by @widget are invalidated.
4701 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4704 cairo_region_t *region;
4706 if (!gtk_widget_get_realized (widget))
4709 gtk_widget_get_allocation (widget, &rect);
4711 region = cairo_region_create_rectangle (&rect);
4712 gtk_widget_invalidate_widget_windows (widget, region);
4713 cairo_region_destroy (region);
4717 * gtk_widget_size_allocate:
4718 * @widget: a #GtkWidget
4719 * @allocation: position and size to be allocated to @widget
4721 * This function is only used by #GtkContainer subclasses, to assign a size
4722 * and position to their child widgets.
4724 * In this function, the allocation may be adjusted. It will be forced
4725 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4726 * method on the child will be used to adjust the allocation. Standard
4727 * adjustments include removing the widget's margins, and applying the
4728 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4731 gtk_widget_size_allocate (GtkWidget *widget,
4732 GtkAllocation *allocation)
4734 GtkWidgetPrivate *priv;
4735 GdkRectangle real_allocation;
4736 GdkRectangle old_allocation;
4737 GdkRectangle adjusted_allocation;
4738 gboolean alloc_needed;
4739 gboolean size_changed;
4740 gboolean position_changed;
4741 gint natural_width, natural_height, dummy;
4742 gint min_width, min_height;
4744 priv = widget->priv;
4746 g_return_if_fail (GTK_IS_WIDGET (widget));
4748 gtk_widget_push_verify_invariants (widget);
4750 #ifdef G_ENABLE_DEBUG
4751 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4762 parent = gtk_widget_get_parent (parent);
4765 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4766 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4767 2 * depth, " ", name,
4768 allocation->width, allocation->height);
4770 #endif /* G_ENABLE_DEBUG */
4772 alloc_needed = priv->alloc_needed;
4773 if (!priv->width_request_needed && !priv->height_request_needed)
4774 /* Preserve request/allocate ordering */
4775 priv->alloc_needed = FALSE;
4777 old_allocation = priv->allocation;
4778 real_allocation = *allocation;
4780 adjusted_allocation = real_allocation;
4781 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4783 /* Go ahead and request the height for allocated width, note that the internals
4784 * of get_height_for_width will internally limit the for_size to natural size
4785 * when aligning implicitly.
4787 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4788 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
4792 /* Go ahead and request the width for allocated height, note that the internals
4793 * of get_width_for_height will internally limit the for_size to natural size
4794 * when aligning implicitly.
4796 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4797 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
4800 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
4801 !GTK_IS_SCROLLABLE (widget))
4802 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
4803 "Allocation is %dx%d, but minimum required size is %dx%d.",
4804 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
4805 G_OBJECT_TYPE_NAME (widget), widget,
4806 real_allocation.width, real_allocation.height,
4807 min_width, min_height);
4808 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4809 * allocated sizes and possibly limit them to the natural sizes */
4810 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4811 GTK_ORIENTATION_HORIZONTAL,
4814 &adjusted_allocation.x,
4815 &adjusted_allocation.width);
4816 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4817 GTK_ORIENTATION_VERTICAL,
4820 &adjusted_allocation.y,
4821 &adjusted_allocation.height);
4823 if (adjusted_allocation.x < real_allocation.x ||
4824 adjusted_allocation.y < real_allocation.y ||
4825 (adjusted_allocation.x + adjusted_allocation.width) >
4826 (real_allocation.x + real_allocation.width) ||
4827 (adjusted_allocation.y + adjusted_allocation.height >
4828 real_allocation.y + real_allocation.height))
4830 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",
4831 G_OBJECT_TYPE_NAME (widget), widget,
4832 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4833 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4834 adjusted_allocation = real_allocation; /* veto it */
4838 real_allocation = adjusted_allocation;
4841 if (real_allocation.width < 0 || real_allocation.height < 0)
4843 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4844 real_allocation.width,
4845 real_allocation.height);
4848 real_allocation.width = MAX (real_allocation.width, 1);
4849 real_allocation.height = MAX (real_allocation.height, 1);
4851 size_changed = (old_allocation.width != real_allocation.width ||
4852 old_allocation.height != real_allocation.height);
4853 position_changed = (old_allocation.x != real_allocation.x ||
4854 old_allocation.y != real_allocation.y);
4856 if (!alloc_needed && !size_changed && !position_changed)
4859 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4861 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4862 priv->width_request_needed = FALSE;
4863 priv->height_request_needed = FALSE;
4864 priv->alloc_needed = FALSE;
4866 if (gtk_widget_get_mapped (widget))
4868 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4870 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4872 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4873 cairo_region_union_rectangle (invalidate, &old_allocation);
4875 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4876 cairo_region_destroy (invalidate);
4881 if (priv->redraw_on_alloc)
4883 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4885 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4886 cairo_region_union_rectangle (invalidate, &old_allocation);
4888 gtk_widget_invalidate_widget_windows (widget, invalidate);
4889 cairo_region_destroy (invalidate);
4893 if (size_changed || position_changed)
4895 GtkStyleContext *context;
4897 context = gtk_widget_get_style_context (widget);
4898 _gtk_style_context_invalidate_animation_areas (context);
4902 if ((size_changed || position_changed) && priv->parent &&
4903 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4905 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4906 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4907 cairo_region_destroy (invalidate);
4911 gtk_widget_pop_verify_invariants (widget);
4915 * gtk_widget_common_ancestor:
4916 * @widget_a: a #GtkWidget
4917 * @widget_b: a #GtkWidget
4919 * Find the common ancestor of @widget_a and @widget_b that
4920 * is closest to the two widgets.
4922 * Return value: the closest common ancestor of @widget_a and
4923 * @widget_b or %NULL if @widget_a and @widget_b do not
4924 * share a common ancestor.
4927 gtk_widget_common_ancestor (GtkWidget *widget_a,
4928 GtkWidget *widget_b)
4930 GtkWidget *parent_a;
4931 GtkWidget *parent_b;
4935 parent_a = widget_a;
4936 while (parent_a->priv->parent)
4938 parent_a = parent_a->priv->parent;
4942 parent_b = widget_b;
4943 while (parent_b->priv->parent)
4945 parent_b = parent_b->priv->parent;
4949 if (parent_a != parent_b)
4952 while (depth_a > depth_b)
4954 widget_a = widget_a->priv->parent;
4958 while (depth_b > depth_a)
4960 widget_b = widget_b->priv->parent;
4964 while (widget_a != widget_b)
4966 widget_a = widget_a->priv->parent;
4967 widget_b = widget_b->priv->parent;
4974 * gtk_widget_translate_coordinates:
4975 * @src_widget: a #GtkWidget
4976 * @dest_widget: a #GtkWidget
4977 * @src_x: X position relative to @src_widget
4978 * @src_y: Y position relative to @src_widget
4979 * @dest_x: (out): location to store X position relative to @dest_widget
4980 * @dest_y: (out): location to store Y position relative to @dest_widget
4982 * Translate coordinates relative to @src_widget's allocation to coordinates
4983 * relative to @dest_widget's allocations. In order to perform this
4984 * operation, both widgets must be realized, and must share a common
4987 * Return value: %FALSE if either widget was not realized, or there
4988 * was no common ancestor. In this case, nothing is stored in
4989 * *@dest_x and *@dest_y. Otherwise %TRUE.
4992 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4993 GtkWidget *dest_widget,
4999 GtkWidgetPrivate *src_priv = src_widget->priv;
5000 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5001 GtkWidget *ancestor;
5003 GList *dest_list = NULL;
5005 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5006 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5008 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5009 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5012 /* Translate from allocation relative to window relative */
5013 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5016 gdk_window_get_position (src_priv->window, &wx, &wy);
5018 src_x -= wx - src_priv->allocation.x;
5019 src_y -= wy - src_priv->allocation.y;
5023 src_x += src_priv->allocation.x;
5024 src_y += src_priv->allocation.y;
5027 /* Translate to the common ancestor */
5028 window = src_priv->window;
5029 while (window != ancestor->priv->window)
5033 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5038 window = gdk_window_get_effective_parent (window);
5040 if (!window) /* Handle GtkHandleBox */
5045 window = dest_priv->window;
5046 while (window != ancestor->priv->window)
5048 dest_list = g_list_prepend (dest_list, window);
5050 window = gdk_window_get_effective_parent (window);
5052 if (!window) /* Handle GtkHandleBox */
5054 g_list_free (dest_list);
5063 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5068 dest_list = g_list_remove (dest_list, dest_list->data);
5071 /* Translate from window relative to allocation relative */
5072 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5075 gdk_window_get_position (dest_priv->window, &wx, &wy);
5077 src_x += wx - dest_priv->allocation.x;
5078 src_y += wy - dest_priv->allocation.y;
5082 src_x -= dest_priv->allocation.x;
5083 src_y -= dest_priv->allocation.y;
5095 gtk_widget_real_size_allocate (GtkWidget *widget,
5096 GtkAllocation *allocation)
5098 GtkWidgetPrivate *priv = widget->priv;
5100 priv->allocation = *allocation;
5102 if (gtk_widget_get_realized (widget) &&
5103 gtk_widget_get_has_window (widget))
5105 gdk_window_move_resize (priv->window,
5106 allocation->x, allocation->y,
5107 allocation->width, allocation->height);
5111 /* translate initial/final into start/end */
5113 effective_align (GtkAlign align,
5114 GtkTextDirection direction)
5118 case GTK_ALIGN_START:
5119 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5121 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5128 adjust_for_align (GtkAlign align,
5130 gint *allocated_pos,
5131 gint *allocated_size)
5135 case GTK_ALIGN_FILL:
5136 /* change nothing */
5138 case GTK_ALIGN_START:
5139 /* keep *allocated_pos where it is */
5140 *allocated_size = MIN (*allocated_size, *natural_size);
5143 if (*allocated_size > *natural_size)
5145 *allocated_pos += (*allocated_size - *natural_size);
5146 *allocated_size = *natural_size;
5149 case GTK_ALIGN_CENTER:
5150 if (*allocated_size > *natural_size)
5152 *allocated_pos += (*allocated_size - *natural_size) / 2;
5153 *allocated_size = MIN (*allocated_size, *natural_size);
5160 adjust_for_margin(gint start_margin,
5164 gint *allocated_pos,
5165 gint *allocated_size)
5167 *minimum_size -= (start_margin + end_margin);
5168 *natural_size -= (start_margin + end_margin);
5169 *allocated_pos += start_margin;
5170 *allocated_size -= (start_margin + end_margin);
5174 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5175 GtkOrientation orientation,
5178 gint *allocated_pos,
5179 gint *allocated_size)
5181 const GtkWidgetAuxInfo *aux_info;
5183 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5185 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5187 adjust_for_margin (aux_info->margin.left,
5188 aux_info->margin.right,
5189 minimum_size, natural_size,
5190 allocated_pos, allocated_size);
5191 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5192 natural_size, allocated_pos, allocated_size);
5196 adjust_for_margin (aux_info->margin.top,
5197 aux_info->margin.bottom,
5198 minimum_size, natural_size,
5199 allocated_pos, allocated_size);
5200 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5201 natural_size, allocated_pos, allocated_size);
5206 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5209 GtkWidgetPrivate *priv = widget->priv;
5211 /* widgets must be onscreen for accels to take effect */
5212 return gtk_widget_is_sensitive (widget) &&
5213 gtk_widget_is_drawable (widget) &&
5214 gdk_window_is_viewable (priv->window);
5218 * gtk_widget_can_activate_accel:
5219 * @widget: a #GtkWidget
5220 * @signal_id: the ID of a signal installed on @widget
5222 * Determines whether an accelerator that activates the signal
5223 * identified by @signal_id can currently be activated.
5224 * This is done by emitting the #GtkWidget::can-activate-accel
5225 * signal on @widget; if the signal isn't overridden by a
5226 * handler or in a derived widget, then the default check is
5227 * that the widget must be sensitive, and the widget and all
5228 * its ancestors mapped.
5230 * Return value: %TRUE if the accelerator can be activated.
5235 gtk_widget_can_activate_accel (GtkWidget *widget,
5238 gboolean can_activate = FALSE;
5239 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5240 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5241 return can_activate;
5250 closure_accel_activate (GClosure *closure,
5251 GValue *return_value,
5252 guint n_param_values,
5253 const GValue *param_values,
5254 gpointer invocation_hint,
5255 gpointer marshal_data)
5257 AccelClosure *aclosure = (AccelClosure*) closure;
5258 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5261 g_signal_emit (closure->data, aclosure->signal_id, 0);
5263 /* whether accelerator was handled */
5264 g_value_set_boolean (return_value, can_activate);
5268 closures_destroy (gpointer data)
5270 GSList *slist, *closures = data;
5272 for (slist = closures; slist; slist = slist->next)
5274 g_closure_invalidate (slist->data);
5275 g_closure_unref (slist->data);
5277 g_slist_free (closures);
5281 widget_new_accel_closure (GtkWidget *widget,
5284 AccelClosure *aclosure;
5285 GClosure *closure = NULL;
5286 GSList *slist, *closures;
5288 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5289 for (slist = closures; slist; slist = slist->next)
5290 if (!gtk_accel_group_from_accel_closure (slist->data))
5292 /* reuse this closure */
5293 closure = slist->data;
5298 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5299 closures = g_slist_prepend (closures, g_closure_ref (closure));
5300 g_closure_sink (closure);
5301 g_closure_set_marshal (closure, closure_accel_activate);
5303 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5305 aclosure = (AccelClosure*) closure;
5306 g_assert (closure->data == widget);
5307 g_assert (closure->marshal == closure_accel_activate);
5308 aclosure->signal_id = signal_id;
5314 * gtk_widget_add_accelerator
5315 * @widget: widget to install an accelerator on
5316 * @accel_signal: widget signal to emit on accelerator activation
5317 * @accel_group: accel group for this widget, added to its toplevel
5318 * @accel_key: GDK keyval of the accelerator
5319 * @accel_mods: modifier key combination of the accelerator
5320 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5322 * Installs an accelerator for this @widget in @accel_group that causes
5323 * @accel_signal to be emitted if the accelerator is activated.
5324 * The @accel_group needs to be added to the widget's toplevel via
5325 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5326 * Accelerators added through this function are not user changeable during
5327 * runtime. If you want to support accelerators that can be changed by the
5328 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5329 * gtk_menu_item_set_accel_path() instead.
5332 gtk_widget_add_accelerator (GtkWidget *widget,
5333 const gchar *accel_signal,
5334 GtkAccelGroup *accel_group,
5336 GdkModifierType accel_mods,
5337 GtkAccelFlags accel_flags)
5342 g_return_if_fail (GTK_IS_WIDGET (widget));
5343 g_return_if_fail (accel_signal != NULL);
5344 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5346 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5347 if (!query.signal_id ||
5348 !(query.signal_flags & G_SIGNAL_ACTION) ||
5349 query.return_type != G_TYPE_NONE ||
5352 /* hmm, should be elaborate enough */
5353 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5354 G_OBJECT_TYPE_NAME (widget), accel_signal);
5358 closure = widget_new_accel_closure (widget, query.signal_id);
5360 g_object_ref (widget);
5362 /* install the accelerator. since we don't map this onto an accel_path,
5363 * the accelerator will automatically be locked.
5365 gtk_accel_group_connect (accel_group,
5368 accel_flags | GTK_ACCEL_LOCKED,
5371 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5373 g_object_unref (widget);
5377 * gtk_widget_remove_accelerator:
5378 * @widget: widget to install an accelerator on
5379 * @accel_group: accel group for this widget
5380 * @accel_key: GDK keyval of the accelerator
5381 * @accel_mods: modifier key combination of the accelerator
5382 * @returns: whether an accelerator was installed and could be removed
5384 * Removes an accelerator from @widget, previously installed with
5385 * gtk_widget_add_accelerator().
5388 gtk_widget_remove_accelerator (GtkWidget *widget,
5389 GtkAccelGroup *accel_group,
5391 GdkModifierType accel_mods)
5393 GtkAccelGroupEntry *ag_entry;
5394 GList *slist, *clist;
5397 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5398 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5400 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5401 clist = gtk_widget_list_accel_closures (widget);
5402 for (slist = clist; slist; slist = slist->next)
5406 for (i = 0; i < n; i++)
5407 if (slist->data == (gpointer) ag_entry[i].closure)
5409 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5411 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5413 g_list_free (clist);
5418 g_list_free (clist);
5420 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5421 accel_key, accel_mods, accel_group,
5422 G_OBJECT_TYPE_NAME (widget), widget);
5428 * gtk_widget_list_accel_closures:
5429 * @widget: widget to list accelerator closures for
5431 * Lists the closures used by @widget for accelerator group connections
5432 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5433 * The closures can be used to monitor accelerator changes on @widget,
5434 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5435 * #GtkAccelGroup of a closure which can be found out with
5436 * gtk_accel_group_from_accel_closure().
5438 * Return value: (transfer container) (element-type GClosure):
5439 * a newly allocated #GList of closures
5442 gtk_widget_list_accel_closures (GtkWidget *widget)
5445 GList *clist = NULL;
5447 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5449 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5450 if (gtk_accel_group_from_accel_closure (slist->data))
5451 clist = g_list_prepend (clist, slist->data);
5457 GtkAccelGroup *accel_group;
5462 destroy_accel_path (gpointer data)
5464 AccelPath *apath = data;
5466 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5468 /* closures_destroy takes care of unrefing the closure */
5469 g_object_unref (apath->accel_group);
5471 g_slice_free (AccelPath, apath);
5476 * gtk_widget_set_accel_path:
5477 * @widget: a #GtkWidget
5478 * @accel_path: (allow-none): path used to look up the accelerator
5479 * @accel_group: (allow-none): a #GtkAccelGroup.
5481 * Given an accelerator group, @accel_group, and an accelerator path,
5482 * @accel_path, sets up an accelerator in @accel_group so whenever the
5483 * key binding that is defined for @accel_path is pressed, @widget
5484 * will be activated. This removes any accelerators (for any
5485 * accelerator group) installed by previous calls to
5486 * gtk_widget_set_accel_path(). Associating accelerators with
5487 * paths allows them to be modified by the user and the modifications
5488 * to be saved for future use. (See gtk_accel_map_save().)
5490 * This function is a low level function that would most likely
5491 * be used by a menu creation system like #GtkUIManager. If you
5492 * use #GtkUIManager, setting up accelerator paths will be done
5495 * Even when you you aren't using #GtkUIManager, if you only want to
5496 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5497 * provides a somewhat more convenient interface.
5499 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5500 * pass a static string, you can save some memory by interning it first with
5501 * g_intern_static_string().
5504 gtk_widget_set_accel_path (GtkWidget *widget,
5505 const gchar *accel_path,
5506 GtkAccelGroup *accel_group)
5510 g_return_if_fail (GTK_IS_WIDGET (widget));
5511 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5515 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5516 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5518 gtk_accel_map_add_entry (accel_path, 0, 0);
5519 apath = g_slice_new (AccelPath);
5520 apath->accel_group = g_object_ref (accel_group);
5521 apath->path_quark = g_quark_from_string (accel_path);
5522 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5527 /* also removes possible old settings */
5528 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5531 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5533 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5537 _gtk_widget_get_accel_path (GtkWidget *widget,
5542 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5544 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5546 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5547 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5551 * gtk_widget_mnemonic_activate:
5552 * @widget: a #GtkWidget
5553 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5555 * Emits the #GtkWidget::mnemonic-activate signal.
5557 * The default handler for this signal activates the @widget if
5558 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5561 * Returns: %TRUE if the signal has been handled
5564 gtk_widget_mnemonic_activate (GtkWidget *widget,
5565 gboolean group_cycling)
5569 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5571 group_cycling = group_cycling != FALSE;
5572 if (!gtk_widget_is_sensitive (widget))
5575 g_signal_emit (widget,
5576 widget_signals[MNEMONIC_ACTIVATE],
5584 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5585 gboolean group_cycling)
5587 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5588 gtk_widget_activate (widget);
5589 else if (gtk_widget_get_can_focus (widget))
5590 gtk_widget_grab_focus (widget);
5593 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5594 G_OBJECT_TYPE_NAME (widget));
5595 gtk_widget_error_bell (widget);
5600 static const cairo_user_data_key_t event_key;
5603 _gtk_cairo_get_event (cairo_t *cr)
5605 g_return_val_if_fail (cr != NULL, NULL);
5607 return cairo_get_user_data (cr, &event_key);
5611 gtk_cairo_set_event (cairo_t *cr,
5612 GdkEventExpose *event)
5614 cairo_set_user_data (cr, &event_key, event, NULL);
5618 * gtk_cairo_should_draw_window:
5619 * @cr: a cairo context
5620 * @window: the window to check. @window may not be an input-only
5623 * This function is supposed to be called in #GtkWidget::draw
5624 * implementations for widgets that support multiple windows.
5625 * @cr must be untransformed from invoking of the draw function.
5626 * This function will return %TRUE if the contents of the given
5627 * @window are supposed to be drawn and %FALSE otherwise. Note
5628 * that when the drawing was not initiated by the windowing
5629 * system this function will return %TRUE for all windows, so
5630 * you need to draw the bottommost window first. Also, do not
5631 * use "else if" statements to check which window should be drawn.
5633 * Returns: %TRUE if @window should be drawn
5638 gtk_cairo_should_draw_window (cairo_t *cr,
5641 GdkEventExpose *event;
5643 g_return_val_if_fail (cr != NULL, FALSE);
5644 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5646 event = _gtk_cairo_get_event (cr);
5648 return event == NULL ||
5649 event->window == window;
5653 gtk_widget_get_clip_draw (GtkWidget *widget)
5655 /* labels are not clipped, because clipping them would cause
5656 * mnemonics to not appear on characters that go beyond the
5658 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
5660 if (GTK_IS_LABEL (widget))
5666 /* code shared by gtk_container_propagate_draw() and
5670 _gtk_widget_draw_internal (GtkWidget *widget,
5672 gboolean clip_to_size)
5674 GtkStyleContext *context;
5676 if (!gtk_widget_is_drawable (widget))
5679 clip_to_size &= gtk_widget_get_clip_draw (widget);
5683 cairo_rectangle (cr,
5685 widget->priv->allocation.width,
5686 widget->priv->allocation.height);
5690 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5694 g_signal_emit (widget, widget_signals[DRAW],
5699 context = gtk_widget_get_style_context (widget);
5700 _gtk_style_context_coalesce_animation_areas (context, widget);
5705 * @widget: the widget to draw. It must be drawable (see
5706 * gtk_widget_is_drawable()) and a size must have been allocated.
5707 * @cr: a cairo context to draw to
5709 * Draws @widget to @cr. The top left corner of the widget will be
5710 * drawn to the currently set origin point of @cr.
5712 * You should pass a cairo context as @cr argument that is in an
5713 * original state. Otherwise the resulting drawing is undefined. For
5714 * example changing the operator using cairo_set_operator() or the
5715 * line width using cairo_set_line_width() might have unwanted side
5717 * You may however change the context's transform matrix - like with
5718 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5719 * region with cairo_clip() prior to calling this function. Also, it
5720 * is fine to modify the context with cairo_save() and
5721 * cairo_push_group() prior to calling this function.
5723 * <note><para>Special purpose widgets may contain special code for
5724 * rendering to the screen and might appear differently on screen
5725 * and when rendered using gtk_widget_draw().</para></note>
5730 gtk_widget_draw (GtkWidget *widget,
5733 GdkEventExpose *tmp_event;
5735 g_return_if_fail (GTK_IS_WIDGET (widget));
5736 g_return_if_fail (!widget->priv->alloc_needed);
5737 g_return_if_fail (cr != NULL);
5740 /* We have to reset the event here so that draw functions can call
5741 * gtk_widget_draw() on random other widgets and get the desired
5742 * effect: Drawing all contents, not just the current window.
5744 tmp_event = _gtk_cairo_get_event (cr);
5745 gtk_cairo_set_event (cr, NULL);
5747 _gtk_widget_draw_internal (widget, cr, TRUE);
5749 gtk_cairo_set_event (cr, tmp_event);
5754 gtk_widget_real_key_press_event (GtkWidget *widget,
5757 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5761 gtk_widget_real_key_release_event (GtkWidget *widget,
5764 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5768 gtk_widget_real_focus_in_event (GtkWidget *widget,
5769 GdkEventFocus *event)
5771 gtk_widget_queue_shallow_draw (widget);
5777 gtk_widget_real_focus_out_event (GtkWidget *widget,
5778 GdkEventFocus *event)
5780 gtk_widget_queue_shallow_draw (widget);
5785 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5786 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5790 * @widget: a #GtkWidget
5791 * @event: a #GdkEvent
5793 * Rarely-used function. This function is used to emit
5794 * the event signals on a widget (those signals should never
5795 * be emitted without using this function to do so).
5796 * If you want to synthesize an event though, don't use this function;
5797 * instead, use gtk_main_do_event() so the event will behave as if
5798 * it were in the event queue. Don't synthesize expose events; instead,
5799 * use gdk_window_invalidate_rect() to invalidate a region of the
5802 * Return value: return from the event signal emission (%TRUE if
5803 * the event was handled)
5806 gtk_widget_event (GtkWidget *widget,
5809 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5810 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5812 if (event->type == GDK_EXPOSE)
5814 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5815 "the same effect, call gdk_window_invalidate_rect/region(), "
5816 "followed by gdk_window_process_updates().");
5820 return gtk_widget_event_internal (widget, event);
5823 /* Returns TRUE if a translation should be done */
5825 _gtk_widget_get_translation_to_window (GtkWidget *widget,
5830 GdkWindow *w, *widget_window;
5832 if (!gtk_widget_get_has_window (widget))
5834 *x = -widget->priv->allocation.x;
5835 *y = -widget->priv->allocation.y;
5843 widget_window = gtk_widget_get_window (widget);
5845 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5848 gdk_window_get_position (w, &wx, &wy);
5865 * gtk_cairo_transform_to_window:
5866 * @cr: the cairo context to transform
5867 * @widget: the widget the context is currently centered for
5868 * @window: the window to transform the context to
5870 * Transforms the given cairo context @cr that from @widget-relative
5871 * coordinates to @window-relative coordinates.
5872 * If the @widget's window is not an ancestor of @window, no
5873 * modification will be applied.
5875 * This is the inverse to the transformation GTK applies when
5876 * preparing an expose event to be emitted with the #GtkWidget::draw
5877 * signal. It is intended to help porting multiwindow widgets from
5878 * GTK+ 2 to the rendering architecture of GTK+ 3.
5883 gtk_cairo_transform_to_window (cairo_t *cr,
5889 g_return_if_fail (cr != NULL);
5890 g_return_if_fail (GTK_IS_WIDGET (widget));
5891 g_return_if_fail (GDK_IS_WINDOW (window));
5893 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
5894 cairo_translate (cr, x, y);
5898 * gtk_widget_send_expose:
5899 * @widget: a #GtkWidget
5900 * @event: a expose #GdkEvent
5902 * Very rarely-used function. This function is used to emit
5903 * an expose event on a widget. This function is not normally used
5904 * directly. The only time it is used is when propagating an expose
5905 * event to a child %NO_WINDOW widget, and that is normally done
5906 * using gtk_container_propagate_draw().
5908 * If you want to force an area of a window to be redrawn,
5909 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5910 * To cause the redraw to be done immediately, follow that call
5911 * with a call to gdk_window_process_updates().
5913 * Return value: return from the event signal emission (%TRUE if
5914 * the event was handled)
5917 gtk_widget_send_expose (GtkWidget *widget,
5920 gboolean result = FALSE;
5925 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5926 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5927 g_return_val_if_fail (event != NULL, TRUE);
5928 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5930 cr = gdk_cairo_create (event->expose.window);
5931 gtk_cairo_set_event (cr, &event->expose);
5933 gdk_cairo_region (cr, event->expose.region);
5936 do_clip = _gtk_widget_get_translation_to_window (widget,
5937 event->expose.window,
5939 cairo_translate (cr, -x, -y);
5941 _gtk_widget_draw_internal (widget, cr, do_clip);
5943 /* unset here, so if someone keeps a reference to cr we
5944 * don't leak the window. */
5945 gtk_cairo_set_event (cr, NULL);
5952 event_window_is_still_viewable (GdkEvent *event)
5954 /* Check that we think the event's window is viewable before
5955 * delivering the event, to prevent suprises. We do this here
5956 * at the last moment, since the event may have been queued
5957 * up behind other events, held over a recursive main loop, etc.
5959 switch (event->type)
5962 case GDK_MOTION_NOTIFY:
5963 case GDK_BUTTON_PRESS:
5964 case GDK_2BUTTON_PRESS:
5965 case GDK_3BUTTON_PRESS:
5967 case GDK_ENTER_NOTIFY:
5968 case GDK_PROXIMITY_IN:
5970 return event->any.window && gdk_window_is_viewable (event->any.window);
5973 /* The following events are the second half of paired events;
5974 * we always deliver them to deal with widgets that clean up
5975 * on the second half.
5977 case GDK_BUTTON_RELEASE:
5978 case GDK_KEY_RELEASE:
5979 case GDK_LEAVE_NOTIFY:
5980 case GDK_PROXIMITY_OUT:
5984 /* Remaining events would make sense on an not-viewable window,
5985 * or don't have an associated window.
5992 gtk_widget_event_internal (GtkWidget *widget,
5995 gboolean return_val = FALSE;
5997 /* We check only once for is-still-visible; if someone
5998 * hides the window in on of the signals on the widget,
5999 * they are responsible for returning TRUE to terminate
6002 if (!event_window_is_still_viewable (event))
6005 g_object_ref (widget);
6007 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6008 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6013 switch (event->type)
6019 case GDK_BUTTON_PRESS:
6020 case GDK_2BUTTON_PRESS:
6021 case GDK_3BUTTON_PRESS:
6022 signal_num = BUTTON_PRESS_EVENT;
6025 signal_num = SCROLL_EVENT;
6027 case GDK_BUTTON_RELEASE:
6028 signal_num = BUTTON_RELEASE_EVENT;
6030 case GDK_MOTION_NOTIFY:
6031 signal_num = MOTION_NOTIFY_EVENT;
6034 signal_num = DELETE_EVENT;
6037 signal_num = DESTROY_EVENT;
6038 _gtk_tooltip_hide (widget);
6041 signal_num = KEY_PRESS_EVENT;
6043 case GDK_KEY_RELEASE:
6044 signal_num = KEY_RELEASE_EVENT;
6046 case GDK_ENTER_NOTIFY:
6047 signal_num = ENTER_NOTIFY_EVENT;
6049 case GDK_LEAVE_NOTIFY:
6050 signal_num = LEAVE_NOTIFY_EVENT;
6052 case GDK_FOCUS_CHANGE:
6053 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6054 if (event->focus_change.in)
6055 _gtk_tooltip_focus_in (widget);
6057 _gtk_tooltip_focus_out (widget);
6060 signal_num = CONFIGURE_EVENT;
6063 signal_num = MAP_EVENT;
6066 signal_num = UNMAP_EVENT;
6068 case GDK_WINDOW_STATE:
6069 signal_num = WINDOW_STATE_EVENT;
6071 case GDK_PROPERTY_NOTIFY:
6072 signal_num = PROPERTY_NOTIFY_EVENT;
6074 case GDK_SELECTION_CLEAR:
6075 signal_num = SELECTION_CLEAR_EVENT;
6077 case GDK_SELECTION_REQUEST:
6078 signal_num = SELECTION_REQUEST_EVENT;
6080 case GDK_SELECTION_NOTIFY:
6081 signal_num = SELECTION_NOTIFY_EVENT;
6083 case GDK_PROXIMITY_IN:
6084 signal_num = PROXIMITY_IN_EVENT;
6086 case GDK_PROXIMITY_OUT:
6087 signal_num = PROXIMITY_OUT_EVENT;
6089 case GDK_VISIBILITY_NOTIFY:
6090 signal_num = VISIBILITY_NOTIFY_EVENT;
6092 case GDK_GRAB_BROKEN:
6093 signal_num = GRAB_BROKEN_EVENT;
6096 signal_num = DAMAGE_EVENT;
6099 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6103 if (signal_num != -1)
6104 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6106 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6107 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6111 g_object_unref (widget);
6117 * gtk_widget_activate:
6118 * @widget: a #GtkWidget that's activatable
6120 * For widgets that can be "activated" (buttons, menu items, etc.)
6121 * this function activates them. Activation is what happens when you
6122 * press Enter on a widget during key navigation. If @widget isn't
6123 * activatable, the function returns %FALSE.
6125 * Return value: %TRUE if the widget was activatable
6128 gtk_widget_activate (GtkWidget *widget)
6130 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6132 if (WIDGET_CLASS (widget)->activate_signal)
6134 /* FIXME: we should eventually check the signals signature here */
6135 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6144 gtk_widget_reparent_subwindows (GtkWidget *widget,
6145 GdkWindow *new_window)
6147 GtkWidgetPrivate *priv = widget->priv;
6149 if (!gtk_widget_get_has_window (widget))
6151 GList *children = gdk_window_get_children (priv->window);
6154 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6156 GdkWindow *window = tmp_list->data;
6159 gdk_window_get_user_data (window, &child);
6160 while (child && child != widget)
6161 child = ((GtkWidget*) child)->priv->parent;
6164 gdk_window_reparent (window, new_window, 0, 0);
6167 g_list_free (children);
6172 GList *tmp_list, *children;
6174 parent = gdk_window_get_parent (priv->window);
6177 gdk_window_reparent (priv->window, new_window, 0, 0);
6180 children = gdk_window_get_children (parent);
6182 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6184 GdkWindow *window = tmp_list->data;
6187 gdk_window_get_user_data (window, &child);
6189 if (child == widget)
6190 gdk_window_reparent (window, new_window, 0, 0);
6193 g_list_free (children);
6199 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6200 gpointer client_data)
6202 GtkWidgetPrivate *priv = widget->priv;
6204 g_assert (client_data != NULL);
6206 if (!gtk_widget_get_has_window (widget))
6209 g_object_unref (priv->window);
6210 priv->window = (GdkWindow*) client_data;
6212 g_object_ref (priv->window);
6214 if (GTK_IS_CONTAINER (widget))
6215 gtk_container_forall (GTK_CONTAINER (widget),
6216 gtk_widget_reparent_fixup_child,
6222 * gtk_widget_reparent:
6223 * @widget: a #GtkWidget
6224 * @new_parent: a #GtkContainer to move the widget into
6226 * Moves a widget from one #GtkContainer to another, handling reference
6227 * count issues to avoid destroying the widget.
6230 gtk_widget_reparent (GtkWidget *widget,
6231 GtkWidget *new_parent)
6233 GtkWidgetPrivate *priv;
6235 g_return_if_fail (GTK_IS_WIDGET (widget));
6236 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6237 priv = widget->priv;
6238 g_return_if_fail (priv->parent != NULL);
6240 if (priv->parent != new_parent)
6242 /* First try to see if we can get away without unrealizing
6243 * the widget as we reparent it. if so we set a flag so
6244 * that gtk_widget_unparent doesn't unrealize widget
6246 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6247 priv->in_reparent = TRUE;
6249 g_object_ref (widget);
6250 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6251 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6252 g_object_unref (widget);
6254 if (priv->in_reparent)
6256 priv->in_reparent = FALSE;
6258 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6259 gtk_widget_reparent_fixup_child (widget,
6260 gtk_widget_get_parent_window (widget));
6263 g_object_notify (G_OBJECT (widget), "parent");
6268 * gtk_widget_intersect:
6269 * @widget: a #GtkWidget
6270 * @area: a rectangle
6271 * @intersection: rectangle to store intersection of @widget and @area
6273 * Computes the intersection of a @widget's area and @area, storing
6274 * the intersection in @intersection, and returns %TRUE if there was
6275 * an intersection. @intersection may be %NULL if you're only
6276 * interested in whether there was an intersection.
6278 * Return value: %TRUE if there was an intersection
6281 gtk_widget_intersect (GtkWidget *widget,
6282 const GdkRectangle *area,
6283 GdkRectangle *intersection)
6285 GtkWidgetPrivate *priv;
6290 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6291 g_return_val_if_fail (area != NULL, FALSE);
6293 priv = widget->priv;
6296 dest = intersection;
6300 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6302 if (return_val && intersection && gtk_widget_get_has_window (widget))
6304 intersection->x -= priv->allocation.x;
6305 intersection->y -= priv->allocation.y;
6312 * gtk_widget_region_intersect:
6313 * @widget: a #GtkWidget
6314 * @region: a #cairo_region_t, in the same coordinate system as
6315 * @widget->allocation. That is, relative to @widget->window
6316 * for %NO_WINDOW widgets; relative to the parent window
6317 * of @widget->window for widgets with their own window.
6318 * @returns: A newly allocated region holding the intersection of @widget
6319 * and @region. The coordinates of the return value are
6320 * relative to @widget->window for %NO_WINDOW widgets, and
6321 * relative to the parent window of @widget->window for
6322 * widgets with their own window.
6324 * Computes the intersection of a @widget's area and @region, returning
6325 * the intersection. The result may be empty, use cairo_region_is_empty() to
6329 gtk_widget_region_intersect (GtkWidget *widget,
6330 const cairo_region_t *region)
6333 cairo_region_t *dest;
6335 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6336 g_return_val_if_fail (region != NULL, NULL);
6338 gtk_widget_get_allocation (widget, &rect);
6340 dest = cairo_region_create_rectangle (&rect);
6342 cairo_region_intersect (dest, region);
6348 * _gtk_widget_grab_notify:
6349 * @widget: a #GtkWidget
6350 * @was_grabbed: whether a grab is now in effect
6352 * Emits the #GtkWidget::grab-notify signal on @widget.
6357 _gtk_widget_grab_notify (GtkWidget *widget,
6358 gboolean was_grabbed)
6360 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6364 * gtk_widget_grab_focus:
6365 * @widget: a #GtkWidget
6367 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6368 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6369 * something like #GtkFrame won't work.
6371 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6372 * gtk_widget_set_can_focus() to modify that flag.
6374 * The widget also needs to be realized and mapped. This is indicated by the
6375 * related signals. Grabbing the focus immediately after creating the widget
6376 * will likely fail and cause critical warnings.
6379 gtk_widget_grab_focus (GtkWidget *widget)
6381 g_return_if_fail (GTK_IS_WIDGET (widget));
6383 if (!gtk_widget_is_sensitive (widget))
6386 g_object_ref (widget);
6387 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6388 g_object_notify (G_OBJECT (widget), "has-focus");
6389 g_object_unref (widget);
6393 reset_focus_recurse (GtkWidget *widget,
6396 if (GTK_IS_CONTAINER (widget))
6398 GtkContainer *container;
6400 container = GTK_CONTAINER (widget);
6401 gtk_container_set_focus_child (container, NULL);
6403 gtk_container_foreach (container,
6404 reset_focus_recurse,
6410 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6412 if (gtk_widget_get_can_focus (focus_widget))
6414 GtkWidget *toplevel;
6417 /* clear the current focus setting, break if the current widget
6418 * is the focus widget's parent, since containers above that will
6419 * be set by the next loop.
6421 toplevel = gtk_widget_get_toplevel (focus_widget);
6422 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6424 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6426 if (widget == focus_widget)
6428 /* We call _gtk_window_internal_set_focus() here so that the
6429 * toplevel window can request the focus if necessary.
6430 * This is needed when the toplevel is a GtkPlug
6432 if (!gtk_widget_has_focus (widget))
6433 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6440 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
6442 widget = widget->priv->parent;
6443 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6447 else if (toplevel != focus_widget)
6449 /* gtk_widget_grab_focus() operates on a tree without window...
6450 * actually, this is very questionable behaviour.
6453 gtk_container_foreach (GTK_CONTAINER (toplevel),
6454 reset_focus_recurse,
6458 /* now propagate the new focus up the widget tree and finally
6459 * set it on the window
6461 widget = focus_widget;
6462 while (widget->priv->parent)
6464 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6465 widget = widget->priv->parent;
6467 if (GTK_IS_WINDOW (widget))
6468 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6473 gtk_widget_real_query_tooltip (GtkWidget *widget,
6476 gboolean keyboard_tip,
6477 GtkTooltip *tooltip)
6479 gchar *tooltip_markup;
6480 gboolean has_tooltip;
6482 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6483 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6485 if (has_tooltip && tooltip_markup)
6487 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6495 gtk_widget_real_style_updated (GtkWidget *widget)
6497 GtkWidgetPrivate *priv = widget->priv;
6499 gtk_widget_update_pango_context (widget);
6501 if (priv->style != NULL &&
6502 priv->style != gtk_widget_get_default_style ())
6504 /* Trigger ::style-set for old
6505 * widgets not listening to this
6507 g_signal_emit (widget,
6508 widget_signals[STYLE_SET],
6510 widget->priv->style);
6513 if (widget->priv->context)
6515 if (gtk_widget_get_realized (widget) &&
6516 gtk_widget_get_has_window (widget))
6517 gtk_style_context_set_background (widget->priv->context,
6518 widget->priv->window);
6521 if (widget->priv->anchored)
6522 gtk_widget_queue_resize (widget);
6526 gtk_widget_real_show_help (GtkWidget *widget,
6527 GtkWidgetHelpType help_type)
6529 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6531 _gtk_tooltip_toggle_keyboard_mode (widget);
6540 gtk_widget_real_focus (GtkWidget *widget,
6541 GtkDirectionType direction)
6543 if (!gtk_widget_get_can_focus (widget))
6546 if (!gtk_widget_is_focus (widget))
6548 gtk_widget_grab_focus (widget);
6556 gtk_widget_real_move_focus (GtkWidget *widget,
6557 GtkDirectionType direction)
6559 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6561 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6563 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6569 gtk_widget_real_keynav_failed (GtkWidget *widget,
6570 GtkDirectionType direction)
6572 gboolean cursor_only;
6576 case GTK_DIR_TAB_FORWARD:
6577 case GTK_DIR_TAB_BACKWARD:
6584 g_object_get (gtk_widget_get_settings (widget),
6585 "gtk-keynav-cursor-only", &cursor_only,
6592 gtk_widget_error_bell (widget);
6598 * gtk_widget_set_can_focus:
6599 * @widget: a #GtkWidget
6600 * @can_focus: whether or not @widget can own the input focus.
6602 * Specifies whether @widget can own the input focus. See
6603 * gtk_widget_grab_focus() for actually setting the input focus on a
6609 gtk_widget_set_can_focus (GtkWidget *widget,
6612 g_return_if_fail (GTK_IS_WIDGET (widget));
6614 if (widget->priv->can_focus != can_focus)
6616 widget->priv->can_focus = can_focus;
6618 gtk_widget_queue_resize (widget);
6619 g_object_notify (G_OBJECT (widget), "can-focus");
6624 * gtk_widget_get_can_focus:
6625 * @widget: a #GtkWidget
6627 * Determines whether @widget can own the input focus. See
6628 * gtk_widget_set_can_focus().
6630 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6635 gtk_widget_get_can_focus (GtkWidget *widget)
6637 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6639 return widget->priv->can_focus;
6643 * gtk_widget_has_focus:
6644 * @widget: a #GtkWidget
6646 * Determines if the widget has the global input focus. See
6647 * gtk_widget_is_focus() for the difference between having the global
6648 * input focus, and only having the focus within a toplevel.
6650 * Return value: %TRUE if the widget has the global input focus.
6655 gtk_widget_has_focus (GtkWidget *widget)
6657 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6659 return widget->priv->has_focus;
6663 * gtk_widget_is_focus:
6664 * @widget: a #GtkWidget
6666 * Determines if the widget is the focus widget within its
6667 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6668 * necessarily set; %HAS_FOCUS will only be set if the
6669 * toplevel widget additionally has the global input focus.)
6671 * Return value: %TRUE if the widget is the focus widget.
6674 gtk_widget_is_focus (GtkWidget *widget)
6676 GtkWidget *toplevel;
6678 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6680 toplevel = gtk_widget_get_toplevel (widget);
6682 if (GTK_IS_WINDOW (toplevel))
6683 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6689 * gtk_widget_set_can_default:
6690 * @widget: a #GtkWidget
6691 * @can_default: whether or not @widget can be a default widget.
6693 * Specifies whether @widget can be a default widget. See
6694 * gtk_widget_grab_default() for details about the meaning of
6700 gtk_widget_set_can_default (GtkWidget *widget,
6701 gboolean can_default)
6703 g_return_if_fail (GTK_IS_WIDGET (widget));
6705 if (widget->priv->can_default != can_default)
6707 widget->priv->can_default = can_default;
6709 gtk_widget_queue_resize (widget);
6710 g_object_notify (G_OBJECT (widget), "can-default");
6715 * gtk_widget_get_can_default:
6716 * @widget: a #GtkWidget
6718 * Determines whether @widget can be a default widget. See
6719 * gtk_widget_set_can_default().
6721 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6726 gtk_widget_get_can_default (GtkWidget *widget)
6728 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6730 return widget->priv->can_default;
6734 * gtk_widget_has_default:
6735 * @widget: a #GtkWidget
6737 * Determines whether @widget is the current default widget within its
6738 * toplevel. See gtk_widget_set_can_default().
6740 * Return value: %TRUE if @widget is the current default widget within
6741 * its toplevel, %FALSE otherwise
6746 gtk_widget_has_default (GtkWidget *widget)
6748 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6750 return widget->priv->has_default;
6754 _gtk_widget_set_has_default (GtkWidget *widget,
6755 gboolean has_default)
6757 widget->priv->has_default = has_default;
6761 * gtk_widget_grab_default:
6762 * @widget: a #GtkWidget
6764 * Causes @widget to become the default widget. @widget must have the
6765 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6766 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6767 * %TRUE)</literal>. The default widget is activated when
6768 * the user presses Enter in a window. Default widgets must be
6769 * activatable, that is, gtk_widget_activate() should affect them. Note
6770 * that #GtkEntry widgets require the "activates-default" property
6771 * set to %TRUE before they activate the default widget when Enter
6772 * is pressed and the #GtkEntry is focused.
6775 gtk_widget_grab_default (GtkWidget *widget)
6779 g_return_if_fail (GTK_IS_WIDGET (widget));
6780 g_return_if_fail (gtk_widget_get_can_default (widget));
6782 window = gtk_widget_get_toplevel (widget);
6784 if (window && gtk_widget_is_toplevel (window))
6785 gtk_window_set_default (GTK_WINDOW (window), widget);
6787 g_warning (G_STRLOC ": widget not within a GtkWindow");
6791 * gtk_widget_set_receives_default:
6792 * @widget: a #GtkWidget
6793 * @receives_default: whether or not @widget can be a default widget.
6795 * Specifies whether @widget will be treated as the default widget
6796 * within its toplevel when it has the focus, even if another widget
6799 * See gtk_widget_grab_default() for details about the meaning of
6805 gtk_widget_set_receives_default (GtkWidget *widget,
6806 gboolean receives_default)
6808 g_return_if_fail (GTK_IS_WIDGET (widget));
6810 if (widget->priv->receives_default != receives_default)
6812 widget->priv->receives_default = receives_default;
6814 g_object_notify (G_OBJECT (widget), "receives-default");
6819 * gtk_widget_get_receives_default:
6820 * @widget: a #GtkWidget
6822 * Determines whether @widget is alyways treated as default widget
6823 * withing its toplevel when it has the focus, even if another widget
6826 * See gtk_widget_set_receives_default().
6828 * Return value: %TRUE if @widget acts as default widget when focussed,
6834 gtk_widget_get_receives_default (GtkWidget *widget)
6836 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6838 return widget->priv->receives_default;
6842 * gtk_widget_has_grab:
6843 * @widget: a #GtkWidget
6845 * Determines whether the widget is currently grabbing events, so it
6846 * is the only widget receiving input events (keyboard and mouse).
6848 * See also gtk_grab_add().
6850 * Return value: %TRUE if the widget is in the grab_widgets stack
6855 gtk_widget_has_grab (GtkWidget *widget)
6857 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6859 return widget->priv->has_grab;
6863 _gtk_widget_set_has_grab (GtkWidget *widget,
6866 widget->priv->has_grab = has_grab;
6870 * gtk_widget_device_is_shadowed:
6871 * @widget: a #GtkWidget
6872 * @device: a #GdkDevice
6874 * Returns %TRUE if @device has been shadowed by a GTK+
6875 * device grab on another widget, so it would stop sending
6876 * events to @widget. This may be used in the
6877 * #GtkWidget::grab-notify signal to check for specific
6878 * devices. See gtk_device_grab_add().
6880 * Returns: %TRUE if there is an ongoing grab on @device
6881 * by another #GtkWidget than @widget.
6886 gtk_widget_device_is_shadowed (GtkWidget *widget,
6889 GtkWindowGroup *group;
6890 GtkWidget *grab_widget, *toplevel;
6892 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6893 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6895 if (!gtk_widget_get_realized (widget))
6898 toplevel = gtk_widget_get_toplevel (widget);
6900 if (GTK_IS_WINDOW (toplevel))
6901 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6903 group = gtk_window_get_group (NULL);
6905 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6907 /* Widget not inside the hierarchy of grab_widget */
6909 widget != grab_widget &&
6910 !gtk_widget_is_ancestor (widget, grab_widget))
6913 grab_widget = gtk_window_group_get_current_grab (group);
6914 if (grab_widget && widget != grab_widget &&
6915 !gtk_widget_is_ancestor (widget, grab_widget))
6922 * gtk_widget_set_name:
6923 * @widget: a #GtkWidget
6924 * @name: name for the widget
6926 * Widgets can be named, which allows you to refer to them from a
6927 * CSS file. You can apply a style to widgets with a particular name
6928 * in the CSS file. See the documentation for the CSS syntax (on the
6929 * same page as the docs for #GtkStyleContext).
6931 * Note that the CSS syntax has certain special characters to delimit
6932 * and represent elements in a selector (period, #, >, *...),
6933 * so using these will make your widget impossible to match by name.
6934 * Any combination of alphanumeric symbols, dashes and underscores will
6938 gtk_widget_set_name (GtkWidget *widget,
6941 GtkWidgetPrivate *priv;
6944 g_return_if_fail (GTK_IS_WIDGET (widget));
6946 priv = widget->priv;
6948 new_name = g_strdup (name);
6949 g_free (priv->name);
6950 priv->name = new_name;
6952 gtk_widget_reset_style (widget);
6954 g_object_notify (G_OBJECT (widget), "name");
6958 * gtk_widget_get_name:
6959 * @widget: a #GtkWidget
6961 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6962 * significance of widget names.
6964 * Return value: name of the widget. This string is owned by GTK+ and
6965 * should not be modified or freed
6967 G_CONST_RETURN gchar*
6968 gtk_widget_get_name (GtkWidget *widget)
6970 GtkWidgetPrivate *priv;
6972 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6974 priv = widget->priv;
6978 return G_OBJECT_TYPE_NAME (widget);
6982 _gtk_widget_update_state_flags (GtkWidget *widget,
6983 GtkStateFlags flags,
6986 GtkWidgetPrivate *priv;
6988 priv = widget->priv;
6990 /* Handle insensitive first, since it is propagated
6991 * differently throughout the widget hierarchy.
6993 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_UNSET))
6994 gtk_widget_set_sensitive (widget, TRUE);
6995 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation != STATE_CHANGE_UNSET))
6996 gtk_widget_set_sensitive (widget, FALSE);
6997 else if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && !(flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_REPLACE))
6998 gtk_widget_set_sensitive (widget, TRUE);
7000 if (operation != STATE_CHANGE_REPLACE)
7001 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
7004 operation == STATE_CHANGE_REPLACE)
7009 data.operation = operation;
7010 data.use_forall = FALSE;
7012 gtk_widget_propagate_state (widget, &data);
7014 gtk_widget_queue_resize (widget);
7019 * gtk_widget_set_state_flags:
7020 * @widget: a #GtkWidget
7021 * @flags: State flags to turn on
7022 * @clear: Whether to clear state before turning on @flags
7024 * This function is for use in widget implementations. Turns on flag
7025 * values in the current widget state (insensitive, prelighted, etc.).
7027 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7028 * will be propagated down to all non-internal children if @widget is a
7029 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7030 * down to all #GtkContainer children by different means than turning on the
7031 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7032 * gtk_widget_is_sensitive() will make use of these.
7037 gtk_widget_set_state_flags (GtkWidget *widget,
7038 GtkStateFlags flags,
7041 g_return_if_fail (GTK_IS_WIDGET (widget));
7043 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7044 (clear && widget->priv->state_flags == flags))
7048 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7050 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
7054 * gtk_widget_unset_state_flags:
7055 * @widget: a #GtkWidget
7056 * @flags: State flags to turn off
7058 * This function is for use in widget implementations. Turns off flag
7059 * values for the current widget state (insensitive, prelighted, etc.).
7060 * See gtk_widget_set_state_flags().
7065 gtk_widget_unset_state_flags (GtkWidget *widget,
7066 GtkStateFlags flags)
7068 g_return_if_fail (GTK_IS_WIDGET (widget));
7070 if ((widget->priv->state_flags & flags) == 0)
7073 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
7077 * gtk_widget_get_state_flags:
7078 * @widget: a #GtkWidget
7080 * Returns the widget state as a flag set. It is worth mentioning
7081 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7082 * returned, that is, also based on parent insensitivity, even if
7083 * @widget itself is sensitive.
7085 * Returns: The state flags for widget
7090 gtk_widget_get_state_flags (GtkWidget *widget)
7092 GtkStateFlags flags;
7094 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7096 flags = widget->priv->state_flags;
7098 if (gtk_widget_has_focus (widget))
7099 flags |= GTK_STATE_FLAG_FOCUSED;
7105 * gtk_widget_set_state:
7106 * @widget: a #GtkWidget
7107 * @state: new state for @widget
7109 * This function is for use in widget implementations. Sets the state
7110 * of a widget (insensitive, prelighted, etc.) Usually you should set
7111 * the state using wrapper functions such as gtk_widget_set_sensitive().
7113 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7116 gtk_widget_set_state (GtkWidget *widget,
7119 GtkStateFlags flags;
7121 if (state == gtk_widget_get_state (widget))
7126 case GTK_STATE_ACTIVE:
7127 flags = GTK_STATE_FLAG_ACTIVE;
7129 case GTK_STATE_PRELIGHT:
7130 flags = GTK_STATE_FLAG_PRELIGHT;
7132 case GTK_STATE_SELECTED:
7133 flags = GTK_STATE_FLAG_SELECTED;
7135 case GTK_STATE_INSENSITIVE:
7136 flags = GTK_STATE_FLAG_INSENSITIVE;
7138 case GTK_STATE_INCONSISTENT:
7139 flags = GTK_STATE_FLAG_INCONSISTENT;
7141 case GTK_STATE_FOCUSED:
7142 flags = GTK_STATE_FLAG_FOCUSED;
7144 case GTK_STATE_NORMAL:
7150 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7154 * gtk_widget_get_state:
7155 * @widget: a #GtkWidget
7157 * Returns the widget's state. See gtk_widget_set_state().
7159 * Returns: the state of @widget.
7163 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7166 gtk_widget_get_state (GtkWidget *widget)
7168 GtkStateFlags flags;
7170 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7172 flags = gtk_widget_get_state_flags (widget);
7174 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7175 return GTK_STATE_INSENSITIVE;
7176 else if (flags & GTK_STATE_FLAG_ACTIVE)
7177 return GTK_STATE_ACTIVE;
7178 else if (flags & GTK_STATE_FLAG_SELECTED)
7179 return GTK_STATE_SELECTED;
7180 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7181 return GTK_STATE_PRELIGHT;
7183 return GTK_STATE_NORMAL;
7187 * gtk_widget_set_visible:
7188 * @widget: a #GtkWidget
7189 * @visible: whether the widget should be shown or not
7191 * Sets the visibility state of @widget. Note that setting this to
7192 * %TRUE doesn't mean the widget is actually viewable, see
7193 * gtk_widget_get_visible().
7195 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7196 * but is nicer to use when the visibility of the widget depends on
7202 gtk_widget_set_visible (GtkWidget *widget,
7205 g_return_if_fail (GTK_IS_WIDGET (widget));
7207 if (visible != gtk_widget_get_visible (widget))
7210 gtk_widget_show (widget);
7212 gtk_widget_hide (widget);
7217 _gtk_widget_set_visible_flag (GtkWidget *widget,
7220 widget->priv->visible = visible;
7224 * gtk_widget_get_visible:
7225 * @widget: a #GtkWidget
7227 * Determines whether the widget is visible. Note that this doesn't
7228 * take into account whether the widget's parent is also visible
7229 * or the widget is obscured in any way.
7231 * See gtk_widget_set_visible().
7233 * Return value: %TRUE if the widget is visible
7238 gtk_widget_get_visible (GtkWidget *widget)
7240 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7242 return widget->priv->visible;
7246 * gtk_widget_set_has_window:
7247 * @widget: a #GtkWidget
7248 * @has_window: whether or not @widget has a window.
7250 * Specifies whether @widget has a #GdkWindow of its own. Note that
7251 * all realized widgets have a non-%NULL "window" pointer
7252 * (gtk_widget_get_window() never returns a %NULL window when a widget
7253 * is realized), but for many of them it's actually the #GdkWindow of
7254 * one of its parent widgets. Widgets that do not create a %window for
7255 * themselves in #GtkWidget::realize must announce this by
7256 * calling this function with @has_window = %FALSE.
7258 * This function should only be called by widget implementations,
7259 * and they should call it in their init() function.
7264 gtk_widget_set_has_window (GtkWidget *widget,
7265 gboolean has_window)
7267 g_return_if_fail (GTK_IS_WIDGET (widget));
7269 widget->priv->no_window = !has_window;
7273 * gtk_widget_get_has_window:
7274 * @widget: a #GtkWidget
7276 * Determines whether @widget has a #GdkWindow of its own. See
7277 * gtk_widget_set_has_window().
7279 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7284 gtk_widget_get_has_window (GtkWidget *widget)
7286 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7288 return ! widget->priv->no_window;
7292 * gtk_widget_is_toplevel:
7293 * @widget: a #GtkWidget
7295 * Determines whether @widget is a toplevel widget.
7297 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7298 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7301 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7306 gtk_widget_is_toplevel (GtkWidget *widget)
7308 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7310 return widget->priv->toplevel;
7314 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7315 gboolean is_toplevel)
7317 widget->priv->toplevel = is_toplevel;
7321 * gtk_widget_is_drawable:
7322 * @widget: a #GtkWidget
7324 * Determines whether @widget can be drawn to. A widget can be drawn
7325 * to if it is mapped and visible.
7327 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7332 gtk_widget_is_drawable (GtkWidget *widget)
7334 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7336 return (gtk_widget_get_visible (widget) &&
7337 gtk_widget_get_mapped (widget));
7341 * gtk_widget_get_realized:
7342 * @widget: a #GtkWidget
7344 * Determines whether @widget is realized.
7346 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7351 gtk_widget_get_realized (GtkWidget *widget)
7353 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7355 return widget->priv->realized;
7359 * gtk_widget_set_realized:
7360 * @widget: a #GtkWidget
7361 * @realized: %TRUE to mark the widget as realized
7363 * Marks the widget as being realized.
7365 * This function should only ever be called in a derived widget's
7366 * "realize" or "unrealize" implementation.
7371 gtk_widget_set_realized (GtkWidget *widget,
7374 g_return_if_fail (GTK_IS_WIDGET (widget));
7376 widget->priv->realized = realized;
7380 * gtk_widget_get_mapped:
7381 * @widget: a #GtkWidget
7383 * Whether the widget is mapped.
7385 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7390 gtk_widget_get_mapped (GtkWidget *widget)
7392 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7394 return widget->priv->mapped;
7398 * gtk_widget_set_mapped:
7399 * @widget: a #GtkWidget
7400 * @mapped: %TRUE to mark the widget as mapped
7402 * Marks the widget as being realized.
7404 * This function should only ever be called in a derived widget's
7405 * "map" or "unmap" implementation.
7410 gtk_widget_set_mapped (GtkWidget *widget,
7413 g_return_if_fail (GTK_IS_WIDGET (widget));
7415 widget->priv->mapped = mapped;
7419 * gtk_widget_set_app_paintable:
7420 * @widget: a #GtkWidget
7421 * @app_paintable: %TRUE if the application will paint on the widget
7423 * Sets whether the application intends to draw on the widget in
7424 * an #GtkWidget::draw handler.
7426 * This is a hint to the widget and does not affect the behavior of
7427 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7428 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7429 * the effect is to suppress default themed drawing of the widget's
7430 * background. (Children of the widget will still be drawn.) The application
7431 * is then entirely responsible for drawing the widget background.
7433 * Note that the background is still drawn when the widget is mapped.
7436 gtk_widget_set_app_paintable (GtkWidget *widget,
7437 gboolean app_paintable)
7439 g_return_if_fail (GTK_IS_WIDGET (widget));
7441 app_paintable = (app_paintable != FALSE);
7443 if (widget->priv->app_paintable != app_paintable)
7445 widget->priv->app_paintable = app_paintable;
7447 if (gtk_widget_is_drawable (widget))
7448 gtk_widget_queue_draw (widget);
7450 g_object_notify (G_OBJECT (widget), "app-paintable");
7455 * gtk_widget_get_app_paintable:
7456 * @widget: a #GtkWidget
7458 * Determines whether the application intends to draw on the widget in
7459 * an #GtkWidget::draw handler.
7461 * See gtk_widget_set_app_paintable()
7463 * Return value: %TRUE if the widget is app paintable
7468 gtk_widget_get_app_paintable (GtkWidget *widget)
7470 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7472 return widget->priv->app_paintable;
7476 * gtk_widget_set_double_buffered:
7477 * @widget: a #GtkWidget
7478 * @double_buffered: %TRUE to double-buffer a widget
7480 * Widgets are double buffered by default; you can use this function
7481 * to turn off the buffering. "Double buffered" simply means that
7482 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7483 * automatically around expose events sent to the
7484 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7485 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7486 * buffer to the screen. The result is that users see the window
7487 * update in one smooth step, and don't see individual graphics
7488 * primitives being rendered.
7490 * In very simple terms, double buffered widgets don't flicker,
7491 * so you would only use this function to turn off double buffering
7492 * if you had special needs and really knew what you were doing.
7494 * Note: if you turn off double-buffering, you have to handle
7495 * expose events, since even the clearing to the background color or
7496 * pixmap will not happen automatically (as it is done in
7497 * gdk_window_begin_paint()).
7500 gtk_widget_set_double_buffered (GtkWidget *widget,
7501 gboolean double_buffered)
7503 g_return_if_fail (GTK_IS_WIDGET (widget));
7505 double_buffered = (double_buffered != FALSE);
7507 if (widget->priv->double_buffered != double_buffered)
7509 widget->priv->double_buffered = double_buffered;
7511 g_object_notify (G_OBJECT (widget), "double-buffered");
7516 * gtk_widget_get_double_buffered:
7517 * @widget: a #GtkWidget
7519 * Determines whether the widget is double buffered.
7521 * See gtk_widget_set_double_buffered()
7523 * Return value: %TRUE if the widget is double buffered
7528 gtk_widget_get_double_buffered (GtkWidget *widget)
7530 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7532 return widget->priv->double_buffered;
7536 * gtk_widget_set_redraw_on_allocate:
7537 * @widget: a #GtkWidget
7538 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7539 * when it is allocated to a new size. Otherwise, only the
7540 * new portion of the widget will be redrawn.
7542 * Sets whether the entire widget is queued for drawing when its size
7543 * allocation changes. By default, this setting is %TRUE and
7544 * the entire widget is redrawn on every size change. If your widget
7545 * leaves the upper left unchanged when made bigger, turning this
7546 * setting off will improve performance.
7548 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7549 * off all allocation on resizing: the widget will not even redraw if
7550 * its position changes; this is to allow containers that don't draw
7551 * anything to avoid excess invalidations. If you set this flag on a
7552 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7553 * you are responsible for invalidating both the old and new allocation
7554 * of the widget when the widget is moved and responsible for invalidating
7555 * regions newly when the widget increases size.
7558 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7559 gboolean redraw_on_allocate)
7561 g_return_if_fail (GTK_IS_WIDGET (widget));
7563 widget->priv->redraw_on_alloc = redraw_on_allocate;
7567 * gtk_widget_set_sensitive:
7568 * @widget: a #GtkWidget
7569 * @sensitive: %TRUE to make the widget sensitive
7571 * Sets the sensitivity of a widget. A widget is sensitive if the user
7572 * can interact with it. Insensitive widgets are "grayed out" and the
7573 * user can't interact with them. Insensitive widgets are known as
7574 * "inactive", "disabled", or "ghosted" in some other toolkits.
7577 gtk_widget_set_sensitive (GtkWidget *widget,
7580 GtkWidgetPrivate *priv;
7583 g_return_if_fail (GTK_IS_WIDGET (widget));
7585 priv = widget->priv;
7587 sensitive = (sensitive != FALSE);
7589 if (priv->sensitive == sensitive)
7592 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7596 priv->sensitive = TRUE;
7597 data.operation = STATE_CHANGE_UNSET;
7601 priv->sensitive = FALSE;
7602 data.operation = STATE_CHANGE_SET;
7605 data.use_forall = TRUE;
7607 gtk_widget_propagate_state (widget, &data);
7609 gtk_widget_queue_resize (widget);
7611 g_object_notify (G_OBJECT (widget), "sensitive");
7615 * gtk_widget_get_sensitive:
7616 * @widget: a #GtkWidget
7618 * Returns the widget's sensitivity (in the sense of returning
7619 * the value that has been set using gtk_widget_set_sensitive()).
7621 * The effective sensitivity of a widget is however determined by both its
7622 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7624 * Returns: %TRUE if the widget is sensitive
7629 gtk_widget_get_sensitive (GtkWidget *widget)
7631 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7633 return widget->priv->sensitive;
7637 * gtk_widget_is_sensitive:
7638 * @widget: a #GtkWidget
7640 * Returns the widget's effective sensitivity, which means
7641 * it is sensitive itself and also its parent widget is sensitive
7643 * Returns: %TRUE if the widget is effectively sensitive
7648 gtk_widget_is_sensitive (GtkWidget *widget)
7650 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7652 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
7656 _gtk_widget_update_path (GtkWidget *widget)
7658 if (widget->priv->path)
7660 gtk_widget_path_free (widget->priv->path);
7661 widget->priv->path = NULL;
7664 gtk_widget_get_path (widget);
7668 * gtk_widget_set_parent:
7669 * @widget: a #GtkWidget
7670 * @parent: parent container
7672 * This function is useful only when implementing subclasses of
7674 * Sets the container as the parent of @widget, and takes care of
7675 * some details such as updating the state and style of the child
7676 * to reflect its new location. The opposite function is
7677 * gtk_widget_unparent().
7680 gtk_widget_set_parent (GtkWidget *widget,
7683 GtkStateFlags parent_flags;
7684 GtkWidgetPrivate *priv;
7687 g_return_if_fail (GTK_IS_WIDGET (widget));
7688 g_return_if_fail (GTK_IS_WIDGET (parent));
7689 g_return_if_fail (widget != parent);
7691 priv = widget->priv;
7693 if (priv->parent != NULL)
7695 g_warning ("Can't set a parent on widget which has a parent\n");
7698 if (gtk_widget_is_toplevel (widget))
7700 g_warning ("Can't set a parent on a toplevel widget\n");
7704 /* keep this function in sync with gtk_menu_attach_to_widget()
7707 g_object_ref_sink (widget);
7709 gtk_widget_push_verify_invariants (widget);
7711 priv->parent = parent;
7713 parent_flags = gtk_widget_get_state_flags (parent);
7715 /* Merge both old state and current parent state,
7716 * making sure to only propagate the right states */
7717 data.flags = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
7718 data.flags |= priv->state_flags;
7720 data.operation = STATE_CHANGE_REPLACE;
7721 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7722 gtk_widget_propagate_state (widget, &data);
7724 gtk_widget_reset_style (widget);
7726 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7727 if (priv->parent->priv->anchored)
7728 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7729 g_object_notify (G_OBJECT (widget), "parent");
7731 /* Enforce realized/mapped invariants
7733 if (gtk_widget_get_realized (priv->parent))
7734 gtk_widget_realize (widget);
7736 if (gtk_widget_get_visible (priv->parent) &&
7737 gtk_widget_get_visible (widget))
7739 if (gtk_widget_get_child_visible (widget) &&
7740 gtk_widget_get_mapped (priv->parent))
7741 gtk_widget_map (widget);
7743 gtk_widget_queue_resize (widget);
7746 /* child may cause parent's expand to change, if the child is
7747 * expanded. If child is not expanded, then it can't modify the
7748 * parent's expand. If the child becomes expanded later then it will
7749 * queue compute_expand then. This optimization plus defaulting
7750 * newly-constructed widgets to need_compute_expand=FALSE should
7751 * mean that initially building a widget tree doesn't have to keep
7752 * walking up setting need_compute_expand on parents over and over.
7754 * We can't change a parent to need to expand unless we're visible.
7756 if (gtk_widget_get_visible (widget) &&
7757 (priv->need_compute_expand ||
7758 priv->computed_hexpand ||
7759 priv->computed_vexpand))
7761 gtk_widget_queue_compute_expand (parent);
7764 gtk_widget_pop_verify_invariants (widget);
7768 * gtk_widget_get_parent:
7769 * @widget: a #GtkWidget
7771 * Returns the parent container of @widget.
7773 * Return value: (transfer none): the parent container of @widget, or %NULL
7776 gtk_widget_get_parent (GtkWidget *widget)
7778 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7780 return widget->priv->parent;
7783 /*****************************************
7785 * see docs/styles.txt
7786 *****************************************/
7789 * gtk_widget_style_attach:
7790 * @widget: a #GtkWidget
7792 * This function attaches the widget's #GtkStyle to the widget's
7793 * #GdkWindow. It is a replacement for
7796 * widget->style = gtk_style_attach (widget->style, widget->window);
7799 * and should only ever be called in a derived widget's "realize"
7800 * implementation which does not chain up to its parent class'
7801 * "realize" implementation, because one of the parent classes
7802 * (finally #GtkWidget) would attach the style itself.
7806 * Deprecated: 3.0. This step is unnecessary with #GtkStyleContext.
7809 gtk_widget_style_attach (GtkWidget *widget)
7811 g_return_if_fail (GTK_IS_WIDGET (widget));
7812 g_return_if_fail (gtk_widget_get_realized (widget));
7816 * gtk_widget_has_rc_style:
7817 * @widget: a #GtkWidget
7819 * Determines if the widget style has been looked up through the rc mechanism.
7821 * Returns: %TRUE if the widget has been looked up through the rc
7822 * mechanism, %FALSE otherwise.
7826 * Deprecated:3.0: Use #GtkStyleContext instead
7829 gtk_widget_has_rc_style (GtkWidget *widget)
7831 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7833 return widget->priv->rc_style;
7837 * gtk_widget_set_style:
7838 * @widget: a #GtkWidget
7839 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect
7840 * of a previous call to gtk_widget_set_style() and go back to
7843 * Used to set the #GtkStyle for a widget (@widget->style). Since
7844 * GTK 3, this function does nothing, the passed in style is ignored.
7846 * Deprecated:3.0: Use #GtkStyleContext instead
7849 gtk_widget_set_style (GtkWidget *widget,
7852 g_return_if_fail (GTK_IS_WIDGET (widget));
7856 * gtk_widget_ensure_style:
7857 * @widget: a #GtkWidget
7859 * Ensures that @widget has a style (@widget->style).
7861 * Not a very useful function; most of the time, if you
7862 * want the style, the widget is realized, and realized
7863 * widgets are guaranteed to have a style already.
7865 * Deprecated:3.0: Use #GtkStyleContext instead
7868 gtk_widget_ensure_style (GtkWidget *widget)
7870 GtkWidgetPrivate *priv;
7872 g_return_if_fail (GTK_IS_WIDGET (widget));
7874 priv = widget->priv;
7876 if (priv->style == gtk_widget_get_default_style ())
7878 g_object_unref (priv->style);
7882 g_signal_emit (widget,
7883 widget_signals[STYLE_SET],
7889 * gtk_widget_get_style:
7890 * @widget: a #GtkWidget
7892 * Simply an accessor function that returns @widget->style.
7894 * Return value: (transfer none): the widget's #GtkStyle
7896 * Deprecated:3.0: Use #GtkStyleContext instead
7899 gtk_widget_get_style (GtkWidget *widget)
7901 GtkWidgetPrivate *priv;
7903 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7905 priv = widget->priv;
7907 if (priv->style == NULL)
7909 priv->style = g_object_new (GTK_TYPE_STYLE,
7910 "context", gtk_widget_get_style_context (widget),
7919 * gtk_widget_modify_style:
7920 * @widget: a #GtkWidget
7921 * @style: the #GtkRcStyle holding the style modifications
7923 * Modifies style values on the widget.
7925 * Modifications made using this technique take precedence over
7926 * style values set via an RC file, however, they will be overridden
7927 * if a style is explicitely set on the widget using gtk_widget_set_style().
7928 * The #GtkRcStyle structure is designed so each field can either be
7929 * set or unset, so it is possible, using this function, to modify some
7930 * style values and leave the others unchanged.
7932 * Note that modifications made with this function are not cumulative
7933 * with previous calls to gtk_widget_modify_style() or with such
7934 * functions as gtk_widget_modify_fg(). If you wish to retain
7935 * previous values, you must first call gtk_widget_get_modifier_style(),
7936 * make your modifications to the returned style, then call
7937 * gtk_widget_modify_style() with that style. On the other hand,
7938 * if you first call gtk_widget_modify_style(), subsequent calls
7939 * to such functions gtk_widget_modify_fg() will have a cumulative
7940 * effect with the initial modifications.
7942 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7945 gtk_widget_modify_style (GtkWidget *widget,
7948 g_return_if_fail (GTK_IS_WIDGET (widget));
7949 g_return_if_fail (GTK_IS_RC_STYLE (style));
7951 g_object_set_qdata_full (G_OBJECT (widget),
7953 gtk_rc_style_copy (style),
7954 (GDestroyNotify) g_object_unref);
7958 * gtk_widget_get_modifier_style:
7959 * @widget: a #GtkWidget
7961 * Returns the current modifier style for the widget. (As set by
7962 * gtk_widget_modify_style().) If no style has previously set, a new
7963 * #GtkRcStyle will be created with all values unset, and set as the
7964 * modifier style for the widget. If you make changes to this rc
7965 * style, you must call gtk_widget_modify_style(), passing in the
7966 * returned rc style, to make sure that your changes take effect.
7968 * Caution: passing the style back to gtk_widget_modify_style() will
7969 * normally end up destroying it, because gtk_widget_modify_style() copies
7970 * the passed-in style and sets the copy as the new modifier style,
7971 * thus dropping any reference to the old modifier style. Add a reference
7972 * to the modifier style if you want to keep it alive.
7974 * Return value: (transfer none): the modifier style for the widget.
7975 * This rc style is owned by the widget. If you want to keep a
7976 * pointer to value this around, you must add a refcount using
7979 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7982 gtk_widget_get_modifier_style (GtkWidget *widget)
7984 GtkRcStyle *rc_style;
7986 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7988 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7992 rc_style = gtk_rc_style_new ();
7993 g_object_set_qdata_full (G_OBJECT (widget),
7996 (GDestroyNotify) g_object_unref);
8003 gtk_widget_modify_color_component (GtkWidget *widget,
8004 GtkRcFlags component,
8006 const GdkColor *color)
8008 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
8015 rc_style->fg[state] = *color;
8018 rc_style->bg[state] = *color;
8021 rc_style->text[state] = *color;
8024 rc_style->base[state] = *color;
8027 g_assert_not_reached();
8030 rc_style->color_flags[state] |= component;
8033 rc_style->color_flags[state] &= ~component;
8035 gtk_widget_modify_style (widget, rc_style);
8039 modifier_style_changed (GtkModifierStyle *style,
8042 GtkStyleContext *context;
8044 context = gtk_widget_get_style_context (widget);
8045 gtk_style_context_invalidate (context);
8048 static GtkModifierStyle *
8049 _gtk_widget_get_modifier_properties (GtkWidget *widget)
8051 GtkModifierStyle *style;
8053 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
8055 if (G_UNLIKELY (!style))
8057 GtkStyleContext *context;
8059 style = _gtk_modifier_style_new ();
8060 g_object_set_qdata_full (G_OBJECT (widget),
8061 quark_modifier_style,
8063 (GDestroyNotify) g_object_unref);
8065 g_signal_connect (style, "changed",
8066 G_CALLBACK (modifier_style_changed), widget);
8068 context = gtk_widget_get_style_context (widget);
8070 gtk_style_context_add_provider (context,
8071 GTK_STYLE_PROVIDER (style),
8072 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
8079 * gtk_widget_override_color:
8080 * @widget: a #GtkWidget
8081 * @state: the state for which to set the color
8082 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8083 * of previous calls to gtk_widget_override_color()
8085 * Sets the color to use for a widget.
8087 * All other style values are left untouched.
8090 * This API is mostly meant as a quick way for applications to
8091 * change a widget appearance. If you are developing a widgets
8092 * library and intend this change to be themeable, it is better
8093 * done by setting meaningful CSS classes and regions in your
8094 * widget/container implementation through gtk_style_context_add_class()
8095 * and gtk_style_context_add_region().
8097 * This way, your widget library can install a #GtkCssProvider
8098 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
8099 * to provide a default styling for those widgets that need so, and
8100 * this theming may fully overridden by the user's theme.
8103 * Note that for complex widgets this may bring in undesired
8104 * results (such as uniform background color everywhere), in
8105 * these cases it is better to fully style such widgets through a
8106 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8113 gtk_widget_override_color (GtkWidget *widget,
8114 GtkStateFlags state,
8115 const GdkRGBA *color)
8117 GtkModifierStyle *style;
8119 g_return_if_fail (GTK_IS_WIDGET (widget));
8121 style = _gtk_widget_get_modifier_properties (widget);
8122 _gtk_modifier_style_set_color (style, state, color);
8126 * gtk_widget_override_background_color:
8127 * @widget: a #GtkWidget
8128 * @state: the state for which to set the background color
8129 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8130 * of previous calls to gtk_widget_override_background_color()
8132 * Sets the background color to use for a widget.
8134 * All other style values are left untouched.
8135 * See gtk_widget_override_color().
8140 gtk_widget_override_background_color (GtkWidget *widget,
8141 GtkStateFlags state,
8142 const GdkRGBA *color)
8144 GtkModifierStyle *style;
8146 g_return_if_fail (GTK_IS_WIDGET (widget));
8148 style = _gtk_widget_get_modifier_properties (widget);
8149 _gtk_modifier_style_set_background_color (style, state, color);
8153 * gtk_widget_override_font:
8154 * @widget: a #GtkWidget
8155 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
8156 * the effect of previous calls to gtk_widget_override_font()
8158 * Sets the font to use for a widget. All other style values are
8159 * left untouched. See gtk_widget_override_color().
8164 gtk_widget_override_font (GtkWidget *widget,
8165 const PangoFontDescription *font_desc)
8167 GtkModifierStyle *style;
8169 g_return_if_fail (GTK_IS_WIDGET (widget));
8171 style = _gtk_widget_get_modifier_properties (widget);
8172 _gtk_modifier_style_set_font (style, font_desc);
8176 * gtk_widget_override_symbolic_color:
8177 * @widget: a #GtkWidget
8178 * @name: the name of the symbolic color to modify
8179 * @color: (allow-none): the color to assign (does not need
8180 * to be allocated), or %NULL to undo the effect of previous
8181 * calls to gtk_widget_override_symbolic_color()
8183 * Sets a symbolic color for a widget.
8185 * All other style values are left untouched.
8186 * See gtk_widget_override_color() for overriding the foreground
8187 * or background color.
8192 gtk_widget_override_symbolic_color (GtkWidget *widget,
8194 const GdkRGBA *color)
8196 GtkModifierStyle *style;
8198 g_return_if_fail (GTK_IS_WIDGET (widget));
8200 style = _gtk_widget_get_modifier_properties (widget);
8201 _gtk_modifier_style_map_color (style, name, color);
8205 * gtk_widget_override_cursor:
8206 * @widget: a #GtkWidget
8207 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8208 * allocated), or %NULL to undo the effect of previous calls to
8209 * of gtk_widget_override_cursor().
8210 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8211 * need to be allocated), or %NULL to undo the effect of previous
8212 * calls to of gtk_widget_override_cursor().
8214 * Sets the cursor color to use in a widget, overriding the
8215 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8216 * style properties. All other style values are left untouched.
8217 * See also gtk_widget_modify_style().
8219 * Note that the underlying properties have the #GdkColor type,
8220 * so the alpha value in @primary and @secondary will be ignored.
8225 gtk_widget_override_cursor (GtkWidget *widget,
8226 const GdkRGBA *cursor,
8227 const GdkRGBA *secondary_cursor)
8229 GtkModifierStyle *style;
8231 g_return_if_fail (GTK_IS_WIDGET (widget));
8233 style = _gtk_widget_get_modifier_properties (widget);
8234 _gtk_modifier_style_set_color_property (style,
8236 "cursor-color", cursor);
8237 _gtk_modifier_style_set_color_property (style,
8239 "secondary-cursor-color",
8244 * gtk_widget_modify_fg:
8245 * @widget: a #GtkWidget
8246 * @state: the state for which to set the foreground color
8247 * @color: (allow-none): the color to assign (does not need to be allocated),
8248 * or %NULL to undo the effect of previous calls to
8249 * of gtk_widget_modify_fg().
8251 * Sets the foreground color for a widget in a particular state.
8253 * All other style values are left untouched.
8254 * See also gtk_widget_modify_style().
8256 * Deprecated:3.0: Use gtk_widget_override_color() instead
8259 gtk_widget_modify_fg (GtkWidget *widget,
8261 const GdkColor *color)
8263 GtkStateFlags flags;
8266 g_return_if_fail (GTK_IS_WIDGET (widget));
8267 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8271 case GTK_STATE_ACTIVE:
8272 flags = GTK_STATE_FLAG_ACTIVE;
8274 case GTK_STATE_PRELIGHT:
8275 flags = GTK_STATE_FLAG_PRELIGHT;
8277 case GTK_STATE_SELECTED:
8278 flags = GTK_STATE_FLAG_SELECTED;
8280 case GTK_STATE_INSENSITIVE:
8281 flags = GTK_STATE_FLAG_INSENSITIVE;
8283 case GTK_STATE_NORMAL:
8290 rgba.red = color->red / 65535.;
8291 rgba.green = color->green / 65535.;
8292 rgba.blue = color->blue / 65535.;
8295 gtk_widget_override_color (widget, flags, &rgba);
8298 gtk_widget_override_color (widget, flags, NULL);
8302 * gtk_widget_modify_bg:
8303 * @widget: a #GtkWidget
8304 * @state: the state for which to set the background color
8305 * @color: (allow-none): the color to assign (does not need
8306 * to be allocated), or %NULL to undo the effect of previous
8307 * calls to of gtk_widget_modify_bg().
8309 * Sets the background color for a widget in a particular state.
8311 * All other style values are left untouched.
8312 * See also gtk_widget_modify_style().
8315 * Note that "no window" widgets (which have the %GTK_NO_WINDOW
8316 * flag set) draw on their parent container's window and thus may
8317 * not draw any background themselves. This is the case for e.g.
8320 * To modify the background of such widgets, you have to set the
8321 * background color on their parent; if you want to set the background
8322 * of a rectangular area around a label, try placing the label in
8323 * a #GtkEventBox widget and setting the background color on that.
8326 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8329 gtk_widget_modify_bg (GtkWidget *widget,
8331 const GdkColor *color)
8333 GtkStateFlags flags;
8336 g_return_if_fail (GTK_IS_WIDGET (widget));
8337 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8341 case GTK_STATE_ACTIVE:
8342 flags = GTK_STATE_FLAG_ACTIVE;
8344 case GTK_STATE_PRELIGHT:
8345 flags = GTK_STATE_FLAG_PRELIGHT;
8347 case GTK_STATE_SELECTED:
8348 flags = GTK_STATE_FLAG_SELECTED;
8350 case GTK_STATE_INSENSITIVE:
8351 flags = GTK_STATE_FLAG_INSENSITIVE;
8353 case GTK_STATE_NORMAL:
8360 rgba.red = color->red / 65535.;
8361 rgba.green = color->green / 65535.;
8362 rgba.blue = color->blue / 65535.;
8365 gtk_widget_override_background_color (widget, flags, &rgba);
8368 gtk_widget_override_background_color (widget, flags, NULL);
8372 * gtk_widget_modify_text:
8373 * @widget: a #GtkWidget
8374 * @state: the state for which to set the text color
8375 * @color: (allow-none): the color to assign (does not need to
8376 * be allocated), or %NULL to undo the effect of previous
8377 * calls to of gtk_widget_modify_text().
8379 * Sets the text color for a widget in a particular state.
8381 * All other style values are left untouched.
8382 * The text color is the foreground color used along with the
8383 * base color (see gtk_widget_modify_base()) for widgets such
8384 * as #GtkEntry and #GtkTextView.
8385 * See also gtk_widget_modify_style().
8387 * Deprecated:3.0: Use gtk_widget_override_color() instead
8390 gtk_widget_modify_text (GtkWidget *widget,
8392 const GdkColor *color)
8394 g_return_if_fail (GTK_IS_WIDGET (widget));
8395 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8397 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
8401 * gtk_widget_modify_base:
8402 * @widget: a #GtkWidget
8403 * @state: the state for which to set the base color
8404 * @color: (allow-none): the color to assign (does not need to
8405 * be allocated), or %NULL to undo the effect of previous
8406 * calls to of gtk_widget_modify_base().
8408 * Sets the base color for a widget in a particular state.
8409 * All other style values are left untouched. The base color
8410 * is the background color used along with the text color
8411 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
8412 * and #GtkTextView. See also gtk_widget_modify_style().
8415 * Note that "no window" widgets (which have the %GTK_NO_WINDOW
8416 * flag set) draw on their parent container's window and thus may
8417 * not draw any background themselves. This is the case for e.g.
8420 * To modify the background of such widgets, you have to set the
8421 * base color on their parent; if you want to set the background
8422 * of a rectangular area around a label, try placing the label in
8423 * a #GtkEventBox widget and setting the base color on that.
8426 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8429 gtk_widget_modify_base (GtkWidget *widget,
8431 const GdkColor *color)
8433 g_return_if_fail (GTK_IS_WIDGET (widget));
8434 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8436 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
8440 * gtk_widget_modify_cursor:
8441 * @widget: a #GtkWidget
8442 * @primary: the color to use for primary cursor (does not need to be
8443 * allocated), or %NULL to undo the effect of previous calls to
8444 * of gtk_widget_modify_cursor().
8445 * @secondary: the color to use for secondary cursor (does not need to be
8446 * allocated), or %NULL to undo the effect of previous calls to
8447 * of gtk_widget_modify_cursor().
8449 * Sets the cursor color to use in a widget, overriding the
8450 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8453 * All other style values are left untouched.
8454 * See also gtk_widget_modify_style().
8458 * Deprecated: 3.0. Use gtk_widget_override_cursor() instead.
8461 gtk_widget_modify_cursor (GtkWidget *widget,
8462 const GdkColor *primary,
8463 const GdkColor *secondary)
8465 GdkRGBA primary_rgba, secondary_rgba;
8467 g_return_if_fail (GTK_IS_WIDGET (widget));
8469 primary_rgba.red = primary->red / 65535.;
8470 primary_rgba.green = primary->green / 65535.;
8471 primary_rgba.blue = primary->blue / 65535.;
8472 primary_rgba.alpha = 1;
8474 secondary_rgba.red = secondary->red / 65535.;
8475 secondary_rgba.green = secondary->green / 65535.;
8476 secondary_rgba.blue = secondary->blue / 65535.;
8477 secondary_rgba.alpha = 1;
8479 gtk_widget_override_cursor (widget, &primary_rgba, &secondary_rgba);
8483 * gtk_widget_modify_font:
8484 * @widget: a #GtkWidget
8485 * @font_desc: (allow-none): the font description to use, or %NULL
8486 * to undo the effect of previous calls to gtk_widget_modify_font()
8488 * Sets the font to use for a widget.
8490 * All other style values are left untouched.
8491 * See also gtk_widget_modify_style().
8493 * Deprecated:3.0: Use gtk_widget_override_font() instead
8496 gtk_widget_modify_font (GtkWidget *widget,
8497 PangoFontDescription *font_desc)
8499 g_return_if_fail (GTK_IS_WIDGET (widget));
8501 gtk_widget_override_font (widget, font_desc);
8505 gtk_widget_real_direction_changed (GtkWidget *widget,
8506 GtkTextDirection previous_direction)
8508 gtk_widget_queue_resize (widget);
8512 gtk_widget_real_style_set (GtkWidget *widget,
8513 GtkStyle *previous_style)
8518 GtkWidget *previous_toplevel;
8519 GdkScreen *previous_screen;
8520 GdkScreen *new_screen;
8521 } HierarchyChangedInfo;
8524 do_screen_change (GtkWidget *widget,
8525 GdkScreen *old_screen,
8526 GdkScreen *new_screen)
8528 if (old_screen != new_screen)
8530 GtkWidgetPrivate *priv = widget->priv;
8534 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8536 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8539 _gtk_tooltip_hide (widget);
8541 if (new_screen && priv->context)
8542 gtk_style_context_set_screen (priv->context, new_screen);
8544 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8549 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8550 gpointer client_data)
8552 GtkWidgetPrivate *priv = widget->priv;
8553 HierarchyChangedInfo *info = client_data;
8554 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8555 (priv->parent && priv->parent->priv->anchored);
8557 if (priv->anchored != new_anchored)
8559 g_object_ref (widget);
8561 priv->anchored = new_anchored;
8563 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8564 do_screen_change (widget, info->previous_screen, info->new_screen);
8566 if (GTK_IS_CONTAINER (widget))
8567 gtk_container_forall (GTK_CONTAINER (widget),
8568 gtk_widget_propagate_hierarchy_changed_recurse,
8571 g_object_unref (widget);
8576 * _gtk_widget_propagate_hierarchy_changed:
8577 * @widget: a #GtkWidget
8578 * @previous_toplevel: Previous toplevel
8580 * Propagates changes in the anchored state to a widget and all
8581 * children, unsetting or setting the %ANCHORED flag, and
8582 * emitting #GtkWidget::hierarchy-changed.
8585 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8586 GtkWidget *previous_toplevel)
8588 GtkWidgetPrivate *priv = widget->priv;
8589 HierarchyChangedInfo info;
8591 info.previous_toplevel = previous_toplevel;
8592 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8594 if (gtk_widget_is_toplevel (widget) ||
8595 (priv->parent && priv->parent->priv->anchored))
8596 info.new_screen = gtk_widget_get_screen (widget);
8598 info.new_screen = NULL;
8600 if (info.previous_screen)
8601 g_object_ref (info.previous_screen);
8602 if (previous_toplevel)
8603 g_object_ref (previous_toplevel);
8605 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8607 if (previous_toplevel)
8608 g_object_unref (previous_toplevel);
8609 if (info.previous_screen)
8610 g_object_unref (info.previous_screen);
8614 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8615 gpointer client_data)
8617 HierarchyChangedInfo *info = client_data;
8619 g_object_ref (widget);
8621 do_screen_change (widget, info->previous_screen, info->new_screen);
8623 if (GTK_IS_CONTAINER (widget))
8624 gtk_container_forall (GTK_CONTAINER (widget),
8625 gtk_widget_propagate_screen_changed_recurse,
8628 g_object_unref (widget);
8632 * gtk_widget_is_composited:
8633 * @widget: a #GtkWidget
8635 * Whether @widget can rely on having its alpha channel
8636 * drawn correctly. On X11 this function returns whether a
8637 * compositing manager is running for @widget's screen.
8639 * Please note that the semantics of this call will change
8640 * in the future if used on a widget that has a composited
8641 * window in its hierarchy (as set by gdk_window_set_composited()).
8643 * Return value: %TRUE if the widget can rely on its alpha
8644 * channel being drawn correctly.
8649 gtk_widget_is_composited (GtkWidget *widget)
8653 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8655 screen = gtk_widget_get_screen (widget);
8657 return gdk_screen_is_composited (screen);
8661 propagate_composited_changed (GtkWidget *widget,
8664 if (GTK_IS_CONTAINER (widget))
8666 gtk_container_forall (GTK_CONTAINER (widget),
8667 propagate_composited_changed,
8671 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8675 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8677 propagate_composited_changed (widget, NULL);
8681 * _gtk_widget_propagate_screen_changed:
8682 * @widget: a #GtkWidget
8683 * @previous_screen: Previous screen
8685 * Propagates changes in the screen for a widget to all
8686 * children, emitting #GtkWidget::screen-changed.
8689 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8690 GdkScreen *previous_screen)
8692 HierarchyChangedInfo info;
8694 info.previous_screen = previous_screen;
8695 info.new_screen = gtk_widget_get_screen (widget);
8697 if (previous_screen)
8698 g_object_ref (previous_screen);
8700 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8702 if (previous_screen)
8703 g_object_unref (previous_screen);
8707 reset_style_recurse (GtkWidget *widget, gpointer data)
8709 _gtk_widget_update_path (widget);
8711 if (GTK_IS_CONTAINER (widget))
8712 gtk_container_forall (GTK_CONTAINER (widget),
8713 reset_style_recurse,
8718 * gtk_widget_reset_style:
8719 * @widget: a #GtkWidget
8721 * Updates the style context of @widget and all descendents
8722 * by updating its widget path. #GtkContainer<!-- -->s may want
8723 * to use this on a child when reordering it in a way that a different
8724 * style might apply to it. See also gtk_container_get_path_for_child().
8729 gtk_widget_reset_style (GtkWidget *widget)
8731 g_return_if_fail (GTK_IS_WIDGET (widget));
8733 reset_style_recurse (widget, NULL);
8737 * gtk_widget_reset_rc_styles:
8738 * @widget: a #GtkWidget.
8740 * Reset the styles of @widget and all descendents, so when
8741 * they are looked up again, they get the correct values
8742 * for the currently loaded RC file settings.
8744 * This function is not useful for applications.
8746 * Deprecated:3.0: Use #GtkStyleContext instead, and gtk_widget_reset_style()
8749 gtk_widget_reset_rc_styles (GtkWidget *widget)
8751 g_return_if_fail (GTK_IS_WIDGET (widget));
8753 reset_style_recurse (widget, NULL);
8757 * gtk_widget_get_default_style:
8759 * Returns the default style used by all widgets initially.
8761 * Returns: (transfer none): the default style. This #GtkStyle
8762 * object is owned by GTK+ and should not be modified or freed.
8764 * Deprecated:3.0: Use #GtkStyleContext instead, and
8765 * gtk_css_provider_get_default() to obtain a #GtkStyleProvider
8766 * with the default widget style information.
8769 gtk_widget_get_default_style (void)
8771 if (!gtk_default_style)
8773 gtk_default_style = gtk_style_new ();
8774 g_object_ref (gtk_default_style);
8777 return gtk_default_style;
8780 #ifdef G_ENABLE_DEBUG
8782 /* Verify invariants, see docs/widget_system.txt for notes on much of
8783 * this. Invariants may be temporarily broken while we're in the
8784 * process of updating state, of course, so you can only
8785 * verify_invariants() after a given operation is complete.
8786 * Use push/pop_verify_invariants to help with that.
8789 gtk_widget_verify_invariants (GtkWidget *widget)
8793 if (widget->priv->verifying_invariants_count > 0)
8796 parent = widget->priv->parent;
8798 if (widget->priv->mapped)
8800 /* Mapped implies ... */
8802 if (!widget->priv->realized)
8803 g_warning ("%s %p is mapped but not realized",
8804 G_OBJECT_TYPE_NAME (widget), widget);
8806 if (!widget->priv->visible)
8807 g_warning ("%s %p is mapped but not visible",
8808 G_OBJECT_TYPE_NAME (widget), widget);
8810 if (!widget->priv->toplevel)
8812 if (!widget->priv->child_visible)
8813 g_warning ("%s %p is mapped but not child_visible",
8814 G_OBJECT_TYPE_NAME (widget), widget);
8819 /* Not mapped implies... */
8822 /* This check makes sense for normal toplevels, but for
8823 * something like a toplevel that is embedded within a clutter
8824 * state, mapping may depend on external factors.
8826 if (widget->priv->toplevel)
8828 if (widget->priv->visible)
8829 g_warning ("%s %p toplevel is visible but not mapped",
8830 G_OBJECT_TYPE_NAME (widget), widget);
8835 /* Parent related checks aren't possible if parent has
8836 * verifying_invariants_count > 0 because parent needs to recurse
8837 * children first before the invariants will hold.
8839 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8842 parent->priv->realized)
8844 /* Parent realized implies... */
8847 /* This is in widget_system.txt but appears to fail
8848 * because there's no gtk_container_realize() that
8849 * realizes all children... instead we just lazily
8850 * wait for map to fix things up.
8852 if (!widget->priv->realized)
8853 g_warning ("%s %p is realized but child %s %p is not realized",
8854 G_OBJECT_TYPE_NAME (parent), parent,
8855 G_OBJECT_TYPE_NAME (widget), widget);
8858 else if (!widget->priv->toplevel)
8860 /* No parent or parent not realized on non-toplevel implies... */
8862 if (widget->priv->realized && !widget->priv->in_reparent)
8863 g_warning ("%s %p is not realized but child %s %p is realized",
8864 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8865 G_OBJECT_TYPE_NAME (widget), widget);
8869 parent->priv->mapped &&
8870 widget->priv->visible &&
8871 widget->priv->child_visible)
8873 /* Parent mapped and we are visible implies... */
8875 if (!widget->priv->mapped)
8876 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8877 G_OBJECT_TYPE_NAME (parent), parent,
8878 G_OBJECT_TYPE_NAME (widget), widget);
8880 else if (!widget->priv->toplevel)
8882 /* No parent or parent not mapped on non-toplevel implies... */
8884 if (widget->priv->mapped && !widget->priv->in_reparent)
8885 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8886 G_OBJECT_TYPE_NAME (widget), widget,
8887 widget->priv->visible,
8888 widget->priv->child_visible,
8889 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8890 parent ? parent->priv->mapped : FALSE);
8894 if (!widget->priv->realized)
8896 /* Not realized implies... */
8899 /* widget_system.txt says these hold, but they don't. */
8900 if (widget->priv->resize_pending)
8901 g_warning ("%s %p resize pending but not realized",
8902 G_OBJECT_TYPE_NAME (widget), widget);
8904 if (widget->priv->alloc_needed)
8905 g_warning ("%s %p alloc needed but not realized",
8906 G_OBJECT_TYPE_NAME (widget), widget);
8908 if (widget->priv->width_request_needed)
8909 g_warning ("%s %p width request needed but not realized",
8910 G_OBJECT_TYPE_NAME (widget), widget);
8912 if (widget->priv->height_request_needed)
8913 g_warning ("%s %p height request needed but not realized",
8914 G_OBJECT_TYPE_NAME (widget), widget);
8919 /* The point of this push/pop is that invariants may not hold while
8920 * we're busy making changes. So we only check at the outermost call
8921 * on the call stack, after we finish updating everything.
8924 gtk_widget_push_verify_invariants (GtkWidget *widget)
8926 widget->priv->verifying_invariants_count += 1;
8930 gtk_widget_verify_child_invariants (GtkWidget *widget,
8931 gpointer client_data)
8933 /* We don't recurse further; this is a one-level check. */
8934 gtk_widget_verify_invariants (widget);
8938 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8940 g_assert (widget->priv->verifying_invariants_count > 0);
8942 widget->priv->verifying_invariants_count -= 1;
8944 if (widget->priv->verifying_invariants_count == 0)
8946 gtk_widget_verify_invariants (widget);
8948 if (GTK_IS_CONTAINER (widget))
8950 /* Check one level of children, because our
8951 * push_verify_invariants() will have prevented some of the
8952 * checks. This does not recurse because if recursion is
8953 * needed, it will happen naturally as each child has a
8954 * push/pop on that child. For example if we're recursively
8955 * mapping children, we'll push/pop on each child as we map
8958 gtk_container_forall (GTK_CONTAINER (widget),
8959 gtk_widget_verify_child_invariants,
8964 #endif /* G_ENABLE_DEBUG */
8966 static PangoContext *
8967 gtk_widget_peek_pango_context (GtkWidget *widget)
8969 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8973 * gtk_widget_get_pango_context:
8974 * @widget: a #GtkWidget
8976 * Gets a #PangoContext with the appropriate font map, font description,
8977 * and base direction for this widget. Unlike the context returned
8978 * by gtk_widget_create_pango_context(), this context is owned by
8979 * the widget (it can be used until the screen for the widget changes
8980 * or the widget is removed from its toplevel), and will be updated to
8981 * match any changes to the widget's attributes.
8983 * If you create and keep a #PangoLayout using this context, you must
8984 * deal with changes to the context by calling pango_layout_context_changed()
8985 * on the layout in response to the #GtkWidget::style-updated and
8986 * #GtkWidget::direction-changed signals for the widget.
8988 * Return value: (transfer none): the #PangoContext for the widget.
8991 gtk_widget_get_pango_context (GtkWidget *widget)
8993 PangoContext *context;
8995 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8997 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
9000 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
9001 g_object_set_qdata_full (G_OBJECT (widget),
9002 quark_pango_context,
9011 update_pango_context (GtkWidget *widget,
9012 PangoContext *context)
9014 const PangoFontDescription *font_desc;
9015 GtkStyleContext *style_context;
9017 style_context = gtk_widget_get_style_context (widget);
9019 font_desc = gtk_style_context_get_font (style_context,
9020 gtk_widget_get_state_flags (widget));
9022 pango_context_set_font_description (context, font_desc);
9023 pango_context_set_base_dir (context,
9024 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
9025 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
9029 gtk_widget_update_pango_context (GtkWidget *widget)
9031 PangoContext *context = gtk_widget_peek_pango_context (widget);
9037 update_pango_context (widget, context);
9039 screen = gtk_widget_get_screen_unchecked (widget);
9042 pango_cairo_context_set_resolution (context,
9043 gdk_screen_get_resolution (screen));
9044 pango_cairo_context_set_font_options (context,
9045 gdk_screen_get_font_options (screen));
9051 * gtk_widget_create_pango_context:
9052 * @widget: a #GtkWidget
9054 * Creates a new #PangoContext with the appropriate font map,
9055 * font description, and base direction for drawing text for
9056 * this widget. See also gtk_widget_get_pango_context().
9058 * Return value: (transfer full): the new #PangoContext
9061 gtk_widget_create_pango_context (GtkWidget *widget)
9064 PangoContext *context;
9066 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9068 screen = gtk_widget_get_screen_unchecked (widget);
9071 GTK_NOTE (MULTIHEAD,
9072 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
9074 screen = gdk_screen_get_default ();
9077 context = gdk_pango_context_get_for_screen (screen);
9079 update_pango_context (widget, context);
9080 pango_context_set_language (context, gtk_get_default_language ());
9086 * gtk_widget_create_pango_layout:
9087 * @widget: a #GtkWidget
9088 * @text: text to set on the layout (can be %NULL)
9090 * Creates a new #PangoLayout with the appropriate font map,
9091 * font description, and base direction for drawing text for
9094 * If you keep a #PangoLayout created in this way around, in order to
9095 * notify the layout of changes to the base direction or font of this
9096 * widget, you must call pango_layout_context_changed() in response to
9097 * the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
9100 * Return value: (transfer full): the new #PangoLayout
9103 gtk_widget_create_pango_layout (GtkWidget *widget,
9106 PangoLayout *layout;
9107 PangoContext *context;
9109 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9111 context = gtk_widget_get_pango_context (widget);
9112 layout = pango_layout_new (context);
9115 pango_layout_set_text (layout, text, -1);
9121 * gtk_widget_render_icon_pixbuf:
9122 * @widget: a #GtkWidget
9123 * @stock_id: a stock ID
9124 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
9125 * render at the size of the source and don't scale (if there are
9126 * multiple source sizes, GTK+ picks one of the available sizes).
9128 * A convenience function that uses the theme engine and style
9129 * settings for @widget to look up @stock_id and render it to
9130 * a pixbuf. @stock_id should be a stock icon ID such as
9131 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
9132 * such as #GTK_ICON_SIZE_MENU.
9134 * The pixels in the returned #GdkPixbuf are shared with the rest of
9135 * the application and should not be modified. The pixbuf should be freed
9136 * after use with g_object_unref().
9138 * Return value: (transfer full): a new pixbuf, or %NULL if the
9139 * stock ID wasn't known
9144 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
9145 const gchar *stock_id,
9148 GtkStyleContext *context;
9149 GtkIconSet *icon_set;
9151 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9152 g_return_val_if_fail (stock_id != NULL, NULL);
9153 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
9155 context = gtk_widget_get_style_context (widget);
9156 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
9158 if (icon_set == NULL)
9161 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
9165 * gtk_widget_render_icon:
9166 * @widget: a #GtkWidget
9167 * @stock_id: a stock ID
9168 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
9169 * render at the size of the source and don't scale (if there are
9170 * multiple source sizes, GTK+ picks one of the available sizes).
9171 * @detail: (allow-none): render detail to pass to theme engine
9173 * A convenience function that uses the theme settings for @widget
9174 * to look up @stock_id and render it to a pixbuf. @stock_id should
9175 * be a stock icon ID such as #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size
9176 * should be a size such as #GTK_ICON_SIZE_MENU. @detail should be a
9177 * string that identifies the widget or code doing the rendering, so
9178 * that theme engines can special-case rendering for that widget or
9181 * The pixels in the returned #GdkPixbuf are shared with the rest of
9182 * the application and should not be modified. The pixbuf should be
9183 * freed after use with g_object_unref().
9185 * Return value: (transfer full): a new pixbuf, or %NULL if the
9186 * stock ID wasn't known
9188 * Deprecated: 3.0: Use gtk_widget_render_icon_pixbuf() instead.
9191 gtk_widget_render_icon (GtkWidget *widget,
9192 const gchar *stock_id,
9194 const gchar *detail)
9196 gtk_widget_ensure_style (widget);
9198 return gtk_widget_render_icon_pixbuf (widget, stock_id, size);
9202 * gtk_widget_set_parent_window:
9203 * @widget: a #GtkWidget.
9204 * @parent_window: the new parent window.
9206 * Sets a non default parent window for @widget.
9208 * For GtkWindow classes, setting a @parent_window effects whether
9209 * the window is a toplevel window or can be embedded into other
9213 * For GtkWindow classes, this needs to be called before the
9214 * window is realized.
9219 gtk_widget_set_parent_window (GtkWidget *widget,
9220 GdkWindow *parent_window)
9222 GdkWindow *old_parent_window;
9224 g_return_if_fail (GTK_IS_WIDGET (widget));
9226 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
9227 quark_parent_window);
9229 if (parent_window != old_parent_window)
9233 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
9235 if (old_parent_window)
9236 g_object_unref (old_parent_window);
9238 g_object_ref (parent_window);
9240 /* Unset toplevel flag when adding a parent window to a widget,
9241 * this is the primary entry point to allow toplevels to be
9244 #ifdef GDK_WINDOWING_X11
9245 is_plug = GTK_IS_PLUG (widget);
9249 if (GTK_IS_WINDOW (widget) && !is_plug)
9250 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
9255 * gtk_widget_get_parent_window:
9256 * @widget: a #GtkWidget.
9258 * Gets @widget's parent window.
9260 * Returns: (transfer none): the parent window of @widget.
9263 gtk_widget_get_parent_window (GtkWidget *widget)
9265 GtkWidgetPrivate *priv;
9266 GdkWindow *parent_window;
9268 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9270 priv = widget->priv;
9272 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
9274 return (parent_window != NULL) ? parent_window :
9275 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
9280 * gtk_widget_set_child_visible:
9281 * @widget: a #GtkWidget
9282 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
9284 * Sets whether @widget should be mapped along with its when its parent
9285 * is mapped and @widget has been shown with gtk_widget_show().
9287 * The child visibility can be set for widget before it is added to
9288 * a container with gtk_widget_set_parent(), to avoid mapping
9289 * children unnecessary before immediately unmapping them. However
9290 * it will be reset to its default state of %TRUE when the widget
9291 * is removed from a container.
9293 * Note that changing the child visibility of a widget does not
9294 * queue a resize on the widget. Most of the time, the size of
9295 * a widget is computed from all visible children, whether or
9296 * not they are mapped. If this is not the case, the container
9297 * can queue a resize itself.
9299 * This function is only useful for container implementations and
9300 * never should be called by an application.
9303 gtk_widget_set_child_visible (GtkWidget *widget,
9304 gboolean is_visible)
9306 GtkWidgetPrivate *priv;
9308 g_return_if_fail (GTK_IS_WIDGET (widget));
9309 g_return_if_fail (!gtk_widget_is_toplevel (widget));
9311 priv = widget->priv;
9313 g_object_ref (widget);
9314 gtk_widget_verify_invariants (widget);
9317 priv->child_visible = TRUE;
9320 GtkWidget *toplevel;
9322 priv->child_visible = FALSE;
9324 toplevel = gtk_widget_get_toplevel (widget);
9325 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
9326 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
9329 if (priv->parent && gtk_widget_get_realized (priv->parent))
9331 if (gtk_widget_get_mapped (priv->parent) &&
9332 priv->child_visible &&
9333 gtk_widget_get_visible (widget))
9334 gtk_widget_map (widget);
9336 gtk_widget_unmap (widget);
9339 gtk_widget_verify_invariants (widget);
9340 g_object_unref (widget);
9344 * gtk_widget_get_child_visible:
9345 * @widget: a #GtkWidget
9347 * Gets the value set with gtk_widget_set_child_visible().
9348 * If you feel a need to use this function, your code probably
9349 * needs reorganization.
9351 * This function is only useful for container implementations and
9352 * never should be called by an application.
9354 * Return value: %TRUE if the widget is mapped with the parent.
9357 gtk_widget_get_child_visible (GtkWidget *widget)
9359 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9361 return widget->priv->child_visible;
9365 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9367 GtkWidget *toplevel;
9369 toplevel = gtk_widget_get_toplevel (widget);
9371 if (gtk_widget_is_toplevel (toplevel))
9373 if (GTK_IS_WINDOW (toplevel))
9374 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9375 else if (GTK_IS_INVISIBLE (toplevel))
9376 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9383 * gtk_widget_get_screen:
9384 * @widget: a #GtkWidget
9386 * Get the #GdkScreen from the toplevel window associated with
9387 * this widget. This function can only be called after the widget
9388 * has been added to a widget hierarchy with a #GtkWindow
9391 * In general, you should only create screen specific
9392 * resources when a widget has been realized, and you should
9393 * free those resources when the widget is unrealized.
9395 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9400 gtk_widget_get_screen (GtkWidget *widget)
9404 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9406 screen = gtk_widget_get_screen_unchecked (widget);
9413 g_warning (G_STRLOC ": Can't get associated screen"
9414 " for a widget unless it is inside a toplevel GtkWindow\n"
9415 " widget type is %s associated top level type is %s",
9416 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9417 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9419 return gdk_screen_get_default ();
9424 * gtk_widget_has_screen:
9425 * @widget: a #GtkWidget
9427 * Checks whether there is a #GdkScreen is associated with
9428 * this widget. All toplevel widgets have an associated
9429 * screen, and all widgets added into a hierarchy with a toplevel
9430 * window at the top.
9432 * Return value: %TRUE if there is a #GdkScreen associcated
9438 gtk_widget_has_screen (GtkWidget *widget)
9440 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9442 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9446 * gtk_widget_get_display:
9447 * @widget: a #GtkWidget
9449 * Get the #GdkDisplay for the toplevel window associated with
9450 * this widget. This function can only be called after the widget
9451 * has been added to a widget hierarchy with a #GtkWindow at the top.
9453 * In general, you should only create display specific
9454 * resources when a widget has been realized, and you should
9455 * free those resources when the widget is unrealized.
9457 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9462 gtk_widget_get_display (GtkWidget *widget)
9464 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9466 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9470 * gtk_widget_get_root_window:
9471 * @widget: a #GtkWidget
9473 * Get the root window where this widget is located. This function can
9474 * only be called after the widget has been added to a widget
9475 * hierarchy with #GtkWindow at the top.
9477 * The root window is useful for such purposes as creating a popup
9478 * #GdkWindow associated with the window. In general, you should only
9479 * create display specific resources when a widget has been realized,
9480 * and you should free those resources when the widget is unrealized.
9482 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9487 gtk_widget_get_root_window (GtkWidget *widget)
9489 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9491 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9495 * gtk_widget_child_focus:
9496 * @widget: a #GtkWidget
9497 * @direction: direction of focus movement
9499 * This function is used by custom widget implementations; if you're
9500 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9501 * to a particular widget, and gtk_container_set_focus_chain() to
9502 * change the focus tab order. So you may want to investigate those
9503 * functions instead.
9505 * gtk_widget_child_focus() is called by containers as the user moves
9506 * around the window using keyboard shortcuts. @direction indicates
9507 * what kind of motion is taking place (up, down, left, right, tab
9508 * forward, tab backward). gtk_widget_child_focus() emits the
9509 * #GtkWidget::focus signal; widgets override the default handler
9510 * for this signal in order to implement appropriate focus behavior.
9512 * The default ::focus handler for a widget should return %TRUE if
9513 * moving in @direction left the focus on a focusable location inside
9514 * that widget, and %FALSE if moving in @direction moved the focus
9515 * outside the widget. If returning %TRUE, widgets normally
9516 * call gtk_widget_grab_focus() to place the focus accordingly;
9517 * if returning %FALSE, they don't modify the current focus location.
9519 * Return value: %TRUE if focus ended up inside @widget
9522 gtk_widget_child_focus (GtkWidget *widget,
9523 GtkDirectionType direction)
9525 gboolean return_val;
9527 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9529 if (!gtk_widget_get_visible (widget) ||
9530 !gtk_widget_is_sensitive (widget))
9533 /* child widgets must set CAN_FOCUS, containers
9534 * don't have to though.
9536 if (!GTK_IS_CONTAINER (widget) &&
9537 !gtk_widget_get_can_focus (widget))
9540 g_signal_emit (widget,
9541 widget_signals[FOCUS],
9543 direction, &return_val);
9549 * gtk_widget_keynav_failed:
9550 * @widget: a #GtkWidget
9551 * @direction: direction of focus movement
9553 * This function should be called whenever keyboard navigation within
9554 * a single widget hits a boundary. The function emits the
9555 * #GtkWidget::keynav-failed signal on the widget and its return
9556 * value should be interpreted in a way similar to the return value of
9557 * gtk_widget_child_focus():
9559 * When %TRUE is returned, stay in the widget, the failed keyboard
9560 * navigation is Ok and/or there is nowhere we can/should move the
9563 * When %FALSE is returned, the caller should continue with keyboard
9564 * navigation outside the widget, e.g. by calling
9565 * gtk_widget_child_focus() on the widget's toplevel.
9567 * The default ::keynav-failed handler returns %TRUE for
9568 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9569 * values of #GtkDirectionType, it looks at the
9570 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9571 * if the setting is %TRUE. This way the entire user interface
9572 * becomes cursor-navigatable on input devices such as mobile phones
9573 * which only have cursor keys but no tab key.
9575 * Whenever the default handler returns %TRUE, it also calls
9576 * gtk_widget_error_bell() to notify the user of the failed keyboard
9579 * A use case for providing an own implementation of ::keynav-failed
9580 * (either by connecting to it or by overriding it) would be a row of
9581 * #GtkEntry widgets where the user should be able to navigate the
9582 * entire row with the cursor keys, as e.g. known from user interfaces
9583 * that require entering license keys.
9585 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9586 * if the emitting widget should try to handle the keyboard
9587 * navigation attempt in its parent container(s).
9592 gtk_widget_keynav_failed (GtkWidget *widget,
9593 GtkDirectionType direction)
9595 gboolean return_val;
9597 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9599 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9600 direction, &return_val);
9606 * gtk_widget_error_bell:
9607 * @widget: a #GtkWidget
9609 * Notifies the user about an input-related error on this widget.
9610 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9611 * gdk_window_beep(), otherwise it does nothing.
9613 * Note that the effect of gdk_window_beep() can be configured in many
9614 * ways, depending on the windowing backend and the desktop environment
9615 * or window manager that is used.
9620 gtk_widget_error_bell (GtkWidget *widget)
9622 GtkWidgetPrivate *priv;
9623 GtkSettings* settings;
9626 g_return_if_fail (GTK_IS_WIDGET (widget));
9628 priv = widget->priv;
9630 settings = gtk_widget_get_settings (widget);
9634 g_object_get (settings,
9635 "gtk-error-bell", &beep,
9638 if (beep && priv->window)
9639 gdk_window_beep (priv->window);
9643 gtk_widget_set_usize_internal (GtkWidget *widget,
9646 GtkQueueResizeFlags flags)
9648 GtkWidgetAuxInfo *aux_info;
9649 gboolean changed = FALSE;
9651 g_object_freeze_notify (G_OBJECT (widget));
9653 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9655 if (width > -2 && aux_info->width != width)
9657 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9658 g_object_notify (G_OBJECT (widget), "width-request");
9659 aux_info->width = width;
9662 if (height > -2 && aux_info->height != height)
9664 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9665 g_object_notify (G_OBJECT (widget), "height-request");
9666 aux_info->height = height;
9670 if (gtk_widget_get_visible (widget) && changed)
9672 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9673 gtk_widget_queue_resize (widget);
9675 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9678 g_object_thaw_notify (G_OBJECT (widget));
9682 * gtk_widget_set_size_request:
9683 * @widget: a #GtkWidget
9684 * @width: width @widget should request, or -1 to unset
9685 * @height: height @widget should request, or -1 to unset
9687 * Sets the minimum size of a widget; that is, the widget's size
9688 * request will be @width by @height. You can use this function to
9689 * force a widget to be either larger or smaller than it normally
9692 * In most cases, gtk_window_set_default_size() is a better choice for
9693 * toplevel windows than this function; setting the default size will
9694 * still allow users to shrink the window. Setting the size request
9695 * will force them to leave the window at least as large as the size
9696 * request. When dealing with window sizes,
9697 * gtk_window_set_geometry_hints() can be a useful function as well.
9699 * Note the inherent danger of setting any fixed size - themes,
9700 * translations into other languages, different fonts, and user action
9701 * can all change the appropriate size for a given widget. So, it's
9702 * basically impossible to hardcode a size that will always be
9705 * The size request of a widget is the smallest size a widget can
9706 * accept while still functioning well and drawing itself correctly.
9707 * However in some strange cases a widget may be allocated less than
9708 * its requested size, and in many cases a widget may be allocated more
9709 * space than it requested.
9711 * If the size request in a given direction is -1 (unset), then
9712 * the "natural" size request of the widget will be used instead.
9714 * Widgets can't actually be allocated a size less than 1 by 1, but
9715 * you can pass 0,0 to this function to mean "as small as possible."
9717 * The size request set here does not include any margin from the
9718 * #GtkWidget properties margin-left, margin-right, margin-top, and
9719 * margin-bottom, but it does include pretty much all other padding
9720 * or border properties set by any subclass of #GtkWidget.
9723 gtk_widget_set_size_request (GtkWidget *widget,
9727 g_return_if_fail (GTK_IS_WIDGET (widget));
9728 g_return_if_fail (width >= -1);
9729 g_return_if_fail (height >= -1);
9736 gtk_widget_set_usize_internal (widget, width, height, 0);
9741 * gtk_widget_get_size_request:
9742 * @widget: a #GtkWidget
9743 * @width: (out) (allow-none): return location for width, or %NULL
9744 * @height: (out) (allow-none): return location for height, or %NULL
9746 * Gets the size request that was explicitly set for the widget using
9747 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9748 * @height indicates that that dimension has not been set explicitly
9749 * and the natural requisition of the widget will be used intead. See
9750 * gtk_widget_set_size_request(). To get the size a widget will
9751 * actually request, call gtk_widget_get_preferred_size() instead of
9755 gtk_widget_get_size_request (GtkWidget *widget,
9759 const GtkWidgetAuxInfo *aux_info;
9761 g_return_if_fail (GTK_IS_WIDGET (widget));
9763 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9766 *width = aux_info->width;
9769 *height = aux_info->height;
9773 * _gtk_widget_override_size_request:
9774 * @widget: a #GtkWidget
9775 * @width: new forced minimum width
9776 * @height: new forced minimum height
9777 * @old_width: location to store previous forced minimum width
9778 * @old_width: location to store previous forced minumum height
9780 * Temporarily establishes a forced minimum size for a widget; this
9781 * is used by GtkWindow when calculating the size to add to the
9782 * window's geometry widget. Cached sizes for the widget and its
9783 * parents are invalidated, so that subsequent calls to the size
9784 * negotiation machinery produce the overriden result, but the
9785 * widget is not queued for relayout or redraw. The old size must
9786 * be restored with _gtk_widget_restore_size_request() or things
9790 _gtk_widget_override_size_request (GtkWidget *widget,
9796 gtk_widget_get_size_request (widget, old_width, old_height);
9797 gtk_widget_set_usize_internal (widget, width, height,
9798 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9802 * _gtk_widget_restore_size_request:
9803 * @widget: a #GtkWidget
9804 * @old_width: saved forced minimum size
9805 * @old_height: saved forced minimum size
9807 * Undoes the operation of_gtk_widget_override_size_request().
9810 _gtk_widget_restore_size_request (GtkWidget *widget,
9814 gtk_widget_set_usize_internal (widget, old_width, old_height,
9815 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9819 * gtk_widget_set_events:
9820 * @widget: a #GtkWidget
9821 * @events: event mask
9823 * Sets the event mask (see #GdkEventMask) for a widget. The event
9824 * mask determines which events a widget will receive. Keep in mind
9825 * that different widgets have different default event masks, and by
9826 * changing the event mask you may disrupt a widget's functionality,
9827 * so be careful. This function must be called while a widget is
9828 * unrealized. Consider gtk_widget_add_events() for widgets that are
9829 * already realized, or if you want to preserve the existing event
9830 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9831 * to get events on those widgets, place them inside a #GtkEventBox
9832 * and receive events on the event box.
9835 gtk_widget_set_events (GtkWidget *widget,
9838 g_return_if_fail (GTK_IS_WIDGET (widget));
9839 g_return_if_fail (!gtk_widget_get_realized (widget));
9841 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9842 GINT_TO_POINTER (events));
9843 g_object_notify (G_OBJECT (widget), "events");
9847 * gtk_widget_set_device_events:
9848 * @widget: a #GtkWidget
9849 * @device: a #GdkDevice
9850 * @events: event mask
9852 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9853 * mask determines which events a widget will receive from @device. Keep
9854 * in mind that different widgets have different default event masks, and by
9855 * changing the event mask you may disrupt a widget's functionality,
9856 * so be careful. This function must be called while a widget is
9857 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9858 * already realized, or if you want to preserve the existing event
9859 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9860 * to get events on those widgets, place them inside a #GtkEventBox
9861 * and receive events on the event box.
9866 gtk_widget_set_device_events (GtkWidget *widget,
9868 GdkEventMask events)
9870 GHashTable *device_events;
9872 g_return_if_fail (GTK_IS_WIDGET (widget));
9873 g_return_if_fail (GDK_IS_DEVICE (device));
9874 g_return_if_fail (!gtk_widget_get_realized (widget));
9876 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9878 if (G_UNLIKELY (!device_events))
9880 device_events = g_hash_table_new (NULL, NULL);
9881 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9882 (GDestroyNotify) g_hash_table_unref);
9885 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9889 * gtk_widget_set_device_enabled:
9890 * @widget: a #GtkWidget
9891 * @device: a #GdkDevice
9892 * @enabled: whether to enable the device
9894 * Enables or disables a #GdkDevice to interact with @widget
9895 * and all its children.
9897 * It does so by descending through the #GdkWindow hierarchy
9898 * and enabling the same mask that is has for core events
9899 * (i.e. the one that gdk_window_get_events() returns).
9904 gtk_widget_set_device_enabled (GtkWidget *widget,
9908 GList *enabled_devices;
9910 g_return_if_fail (GTK_IS_WIDGET (widget));
9911 g_return_if_fail (GDK_IS_DEVICE (device));
9913 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9914 enabled_devices = g_list_append (enabled_devices, device);
9916 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9917 enabled_devices, (GDestroyNotify) g_list_free);;
9919 if (gtk_widget_get_realized (widget))
9920 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9924 * gtk_widget_get_device_enabled:
9925 * @widget: a #GtkWidget
9926 * @device: a #GdkDevice
9928 * Returns whether @device can interact with @widget and its
9929 * children. See gtk_widget_set_device_enabled().
9931 * Return value: %TRUE is @device is enabled for @widget
9936 gtk_widget_get_device_enabled (GtkWidget *widget,
9939 GList *enabled_devices;
9941 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9942 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9944 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9946 return g_list_find (enabled_devices, device) != NULL;
9950 gtk_widget_add_events_internal_list (GtkWidget *widget,
9957 for (l = window_list; l != NULL; l = l->next)
9959 GdkWindow *window = l->data;
9962 gdk_window_get_user_data (window, &user_data);
9963 if (user_data == widget)
9968 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9970 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9972 children = gdk_window_get_children (window);
9973 gtk_widget_add_events_internal_list (widget, device, events, children);
9974 g_list_free (children);
9980 gtk_widget_add_events_internal (GtkWidget *widget,
9984 GtkWidgetPrivate *priv = widget->priv;
9987 if (!gtk_widget_get_has_window (widget))
9988 window_list = gdk_window_get_children (priv->window);
9990 window_list = g_list_prepend (NULL, priv->window);
9992 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9994 g_list_free (window_list);
9998 * gtk_widget_add_events:
9999 * @widget: a #GtkWidget
10000 * @events: an event mask, see #GdkEventMask
10002 * Adds the events in the bitfield @events to the event mask for
10003 * @widget. See gtk_widget_set_events() for details.
10006 gtk_widget_add_events (GtkWidget *widget,
10011 g_return_if_fail (GTK_IS_WIDGET (widget));
10013 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10014 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
10015 GINT_TO_POINTER (old_events | events));
10017 if (gtk_widget_get_realized (widget))
10019 gtk_widget_add_events_internal (widget, NULL, events);
10020 gtk_widget_update_devices_mask (widget, FALSE);
10023 g_object_notify (G_OBJECT (widget), "events");
10027 * gtk_widget_add_device_events:
10028 * @widget: a #GtkWidget
10029 * @device: a #GdkDevice
10030 * @events: an event mask, see #GdkEventMask
10032 * Adds the device events in the bitfield @events to the event mask for
10033 * @widget. See gtk_widget_set_device_events() for details.
10038 gtk_widget_add_device_events (GtkWidget *widget,
10040 GdkEventMask events)
10042 GdkEventMask old_events;
10043 GHashTable *device_events;
10045 g_return_if_fail (GTK_IS_WIDGET (widget));
10046 g_return_if_fail (GDK_IS_DEVICE (device));
10048 old_events = gtk_widget_get_device_events (widget, device);
10050 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10052 if (G_UNLIKELY (!device_events))
10054 device_events = g_hash_table_new (NULL, NULL);
10055 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
10056 (GDestroyNotify) g_hash_table_unref);
10059 g_hash_table_insert (device_events, device,
10060 GUINT_TO_POINTER (old_events | events));
10062 if (gtk_widget_get_realized (widget))
10063 gtk_widget_add_events_internal (widget, device, events);
10065 g_object_notify (G_OBJECT (widget), "events");
10069 * gtk_widget_get_toplevel:
10070 * @widget: a #GtkWidget
10072 * This function returns the topmost widget in the container hierarchy
10073 * @widget is a part of. If @widget has no parent widgets, it will be
10074 * returned as the topmost widget. No reference will be added to the
10075 * returned widget; it should not be unreferenced.
10077 * Note the difference in behavior vs. gtk_widget_get_ancestor();
10078 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
10080 * %NULL if @widget wasn't inside a toplevel window, and if the
10081 * window was inside a #GtkWindow-derived widget which was in turn
10082 * inside the toplevel #GtkWindow. While the second case may
10083 * seem unlikely, it actually happens when a #GtkPlug is embedded
10084 * inside a #GtkSocket within the same application.
10086 * To reliably find the toplevel #GtkWindow, use
10087 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
10088 * is set on the result.
10090 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
10091 * if (gtk_widget_is_toplevel (toplevel))
10093 * /* Perform action on toplevel. */
10097 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
10098 * if there's no ancestor.
10101 gtk_widget_get_toplevel (GtkWidget *widget)
10103 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10105 while (widget->priv->parent)
10106 widget = widget->priv->parent;
10112 * gtk_widget_get_ancestor:
10113 * @widget: a #GtkWidget
10114 * @widget_type: ancestor type
10116 * Gets the first ancestor of @widget with type @widget_type. For example,
10117 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
10118 * the first #GtkBox that's an ancestor of @widget. No reference will be
10119 * added to the returned widget; it should not be unreferenced. See note
10120 * about checking for a toplevel #GtkWindow in the docs for
10121 * gtk_widget_get_toplevel().
10123 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
10124 * considers @widget to be an ancestor of itself.
10126 * Return value: (transfer none): the ancestor widget, or %NULL if not found
10129 gtk_widget_get_ancestor (GtkWidget *widget,
10132 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10134 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
10135 widget = widget->priv->parent;
10137 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
10144 * gtk_widget_set_visual:
10145 * @widget: a #GtkWidget
10146 * @visual: visual to be used or %NULL to unset a previous one
10148 * Sets the visual that should be used for by widget and its children for
10149 * creating #GdkWindows. The visual must be on the same #GdkScreen as
10150 * returned by gdk_widget_get_screen(), so handling the
10151 * #GtkWidget::screen-changed signal is necessary.
10153 * Setting a new @visual will not cause @widget to recreate its windows,
10154 * so you should call this function before @widget is realized.
10157 gtk_widget_set_visual (GtkWidget *widget,
10160 g_return_if_fail (GTK_IS_WIDGET (widget));
10161 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
10164 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
10167 g_object_set_qdata_full (G_OBJECT (widget),
10169 g_object_ref (visual),
10174 * gtk_widget_get_visual:
10175 * @widget: a #GtkWidget
10177 * Gets the visual that will be used to render @widget.
10179 * Return value: (transfer none): the visual for @widget
10182 gtk_widget_get_visual (GtkWidget *widget)
10188 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10190 if (gtk_widget_get_has_window (widget) &&
10191 widget->priv->window)
10192 return gdk_window_get_visual (widget->priv->window);
10194 screen = gtk_widget_get_screen (widget);
10196 for (w = widget; w != NULL; w = w->priv->parent)
10198 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
10201 if (gdk_visual_get_screen (visual) == screen)
10204 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
10205 gtk_widget_get_name (widget));
10209 return gdk_screen_get_system_visual (screen);
10213 * gtk_widget_get_settings:
10214 * @widget: a #GtkWidget
10216 * Gets the settings object holding the settings used for this widget.
10218 * Note that this function can only be called when the #GtkWidget
10219 * is attached to a toplevel, since the settings object is specific
10220 * to a particular #GdkScreen.
10222 * Return value: (transfer none): the relevant #GtkSettings object
10225 gtk_widget_get_settings (GtkWidget *widget)
10227 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10229 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
10233 * gtk_widget_get_events:
10234 * @widget: a #GtkWidget
10236 * Returns the event mask for the widget (a bitfield containing flags
10237 * from the #GdkEventMask enumeration). These are the events that the widget
10240 * Return value: event mask for @widget
10243 gtk_widget_get_events (GtkWidget *widget)
10245 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10247 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10251 * gtk_widget_get_device_events:
10252 * @widget: a #GtkWidget
10253 * @device: a #GdkDevice
10255 * Returns the events mask for the widget corresponding to an specific device. These
10256 * are the events that the widget will receive when @device operates on it.
10258 * Returns: device event mask for @widget
10263 gtk_widget_get_device_events (GtkWidget *widget,
10266 GHashTable *device_events;
10268 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10269 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
10271 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10273 if (!device_events)
10276 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
10280 * gtk_widget_get_pointer:
10281 * @widget: a #GtkWidget
10282 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
10283 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
10285 * Obtains the location of the mouse pointer in widget coordinates.
10286 * Widget coordinates are a bit odd; for historical reasons, they are
10287 * defined as @widget->window coordinates for widgets that are not
10288 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
10289 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
10292 gtk_widget_get_pointer (GtkWidget *widget,
10296 GtkWidgetPrivate *priv;
10298 g_return_if_fail (GTK_IS_WIDGET (widget));
10300 priv = widget->priv;
10307 if (gtk_widget_get_realized (widget))
10309 gdk_window_get_pointer (priv->window, x, y, NULL);
10311 if (!gtk_widget_get_has_window (widget))
10314 *x -= priv->allocation.x;
10316 *y -= priv->allocation.y;
10322 * gtk_widget_is_ancestor:
10323 * @widget: a #GtkWidget
10324 * @ancestor: another #GtkWidget
10326 * Determines whether @widget is somewhere inside @ancestor, possibly with
10327 * intermediate containers.
10329 * Return value: %TRUE if @ancestor contains @widget as a child,
10330 * grandchild, great grandchild, etc.
10333 gtk_widget_is_ancestor (GtkWidget *widget,
10334 GtkWidget *ancestor)
10336 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10337 g_return_val_if_fail (ancestor != NULL, FALSE);
10341 if (widget->priv->parent == ancestor)
10343 widget = widget->priv->parent;
10349 static GQuark quark_composite_name = 0;
10352 * gtk_widget_set_composite_name:
10353 * @widget: a #GtkWidget.
10354 * @name: the name to set
10356 * Sets a widgets composite name. The widget must be
10357 * a composite child of its parent; see gtk_widget_push_composite_child().
10360 gtk_widget_set_composite_name (GtkWidget *widget,
10363 g_return_if_fail (GTK_IS_WIDGET (widget));
10364 g_return_if_fail (widget->priv->composite_child);
10365 g_return_if_fail (name != NULL);
10367 if (!quark_composite_name)
10368 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10370 g_object_set_qdata_full (G_OBJECT (widget),
10371 quark_composite_name,
10377 * gtk_widget_get_composite_name:
10378 * @widget: a #GtkWidget
10380 * Obtains the composite name of a widget.
10382 * Returns: the composite name of @widget, or %NULL if @widget is not
10383 * a composite child. The string should be freed when it is no
10387 gtk_widget_get_composite_name (GtkWidget *widget)
10389 GtkWidgetPrivate *priv;
10391 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10393 priv = widget->priv;
10395 if (widget->priv->composite_child && priv->parent)
10396 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10403 * gtk_widget_push_composite_child:
10405 * Makes all newly-created widgets as composite children until
10406 * the corresponding gtk_widget_pop_composite_child() call.
10408 * A composite child is a child that's an implementation detail of the
10409 * container it's inside and should not be visible to people using the
10410 * container. Composite children aren't treated differently by GTK (but
10411 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10412 * builders might want to treat them in a different way.
10414 * Here is a simple example:
10416 * gtk_widget_push_composite_child ();
10417 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10418 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10419 * gtk_widget_pop_composite_child ();
10420 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10421 * GTK_WIDGET (scrolled_window));
10422 * g_object_ref (scrolled_window->hscrollbar);
10426 gtk_widget_push_composite_child (void)
10428 composite_child_stack++;
10432 * gtk_widget_pop_composite_child:
10434 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10437 gtk_widget_pop_composite_child (void)
10439 if (composite_child_stack)
10440 composite_child_stack--;
10444 gtk_widget_emit_direction_changed (GtkWidget *widget,
10445 GtkTextDirection old_dir)
10447 gtk_widget_update_pango_context (widget);
10449 if (widget->priv->context)
10450 gtk_style_context_set_direction (widget->priv->context,
10451 gtk_widget_get_direction (widget));
10453 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10457 * gtk_widget_set_direction:
10458 * @widget: a #GtkWidget
10459 * @dir: the new direction
10461 * Sets the reading direction on a particular widget. This direction
10462 * controls the primary direction for widgets containing text,
10463 * and also the direction in which the children of a container are
10464 * packed. The ability to set the direction is present in order
10465 * so that correct localization into languages with right-to-left
10466 * reading directions can be done. Generally, applications will
10467 * let the default reading direction present, except for containers
10468 * where the containers are arranged in an order that is explicitely
10469 * visual rather than logical (such as buttons for text justification).
10471 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10472 * set by gtk_widget_set_default_direction() will be used.
10475 gtk_widget_set_direction (GtkWidget *widget,
10476 GtkTextDirection dir)
10478 GtkTextDirection old_dir;
10480 g_return_if_fail (GTK_IS_WIDGET (widget));
10481 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10483 old_dir = gtk_widget_get_direction (widget);
10485 widget->priv->direction = dir;
10487 if (old_dir != gtk_widget_get_direction (widget))
10488 gtk_widget_emit_direction_changed (widget, old_dir);
10492 * gtk_widget_get_direction:
10493 * @widget: a #GtkWidget
10495 * Gets the reading direction for a particular widget. See
10496 * gtk_widget_set_direction().
10498 * Return value: the reading direction for the widget.
10501 gtk_widget_get_direction (GtkWidget *widget)
10503 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10505 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10506 return gtk_default_direction;
10508 return widget->priv->direction;
10512 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10514 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10516 g_object_ref (widget);
10518 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10519 gtk_widget_emit_direction_changed (widget, old_dir);
10521 if (GTK_IS_CONTAINER (widget))
10522 gtk_container_forall (GTK_CONTAINER (widget),
10523 gtk_widget_set_default_direction_recurse,
10526 g_object_unref (widget);
10530 * gtk_widget_set_default_direction:
10531 * @dir: the new default direction. This cannot be
10532 * %GTK_TEXT_DIR_NONE.
10534 * Sets the default reading direction for widgets where the
10535 * direction has not been explicitly set by gtk_widget_set_direction().
10538 gtk_widget_set_default_direction (GtkTextDirection dir)
10540 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10542 if (dir != gtk_default_direction)
10544 GList *toplevels, *tmp_list;
10545 GtkTextDirection old_dir = gtk_default_direction;
10547 gtk_default_direction = dir;
10549 tmp_list = toplevels = gtk_window_list_toplevels ();
10550 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10554 gtk_widget_set_default_direction_recurse (tmp_list->data,
10555 GUINT_TO_POINTER (old_dir));
10556 g_object_unref (tmp_list->data);
10557 tmp_list = tmp_list->next;
10560 g_list_free (toplevels);
10565 * gtk_widget_get_default_direction:
10567 * Obtains the current default reading direction. See
10568 * gtk_widget_set_default_direction().
10570 * Return value: the current default direction.
10573 gtk_widget_get_default_direction (void)
10575 return gtk_default_direction;
10579 gtk_widget_dispose (GObject *object)
10581 GtkWidget *widget = GTK_WIDGET (object);
10582 GtkWidgetPrivate *priv = widget->priv;
10585 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10586 else if (gtk_widget_get_visible (widget))
10587 gtk_widget_hide (widget);
10589 priv->visible = FALSE;
10590 if (gtk_widget_get_realized (widget))
10591 gtk_widget_unrealize (widget);
10593 if (!priv->in_destruction)
10595 priv->in_destruction = TRUE;
10596 g_signal_emit (object, widget_signals[DESTROY], 0);
10597 priv->in_destruction = FALSE;
10600 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10604 gtk_widget_real_destroy (GtkWidget *object)
10606 /* gtk_object_destroy() will already hold a refcount on object */
10607 GtkWidget *widget = GTK_WIDGET (object);
10608 GtkWidgetPrivate *priv = widget->priv;
10610 /* wipe accelerator closures (keep order) */
10611 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10612 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10614 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10615 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10617 gtk_grab_remove (widget);
10620 g_object_unref (priv->style);
10621 priv->style = gtk_widget_get_default_style ();
10622 g_object_ref (priv->style);
10626 gtk_widget_finalize (GObject *object)
10628 GtkWidget *widget = GTK_WIDGET (object);
10629 GtkWidgetPrivate *priv = widget->priv;
10630 GtkWidgetAuxInfo *aux_info;
10631 GtkAccessible *accessible;
10633 gtk_grab_remove (widget);
10635 g_object_unref (priv->style);
10636 priv->style = NULL;
10638 g_free (priv->name);
10640 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10642 gtk_widget_aux_info_destroy (aux_info);
10644 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10646 g_object_unref (accessible);
10649 gtk_widget_path_free (priv->path);
10652 g_object_unref (priv->context);
10654 _gtk_widget_free_cached_sizes (widget);
10656 if (g_object_is_floating (object))
10657 g_warning ("A floating object was finalized. This means that someone\n"
10658 "called g_object_unref() on an object that had only a floating\n"
10659 "reference; the initial floating reference is not owned by anyone\n"
10660 "and must be removed with g_object_ref_sink().");
10662 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10665 /*****************************************
10666 * gtk_widget_real_map:
10671 *****************************************/
10674 gtk_widget_real_map (GtkWidget *widget)
10676 GtkWidgetPrivate *priv = widget->priv;
10678 g_assert (gtk_widget_get_realized (widget));
10680 if (!gtk_widget_get_mapped (widget))
10682 gtk_widget_set_mapped (widget, TRUE);
10684 if (gtk_widget_get_has_window (widget))
10685 gdk_window_show (priv->window);
10689 /*****************************************
10690 * gtk_widget_real_unmap:
10695 *****************************************/
10698 gtk_widget_real_unmap (GtkWidget *widget)
10700 GtkWidgetPrivate *priv = widget->priv;
10702 if (gtk_widget_get_mapped (widget))
10704 gtk_widget_set_mapped (widget, FALSE);
10706 if (gtk_widget_get_has_window (widget))
10707 gdk_window_hide (priv->window);
10711 /*****************************************
10712 * gtk_widget_real_realize:
10717 *****************************************/
10720 gtk_widget_real_realize (GtkWidget *widget)
10722 GtkWidgetPrivate *priv = widget->priv;
10724 g_assert (!gtk_widget_get_has_window (widget));
10726 gtk_widget_set_realized (widget, TRUE);
10729 priv->window = gtk_widget_get_parent_window (widget);
10730 g_object_ref (priv->window);
10734 /*****************************************
10735 * gtk_widget_real_unrealize:
10740 *****************************************/
10743 gtk_widget_real_unrealize (GtkWidget *widget)
10745 GtkWidgetPrivate *priv = widget->priv;
10747 g_assert (!widget->priv->mapped);
10749 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10752 /* We must do unrealize child widget BEFORE container widget.
10753 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10754 * So, unrealizing container widget bofore its children causes the problem
10755 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10758 if (GTK_IS_CONTAINER (widget))
10759 gtk_container_forall (GTK_CONTAINER (widget),
10760 (GtkCallback) gtk_widget_unrealize,
10763 if (gtk_widget_get_has_window (widget))
10765 gdk_window_set_user_data (priv->window, NULL);
10766 gdk_window_destroy (priv->window);
10767 priv->window = NULL;
10771 g_object_unref (priv->window);
10772 priv->window = NULL;
10775 gtk_selection_remove_all (widget);
10777 gtk_widget_set_realized (widget, FALSE);
10781 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10782 GtkOrientation orientation,
10783 gint *minimum_size,
10784 gint *natural_size)
10786 const GtkWidgetAuxInfo *aux_info;
10788 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10790 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10791 aux_info->width > 0)
10793 *minimum_size = MAX (*minimum_size, aux_info->width);
10795 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10796 aux_info->height > 0)
10798 *minimum_size = MAX (*minimum_size, aux_info->height);
10801 /* Fix it if set_size_request made natural size smaller than min size.
10802 * This would also silently fix broken widgets, but we warn about them
10803 * in gtksizerequest.c when calling their size request vfuncs.
10805 *natural_size = MAX (*natural_size, *minimum_size);
10807 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10809 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10810 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10814 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10815 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10820 * _gtk_widget_peek_request_cache:
10822 * Returns the address of the widget's request cache (strictly for
10823 * internal use in gtksizerequest.c)
10825 * Return value: the address of @widget's size request cache.
10828 _gtk_widget_peek_request_cache (GtkWidget *widget)
10830 /* Don't bother slowing things down with the return_if_fail guards here */
10831 return &widget->priv->requests;
10835 * _gtk_widget_set_device_window:
10836 * @widget: a #GtkWidget
10837 * @device: a #GdkDevice
10838 * @window: the new device window
10840 * Sets pointer window for @widget and @device.
10841 * Does not ref @window.
10844 _gtk_widget_set_device_window (GtkWidget *widget,
10848 GHashTable *device_window;
10850 g_return_if_fail (GTK_IS_WIDGET (widget));
10851 g_return_if_fail (GDK_IS_DEVICE (device));
10852 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10854 if (!gtk_widget_get_mapped (widget))
10857 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10859 if (!device_window && window)
10861 device_window = g_hash_table_new (NULL, NULL);
10862 g_object_set_qdata_full (G_OBJECT (widget),
10863 quark_pointer_window,
10865 (GDestroyNotify) g_hash_table_destroy);
10869 g_hash_table_insert (device_window, device, window);
10870 else if (device_window)
10872 g_hash_table_remove (device_window, device);
10874 if (g_hash_table_size (device_window) == 0)
10875 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10880 * _gtk_widget_get_device_window:
10881 * @widget: a #GtkWidget
10882 * @device: a #GdkDevice
10884 * Return value: the device window set on @widget, or %NULL
10887 _gtk_widget_get_device_window (GtkWidget *widget,
10890 GHashTable *device_window;
10892 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10893 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10895 if (!gtk_widget_get_mapped (widget))
10898 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10900 if (!device_window)
10903 return g_hash_table_lookup (device_window, device);
10907 * _gtk_widget_list_devices:
10908 * @widget: a #GtkWidget
10910 * Returns the list of #GdkDevices that is currently on top
10911 * of any window belonging to @widget.
10912 * Free the list with g_list_free(), the elements are owned
10913 * by GTK+ and must not be freed.
10916 _gtk_widget_list_devices (GtkWidget *widget)
10918 GHashTableIter iter;
10919 GHashTable *device_window;
10920 GList *devices = NULL;
10921 gpointer key, value;
10923 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10925 if (!gtk_widget_get_mapped (widget))
10928 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10930 if (G_UNLIKELY (!device_window))
10933 g_hash_table_iter_init (&iter, device_window);
10935 while (g_hash_table_iter_next (&iter, &key, &value))
10936 devices = g_list_prepend (devices, key);
10942 synth_crossing (GtkWidget *widget,
10946 GdkCrossingMode mode,
10947 GdkNotifyType detail)
10951 event = gdk_event_new (type);
10953 event->crossing.window = g_object_ref (window);
10954 event->crossing.send_event = TRUE;
10955 event->crossing.subwindow = g_object_ref (window);
10956 event->crossing.time = GDK_CURRENT_TIME;
10957 event->crossing.x = event->crossing.y = 0;
10958 event->crossing.x_root = event->crossing.y_root = 0;
10959 event->crossing.mode = mode;
10960 event->crossing.detail = detail;
10961 event->crossing.focus = FALSE;
10962 event->crossing.state = 0;
10963 gdk_event_set_device (event, device);
10966 widget = gtk_get_event_widget (event);
10969 gtk_widget_event_internal (widget, event);
10971 gdk_event_free (event);
10975 * _gtk_widget_synthesize_crossing:
10976 * @from: the #GtkWidget the virtual pointer is leaving.
10977 * @to: the #GtkWidget the virtual pointer is moving to.
10978 * @mode: the #GdkCrossingMode to place on the synthesized events.
10980 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10982 * The real pointer window is the window that most recently received an enter notify
10983 * event. Windows that don't select for crossing events can't become the real
10984 * poiner window. The real pointer widget that owns the real pointer window. The
10985 * effective pointer window is the same as the real pointer window unless the real
10986 * pointer widget is either insensitive or there is a grab on a widget that is not
10987 * an ancestor of the real pointer widget (in which case the effective pointer
10988 * window should be the root window).
10990 * When the effective pointer window is the same as the real poiner window, we
10991 * receive crossing events from the windowing system. When the effective pointer
10992 * window changes to become different from the real pointer window we synthesize
10993 * crossing events, attempting to follow X protocol rules:
10995 * When the root window becomes the effective pointer window:
10996 * - leave notify on real pointer window, detail Ancestor
10997 * - leave notify on all of its ancestors, detail Virtual
10998 * - enter notify on root window, detail Inferior
11000 * When the root window ceases to be the effective pointer window:
11001 * - leave notify on root window, detail Inferior
11002 * - enter notify on all ancestors of real pointer window, detail Virtual
11003 * - enter notify on real pointer window, detail Ancestor
11006 _gtk_widget_synthesize_crossing (GtkWidget *from,
11009 GdkCrossingMode mode)
11011 GdkWindow *from_window = NULL, *to_window = NULL;
11013 g_return_if_fail (from != NULL || to != NULL);
11017 from_window = _gtk_widget_get_device_window (from, device);
11020 from_window = from->priv->window;
11025 to_window = _gtk_widget_get_device_window (to, device);
11028 to_window = to->priv->window;
11031 if (from_window == NULL && to_window == NULL)
11033 else if (from_window != NULL && to_window == NULL)
11035 GList *from_ancestors = NULL, *list;
11036 GdkWindow *from_ancestor = from_window;
11038 while (from_ancestor != NULL)
11040 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
11041 if (from_ancestor == NULL)
11043 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
11046 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11047 device, mode, GDK_NOTIFY_ANCESTOR);
11048 for (list = g_list_last (from_ancestors); list; list = list->prev)
11050 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11051 device, mode, GDK_NOTIFY_VIRTUAL);
11054 /* XXX: enter/inferior on root window? */
11056 g_list_free (from_ancestors);
11058 else if (from_window == NULL && to_window != NULL)
11060 GList *to_ancestors = NULL, *list;
11061 GdkWindow *to_ancestor = to_window;
11063 while (to_ancestor != NULL)
11065 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
11066 if (to_ancestor == NULL)
11068 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
11071 /* XXX: leave/inferior on root window? */
11073 for (list = to_ancestors; list; list = list->next)
11075 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11076 device, mode, GDK_NOTIFY_VIRTUAL);
11078 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11079 device, mode, GDK_NOTIFY_ANCESTOR);
11081 g_list_free (to_ancestors);
11083 else if (from_window == to_window)
11087 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
11088 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
11090 while (from_ancestor != NULL || to_ancestor != NULL)
11092 if (from_ancestor != NULL)
11094 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
11095 if (from_ancestor == to_window)
11098 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
11100 if (to_ancestor != NULL)
11102 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
11103 if (to_ancestor == from_window)
11106 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
11109 if (to_ancestor == from_window)
11111 if (mode != GDK_CROSSING_GTK_UNGRAB)
11112 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11113 device, mode, GDK_NOTIFY_INFERIOR);
11114 for (list = to_ancestors; list; list = list->next)
11115 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11116 device, mode, GDK_NOTIFY_VIRTUAL);
11117 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11118 device, mode, GDK_NOTIFY_ANCESTOR);
11120 else if (from_ancestor == to_window)
11122 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11123 device, mode, GDK_NOTIFY_ANCESTOR);
11124 for (list = g_list_last (from_ancestors); list; list = list->prev)
11126 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11127 device, mode, GDK_NOTIFY_VIRTUAL);
11129 if (mode != GDK_CROSSING_GTK_GRAB)
11130 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11131 device, mode, GDK_NOTIFY_INFERIOR);
11135 while (from_ancestors != NULL && to_ancestors != NULL
11136 && from_ancestors->data == to_ancestors->data)
11138 from_ancestors = g_list_delete_link (from_ancestors,
11140 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
11143 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11144 device, mode, GDK_NOTIFY_NONLINEAR);
11146 for (list = g_list_last (from_ancestors); list; list = list->prev)
11148 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11149 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11151 for (list = to_ancestors; list; list = list->next)
11153 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11154 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11156 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11157 device, mode, GDK_NOTIFY_NONLINEAR);
11159 g_list_free (from_ancestors);
11160 g_list_free (to_ancestors);
11165 gtk_widget_propagate_state (GtkWidget *widget,
11166 GtkStateData *data)
11168 GtkWidgetPrivate *priv = widget->priv;
11169 GtkStateFlags new_flags, old_flags = priv->state_flags;
11170 GtkStateType old_state;
11172 old_state = gtk_widget_get_state (widget);
11174 switch (data->operation)
11176 case STATE_CHANGE_REPLACE:
11177 priv->state_flags = data->flags;
11179 case STATE_CHANGE_SET:
11180 priv->state_flags |= data->flags;
11182 case STATE_CHANGE_UNSET:
11183 priv->state_flags &= ~(data->flags);
11187 /* make insensitivity unoverridable */
11188 if (!priv->sensitive)
11189 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
11191 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
11195 window = gtk_widget_get_toplevel (widget);
11197 if (window && gtk_widget_is_toplevel (window))
11198 gtk_window_set_focus (GTK_WINDOW (window), NULL);
11201 new_flags = priv->state_flags;
11203 if (old_flags != new_flags)
11205 g_object_ref (widget);
11207 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
11208 gtk_grab_remove (widget);
11210 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
11211 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
11213 if (!priv->shadowed)
11215 GList *event_windows = NULL;
11216 GList *devices, *d;
11218 devices = _gtk_widget_list_devices (widget);
11220 for (d = devices; d; d = d->next)
11226 window = _gtk_widget_get_device_window (widget, device);
11228 /* Do not propagate more than once to the
11229 * same window if non-multidevice aware.
11231 if (!gdk_window_get_support_multidevice (window) &&
11232 g_list_find (event_windows, window))
11235 if (!gtk_widget_is_sensitive (widget))
11236 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
11237 GDK_CROSSING_STATE_CHANGED);
11238 else if (old_flags & GTK_STATE_FLAG_INSENSITIVE)
11239 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
11240 GDK_CROSSING_STATE_CHANGED);
11242 event_windows = g_list_prepend (event_windows, window);
11245 g_list_free (event_windows);
11246 g_list_free (devices);
11249 if (GTK_IS_CONTAINER (widget))
11251 GtkStateData child_data = *data;
11253 /* Make sure to only propate the right states further */
11254 child_data.flags &= GTK_STATE_FLAGS_DO_PROPAGATE;
11256 if (child_data.use_forall)
11257 gtk_container_forall (GTK_CONTAINER (widget),
11258 (GtkCallback) gtk_widget_propagate_state,
11261 gtk_container_foreach (GTK_CONTAINER (widget),
11262 (GtkCallback) gtk_widget_propagate_state,
11266 /* Trigger state change transitions for the widget */
11267 if (priv->context &&
11268 gtk_widget_get_mapped (widget))
11270 gint diff, flag = 1;
11272 diff = old_flags ^ new_flags;
11276 if ((diff & flag) != 0)
11280 target = ((new_flags & flag) != 0);
11281 _gtk_widget_notify_state_change (widget, flag, target);
11290 g_object_unref (widget);
11294 static const GtkWidgetAuxInfo default_aux_info = {
11302 * gtk_widget_get_aux_info:
11303 * @widget: a #GtkWidget
11304 * @create: if %TRUE, create the structure if it doesn't exist
11306 * Get the #GtkWidgetAuxInfo structure for the widget.
11308 * Return value: the #GtkAuxInfo structure for the widget, or
11309 * %NULL if @create is %FALSE and one doesn't already exist.
11311 static GtkWidgetAuxInfo *
11312 gtk_widget_get_aux_info (GtkWidget *widget,
11315 GtkWidgetAuxInfo *aux_info;
11317 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
11318 if (!aux_info && create)
11320 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
11322 *aux_info = default_aux_info;
11324 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
11330 static const GtkWidgetAuxInfo*
11331 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11333 GtkWidgetAuxInfo *aux_info;
11335 aux_info = gtk_widget_get_aux_info (widget, FALSE);
11336 if (aux_info == NULL)
11338 return &default_aux_info;
11346 /*****************************************
11347 * gtk_widget_aux_info_destroy:
11352 *****************************************/
11355 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11357 g_slice_free (GtkWidgetAuxInfo, aux_info);
11361 * gtk_widget_shape_combine_region:
11362 * @widget: a #GtkWidget
11363 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11365 * Sets a shape for this widget's GDK window. This allows for
11366 * transparent windows etc., see gdk_window_shape_combine_region()
11367 * for more information.
11372 gtk_widget_shape_combine_region (GtkWidget *widget,
11373 cairo_region_t *region)
11375 GtkWidgetPrivate *priv;
11377 g_return_if_fail (GTK_IS_WIDGET (widget));
11378 /* set_shape doesn't work on widgets without gdk window */
11379 g_return_if_fail (gtk_widget_get_has_window (widget));
11381 priv = widget->priv;
11383 if (region == NULL)
11385 priv->has_shape_mask = FALSE;
11388 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11390 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11394 priv->has_shape_mask = TRUE;
11396 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11397 cairo_region_copy (region),
11398 (GDestroyNotify) cairo_region_destroy);
11400 /* set shape if widget has a gdk window already.
11401 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11404 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11409 * gtk_widget_input_shape_combine_region:
11410 * @widget: a #GtkWidget
11411 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11413 * Sets an input shape for this widget's GDK window. This allows for
11414 * windows which react to mouse click in a nonrectangular region, see
11415 * gdk_window_input_shape_combine_region() for more information.
11420 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11421 cairo_region_t *region)
11423 GtkWidgetPrivate *priv;
11425 g_return_if_fail (GTK_IS_WIDGET (widget));
11426 /* set_shape doesn't work on widgets without gdk window */
11427 g_return_if_fail (gtk_widget_get_has_window (widget));
11429 priv = widget->priv;
11431 if (region == NULL)
11434 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11436 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11440 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11441 cairo_region_copy (region),
11442 (GDestroyNotify) cairo_region_destroy);
11444 /* set shape if widget has a gdk window already.
11445 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11448 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11453 /* style properties
11457 * gtk_widget_class_install_style_property_parser: (skip)
11458 * @klass: a #GtkWidgetClass
11459 * @pspec: the #GParamSpec for the style property
11460 * @parser: the parser for the style property
11462 * Installs a style property on a widget class.
11465 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11467 GtkRcPropertyParser parser)
11469 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11470 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11471 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11472 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11474 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11476 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11477 G_OBJECT_CLASS_NAME (klass),
11482 g_param_spec_ref_sink (pspec);
11483 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11484 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11488 * gtk_widget_class_install_style_property:
11489 * @klass: a #GtkWidgetClass
11490 * @pspec: the #GParamSpec for the property
11492 * Installs a style property on a widget class. The parser for the
11493 * style property is determined by the value type of @pspec.
11496 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11499 GtkRcPropertyParser parser;
11501 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11502 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11504 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11506 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11510 * gtk_widget_class_find_style_property:
11511 * @klass: a #GtkWidgetClass
11512 * @property_name: the name of the style property to find
11513 * @returns: (transfer none): the #GParamSpec of the style property or
11514 * %NULL if @class has no style property with that name.
11516 * Finds a style property of a widget class by name.
11521 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11522 const gchar *property_name)
11524 g_return_val_if_fail (property_name != NULL, NULL);
11526 return g_param_spec_pool_lookup (style_property_spec_pool,
11528 G_OBJECT_CLASS_TYPE (klass),
11533 * gtk_widget_class_list_style_properties:
11534 * @klass: a #GtkWidgetClass
11535 * @n_properties: location to return the number of style properties found
11536 * @returns: (array length=n_properties) (transfer container): an
11537 * newly allocated array of #GParamSpec*. The array must be
11538 * freed with g_free().
11540 * Returns all style properties of a widget class.
11545 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11546 guint *n_properties)
11548 GParamSpec **pspecs;
11551 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11552 G_OBJECT_CLASS_TYPE (klass),
11561 * gtk_widget_style_get_property:
11562 * @widget: a #GtkWidget
11563 * @property_name: the name of a style property
11564 * @value: location to return the property value
11566 * Gets the value of a style property of @widget.
11569 gtk_widget_style_get_property (GtkWidget *widget,
11570 const gchar *property_name,
11575 g_return_if_fail (GTK_IS_WIDGET (widget));
11576 g_return_if_fail (property_name != NULL);
11577 g_return_if_fail (G_IS_VALUE (value));
11579 g_object_ref (widget);
11580 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11582 G_OBJECT_TYPE (widget),
11585 g_warning ("%s: widget class `%s' has no property named `%s'",
11587 G_OBJECT_TYPE_NAME (widget),
11591 GtkStyleContext *context;
11592 const GValue *peek_value;
11593 GtkStateFlags state;
11595 context = gtk_widget_get_style_context (widget);
11596 state = gtk_widget_get_state_flags (widget);
11598 peek_value = _gtk_style_context_peek_style_property (context,
11599 G_OBJECT_TYPE (widget),
11602 /* auto-conversion of the caller's value type
11604 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11605 g_value_copy (peek_value, value);
11606 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11607 g_value_transform (peek_value, value);
11609 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11611 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11612 G_VALUE_TYPE_NAME (value));
11614 g_object_unref (widget);
11618 * gtk_widget_style_get_valist:
11619 * @widget: a #GtkWidget
11620 * @first_property_name: the name of the first property to get
11621 * @var_args: a <type>va_list</type> of pairs of property names and
11622 * locations to return the property values, starting with the location
11623 * for @first_property_name.
11625 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11629 gtk_widget_style_get_valist (GtkWidget *widget,
11630 const gchar *first_property_name,
11633 GtkStyleContext *context;
11634 GtkStateFlags state;
11637 g_return_if_fail (GTK_IS_WIDGET (widget));
11639 g_object_ref (widget);
11640 context = gtk_widget_get_style_context (widget);
11641 state = gtk_widget_get_state_flags (widget);
11643 name = first_property_name;
11646 const GValue *peek_value;
11650 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11652 G_OBJECT_TYPE (widget),
11656 g_warning ("%s: widget class `%s' has no property named `%s'",
11658 G_OBJECT_TYPE_NAME (widget),
11662 /* style pspecs are always readable so we can spare that check here */
11664 peek_value = _gtk_style_context_peek_style_property (context,
11665 G_OBJECT_TYPE (widget),
11668 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11671 g_warning ("%s: %s", G_STRLOC, error);
11676 name = va_arg (var_args, gchar*);
11679 g_object_unref (widget);
11683 * gtk_widget_style_get:
11684 * @widget: a #GtkWidget
11685 * @first_property_name: the name of the first property to get
11686 * @Varargs: pairs of property names and locations to
11687 * return the property values, starting with the location for
11688 * @first_property_name, terminated by %NULL.
11690 * Gets the values of a multiple style properties of @widget.
11693 gtk_widget_style_get (GtkWidget *widget,
11694 const gchar *first_property_name,
11699 g_return_if_fail (GTK_IS_WIDGET (widget));
11701 va_start (var_args, first_property_name);
11702 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11708 * @widget: a #GtkWidget
11709 * @path_length: (out) (allow-none): location to store length of the path,
11711 * @path: (out) (allow-none): location to store allocated path string,
11713 * @path_reversed: (out) (allow-none): location to store allocated reverse
11714 * path string, or %NULL
11716 * Obtains the full path to @widget. The path is simply the name of a
11717 * widget and all its parents in the container hierarchy, separated by
11718 * periods. The name of a widget comes from
11719 * gtk_widget_get_name(). Paths are used to apply styles to a widget
11720 * in gtkrc configuration files. Widget names are the type of the
11721 * widget by default (e.g. "GtkButton") or can be set to an
11722 * application-specific value with gtk_widget_set_name(). By setting
11723 * the name of a widget, you allow users or theme authors to apply
11724 * styles to that specific widget in their gtkrc
11725 * file. @path_reversed_p fills in the path in reverse order,
11726 * i.e. starting with @widget's name instead of starting with the name
11727 * of @widget's outermost ancestor.
11729 * Deprecated:3.0: Use gtk_widget_get_path() instead
11732 gtk_widget_path (GtkWidget *widget,
11733 guint *path_length,
11735 gchar **path_reversed)
11737 static gchar *rev_path = NULL;
11738 static guint tmp_path_len = 0;
11741 g_return_if_fail (GTK_IS_WIDGET (widget));
11746 const gchar *string;
11751 string = gtk_widget_get_name (widget);
11752 l = strlen (string);
11753 while (tmp_path_len <= len + l + 1)
11755 tmp_path_len += INIT_PATH_SIZE;
11756 rev_path = g_realloc (rev_path, tmp_path_len);
11758 s = string + l - 1;
11759 d = rev_path + len;
11760 while (s >= string)
11764 widget = widget->priv->parent;
11767 rev_path[len++] = '.';
11769 rev_path[len++] = 0;
11774 *path_length = len - 1;
11776 *path_reversed = g_strdup (rev_path);
11779 *path = g_strdup (rev_path);
11780 g_strreverse (*path);
11785 * gtk_widget_class_path:
11786 * @widget: a #GtkWidget
11787 * @path_length: (out) (allow-none): location to store the length of the
11788 * class path, or %NULL
11789 * @path: (out) (allow-none): location to store the class path as an
11790 * allocated string, or %NULL
11791 * @path_reversed: (out) (allow-none): location to store the reverse
11792 * class path as an allocated string, or %NULL
11794 * Same as gtk_widget_path(), but always uses the name of a widget's type,
11795 * never uses a custom name set with gtk_widget_set_name().
11797 * Deprecated:3.0: Use gtk_widget_get_path() instead
11800 gtk_widget_class_path (GtkWidget *widget,
11801 guint *path_length,
11803 gchar **path_reversed)
11805 static gchar *rev_path = NULL;
11806 static guint tmp_path_len = 0;
11809 g_return_if_fail (GTK_IS_WIDGET (widget));
11814 const gchar *string;
11819 string = g_type_name (G_OBJECT_TYPE (widget));
11820 l = strlen (string);
11821 while (tmp_path_len <= len + l + 1)
11823 tmp_path_len += INIT_PATH_SIZE;
11824 rev_path = g_realloc (rev_path, tmp_path_len);
11826 s = string + l - 1;
11827 d = rev_path + len;
11828 while (s >= string)
11832 widget = widget->priv->parent;
11835 rev_path[len++] = '.';
11837 rev_path[len++] = 0;
11842 *path_length = len - 1;
11844 *path_reversed = g_strdup (rev_path);
11847 *path = g_strdup (rev_path);
11848 g_strreverse (*path);
11853 * gtk_requisition_new:
11855 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11857 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11858 * be freed with gtk_requisition_free().
11863 gtk_requisition_new (void)
11865 return g_slice_new0 (GtkRequisition);
11869 * gtk_requisition_copy:
11870 * @requisition: a #GtkRequisition
11872 * Copies a #GtkRequisition.
11874 * Returns: a copy of @requisition
11877 gtk_requisition_copy (const GtkRequisition *requisition)
11879 return g_slice_dup (GtkRequisition, requisition);
11883 * gtk_requisition_free:
11884 * @requisition: a #GtkRequisition
11886 * Frees a #GtkRequisition.
11889 gtk_requisition_free (GtkRequisition *requisition)
11891 g_slice_free (GtkRequisition, requisition);
11894 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11895 gtk_requisition_copy,
11896 gtk_requisition_free)
11899 * gtk_widget_get_accessible:
11900 * @widget: a #GtkWidget
11902 * Returns the accessible object that describes the widget to an
11903 * assistive technology.
11905 * If no accessibility library is loaded (i.e. no ATK implementation library is
11906 * loaded via <envar>GTK_MODULES</envar> or via another application library,
11907 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
11908 * if no class-specific #AtkObject implementation is available for the widget
11909 * instance in question, it will inherit an #AtkObject implementation from the
11910 * first ancestor class for which such an implementation is defined.
11912 * The documentation of the
11913 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
11914 * library contains more information about accessible objects and their uses.
11916 * Returns: (transfer none): the #AtkObject associated with @widget
11919 gtk_widget_get_accessible (GtkWidget *widget)
11921 GtkWidgetClass *klass;
11923 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11925 klass = GTK_WIDGET_GET_CLASS (widget);
11927 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11929 return klass->get_accessible (widget);
11933 gtk_widget_real_get_accessible (GtkWidget *widget)
11935 AtkObject* accessible;
11937 accessible = g_object_get_qdata (G_OBJECT (widget),
11938 quark_accessible_object);
11941 AtkObjectFactory *factory;
11942 AtkRegistry *default_registry;
11944 default_registry = atk_get_default_registry ();
11945 factory = atk_registry_get_factory (default_registry,
11946 G_TYPE_FROM_INSTANCE (widget));
11948 atk_object_factory_create_accessible (factory,
11949 G_OBJECT (widget));
11950 g_object_set_qdata (G_OBJECT (widget),
11951 quark_accessible_object,
11958 * Initialize a AtkImplementorIface instance's virtual pointers as
11959 * appropriate to this implementor's class (GtkWidget).
11962 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11964 iface->ref_accessible = gtk_widget_ref_accessible;
11968 gtk_widget_ref_accessible (AtkImplementor *implementor)
11970 AtkObject *accessible;
11972 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11974 g_object_ref (accessible);
11979 * Expand flag management
11983 gtk_widget_update_computed_expand (GtkWidget *widget)
11985 GtkWidgetPrivate *priv;
11987 priv = widget->priv;
11989 if (priv->need_compute_expand)
11993 if (priv->hexpand_set)
11998 if (priv->vexpand_set)
12003 /* we don't need to use compute_expand if both expands are
12004 * forced by the app
12006 if (!(priv->hexpand_set && priv->vexpand_set))
12008 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
12012 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
12013 priv->hexpand_set ? &ignored : &h,
12014 priv->vexpand_set ? &ignored : &v);
12018 priv->need_compute_expand = FALSE;
12019 priv->computed_hexpand = h != FALSE;
12020 priv->computed_vexpand = v != FALSE;
12025 * gtk_widget_queue_compute_expand:
12026 * @widget: a #GtkWidget
12028 * Mark @widget as needing to recompute its expand flags. Call
12029 * this function when setting legacy expand child properties
12030 * on the child of a container.
12032 * See gtk_widget_compute_expand().
12035 gtk_widget_queue_compute_expand (GtkWidget *widget)
12038 gboolean changed_anything;
12040 if (widget->priv->need_compute_expand)
12043 changed_anything = FALSE;
12045 while (parent != NULL)
12047 if (!parent->priv->need_compute_expand)
12049 parent->priv->need_compute_expand = TRUE;
12050 changed_anything = TRUE;
12053 /* Note: if we had an invariant that "if a child needs to
12054 * compute expand, its parents also do" then we could stop going
12055 * up when we got to a parent that already needed to
12056 * compute. However, in general we compute expand lazily (as
12057 * soon as we see something in a subtree that is expand, we know
12058 * we're expanding) and so this invariant does not hold and we
12059 * have to always walk all the way up in case some ancestor
12060 * is not currently need_compute_expand.
12063 parent = parent->priv->parent;
12066 /* recomputing expand always requires
12067 * a relayout as well
12069 if (changed_anything)
12070 gtk_widget_queue_resize (widget);
12074 * gtk_widget_compute_expand:
12075 * @widget: the widget
12076 * @orientation: expand direction
12078 * Computes whether a container should give this widget extra space
12079 * when possible. Containers should check this, rather than
12080 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
12082 * This function already checks whether the widget is visible, so
12083 * visibility does not need to be checked separately. Non-visible
12084 * widgets are not expanded.
12086 * The computed expand value uses either the expand setting explicitly
12087 * set on the widget itself, or, if none has been explicitly set,
12088 * the widget may expand if some of its children do.
12090 * Return value: whether widget tree rooted here should be expanded
12093 gtk_widget_compute_expand (GtkWidget *widget,
12094 GtkOrientation orientation)
12096 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12098 /* We never make a widget expand if not even showing. */
12099 if (!gtk_widget_get_visible (widget))
12102 gtk_widget_update_computed_expand (widget);
12104 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12106 return widget->priv->computed_hexpand;
12110 return widget->priv->computed_vexpand;
12115 gtk_widget_set_expand (GtkWidget *widget,
12116 GtkOrientation orientation,
12119 const char *expand_prop;
12120 const char *expand_set_prop;
12122 GtkWidgetPrivate *priv;
12124 g_return_if_fail (GTK_IS_WIDGET (widget));
12126 priv = widget->priv;
12128 expand = expand != FALSE;
12130 was_both = priv->hexpand && priv->vexpand;
12132 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12134 if (priv->hexpand_set &&
12135 priv->hexpand == expand)
12138 priv->hexpand_set = TRUE;
12139 priv->hexpand = expand;
12141 expand_prop = "hexpand";
12142 expand_set_prop = "hexpand-set";
12146 if (priv->vexpand_set &&
12147 priv->vexpand == expand)
12150 priv->vexpand_set = TRUE;
12151 priv->vexpand = expand;
12153 expand_prop = "vexpand";
12154 expand_set_prop = "vexpand-set";
12157 gtk_widget_queue_compute_expand (widget);
12159 g_object_freeze_notify (G_OBJECT (widget));
12160 g_object_notify (G_OBJECT (widget), expand_prop);
12161 g_object_notify (G_OBJECT (widget), expand_set_prop);
12162 if (was_both != (priv->hexpand && priv->vexpand))
12163 g_object_notify (G_OBJECT (widget), "expand");
12164 g_object_thaw_notify (G_OBJECT (widget));
12168 gtk_widget_set_expand_set (GtkWidget *widget,
12169 GtkOrientation orientation,
12172 GtkWidgetPrivate *priv;
12175 priv = widget->priv;
12177 set = set != FALSE;
12179 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12181 if (set == priv->hexpand_set)
12184 priv->hexpand_set = set;
12185 prop = "hexpand-set";
12189 if (set == priv->vexpand_set)
12192 priv->vexpand_set = set;
12193 prop = "vexpand-set";
12196 gtk_widget_queue_compute_expand (widget);
12198 g_object_notify (G_OBJECT (widget), prop);
12202 * gtk_widget_get_hexpand:
12203 * @widget: the widget
12205 * Gets whether the widget would like any available extra horizontal
12206 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12207 * generally receive the extra space. For example, a list or
12208 * scrollable area or document in your window would often be set to
12211 * Containers should use gtk_widget_compute_expand() rather than
12212 * this function, to see whether a widget, or any of its children,
12213 * has the expand flag set. If any child of a widget wants to
12214 * expand, the parent may ask to expand also.
12216 * This function only looks at the widget's own hexpand flag, rather
12217 * than computing whether the entire widget tree rooted at this widget
12220 * Return value: whether hexpand flag is set
12223 gtk_widget_get_hexpand (GtkWidget *widget)
12225 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12227 return widget->priv->hexpand;
12231 * gtk_widget_set_hexpand:
12232 * @widget: the widget
12233 * @expand: whether to expand
12235 * Sets whether the widget would like any available extra horizontal
12236 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12237 * generally receive the extra space. For example, a list or
12238 * scrollable area or document in your window would often be set to
12241 * Call this function to set the expand flag if you would like your
12242 * widget to become larger horizontally when the window has extra
12245 * By default, widgets automatically expand if any of their children
12246 * want to expand. (To see if a widget will automatically expand given
12247 * its current children and state, call gtk_widget_compute_expand(). A
12248 * container can decide how the expandability of children affects the
12249 * expansion of the container by overriding the compute_expand virtual
12250 * method on #GtkWidget.).
12252 * Setting hexpand explicitly with this function will override the
12253 * automatic expand behavior.
12255 * This function forces the widget to expand or not to expand,
12256 * regardless of children. The override occurs because
12257 * gtk_widget_set_hexpand() sets the hexpand-set property (see
12258 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
12259 * value to be used, rather than looking at children and widget state.
12262 gtk_widget_set_hexpand (GtkWidget *widget,
12265 g_return_if_fail (GTK_IS_WIDGET (widget));
12267 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
12271 * gtk_widget_get_hexpand_set:
12272 * @widget: the widget
12274 * Gets whether gtk_widget_set_hexpand() has been used to
12275 * explicitly set the expand flag on this widget.
12277 * If hexpand is set, then it overrides any computed
12278 * expand value based on child widgets. If hexpand is not
12279 * set, then the expand value depends on whether any
12280 * children of the widget would like to expand.
12282 * There are few reasons to use this function, but it's here
12283 * for completeness and consistency.
12285 * Return value: whether hexpand has been explicitly set
12288 gtk_widget_get_hexpand_set (GtkWidget *widget)
12290 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12292 return widget->priv->hexpand_set;
12296 * gtk_widget_set_hexpand_set:
12297 * @widget: the widget
12298 * @set: value for hexpand-set property
12300 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
12303 * The hexpand-set property will be set automatically when you call
12304 * gtk_widget_set_hexpand() to set hexpand, so the most likely
12305 * reason to use this function would be to unset an explicit expand
12308 * If hexpand is set, then it overrides any computed
12309 * expand value based on child widgets. If hexpand is not
12310 * set, then the expand value depends on whether any
12311 * children of the widget would like to expand.
12313 * There are few reasons to use this function, but it's here
12314 * for completeness and consistency.
12317 gtk_widget_set_hexpand_set (GtkWidget *widget,
12320 g_return_if_fail (GTK_IS_WIDGET (widget));
12322 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
12327 * gtk_widget_get_vexpand:
12328 * @widget: the widget
12330 * Gets whether the widget would like any available extra vertical
12333 * See gtk_widget_get_hexpand() for more detail.
12335 * Return value: whether vexpand flag is set
12338 gtk_widget_get_vexpand (GtkWidget *widget)
12340 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12342 return widget->priv->vexpand;
12346 * gtk_widget_set_vexpand:
12347 * @widget: the widget
12348 * @expand: whether to expand
12350 * Sets whether the widget would like any available extra vertical
12353 * See gtk_widget_set_hexpand() for more detail.
12356 gtk_widget_set_vexpand (GtkWidget *widget,
12359 g_return_if_fail (GTK_IS_WIDGET (widget));
12361 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12365 * gtk_widget_get_vexpand_set:
12366 * @widget: the widget
12368 * Gets whether gtk_widget_set_vexpand() has been used to
12369 * explicitly set the expand flag on this widget.
12371 * See gtk_widget_get_hexpand_set() for more detail.
12373 * Return value: whether vexpand has been explicitly set
12376 gtk_widget_get_vexpand_set (GtkWidget *widget)
12378 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12380 return widget->priv->vexpand_set;
12384 * gtk_widget_set_vexpand_set:
12385 * @widget: the widget
12386 * @set: value for vexpand-set property
12388 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12391 * See gtk_widget_set_hexpand_set() for more detail.
12394 gtk_widget_set_vexpand_set (GtkWidget *widget,
12397 g_return_if_fail (GTK_IS_WIDGET (widget));
12399 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12403 * GtkBuildable implementation
12405 static GQuark quark_builder_has_default = 0;
12406 static GQuark quark_builder_has_focus = 0;
12407 static GQuark quark_builder_atk_relations = 0;
12408 static GQuark quark_builder_set_name = 0;
12411 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12413 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12414 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12415 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12416 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12418 iface->set_name = gtk_widget_buildable_set_name;
12419 iface->get_name = gtk_widget_buildable_get_name;
12420 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12421 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12422 iface->parser_finished = gtk_widget_buildable_parser_finished;
12423 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12424 iface->custom_finished = gtk_widget_buildable_custom_finished;
12428 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12431 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12432 g_strdup (name), g_free);
12435 static const gchar *
12436 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12438 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12442 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12443 GtkBuilder *builder,
12444 const gchar *childname)
12446 if (strcmp (childname, "accessible") == 0)
12447 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12453 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12454 GtkBuilder *builder,
12456 const GValue *value)
12458 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12459 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12460 GINT_TO_POINTER (TRUE));
12461 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12462 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12463 GINT_TO_POINTER (TRUE));
12465 g_object_set_property (G_OBJECT (buildable), name, value);
12470 gchar *action_name;
12471 GString *description;
12473 gboolean translatable;
12483 free_action (AtkActionData *data, gpointer user_data)
12485 g_free (data->action_name);
12486 g_string_free (data->description, TRUE);
12487 g_free (data->context);
12488 g_slice_free (AtkActionData, data);
12492 free_relation (AtkRelationData *data, gpointer user_data)
12494 g_free (data->target);
12495 g_free (data->type);
12496 g_slice_free (AtkRelationData, data);
12500 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12501 GtkBuilder *builder)
12503 GSList *atk_relations;
12505 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12506 gtk_widget_grab_default (GTK_WIDGET (buildable));
12507 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12508 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12510 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12511 quark_builder_atk_relations);
12514 AtkObject *accessible;
12515 AtkRelationSet *relation_set;
12518 AtkRelationType relation_type;
12519 AtkObject *target_accessible;
12521 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12522 relation_set = atk_object_ref_relation_set (accessible);
12524 for (l = atk_relations; l; l = l->next)
12526 AtkRelationData *relation = (AtkRelationData*)l->data;
12528 target = gtk_builder_get_object (builder, relation->target);
12531 g_warning ("Target object %s in <relation> does not exist",
12535 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12536 g_assert (target_accessible != NULL);
12538 relation_type = atk_relation_type_for_name (relation->type);
12539 if (relation_type == ATK_RELATION_NULL)
12541 g_warning ("<relation> type %s not found",
12545 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12546 target_accessible);
12548 g_object_unref (relation_set);
12550 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
12551 g_slist_free (atk_relations);
12552 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12561 } AccessibilitySubParserData;
12564 accessibility_start_element (GMarkupParseContext *context,
12565 const gchar *element_name,
12566 const gchar **names,
12567 const gchar **values,
12568 gpointer user_data,
12571 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12573 gint line_number, char_number;
12575 if (strcmp (element_name, "relation") == 0)
12577 gchar *target = NULL;
12578 gchar *type = NULL;
12579 AtkRelationData *relation;
12581 for (i = 0; names[i]; i++)
12583 if (strcmp (names[i], "target") == 0)
12584 target = g_strdup (values[i]);
12585 else if (strcmp (names[i], "type") == 0)
12586 type = g_strdup (values[i]);
12589 g_markup_parse_context_get_position (context,
12592 g_set_error (error,
12594 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12595 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12597 line_number, char_number, names[i], "relation");
12604 if (!target || !type)
12606 g_markup_parse_context_get_position (context,
12609 g_set_error (error,
12611 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12612 "%s:%d:%d <%s> requires attribute \"%s\"",
12614 line_number, char_number, "relation",
12615 type ? "target" : "type");
12621 relation = g_slice_new (AtkRelationData);
12622 relation->target = target;
12623 relation->type = type;
12625 data->relations = g_slist_prepend (data->relations, relation);
12627 else if (strcmp (element_name, "action") == 0)
12629 const gchar *action_name = NULL;
12630 const gchar *description = NULL;
12631 const gchar *msg_context = NULL;
12632 gboolean translatable = FALSE;
12633 AtkActionData *action;
12635 for (i = 0; names[i]; i++)
12637 if (strcmp (names[i], "action_name") == 0)
12638 action_name = values[i];
12639 else if (strcmp (names[i], "description") == 0)
12640 description = values[i];
12641 else if (strcmp (names[i], "translatable") == 0)
12643 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12646 else if (strcmp (names[i], "comments") == 0)
12648 /* do nothing, comments are for translators */
12650 else if (strcmp (names[i], "context") == 0)
12651 msg_context = values[i];
12654 g_markup_parse_context_get_position (context,
12657 g_set_error (error,
12659 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12660 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12662 line_number, char_number, names[i], "action");
12669 g_markup_parse_context_get_position (context,
12672 g_set_error (error,
12674 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12675 "%s:%d:%d <%s> requires attribute \"%s\"",
12677 line_number, char_number, "action",
12682 action = g_slice_new (AtkActionData);
12683 action->action_name = g_strdup (action_name);
12684 action->description = g_string_new (description);
12685 action->context = g_strdup (msg_context);
12686 action->translatable = translatable;
12688 data->actions = g_slist_prepend (data->actions, action);
12690 else if (strcmp (element_name, "accessibility") == 0)
12693 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12697 accessibility_text (GMarkupParseContext *context,
12700 gpointer user_data,
12703 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12705 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12707 AtkActionData *action = data->actions->data;
12709 g_string_append_len (action->description, text, text_len);
12713 static const GMarkupParser accessibility_parser =
12715 accessibility_start_element,
12717 accessibility_text,
12726 } AccelGroupParserData;
12729 accel_group_start_element (GMarkupParseContext *context,
12730 const gchar *element_name,
12731 const gchar **names,
12732 const gchar **values,
12733 gpointer user_data,
12738 guint modifiers = 0;
12739 gchar *signal = NULL;
12740 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12742 for (i = 0; names[i]; i++)
12744 if (strcmp (names[i], "key") == 0)
12745 key = gdk_keyval_from_name (values[i]);
12746 else if (strcmp (names[i], "modifiers") == 0)
12748 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12754 else if (strcmp (names[i], "signal") == 0)
12755 signal = g_strdup (values[i]);
12758 if (key == 0 || signal == NULL)
12760 g_warning ("<accelerator> requires key and signal attributes");
12763 parser_data->key = key;
12764 parser_data->modifiers = modifiers;
12765 parser_data->signal = signal;
12768 static const GMarkupParser accel_group_parser =
12770 accel_group_start_element,
12779 style_start_element (GMarkupParseContext *context,
12780 const gchar *element_name,
12781 const gchar **names,
12782 const gchar **values,
12783 gpointer user_data,
12786 StyleParserData *style_data = (StyleParserData *)user_data;
12789 if (strcmp (element_name, "class") == 0)
12791 if (g_markup_collect_attributes (element_name,
12795 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12796 G_MARKUP_COLLECT_INVALID))
12798 style_data->classes = g_slist_append (style_data->classes, class_name);
12801 else if (strcmp (element_name, "style") == 0)
12804 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12807 static const GMarkupParser style_parser =
12809 style_start_element,
12813 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12814 GtkBuilder *builder,
12816 const gchar *tagname,
12817 GMarkupParser *parser,
12820 g_assert (buildable);
12822 if (strcmp (tagname, "accelerator") == 0)
12824 AccelGroupParserData *parser_data;
12826 parser_data = g_slice_new0 (AccelGroupParserData);
12827 parser_data->object = g_object_ref (buildable);
12828 *parser = accel_group_parser;
12829 *data = parser_data;
12832 if (strcmp (tagname, "accessibility") == 0)
12834 AccessibilitySubParserData *parser_data;
12836 parser_data = g_slice_new0 (AccessibilitySubParserData);
12837 *parser = accessibility_parser;
12838 *data = parser_data;
12841 if (strcmp (tagname, "style") == 0)
12843 StyleParserData *parser_data;
12845 parser_data = g_slice_new0 (StyleParserData);
12846 *parser = style_parser;
12847 *data = parser_data;
12855 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12856 GtkWidget *toplevel,
12857 gpointer user_data)
12859 AccelGroupParserData *accel_data;
12860 GSList *accel_groups;
12861 GtkAccelGroup *accel_group;
12863 g_return_if_fail (GTK_IS_WIDGET (widget));
12864 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12865 g_return_if_fail (user_data != NULL);
12867 accel_data = (AccelGroupParserData*)user_data;
12868 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12869 if (g_slist_length (accel_groups) == 0)
12871 accel_group = gtk_accel_group_new ();
12872 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12876 g_assert (g_slist_length (accel_groups) == 1);
12877 accel_group = g_slist_nth_data (accel_groups, 0);
12880 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12881 accel_data->signal,
12884 accel_data->modifiers,
12885 GTK_ACCEL_VISIBLE);
12887 g_object_unref (accel_data->object);
12888 g_free (accel_data->signal);
12889 g_slice_free (AccelGroupParserData, accel_data);
12893 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12894 GtkBuilder *builder,
12896 const gchar *tagname,
12897 gpointer user_data)
12899 if (strcmp (tagname, "accelerator") == 0)
12901 AccelGroupParserData *accel_data;
12902 GtkWidget *toplevel;
12904 accel_data = (AccelGroupParserData*)user_data;
12905 g_assert (accel_data->object);
12907 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12909 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12911 else if (strcmp (tagname, "accessibility") == 0)
12913 AccessibilitySubParserData *a11y_data;
12915 a11y_data = (AccessibilitySubParserData*)user_data;
12917 if (a11y_data->actions)
12919 AtkObject *accessible;
12924 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12926 if (ATK_IS_ACTION (accessible))
12928 action = ATK_ACTION (accessible);
12929 n_actions = atk_action_get_n_actions (action);
12931 for (l = a11y_data->actions; l; l = l->next)
12933 AtkActionData *action_data = (AtkActionData*)l->data;
12935 for (i = 0; i < n_actions; i++)
12936 if (strcmp (atk_action_get_name (action, i),
12937 action_data->action_name) == 0)
12942 gchar *description;
12944 if (action_data->translatable && action_data->description->len)
12945 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12946 action_data->context,
12947 action_data->description->str);
12949 description = action_data->description->str;
12951 atk_action_set_description (action, i, description);
12956 g_warning ("accessibility action on a widget that does not implement AtkAction");
12958 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
12959 g_slist_free (a11y_data->actions);
12962 if (a11y_data->relations)
12963 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12964 a11y_data->relations);
12966 g_slice_free (AccessibilitySubParserData, a11y_data);
12968 else if (strcmp (tagname, "style") == 0)
12970 StyleParserData *style_data = (StyleParserData *)user_data;
12971 GtkStyleContext *context;
12974 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
12976 for (l = style_data->classes; l; l = l->next)
12977 gtk_style_context_add_class (context, (const gchar *)l->data);
12979 gtk_widget_reset_style (GTK_WIDGET (buildable));
12981 g_slist_free_full (style_data->classes, g_free);
12982 g_slice_free (StyleParserData, style_data);
12986 static GtkSizeRequestMode
12987 gtk_widget_real_get_request_mode (GtkWidget *widget)
12989 /* By default widgets dont trade size at all. */
12990 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
12994 gtk_widget_real_get_width (GtkWidget *widget,
12995 gint *minimum_size,
12996 gint *natural_size)
13006 gtk_widget_real_get_height (GtkWidget *widget,
13007 gint *minimum_size,
13008 gint *natural_size)
13018 gtk_widget_real_get_height_for_width (GtkWidget *widget,
13020 gint *minimum_height,
13021 gint *natural_height)
13023 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
13027 gtk_widget_real_get_width_for_height (GtkWidget *widget,
13029 gint *minimum_width,
13030 gint *natural_width)
13032 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
13036 * gtk_widget_get_halign:
13037 * @widget: a #GtkWidget
13039 * Gets the value of the #GtkWidget:halign property.
13041 * Returns: the horizontal alignment of @widget
13044 gtk_widget_get_halign (GtkWidget *widget)
13046 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
13047 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
13051 * gtk_widget_set_halign:
13052 * @widget: a #GtkWidget
13053 * @align: the horizontal alignment
13055 * Sets the horizontal alignment of @widget.
13056 * See the #GtkWidget:halign property.
13059 gtk_widget_set_halign (GtkWidget *widget,
13062 GtkWidgetAuxInfo *aux_info;
13064 g_return_if_fail (GTK_IS_WIDGET (widget));
13066 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13068 if (aux_info->halign == align)
13071 aux_info->halign = align;
13072 gtk_widget_queue_resize (widget);
13073 g_object_notify (G_OBJECT (widget), "halign");
13077 * gtk_widget_get_valign:
13078 * @widget: a #GtkWidget
13080 * Gets the value of the #GtkWidget:valign property.
13082 * Returns: the vertical alignment of @widget
13085 gtk_widget_get_valign (GtkWidget *widget)
13087 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
13088 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
13092 * gtk_widget_set_valign:
13093 * @widget: a #GtkWidget
13094 * @align: the vertical alignment
13096 * Sets the vertical alignment of @widget.
13097 * See the #GtkWidget:valign property.
13100 gtk_widget_set_valign (GtkWidget *widget,
13103 GtkWidgetAuxInfo *aux_info;
13105 g_return_if_fail (GTK_IS_WIDGET (widget));
13107 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13109 if (aux_info->valign == align)
13112 aux_info->valign = align;
13113 gtk_widget_queue_resize (widget);
13114 g_object_notify (G_OBJECT (widget), "valign");
13118 * gtk_widget_get_margin_left:
13119 * @widget: a #GtkWidget
13121 * Gets the value of the #GtkWidget:margin-left property.
13123 * Returns: The left margin of @widget
13128 gtk_widget_get_margin_left (GtkWidget *widget)
13130 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13132 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
13136 * gtk_widget_set_margin_left:
13137 * @widget: a #GtkWidget
13138 * @margin: the left margin
13140 * Sets the left margin of @widget.
13141 * See the #GtkWidget:margin-left property.
13146 gtk_widget_set_margin_left (GtkWidget *widget,
13149 GtkWidgetAuxInfo *aux_info;
13151 g_return_if_fail (GTK_IS_WIDGET (widget));
13152 g_return_if_fail (margin <= G_MAXINT16);
13154 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13156 if (aux_info->margin.left == margin)
13159 aux_info->margin.left = margin;
13160 gtk_widget_queue_resize (widget);
13161 g_object_notify (G_OBJECT (widget), "margin-left");
13165 * gtk_widget_get_margin_right:
13166 * @widget: a #GtkWidget
13168 * Gets the value of the #GtkWidget:margin-right property.
13170 * Returns: The right margin of @widget
13175 gtk_widget_get_margin_right (GtkWidget *widget)
13177 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13179 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
13183 * gtk_widget_set_margin_right:
13184 * @widget: a #GtkWidget
13185 * @margin: the right margin
13187 * Sets the right margin of @widget.
13188 * See the #GtkWidget:margin-right property.
13193 gtk_widget_set_margin_right (GtkWidget *widget,
13196 GtkWidgetAuxInfo *aux_info;
13198 g_return_if_fail (GTK_IS_WIDGET (widget));
13199 g_return_if_fail (margin <= G_MAXINT16);
13201 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13203 if (aux_info->margin.right == margin)
13206 aux_info->margin.right = margin;
13207 gtk_widget_queue_resize (widget);
13208 g_object_notify (G_OBJECT (widget), "margin-right");
13212 * gtk_widget_get_margin_top:
13213 * @widget: a #GtkWidget
13215 * Gets the value of the #GtkWidget:margin-top property.
13217 * Returns: The top margin of @widget
13222 gtk_widget_get_margin_top (GtkWidget *widget)
13224 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13226 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
13230 * gtk_widget_set_margin_top:
13231 * @widget: a #GtkWidget
13232 * @margin: the top margin
13234 * Sets the top margin of @widget.
13235 * See the #GtkWidget:margin-top property.
13240 gtk_widget_set_margin_top (GtkWidget *widget,
13243 GtkWidgetAuxInfo *aux_info;
13245 g_return_if_fail (GTK_IS_WIDGET (widget));
13246 g_return_if_fail (margin <= G_MAXINT16);
13248 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13250 if (aux_info->margin.top == margin)
13253 aux_info->margin.top = margin;
13254 gtk_widget_queue_resize (widget);
13255 g_object_notify (G_OBJECT (widget), "margin-top");
13259 * gtk_widget_get_margin_bottom:
13260 * @widget: a #GtkWidget
13262 * Gets the value of the #GtkWidget:margin-bottom property.
13264 * Returns: The bottom margin of @widget
13269 gtk_widget_get_margin_bottom (GtkWidget *widget)
13271 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13273 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
13277 * gtk_widget_set_margin_bottom:
13278 * @widget: a #GtkWidget
13279 * @margin: the bottom margin
13281 * Sets the bottom margin of @widget.
13282 * See the #GtkWidget:margin-bottom property.
13287 gtk_widget_set_margin_bottom (GtkWidget *widget,
13290 GtkWidgetAuxInfo *aux_info;
13292 g_return_if_fail (GTK_IS_WIDGET (widget));
13293 g_return_if_fail (margin <= G_MAXINT16);
13295 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13297 if (aux_info->margin.bottom == margin)
13300 aux_info->margin.bottom = margin;
13301 gtk_widget_queue_resize (widget);
13302 g_object_notify (G_OBJECT (widget), "margin-bottom");
13306 * gtk_widget_get_clipboard:
13307 * @widget: a #GtkWidget
13308 * @selection: a #GdkAtom which identifies the clipboard
13309 * to use. %GDK_SELECTION_CLIPBOARD gives the
13310 * default clipboard. Another common value
13311 * is %GDK_SELECTION_PRIMARY, which gives
13312 * the primary X selection.
13314 * Returns the clipboard object for the given selection to
13315 * be used with @widget. @widget must have a #GdkDisplay
13316 * associated with it, so must be attached to a toplevel
13319 * Return value: (transfer none): the appropriate clipboard object. If no
13320 * clipboard already exists, a new one will
13321 * be created. Once a clipboard object has
13322 * been created, it is persistent for all time.
13327 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
13329 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13330 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
13332 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
13337 * gtk_widget_list_mnemonic_labels:
13338 * @widget: a #GtkWidget
13340 * Returns a newly allocated list of the widgets, normally labels, for
13341 * which this widget is the target of a mnemonic (see for example,
13342 * gtk_label_set_mnemonic_widget()).
13344 * The widgets in the list are not individually referenced. If you
13345 * want to iterate through the list and perform actions involving
13346 * callbacks that might destroy the widgets, you
13347 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
13348 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
13349 * widgets afterwards.
13351 * Return value: (element-type GtkWidget) (transfer container): the list of
13352 * mnemonic labels; free this list
13353 * with g_list_free() when you are done with it.
13358 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
13360 GList *list = NULL;
13363 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13365 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13366 list = g_list_prepend (list, l->data);
13372 * gtk_widget_add_mnemonic_label:
13373 * @widget: a #GtkWidget
13374 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13376 * Adds a widget to the list of mnemonic labels for
13377 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13378 * list of mnemonic labels for the widget is cleared when the
13379 * widget is destroyed, so the caller must make sure to update
13380 * its internal state at this point as well, by using a connection
13381 * to the #GtkWidget::destroy signal or a weak notifier.
13386 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13389 GSList *old_list, *new_list;
13391 g_return_if_fail (GTK_IS_WIDGET (widget));
13392 g_return_if_fail (GTK_IS_WIDGET (label));
13394 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13395 new_list = g_slist_prepend (old_list, label);
13397 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13398 new_list, (GDestroyNotify) g_slist_free);
13402 * gtk_widget_remove_mnemonic_label:
13403 * @widget: a #GtkWidget
13404 * @label: a #GtkWidget that was previously set as a mnemnic label for
13405 * @widget with gtk_widget_add_mnemonic_label().
13407 * Removes a widget from the list of mnemonic labels for
13408 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13409 * must have previously been added to the list with
13410 * gtk_widget_add_mnemonic_label().
13415 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13418 GSList *old_list, *new_list;
13420 g_return_if_fail (GTK_IS_WIDGET (widget));
13421 g_return_if_fail (GTK_IS_WIDGET (label));
13423 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13424 new_list = g_slist_remove (old_list, label);
13427 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13428 new_list, (GDestroyNotify) g_slist_free);
13432 * gtk_widget_get_no_show_all:
13433 * @widget: a #GtkWidget
13435 * Returns the current value of the #GtkWidget:no-show-all property,
13436 * which determines whether calls to gtk_widget_show_all()
13437 * will affect this widget.
13439 * Return value: the current value of the "no-show-all" property.
13444 gtk_widget_get_no_show_all (GtkWidget *widget)
13446 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13448 return widget->priv->no_show_all;
13452 * gtk_widget_set_no_show_all:
13453 * @widget: a #GtkWidget
13454 * @no_show_all: the new value for the "no-show-all" property
13456 * Sets the #GtkWidget:no-show-all property, which determines whether
13457 * calls to gtk_widget_show_all() will affect this widget.
13459 * This is mostly for use in constructing widget hierarchies with externally
13460 * controlled visibility, see #GtkUIManager.
13465 gtk_widget_set_no_show_all (GtkWidget *widget,
13466 gboolean no_show_all)
13468 g_return_if_fail (GTK_IS_WIDGET (widget));
13470 no_show_all = (no_show_all != FALSE);
13472 if (widget->priv->no_show_all != no_show_all)
13474 widget->priv->no_show_all = no_show_all;
13476 g_object_notify (G_OBJECT (widget), "no-show-all");
13482 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13483 gboolean has_tooltip,
13486 GtkWidgetPrivate *priv = widget->priv;
13487 gboolean priv_has_tooltip;
13489 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13490 quark_has_tooltip));
13492 if (priv_has_tooltip != has_tooltip || force)
13494 priv_has_tooltip = has_tooltip;
13496 if (priv_has_tooltip)
13498 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13499 gdk_window_set_events (priv->window,
13500 gdk_window_get_events (priv->window) |
13501 GDK_LEAVE_NOTIFY_MASK |
13502 GDK_POINTER_MOTION_MASK |
13503 GDK_POINTER_MOTION_HINT_MASK);
13505 if (gtk_widget_get_has_window (widget))
13506 gtk_widget_add_events (widget,
13507 GDK_LEAVE_NOTIFY_MASK |
13508 GDK_POINTER_MOTION_MASK |
13509 GDK_POINTER_MOTION_HINT_MASK);
13512 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13513 GUINT_TO_POINTER (priv_has_tooltip));
13518 * gtk_widget_set_tooltip_window:
13519 * @widget: a #GtkWidget
13520 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13522 * Replaces the default, usually yellow, window used for displaying
13523 * tooltips with @custom_window. GTK+ will take care of showing and
13524 * hiding @custom_window at the right moment, to behave likewise as
13525 * the default tooltip window. If @custom_window is %NULL, the default
13526 * tooltip window will be used.
13528 * If the custom window should have the default theming it needs to
13529 * have the name "gtk-tooltip", see gtk_widget_set_name().
13534 gtk_widget_set_tooltip_window (GtkWidget *widget,
13535 GtkWindow *custom_window)
13537 gboolean has_tooltip;
13538 gchar *tooltip_markup;
13540 g_return_if_fail (GTK_IS_WIDGET (widget));
13541 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13543 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13546 g_object_ref (custom_window);
13548 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13549 custom_window, g_object_unref);
13551 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13552 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13554 if (has_tooltip && gtk_widget_get_visible (widget))
13555 gtk_widget_queue_tooltip_query (widget);
13559 * gtk_widget_get_tooltip_window:
13560 * @widget: a #GtkWidget
13562 * Returns the #GtkWindow of the current tooltip. This can be the
13563 * GtkWindow created by default, or the custom tooltip window set
13564 * using gtk_widget_set_tooltip_window().
13566 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13571 gtk_widget_get_tooltip_window (GtkWidget *widget)
13573 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13575 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13579 * gtk_widget_trigger_tooltip_query:
13580 * @widget: a #GtkWidget
13582 * Triggers a tooltip query on the display where the toplevel of @widget
13583 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13589 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13591 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13594 static guint tooltip_query_id;
13595 static GSList *tooltip_query_displays;
13598 tooltip_query_idle (gpointer data)
13600 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13601 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13602 g_slist_free (tooltip_query_displays);
13604 tooltip_query_displays = NULL;
13605 tooltip_query_id = 0;
13611 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13613 GdkDisplay *display;
13615 display = gtk_widget_get_display (widget);
13617 if (!g_slist_find (tooltip_query_displays, display))
13618 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13620 if (tooltip_query_id == 0)
13621 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13625 * gtk_widget_set_tooltip_text:
13626 * @widget: a #GtkWidget
13627 * @text: the contents of the tooltip for @widget
13629 * Sets @text as the contents of the tooltip. This function will take
13630 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13631 * handler for the #GtkWidget::query-tooltip signal.
13633 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13638 gtk_widget_set_tooltip_text (GtkWidget *widget,
13641 g_return_if_fail (GTK_IS_WIDGET (widget));
13643 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13647 * gtk_widget_get_tooltip_text:
13648 * @widget: a #GtkWidget
13650 * Gets the contents of the tooltip for @widget.
13652 * Return value: the tooltip text, or %NULL. You should free the
13653 * returned string with g_free() when done.
13658 gtk_widget_get_tooltip_text (GtkWidget *widget)
13660 gchar *text = NULL;
13662 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13664 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13670 * gtk_widget_set_tooltip_markup:
13671 * @widget: a #GtkWidget
13672 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13674 * Sets @markup as the contents of the tooltip, which is marked up with
13675 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13677 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13678 * and of the default handler for the #GtkWidget::query-tooltip signal.
13680 * See also the #GtkWidget:tooltip-markup property and
13681 * gtk_tooltip_set_markup().
13686 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13687 const gchar *markup)
13689 g_return_if_fail (GTK_IS_WIDGET (widget));
13691 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13695 * gtk_widget_get_tooltip_markup:
13696 * @widget: a #GtkWidget
13698 * Gets the contents of the tooltip for @widget.
13700 * Return value: the tooltip text, or %NULL. You should free the
13701 * returned string with g_free() when done.
13706 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13708 gchar *text = NULL;
13710 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13712 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13718 * gtk_widget_set_has_tooltip:
13719 * @widget: a #GtkWidget
13720 * @has_tooltip: whether or not @widget has a tooltip.
13722 * Sets the has-tooltip property on @widget to @has_tooltip. See
13723 * #GtkWidget:has-tooltip for more information.
13728 gtk_widget_set_has_tooltip (GtkWidget *widget,
13729 gboolean has_tooltip)
13731 g_return_if_fail (GTK_IS_WIDGET (widget));
13733 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13737 * gtk_widget_get_has_tooltip:
13738 * @widget: a #GtkWidget
13740 * Returns the current value of the has-tooltip property. See
13741 * #GtkWidget:has-tooltip for more information.
13743 * Return value: current value of has-tooltip on @widget.
13748 gtk_widget_get_has_tooltip (GtkWidget *widget)
13750 gboolean has_tooltip = FALSE;
13752 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13754 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13756 return has_tooltip;
13760 * gtk_widget_get_allocation:
13761 * @widget: a #GtkWidget
13762 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13764 * Retrieves the widget's allocation.
13766 * Note, when implementing a #GtkContainer: a widget's allocation will
13767 * be its "adjusted" allocation, that is, the widget's parent
13768 * container typically calls gtk_widget_size_allocate() with an
13769 * allocation, and that allocation is then adjusted (to handle margin
13770 * and alignment for example) before assignment to the widget.
13771 * gtk_widget_get_allocation() returns the adjusted allocation that
13772 * was actually assigned to the widget. The adjusted allocation is
13773 * guaranteed to be completely contained within the
13774 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13775 * is guaranteed that its children stay inside the assigned bounds,
13776 * but not that they have exactly the bounds the container assigned.
13777 * There is no way to get the original allocation assigned by
13778 * gtk_widget_size_allocate(), since it isn't stored; if a container
13779 * implementation needs that information it will have to track it itself.
13784 gtk_widget_get_allocation (GtkWidget *widget,
13785 GtkAllocation *allocation)
13787 GtkWidgetPrivate *priv;
13789 g_return_if_fail (GTK_IS_WIDGET (widget));
13790 g_return_if_fail (allocation != NULL);
13792 priv = widget->priv;
13794 *allocation = priv->allocation;
13798 * gtk_widget_set_allocation:
13799 * @widget: a #GtkWidget
13800 * @allocation: a pointer to a #GtkAllocation to copy from
13802 * Sets the widget's allocation. This should not be used
13803 * directly, but from within a widget's size_allocate method.
13805 * The allocation set should be the "adjusted" or actual
13806 * allocation. If you're implementing a #GtkContainer, you want to use
13807 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13808 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13809 * allocation inside gtk_widget_size_allocate() to create an adjusted
13815 gtk_widget_set_allocation (GtkWidget *widget,
13816 const GtkAllocation *allocation)
13818 GtkWidgetPrivate *priv;
13820 g_return_if_fail (GTK_IS_WIDGET (widget));
13821 g_return_if_fail (allocation != NULL);
13823 priv = widget->priv;
13825 priv->allocation = *allocation;
13829 * gtk_widget_get_allocated_width:
13830 * @widget: the widget to query
13832 * Returns the width that has currently been allocated to @widget.
13833 * This function is intended to be used when implementing handlers
13834 * for the #GtkWidget::draw function.
13836 * Returns: the width of the @widget
13839 gtk_widget_get_allocated_width (GtkWidget *widget)
13841 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13843 return widget->priv->allocation.width;
13847 * gtk_widget_get_allocated_height:
13848 * @widget: the widget to query
13850 * Returns the height that has currently been allocated to @widget.
13851 * This function is intended to be used when implementing handlers
13852 * for the #GtkWidget::draw function.
13854 * Returns: the height of the @widget
13857 gtk_widget_get_allocated_height (GtkWidget *widget)
13859 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13861 return widget->priv->allocation.height;
13865 * gtk_widget_get_requisition:
13866 * @widget: a #GtkWidget
13867 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13869 * Retrieves the widget's requisition.
13871 * This function should only be used by widget implementations in
13872 * order to figure whether the widget's requisition has actually
13873 * changed after some internal state change (so that they can call
13874 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13876 * Normally, gtk_widget_size_request() should be used.
13880 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13881 * removed, If you need to cache sizes across requests and allocations,
13882 * add an explicit cache to the widget in question instead.
13885 gtk_widget_get_requisition (GtkWidget *widget,
13886 GtkRequisition *requisition)
13888 g_return_if_fail (GTK_IS_WIDGET (widget));
13889 g_return_if_fail (requisition != NULL);
13891 gtk_widget_get_preferred_size (widget, requisition, NULL);
13895 * gtk_widget_set_window:
13896 * @widget: a #GtkWidget
13897 * @window: a #GdkWindow
13899 * Sets a widget's window. This function should only be used in a
13900 * widget's #GtkWidget::realize implementation. The %window passed is
13901 * usually either new window created with gdk_window_new(), or the
13902 * window of its parent widget as returned by
13903 * gtk_widget_get_parent_window().
13905 * Widgets must indicate whether they will create their own #GdkWindow
13906 * by calling gtk_widget_set_has_window(). This is usually done in the
13907 * widget's init() function.
13909 * <note><para>This function does not add any reference to @window.</para></note>
13914 gtk_widget_set_window (GtkWidget *widget,
13917 GtkWidgetPrivate *priv;
13919 g_return_if_fail (GTK_IS_WIDGET (widget));
13920 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13922 priv = widget->priv;
13924 if (priv->window != window)
13926 priv->window = window;
13927 g_object_notify (G_OBJECT (widget), "window");
13932 * gtk_widget_get_window:
13933 * @widget: a #GtkWidget
13935 * Returns the widget's window if it is realized, %NULL otherwise
13937 * Return value: (transfer none): @widget's window.
13942 gtk_widget_get_window (GtkWidget *widget)
13944 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13946 return widget->priv->window;
13950 * gtk_widget_get_support_multidevice:
13951 * @widget: a #GtkWidget
13953 * Returns %TRUE if @widget is multiple pointer aware. See
13954 * gtk_widget_set_support_multidevice() for more information.
13956 * Returns: %TRUE if @widget is multidevice aware.
13959 gtk_widget_get_support_multidevice (GtkWidget *widget)
13961 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13963 return widget->priv->multidevice;
13967 * gtk_widget_set_support_multidevice:
13968 * @widget: a #GtkWidget
13969 * @support_multidevice: %TRUE to support input from multiple devices.
13971 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13972 * @widget will start receiving multiple, per device enter/leave events. Note
13973 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13974 * gdk_window_set_support_multidevice() will have to be called manually on them.
13979 gtk_widget_set_support_multidevice (GtkWidget *widget,
13980 gboolean support_multidevice)
13982 GtkWidgetPrivate *priv;
13984 g_return_if_fail (GTK_IS_WIDGET (widget));
13986 priv = widget->priv;
13987 priv->multidevice = (support_multidevice == TRUE);
13989 if (gtk_widget_get_realized (widget))
13990 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13994 _gtk_widget_set_has_focus (GtkWidget *widget,
13995 gboolean has_focus)
13997 widget->priv->has_focus = has_focus;
14000 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
14002 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
14006 * gtk_widget_send_focus_change:
14007 * @widget: a #GtkWidget
14008 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
14010 * Sends the focus change @event to @widget
14012 * This function is not meant to be used by applications. The only time it
14013 * should be used is when it is necessary for a #GtkWidget to assign focus
14014 * to a widget that is semantically owned by the first widget even though
14015 * it's not a direct child - for instance, a search entry in a floating
14016 * window similar to the quick search in #GtkTreeView.
14018 * An example of its usage is:
14021 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
14023 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
14024 * fevent->focus_change.in = TRUE;
14025 * fevent->focus_change.window = gtk_widget_get_window (widget);
14026 * if (fevent->focus_change.window != NULL)
14027 * g_object_ref (fevent->focus_change.window);
14029 * gtk_widget_send_focus_change (widget, fevent);
14031 * gdk_event_free (event);
14034 * Return value: the return value from the event signal emission: %TRUE
14035 * if the event was handled, and %FALSE otherwise
14040 gtk_widget_send_focus_change (GtkWidget *widget,
14045 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
14046 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
14048 g_object_ref (widget);
14050 _gtk_widget_set_has_focus (widget, event->focus_change.in);
14052 res = gtk_widget_event (widget, event);
14054 g_object_notify (G_OBJECT (widget), "has-focus");
14056 g_object_unref (widget);
14062 * gtk_widget_in_destruction:
14063 * @widget: a #GtkWidget
14065 * Returns whether the widget is currently being destroyed.
14066 * This information can sometimes be used to avoid doing
14067 * unnecessary work.
14069 * Returns: %TRUE if @widget is being destroyed
14072 gtk_widget_in_destruction (GtkWidget *widget)
14074 return widget->priv->in_destruction;
14078 _gtk_widget_get_resize_pending (GtkWidget *widget)
14080 return widget->priv->resize_pending;
14084 _gtk_widget_set_resize_pending (GtkWidget *widget,
14085 gboolean resize_pending)
14087 widget->priv->resize_pending = resize_pending;
14091 _gtk_widget_get_in_reparent (GtkWidget *widget)
14093 return widget->priv->in_reparent;
14097 _gtk_widget_set_in_reparent (GtkWidget *widget,
14098 gboolean in_reparent)
14100 widget->priv->in_reparent = in_reparent;
14104 _gtk_widget_get_anchored (GtkWidget *widget)
14106 return widget->priv->anchored;
14110 _gtk_widget_set_anchored (GtkWidget *widget,
14113 widget->priv->anchored = anchored;
14117 _gtk_widget_get_shadowed (GtkWidget *widget)
14119 return widget->priv->shadowed;
14123 _gtk_widget_set_shadowed (GtkWidget *widget,
14126 widget->priv->shadowed = shadowed;
14130 _gtk_widget_get_alloc_needed (GtkWidget *widget)
14132 return widget->priv->alloc_needed;
14136 _gtk_widget_set_alloc_needed (GtkWidget *widget,
14137 gboolean alloc_needed)
14139 widget->priv->alloc_needed = alloc_needed;
14143 _gtk_widget_get_width_request_needed (GtkWidget *widget)
14145 return widget->priv->width_request_needed;
14149 _gtk_widget_set_width_request_needed (GtkWidget *widget,
14150 gboolean width_request_needed)
14152 widget->priv->width_request_needed = width_request_needed;
14156 _gtk_widget_get_height_request_needed (GtkWidget *widget)
14158 return widget->priv->height_request_needed;
14162 _gtk_widget_set_height_request_needed (GtkWidget *widget,
14163 gboolean height_request_needed)
14165 widget->priv->height_request_needed = height_request_needed;
14169 _gtk_widget_get_sizegroup_visited (GtkWidget *widget)
14171 return widget->priv->sizegroup_visited;
14175 _gtk_widget_set_sizegroup_visited (GtkWidget *widget,
14178 widget->priv->sizegroup_visited = visited;
14182 _gtk_widget_get_sizegroup_bumping (GtkWidget *widget)
14184 return widget->priv->sizegroup_bumping;
14188 _gtk_widget_set_sizegroup_bumping (GtkWidget *widget,
14191 widget->priv->sizegroup_bumping = bumping;
14195 _gtk_widget_add_sizegroup (GtkWidget *widget,
14200 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14201 groups = g_slist_prepend (groups, group);
14202 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14204 widget->priv->have_size_groups = TRUE;
14208 _gtk_widget_remove_sizegroup (GtkWidget *widget,
14213 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14214 groups = g_slist_remove (groups, group);
14215 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14217 widget->priv->have_size_groups = groups != NULL;
14221 _gtk_widget_get_sizegroups (GtkWidget *widget)
14223 if (widget->priv->have_size_groups)
14224 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14230 * gtk_widget_path_append_for_widget:
14231 * @path: a widget path
14232 * @widget: the widget to append to the widget path
14234 * Appends the data from @widget to the widget hierarchy represented
14235 * by @path. This function is a shortcut for adding information from
14236 * @widget to the given @path. This includes setting the name or
14237 * adding the style classes from @widget.
14239 * Returns: the position where the data was inserted
14244 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
14249 g_return_val_if_fail (path != NULL, 0);
14250 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14252 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
14254 if (widget->priv->name)
14255 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
14257 if (widget->priv->context)
14259 GList *classes, *l;
14261 /* Also add any persistent classes in
14262 * the style context the widget path
14264 classes = gtk_style_context_list_classes (widget->priv->context);
14266 for (l = classes; l; l = l->next)
14267 gtk_widget_path_iter_add_class (path, pos, l->data);
14269 g_list_free (classes);
14276 * gtk_widget_get_path:
14277 * @widget: a #GtkWidget
14279 * Returns the #GtkWidgetPath representing @widget, if the widget
14280 * is not connected to a toplevel widget, a partial path will be
14283 * Returns: (transfer none): The #GtkWidgetPath representing @widget
14286 gtk_widget_get_path (GtkWidget *widget)
14288 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14290 /* As strange as it may seem, this may happen on object construction.
14291 * init() implementations of parent types may eventually call this function,
14292 * each with its corresponding GType, which could leave a child
14293 * implementation with a wrong widget type in the widget path
14295 if (widget->priv->path &&
14296 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (widget->priv->path))
14298 gtk_widget_path_free (widget->priv->path);
14299 widget->priv->path = NULL;
14302 if (!widget->priv->path)
14306 parent = widget->priv->parent;
14309 widget->priv->path = gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
14312 /* Widget is either toplevel or unparented, treat both
14313 * as toplevels style wise, since there are situations
14314 * where style properties might be retrieved on that
14317 widget->priv->path = gtk_widget_path_new ();
14319 gtk_widget_path_append_for_widget (widget->priv->path, widget);
14322 if (widget->priv->context)
14323 gtk_style_context_set_path (widget->priv->context,
14324 widget->priv->path);
14327 return widget->priv->path;
14331 style_context_changed (GtkStyleContext *context,
14332 gpointer user_data)
14334 GtkWidget *widget = user_data;
14336 if (gtk_widget_get_realized (widget))
14337 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
14340 /* Compress all style updates so it
14341 * is only emitted once pre-realize.
14343 widget->priv->style_update_pending = TRUE;
14346 if (widget->priv->anchored)
14347 gtk_widget_queue_resize (widget);
14351 * gtk_widget_get_style_context:
14352 * @widget: a #GtkWidget
14354 * Returns the style context associated to @widget.
14356 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
14357 * must not be freed.
14360 gtk_widget_get_style_context (GtkWidget *widget)
14362 GtkWidgetPrivate *priv;
14363 GtkWidgetPath *path;
14365 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14367 priv = widget->priv;
14369 /* updates style context if it exists already */
14370 path = gtk_widget_get_path (widget);
14372 if (G_UNLIKELY (priv->context == NULL))
14376 priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
14377 "direction", gtk_widget_get_direction (widget),
14380 g_signal_connect (widget->priv->context, "changed",
14381 G_CALLBACK (style_context_changed), widget);
14383 screen = gtk_widget_get_screen (widget);
14386 gtk_style_context_set_screen (priv->context, screen);
14388 gtk_style_context_set_path (priv->context, path);
14391 return widget->priv->context;