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 "gtkselection.h"
46 #include "gtksettingsprivate.h"
47 #include "gtksizegroup-private.h"
48 #include "gtkwidget.h"
49 #include "gtkwidgetprivate.h"
50 #include "gtkwindowprivate.h"
51 #include "gtkbindings.h"
52 #include "gtkprivate.h"
53 #include "gtkaccessible.h"
54 #include "gtktooltip.h"
55 #include "gtkinvisible.h"
56 #include "gtkbuildable.h"
57 #include "gtkbuilderprivate.h"
58 #include "gtksizerequest.h"
59 #include "gtkstylecontext.h"
60 #include "gtksymboliccolor.h"
61 #include "gtkcssprovider.h"
62 #include "gtkanimationdescription.h"
63 #include "gtkmodifierstyle.h"
64 #include "gtkversion.h"
66 #include "gtktypebuiltins.h"
71 * @Short_description: Base class for all widgets
74 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
75 * widget lifecycle, states and style.
77 * <refsect2 id="geometry-management">
78 * <title>Height-for-width Geometry Management</title>
80 * GTK+ uses a height-for-width (and width-for-height) geometry management
81 * system. Height-for-width means that a widget can change how much
82 * vertical space it needs, depending on the amount of horizontal space
83 * that it is given (and similar for width-for-height). The most common
84 * example is a label that reflows to fill up the available width, wraps
85 * to fewer lines, and therefore needs less height.
87 * Height-for-width geometry management is implemented in GTK+ by way
88 * of five virtual methods:
90 * <listitem>#GtkWidgetClass.get_request_mode()</listitem>
91 * <listitem>#GtkWidgetClass.get_preferred_width()</listitem>
92 * <listitem>#GtkWidgetClass.get_preferred_height()</listitem>
93 * <listitem>#GtkWidgetClass.get_preferred_height_for_width()</listitem>
94 * <listitem>#GtkWidgetClass.get_preferred_width_for_height()</listitem>
97 * There are some important things to keep in mind when implementing
98 * height-for-width and when using it in container implementations.
100 * The geometry management system will query a widget hierarchy in
101 * only one orientation at a time. When widgets are initially queried
102 * for their minimum sizes it is generally done in two initial passes
103 * in the #GtkSizeRequestMode chosen by the toplevel.
105 * For example, when queried in the normal
106 * %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode:
107 * First, the default minimum and natural width for each widget
108 * in the interface will be computed using gtk_widget_get_preferred_width().
109 * Because the preferred widths for each container depend on the preferred
110 * widths of their children, this information propagates up the hierarchy,
111 * and finally a minimum and natural width is determined for the entire
112 * toplevel. Next, the toplevel will use the minimum width to query for the
113 * minimum height contextual to that width using
114 * gtk_widget_get_preferred_height_for_width(), which will also be a highly
115 * recursive operation. The minimum height for the minimum width is normally
116 * used to set the minimum size constraint on the toplevel
117 * (unless gtk_window_set_geometry_hints() is explicitly used instead).
119 * After the toplevel window has initially requested its size in both
120 * dimensions it can go on to allocate itself a reasonable size (or a size
121 * previously specified with gtk_window_set_default_size()). During the
122 * recursive allocation process it's important to note that request cycles
123 * will be recursively executed while container widgets allocate their children.
124 * Each container widget, once allocated a size, will go on to first share the
125 * space in one orientation among its children and then request each child's
126 * height for its target allocated width or its width for allocated height,
127 * depending. In this way a #GtkWidget will typically be requested its size
128 * a number of times before actually being allocated a size. The size a
129 * widget is finally allocated can of course differ from the size it has
130 * requested. For this reason, #GtkWidget caches a small number of results
131 * to avoid re-querying for the same sizes in one allocation cycle.
133 * See <link linkend="container-geometry-management">GtkContainer's
134 * geometry management section</link>
135 * to learn more about how height-for-width allocations are performed
136 * by container widgets.
138 * If a widget does move content around to intelligently use up the
139 * allocated size then it must support the request in both
140 * #GtkSizeRequestModes even if the widget in question only
141 * trades sizes in a single orientation.
143 * For instance, a #GtkLabel that does height-for-width word wrapping
144 * will not expect to have #GtkWidgetClass.get_preferred_height() called
145 * because that call is specific to a width-for-height request. In this
146 * case the label must return the height required for its own minimum
147 * possible width. By following this rule any widget that handles
148 * height-for-width or width-for-height requests will always be allocated
149 * at least enough space to fit its own content.
151 * Here are some examples of how a %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH widget
152 * generally deals with width-for-height requests, for #GtkWidgetClass.get_preferred_height()
154 * <programlisting><![CDATA[
156 * foo_widget_get_preferred_height (GtkWidget *widget, gint *min_height, gint *nat_height)
158 * if (i_am_in_height_for_width_mode)
162 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
163 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width,
164 * min_height, nat_height);
168 * ... some widgets do both. For instance, if a GtkLabel is rotated to 90 degrees
169 * it will return the minimum and natural height for the rotated label here.
172 * ]]></programlisting>
174 * And in #GtkWidgetClass.get_preferred_width_for_height() it will simply return
175 * the minimum and natural width:
177 * <programlisting><![CDATA[
179 * foo_widget_get_preferred_width_for_height (GtkWidget *widget, gint for_height,
180 * gint *min_width, gint *nat_width)
182 * if (i_am_in_height_for_width_mode)
184 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, min_width, nat_width);
188 * ... again if a widget is sometimes operating in width-for-height mode
189 * (like a rotated GtkLabel) it can go ahead and do its real width for
190 * height calculation here.
193 * ]]></programlisting>
195 * Often a widget needs to get its own request during size request or
196 * allocation. For example, when computing height it may need to also
197 * compute width. Or when deciding how to use an allocation, the widget
198 * may need to know its natural size. In these cases, the widget should
199 * be careful to call its virtual methods directly, like this:
201 * <title>Widget calling its own size request method.</title>
203 * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget),
208 * It will not work to use the wrapper functions, such as
209 * gtk_widget_get_preferred_width() inside your own size request
210 * implementation. These return a request adjusted by #GtkSizeGroup
211 * and by the #GtkWidgetClass.adjust_size_request() virtual method. If a
212 * widget used the wrappers inside its virtual method implementations,
213 * then the adjustments (such as widget margins) would be applied
214 * twice. GTK+ therefore does not allow this and will warn if you try
217 * Of course if you are getting the size request for
218 * <emphasis>another</emphasis> widget, such as a child of a
219 * container, you <emphasis>must</emphasis> use the wrapper APIs.
220 * Otherwise, you would not properly consider widget margins,
221 * #GtkSizeGroup, and so forth.
224 * <refsect2 id="style-properties">
225 * <title>Style Properties</title>
227 * <structname>GtkWidget</structname> introduces <firstterm>style
228 * properties</firstterm> - these are basically object properties that are stored
229 * not on the object, but in the style object associated to the widget. Style
230 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
231 * This mechanism is used for configuring such things as the location of the
232 * scrollbar arrows through the theme, giving theme authors more control over the
233 * look of applications without the need to write a theme engine in C.
236 * Use gtk_widget_class_install_style_property() to install style properties for
237 * a widget class, gtk_widget_class_find_style_property() or
238 * gtk_widget_class_list_style_properties() to get information about existing
239 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
240 * gtk_widget_style_get_valist() to obtain the value of a style property.
243 * <refsect2 id="GtkWidget-BUILDER-UI">
244 * <title>GtkWidget as GtkBuildable</title>
246 * The GtkWidget implementation of the GtkBuildable interface supports a
247 * custom <accelerator> element, which has attributes named key,
248 * modifiers and signal and allows to specify accelerators.
251 * <title>A UI definition fragment specifying an accelerator</title>
252 * <programlisting><![CDATA[
253 * <object class="GtkButton">
254 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
256 * ]]></programlisting>
259 * In addition to accelerators, <structname>GtkWidget</structname> also support a
260 * custom <accessible> element, which supports actions and relations.
261 * Properties on the accessible implementation of an object can be set by accessing the
262 * internal child "accessible" of a <structname>GtkWidget</structname>.
265 * <title>A UI definition fragment specifying an accessible</title>
266 * <programlisting><![CDATA[
267 * <object class="GtkButton" id="label1"/>
268 * <property name="label">I am a Label for a Button</property>
270 * <object class="GtkButton" id="button1">
272 * <action action_name="click" translatable="yes">Click the button.</action>
273 * <relation target="label1" type="labelled-by"/>
275 * <child internal-child="accessible">
276 * <object class="AtkObject" id="a11y-button1">
277 * <property name="AtkObject::name">Clickable Button</property>
281 * ]]></programlisting>
286 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
287 #define INIT_PATH_SIZE (512)
289 struct _GtkWidgetPrivate
291 /* The state of the widget. There are actually only
292 * 5 widget states (defined in "gtkenums.h")
295 guint state_flags : 6;
299 guint in_destruction : 1;
302 guint composite_child : 1;
308 guint parent_sensitive : 1;
311 guint can_default : 1;
312 guint has_default : 1;
313 guint receives_default : 1;
317 guint style_update_pending : 1;
318 guint app_paintable : 1;
319 guint double_buffered : 1;
320 guint redraw_on_alloc : 1;
321 guint no_show_all : 1;
322 guint child_visible : 1;
323 guint multidevice : 1;
324 guint has_shape_mask : 1;
325 guint in_reparent : 1;
326 guint resize_pending : 1;
327 guint alloc_needed : 1;
328 guint width_request_needed : 1;
329 guint height_request_needed : 1;
331 /* Expand-related flags */
332 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
333 guint computed_hexpand : 1; /* computed results (composite of child flags) */
334 guint computed_vexpand : 1;
335 guint hexpand : 1; /* application-forced expand */
337 guint hexpand_set : 1; /* whether to use application-forced */
338 guint vexpand_set : 1; /* instead of computing from children */
340 /* The widget's name. If the widget does not have a name
341 * (the name is NULL), then its name (as returned by
342 * "gtk_widget_get_name") is its class's name.
343 * Among other things, the widget name is used to determine
344 * the style to use for a widget.
348 /* The style for the widget. The style contains the
349 * colors the widget should be drawn in for each state
350 * along with graphics contexts used to draw with and
351 * the font to use for text.
354 GtkStyleContext *context;
356 /* The widget's allocated size.
358 GtkAllocation allocation;
360 /* The widget's requested sizes */
361 SizeRequestCache requests;
363 /* The widget's window or its parent window if it does
364 * not have a window. (Which will be indicated by the
365 * GTK_NO_WINDOW flag being set).
369 /* The widget's parent.
373 #ifdef G_ENABLE_DEBUG
374 /* Number of gtk_widget_push_verify_invariants () */
375 guint verifying_invariants_count;
376 #endif /* G_ENABLE_DEBUG */
378 /* Widget's path for styling */
408 BUTTON_RELEASE_EVENT,
423 PROPERTY_NOTIFY_EVENT,
424 SELECTION_CLEAR_EVENT,
425 SELECTION_REQUEST_EVENT,
426 SELECTION_NOTIFY_EVENT,
432 VISIBILITY_NOTIFY_EVENT,
446 ACCEL_CLOSURES_CHANGED,
470 PROP_RECEIVES_DEFAULT,
471 PROP_COMPOSITE_CHILD,
479 PROP_DOUBLE_BUFFERED,
494 typedef struct _GtkStateData GtkStateData;
497 STATE_CHANGE_REPLACE,
506 guint parent_sensitive : 1;
507 guint use_forall : 1;
510 /* --- prototypes --- */
511 static void gtk_widget_class_init (GtkWidgetClass *klass);
512 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
513 static void gtk_widget_init (GtkWidget *widget);
514 static void gtk_widget_set_property (GObject *object,
518 static void gtk_widget_get_property (GObject *object,
522 static void gtk_widget_dispose (GObject *object);
523 static void gtk_widget_real_destroy (GtkWidget *object);
524 static void gtk_widget_finalize (GObject *object);
525 static void gtk_widget_real_show (GtkWidget *widget);
526 static void gtk_widget_real_hide (GtkWidget *widget);
527 static void gtk_widget_real_map (GtkWidget *widget);
528 static void gtk_widget_real_unmap (GtkWidget *widget);
529 static void gtk_widget_real_realize (GtkWidget *widget);
530 static void gtk_widget_real_unrealize (GtkWidget *widget);
531 static void gtk_widget_real_size_allocate (GtkWidget *widget,
532 GtkAllocation *allocation);
533 static void gtk_widget_real_style_set (GtkWidget *widget,
534 GtkStyle *previous_style);
535 static void gtk_widget_real_direction_changed(GtkWidget *widget,
536 GtkTextDirection previous_direction);
538 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
539 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
542 gboolean keyboard_tip,
543 GtkTooltip *tooltip);
544 static void gtk_widget_real_style_updated (GtkWidget *widget);
545 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
546 GtkWidgetHelpType help_type);
548 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
550 GParamSpec **pspecs);
551 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
553 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
555 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
556 GdkEventFocus *event);
557 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
558 GdkEventFocus *event);
559 static gboolean gtk_widget_real_focus (GtkWidget *widget,
560 GtkDirectionType direction);
561 static void gtk_widget_real_move_focus (GtkWidget *widget,
562 GtkDirectionType direction);
563 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
564 GtkDirectionType direction);
565 #ifdef G_ENABLE_DEBUG
566 static void gtk_widget_verify_invariants (GtkWidget *widget);
567 static void gtk_widget_push_verify_invariants (GtkWidget *widget);
568 static void gtk_widget_pop_verify_invariants (GtkWidget *widget);
570 #define gtk_widget_verify_invariants(widget)
571 #define gtk_widget_push_verify_invariants(widget)
572 #define gtk_widget_pop_verify_invariants(widget)
574 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
575 static void gtk_widget_update_pango_context (GtkWidget *widget);
576 static void gtk_widget_propagate_state (GtkWidget *widget,
579 static gint gtk_widget_event_internal (GtkWidget *widget,
581 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
582 gboolean group_cycling);
583 static void gtk_widget_real_get_width (GtkWidget *widget,
586 static void gtk_widget_real_get_height (GtkWidget *widget,
589 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
591 gint *minimum_height,
592 gint *natural_height);
593 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
596 gint *natural_width);
597 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
598 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
599 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
600 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
601 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
602 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
603 cairo_region_t *region);
604 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
605 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
606 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
609 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
610 gboolean has_tooltip,
612 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
613 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
615 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
616 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
618 const gchar *childname);
619 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
622 const GValue *value);
623 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
626 const gchar *tagname,
627 GMarkupParser *parser,
629 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
632 const gchar *tagname,
634 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
635 GtkBuilder *builder);
637 static void gtk_widget_real_get_width (GtkWidget *widget,
640 static void gtk_widget_real_get_height (GtkWidget *widget,
644 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
647 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
648 GtkOrientation orientation,
651 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
652 GtkOrientation orientation,
656 gint *allocated_size);
658 static void gtk_widget_set_usize_internal (GtkWidget *widget,
661 GtkQueueResizeFlags flags);
663 static void gtk_widget_add_events_internal (GtkWidget *widget,
666 static void gtk_widget_set_device_enabled_internal (GtkWidget *widget,
671 /* --- variables --- */
672 static gpointer gtk_widget_parent_class = NULL;
673 static guint widget_signals[LAST_SIGNAL] = { 0 };
674 static GtkStyle *gtk_default_style = NULL;
675 static guint composite_child_stack = 0;
676 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
677 static GParamSpecPool *style_property_spec_pool = NULL;
679 static GQuark quark_property_parser = 0;
680 static GQuark quark_aux_info = 0;
681 static GQuark quark_accel_path = 0;
682 static GQuark quark_accel_closures = 0;
683 static GQuark quark_event_mask = 0;
684 static GQuark quark_device_event_mask = 0;
685 static GQuark quark_parent_window = 0;
686 static GQuark quark_pointer_window = 0;
687 static GQuark quark_shape_info = 0;
688 static GQuark quark_input_shape_info = 0;
689 static GQuark quark_pango_context = 0;
690 static GQuark quark_rc_style = 0;
691 static GQuark quark_accessible_object = 0;
692 static GQuark quark_mnemonic_labels = 0;
693 static GQuark quark_tooltip_markup = 0;
694 static GQuark quark_has_tooltip = 0;
695 static GQuark quark_tooltip_window = 0;
696 static GQuark quark_visual = 0;
697 static GQuark quark_modifier_style = 0;
698 static GQuark quark_enabled_devices = 0;
699 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
700 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
702 /* --- functions --- */
704 gtk_widget_get_type (void)
706 static GType widget_type = 0;
708 if (G_UNLIKELY (widget_type == 0))
710 const GTypeInfo widget_info =
712 sizeof (GtkWidgetClass),
713 NULL, /* base_init */
714 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
715 (GClassInitFunc) gtk_widget_class_init,
716 NULL, /* class_finalize */
717 NULL, /* class_init */
720 (GInstanceInitFunc) gtk_widget_init,
721 NULL, /* value_table */
724 const GInterfaceInfo accessibility_info =
726 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
727 (GInterfaceFinalizeFunc) NULL,
728 NULL /* interface data */
731 const GInterfaceInfo buildable_info =
733 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
734 (GInterfaceFinalizeFunc) NULL,
735 NULL /* interface data */
738 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
739 &widget_info, G_TYPE_FLAG_ABSTRACT);
741 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
742 &accessibility_info) ;
743 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
751 child_property_notify_dispatcher (GObject *object,
755 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
758 /* We guard against the draw signal callbacks modifying the state of the
759 * cairo context by surounding it with save/restore.
760 * Maybe we should also cairo_new_path() just to be sure?
763 gtk_widget_draw_marshaller (GClosure *closure,
764 GValue *return_value,
765 guint n_param_values,
766 const GValue *param_values,
767 gpointer invocation_hint,
768 gpointer marshal_data)
770 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
774 _gtk_marshal_BOOLEAN__BOXED (closure,
785 gtk_widget_class_init (GtkWidgetClass *klass)
787 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
788 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
789 GtkBindingSet *binding_set;
791 gtk_widget_parent_class = g_type_class_peek_parent (klass);
793 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
794 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
795 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
796 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
797 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
798 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
799 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
800 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
801 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
802 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
803 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
804 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
805 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
806 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
807 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
808 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
809 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
810 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
811 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
812 quark_enabled_devices = g_quark_from_static_string ("gtk-widget-enabled-devices");
814 style_property_spec_pool = g_param_spec_pool_new (FALSE);
815 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
816 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
817 cpn_context.dispatcher = child_property_notify_dispatcher;
818 _gtk_widget_child_property_notify_context = &cpn_context;
820 gobject_class->dispose = gtk_widget_dispose;
821 gobject_class->finalize = gtk_widget_finalize;
822 gobject_class->set_property = gtk_widget_set_property;
823 gobject_class->get_property = gtk_widget_get_property;
825 klass->destroy = gtk_widget_real_destroy;
827 klass->activate_signal = 0;
828 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
829 klass->show = gtk_widget_real_show;
830 klass->show_all = gtk_widget_show;
831 klass->hide = gtk_widget_real_hide;
832 klass->map = gtk_widget_real_map;
833 klass->unmap = gtk_widget_real_unmap;
834 klass->realize = gtk_widget_real_realize;
835 klass->unrealize = gtk_widget_real_unrealize;
836 klass->size_allocate = gtk_widget_real_size_allocate;
837 klass->get_preferred_width = gtk_widget_real_get_width;
838 klass->get_preferred_height = gtk_widget_real_get_height;
839 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
840 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
841 klass->state_changed = NULL;
842 klass->parent_set = NULL;
843 klass->hierarchy_changed = NULL;
844 klass->style_set = gtk_widget_real_style_set;
845 klass->direction_changed = gtk_widget_real_direction_changed;
846 klass->grab_notify = NULL;
847 klass->child_notify = NULL;
849 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
850 klass->grab_focus = gtk_widget_real_grab_focus;
851 klass->focus = gtk_widget_real_focus;
852 klass->move_focus = gtk_widget_real_move_focus;
853 klass->keynav_failed = gtk_widget_real_keynav_failed;
855 klass->button_press_event = NULL;
856 klass->button_release_event = NULL;
857 klass->motion_notify_event = NULL;
858 klass->delete_event = NULL;
859 klass->destroy_event = NULL;
860 klass->key_press_event = gtk_widget_real_key_press_event;
861 klass->key_release_event = gtk_widget_real_key_release_event;
862 klass->enter_notify_event = NULL;
863 klass->leave_notify_event = NULL;
864 klass->configure_event = NULL;
865 klass->focus_in_event = gtk_widget_real_focus_in_event;
866 klass->focus_out_event = gtk_widget_real_focus_out_event;
867 klass->map_event = NULL;
868 klass->unmap_event = NULL;
869 klass->window_state_event = NULL;
870 klass->property_notify_event = _gtk_selection_property_notify;
871 klass->selection_clear_event = _gtk_selection_clear;
872 klass->selection_request_event = _gtk_selection_request;
873 klass->selection_notify_event = _gtk_selection_notify;
874 klass->selection_received = NULL;
875 klass->proximity_in_event = NULL;
876 klass->proximity_out_event = NULL;
877 klass->drag_begin = NULL;
878 klass->drag_end = NULL;
879 klass->drag_data_delete = NULL;
880 klass->drag_leave = NULL;
881 klass->drag_motion = NULL;
882 klass->drag_drop = NULL;
883 klass->drag_data_received = NULL;
884 klass->screen_changed = NULL;
885 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
886 klass->grab_broken_event = NULL;
887 klass->query_tooltip = gtk_widget_real_query_tooltip;
888 klass->style_updated = gtk_widget_real_style_updated;
890 klass->show_help = gtk_widget_real_show_help;
892 /* Accessibility support */
893 klass->get_accessible = gtk_widget_real_get_accessible;
895 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
896 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
898 g_object_class_install_property (gobject_class,
900 g_param_spec_string ("name",
902 P_("The name of the widget"),
904 GTK_PARAM_READWRITE));
905 g_object_class_install_property (gobject_class,
907 g_param_spec_object ("parent",
909 P_("The parent widget of this widget. Must be a Container widget"),
911 GTK_PARAM_READWRITE));
913 g_object_class_install_property (gobject_class,
915 g_param_spec_int ("width-request",
917 P_("Override for width request of the widget, or -1 if natural request should be used"),
921 GTK_PARAM_READWRITE));
922 g_object_class_install_property (gobject_class,
924 g_param_spec_int ("height-request",
925 P_("Height request"),
926 P_("Override for height request of the widget, or -1 if natural request should be used"),
930 GTK_PARAM_READWRITE));
931 g_object_class_install_property (gobject_class,
933 g_param_spec_boolean ("visible",
935 P_("Whether the widget is visible"),
937 GTK_PARAM_READWRITE));
938 g_object_class_install_property (gobject_class,
940 g_param_spec_boolean ("sensitive",
942 P_("Whether the widget responds to input"),
944 GTK_PARAM_READWRITE));
945 g_object_class_install_property (gobject_class,
947 g_param_spec_boolean ("app-paintable",
948 P_("Application paintable"),
949 P_("Whether the application will paint directly on the widget"),
951 GTK_PARAM_READWRITE));
952 g_object_class_install_property (gobject_class,
954 g_param_spec_boolean ("can-focus",
956 P_("Whether the widget can accept the input focus"),
958 GTK_PARAM_READWRITE));
959 g_object_class_install_property (gobject_class,
961 g_param_spec_boolean ("has-focus",
963 P_("Whether the widget has the input focus"),
965 GTK_PARAM_READWRITE));
966 g_object_class_install_property (gobject_class,
968 g_param_spec_boolean ("is-focus",
970 P_("Whether the widget is the focus widget within the toplevel"),
972 GTK_PARAM_READWRITE));
973 g_object_class_install_property (gobject_class,
975 g_param_spec_boolean ("can-default",
977 P_("Whether the widget can be the default widget"),
979 GTK_PARAM_READWRITE));
980 g_object_class_install_property (gobject_class,
982 g_param_spec_boolean ("has-default",
984 P_("Whether the widget is the default widget"),
986 GTK_PARAM_READWRITE));
987 g_object_class_install_property (gobject_class,
988 PROP_RECEIVES_DEFAULT,
989 g_param_spec_boolean ("receives-default",
990 P_("Receives default"),
991 P_("If TRUE, the widget will receive the default action when it is focused"),
993 GTK_PARAM_READWRITE));
994 g_object_class_install_property (gobject_class,
995 PROP_COMPOSITE_CHILD,
996 g_param_spec_boolean ("composite-child",
997 P_("Composite child"),
998 P_("Whether the widget is part of a composite widget"),
1000 GTK_PARAM_READABLE));
1001 g_object_class_install_property (gobject_class,
1003 g_param_spec_object ("style",
1005 P_("The style of the widget, which contains information about how it will look (colors etc)"),
1007 GTK_PARAM_READWRITE));
1008 g_object_class_install_property (gobject_class,
1010 g_param_spec_flags ("events",
1012 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1013 GDK_TYPE_EVENT_MASK,
1015 GTK_PARAM_READWRITE));
1016 g_object_class_install_property (gobject_class,
1018 g_param_spec_boolean ("no-show-all",
1020 P_("Whether gtk_widget_show_all() should not affect this widget"),
1022 GTK_PARAM_READWRITE));
1025 * GtkWidget:has-tooltip:
1027 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1028 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1029 * the widget will be queried using #GtkWidget::query-tooltip to determine
1030 * whether it will provide a tooltip or not.
1032 * Note that setting this property to %TRUE for the first time will change
1033 * the event masks of the GdkWindows of this widget to include leave-notify
1034 * and motion-notify events. This cannot and will not be undone when the
1035 * property is set to %FALSE again.
1039 g_object_class_install_property (gobject_class,
1041 g_param_spec_boolean ("has-tooltip",
1043 P_("Whether this widget has a tooltip"),
1045 GTK_PARAM_READWRITE));
1047 * GtkWidget:tooltip-text:
1049 * Sets the text of tooltip to be the given string.
1051 * Also see gtk_tooltip_set_text().
1053 * This is a convenience property which will take care of getting the
1054 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1055 * will automatically be set to %TRUE and there will be taken care of
1056 * #GtkWidget::query-tooltip in the default signal handler.
1060 g_object_class_install_property (gobject_class,
1062 g_param_spec_string ("tooltip-text",
1064 P_("The contents of the tooltip for this widget"),
1066 GTK_PARAM_READWRITE));
1068 * GtkWidget:tooltip-markup:
1070 * Sets the text of tooltip to be the given string, which is marked up
1071 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1072 * Also see gtk_tooltip_set_markup().
1074 * This is a convenience property which will take care of getting the
1075 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1076 * will automatically be set to %TRUE and there will be taken care of
1077 * #GtkWidget::query-tooltip in the default signal handler.
1081 g_object_class_install_property (gobject_class,
1082 PROP_TOOLTIP_MARKUP,
1083 g_param_spec_string ("tooltip-markup",
1084 P_("Tooltip markup"),
1085 P_("The contents of the tooltip for this widget"),
1087 GTK_PARAM_READWRITE));
1092 * The widget's window if it is realized, %NULL otherwise.
1096 g_object_class_install_property (gobject_class,
1098 g_param_spec_object ("window",
1100 P_("The widget's window if it is realized"),
1102 GTK_PARAM_READABLE));
1105 * GtkWidget:double-buffered
1107 * Whether the widget is double buffered.
1111 g_object_class_install_property (gobject_class,
1112 PROP_DOUBLE_BUFFERED,
1113 g_param_spec_boolean ("double-buffered",
1114 P_("Double Buffered"),
1115 P_("Whether the widget is double buffered"),
1117 GTK_PARAM_READWRITE));
1122 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1126 g_object_class_install_property (gobject_class,
1128 g_param_spec_enum ("halign",
1129 P_("Horizontal Alignment"),
1130 P_("How to position in extra horizontal space"),
1133 GTK_PARAM_READWRITE));
1138 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1142 g_object_class_install_property (gobject_class,
1144 g_param_spec_enum ("valign",
1145 P_("Vertical Alignment"),
1146 P_("How to position in extra vertical space"),
1149 GTK_PARAM_READWRITE));
1152 * GtkWidget:margin-left
1154 * Margin on left side of widget.
1156 * This property adds margin outside of the widget's normal size
1157 * request, the margin will be added in addition to the size from
1158 * gtk_widget_set_size_request() for example.
1162 g_object_class_install_property (gobject_class,
1164 g_param_spec_int ("margin-left",
1165 P_("Margin on Left"),
1166 P_("Pixels of extra space on the left side"),
1170 GTK_PARAM_READWRITE));
1173 * GtkWidget:margin-right
1175 * Margin on right side of widget.
1177 * This property adds margin outside of the widget's normal size
1178 * request, the margin will be added in addition to the size from
1179 * gtk_widget_set_size_request() for example.
1183 g_object_class_install_property (gobject_class,
1185 g_param_spec_int ("margin-right",
1186 P_("Margin on Right"),
1187 P_("Pixels of extra space on the right side"),
1191 GTK_PARAM_READWRITE));
1194 * GtkWidget:margin-top
1196 * Margin on top side of widget.
1198 * This property adds margin outside of the widget's normal size
1199 * request, the margin will be added in addition to the size from
1200 * gtk_widget_set_size_request() for example.
1204 g_object_class_install_property (gobject_class,
1206 g_param_spec_int ("margin-top",
1207 P_("Margin on Top"),
1208 P_("Pixels of extra space on the top side"),
1212 GTK_PARAM_READWRITE));
1215 * GtkWidget:margin-bottom
1217 * Margin on bottom side of widget.
1219 * This property adds margin outside of the widget's normal size
1220 * request, the margin will be added in addition to the size from
1221 * gtk_widget_set_size_request() for example.
1225 g_object_class_install_property (gobject_class,
1227 g_param_spec_int ("margin-bottom",
1228 P_("Margin on Bottom"),
1229 P_("Pixels of extra space on the bottom side"),
1233 GTK_PARAM_READWRITE));
1238 * Sets all four sides' margin at once. If read, returns max
1239 * margin on any side.
1243 g_object_class_install_property (gobject_class,
1245 g_param_spec_int ("margin",
1247 P_("Pixels of extra space on all four sides"),
1251 GTK_PARAM_READWRITE));
1254 * GtkWidget::destroy:
1255 * @object: the object which received the signal
1257 * Signals that all holders of a reference to the widget should release
1258 * the reference that they hold. May result in finalization of the widget
1259 * if all references are released.
1261 widget_signals[DESTROY] =
1262 g_signal_new (I_("destroy"),
1263 G_TYPE_FROM_CLASS (gobject_class),
1264 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1265 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1267 _gtk_marshal_VOID__VOID,
1273 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1277 g_object_class_install_property (gobject_class,
1279 g_param_spec_boolean ("hexpand",
1280 P_("Horizontal Expand"),
1281 P_("Whether widget wants more horizontal space"),
1283 GTK_PARAM_READWRITE));
1286 * GtkWidget:hexpand-set
1288 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1292 g_object_class_install_property (gobject_class,
1294 g_param_spec_boolean ("hexpand-set",
1295 P_("Horizontal Expand Set"),
1296 P_("Whether to use the hexpand property"),
1298 GTK_PARAM_READWRITE));
1303 * Whether to expand vertically. See gtk_widget_set_vexpand().
1307 g_object_class_install_property (gobject_class,
1309 g_param_spec_boolean ("vexpand",
1310 P_("Vertical Expand"),
1311 P_("Whether widget wants more vertical space"),
1313 GTK_PARAM_READWRITE));
1316 * GtkWidget:vexpand-set
1318 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1322 g_object_class_install_property (gobject_class,
1324 g_param_spec_boolean ("vexpand-set",
1325 P_("Vertical Expand Set"),
1326 P_("Whether to use the vexpand property"),
1328 GTK_PARAM_READWRITE));
1333 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1337 g_object_class_install_property (gobject_class,
1339 g_param_spec_boolean ("expand",
1341 P_("Whether widget wants to expand in both directions"),
1343 GTK_PARAM_READWRITE));
1347 * @widget: the object which received the signal.
1349 widget_signals[SHOW] =
1350 g_signal_new (I_("show"),
1351 G_TYPE_FROM_CLASS (gobject_class),
1353 G_STRUCT_OFFSET (GtkWidgetClass, show),
1355 _gtk_marshal_VOID__VOID,
1360 * @widget: the object which received the signal.
1362 widget_signals[HIDE] =
1363 g_signal_new (I_("hide"),
1364 G_TYPE_FROM_CLASS (gobject_class),
1366 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1368 _gtk_marshal_VOID__VOID,
1373 * @widget: the object which received the signal.
1375 widget_signals[MAP] =
1376 g_signal_new (I_("map"),
1377 G_TYPE_FROM_CLASS (gobject_class),
1379 G_STRUCT_OFFSET (GtkWidgetClass, map),
1381 _gtk_marshal_VOID__VOID,
1386 * @widget: the object which received the signal.
1388 widget_signals[UNMAP] =
1389 g_signal_new (I_("unmap"),
1390 G_TYPE_FROM_CLASS (gobject_class),
1392 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1394 _gtk_marshal_VOID__VOID,
1398 * GtkWidget::realize:
1399 * @widget: the object which received the signal.
1401 widget_signals[REALIZE] =
1402 g_signal_new (I_("realize"),
1403 G_TYPE_FROM_CLASS (gobject_class),
1405 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1407 _gtk_marshal_VOID__VOID,
1411 * GtkWidget::unrealize:
1412 * @widget: the object which received the signal.
1414 widget_signals[UNREALIZE] =
1415 g_signal_new (I_("unrealize"),
1416 G_TYPE_FROM_CLASS (gobject_class),
1418 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1420 _gtk_marshal_VOID__VOID,
1424 * GtkWidget::size-allocate:
1425 * @widget: the object which received the signal.
1428 widget_signals[SIZE_ALLOCATE] =
1429 g_signal_new (I_("size-allocate"),
1430 G_TYPE_FROM_CLASS (gobject_class),
1432 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1434 _gtk_marshal_VOID__BOXED,
1436 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1439 * GtkWidget::state-changed:
1440 * @widget: the object which received the signal.
1441 * @state: the previous state
1443 * The ::state-changed signal is emitted when the widget state changes.
1444 * See gtk_widget_get_state().
1446 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1448 widget_signals[STATE_CHANGED] =
1449 g_signal_new (I_("state-changed"),
1450 G_TYPE_FROM_CLASS (gobject_class),
1452 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1454 _gtk_marshal_VOID__ENUM,
1456 GTK_TYPE_STATE_TYPE);
1459 * GtkWidget::state-flags-changed:
1460 * @widget: the object which received the signal.
1461 * @flags: The previous state flags.
1463 * The ::state-flags-changed signal is emitted when the widget state
1464 * changes, see gtk_widget_get_state_flags().
1468 widget_signals[STATE_FLAGS_CHANGED] =
1469 g_signal_new (I_("state-flags-changed"),
1470 G_TYPE_FROM_CLASS (gobject_class),
1472 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1474 _gtk_marshal_VOID__FLAGS,
1476 GTK_TYPE_STATE_FLAGS);
1479 * GtkWidget::parent-set:
1480 * @widget: the object on which the signal is emitted
1481 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1482 * just got its initial parent.
1484 * The ::parent-set signal is emitted when a new parent
1485 * has been set on a widget.
1487 widget_signals[PARENT_SET] =
1488 g_signal_new (I_("parent-set"),
1489 G_TYPE_FROM_CLASS (gobject_class),
1491 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1493 _gtk_marshal_VOID__OBJECT,
1498 * GtkWidget::hierarchy-changed:
1499 * @widget: the object on which the signal is emitted
1500 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1501 * if the widget was previously unanchored
1503 * The ::hierarchy-changed signal is emitted when the
1504 * anchored state of a widget changes. A widget is
1505 * <firstterm>anchored</firstterm> when its toplevel
1506 * ancestor is a #GtkWindow. This signal is emitted when
1507 * a widget changes from un-anchored to anchored or vice-versa.
1509 widget_signals[HIERARCHY_CHANGED] =
1510 g_signal_new (I_("hierarchy-changed"),
1511 G_TYPE_FROM_CLASS (gobject_class),
1513 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1515 _gtk_marshal_VOID__OBJECT,
1520 * GtkWidget::style-set:
1521 * @widget: the object on which the signal is emitted
1522 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1523 * just got its initial style
1525 * The ::style-set signal is emitted when a new style has been set
1526 * on a widget. Note that style-modifying functions like
1527 * gtk_widget_modify_base() also cause this signal to be emitted.
1529 * Note that this signal is emitted for changes to the deprecated
1530 * #GtkStyle. To track changes to the #GtkStyleContext associated
1531 * with a widget, use the #GtkWidget::style-updated signal.
1533 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1535 widget_signals[STYLE_SET] =
1536 g_signal_new (I_("style-set"),
1537 G_TYPE_FROM_CLASS (gobject_class),
1539 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1541 _gtk_marshal_VOID__OBJECT,
1546 * GtkWidget::style-updated:
1547 * @widget: the object on which the signal is emitted
1549 * The ::style-updated signal is emitted when the #GtkStyleContext
1550 * of a widget is changed. Note that style-modifying functions like
1551 * gtk_widget_override_color() also cause this signal to be emitted.
1555 widget_signals[STYLE_UPDATED] =
1556 g_signal_new (I_("style-updated"),
1557 G_TYPE_FROM_CLASS (gobject_class),
1559 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1561 g_cclosure_marshal_VOID__VOID,
1565 * GtkWidget::direction-changed:
1566 * @widget: the object on which the signal is emitted
1567 * @previous_direction: the previous text direction of @widget
1569 * The ::direction-changed signal is emitted when the text direction
1570 * of a widget changes.
1572 widget_signals[DIRECTION_CHANGED] =
1573 g_signal_new (I_("direction-changed"),
1574 G_TYPE_FROM_CLASS (gobject_class),
1576 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1578 _gtk_marshal_VOID__ENUM,
1580 GTK_TYPE_TEXT_DIRECTION);
1583 * GtkWidget::grab-notify:
1584 * @widget: the object which received the signal
1585 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1586 * if it becomes unshadowed
1588 * The ::grab-notify signal is emitted when a widget becomes
1589 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1590 * another widget, or when it becomes unshadowed due to a grab
1593 * A widget is shadowed by a gtk_grab_add() when the topmost
1594 * grab widget in the grab stack of its window group is not
1597 widget_signals[GRAB_NOTIFY] =
1598 g_signal_new (I_("grab-notify"),
1599 G_TYPE_FROM_CLASS (gobject_class),
1601 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1603 _gtk_marshal_VOID__BOOLEAN,
1608 * GtkWidget::child-notify:
1609 * @widget: the object which received the signal
1610 * @pspec: the #GParamSpec of the changed child property
1612 * The ::child-notify signal is emitted for each
1613 * <link linkend="child-properties">child property</link> that has
1614 * changed on an object. The signal's detail holds the property name.
1616 widget_signals[CHILD_NOTIFY] =
1617 g_signal_new (I_("child-notify"),
1618 G_TYPE_FROM_CLASS (gobject_class),
1619 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1620 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1622 g_cclosure_marshal_VOID__PARAM,
1628 * @widget: the object which received the signal
1629 * @cr: the cairo context to draw to
1631 * This signal is emitted when a widget is supposed to render itself.
1632 * The @widget's top left corner must be painted at the origin of
1633 * the passed in context and be sized to the values returned by
1634 * gtk_widget_get_allocated_width() and
1635 * gtk_widget_get_allocated_height().
1637 * Signal handlers connected to this signal can modify the cairo
1638 * context passed as @cr in any way they like and don't need to
1639 * restore it. The signal emission takes care of calling cairo_save()
1640 * before and cairo_restore() after invoking the handler.
1642 widget_signals[DRAW] =
1643 g_signal_new (I_("draw"),
1644 G_TYPE_FROM_CLASS (gobject_class),
1646 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1647 _gtk_boolean_handled_accumulator, NULL,
1648 gtk_widget_draw_marshaller,
1650 CAIRO_GOBJECT_TYPE_CONTEXT);
1653 * GtkWidget::mnemonic-activate:
1654 * @widget: the object which received the signal.
1657 widget_signals[MNEMONIC_ACTIVATE] =
1658 g_signal_new (I_("mnemonic-activate"),
1659 G_TYPE_FROM_CLASS (gobject_class),
1661 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1662 _gtk_boolean_handled_accumulator, NULL,
1663 _gtk_marshal_BOOLEAN__BOOLEAN,
1668 * GtkWidget::grab-focus:
1669 * @widget: the object which received the signal.
1671 widget_signals[GRAB_FOCUS] =
1672 g_signal_new (I_("grab-focus"),
1673 G_TYPE_FROM_CLASS (gobject_class),
1674 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1675 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1677 _gtk_marshal_VOID__VOID,
1682 * @widget: the object which received the signal.
1685 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1687 widget_signals[FOCUS] =
1688 g_signal_new (I_("focus"),
1689 G_TYPE_FROM_CLASS (klass),
1691 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1692 _gtk_boolean_handled_accumulator, NULL,
1693 _gtk_marshal_BOOLEAN__ENUM,
1695 GTK_TYPE_DIRECTION_TYPE);
1698 * GtkWidget::move-focus:
1699 * @widget: the object which received the signal.
1702 widget_signals[MOVE_FOCUS] =
1703 g_signal_new (I_("move-focus"),
1704 G_TYPE_FROM_CLASS (klass),
1705 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1706 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1708 _gtk_marshal_VOID__ENUM,
1711 GTK_TYPE_DIRECTION_TYPE);
1714 * GtkWidget::keynav-failed:
1715 * @widget: the object which received the signal
1716 * @direction: the direction of movement
1718 * Gets emitted if keyboard navigation fails.
1719 * See gtk_widget_keynav_failed() for details.
1721 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1722 * if the emitting widget should try to handle the keyboard
1723 * navigation attempt in its parent container(s).
1727 widget_signals[KEYNAV_FAILED] =
1728 g_signal_new (I_("keynav-failed"),
1729 G_TYPE_FROM_CLASS (klass),
1731 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1732 _gtk_boolean_handled_accumulator, NULL,
1733 _gtk_marshal_BOOLEAN__ENUM,
1735 GTK_TYPE_DIRECTION_TYPE);
1739 * @widget: the object which received the signal.
1740 * @event: the #GdkEvent which triggered this signal
1742 * The GTK+ main loop will emit three signals for each GDK event delivered
1743 * to a widget: one generic ::event signal, another, more specific,
1744 * signal that matches the type of event delivered (e.g.
1745 * #GtkWidget::key-press-event) and finally a generic
1746 * #GtkWidget::event-after signal.
1748 * Returns: %TRUE to stop other handlers from being invoked for the event
1749 * and to cancel the emission of the second specific ::event signal.
1750 * %FALSE to propagate the event further and to allow the emission of
1751 * the second signal. The ::event-after signal is emitted regardless of
1754 widget_signals[EVENT] =
1755 g_signal_new (I_("event"),
1756 G_TYPE_FROM_CLASS (klass),
1758 G_STRUCT_OFFSET (GtkWidgetClass, event),
1759 _gtk_boolean_handled_accumulator, NULL,
1760 _gtk_marshal_BOOLEAN__BOXED,
1762 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1765 * GtkWidget::event-after:
1766 * @widget: the object which received the signal.
1767 * @event: the #GdkEvent which triggered this signal
1769 * After the emission of the #GtkWidget::event signal and (optionally)
1770 * the second more specific signal, ::event-after will be emitted
1771 * regardless of the previous two signals handlers return values.
1774 widget_signals[EVENT_AFTER] =
1775 g_signal_new (I_("event-after"),
1776 G_TYPE_FROM_CLASS (klass),
1780 _gtk_marshal_VOID__BOXED,
1782 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1785 * GtkWidget::button-press-event:
1786 * @widget: the object which received the signal.
1787 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1790 * The ::button-press-event signal will be emitted when a button
1791 * (typically from a mouse) is pressed.
1793 * To receive this signal, the #GdkWindow associated to the
1794 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1796 * This signal will be sent to the grab widget if there is one.
1798 * Returns: %TRUE to stop other handlers from being invoked for the event.
1799 * %FALSE to propagate the event further.
1801 widget_signals[BUTTON_PRESS_EVENT] =
1802 g_signal_new (I_("button-press-event"),
1803 G_TYPE_FROM_CLASS (klass),
1805 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1806 _gtk_boolean_handled_accumulator, NULL,
1807 _gtk_marshal_BOOLEAN__BOXED,
1809 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1812 * GtkWidget::button-release-event:
1813 * @widget: the object which received the signal.
1814 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1817 * The ::button-release-event signal will be emitted when a button
1818 * (typically from a mouse) is released.
1820 * To receive this signal, the #GdkWindow associated to the
1821 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1823 * This signal will be sent to the grab widget if there is one.
1825 * Returns: %TRUE to stop other handlers from being invoked for the event.
1826 * %FALSE to propagate the event further.
1828 widget_signals[BUTTON_RELEASE_EVENT] =
1829 g_signal_new (I_("button-release-event"),
1830 G_TYPE_FROM_CLASS (klass),
1832 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1833 _gtk_boolean_handled_accumulator, NULL,
1834 _gtk_marshal_BOOLEAN__BOXED,
1836 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1839 * GtkWidget::scroll-event:
1840 * @widget: the object which received the signal.
1841 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1844 * The ::scroll-event signal is emitted when a button in the 4 to 7
1845 * range is pressed. Wheel mice are usually configured to generate
1846 * button press events for buttons 4 and 5 when the wheel is turned.
1848 * To receive this signal, the #GdkWindow associated to the widget needs
1849 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1851 * This signal will be sent to the grab widget if there is one.
1853 * Returns: %TRUE to stop other handlers from being invoked for the event.
1854 * %FALSE to propagate the event further.
1856 widget_signals[SCROLL_EVENT] =
1857 g_signal_new (I_("scroll-event"),
1858 G_TYPE_FROM_CLASS (klass),
1860 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1861 _gtk_boolean_handled_accumulator, NULL,
1862 _gtk_marshal_BOOLEAN__BOXED,
1864 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1867 * GtkWidget::motion-notify-event:
1868 * @widget: the object which received the signal.
1869 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1872 * The ::motion-notify-event signal is emitted when the pointer moves
1873 * over the widget's #GdkWindow.
1875 * To receive this signal, the #GdkWindow associated to the widget
1876 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1878 * This signal will be sent to the grab widget if there is one.
1880 * Returns: %TRUE to stop other handlers from being invoked for the event.
1881 * %FALSE to propagate the event further.
1883 widget_signals[MOTION_NOTIFY_EVENT] =
1884 g_signal_new (I_("motion-notify-event"),
1885 G_TYPE_FROM_CLASS (klass),
1887 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1888 _gtk_boolean_handled_accumulator, NULL,
1889 _gtk_marshal_BOOLEAN__BOXED,
1891 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1894 * GtkWidget::composited-changed:
1895 * @widget: the object on which the signal is emitted
1897 * The ::composited-changed signal is emitted when the composited
1898 * status of @widget<!-- -->s screen changes.
1899 * See gdk_screen_is_composited().
1901 widget_signals[COMPOSITED_CHANGED] =
1902 g_signal_new (I_("composited-changed"),
1903 G_TYPE_FROM_CLASS (klass),
1904 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1905 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1907 _gtk_marshal_VOID__VOID,
1911 * GtkWidget::delete-event:
1912 * @widget: the object which received the signal
1913 * @event: the event which triggered this signal
1915 * The ::delete-event signal is emitted if a user requests that
1916 * a toplevel window is closed. The default handler for this signal
1917 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1918 * this signal will cause the window to be hidden instead, so that
1919 * it can later be shown again without reconstructing it.
1921 * Returns: %TRUE to stop other handlers from being invoked for the event.
1922 * %FALSE to propagate the event further.
1924 widget_signals[DELETE_EVENT] =
1925 g_signal_new (I_("delete-event"),
1926 G_TYPE_FROM_CLASS (klass),
1928 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1929 _gtk_boolean_handled_accumulator, NULL,
1930 _gtk_marshal_BOOLEAN__BOXED,
1932 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1935 * GtkWidget::destroy-event:
1936 * @widget: the object which received the signal.
1937 * @event: the event which triggered this signal
1939 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1940 * You rarely get this signal, because most widgets disconnect themselves
1941 * from their window before they destroy it, so no widget owns the
1942 * window at destroy time.
1944 * To receive this signal, the #GdkWindow associated to the widget needs
1945 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1946 * automatically for all new windows.
1948 * Returns: %TRUE to stop other handlers from being invoked for the event.
1949 * %FALSE to propagate the event further.
1951 widget_signals[DESTROY_EVENT] =
1952 g_signal_new (I_("destroy-event"),
1953 G_TYPE_FROM_CLASS (klass),
1955 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1956 _gtk_boolean_handled_accumulator, NULL,
1957 _gtk_marshal_BOOLEAN__BOXED,
1959 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1962 * GtkWidget::key-press-event:
1963 * @widget: the object which received the signal
1964 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1966 * The ::key-press-event signal is emitted when a key is pressed.
1968 * To receive this signal, the #GdkWindow associated to the widget needs
1969 * to enable the #GDK_KEY_PRESS_MASK mask.
1971 * This signal will be sent to the grab widget if there is one.
1973 * Returns: %TRUE to stop other handlers from being invoked for the event.
1974 * %FALSE to propagate the event further.
1976 widget_signals[KEY_PRESS_EVENT] =
1977 g_signal_new (I_("key-press-event"),
1978 G_TYPE_FROM_CLASS (klass),
1980 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1981 _gtk_boolean_handled_accumulator, NULL,
1982 _gtk_marshal_BOOLEAN__BOXED,
1984 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1987 * GtkWidget::key-release-event:
1988 * @widget: the object which received the signal
1989 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1991 * The ::key-release-event signal is emitted when a key is pressed.
1993 * To receive this signal, the #GdkWindow associated to the widget needs
1994 * to enable the #GDK_KEY_RELEASE_MASK mask.
1996 * This signal will be sent to the grab widget if there is one.
1998 * Returns: %TRUE to stop other handlers from being invoked for the event.
1999 * %FALSE to propagate the event further.
2001 widget_signals[KEY_RELEASE_EVENT] =
2002 g_signal_new (I_("key-release-event"),
2003 G_TYPE_FROM_CLASS (klass),
2005 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2006 _gtk_boolean_handled_accumulator, NULL,
2007 _gtk_marshal_BOOLEAN__BOXED,
2009 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2012 * GtkWidget::enter-notify-event:
2013 * @widget: the object which received the signal
2014 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2017 * The ::enter-notify-event will be emitted when the pointer enters
2018 * the @widget's window.
2020 * To receive this signal, the #GdkWindow associated to the widget needs
2021 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2023 * This signal will be sent to the grab widget if there is one.
2025 * Returns: %TRUE to stop other handlers from being invoked for the event.
2026 * %FALSE to propagate the event further.
2028 widget_signals[ENTER_NOTIFY_EVENT] =
2029 g_signal_new (I_("enter-notify-event"),
2030 G_TYPE_FROM_CLASS (klass),
2032 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2033 _gtk_boolean_handled_accumulator, NULL,
2034 _gtk_marshal_BOOLEAN__BOXED,
2036 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2039 * GtkWidget::leave-notify-event:
2040 * @widget: the object which received the signal
2041 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2044 * The ::leave-notify-event will be emitted when the pointer leaves
2045 * the @widget's window.
2047 * To receive this signal, the #GdkWindow associated to the widget needs
2048 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2050 * This signal will be sent to the grab widget if there is one.
2052 * Returns: %TRUE to stop other handlers from being invoked for the event.
2053 * %FALSE to propagate the event further.
2055 widget_signals[LEAVE_NOTIFY_EVENT] =
2056 g_signal_new (I_("leave-notify-event"),
2057 G_TYPE_FROM_CLASS (klass),
2059 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2060 _gtk_boolean_handled_accumulator, NULL,
2061 _gtk_marshal_BOOLEAN__BOXED,
2063 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2066 * GtkWidget::configure-event:
2067 * @widget: the object which received the signal
2068 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2071 * The ::configure-event signal will be emitted when the size, position or
2072 * stacking of the @widget's window has changed.
2074 * To receive this signal, the #GdkWindow associated to the widget needs
2075 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2076 * automatically for all new windows.
2078 * Returns: %TRUE to stop other handlers from being invoked for the event.
2079 * %FALSE to propagate the event further.
2081 widget_signals[CONFIGURE_EVENT] =
2082 g_signal_new (I_("configure-event"),
2083 G_TYPE_FROM_CLASS (klass),
2085 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2086 _gtk_boolean_handled_accumulator, NULL,
2087 _gtk_marshal_BOOLEAN__BOXED,
2089 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2092 * GtkWidget::focus-in-event:
2093 * @widget: the object which received the signal
2094 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2097 * The ::focus-in-event signal will be emitted when the keyboard focus
2098 * enters the @widget's window.
2100 * To receive this signal, the #GdkWindow associated to the widget needs
2101 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2103 * Returns: %TRUE to stop other handlers from being invoked for the event.
2104 * %FALSE to propagate the event further.
2106 widget_signals[FOCUS_IN_EVENT] =
2107 g_signal_new (I_("focus-in-event"),
2108 G_TYPE_FROM_CLASS (klass),
2110 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2111 _gtk_boolean_handled_accumulator, NULL,
2112 _gtk_marshal_BOOLEAN__BOXED,
2114 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2117 * GtkWidget::focus-out-event:
2118 * @widget: the object which received the signal
2119 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2122 * The ::focus-out-event signal will be emitted when the keyboard focus
2123 * leaves the @widget's window.
2125 * To receive this signal, the #GdkWindow associated to the widget needs
2126 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2128 * Returns: %TRUE to stop other handlers from being invoked for the event.
2129 * %FALSE to propagate the event further.
2131 widget_signals[FOCUS_OUT_EVENT] =
2132 g_signal_new (I_("focus-out-event"),
2133 G_TYPE_FROM_CLASS (klass),
2135 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2136 _gtk_boolean_handled_accumulator, NULL,
2137 _gtk_marshal_BOOLEAN__BOXED,
2139 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2142 * GtkWidget::map-event:
2143 * @widget: the object which received the signal
2144 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2146 * The ::map-event signal will be emitted when the @widget's window is
2147 * mapped. A window is mapped when it becomes visible on the screen.
2149 * To receive this signal, the #GdkWindow associated to the widget needs
2150 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2151 * automatically for all new windows.
2153 * Returns: %TRUE to stop other handlers from being invoked for the event.
2154 * %FALSE to propagate the event further.
2156 widget_signals[MAP_EVENT] =
2157 g_signal_new (I_("map-event"),
2158 G_TYPE_FROM_CLASS (klass),
2160 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2161 _gtk_boolean_handled_accumulator, NULL,
2162 _gtk_marshal_BOOLEAN__BOXED,
2164 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2167 * GtkWidget::unmap-event:
2168 * @widget: the object which received the signal
2169 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2171 * The ::unmap-event signal will be emitted when the @widget's window is
2172 * unmapped. A window is unmapped when it becomes invisible on the screen.
2174 * To receive this signal, the #GdkWindow associated to the widget needs
2175 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2176 * automatically for all new windows.
2178 * Returns: %TRUE to stop other handlers from being invoked for the event.
2179 * %FALSE to propagate the event further.
2181 widget_signals[UNMAP_EVENT] =
2182 g_signal_new (I_("unmap-event"),
2183 G_TYPE_FROM_CLASS (klass),
2185 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2186 _gtk_boolean_handled_accumulator, NULL,
2187 _gtk_marshal_BOOLEAN__BOXED,
2189 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2192 * GtkWidget::property-notify-event:
2193 * @widget: the object which received the signal
2194 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2197 * The ::property-notify-event signal will be emitted when a property on
2198 * the @widget's window has been changed or deleted.
2200 * To receive this signal, the #GdkWindow associated to the widget needs
2201 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2203 * Returns: %TRUE to stop other handlers from being invoked for the event.
2204 * %FALSE to propagate the event further.
2206 widget_signals[PROPERTY_NOTIFY_EVENT] =
2207 g_signal_new (I_("property-notify-event"),
2208 G_TYPE_FROM_CLASS (klass),
2210 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2211 _gtk_boolean_handled_accumulator, NULL,
2212 _gtk_marshal_BOOLEAN__BOXED,
2214 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2217 * GtkWidget::selection-clear-event:
2218 * @widget: the object which received the signal
2219 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2222 * The ::selection-clear-event signal will be emitted when the
2223 * the @widget's window has lost ownership of a selection.
2225 * Returns: %TRUE to stop other handlers from being invoked for the event.
2226 * %FALSE to propagate the event further.
2228 widget_signals[SELECTION_CLEAR_EVENT] =
2229 g_signal_new (I_("selection-clear-event"),
2230 G_TYPE_FROM_CLASS (klass),
2232 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2233 _gtk_boolean_handled_accumulator, NULL,
2234 _gtk_marshal_BOOLEAN__BOXED,
2236 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2239 * GtkWidget::selection-request-event:
2240 * @widget: the object which received the signal
2241 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2244 * The ::selection-request-event signal will be emitted when
2245 * another client requests ownership of the selection owned by
2246 * the @widget's window.
2248 * Returns: %TRUE to stop other handlers from being invoked for the event.
2249 * %FALSE to propagate the event further.
2251 widget_signals[SELECTION_REQUEST_EVENT] =
2252 g_signal_new (I_("selection-request-event"),
2253 G_TYPE_FROM_CLASS (klass),
2255 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2256 _gtk_boolean_handled_accumulator, NULL,
2257 _gtk_marshal_BOOLEAN__BOXED,
2259 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2262 * GtkWidget::selection-notify-event:
2263 * @widget: the object which received the signal.
2266 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2268 widget_signals[SELECTION_NOTIFY_EVENT] =
2269 g_signal_new (I_("selection-notify-event"),
2270 G_TYPE_FROM_CLASS (klass),
2272 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2273 _gtk_boolean_handled_accumulator, NULL,
2274 _gtk_marshal_BOOLEAN__BOXED,
2276 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2279 * GtkWidget::selection-received:
2280 * @widget: the object which received the signal.
2284 widget_signals[SELECTION_RECEIVED] =
2285 g_signal_new (I_("selection-received"),
2286 G_TYPE_FROM_CLASS (klass),
2288 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2290 _gtk_marshal_VOID__BOXED_UINT,
2292 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2296 * GtkWidget::selection-get:
2297 * @widget: the object which received the signal.
2302 widget_signals[SELECTION_GET] =
2303 g_signal_new (I_("selection-get"),
2304 G_TYPE_FROM_CLASS (klass),
2306 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2308 _gtk_marshal_VOID__BOXED_UINT_UINT,
2310 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2315 * GtkWidget::proximity-in-event:
2316 * @widget: the object which received the signal
2317 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2320 * To receive this signal the #GdkWindow associated to the widget needs
2321 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2323 * This signal will be sent to the grab widget if there is one.
2325 * Returns: %TRUE to stop other handlers from being invoked for the event.
2326 * %FALSE to propagate the event further.
2328 widget_signals[PROXIMITY_IN_EVENT] =
2329 g_signal_new (I_("proximity-in-event"),
2330 G_TYPE_FROM_CLASS (klass),
2332 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2333 _gtk_boolean_handled_accumulator, NULL,
2334 _gtk_marshal_BOOLEAN__BOXED,
2336 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2339 * GtkWidget::proximity-out-event:
2340 * @widget: the object which received the signal
2341 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2344 * To receive this signal the #GdkWindow associated to the widget needs
2345 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2347 * This signal will be sent to the grab widget if there is one.
2349 * Returns: %TRUE to stop other handlers from being invoked for the event.
2350 * %FALSE to propagate the event further.
2352 widget_signals[PROXIMITY_OUT_EVENT] =
2353 g_signal_new (I_("proximity-out-event"),
2354 G_TYPE_FROM_CLASS (klass),
2356 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2357 _gtk_boolean_handled_accumulator, NULL,
2358 _gtk_marshal_BOOLEAN__BOXED,
2360 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2363 * GtkWidget::drag-leave:
2364 * @widget: the object which received the signal.
2365 * @drag_context: the drag context
2366 * @time: the timestamp of the motion event
2368 * The ::drag-leave signal is emitted on the drop site when the cursor
2369 * leaves the widget. A typical reason to connect to this signal is to
2370 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2371 * with gtk_drag_unhighlight()
2373 widget_signals[DRAG_LEAVE] =
2374 g_signal_new (I_("drag-leave"),
2375 G_TYPE_FROM_CLASS (klass),
2377 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2379 _gtk_marshal_VOID__OBJECT_UINT,
2381 GDK_TYPE_DRAG_CONTEXT,
2385 * GtkWidget::drag-begin:
2386 * @widget: the object which received the signal
2387 * @drag_context: the drag context
2389 * The ::drag-begin signal is emitted on the drag source when a drag is
2390 * started. A typical reason to connect to this signal is to set up a
2391 * custom drag icon with gtk_drag_source_set_icon().
2393 * Note that some widgets set up a drag icon in the default handler of
2394 * this signal, so you may have to use g_signal_connect_after() to
2395 * override what the default handler did.
2397 widget_signals[DRAG_BEGIN] =
2398 g_signal_new (I_("drag-begin"),
2399 G_TYPE_FROM_CLASS (klass),
2401 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2403 _gtk_marshal_VOID__OBJECT,
2405 GDK_TYPE_DRAG_CONTEXT);
2408 * GtkWidget::drag-end:
2409 * @widget: the object which received the signal
2410 * @drag_context: the drag context
2412 * The ::drag-end signal is emitted on the drag source when a drag is
2413 * finished. A typical reason to connect to this signal is to undo
2414 * things done in #GtkWidget::drag-begin.
2416 widget_signals[DRAG_END] =
2417 g_signal_new (I_("drag-end"),
2418 G_TYPE_FROM_CLASS (klass),
2420 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2422 _gtk_marshal_VOID__OBJECT,
2424 GDK_TYPE_DRAG_CONTEXT);
2427 * GtkWidget::drag-data-delete:
2428 * @widget: the object which received the signal
2429 * @drag_context: the drag context
2431 * The ::drag-data-delete signal is emitted on the drag source when a drag
2432 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2433 * handler is responsible for deleting the data that has been dropped. What
2434 * "delete" means depends on the context of the drag operation.
2436 widget_signals[DRAG_DATA_DELETE] =
2437 g_signal_new (I_("drag-data-delete"),
2438 G_TYPE_FROM_CLASS (klass),
2440 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2442 _gtk_marshal_VOID__OBJECT,
2444 GDK_TYPE_DRAG_CONTEXT);
2447 * GtkWidget::drag-failed:
2448 * @widget: the object which received the signal
2449 * @drag_context: the drag context
2450 * @result: the result of the drag operation
2452 * The ::drag-failed signal is emitted on the drag source when a drag has
2453 * failed. The signal handler may hook custom code to handle a failed DND
2454 * operation based on the type of error, it returns %TRUE is the failure has
2455 * been already handled (not showing the default "drag operation failed"
2456 * animation), otherwise it returns %FALSE.
2458 * Return value: %TRUE if the failed drag operation has been already handled.
2462 widget_signals[DRAG_FAILED] =
2463 g_signal_new (I_("drag-failed"),
2464 G_TYPE_FROM_CLASS (klass),
2466 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2467 _gtk_boolean_handled_accumulator, NULL,
2468 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2470 GDK_TYPE_DRAG_CONTEXT,
2471 GTK_TYPE_DRAG_RESULT);
2474 * GtkWidget::drag-motion:
2475 * @widget: the object which received the signal
2476 * @drag_context: the drag context
2477 * @x: the x coordinate of the current cursor position
2478 * @y: the y coordinate of the current cursor position
2479 * @time: the timestamp of the motion event
2480 * @returns: whether the cursor position is in a drop zone
2482 * The drag-motion signal is emitted on the drop site when the user
2483 * moves the cursor over the widget during a drag. The signal handler
2484 * must determine whether the cursor position is in a drop zone or not.
2485 * If it is not in a drop zone, it returns %FALSE and no further processing
2486 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2487 * handler is responsible for providing the necessary information for
2488 * displaying feedback to the user, by calling gdk_drag_status().
2490 * If the decision whether the drop will be accepted or rejected can't be
2491 * made based solely on the cursor position and the type of the data, the
2492 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2493 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2494 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2495 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2496 * when using the drag-motion signal that way.
2498 * Also note that there is no drag-enter signal. The drag receiver has to
2499 * keep track of whether he has received any drag-motion signals since the
2500 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2501 * an "enter" signal. Upon an "enter", the handler will typically highlight
2502 * the drop site with gtk_drag_highlight().
2505 * drag_motion (GtkWidget *widget,
2506 * GdkDragContext *context,
2513 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2515 * if (!private_data->drag_highlight)
2517 * private_data->drag_highlight = 1;
2518 * gtk_drag_highlight (widget);
2521 * target = gtk_drag_dest_find_target (widget, context, NULL);
2522 * if (target == GDK_NONE)
2523 * gdk_drag_status (context, 0, time);
2526 * private_data->pending_status = context->suggested_action;
2527 * gtk_drag_get_data (widget, context, target, time);
2534 * drag_data_received (GtkWidget *widget,
2535 * GdkDragContext *context,
2538 * GtkSelectionData *selection_data,
2542 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2544 * if (private_data->suggested_action)
2546 * private_data->suggested_action = 0;
2548 * /* We are getting this data due to a request in drag_motion,
2549 * * rather than due to a request in drag_drop, so we are just
2550 * * supposed to call gdk_drag_status (), not actually paste in
2553 * str = gtk_selection_data_get_text (selection_data);
2554 * if (!data_is_acceptable (str))
2555 * gdk_drag_status (context, 0, time);
2557 * gdk_drag_status (context, private_data->suggested_action, time);
2561 * /* accept the drop */
2566 widget_signals[DRAG_MOTION] =
2567 g_signal_new (I_("drag-motion"),
2568 G_TYPE_FROM_CLASS (klass),
2570 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2571 _gtk_boolean_handled_accumulator, NULL,
2572 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2574 GDK_TYPE_DRAG_CONTEXT,
2580 * GtkWidget::drag-drop:
2581 * @widget: the object which received the signal
2582 * @drag_context: the drag context
2583 * @x: the x coordinate of the current cursor position
2584 * @y: the y coordinate of the current cursor position
2585 * @time: the timestamp of the motion event
2586 * @returns: whether the cursor position is in a drop zone
2588 * The ::drag-drop signal is emitted on the drop site when the user drops
2589 * the data onto the widget. The signal handler must determine whether
2590 * the cursor position is in a drop zone or not. If it is not in a drop
2591 * zone, it returns %FALSE and no further processing is necessary.
2592 * Otherwise, the handler returns %TRUE. In this case, the handler must
2593 * ensure that gtk_drag_finish() is called to let the source know that
2594 * the drop is done. The call to gtk_drag_finish() can be done either
2595 * directly or in a #GtkWidget::drag-data-received handler which gets
2596 * triggered by calling gtk_drag_get_data() to receive the data for one
2597 * or more of the supported targets.
2599 widget_signals[DRAG_DROP] =
2600 g_signal_new (I_("drag-drop"),
2601 G_TYPE_FROM_CLASS (klass),
2603 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2604 _gtk_boolean_handled_accumulator, NULL,
2605 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2607 GDK_TYPE_DRAG_CONTEXT,
2613 * GtkWidget::drag-data-get:
2614 * @widget: the object which received the signal
2615 * @drag_context: the drag context
2616 * @data: the #GtkSelectionData to be filled with the dragged data
2617 * @info: the info that has been registered with the target in the
2619 * @time: the timestamp at which the data was requested
2621 * The ::drag-data-get signal is emitted on the drag source when the drop
2622 * site requests the data which is dragged. It is the responsibility of
2623 * the signal handler to fill @data with the data in the format which
2624 * is indicated by @info. See gtk_selection_data_set() and
2625 * gtk_selection_data_set_text().
2627 widget_signals[DRAG_DATA_GET] =
2628 g_signal_new (I_("drag-data-get"),
2629 G_TYPE_FROM_CLASS (klass),
2631 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2633 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2635 GDK_TYPE_DRAG_CONTEXT,
2636 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2641 * GtkWidget::drag-data-received:
2642 * @widget: the object which received the signal
2643 * @drag_context: the drag context
2644 * @x: where the drop happened
2645 * @y: where the drop happened
2646 * @data: the received data
2647 * @info: the info that has been registered with the target in the
2649 * @time: the timestamp at which the data was received
2651 * The ::drag-data-received signal is emitted on the drop site when the
2652 * dragged data has been received. If the data was received in order to
2653 * determine whether the drop will be accepted, the handler is expected
2654 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2655 * If the data was received in response to a #GtkWidget::drag-drop signal
2656 * (and this is the last target to be received), the handler for this
2657 * signal is expected to process the received data and then call
2658 * gtk_drag_finish(), setting the @success parameter depending on whether
2659 * the data was processed successfully.
2661 * The handler may inspect and modify @drag_context->action before calling
2662 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2663 * following example:
2666 * drag_data_received (GtkWidget *widget,
2667 * GdkDragContext *drag_context,
2670 * GtkSelectionData *data,
2674 * if ((data->length >= 0) && (data->format == 8))
2676 * if (drag_context->action == GDK_ACTION_ASK)
2678 * GtkWidget *dialog;
2681 * dialog = gtk_message_dialog_new (NULL,
2682 * GTK_DIALOG_MODAL |
2683 * GTK_DIALOG_DESTROY_WITH_PARENT,
2685 * GTK_BUTTONS_YES_NO,
2686 * "Move the data ?\n");
2687 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2688 * gtk_widget_destroy (dialog);
2690 * if (response == GTK_RESPONSE_YES)
2691 * drag_context->action = GDK_ACTION_MOVE;
2693 * drag_context->action = GDK_ACTION_COPY;
2696 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2700 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2704 widget_signals[DRAG_DATA_RECEIVED] =
2705 g_signal_new (I_("drag-data-received"),
2706 G_TYPE_FROM_CLASS (klass),
2708 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2710 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2712 GDK_TYPE_DRAG_CONTEXT,
2715 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2720 * GtkWidget::visibility-notify-event:
2721 * @widget: the object which received the signal
2722 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2723 * triggered this signal.
2725 * The ::visibility-notify-event will be emitted when the @widget's window
2726 * is obscured or unobscured.
2728 * To receive this signal the #GdkWindow associated to the widget needs
2729 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2731 * Returns: %TRUE to stop other handlers from being invoked for the event.
2732 * %FALSE to propagate the event further.
2734 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2735 g_signal_new (I_("visibility-notify-event"),
2736 G_TYPE_FROM_CLASS (klass),
2738 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2739 _gtk_boolean_handled_accumulator, NULL,
2740 _gtk_marshal_BOOLEAN__BOXED,
2742 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2745 * GtkWidget::client-event:
2746 * @widget: the object which received the signal
2747 * @event: (type Gdk.EventClient): the #GdkEventClient which triggered
2750 * The ::client-event will be emitted when the @widget's window
2751 * receives a message (via a ClientMessage event) from another
2754 * Returns: %TRUE to stop other handlers from being invoked for
2755 * the event. %FALSE to propagate the event further.
2757 widget_signals[CLIENT_EVENT] =
2758 g_signal_new (I_("client-event"),
2759 G_TYPE_FROM_CLASS (klass),
2761 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2762 _gtk_boolean_handled_accumulator, NULL,
2763 _gtk_marshal_BOOLEAN__BOXED,
2765 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2768 * GtkWidget::window-state-event:
2769 * @widget: the object which received the signal
2770 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2771 * triggered this signal.
2773 * The ::window-state-event will be emitted when the state of the
2774 * toplevel window associated to the @widget changes.
2776 * To receive this signal the #GdkWindow associated to the widget
2777 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2778 * this mask automatically for all new windows.
2780 * Returns: %TRUE to stop other handlers from being invoked for the
2781 * event. %FALSE to propagate the event further.
2783 widget_signals[WINDOW_STATE_EVENT] =
2784 g_signal_new (I_("window-state-event"),
2785 G_TYPE_FROM_CLASS (klass),
2787 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2788 _gtk_boolean_handled_accumulator, NULL,
2789 _gtk_marshal_BOOLEAN__BOXED,
2791 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2794 * GtkWidget::damage-event:
2795 * @widget: the object which received the signal
2796 * @event: the #GdkEventExpose event
2798 * Emitted when a redirected window belonging to @widget gets drawn into.
2799 * The region/area members of the event shows what area of the redirected
2800 * drawable was drawn into.
2802 * Returns: %TRUE to stop other handlers from being invoked for the event.
2803 * %FALSE to propagate the event further.
2807 widget_signals[DAMAGE_EVENT] =
2808 g_signal_new (I_("damage-event"),
2809 G_TYPE_FROM_CLASS (klass),
2811 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2812 _gtk_boolean_handled_accumulator, NULL,
2813 _gtk_marshal_BOOLEAN__BOXED,
2815 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2818 * GtkWidget::grab-broken-event:
2819 * @widget: the object which received the signal
2820 * @event: the #GdkEventGrabBroken event
2822 * Emitted when a pointer or keyboard grab on a window belonging
2823 * to @widget gets broken.
2825 * On X11, this happens when the grab window becomes unviewable
2826 * (i.e. it or one of its ancestors is unmapped), or if the same
2827 * application grabs the pointer or keyboard again.
2829 * Returns: %TRUE to stop other handlers from being invoked for
2830 * the event. %FALSE to propagate the event further.
2834 widget_signals[GRAB_BROKEN_EVENT] =
2835 g_signal_new (I_("grab-broken-event"),
2836 G_TYPE_FROM_CLASS (klass),
2838 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2839 _gtk_boolean_handled_accumulator, NULL,
2840 _gtk_marshal_BOOLEAN__BOXED,
2842 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2845 * GtkWidget::query-tooltip:
2846 * @widget: the object which received the signal
2847 * @x: the x coordinate of the cursor position where the request has
2848 * been emitted, relative to @widget->window
2849 * @y: the y coordinate of the cursor position where the request has
2850 * been emitted, relative to @widget->window
2851 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2852 * @tooltip: a #GtkTooltip
2854 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2855 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2856 * focus in keyboard mode.
2858 * Using the given coordinates, the signal handler should determine
2859 * whether a tooltip should be shown for @widget. If this is the case
2860 * %TRUE should be returned, %FALSE otherwise. Note that if
2861 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2862 * should not be used.
2864 * The signal handler is free to manipulate @tooltip with the therefore
2865 * destined function calls.
2867 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2871 widget_signals[QUERY_TOOLTIP] =
2872 g_signal_new (I_("query-tooltip"),
2873 G_TYPE_FROM_CLASS (klass),
2875 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2876 _gtk_boolean_handled_accumulator, NULL,
2877 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2885 * GtkWidget::popup-menu
2886 * @widget: the object which received the signal
2888 * This signal gets emitted whenever a widget should pop up a context
2889 * menu. This usually happens through the standard key binding mechanism;
2890 * by pressing a certain key while a widget is focused, the user can cause
2891 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2892 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2893 * for an example of how to use this signal.
2895 * Returns: %TRUE if a menu was activated
2897 widget_signals[POPUP_MENU] =
2898 g_signal_new (I_("popup-menu"),
2899 G_TYPE_FROM_CLASS (klass),
2900 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2901 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2902 _gtk_boolean_handled_accumulator, NULL,
2903 _gtk_marshal_BOOLEAN__VOID,
2907 * GtkWidget::show-help:
2908 * @widget: the object which received the signal.
2911 widget_signals[SHOW_HELP] =
2912 g_signal_new (I_("show-help"),
2913 G_TYPE_FROM_CLASS (klass),
2914 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2915 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2916 _gtk_boolean_handled_accumulator, NULL,
2917 _gtk_marshal_BOOLEAN__ENUM,
2919 GTK_TYPE_WIDGET_HELP_TYPE);
2922 * GtkWidget::accel-closures-changed:
2923 * @widget: the object which received the signal.
2925 widget_signals[ACCEL_CLOSURES_CHANGED] =
2926 g_signal_new (I_("accel-closures-changed"),
2927 G_TYPE_FROM_CLASS (klass),
2931 _gtk_marshal_VOID__VOID,
2935 * GtkWidget::screen-changed:
2936 * @widget: the object on which the signal is emitted
2937 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2938 * widget was not associated with a screen before
2940 * The ::screen-changed signal gets emitted when the
2941 * screen of a widget has changed.
2943 widget_signals[SCREEN_CHANGED] =
2944 g_signal_new (I_("screen-changed"),
2945 G_TYPE_FROM_CLASS (klass),
2947 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2949 _gtk_marshal_VOID__OBJECT,
2954 * GtkWidget::can-activate-accel:
2955 * @widget: the object which received the signal
2956 * @signal_id: the ID of a signal installed on @widget
2958 * Determines whether an accelerator that activates the signal
2959 * identified by @signal_id can currently be activated.
2960 * This signal is present to allow applications and derived
2961 * widgets to override the default #GtkWidget handling
2962 * for determining whether an accelerator can be activated.
2964 * Returns: %TRUE if the signal can be activated.
2966 widget_signals[CAN_ACTIVATE_ACCEL] =
2967 g_signal_new (I_("can-activate-accel"),
2968 G_TYPE_FROM_CLASS (klass),
2970 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2971 _gtk_boolean_handled_accumulator, NULL,
2972 _gtk_marshal_BOOLEAN__UINT,
2973 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2975 binding_set = gtk_binding_set_by_class (klass);
2976 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
2978 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
2981 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
2983 GTK_TYPE_WIDGET_HELP_TYPE,
2984 GTK_WIDGET_HELP_TOOLTIP);
2985 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
2987 GTK_TYPE_WIDGET_HELP_TYPE,
2988 GTK_WIDGET_HELP_TOOLTIP);
2989 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
2991 GTK_TYPE_WIDGET_HELP_TYPE,
2992 GTK_WIDGET_HELP_WHATS_THIS);
2993 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
2995 GTK_TYPE_WIDGET_HELP_TYPE,
2996 GTK_WIDGET_HELP_WHATS_THIS);
2998 gtk_widget_class_install_style_property (klass,
2999 g_param_spec_boolean ("interior-focus",
3000 P_("Interior Focus"),
3001 P_("Whether to draw the focus indicator inside widgets"),
3003 GTK_PARAM_READABLE));
3005 gtk_widget_class_install_style_property (klass,
3006 g_param_spec_int ("focus-line-width",
3007 P_("Focus linewidth"),
3008 P_("Width, in pixels, of the focus indicator line"),
3010 GTK_PARAM_READABLE));
3012 gtk_widget_class_install_style_property (klass,
3013 g_param_spec_string ("focus-line-pattern",
3014 P_("Focus line dash pattern"),
3015 P_("Dash pattern used to draw the focus indicator"),
3017 GTK_PARAM_READABLE));
3018 gtk_widget_class_install_style_property (klass,
3019 g_param_spec_int ("focus-padding",
3020 P_("Focus padding"),
3021 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3023 GTK_PARAM_READABLE));
3024 gtk_widget_class_install_style_property (klass,
3025 g_param_spec_boxed ("cursor-color",
3027 P_("Color with which to draw insertion cursor"),
3029 GTK_PARAM_READABLE));
3030 gtk_widget_class_install_style_property (klass,
3031 g_param_spec_boxed ("secondary-cursor-color",
3032 P_("Secondary cursor color"),
3033 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3035 GTK_PARAM_READABLE));
3036 gtk_widget_class_install_style_property (klass,
3037 g_param_spec_float ("cursor-aspect-ratio",
3038 P_("Cursor line aspect ratio"),
3039 P_("Aspect ratio with which to draw insertion cursor"),
3041 GTK_PARAM_READABLE));
3043 gtk_widget_class_install_style_property (klass,
3044 g_param_spec_boolean ("window-dragging",
3045 P_("Window dragging"),
3046 P_("Whether windows can be dragged by clicking on empty areas"),
3048 GTK_PARAM_READABLE));
3051 * GtkWidget:link-color:
3053 * The "link-color" style property defines the color of unvisited links.
3057 gtk_widget_class_install_style_property (klass,
3058 g_param_spec_boxed ("link-color",
3059 P_("Unvisited Link Color"),
3060 P_("Color of unvisited links"),
3062 GTK_PARAM_READABLE));
3065 * GtkWidget:visited-link-color:
3067 * The "visited-link-color" style property defines the color of visited links.
3071 gtk_widget_class_install_style_property (klass,
3072 g_param_spec_boxed ("visited-link-color",
3073 P_("Visited Link Color"),
3074 P_("Color of visited links"),
3076 GTK_PARAM_READABLE));
3079 * GtkWidget:wide-separators:
3081 * The "wide-separators" style property defines whether separators have
3082 * configurable width and should be drawn using a box instead of a line.
3086 gtk_widget_class_install_style_property (klass,
3087 g_param_spec_boolean ("wide-separators",
3088 P_("Wide Separators"),
3089 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3091 GTK_PARAM_READABLE));
3094 * GtkWidget:separator-width:
3096 * The "separator-width" style property defines the width of separators.
3097 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3101 gtk_widget_class_install_style_property (klass,
3102 g_param_spec_int ("separator-width",
3103 P_("Separator Width"),
3104 P_("The width of separators if wide-separators is TRUE"),
3106 GTK_PARAM_READABLE));
3109 * GtkWidget:separator-height:
3111 * The "separator-height" style property defines the height of separators.
3112 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3116 gtk_widget_class_install_style_property (klass,
3117 g_param_spec_int ("separator-height",
3118 P_("Separator Height"),
3119 P_("The height of separators if \"wide-separators\" is TRUE"),
3121 GTK_PARAM_READABLE));
3124 * GtkWidget:scroll-arrow-hlength:
3126 * The "scroll-arrow-hlength" style property defines the length of
3127 * horizontal scroll arrows.
3131 gtk_widget_class_install_style_property (klass,
3132 g_param_spec_int ("scroll-arrow-hlength",
3133 P_("Horizontal Scroll Arrow Length"),
3134 P_("The length of horizontal scroll arrows"),
3136 GTK_PARAM_READABLE));
3139 * GtkWidget:scroll-arrow-vlength:
3141 * The "scroll-arrow-vlength" style property defines the length of
3142 * vertical scroll arrows.
3146 gtk_widget_class_install_style_property (klass,
3147 g_param_spec_int ("scroll-arrow-vlength",
3148 P_("Vertical Scroll Arrow Length"),
3149 P_("The length of vertical scroll arrows"),
3151 GTK_PARAM_READABLE));
3153 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3157 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3161 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3162 for (node = list; node; node = node->next)
3164 GParamSpec *pspec = node->data;
3166 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3167 g_param_spec_unref (pspec);
3173 gtk_widget_set_property (GObject *object,
3175 const GValue *value,
3178 GtkWidget *widget = GTK_WIDGET (object);
3183 gchar *tooltip_markup;
3184 const gchar *tooltip_text;
3185 GtkWindow *tooltip_window;
3188 gtk_widget_set_name (widget, g_value_get_string (value));
3191 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3193 case PROP_WIDTH_REQUEST:
3194 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3196 case PROP_HEIGHT_REQUEST:
3197 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3200 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3202 case PROP_SENSITIVE:
3203 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3205 case PROP_APP_PAINTABLE:
3206 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3208 case PROP_CAN_FOCUS:
3209 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3211 case PROP_HAS_FOCUS:
3212 if (g_value_get_boolean (value))
3213 gtk_widget_grab_focus (widget);
3216 if (g_value_get_boolean (value))
3217 gtk_widget_grab_focus (widget);
3219 case PROP_CAN_DEFAULT:
3220 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3222 case PROP_HAS_DEFAULT:
3223 if (g_value_get_boolean (value))
3224 gtk_widget_grab_default (widget);
3226 case PROP_RECEIVES_DEFAULT:
3227 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3230 gtk_widget_set_style (widget, g_value_get_object (value));
3233 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3234 gtk_widget_set_events (widget, g_value_get_flags (value));
3236 case PROP_NO_SHOW_ALL:
3237 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3239 case PROP_HAS_TOOLTIP:
3240 gtk_widget_real_set_has_tooltip (widget,
3241 g_value_get_boolean (value), FALSE);
3243 case PROP_TOOLTIP_MARKUP:
3244 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3245 tooltip_markup = g_value_dup_string (value);
3247 /* Treat an empty string as a NULL string,
3248 * because an empty string would be useless for a tooltip:
3250 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3252 g_free (tooltip_markup);
3253 tooltip_markup = NULL;
3256 g_object_set_qdata_full (object, quark_tooltip_markup,
3257 tooltip_markup, g_free);
3259 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3260 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3261 if (gtk_widget_get_visible (widget))
3262 gtk_widget_queue_tooltip_query (widget);
3264 case PROP_TOOLTIP_TEXT:
3265 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3267 tooltip_text = g_value_get_string (value);
3269 /* Treat an empty string as a NULL string,
3270 * because an empty string would be useless for a tooltip:
3272 if (tooltip_text && (strlen (tooltip_text) == 0))
3273 tooltip_text = NULL;
3275 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3277 g_object_set_qdata_full (object, quark_tooltip_markup,
3278 tooltip_markup, g_free);
3280 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3281 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3282 if (gtk_widget_get_visible (widget))
3283 gtk_widget_queue_tooltip_query (widget);
3285 case PROP_DOUBLE_BUFFERED:
3286 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3289 gtk_widget_set_halign (widget, g_value_get_enum (value));
3292 gtk_widget_set_valign (widget, g_value_get_enum (value));
3294 case PROP_MARGIN_LEFT:
3295 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3297 case PROP_MARGIN_RIGHT:
3298 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3300 case PROP_MARGIN_TOP:
3301 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3303 case PROP_MARGIN_BOTTOM:
3304 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3307 g_object_freeze_notify (G_OBJECT (widget));
3308 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3309 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3310 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3311 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3312 g_object_thaw_notify (G_OBJECT (widget));
3315 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3317 case PROP_HEXPAND_SET:
3318 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3321 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3323 case PROP_VEXPAND_SET:
3324 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3327 g_object_freeze_notify (G_OBJECT (widget));
3328 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3329 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3330 g_object_thaw_notify (G_OBJECT (widget));
3333 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3339 gtk_widget_get_property (GObject *object,
3344 GtkWidget *widget = GTK_WIDGET (object);
3345 GtkWidgetPrivate *priv = widget->priv;
3353 g_value_set_string (value, priv->name);
3355 g_value_set_static_string (value, "");
3358 g_value_set_object (value, priv->parent);
3360 case PROP_WIDTH_REQUEST:
3363 gtk_widget_get_size_request (widget, &w, NULL);
3364 g_value_set_int (value, w);
3367 case PROP_HEIGHT_REQUEST:
3370 gtk_widget_get_size_request (widget, NULL, &h);
3371 g_value_set_int (value, h);
3375 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3377 case PROP_SENSITIVE:
3378 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3380 case PROP_APP_PAINTABLE:
3381 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3383 case PROP_CAN_FOCUS:
3384 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3386 case PROP_HAS_FOCUS:
3387 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3390 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3392 case PROP_CAN_DEFAULT:
3393 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3395 case PROP_HAS_DEFAULT:
3396 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3398 case PROP_RECEIVES_DEFAULT:
3399 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3401 case PROP_COMPOSITE_CHILD:
3402 g_value_set_boolean (value, widget->priv->composite_child);
3405 g_value_set_object (value, gtk_widget_get_style (widget));
3408 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3409 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3411 case PROP_NO_SHOW_ALL:
3412 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3414 case PROP_HAS_TOOLTIP:
3415 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3417 case PROP_TOOLTIP_TEXT:
3419 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3422 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3423 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3425 g_value_take_string (value, text);
3428 case PROP_TOOLTIP_MARKUP:
3429 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3432 g_value_set_object (value, gtk_widget_get_window (widget));
3434 case PROP_DOUBLE_BUFFERED:
3435 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3438 g_value_set_enum (value, gtk_widget_get_halign (widget));
3441 g_value_set_enum (value, gtk_widget_get_valign (widget));
3443 case PROP_MARGIN_LEFT:
3444 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3446 case PROP_MARGIN_RIGHT:
3447 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3449 case PROP_MARGIN_TOP:
3450 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3452 case PROP_MARGIN_BOTTOM:
3453 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3457 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3458 if (aux_info == NULL)
3460 g_value_set_int (value, 0);
3464 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3465 aux_info->margin.right),
3466 MAX (aux_info->margin.top,
3467 aux_info->margin.bottom)));
3472 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3474 case PROP_HEXPAND_SET:
3475 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3478 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3480 case PROP_VEXPAND_SET:
3481 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3484 g_value_set_boolean (value,
3485 gtk_widget_get_hexpand (widget) &&
3486 gtk_widget_get_vexpand (widget));
3489 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3495 gtk_widget_init (GtkWidget *widget)
3497 GtkWidgetPrivate *priv;
3499 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3502 priv = widget->priv;
3504 priv->child_visible = TRUE;
3506 priv->allocation.x = -1;
3507 priv->allocation.y = -1;
3508 priv->allocation.width = 1;
3509 priv->allocation.height = 1;
3510 priv->window = NULL;
3511 priv->parent = NULL;
3513 priv->sensitive = TRUE;
3514 priv->parent_sensitive = TRUE;
3515 priv->composite_child = composite_child_stack != 0;
3516 priv->double_buffered = TRUE;
3517 priv->redraw_on_alloc = TRUE;
3518 priv->width_request_needed = TRUE;
3519 priv->height_request_needed = TRUE;
3520 priv->alloc_needed = TRUE;
3522 /* this will be set to TRUE if the widget gets a child or if the
3523 * expand flag is set on the widget, but until one of those happen
3524 * we know the expand is already properly FALSE.
3526 * We really want to default FALSE here to avoid computing expand
3527 * all over the place while initially building a widget tree.
3529 priv->need_compute_expand = FALSE;
3531 priv->style = gtk_widget_get_default_style ();
3532 g_object_ref (priv->style);
3537 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3539 GParamSpec **pspecs)
3541 GtkWidgetPrivate *priv = widget->priv;
3542 GtkWidget *container = priv->parent;
3545 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3546 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3550 * gtk_widget_freeze_child_notify:
3551 * @widget: a #GtkWidget
3553 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3554 * signals are queued until gtk_widget_thaw_child_notify() is called
3557 * This is the analogue of g_object_freeze_notify() for child properties.
3560 gtk_widget_freeze_child_notify (GtkWidget *widget)
3562 g_return_if_fail (GTK_IS_WIDGET (widget));
3564 if (!G_OBJECT (widget)->ref_count)
3567 g_object_ref (widget);
3568 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3569 g_object_unref (widget);
3573 * gtk_widget_child_notify:
3574 * @widget: a #GtkWidget
3575 * @child_property: the name of a child property installed on the
3576 * class of @widget<!-- -->'s parent
3578 * Emits a #GtkWidget::child-notify signal for the
3579 * <link linkend="child-properties">child property</link> @child_property
3582 * This is the analogue of g_object_notify() for child properties.
3585 gtk_widget_child_notify (GtkWidget *widget,
3586 const gchar *child_property)
3588 GtkWidgetPrivate *priv = widget->priv;
3591 g_return_if_fail (GTK_IS_WIDGET (widget));
3592 g_return_if_fail (child_property != NULL);
3593 if (!G_OBJECT (widget)->ref_count || !priv->parent)
3596 g_object_ref (widget);
3597 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3599 G_OBJECT_TYPE (priv->parent),
3602 g_warning ("%s: container class `%s' has no child property named `%s'",
3604 G_OBJECT_TYPE_NAME (priv->parent),
3608 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3610 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3611 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3613 g_object_unref (widget);
3617 * gtk_widget_thaw_child_notify:
3618 * @widget: a #GtkWidget
3620 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3621 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3625 gtk_widget_thaw_child_notify (GtkWidget *widget)
3627 GObjectNotifyQueue *nqueue;
3629 g_return_if_fail (GTK_IS_WIDGET (widget));
3631 if (!G_OBJECT (widget)->ref_count)
3634 g_object_ref (widget);
3635 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3636 if (!nqueue || !nqueue->freeze_count)
3637 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3638 G_OBJECT_TYPE_NAME (widget), widget);
3640 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3641 g_object_unref (widget);
3647 * @type: type ID of the widget to create
3648 * @first_property_name: name of first property to set
3649 * @Varargs: value of first property, followed by more properties,
3652 * This is a convenience function for creating a widget and setting
3653 * its properties in one go. For example you might write:
3654 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3655 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3656 * g_object_new(), but returns a widget so you don't have to
3657 * cast the object yourself.
3659 * Return value: a new #GtkWidget of type @widget_type
3662 gtk_widget_new (GType type,
3663 const gchar *first_property_name,
3669 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3671 va_start (var_args, first_property_name);
3672 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3679 gtk_widget_queue_draw_child (GtkWidget *widget)
3681 GtkWidgetPrivate *priv = widget->priv;
3684 parent = priv->parent;
3685 if (parent && gtk_widget_is_drawable (parent))
3686 gtk_widget_queue_draw_area (parent,
3689 priv->allocation.width,
3690 priv->allocation.height);
3694 * gtk_widget_unparent:
3695 * @widget: a #GtkWidget
3697 * This function is only for use in widget implementations.
3698 * Should be called by implementations of the remove method
3699 * on #GtkContainer, to dissociate a child from the container.
3702 gtk_widget_unparent (GtkWidget *widget)
3704 GtkWidgetPrivate *priv;
3705 GObjectNotifyQueue *nqueue;
3706 GtkWidget *toplevel;
3707 GtkWidget *old_parent;
3709 g_return_if_fail (GTK_IS_WIDGET (widget));
3711 priv = widget->priv;
3713 if (priv->parent == NULL)
3716 /* keep this function in sync with gtk_menu_detach() */
3718 gtk_widget_push_verify_invariants (widget);
3720 g_object_freeze_notify (G_OBJECT (widget));
3721 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3723 toplevel = gtk_widget_get_toplevel (widget);
3724 if (gtk_widget_is_toplevel (toplevel))
3725 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3727 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3728 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3730 gtk_widget_queue_draw_child (widget);
3732 /* Reset the width and height here, to force reallocation if we
3733 * get added back to a new parent. This won't work if our new
3734 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3735 * (would 0x0 be OK here?)
3737 priv->allocation.width = 1;
3738 priv->allocation.height = 1;
3740 if (gtk_widget_get_realized (widget))
3742 if (priv->in_reparent)
3743 gtk_widget_unmap (widget);
3745 gtk_widget_unrealize (widget);
3748 /* If we are unanchoring the child, we save around the toplevel
3749 * to emit hierarchy changed
3751 if (priv->parent->priv->anchored)
3752 g_object_ref (toplevel);
3756 /* Removing a widget from a container restores the child visible
3757 * flag to the default state, so it doesn't affect the child
3758 * in the next parent.
3760 priv->child_visible = TRUE;
3762 old_parent = priv->parent;
3763 priv->parent = NULL;
3765 /* parent may no longer expand if the removed
3766 * child was expand=TRUE and could therefore
3769 if (gtk_widget_get_visible (widget) &&
3770 (priv->need_compute_expand ||
3771 priv->computed_hexpand ||
3772 priv->computed_vexpand))
3774 gtk_widget_queue_compute_expand (old_parent);
3777 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3780 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3781 g_object_unref (toplevel);
3784 /* Now that the parent pointer is nullified and the hierarchy-changed
3785 * already passed, go ahead and unset the parent window, if we are unparenting
3786 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
3787 * will fire again for the new subhierarchy.
3789 gtk_widget_set_parent_window (widget, NULL);
3791 g_object_notify (G_OBJECT (widget), "parent");
3792 g_object_thaw_notify (G_OBJECT (widget));
3794 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3795 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3797 gtk_widget_pop_verify_invariants (widget);
3798 g_object_unref (widget);
3802 * gtk_widget_destroy:
3803 * @widget: a #GtkWidget
3805 * Destroys a widget.
3808 * destroyed, it will break any references it holds to other objects.
3809 * If the widget is inside a container, the widget will be removed
3810 * from the container. If the widget is a toplevel (derived from
3811 * #GtkWindow), it will be removed from the list of toplevels, and the
3812 * reference GTK+ holds to it will be removed. Removing a
3813 * widget from its container or the list of toplevels results in the
3814 * widget being finalized, unless you've added additional references
3815 * to the widget with g_object_ref().
3817 * In most cases, only toplevel widgets (windows) require explicit
3818 * destruction, because when you destroy a toplevel its children will
3819 * be destroyed as well.
3822 gtk_widget_destroy (GtkWidget *widget)
3824 g_return_if_fail (GTK_IS_WIDGET (widget));
3826 if (!widget->priv->in_destruction)
3827 g_object_run_dispose (G_OBJECT (widget));
3831 * gtk_widget_destroyed:
3832 * @widget: a #GtkWidget
3833 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3835 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3836 * %NULL. It's intended to be used as a callback connected to the
3837 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3838 * as a signal handler, and pass the address of your widget variable
3839 * as user data. Then when the widget is destroyed, the variable will
3840 * be set to %NULL. Useful for example to avoid multiple copies
3841 * of the same dialog.
3844 gtk_widget_destroyed (GtkWidget *widget,
3845 GtkWidget **widget_pointer)
3847 /* Don't make any assumptions about the
3849 * Even check widget_pointer.
3852 *widget_pointer = NULL;
3857 * @widget: a #GtkWidget
3859 * Flags a widget to be displayed. Any widget that isn't shown will
3860 * not appear on the screen. If you want to show all the widgets in a
3861 * container, it's easier to call gtk_widget_show_all() on the
3862 * container, instead of individually showing the widgets.
3864 * Remember that you have to show the containers containing a widget,
3865 * in addition to the widget itself, before it will appear onscreen.
3867 * When a toplevel container is shown, it is immediately realized and
3868 * mapped; other shown widgets are realized and mapped when their
3869 * toplevel container is realized and mapped.
3872 gtk_widget_show (GtkWidget *widget)
3874 g_return_if_fail (GTK_IS_WIDGET (widget));
3876 if (!gtk_widget_get_visible (widget))
3878 g_object_ref (widget);
3879 gtk_widget_push_verify_invariants (widget);
3881 if (!gtk_widget_is_toplevel (widget))
3882 gtk_widget_queue_resize (widget);
3884 /* see comment in set_parent() for why this should and can be
3887 if (widget->priv->need_compute_expand ||
3888 widget->priv->computed_hexpand ||
3889 widget->priv->computed_vexpand)
3891 if (widget->priv->parent != NULL)
3892 gtk_widget_queue_compute_expand (widget->priv->parent);
3895 g_signal_emit (widget, widget_signals[SHOW], 0);
3896 g_object_notify (G_OBJECT (widget), "visible");
3898 gtk_widget_pop_verify_invariants (widget);
3899 g_object_unref (widget);
3904 gtk_widget_real_show (GtkWidget *widget)
3906 GtkWidgetPrivate *priv = widget->priv;
3908 if (!gtk_widget_get_visible (widget))
3910 priv->visible = TRUE;
3913 gtk_widget_get_mapped (priv->parent) &&
3914 gtk_widget_get_child_visible (widget) &&
3915 !gtk_widget_get_mapped (widget))
3916 gtk_widget_map (widget);
3921 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3924 g_signal_handlers_disconnect_by_func (widget,
3925 gtk_widget_show_map_callback,
3930 * gtk_widget_show_now:
3931 * @widget: a #GtkWidget
3933 * Shows a widget. If the widget is an unmapped toplevel widget
3934 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3935 * loop and wait for the window to actually be mapped. Be careful;
3936 * because the main loop is running, anything can happen during
3940 gtk_widget_show_now (GtkWidget *widget)
3944 g_return_if_fail (GTK_IS_WIDGET (widget));
3946 /* make sure we will get event */
3947 if (!gtk_widget_get_mapped (widget) &&
3948 gtk_widget_is_toplevel (widget))
3950 gtk_widget_show (widget);
3952 g_signal_connect (widget, "map-event",
3953 G_CALLBACK (gtk_widget_show_map_callback),
3957 gtk_main_iteration ();
3960 gtk_widget_show (widget);
3965 * @widget: a #GtkWidget
3967 * Reverses the effects of gtk_widget_show(), causing the widget to be
3968 * hidden (invisible to the user).
3971 gtk_widget_hide (GtkWidget *widget)
3973 g_return_if_fail (GTK_IS_WIDGET (widget));
3975 if (gtk_widget_get_visible (widget))
3977 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3979 g_object_ref (widget);
3980 gtk_widget_push_verify_invariants (widget);
3982 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3983 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3985 /* a parent may now be expand=FALSE since we're hidden. */
3986 if (widget->priv->need_compute_expand ||
3987 widget->priv->computed_hexpand ||
3988 widget->priv->computed_vexpand)
3990 gtk_widget_queue_compute_expand (widget);
3993 g_signal_emit (widget, widget_signals[HIDE], 0);
3994 if (!gtk_widget_is_toplevel (widget))
3995 gtk_widget_queue_resize (widget);
3996 g_object_notify (G_OBJECT (widget), "visible");
3998 gtk_widget_pop_verify_invariants (widget);
3999 g_object_unref (widget);
4004 gtk_widget_real_hide (GtkWidget *widget)
4006 if (gtk_widget_get_visible (widget))
4008 widget->priv->visible = FALSE;
4010 if (gtk_widget_get_mapped (widget))
4011 gtk_widget_unmap (widget);
4016 * gtk_widget_hide_on_delete:
4017 * @widget: a #GtkWidget
4019 * Utility function; intended to be connected to the #GtkWidget::delete-event
4020 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4021 * argument, then returns %TRUE. If connected to ::delete-event, the
4022 * result is that clicking the close button for a window (on the
4023 * window frame, top right corner usually) will hide but not destroy
4024 * the window. By default, GTK+ destroys windows when ::delete-event
4027 * Return value: %TRUE
4030 gtk_widget_hide_on_delete (GtkWidget *widget)
4032 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4034 gtk_widget_hide (widget);
4040 * gtk_widget_show_all:
4041 * @widget: a #GtkWidget
4043 * Recursively shows a widget, and any child widgets (if the widget is
4047 gtk_widget_show_all (GtkWidget *widget)
4049 GtkWidgetClass *class;
4051 g_return_if_fail (GTK_IS_WIDGET (widget));
4053 if (gtk_widget_get_no_show_all (widget))
4056 class = GTK_WIDGET_GET_CLASS (widget);
4058 if (class->show_all)
4059 class->show_all (widget);
4063 _gtk_widget_notify_state_change (GtkWidget *widget,
4071 case GTK_STATE_FLAG_ACTIVE:
4072 state = GTK_STATE_ACTIVE;
4074 case GTK_STATE_FLAG_PRELIGHT:
4075 state = GTK_STATE_PRELIGHT;
4077 case GTK_STATE_FLAG_SELECTED:
4078 state = GTK_STATE_SELECTED;
4080 case GTK_STATE_FLAG_INSENSITIVE:
4081 state = GTK_STATE_INSENSITIVE;
4083 case GTK_STATE_FLAG_INCONSISTENT:
4084 state = GTK_STATE_INCONSISTENT;
4086 case GTK_STATE_FLAG_FOCUSED:
4087 state = GTK_STATE_FOCUSED;
4093 gtk_style_context_notify_state_change (widget->priv->context,
4094 gtk_widget_get_window (widget),
4095 NULL, state, target);
4098 /* Initializes state transitions for those states that
4099 * were enabled before mapping and have a looping animation.
4102 _gtk_widget_start_state_transitions (GtkWidget *widget)
4104 GtkStateFlags state, flag;
4106 if (!widget->priv->context)
4109 state = gtk_widget_get_state_flags (widget);
4110 flag = GTK_STATE_FLAG_FOCUSED;
4114 GtkAnimationDescription *animation_desc;
4116 if ((state & flag) == 0)
4122 gtk_style_context_get (widget->priv->context, state,
4123 "transition", &animation_desc,
4128 if (_gtk_animation_description_get_loop (animation_desc))
4129 _gtk_widget_notify_state_change (widget, flag, TRUE);
4131 _gtk_animation_description_unref (animation_desc);
4140 * @widget: a #GtkWidget
4142 * This function is only for use in widget implementations. Causes
4143 * a widget to be mapped if it isn't already.
4146 gtk_widget_map (GtkWidget *widget)
4148 GtkWidgetPrivate *priv;
4150 g_return_if_fail (GTK_IS_WIDGET (widget));
4151 g_return_if_fail (gtk_widget_get_visible (widget));
4152 g_return_if_fail (gtk_widget_get_child_visible (widget));
4154 priv = widget->priv;
4156 if (!gtk_widget_get_mapped (widget))
4158 gtk_widget_push_verify_invariants (widget);
4160 if (!gtk_widget_get_realized (widget))
4161 gtk_widget_realize (widget);
4163 g_signal_emit (widget, widget_signals[MAP], 0);
4165 if (!gtk_widget_get_has_window (widget))
4166 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4168 gtk_widget_pop_verify_invariants (widget);
4170 _gtk_widget_start_state_transitions (widget);
4176 * @widget: a #GtkWidget
4178 * This function is only for use in widget implementations. Causes
4179 * a widget to be unmapped if it's currently mapped.
4182 gtk_widget_unmap (GtkWidget *widget)
4184 GtkWidgetPrivate *priv;
4186 g_return_if_fail (GTK_IS_WIDGET (widget));
4188 priv = widget->priv;
4190 if (gtk_widget_get_mapped (widget))
4192 gtk_widget_push_verify_invariants (widget);
4194 if (!gtk_widget_get_has_window (widget))
4195 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4196 _gtk_tooltip_hide (widget);
4197 g_signal_emit (widget, widget_signals[UNMAP], 0);
4199 gtk_widget_pop_verify_invariants (widget);
4202 gtk_style_context_cancel_animations (priv->context, NULL);
4207 _gtk_widget_enable_device_events (GtkWidget *widget)
4209 GHashTable *device_events;
4210 GHashTableIter iter;
4211 gpointer key, value;
4213 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4218 g_hash_table_iter_init (&iter, device_events);
4220 while (g_hash_table_iter_next (&iter, &key, &value))
4223 GdkEventMask event_mask;
4226 event_mask = GPOINTER_TO_UINT (value);
4227 gtk_widget_add_events_internal (widget, device, event_mask);
4232 get_widget_windows (GtkWidget *widget)
4234 GList *window_list, *last, *l, *children, *ret;
4236 if (gtk_widget_get_has_window (widget))
4237 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4239 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4241 last = g_list_last (window_list);
4244 for (l = window_list; l; l = l->next)
4246 GtkWidget *window_widget = NULL;
4248 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4250 if (widget != window_widget)
4253 ret = g_list_prepend (ret, l->data);
4254 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4258 last = g_list_concat (last, children);
4259 last = g_list_last (last);
4263 g_list_free (window_list);
4269 device_enable_foreach (GtkWidget *widget,
4272 GdkDevice *device = user_data;
4273 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4277 device_disable_foreach (GtkWidget *widget,
4280 GdkDevice *device = user_data;
4281 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4285 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4290 GList *window_list, *l;
4292 window_list = get_widget_windows (widget);
4294 for (l = window_list; l; l = l->next)
4296 GdkEventMask events = 0;
4302 events = gdk_window_get_events (window);
4304 gdk_window_set_device_events (window, device, events);
4307 if (recurse && GTK_IS_CONTAINER (widget))
4310 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4312 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4315 g_list_free (window_list);
4319 gtk_widget_update_devices_mask (GtkWidget *widget,
4322 GList *enabled_devices, *l;
4324 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4326 for (l = enabled_devices; l; l = l->next)
4327 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4331 * gtk_widget_realize:
4332 * @widget: a #GtkWidget
4334 * Creates the GDK (windowing system) resources associated with a
4335 * widget. For example, @widget->window will be created when a widget
4336 * is realized. Normally realization happens implicitly; if you show
4337 * a widget and all its parent containers, then the widget will be
4338 * realized and mapped automatically.
4340 * Realizing a widget requires all
4341 * the widget's parent widgets to be realized; calling
4342 * gtk_widget_realize() realizes the widget's parents in addition to
4343 * @widget itself. If a widget is not yet inside a toplevel window
4344 * when you realize it, bad things will happen.
4346 * This function is primarily used in widget implementations, and
4347 * isn't very useful otherwise. Many times when you think you might
4348 * need it, a better approach is to connect to a signal that will be
4349 * called after the widget is realized automatically, such as
4350 * #GtkWidget::expose-event. Or simply g_signal_connect () to the
4351 * #GtkWidget::realize signal.
4354 gtk_widget_realize (GtkWidget *widget)
4356 GtkWidgetPrivate *priv;
4357 cairo_region_t *region;
4359 g_return_if_fail (GTK_IS_WIDGET (widget));
4360 g_return_if_fail (widget->priv->anchored ||
4361 GTK_IS_INVISIBLE (widget));
4363 priv = widget->priv;
4365 if (!gtk_widget_get_realized (widget))
4367 gtk_widget_push_verify_invariants (widget);
4370 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4371 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4374 if (priv->parent == NULL &&
4375 !gtk_widget_is_toplevel (widget))
4376 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4377 "inside a toplevel window is not going to work very well. "
4378 "Widgets must be inside a toplevel container before realizing them.");
4380 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4381 gtk_widget_realize (priv->parent);
4383 gtk_widget_ensure_style (widget);
4385 if (priv->style_update_pending)
4386 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4388 g_signal_emit (widget, widget_signals[REALIZE], 0);
4390 gtk_widget_real_set_has_tooltip (widget,
4391 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4394 if (priv->has_shape_mask)
4396 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4397 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4400 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4402 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4404 if (priv->multidevice)
4405 gdk_window_set_support_multidevice (priv->window, TRUE);
4407 _gtk_widget_enable_device_events (widget);
4408 gtk_widget_update_devices_mask (widget, TRUE);
4410 gtk_widget_pop_verify_invariants (widget);
4415 * gtk_widget_unrealize:
4416 * @widget: a #GtkWidget
4418 * This function is only useful in widget implementations.
4419 * Causes a widget to be unrealized (frees all GDK resources
4420 * associated with the widget, such as @widget->window).
4423 gtk_widget_unrealize (GtkWidget *widget)
4425 g_return_if_fail (GTK_IS_WIDGET (widget));
4427 gtk_widget_push_verify_invariants (widget);
4429 if (widget->priv->has_shape_mask)
4430 gtk_widget_shape_combine_region (widget, NULL);
4432 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4433 gtk_widget_input_shape_combine_region (widget, NULL);
4435 if (gtk_widget_get_realized (widget))
4437 g_object_ref (widget);
4439 if (widget->priv->mapped)
4440 gtk_widget_unmap (widget);
4442 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4443 g_assert (!widget->priv->mapped);
4444 gtk_widget_set_realized (widget, FALSE);
4446 g_object_unref (widget);
4449 gtk_widget_pop_verify_invariants (widget);
4452 /*****************************************
4454 *****************************************/
4457 * gtk_widget_queue_draw_region:
4458 * @widget: a #GtkWidget
4459 * @region: region to draw
4461 * Invalidates the rectangular area of @widget defined by @region by
4462 * calling gdk_window_invalidate_region() on the widget's window and
4463 * all its child windows. Once the main loop becomes idle (after the
4464 * current batch of events has been processed, roughly), the window
4465 * will receive expose events for the union of all regions that have
4468 * Normally you would only use this function in widget
4469 * implementations. You might also use it to schedule a redraw of a
4470 * #GtkDrawingArea or some portion thereof.
4473 gtk_widget_queue_draw_region (GtkWidget *widget,
4474 cairo_region_t *region)
4476 GtkWidgetPrivate *priv;
4479 g_return_if_fail (GTK_IS_WIDGET (widget));
4481 priv = widget->priv;
4483 if (!gtk_widget_get_realized (widget))
4486 /* Just return if the widget or one of its ancestors isn't mapped */
4487 for (w = widget; w != NULL; w = w->priv->parent)
4488 if (!gtk_widget_get_mapped (w))
4491 gdk_window_invalidate_region (priv->window, region, TRUE);
4495 * gtk_widget_queue_draw_area:
4496 * @widget: a #GtkWidget
4497 * @x: x coordinate of upper-left corner of rectangle to redraw
4498 * @y: y coordinate of upper-left corner of rectangle to redraw
4499 * @width: width of region to draw
4500 * @height: height of region to draw
4502 * Convenience function that calls gtk_widget_queue_draw_region() on
4503 * the region created from the given coordinates.
4506 gtk_widget_queue_draw_area (GtkWidget *widget,
4513 cairo_region_t *region;
4515 g_return_if_fail (GTK_IS_WIDGET (widget));
4520 rect.height = height;
4522 region = cairo_region_create_rectangle (&rect);
4523 gtk_widget_queue_draw_region (widget, region);
4524 cairo_region_destroy (region);
4528 * gtk_widget_queue_draw:
4529 * @widget: a #GtkWidget
4531 * Equivalent to calling gtk_widget_queue_draw_area() for the
4532 * entire area of a widget.
4535 gtk_widget_queue_draw (GtkWidget *widget)
4539 g_return_if_fail (GTK_IS_WIDGET (widget));
4541 gtk_widget_get_allocation (widget, &rect);
4543 if (!gtk_widget_get_has_window (widget))
4544 gtk_widget_queue_draw_area (widget,
4545 rect.x, rect.y, rect.width, rect.height);
4547 gtk_widget_queue_draw_area (widget,
4548 0, 0, rect.width, rect.height);
4552 * gtk_widget_queue_resize:
4553 * @widget: a #GtkWidget
4555 * This function is only for use in widget implementations.
4556 * Flags a widget to have its size renegotiated; should
4557 * be called when a widget for some reason has a new size request.
4558 * For example, when you change the text in a #GtkLabel, #GtkLabel
4559 * queues a resize to ensure there's enough space for the new text.
4561 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4562 * from inside it's implementation of the GtkWidgetClass::size_allocate
4563 * virtual method. Calls to gtk_widget_queue_resize() from inside
4564 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4567 gtk_widget_queue_resize (GtkWidget *widget)
4569 g_return_if_fail (GTK_IS_WIDGET (widget));
4571 if (gtk_widget_get_realized (widget))
4572 gtk_widget_queue_shallow_draw (widget);
4574 _gtk_size_group_queue_resize (widget, 0);
4578 * gtk_widget_queue_resize_no_redraw:
4579 * @widget: a #GtkWidget
4581 * This function works like gtk_widget_queue_resize(),
4582 * except that the widget is not invalidated.
4587 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4589 g_return_if_fail (GTK_IS_WIDGET (widget));
4591 _gtk_size_group_queue_resize (widget, 0);
4595 * gtk_widget_size_request:
4596 * @widget: a #GtkWidget
4597 * @requisition: (out): a #GtkRequisition to be filled in
4599 * This function is typically used when implementing a #GtkContainer
4600 * subclass. Obtains the preferred size of a widget. The container
4601 * uses this information to arrange its child widgets and decide what
4602 * size allocations to give them with gtk_widget_size_allocate().
4604 * You can also call this function from an application, with some
4605 * caveats. Most notably, getting a size request requires the widget
4606 * to be associated with a screen, because font information may be
4607 * needed. Multihead-aware applications should keep this in mind.
4609 * Also remember that the size request is not necessarily the size
4610 * a widget will actually be allocated.
4612 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4615 gtk_widget_size_request (GtkWidget *widget,
4616 GtkRequisition *requisition)
4618 g_return_if_fail (GTK_IS_WIDGET (widget));
4620 gtk_widget_get_preferred_size (widget, requisition, NULL);
4624 * gtk_widget_get_child_requisition:
4625 * @widget: a #GtkWidget
4626 * @requisition: (out): a #GtkRequisition to be filled in
4628 * This function is only for use in widget implementations. Obtains
4629 * @widget->requisition, unless someone has forced a particular
4630 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4631 * in which case it returns that geometry instead of the widget's
4634 * This function differs from gtk_widget_size_request() in that
4635 * it retrieves the last size request value from @widget->requisition,
4636 * while gtk_widget_size_request() actually calls the "size_request" method
4637 * on @widget to compute the size request and fill in @widget->requisition,
4638 * and only then returns @widget->requisition.
4640 * Because this function does not call the "size_request" method, it
4641 * can only be used when you know that @widget->requisition is
4642 * up-to-date, that is, gtk_widget_size_request() has been called
4643 * since the last time a resize was queued. In general, only container
4644 * implementations have this information; applications should use
4645 * gtk_widget_size_request().
4648 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4651 gtk_widget_get_child_requisition (GtkWidget *widget,
4652 GtkRequisition *requisition)
4654 gtk_widget_get_preferred_size (widget, requisition, NULL);
4658 invalidate_predicate (GdkWindow *window,
4663 gdk_window_get_user_data (window, &user_data);
4665 return (user_data == data);
4668 /* Invalidate @region in widget->window and all children
4669 * of widget->window owned by widget. @region is in the
4670 * same coordinates as widget->allocation and will be
4671 * modified by this call.
4674 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4675 cairo_region_t *region)
4677 GtkWidgetPrivate *priv = widget->priv;
4679 if (!gtk_widget_get_realized (widget))
4682 if (gtk_widget_get_has_window (widget) && priv->parent)
4686 gdk_window_get_position (priv->window, &x, &y);
4687 cairo_region_translate (region, -x, -y);
4690 gdk_window_invalidate_maybe_recurse (priv->window, region,
4691 invalidate_predicate, widget);
4695 * gtk_widget_queue_shallow_draw:
4696 * @widget: a #GtkWidget
4698 * Like gtk_widget_queue_draw(), but only windows owned
4699 * by @widget are invalidated.
4702 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4705 cairo_region_t *region;
4707 if (!gtk_widget_get_realized (widget))
4710 gtk_widget_get_allocation (widget, &rect);
4712 region = cairo_region_create_rectangle (&rect);
4713 gtk_widget_invalidate_widget_windows (widget, region);
4714 cairo_region_destroy (region);
4718 * gtk_widget_size_allocate:
4719 * @widget: a #GtkWidget
4720 * @allocation: (inout): position and size to be allocated to @widget
4722 * This function is only used by #GtkContainer subclasses, to assign a size
4723 * and position to their child widgets.
4725 * In this function, the allocation may be adjusted. It will be forced
4726 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4727 * method on the child will be used to adjust the allocation. Standard
4728 * adjustments include removing the widget's margins, and applying the
4729 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4732 gtk_widget_size_allocate (GtkWidget *widget,
4733 GtkAllocation *allocation)
4735 GtkWidgetPrivate *priv;
4736 GdkRectangle real_allocation;
4737 GdkRectangle old_allocation;
4738 GdkRectangle adjusted_allocation;
4739 gboolean alloc_needed;
4740 gboolean size_changed;
4741 gboolean position_changed;
4742 gint natural_width, natural_height, dummy;
4743 gint min_width, min_height;
4745 priv = widget->priv;
4747 g_return_if_fail (GTK_IS_WIDGET (widget));
4749 gtk_widget_push_verify_invariants (widget);
4751 #ifdef G_ENABLE_DEBUG
4752 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4763 parent = gtk_widget_get_parent (parent);
4766 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4767 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4768 2 * depth, " ", name,
4769 allocation->width, allocation->height);
4771 #endif /* G_ENABLE_DEBUG */
4773 alloc_needed = priv->alloc_needed;
4774 if (!priv->width_request_needed && !priv->height_request_needed)
4775 /* Preserve request/allocate ordering */
4776 priv->alloc_needed = FALSE;
4778 old_allocation = priv->allocation;
4779 real_allocation = *allocation;
4781 adjusted_allocation = real_allocation;
4782 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4784 /* Go ahead and request the height for allocated width, note that the internals
4785 * of get_height_for_width will internally limit the for_size to natural size
4786 * when aligning implicitly.
4788 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4789 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &dummy, &natural_height);
4793 /* Go ahead and request the width for allocated height, note that the internals
4794 * of get_width_for_height will internally limit the for_size to natural size
4795 * when aligning implicitly.
4797 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4798 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &dummy, &natural_width);
4801 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4802 * allocated sizes and possibly limit them to the natural sizes */
4803 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4804 GTK_ORIENTATION_HORIZONTAL,
4807 &adjusted_allocation.x,
4808 &adjusted_allocation.width);
4809 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4810 GTK_ORIENTATION_VERTICAL,
4813 &adjusted_allocation.y,
4814 &adjusted_allocation.height);
4816 if (adjusted_allocation.x < real_allocation.x ||
4817 adjusted_allocation.y < real_allocation.y ||
4818 (adjusted_allocation.x + adjusted_allocation.width) >
4819 (real_allocation.x + real_allocation.width) ||
4820 (adjusted_allocation.y + adjusted_allocation.height >
4821 real_allocation.y + real_allocation.height))
4823 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",
4824 G_OBJECT_TYPE_NAME (widget), widget,
4825 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4826 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4827 adjusted_allocation = real_allocation; /* veto it */
4831 real_allocation = adjusted_allocation;
4834 if (real_allocation.width < 0 || real_allocation.height < 0)
4836 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4837 real_allocation.width,
4838 real_allocation.height);
4841 real_allocation.width = MAX (real_allocation.width, 1);
4842 real_allocation.height = MAX (real_allocation.height, 1);
4844 size_changed = (old_allocation.width != real_allocation.width ||
4845 old_allocation.height != real_allocation.height);
4846 position_changed = (old_allocation.x != real_allocation.x ||
4847 old_allocation.y != real_allocation.y);
4849 if (!alloc_needed && !size_changed && !position_changed)
4852 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4854 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4855 priv->width_request_needed = FALSE;
4856 priv->height_request_needed = FALSE;
4857 priv->alloc_needed = FALSE;
4859 if (gtk_widget_get_mapped (widget))
4861 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4863 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4865 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4866 cairo_region_union_rectangle (invalidate, &old_allocation);
4868 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4869 cairo_region_destroy (invalidate);
4874 if (priv->redraw_on_alloc)
4876 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4878 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4879 cairo_region_union_rectangle (invalidate, &old_allocation);
4881 gtk_widget_invalidate_widget_windows (widget, invalidate);
4882 cairo_region_destroy (invalidate);
4886 if (size_changed || position_changed)
4888 GtkStyleContext *context;
4890 context = gtk_widget_get_style_context (widget);
4891 _gtk_style_context_invalidate_animation_areas (context);
4895 if ((size_changed || position_changed) && priv->parent &&
4896 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4898 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4899 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4900 cairo_region_destroy (invalidate);
4904 gtk_widget_pop_verify_invariants (widget);
4908 * gtk_widget_common_ancestor:
4909 * @widget_a: a #GtkWidget
4910 * @widget_b: a #GtkWidget
4912 * Find the common ancestor of @widget_a and @widget_b that
4913 * is closest to the two widgets.
4915 * Return value: the closest common ancestor of @widget_a and
4916 * @widget_b or %NULL if @widget_a and @widget_b do not
4917 * share a common ancestor.
4920 gtk_widget_common_ancestor (GtkWidget *widget_a,
4921 GtkWidget *widget_b)
4923 GtkWidget *parent_a;
4924 GtkWidget *parent_b;
4928 parent_a = widget_a;
4929 while (parent_a->priv->parent)
4931 parent_a = parent_a->priv->parent;
4935 parent_b = widget_b;
4936 while (parent_b->priv->parent)
4938 parent_b = parent_b->priv->parent;
4942 if (parent_a != parent_b)
4945 while (depth_a > depth_b)
4947 widget_a = widget_a->priv->parent;
4951 while (depth_b > depth_a)
4953 widget_b = widget_b->priv->parent;
4957 while (widget_a != widget_b)
4959 widget_a = widget_a->priv->parent;
4960 widget_b = widget_b->priv->parent;
4967 * gtk_widget_translate_coordinates:
4968 * @src_widget: a #GtkWidget
4969 * @dest_widget: a #GtkWidget
4970 * @src_x: X position relative to @src_widget
4971 * @src_y: Y position relative to @src_widget
4972 * @dest_x: (out): location to store X position relative to @dest_widget
4973 * @dest_y: (out): location to store Y position relative to @dest_widget
4975 * Translate coordinates relative to @src_widget's allocation to coordinates
4976 * relative to @dest_widget's allocations. In order to perform this
4977 * operation, both widgets must be realized, and must share a common
4980 * Return value: %FALSE if either widget was not realized, or there
4981 * was no common ancestor. In this case, nothing is stored in
4982 * *@dest_x and *@dest_y. Otherwise %TRUE.
4985 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4986 GtkWidget *dest_widget,
4992 GtkWidgetPrivate *src_priv = src_widget->priv;
4993 GtkWidgetPrivate *dest_priv = dest_widget->priv;
4994 GtkWidget *ancestor;
4996 GList *dest_list = NULL;
4998 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4999 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5001 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5002 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5005 /* Translate from allocation relative to window relative */
5006 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5009 gdk_window_get_position (src_priv->window, &wx, &wy);
5011 src_x -= wx - src_priv->allocation.x;
5012 src_y -= wy - src_priv->allocation.y;
5016 src_x += src_priv->allocation.x;
5017 src_y += src_priv->allocation.y;
5020 /* Translate to the common ancestor */
5021 window = src_priv->window;
5022 while (window != ancestor->priv->window)
5026 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5031 window = gdk_window_get_effective_parent (window);
5033 if (!window) /* Handle GtkHandleBox */
5038 window = dest_priv->window;
5039 while (window != ancestor->priv->window)
5041 dest_list = g_list_prepend (dest_list, window);
5043 window = gdk_window_get_effective_parent (window);
5045 if (!window) /* Handle GtkHandleBox */
5047 g_list_free (dest_list);
5056 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5061 dest_list = g_list_remove (dest_list, dest_list->data);
5064 /* Translate from window relative to allocation relative */
5065 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5068 gdk_window_get_position (dest_priv->window, &wx, &wy);
5070 src_x += wx - dest_priv->allocation.x;
5071 src_y += wy - dest_priv->allocation.y;
5075 src_x -= dest_priv->allocation.x;
5076 src_y -= dest_priv->allocation.y;
5088 gtk_widget_real_size_allocate (GtkWidget *widget,
5089 GtkAllocation *allocation)
5091 GtkWidgetPrivate *priv = widget->priv;
5093 priv->allocation = *allocation;
5095 if (gtk_widget_get_realized (widget) &&
5096 gtk_widget_get_has_window (widget))
5098 gdk_window_move_resize (priv->window,
5099 allocation->x, allocation->y,
5100 allocation->width, allocation->height);
5105 adjust_for_align(GtkAlign align,
5107 gint *allocated_pos,
5108 gint *allocated_size)
5112 case GTK_ALIGN_FILL:
5113 /* change nothing */
5115 case GTK_ALIGN_START:
5116 /* keep *allocated_pos where it is */
5117 *allocated_size = MIN (*allocated_size, *natural_size);
5120 if (*allocated_size > *natural_size)
5122 *allocated_pos += (*allocated_size - *natural_size);
5123 *allocated_size = *natural_size;
5126 case GTK_ALIGN_CENTER:
5127 if (*allocated_size > *natural_size)
5129 *allocated_pos += (*allocated_size - *natural_size) / 2;
5130 *allocated_size = MIN (*allocated_size, *natural_size);
5137 adjust_for_margin(gint start_margin,
5141 gint *allocated_pos,
5142 gint *allocated_size)
5144 *minimum_size -= (start_margin + end_margin);
5145 *natural_size -= (start_margin + end_margin);
5146 *allocated_pos += start_margin;
5147 *allocated_size -= (start_margin + end_margin);
5151 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5152 GtkOrientation orientation,
5155 gint *allocated_pos,
5156 gint *allocated_size)
5158 const GtkWidgetAuxInfo *aux_info;
5160 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5162 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5164 adjust_for_margin (aux_info->margin.left,
5165 aux_info->margin.right,
5166 minimum_size, natural_size,
5167 allocated_pos, allocated_size);
5168 adjust_for_align (aux_info->halign,
5169 natural_size, allocated_pos, allocated_size);
5173 adjust_for_margin (aux_info->margin.top,
5174 aux_info->margin.bottom,
5175 minimum_size, natural_size,
5176 allocated_pos, allocated_size);
5177 adjust_for_align (aux_info->valign,
5178 natural_size, allocated_pos, allocated_size);
5183 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5186 GtkWidgetPrivate *priv = widget->priv;
5188 /* widgets must be onscreen for accels to take effect */
5189 return gtk_widget_is_sensitive (widget) &&
5190 gtk_widget_is_drawable (widget) &&
5191 gdk_window_is_viewable (priv->window);
5195 * gtk_widget_can_activate_accel:
5196 * @widget: a #GtkWidget
5197 * @signal_id: the ID of a signal installed on @widget
5199 * Determines whether an accelerator that activates the signal
5200 * identified by @signal_id can currently be activated.
5201 * This is done by emitting the #GtkWidget::can-activate-accel
5202 * signal on @widget; if the signal isn't overridden by a
5203 * handler or in a derived widget, then the default check is
5204 * that the widget must be sensitive, and the widget and all
5205 * its ancestors mapped.
5207 * Return value: %TRUE if the accelerator can be activated.
5212 gtk_widget_can_activate_accel (GtkWidget *widget,
5215 gboolean can_activate = FALSE;
5216 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5217 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5218 return can_activate;
5227 closure_accel_activate (GClosure *closure,
5228 GValue *return_value,
5229 guint n_param_values,
5230 const GValue *param_values,
5231 gpointer invocation_hint,
5232 gpointer marshal_data)
5234 AccelClosure *aclosure = (AccelClosure*) closure;
5235 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5238 g_signal_emit (closure->data, aclosure->signal_id, 0);
5240 /* whether accelerator was handled */
5241 g_value_set_boolean (return_value, can_activate);
5245 closures_destroy (gpointer data)
5247 GSList *slist, *closures = data;
5249 for (slist = closures; slist; slist = slist->next)
5251 g_closure_invalidate (slist->data);
5252 g_closure_unref (slist->data);
5254 g_slist_free (closures);
5258 widget_new_accel_closure (GtkWidget *widget,
5261 AccelClosure *aclosure;
5262 GClosure *closure = NULL;
5263 GSList *slist, *closures;
5265 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5266 for (slist = closures; slist; slist = slist->next)
5267 if (!gtk_accel_group_from_accel_closure (slist->data))
5269 /* reuse this closure */
5270 closure = slist->data;
5275 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5276 closures = g_slist_prepend (closures, g_closure_ref (closure));
5277 g_closure_sink (closure);
5278 g_closure_set_marshal (closure, closure_accel_activate);
5280 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5282 aclosure = (AccelClosure*) closure;
5283 g_assert (closure->data == widget);
5284 g_assert (closure->marshal == closure_accel_activate);
5285 aclosure->signal_id = signal_id;
5291 * gtk_widget_add_accelerator
5292 * @widget: widget to install an accelerator on
5293 * @accel_signal: widget signal to emit on accelerator activation
5294 * @accel_group: accel group for this widget, added to its toplevel
5295 * @accel_key: GDK keyval of the accelerator
5296 * @accel_mods: modifier key combination of the accelerator
5297 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5299 * Installs an accelerator for this @widget in @accel_group that causes
5300 * @accel_signal to be emitted if the accelerator is activated.
5301 * The @accel_group needs to be added to the widget's toplevel via
5302 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5303 * Accelerators added through this function are not user changeable during
5304 * runtime. If you want to support accelerators that can be changed by the
5305 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5306 * gtk_menu_item_set_accel_path() instead.
5309 gtk_widget_add_accelerator (GtkWidget *widget,
5310 const gchar *accel_signal,
5311 GtkAccelGroup *accel_group,
5313 GdkModifierType accel_mods,
5314 GtkAccelFlags accel_flags)
5319 g_return_if_fail (GTK_IS_WIDGET (widget));
5320 g_return_if_fail (accel_signal != NULL);
5321 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5323 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5324 if (!query.signal_id ||
5325 !(query.signal_flags & G_SIGNAL_ACTION) ||
5326 query.return_type != G_TYPE_NONE ||
5329 /* hmm, should be elaborate enough */
5330 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5331 G_OBJECT_TYPE_NAME (widget), accel_signal);
5335 closure = widget_new_accel_closure (widget, query.signal_id);
5337 g_object_ref (widget);
5339 /* install the accelerator. since we don't map this onto an accel_path,
5340 * the accelerator will automatically be locked.
5342 gtk_accel_group_connect (accel_group,
5345 accel_flags | GTK_ACCEL_LOCKED,
5348 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5350 g_object_unref (widget);
5354 * gtk_widget_remove_accelerator:
5355 * @widget: widget to install an accelerator on
5356 * @accel_group: accel group for this widget
5357 * @accel_key: GDK keyval of the accelerator
5358 * @accel_mods: modifier key combination of the accelerator
5359 * @returns: whether an accelerator was installed and could be removed
5361 * Removes an accelerator from @widget, previously installed with
5362 * gtk_widget_add_accelerator().
5365 gtk_widget_remove_accelerator (GtkWidget *widget,
5366 GtkAccelGroup *accel_group,
5368 GdkModifierType accel_mods)
5370 GtkAccelGroupEntry *ag_entry;
5371 GList *slist, *clist;
5374 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5375 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5377 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5378 clist = gtk_widget_list_accel_closures (widget);
5379 for (slist = clist; slist; slist = slist->next)
5383 for (i = 0; i < n; i++)
5384 if (slist->data == (gpointer) ag_entry[i].closure)
5386 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5388 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5390 g_list_free (clist);
5395 g_list_free (clist);
5397 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5398 accel_key, accel_mods, accel_group,
5399 G_OBJECT_TYPE_NAME (widget), widget);
5405 * gtk_widget_list_accel_closures:
5406 * @widget: widget to list accelerator closures for
5408 * Lists the closures used by @widget for accelerator group connections
5409 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5410 * The closures can be used to monitor accelerator changes on @widget,
5411 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5412 * #GtkAccelGroup of a closure which can be found out with
5413 * gtk_accel_group_from_accel_closure().
5415 * Return value: (transfer container) (element-type GClosure):
5416 * a newly allocated #GList of closures
5419 gtk_widget_list_accel_closures (GtkWidget *widget)
5422 GList *clist = NULL;
5424 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5426 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5427 if (gtk_accel_group_from_accel_closure (slist->data))
5428 clist = g_list_prepend (clist, slist->data);
5434 GtkAccelGroup *accel_group;
5439 destroy_accel_path (gpointer data)
5441 AccelPath *apath = data;
5443 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5445 /* closures_destroy takes care of unrefing the closure */
5446 g_object_unref (apath->accel_group);
5448 g_slice_free (AccelPath, apath);
5453 * gtk_widget_set_accel_path:
5454 * @widget: a #GtkWidget
5455 * @accel_path: (allow-none): path used to look up the accelerator
5456 * @accel_group: (allow-none): a #GtkAccelGroup.
5458 * Given an accelerator group, @accel_group, and an accelerator path,
5459 * @accel_path, sets up an accelerator in @accel_group so whenever the
5460 * key binding that is defined for @accel_path is pressed, @widget
5461 * will be activated. This removes any accelerators (for any
5462 * accelerator group) installed by previous calls to
5463 * gtk_widget_set_accel_path(). Associating accelerators with
5464 * paths allows them to be modified by the user and the modifications
5465 * to be saved for future use. (See gtk_accel_map_save().)
5467 * This function is a low level function that would most likely
5468 * be used by a menu creation system like #GtkUIManager. If you
5469 * use #GtkUIManager, setting up accelerator paths will be done
5472 * Even when you you aren't using #GtkUIManager, if you only want to
5473 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5474 * provides a somewhat more convenient interface.
5476 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5477 * pass a static string, you can save some memory by interning it first with
5478 * g_intern_static_string().
5481 gtk_widget_set_accel_path (GtkWidget *widget,
5482 const gchar *accel_path,
5483 GtkAccelGroup *accel_group)
5487 g_return_if_fail (GTK_IS_WIDGET (widget));
5488 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5492 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5493 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5495 gtk_accel_map_add_entry (accel_path, 0, 0);
5496 apath = g_slice_new (AccelPath);
5497 apath->accel_group = g_object_ref (accel_group);
5498 apath->path_quark = g_quark_from_string (accel_path);
5499 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5504 /* also removes possible old settings */
5505 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5508 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5510 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5514 _gtk_widget_get_accel_path (GtkWidget *widget,
5519 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5521 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5523 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5524 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5528 * gtk_widget_mnemonic_activate:
5529 * @widget: a #GtkWidget
5530 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5532 * Emits the #GtkWidget::mnemonic-activate signal.
5534 * The default handler for this signal activates the @widget if
5535 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5538 * Returns: %TRUE if the signal has been handled
5541 gtk_widget_mnemonic_activate (GtkWidget *widget,
5542 gboolean group_cycling)
5546 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5548 group_cycling = group_cycling != FALSE;
5549 if (!gtk_widget_is_sensitive (widget))
5552 g_signal_emit (widget,
5553 widget_signals[MNEMONIC_ACTIVATE],
5561 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5562 gboolean group_cycling)
5564 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5565 gtk_widget_activate (widget);
5566 else if (gtk_widget_get_can_focus (widget))
5567 gtk_widget_grab_focus (widget);
5570 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5571 G_OBJECT_TYPE_NAME (widget));
5572 gtk_widget_error_bell (widget);
5577 static const cairo_user_data_key_t event_key;
5580 _gtk_cairo_get_event (cairo_t *cr)
5582 g_return_val_if_fail (cr != NULL, NULL);
5584 return cairo_get_user_data (cr, &event_key);
5588 gtk_cairo_set_event (cairo_t *cr,
5589 GdkEventExpose *event)
5591 cairo_set_user_data (cr, &event_key, event, NULL);
5595 * gtk_cairo_should_draw_window:
5596 * @cr: a cairo context
5597 * @window: the window to check
5599 * This function is supposed to be called in #GtkWidget::draw
5600 * implementations for widgets that support multiple windows.
5601 * @cr must be untransformed from invoking of the draw function.
5602 * This function will return %TRUE if the contents of the given
5603 * @window are supposed to be drawn and %FALSE otherwise. Note
5604 * that when the drawing was not initiated by the windowing
5605 * system this function will return %TRUE for all windows, so
5606 * you need to draw the bottommost window first. Also, do not
5607 * use "else if" statements to check which window should be drawn.
5609 * Returns: %TRUE if @window should be drawn
5612 gtk_cairo_should_draw_window (cairo_t *cr,
5615 GdkEventExpose *event;
5617 g_return_val_if_fail (cr != NULL, FALSE);
5618 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5620 event = _gtk_cairo_get_event (cr);
5622 return event == NULL ||
5623 event->window == window;
5626 /* code shared by gtk_container_propagate_draw() and
5630 _gtk_widget_draw_internal (GtkWidget *widget,
5632 gboolean clip_to_size)
5634 GtkStyleContext *context;
5636 if (!gtk_widget_is_drawable (widget))
5641 cairo_rectangle (cr,
5643 widget->priv->allocation.width,
5644 widget->priv->allocation.height);
5648 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5652 g_signal_emit (widget, widget_signals[DRAW],
5657 context = gtk_widget_get_style_context (widget);
5658 _gtk_style_context_coalesce_animation_areas (context, widget);
5663 * @widget: the widget to draw. It must be drawable (see
5664 * gtk_widget_is_drawable()) and a size must have been allocated.
5665 * @cr: a cairo context to draw to
5667 * Draws @widget to @cr. The top left corner of the widget will be
5668 * drawn to the currently set origin point of @cr.
5670 * You should pass a cairo context as @cr argument that is in an
5671 * original state. Otherwise the resulting drawing is undefined. For
5672 * example changing the operator using cairo_set_operator() or the
5673 * line width using cairo_set_line_width() might have unwanted side
5675 * You may however change the context's transform matrix - like with
5676 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5677 * region with cairo_clip() prior to calling this function. Also, it
5678 * is fine to modify the context with cairo_save() and
5679 * cairo_push_group() prior to calling this function.
5681 * <note><para>Special purpose widgets may contain special code for
5682 * rendering to the screen and might appear differently on screen
5683 * and when rendered using gtk_widget_draw().</para></note>
5686 gtk_widget_draw (GtkWidget *widget,
5689 GdkEventExpose *tmp_event;
5691 g_return_if_fail (GTK_IS_WIDGET (widget));
5692 g_return_if_fail (!widget->priv->alloc_needed);
5693 g_return_if_fail (cr != NULL);
5696 /* We have to reset the event here so that draw functions can call
5697 * gtk_widget_draw() on random other widgets and get the desired
5698 * effect: Drawing all contents, not just the current window.
5700 tmp_event = _gtk_cairo_get_event (cr);
5701 gtk_cairo_set_event (cr, NULL);
5703 _gtk_widget_draw_internal (widget, cr, TRUE);
5705 gtk_cairo_set_event (cr, tmp_event);
5710 gtk_widget_real_key_press_event (GtkWidget *widget,
5713 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5717 gtk_widget_real_key_release_event (GtkWidget *widget,
5720 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5724 gtk_widget_real_focus_in_event (GtkWidget *widget,
5725 GdkEventFocus *event)
5727 gtk_widget_queue_shallow_draw (widget);
5733 gtk_widget_real_focus_out_event (GtkWidget *widget,
5734 GdkEventFocus *event)
5736 gtk_widget_queue_shallow_draw (widget);
5741 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5742 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5746 * @widget: a #GtkWidget
5747 * @event: a #GdkEvent
5749 * Rarely-used function. This function is used to emit
5750 * the event signals on a widget (those signals should never
5751 * be emitted without using this function to do so).
5752 * If you want to synthesize an event though, don't use this function;
5753 * instead, use gtk_main_do_event() so the event will behave as if
5754 * it were in the event queue. Don't synthesize expose events; instead,
5755 * use gdk_window_invalidate_rect() to invalidate a region of the
5758 * Return value: return from the event signal emission (%TRUE if
5759 * the event was handled)
5762 gtk_widget_event (GtkWidget *widget,
5765 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5766 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5768 if (event->type == GDK_EXPOSE)
5770 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5771 "the same effect, call gdk_window_invalidate_rect/region(), "
5772 "followed by gdk_window_process_updates().");
5776 return gtk_widget_event_internal (widget, event);
5779 /* Returns TRUE if a translation should be done */
5781 _gtk_widget_get_translation_to_window (GtkWidget *widget,
5786 GdkWindow *w, *widget_window;
5788 if (!gtk_widget_get_has_window (widget))
5790 *x = -widget->priv->allocation.x;
5791 *y = -widget->priv->allocation.y;
5799 widget_window = gtk_widget_get_window (widget);
5801 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5804 gdk_window_get_position (w, &wx, &wy);
5821 * gtk_cairo_transform_to_window:
5822 * @cr: the cairo context to transform
5823 * @widget: the widget the context is currently centered for
5824 * @window: the window to transform the context to
5826 * Transforms the given cairo context @cr that from @widget-relative
5827 * coordinates to @window-relative coordinates.
5828 * If the @widget's window is not an ancestor of @window, no
5829 * modification will be applied.
5831 * This is the inverse to the transformation GTK applies when
5832 * preparing an expose event to be emitted with the #GtkWidget::draw
5833 * signal. It is intended to help porting multiwindow widgets from
5834 * GTK+ 2 to the rendering architecture of GTK+ 3.
5837 gtk_cairo_transform_to_window (cairo_t *cr,
5843 g_return_if_fail (cr != NULL);
5844 g_return_if_fail (GTK_IS_WIDGET (widget));
5845 g_return_if_fail (GDK_IS_WINDOW (window));
5847 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
5848 cairo_translate (cr, x, y);
5852 * gtk_widget_send_expose:
5853 * @widget: a #GtkWidget
5854 * @event: a expose #GdkEvent
5856 * Very rarely-used function. This function is used to emit
5857 * an expose event on a widget. This function is not normally used
5858 * directly. The only time it is used is when propagating an expose
5859 * event to a child %NO_WINDOW widget, and that is normally done
5860 * using gtk_container_propagate_draw().
5862 * If you want to force an area of a window to be redrawn,
5863 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5864 * To cause the redraw to be done immediately, follow that call
5865 * with a call to gdk_window_process_updates().
5867 * Return value: return from the event signal emission (%TRUE if
5868 * the event was handled)
5871 gtk_widget_send_expose (GtkWidget *widget,
5874 gboolean result = FALSE;
5879 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5880 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5881 g_return_val_if_fail (event != NULL, TRUE);
5882 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5884 cr = gdk_cairo_create (event->expose.window);
5885 gtk_cairo_set_event (cr, &event->expose);
5887 gdk_cairo_region (cr, event->expose.region);
5890 do_clip = _gtk_widget_get_translation_to_window (widget,
5891 event->expose.window,
5893 cairo_translate (cr, -x, -y);
5895 _gtk_widget_draw_internal (widget, cr, do_clip);
5897 /* unset here, so if someone keeps a reference to cr we
5898 * don't leak the window. */
5899 gtk_cairo_set_event (cr, NULL);
5906 event_window_is_still_viewable (GdkEvent *event)
5908 /* Check that we think the event's window is viewable before
5909 * delivering the event, to prevent suprises. We do this here
5910 * at the last moment, since the event may have been queued
5911 * up behind other events, held over a recursive main loop, etc.
5913 switch (event->type)
5916 case GDK_MOTION_NOTIFY:
5917 case GDK_BUTTON_PRESS:
5918 case GDK_2BUTTON_PRESS:
5919 case GDK_3BUTTON_PRESS:
5921 case GDK_ENTER_NOTIFY:
5922 case GDK_PROXIMITY_IN:
5924 return event->any.window && gdk_window_is_viewable (event->any.window);
5927 /* The following events are the second half of paired events;
5928 * we always deliver them to deal with widgets that clean up
5929 * on the second half.
5931 case GDK_BUTTON_RELEASE:
5932 case GDK_KEY_RELEASE:
5933 case GDK_LEAVE_NOTIFY:
5934 case GDK_PROXIMITY_OUT:
5938 /* Remaining events would make sense on an not-viewable window,
5939 * or don't have an associated window.
5946 gtk_widget_event_internal (GtkWidget *widget,
5949 gboolean return_val = FALSE;
5951 /* We check only once for is-still-visible; if someone
5952 * hides the window in on of the signals on the widget,
5953 * they are responsible for returning TRUE to terminate
5956 if (!event_window_is_still_viewable (event))
5959 g_object_ref (widget);
5961 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5962 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5967 switch (event->type)
5972 case GDK_BUTTON_PRESS:
5973 case GDK_2BUTTON_PRESS:
5974 case GDK_3BUTTON_PRESS:
5975 signal_num = BUTTON_PRESS_EVENT;
5978 signal_num = SCROLL_EVENT;
5980 case GDK_BUTTON_RELEASE:
5981 signal_num = BUTTON_RELEASE_EVENT;
5983 case GDK_MOTION_NOTIFY:
5984 signal_num = MOTION_NOTIFY_EVENT;
5987 signal_num = DELETE_EVENT;
5990 signal_num = DESTROY_EVENT;
5991 _gtk_tooltip_hide (widget);
5994 signal_num = KEY_PRESS_EVENT;
5996 case GDK_KEY_RELEASE:
5997 signal_num = KEY_RELEASE_EVENT;
5999 case GDK_ENTER_NOTIFY:
6000 signal_num = ENTER_NOTIFY_EVENT;
6002 case GDK_LEAVE_NOTIFY:
6003 signal_num = LEAVE_NOTIFY_EVENT;
6005 case GDK_FOCUS_CHANGE:
6006 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6007 if (event->focus_change.in)
6008 _gtk_tooltip_focus_in (widget);
6010 _gtk_tooltip_focus_out (widget);
6013 signal_num = CONFIGURE_EVENT;
6016 signal_num = MAP_EVENT;
6019 signal_num = UNMAP_EVENT;
6021 case GDK_WINDOW_STATE:
6022 signal_num = WINDOW_STATE_EVENT;
6024 case GDK_PROPERTY_NOTIFY:
6025 signal_num = PROPERTY_NOTIFY_EVENT;
6027 case GDK_SELECTION_CLEAR:
6028 signal_num = SELECTION_CLEAR_EVENT;
6030 case GDK_SELECTION_REQUEST:
6031 signal_num = SELECTION_REQUEST_EVENT;
6033 case GDK_SELECTION_NOTIFY:
6034 signal_num = SELECTION_NOTIFY_EVENT;
6036 case GDK_PROXIMITY_IN:
6037 signal_num = PROXIMITY_IN_EVENT;
6039 case GDK_PROXIMITY_OUT:
6040 signal_num = PROXIMITY_OUT_EVENT;
6042 case GDK_CLIENT_EVENT:
6043 signal_num = CLIENT_EVENT;
6046 signal_num = EXPOSE_EVENT;
6048 case GDK_VISIBILITY_NOTIFY:
6049 signal_num = VISIBILITY_NOTIFY_EVENT;
6051 case GDK_GRAB_BROKEN:
6052 signal_num = GRAB_BROKEN_EVENT;
6055 signal_num = DAMAGE_EVENT;
6058 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6062 if (signal_num != -1)
6063 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6065 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6066 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6070 g_object_unref (widget);
6076 * gtk_widget_activate:
6077 * @widget: a #GtkWidget that's activatable
6079 * For widgets that can be "activated" (buttons, menu items, etc.)
6080 * this function activates them. Activation is what happens when you
6081 * press Enter on a widget during key navigation. If @widget isn't
6082 * activatable, the function returns %FALSE.
6084 * Return value: %TRUE if the widget was activatable
6087 gtk_widget_activate (GtkWidget *widget)
6089 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6091 if (WIDGET_CLASS (widget)->activate_signal)
6093 /* FIXME: we should eventually check the signals signature here */
6094 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6103 gtk_widget_reparent_subwindows (GtkWidget *widget,
6104 GdkWindow *new_window)
6106 GtkWidgetPrivate *priv = widget->priv;
6108 if (!gtk_widget_get_has_window (widget))
6110 GList *children = gdk_window_get_children (priv->window);
6113 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6115 GdkWindow *window = tmp_list->data;
6118 gdk_window_get_user_data (window, &child);
6119 while (child && child != widget)
6120 child = ((GtkWidget*) child)->priv->parent;
6123 gdk_window_reparent (window, new_window, 0, 0);
6126 g_list_free (children);
6131 GList *tmp_list, *children;
6133 parent = gdk_window_get_parent (priv->window);
6136 gdk_window_reparent (priv->window, new_window, 0, 0);
6139 children = gdk_window_get_children (parent);
6141 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6143 GdkWindow *window = tmp_list->data;
6146 gdk_window_get_user_data (window, &child);
6148 if (child == widget)
6149 gdk_window_reparent (window, new_window, 0, 0);
6152 g_list_free (children);
6158 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6159 gpointer client_data)
6161 GtkWidgetPrivate *priv = widget->priv;
6163 g_assert (client_data != NULL);
6165 if (!gtk_widget_get_has_window (widget))
6168 g_object_unref (priv->window);
6169 priv->window = (GdkWindow*) client_data;
6171 g_object_ref (priv->window);
6173 if (GTK_IS_CONTAINER (widget))
6174 gtk_container_forall (GTK_CONTAINER (widget),
6175 gtk_widget_reparent_fixup_child,
6181 * gtk_widget_reparent:
6182 * @widget: a #GtkWidget
6183 * @new_parent: a #GtkContainer to move the widget into
6185 * Moves a widget from one #GtkContainer to another, handling reference
6186 * count issues to avoid destroying the widget.
6189 gtk_widget_reparent (GtkWidget *widget,
6190 GtkWidget *new_parent)
6192 GtkWidgetPrivate *priv;
6194 g_return_if_fail (GTK_IS_WIDGET (widget));
6195 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6196 priv = widget->priv;
6197 g_return_if_fail (priv->parent != NULL);
6199 if (priv->parent != new_parent)
6201 /* First try to see if we can get away without unrealizing
6202 * the widget as we reparent it. if so we set a flag so
6203 * that gtk_widget_unparent doesn't unrealize widget
6205 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6206 priv->in_reparent = TRUE;
6208 g_object_ref (widget);
6209 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6210 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6211 g_object_unref (widget);
6213 if (priv->in_reparent)
6215 priv->in_reparent = FALSE;
6217 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6218 gtk_widget_reparent_fixup_child (widget,
6219 gtk_widget_get_parent_window (widget));
6222 g_object_notify (G_OBJECT (widget), "parent");
6227 * gtk_widget_intersect:
6228 * @widget: a #GtkWidget
6229 * @area: a rectangle
6230 * @intersection: rectangle to store intersection of @widget and @area
6232 * Computes the intersection of a @widget's area and @area, storing
6233 * the intersection in @intersection, and returns %TRUE if there was
6234 * an intersection. @intersection may be %NULL if you're only
6235 * interested in whether there was an intersection.
6237 * Return value: %TRUE if there was an intersection
6240 gtk_widget_intersect (GtkWidget *widget,
6241 const GdkRectangle *area,
6242 GdkRectangle *intersection)
6244 GtkWidgetPrivate *priv;
6249 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6250 g_return_val_if_fail (area != NULL, FALSE);
6252 priv = widget->priv;
6255 dest = intersection;
6259 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6261 if (return_val && intersection && gtk_widget_get_has_window (widget))
6263 intersection->x -= priv->allocation.x;
6264 intersection->y -= priv->allocation.y;
6271 * gtk_widget_region_intersect:
6272 * @widget: a #GtkWidget
6273 * @region: a #cairo_region_t, in the same coordinate system as
6274 * @widget->allocation. That is, relative to @widget->window
6275 * for %NO_WINDOW widgets; relative to the parent window
6276 * of @widget->window for widgets with their own window.
6277 * @returns: A newly allocated region holding the intersection of @widget
6278 * and @region. The coordinates of the return value are
6279 * relative to @widget->window for %NO_WINDOW widgets, and
6280 * relative to the parent window of @widget->window for
6281 * widgets with their own window.
6283 * Computes the intersection of a @widget's area and @region, returning
6284 * the intersection. The result may be empty, use cairo_region_is_empty() to
6288 gtk_widget_region_intersect (GtkWidget *widget,
6289 const cairo_region_t *region)
6292 cairo_region_t *dest;
6294 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6295 g_return_val_if_fail (region != NULL, NULL);
6297 gtk_widget_get_allocation (widget, &rect);
6299 dest = cairo_region_create_rectangle (&rect);
6301 cairo_region_intersect (dest, region);
6307 * _gtk_widget_grab_notify:
6308 * @widget: a #GtkWidget
6309 * @was_grabbed: whether a grab is now in effect
6311 * Emits the #GtkWidget::grab-notify signal on @widget.
6316 _gtk_widget_grab_notify (GtkWidget *widget,
6317 gboolean was_grabbed)
6319 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6323 * gtk_widget_grab_focus:
6324 * @widget: a #GtkWidget
6326 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6327 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6328 * something like #GtkFrame won't work.
6330 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6331 * gtk_widget_set_can_focus() to modify that flag.
6333 * The widget also needs to be realized and mapped. This is indicated by the
6334 * related signals. Grabbing the focus immediately after creating the widget
6335 * will likely fail and cause critical warnings.
6338 gtk_widget_grab_focus (GtkWidget *widget)
6340 g_return_if_fail (GTK_IS_WIDGET (widget));
6342 if (!gtk_widget_is_sensitive (widget))
6345 g_object_ref (widget);
6346 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6347 g_object_notify (G_OBJECT (widget), "has-focus");
6348 g_object_unref (widget);
6352 reset_focus_recurse (GtkWidget *widget,
6355 if (GTK_IS_CONTAINER (widget))
6357 GtkContainer *container;
6359 container = GTK_CONTAINER (widget);
6360 gtk_container_set_focus_child (container, NULL);
6362 gtk_container_foreach (container,
6363 reset_focus_recurse,
6369 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6371 if (gtk_widget_get_can_focus (focus_widget))
6373 GtkWidget *toplevel;
6376 /* clear the current focus setting, break if the current widget
6377 * is the focus widget's parent, since containers above that will
6378 * be set by the next loop.
6380 toplevel = gtk_widget_get_toplevel (focus_widget);
6381 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6383 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6385 if (widget == focus_widget)
6387 /* We call _gtk_window_internal_set_focus() here so that the
6388 * toplevel window can request the focus if necessary.
6389 * This is needed when the toplevel is a GtkPlug
6391 if (!gtk_widget_has_focus (widget))
6392 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6399 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
6401 widget = widget->priv->parent;
6402 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6406 else if (toplevel != focus_widget)
6408 /* gtk_widget_grab_focus() operates on a tree without window...
6409 * actually, this is very questionable behaviour.
6412 gtk_container_foreach (GTK_CONTAINER (toplevel),
6413 reset_focus_recurse,
6417 /* now propagate the new focus up the widget tree and finally
6418 * set it on the window
6420 widget = focus_widget;
6421 while (widget->priv->parent)
6423 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6424 widget = widget->priv->parent;
6426 if (GTK_IS_WINDOW (widget))
6427 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6432 gtk_widget_real_query_tooltip (GtkWidget *widget,
6435 gboolean keyboard_tip,
6436 GtkTooltip *tooltip)
6438 gchar *tooltip_markup;
6439 gboolean has_tooltip;
6441 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6442 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6444 if (has_tooltip && tooltip_markup)
6446 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6454 gtk_widget_real_style_updated (GtkWidget *widget)
6456 if (gtk_widget_get_realized (widget))
6458 /* Trigger ::style-set for old
6459 * widgets not listening to this
6461 g_signal_emit (widget,
6462 widget_signals[STYLE_SET],
6464 widget->priv->style);
6467 if (widget->priv->context)
6469 gtk_style_context_invalidate (widget->priv->context);
6471 if (gtk_widget_get_realized (widget) &&
6472 gtk_widget_get_has_window (widget))
6473 gtk_style_context_set_background (widget->priv->context,
6474 widget->priv->window);
6477 if (widget->priv->anchored)
6478 gtk_widget_queue_resize (widget);
6482 gtk_widget_real_show_help (GtkWidget *widget,
6483 GtkWidgetHelpType help_type)
6485 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6487 _gtk_tooltip_toggle_keyboard_mode (widget);
6496 gtk_widget_real_focus (GtkWidget *widget,
6497 GtkDirectionType direction)
6499 if (!gtk_widget_get_can_focus (widget))
6502 if (!gtk_widget_is_focus (widget))
6504 gtk_widget_grab_focus (widget);
6512 gtk_widget_real_move_focus (GtkWidget *widget,
6513 GtkDirectionType direction)
6515 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6517 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6519 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6525 gtk_widget_real_keynav_failed (GtkWidget *widget,
6526 GtkDirectionType direction)
6528 gboolean cursor_only;
6532 case GTK_DIR_TAB_FORWARD:
6533 case GTK_DIR_TAB_BACKWARD:
6540 g_object_get (gtk_widget_get_settings (widget),
6541 "gtk-keynav-cursor-only", &cursor_only,
6548 gtk_widget_error_bell (widget);
6554 * gtk_widget_set_can_focus:
6555 * @widget: a #GtkWidget
6556 * @can_focus: whether or not @widget can own the input focus.
6558 * Specifies whether @widget can own the input focus. See
6559 * gtk_widget_grab_focus() for actually setting the input focus on a
6565 gtk_widget_set_can_focus (GtkWidget *widget,
6568 g_return_if_fail (GTK_IS_WIDGET (widget));
6570 if (widget->priv->can_focus != can_focus)
6572 widget->priv->can_focus = can_focus;
6574 gtk_widget_queue_resize (widget);
6575 g_object_notify (G_OBJECT (widget), "can-focus");
6580 * gtk_widget_get_can_focus:
6581 * @widget: a #GtkWidget
6583 * Determines whether @widget can own the input focus. See
6584 * gtk_widget_set_can_focus().
6586 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6591 gtk_widget_get_can_focus (GtkWidget *widget)
6593 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6595 return widget->priv->can_focus;
6599 * gtk_widget_has_focus:
6600 * @widget: a #GtkWidget
6602 * Determines if the widget has the global input focus. See
6603 * gtk_widget_is_focus() for the difference between having the global
6604 * input focus, and only having the focus within a toplevel.
6606 * Return value: %TRUE if the widget has the global input focus.
6611 gtk_widget_has_focus (GtkWidget *widget)
6613 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6615 return widget->priv->has_focus;
6619 * gtk_widget_is_focus:
6620 * @widget: a #GtkWidget
6622 * Determines if the widget is the focus widget within its
6623 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6624 * necessarily set; %HAS_FOCUS will only be set if the
6625 * toplevel widget additionally has the global input focus.)
6627 * Return value: %TRUE if the widget is the focus widget.
6630 gtk_widget_is_focus (GtkWidget *widget)
6632 GtkWidget *toplevel;
6634 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6636 toplevel = gtk_widget_get_toplevel (widget);
6638 if (GTK_IS_WINDOW (toplevel))
6639 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6645 * gtk_widget_set_can_default:
6646 * @widget: a #GtkWidget
6647 * @can_default: whether or not @widget can be a default widget.
6649 * Specifies whether @widget can be a default widget. See
6650 * gtk_widget_grab_default() for details about the meaning of
6656 gtk_widget_set_can_default (GtkWidget *widget,
6657 gboolean can_default)
6659 g_return_if_fail (GTK_IS_WIDGET (widget));
6661 if (widget->priv->can_default != can_default)
6663 widget->priv->can_default = can_default;
6665 gtk_widget_queue_resize (widget);
6666 g_object_notify (G_OBJECT (widget), "can-default");
6671 * gtk_widget_get_can_default:
6672 * @widget: a #GtkWidget
6674 * Determines whether @widget can be a default widget. See
6675 * gtk_widget_set_can_default().
6677 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6682 gtk_widget_get_can_default (GtkWidget *widget)
6684 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6686 return widget->priv->can_default;
6690 * gtk_widget_has_default:
6691 * @widget: a #GtkWidget
6693 * Determines whether @widget is the current default widget within its
6694 * toplevel. See gtk_widget_set_can_default().
6696 * Return value: %TRUE if @widget is the current default widget within
6697 * its toplevel, %FALSE otherwise
6702 gtk_widget_has_default (GtkWidget *widget)
6704 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6706 return widget->priv->has_default;
6710 _gtk_widget_set_has_default (GtkWidget *widget,
6711 gboolean has_default)
6713 widget->priv->has_default = has_default;
6717 * gtk_widget_grab_default:
6718 * @widget: a #GtkWidget
6720 * Causes @widget to become the default widget. @widget must have the
6721 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6722 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6723 * %TRUE)</literal>. The default widget is activated when
6724 * the user presses Enter in a window. Default widgets must be
6725 * activatable, that is, gtk_widget_activate() should affect them. Note
6726 * that #GtkEntry widgets require the "activates-default" property
6727 * set to %TRUE before they activate the default widget when Enter
6728 * is pressed and the #GtkEntry is focused.
6731 gtk_widget_grab_default (GtkWidget *widget)
6735 g_return_if_fail (GTK_IS_WIDGET (widget));
6736 g_return_if_fail (gtk_widget_get_can_default (widget));
6738 window = gtk_widget_get_toplevel (widget);
6740 if (window && gtk_widget_is_toplevel (window))
6741 gtk_window_set_default (GTK_WINDOW (window), widget);
6743 g_warning (G_STRLOC ": widget not within a GtkWindow");
6747 * gtk_widget_set_receives_default:
6748 * @widget: a #GtkWidget
6749 * @receives_default: whether or not @widget can be a default widget.
6751 * Specifies whether @widget will be treated as the default widget
6752 * within its toplevel when it has the focus, even if another widget
6755 * See gtk_widget_grab_default() for details about the meaning of
6761 gtk_widget_set_receives_default (GtkWidget *widget,
6762 gboolean receives_default)
6764 g_return_if_fail (GTK_IS_WIDGET (widget));
6766 if (widget->priv->receives_default != receives_default)
6768 widget->priv->receives_default = receives_default;
6770 g_object_notify (G_OBJECT (widget), "receives-default");
6775 * gtk_widget_get_receives_default:
6776 * @widget: a #GtkWidget
6778 * Determines whether @widget is alyways treated as default widget
6779 * withing its toplevel when it has the focus, even if another widget
6782 * See gtk_widget_set_receives_default().
6784 * Return value: %TRUE if @widget acts as default widget when focussed,
6790 gtk_widget_get_receives_default (GtkWidget *widget)
6792 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6794 return widget->priv->receives_default;
6798 * gtk_widget_has_grab:
6799 * @widget: a #GtkWidget
6801 * Determines whether the widget is currently grabbing events, so it
6802 * is the only widget receiving input events (keyboard and mouse).
6804 * See also gtk_grab_add().
6806 * Return value: %TRUE if the widget is in the grab_widgets stack
6811 gtk_widget_has_grab (GtkWidget *widget)
6813 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6815 return widget->priv->has_grab;
6819 _gtk_widget_set_has_grab (GtkWidget *widget,
6822 widget->priv->has_grab = has_grab;
6826 * gtk_widget_device_is_shadowed:
6827 * @widget: a #GtkWidget
6828 * @device: a #GdkDevice
6830 * Returns %TRUE if @device has been shadowed by a GTK+
6831 * device grab on another widget, so it would stop sending
6832 * events to @widget. This may be used in the
6833 * #GtkWidget::grab-notify signal to check for specific
6834 * devices. See gtk_device_grab_add().
6836 * Returns: %TRUE if there is an ongoing grab on @device
6837 * by another #GtkWidget than @widget.
6842 gtk_widget_device_is_shadowed (GtkWidget *widget,
6845 GtkWindowGroup *group;
6846 GtkWidget *grab_widget, *toplevel;
6848 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6849 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6851 if (!gtk_widget_get_realized (widget))
6854 toplevel = gtk_widget_get_toplevel (widget);
6856 if (GTK_IS_WINDOW (toplevel))
6857 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6859 group = gtk_window_get_group (NULL);
6861 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6863 /* Widget not inside the hierarchy of grab_widget */
6865 widget != grab_widget &&
6866 !gtk_widget_is_ancestor (widget, grab_widget))
6869 grab_widget = gtk_window_group_get_current_grab (group);
6870 if (grab_widget && widget != grab_widget &&
6871 !gtk_widget_is_ancestor (widget, grab_widget))
6878 * gtk_widget_set_name:
6879 * @widget: a #GtkWidget
6880 * @name: name for the widget
6882 * Widgets can be named, which allows you to refer to them from a
6883 * CSS file. You can apply a style to widgets with a particular name
6884 * in the CSS file. See the documentation for the CSS syntax (on the
6885 * same page as the docs for #GtkStyleContext).
6887 * Note that the CSS syntax has certain special characters to delimit
6888 * and represent elements in a selector (period, #, >, *...),
6889 * so using these will make your widget impossible to match by name.
6890 * Any combination of alphanumeric symbols, dashes and underscores will
6894 gtk_widget_set_name (GtkWidget *widget,
6897 GtkWidgetPrivate *priv;
6900 g_return_if_fail (GTK_IS_WIDGET (widget));
6902 priv = widget->priv;
6904 new_name = g_strdup (name);
6905 g_free (priv->name);
6906 priv->name = new_name;
6912 pos = gtk_widget_path_length (priv->path) - 1;
6913 gtk_widget_path_iter_set_name (priv->path, pos,
6918 gtk_style_context_set_path (priv->context, priv->path);
6920 g_object_notify (G_OBJECT (widget), "name");
6924 * gtk_widget_get_name:
6925 * @widget: a #GtkWidget
6927 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6928 * significance of widget names.
6930 * Return value: name of the widget. This string is owned by GTK+ and
6931 * should not be modified or freed
6933 G_CONST_RETURN gchar*
6934 gtk_widget_get_name (GtkWidget *widget)
6936 GtkWidgetPrivate *priv;
6938 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6940 priv = widget->priv;
6944 return G_OBJECT_TYPE_NAME (widget);
6948 _gtk_widget_update_state_flags (GtkWidget *widget,
6949 GtkStateFlags flags,
6952 GtkWidgetPrivate *priv;
6954 priv = widget->priv;
6956 /* Handle insensitive first, since it is propagated
6957 * differently throughout the widget hierarchy.
6959 if ((flags & GTK_STATE_FLAG_INSENSITIVE) !=
6960 (priv->state_flags & GTK_STATE_FLAG_INSENSITIVE))
6961 gtk_widget_set_sensitive (widget,
6962 operation != STATE_CHANGE_UNSET);
6964 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
6967 operation == STATE_CHANGE_REPLACE)
6972 data.operation = operation;
6973 data.use_forall = FALSE;
6976 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6978 data.parent_sensitive = TRUE;
6980 gtk_widget_propagate_state (widget, &data);
6982 if (gtk_widget_is_drawable (widget))
6983 gtk_widget_queue_draw (widget);
6988 * gtk_widget_set_state_flags:
6989 * @widget: a #GtkWidget
6990 * @flags: State flags to turn on
6991 * @clear: Whether to clear state before turning on @flags
6993 * This function is for use in widget implementations. Turns on flag
6994 * values in the current widget state (insensitive, prelighted, etc.).
6996 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
6997 * will be propagated down to all non-internal children if @widget is a
6998 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
6999 * down to all #GtkContainer children by different means than turning on the
7000 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7001 * gtk_widget_is_sensitive() will make use of these.
7006 gtk_widget_set_state_flags (GtkWidget *widget,
7007 GtkStateFlags flags,
7010 g_return_if_fail (GTK_IS_WIDGET (widget));
7012 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7013 (clear && widget->priv->state_flags == flags))
7017 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7019 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
7023 * gtk_widget_unset_state_flags:
7024 * @widget: a #GtkWidget
7025 * @flags: State flags to turn off
7027 * This function is for use in widget implementations. Turns off flag
7028 * values for the current widget state (insensitive, prelighted, etc.).
7029 * See gtk_widget_set_state_flags().
7034 gtk_widget_unset_state_flags (GtkWidget *widget,
7035 GtkStateFlags flags)
7037 g_return_if_fail (GTK_IS_WIDGET (widget));
7039 if ((widget->priv->state_flags & flags) == 0)
7042 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
7046 * gtk_widget_get_state_flags:
7047 * @widget: a #GtkWidget
7049 * Returns the widget state as a flag set. It is worth mentioning
7050 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7051 * returned, that is, also based on parent insensitivity, even if
7052 * @widget itself is sensitive.
7054 * Returns: The state flags for widget
7059 gtk_widget_get_state_flags (GtkWidget *widget)
7061 GtkStateFlags flags;
7063 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7065 flags = widget->priv->state_flags;
7067 if (!gtk_widget_is_sensitive (widget))
7068 flags |= GTK_STATE_FLAG_INSENSITIVE;
7074 * gtk_widget_set_state:
7075 * @widget: a #GtkWidget
7076 * @state: new state for @widget
7078 * This function is for use in widget implementations. Sets the state
7079 * of a widget (insensitive, prelighted, etc.) Usually you should set
7080 * the state using wrapper functions such as gtk_widget_set_sensitive().
7082 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7085 gtk_widget_set_state (GtkWidget *widget,
7088 GtkStateFlags flags;
7090 if (state == gtk_widget_get_state (widget))
7095 case GTK_STATE_ACTIVE:
7096 flags = GTK_STATE_FLAG_ACTIVE;
7098 case GTK_STATE_PRELIGHT:
7099 flags = GTK_STATE_FLAG_PRELIGHT;
7101 case GTK_STATE_SELECTED:
7102 flags = GTK_STATE_FLAG_SELECTED;
7104 case GTK_STATE_INSENSITIVE:
7105 flags = GTK_STATE_FLAG_INSENSITIVE;
7107 case GTK_STATE_INCONSISTENT:
7108 flags = GTK_STATE_FLAG_INCONSISTENT;
7110 case GTK_STATE_FOCUSED:
7111 flags = GTK_STATE_FLAG_FOCUSED;
7113 case GTK_STATE_NORMAL:
7119 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7123 * gtk_widget_get_state:
7124 * @widget: a #GtkWidget
7126 * Returns the widget's state. See gtk_widget_set_state().
7128 * Returns: the state of @widget.
7132 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7135 gtk_widget_get_state (GtkWidget *widget)
7137 GtkStateFlags flags;
7139 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7141 flags = gtk_widget_get_state_flags (widget);
7143 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7144 return GTK_STATE_INSENSITIVE;
7145 else if (flags & GTK_STATE_FLAG_INCONSISTENT)
7146 return GTK_STATE_INCONSISTENT;
7147 else if (flags & GTK_STATE_FLAG_ACTIVE)
7148 return GTK_STATE_ACTIVE;
7149 else if (flags & GTK_STATE_FLAG_SELECTED)
7150 return GTK_STATE_SELECTED;
7151 else if (flags & GTK_STATE_FLAG_FOCUSED)
7152 return GTK_STATE_FOCUSED;
7153 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7154 return GTK_STATE_PRELIGHT;
7156 return GTK_STATE_NORMAL;
7160 * gtk_widget_set_visible:
7161 * @widget: a #GtkWidget
7162 * @visible: whether the widget should be shown or not
7164 * Sets the visibility state of @widget. Note that setting this to
7165 * %TRUE doesn't mean the widget is actually viewable, see
7166 * gtk_widget_get_visible().
7168 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7169 * but is nicer to use when the visibility of the widget depends on
7175 gtk_widget_set_visible (GtkWidget *widget,
7178 g_return_if_fail (GTK_IS_WIDGET (widget));
7180 if (visible != gtk_widget_get_visible (widget))
7183 gtk_widget_show (widget);
7185 gtk_widget_hide (widget);
7190 _gtk_widget_set_visible_flag (GtkWidget *widget,
7193 widget->priv->visible = visible;
7197 * gtk_widget_get_visible:
7198 * @widget: a #GtkWidget
7200 * Determines whether the widget is visible. Note that this doesn't
7201 * take into account whether the widget's parent is also visible
7202 * or the widget is obscured in any way.
7204 * See gtk_widget_set_visible().
7206 * Return value: %TRUE if the widget is visible
7211 gtk_widget_get_visible (GtkWidget *widget)
7213 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7215 return widget->priv->visible;
7219 * gtk_widget_set_has_window:
7220 * @widget: a #GtkWidget
7221 * @has_window: whether or not @widget has a window.
7223 * Specifies whether @widget has a #GdkWindow of its own. Note that
7224 * all realized widgets have a non-%NULL "window" pointer
7225 * (gtk_widget_get_window() never returns a %NULL window when a widget
7226 * is realized), but for many of them it's actually the #GdkWindow of
7227 * one of its parent widgets. Widgets that do not create a %window for
7228 * themselves in #GtkWidget::realize must announce this by
7229 * calling this function with @has_window = %FALSE.
7231 * This function should only be called by widget implementations,
7232 * and they should call it in their init() function.
7237 gtk_widget_set_has_window (GtkWidget *widget,
7238 gboolean has_window)
7240 g_return_if_fail (GTK_IS_WIDGET (widget));
7242 widget->priv->no_window = !has_window;
7246 * gtk_widget_get_has_window:
7247 * @widget: a #GtkWidget
7249 * Determines whether @widget has a #GdkWindow of its own. See
7250 * gtk_widget_set_has_window().
7252 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7257 gtk_widget_get_has_window (GtkWidget *widget)
7259 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7261 return ! widget->priv->no_window;
7265 * gtk_widget_is_toplevel:
7266 * @widget: a #GtkWidget
7268 * Determines whether @widget is a toplevel widget.
7270 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7271 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7274 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7279 gtk_widget_is_toplevel (GtkWidget *widget)
7281 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7283 return widget->priv->toplevel;
7287 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7288 gboolean is_toplevel)
7290 widget->priv->toplevel = is_toplevel;
7294 * gtk_widget_is_drawable:
7295 * @widget: a #GtkWidget
7297 * Determines whether @widget can be drawn to. A widget can be drawn
7298 * to if it is mapped and visible.
7300 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7305 gtk_widget_is_drawable (GtkWidget *widget)
7307 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7309 return (gtk_widget_get_visible (widget) &&
7310 gtk_widget_get_mapped (widget));
7314 * gtk_widget_get_realized:
7315 * @widget: a #GtkWidget
7317 * Determines whether @widget is realized.
7319 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7324 gtk_widget_get_realized (GtkWidget *widget)
7326 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7328 return widget->priv->realized;
7332 * gtk_widget_set_realized:
7333 * @widget: a #GtkWidget
7334 * @realized: %TRUE to mark the widget as realized
7336 * Marks the widget as being realized.
7338 * This function should only ever be called in a derived widget's
7339 * "realize" or "unrealize" implementation.
7344 gtk_widget_set_realized (GtkWidget *widget,
7347 g_return_if_fail (GTK_IS_WIDGET (widget));
7349 widget->priv->realized = realized;
7353 * gtk_widget_get_mapped:
7354 * @widget: a #GtkWidget
7356 * Whether the widget is mapped.
7358 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7363 gtk_widget_get_mapped (GtkWidget *widget)
7365 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7367 return widget->priv->mapped;
7371 * gtk_widget_set_mapped:
7372 * @widget: a #GtkWidget
7373 * @mapped: %TRUE to mark the widget as mapped
7375 * Marks the widget as being realized.
7377 * This function should only ever be called in a derived widget's
7378 * "map" or "unmap" implementation.
7383 gtk_widget_set_mapped (GtkWidget *widget,
7386 g_return_if_fail (GTK_IS_WIDGET (widget));
7388 widget->priv->mapped = mapped;
7392 * gtk_widget_set_app_paintable:
7393 * @widget: a #GtkWidget
7394 * @app_paintable: %TRUE if the application will paint on the widget
7396 * Sets whether the application intends to draw on the widget in
7397 * an #GtkWidget::draw handler.
7399 * This is a hint to the widget and does not affect the behavior of
7400 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7401 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7402 * the effect is to suppress default themed drawing of the widget's
7403 * background. (Children of the widget will still be drawn.) The application
7404 * is then entirely responsible for drawing the widget background.
7406 * Note that the background is still drawn when the widget is mapped.
7409 gtk_widget_set_app_paintable (GtkWidget *widget,
7410 gboolean app_paintable)
7412 g_return_if_fail (GTK_IS_WIDGET (widget));
7414 app_paintable = (app_paintable != FALSE);
7416 if (widget->priv->app_paintable != app_paintable)
7418 widget->priv->app_paintable = app_paintable;
7420 if (gtk_widget_is_drawable (widget))
7421 gtk_widget_queue_draw (widget);
7423 g_object_notify (G_OBJECT (widget), "app-paintable");
7428 * gtk_widget_get_app_paintable:
7429 * @widget: a #GtkWidget
7431 * Determines whether the application intends to draw on the widget in
7432 * an #GtkWidget::draw handler.
7434 * See gtk_widget_set_app_paintable()
7436 * Return value: %TRUE if the widget is app paintable
7441 gtk_widget_get_app_paintable (GtkWidget *widget)
7443 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7445 return widget->priv->app_paintable;
7449 * gtk_widget_set_double_buffered:
7450 * @widget: a #GtkWidget
7451 * @double_buffered: %TRUE to double-buffer a widget
7453 * Widgets are double buffered by default; you can use this function
7454 * to turn off the buffering. "Double buffered" simply means that
7455 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7456 * automatically around expose events sent to the
7457 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7458 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7459 * buffer to the screen. The result is that users see the window
7460 * update in one smooth step, and don't see individual graphics
7461 * primitives being rendered.
7463 * In very simple terms, double buffered widgets don't flicker,
7464 * so you would only use this function to turn off double buffering
7465 * if you had special needs and really knew what you were doing.
7467 * Note: if you turn off double-buffering, you have to handle
7468 * expose events, since even the clearing to the background color or
7469 * pixmap will not happen automatically (as it is done in
7470 * gdk_window_begin_paint()).
7473 gtk_widget_set_double_buffered (GtkWidget *widget,
7474 gboolean double_buffered)
7476 g_return_if_fail (GTK_IS_WIDGET (widget));
7478 double_buffered = (double_buffered != FALSE);
7480 if (widget->priv->double_buffered != double_buffered)
7482 widget->priv->double_buffered = double_buffered;
7484 g_object_notify (G_OBJECT (widget), "double-buffered");
7489 * gtk_widget_get_double_buffered:
7490 * @widget: a #GtkWidget
7492 * Determines whether the widget is double buffered.
7494 * See gtk_widget_set_double_buffered()
7496 * Return value: %TRUE if the widget is double buffered
7501 gtk_widget_get_double_buffered (GtkWidget *widget)
7503 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7505 return widget->priv->double_buffered;
7509 * gtk_widget_set_redraw_on_allocate:
7510 * @widget: a #GtkWidget
7511 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7512 * when it is allocated to a new size. Otherwise, only the
7513 * new portion of the widget will be redrawn.
7515 * Sets whether the entire widget is queued for drawing when its size
7516 * allocation changes. By default, this setting is %TRUE and
7517 * the entire widget is redrawn on every size change. If your widget
7518 * leaves the upper left unchanged when made bigger, turning this
7519 * setting off will improve performance.
7521 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7522 * off all allocation on resizing: the widget will not even redraw if
7523 * its position changes; this is to allow containers that don't draw
7524 * anything to avoid excess invalidations. If you set this flag on a
7525 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7526 * you are responsible for invalidating both the old and new allocation
7527 * of the widget when the widget is moved and responsible for invalidating
7528 * regions newly when the widget increases size.
7531 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7532 gboolean redraw_on_allocate)
7534 g_return_if_fail (GTK_IS_WIDGET (widget));
7536 widget->priv->redraw_on_alloc = redraw_on_allocate;
7540 * gtk_widget_set_sensitive:
7541 * @widget: a #GtkWidget
7542 * @sensitive: %TRUE to make the widget sensitive
7544 * Sets the sensitivity of a widget. A widget is sensitive if the user
7545 * can interact with it. Insensitive widgets are "grayed out" and the
7546 * user can't interact with them. Insensitive widgets are known as
7547 * "inactive", "disabled", or "ghosted" in some other toolkits.
7550 gtk_widget_set_sensitive (GtkWidget *widget,
7553 GtkWidgetPrivate *priv;
7556 g_return_if_fail (GTK_IS_WIDGET (widget));
7558 priv = widget->priv;
7560 sensitive = (sensitive != FALSE);
7562 if (widget->priv->sensitive == sensitive)
7565 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7569 widget->priv->sensitive = TRUE;
7570 data.operation = STATE_CHANGE_UNSET;
7574 widget->priv->sensitive = FALSE;
7575 data.operation = STATE_CHANGE_SET;
7578 data.use_forall = TRUE;
7581 data.parent_sensitive = gtk_widget_is_sensitive (priv->parent);
7583 data.parent_sensitive = TRUE;
7585 gtk_widget_propagate_state (widget, &data);
7587 if (gtk_widget_is_drawable (widget))
7588 gtk_widget_queue_draw (widget);
7590 g_object_notify (G_OBJECT (widget), "sensitive");
7594 * gtk_widget_get_sensitive:
7595 * @widget: a #GtkWidget
7597 * Returns the widget's sensitivity (in the sense of returning
7598 * the value that has been set using gtk_widget_set_sensitive()).
7600 * The effective sensitivity of a widget is however determined by both its
7601 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7603 * Returns: %TRUE if the widget is sensitive
7608 gtk_widget_get_sensitive (GtkWidget *widget)
7610 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7612 return widget->priv->sensitive;
7616 * gtk_widget_is_sensitive:
7617 * @widget: a #GtkWidget
7619 * Returns the widget's effective sensitivity, which means
7620 * it is sensitive itself and also its parent widget is sensntive
7622 * Returns: %TRUE if the widget is effectively sensitive
7627 gtk_widget_is_sensitive (GtkWidget *widget)
7629 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7631 return widget->priv->sensitive && widget->priv->parent_sensitive;
7635 _gtk_widget_update_path (GtkWidget *widget)
7637 if (widget->priv->path)
7639 gtk_widget_path_free (widget->priv->path);
7640 widget->priv->path = NULL;
7643 gtk_widget_get_path (widget);
7647 * gtk_widget_set_parent:
7648 * @widget: a #GtkWidget
7649 * @parent: parent container
7651 * This function is useful only when implementing subclasses of
7653 * Sets the container as the parent of @widget, and takes care of
7654 * some details such as updating the state and style of the child
7655 * to reflect its new location. The opposite function is
7656 * gtk_widget_unparent().
7659 gtk_widget_set_parent (GtkWidget *widget,
7662 GtkStateFlags parent_flags;
7663 GtkWidgetPrivate *priv;
7666 g_return_if_fail (GTK_IS_WIDGET (widget));
7667 g_return_if_fail (GTK_IS_WIDGET (parent));
7668 g_return_if_fail (widget != parent);
7670 priv = widget->priv;
7672 if (priv->parent != NULL)
7674 g_warning ("Can't set a parent on widget which has a parent\n");
7677 if (gtk_widget_is_toplevel (widget))
7679 g_warning ("Can't set a parent on a toplevel widget\n");
7683 /* keep this function in sync with gtk_menu_attach_to_widget()
7686 g_object_ref_sink (widget);
7688 gtk_widget_push_verify_invariants (widget);
7690 priv->parent = parent;
7692 parent_flags = gtk_widget_get_state_flags (parent);
7694 /* Merge both old state and current parent state,
7695 * We don't want the insensitive flag to propagate
7696 * to the new child though */
7697 data.flags = parent_flags & ~GTK_STATE_FLAG_INSENSITIVE;
7698 data.flags |= priv->state_flags;
7700 data.operation = STATE_CHANGE_REPLACE;
7701 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
7702 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7703 gtk_widget_propagate_state (widget, &data);
7705 gtk_widget_reset_rc_styles (widget);
7707 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7708 if (priv->parent->priv->anchored)
7709 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7710 g_object_notify (G_OBJECT (widget), "parent");
7712 /* Enforce realized/mapped invariants
7714 if (gtk_widget_get_realized (priv->parent))
7715 gtk_widget_realize (widget);
7717 if (gtk_widget_get_visible (priv->parent) &&
7718 gtk_widget_get_visible (widget))
7720 if (gtk_widget_get_child_visible (widget) &&
7721 gtk_widget_get_mapped (priv->parent))
7722 gtk_widget_map (widget);
7724 gtk_widget_queue_resize (widget);
7727 /* child may cause parent's expand to change, if the child is
7728 * expanded. If child is not expanded, then it can't modify the
7729 * parent's expand. If the child becomes expanded later then it will
7730 * queue compute_expand then. This optimization plus defaulting
7731 * newly-constructed widgets to need_compute_expand=FALSE should
7732 * mean that initially building a widget tree doesn't have to keep
7733 * walking up setting need_compute_expand on parents over and over.
7735 * We can't change a parent to need to expand unless we're visible.
7737 if (gtk_widget_get_visible (widget) &&
7738 (priv->need_compute_expand ||
7739 priv->computed_hexpand ||
7740 priv->computed_vexpand))
7742 gtk_widget_queue_compute_expand (parent);
7745 if (widget->priv->context)
7747 _gtk_widget_update_path (widget);
7748 gtk_style_context_set_path (widget->priv->context, widget->priv->path);
7750 gtk_style_context_set_screen (widget->priv->context,
7751 gtk_widget_get_screen (widget));
7754 gtk_widget_pop_verify_invariants (widget);
7758 * gtk_widget_get_parent:
7759 * @widget: a #GtkWidget
7761 * Returns the parent container of @widget.
7763 * Return value: (transfer none): the parent container of @widget, or %NULL
7766 gtk_widget_get_parent (GtkWidget *widget)
7768 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7770 return widget->priv->parent;
7773 /*****************************************
7775 * see docs/styles.txt
7776 *****************************************/
7779 * gtk_widget_style_attach:
7780 * @widget: a #GtkWidget
7782 * This function attaches the widget's #GtkStyle to the widget's
7783 * #GdkWindow. It is a replacement for
7786 * widget->style = gtk_style_attach (widget->style, widget->window);
7789 * and should only ever be called in a derived widget's "realize"
7790 * implementation which does not chain up to its parent class'
7791 * "realize" implementation, because one of the parent classes
7792 * (finally #GtkWidget) would attach the style itself.
7796 * Deprecated: 3.0. This step is unnecessary with #GtkStyleContext.
7799 gtk_widget_style_attach (GtkWidget *widget)
7801 GtkWidgetPrivate *priv;
7803 g_return_if_fail (GTK_IS_WIDGET (widget));
7804 g_return_if_fail (gtk_widget_get_realized (widget));
7806 priv = widget->priv;
7808 priv->style = gtk_style_attach (priv->style, priv->window);
7812 * gtk_widget_has_rc_style:
7813 * @widget: a #GtkWidget
7815 * Determines if the widget style has been looked up through the rc mechanism.
7817 * Returns: %TRUE if the widget has been looked up through the rc
7818 * mechanism, %FALSE otherwise.
7822 * Deprecated:3.0: Use #GtkStyleContext instead
7825 gtk_widget_has_rc_style (GtkWidget *widget)
7827 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7829 return widget->priv->rc_style;
7833 * gtk_widget_set_style:
7834 * @widget: a #GtkWidget
7835 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
7836 * gtk_widget_set_style() and go back to the default style
7838 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
7839 * want to use this function; it interacts badly with themes, because
7840 * themes work by replacing the #GtkStyle. Instead, use
7841 * gtk_widget_modify_style().
7843 * Deprecated:3.0: Use #GtkStyleContext instead
7846 gtk_widget_set_style (GtkWidget *widget,
7849 g_return_if_fail (GTK_IS_WIDGET (widget));
7853 * gtk_widget_ensure_style:
7854 * @widget: a #GtkWidget
7856 * Ensures that @widget has a style (@widget->style). Not a very useful
7857 * function; most of the time, if you want the style, the widget is
7858 * realized, and realized widgets are guaranteed to have a style
7861 * Deprecated:3.0: Use #GtkStyleContext instead
7864 gtk_widget_ensure_style (GtkWidget *widget)
7866 g_return_if_fail (GTK_IS_WIDGET (widget));
7868 if (!widget->priv->style ||
7869 widget->priv->style == gtk_widget_get_default_style ())
7873 if (widget->priv->style)
7874 g_object_unref (widget->priv->style);
7876 style = g_object_new (GTK_TYPE_STYLE,
7877 "context", gtk_widget_get_style_context (widget),
7880 widget->priv->style = g_object_ref (style);
7882 g_signal_emit (widget,
7883 widget_signals[STYLE_SET],
7886 g_object_unref (style);
7891 * gtk_widget_get_style:
7892 * @widget: a #GtkWidget
7894 * Simply an accessor function that returns @widget->style.
7896 * Return value: (transfer none): the widget's #GtkStyle
7898 * Deprecated:3.0: Use #GtkStyleContext instead
7901 gtk_widget_get_style (GtkWidget *widget)
7903 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7905 return widget->priv->style;
7909 * gtk_widget_modify_style:
7910 * @widget: a #GtkWidget
7911 * @style: the #GtkRcStyle holding the style modifications
7913 * Modifies style values on the widget. Modifications made using this
7914 * technique take precedence over style values set via an RC file,
7915 * however, they will be overriden if a style is explicitely set on
7916 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
7917 * is designed so each field can either be set or unset, so it is
7918 * possible, using this function, to modify some style values and
7919 * leave the others unchanged.
7921 * Note that modifications made with this function are not cumulative
7922 * with previous calls to gtk_widget_modify_style() or with such
7923 * functions as gtk_widget_modify_fg(). If you wish to retain
7924 * previous values, you must first call gtk_widget_get_modifier_style(),
7925 * make your modifications to the returned style, then call
7926 * gtk_widget_modify_style() with that style. On the other hand,
7927 * if you first call gtk_widget_modify_style(), subsequent calls
7928 * to such functions gtk_widget_modify_fg() will have a cumulative
7929 * effect with the initial modifications.
7931 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7934 gtk_widget_modify_style (GtkWidget *widget,
7937 g_return_if_fail (GTK_IS_WIDGET (widget));
7938 g_return_if_fail (GTK_IS_RC_STYLE (style));
7940 g_object_set_qdata_full (G_OBJECT (widget),
7942 gtk_rc_style_copy (style),
7943 (GDestroyNotify) g_object_unref);
7947 * gtk_widget_get_modifier_style:
7948 * @widget: a #GtkWidget
7950 * Returns the current modifier style for the widget. (As set by
7951 * gtk_widget_modify_style().) If no style has previously set, a new
7952 * #GtkRcStyle will be created with all values unset, and set as the
7953 * modifier style for the widget. If you make changes to this rc
7954 * style, you must call gtk_widget_modify_style(), passing in the
7955 * returned rc style, to make sure that your changes take effect.
7957 * Caution: passing the style back to gtk_widget_modify_style() will
7958 * normally end up destroying it, because gtk_widget_modify_style() copies
7959 * the passed-in style and sets the copy as the new modifier style,
7960 * thus dropping any reference to the old modifier style. Add a reference
7961 * to the modifier style if you want to keep it alive.
7963 * Return value: (transfer none): the modifier style for the widget.
7964 * This rc style is owned by the widget. If you want to keep a
7965 * pointer to value this around, you must add a refcount using
7968 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7971 gtk_widget_get_modifier_style (GtkWidget *widget)
7973 GtkRcStyle *rc_style;
7975 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7977 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7981 rc_style = gtk_rc_style_new ();
7982 g_object_set_qdata_full (G_OBJECT (widget),
7985 (GDestroyNotify) g_object_unref);
7992 gtk_widget_modify_color_component (GtkWidget *widget,
7993 GtkRcFlags component,
7995 const GdkColor *color)
7997 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
8004 rc_style->fg[state] = *color;
8007 rc_style->bg[state] = *color;
8010 rc_style->text[state] = *color;
8013 rc_style->base[state] = *color;
8016 g_assert_not_reached();
8019 rc_style->color_flags[state] |= component;
8022 rc_style->color_flags[state] &= ~component;
8024 gtk_widget_modify_style (widget, rc_style);
8028 modifier_style_changed (GtkModifierStyle *style,
8031 GtkStyleContext *context;
8033 context = gtk_widget_get_style_context (widget);
8034 gtk_style_context_invalidate (context);
8037 static GtkModifierStyle *
8038 _gtk_widget_get_modifier_properties (GtkWidget *widget)
8040 GtkModifierStyle *style;
8042 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
8044 if (G_UNLIKELY (!style))
8046 GtkStyleContext *context;
8048 style = gtk_modifier_style_new ();
8049 g_object_set_qdata_full (G_OBJECT (widget),
8050 quark_modifier_style,
8052 (GDestroyNotify) g_object_unref);
8054 g_signal_connect (style, "changed",
8055 G_CALLBACK (modifier_style_changed), widget);
8057 context = gtk_widget_get_style_context (widget);
8059 gtk_style_context_add_provider (context,
8060 GTK_STYLE_PROVIDER (style),
8061 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
8068 * gtk_widget_override_color:
8069 * @widget: a #GtkWidget
8070 * @state: the state for which to set the color
8071 * @color: the color to assign, or %NULL to undo the effect
8072 * of previous calls to gtk_widget_override_color()
8074 * Sets the color to use for a widget. All other style values are left
8079 * This API is mostly meant as a quick way for applications to change a
8080 * widget appearance. If you are developing a widgets library and intend
8081 * this change to be themeable, it is better done by setting meaningful
8082 * CSS classes and regions in your widget/container implementation through
8083 * gtk_style_context_add_class() and gtk_style_context_add_region().
8086 * This way, your widget library can install a #GtkCssProvider with the
8087 * %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order to provide a
8088 * default styling for those widgets that need so, and this theming may
8089 * fully overridden by the user's theme.
8095 * Note that for complex widgets this may bring in
8096 * undesired results (such as uniform background color everywhere),
8097 * in these cases it is better to fully style such widgets through a
8098 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8106 gtk_widget_override_color (GtkWidget *widget,
8107 GtkStateFlags state,
8108 const GdkRGBA *color)
8110 GtkModifierStyle *style;
8112 g_return_if_fail (GTK_IS_WIDGET (widget));
8114 style = _gtk_widget_get_modifier_properties (widget);
8115 gtk_modifier_style_set_color (style, state, color);
8119 * gtk_widget_override_background_color:
8120 * @widget: a #GtkWidget
8121 * @state: the state for which to set the background color
8122 * @color: the color to assign, or %NULL to undo the effect
8123 * of previous calls to gtk_widget_override_background_color()
8125 * Sets the background color to use for a widget. All other style values
8126 * are left untouched. See gtk_widget_override_color().
8131 gtk_widget_override_background_color (GtkWidget *widget,
8132 GtkStateFlags state,
8133 const GdkRGBA *color)
8135 GtkModifierStyle *style;
8137 g_return_if_fail (GTK_IS_WIDGET (widget));
8139 style = _gtk_widget_get_modifier_properties (widget);
8140 gtk_modifier_style_set_background_color (style, state, color);
8144 * gtk_widget_override_font:
8145 * @widget: a #GtkWidget
8146 * @font_desc: the font descriptiong to use, or %NULL to undo
8147 * the effect of previous calls to
8148 * gtk_widget_override_font().
8150 * Sets the font to use for a widget. All other style values are
8151 * left untouched. See gtk_widget_override_color().
8156 gtk_widget_override_font (GtkWidget *widget,
8157 const PangoFontDescription *font_desc)
8159 GtkModifierStyle *style;
8161 g_return_if_fail (GTK_IS_WIDGET (widget));
8163 style = _gtk_widget_get_modifier_properties (widget);
8164 gtk_modifier_style_set_font (style, font_desc);
8168 * gtk_widget_override_symbolic_color:
8169 * @widget: a #GtkWidget
8170 * @name: the name of the symbolic color to modify
8171 * @color: (allow-none): the color to assign (does not need to be allocated),
8172 * or %NULL to undo the effect of previous calls to
8173 * gtk_widget_override_symbolic_color().
8175 * Sets a symbolic color for a widget, All other style values are left
8176 * untouched. See gtk_widget_override_color() for overriding the foreground
8177 * or background color.
8182 gtk_widget_override_symbolic_color (GtkWidget *widget,
8184 const GdkRGBA *color)
8186 GtkModifierStyle *style;
8188 g_return_if_fail (GTK_IS_WIDGET (widget));
8190 style = _gtk_widget_get_modifier_properties (widget);
8191 gtk_modifier_style_map_color (style, name, color);
8195 * gtk_widget_override_cursor:
8196 * @widget: a #GtkWidget
8197 * @cursor: the color to use for primary cursor (does not need to be
8198 * allocated), or %NULL to undo the effect of previous calls to
8199 * of gtk_widget_override_cursor().
8200 * @secondary_cursor: the color to use for secondary cursor (does not
8201 * need to be allocated), or %NULL to undo the effect of previous
8202 * calls to of gtk_widget_override_cursor().
8204 * Sets the cursor color to use in a widget, overriding the
8205 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8206 * style properties. All other style values are left untouched.
8207 * See also gtk_widget_modify_style().
8209 * Note that the underlying properties have the #GdkColor type,
8210 * so the alpha value in @primary and @secondary will be ignored.
8215 gtk_widget_override_cursor (GtkWidget *widget,
8216 const GdkRGBA *cursor,
8217 const GdkRGBA *secondary_cursor)
8219 GtkModifierStyle *style;
8221 g_return_if_fail (GTK_IS_WIDGET (widget));
8223 style = _gtk_widget_get_modifier_properties (widget);
8224 gtk_modifier_style_set_color_property (style,
8226 "cursor-color", cursor);
8227 gtk_modifier_style_set_color_property (style,
8229 "secondary-cursor-color",
8234 * gtk_widget_modify_fg:
8235 * @widget: a #GtkWidget
8236 * @state: the state for which to set the foreground color
8237 * @color: (allow-none): the color to assign (does not need to be allocated),
8238 * or %NULL to undo the effect of previous calls to
8239 * of gtk_widget_modify_fg().
8241 * Sets the foreground color for a widget in a particular state.
8242 * All other style values are left untouched. See also
8243 * gtk_widget_modify_style().
8245 * Deprecated:3.0: Use gtk_widget_override_color() instead
8248 gtk_widget_modify_fg (GtkWidget *widget,
8250 const GdkColor *color)
8252 GtkStateFlags flags;
8255 g_return_if_fail (GTK_IS_WIDGET (widget));
8256 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8260 case GTK_STATE_ACTIVE:
8261 flags = GTK_STATE_FLAG_ACTIVE;
8263 case GTK_STATE_PRELIGHT:
8264 flags = GTK_STATE_FLAG_PRELIGHT;
8266 case GTK_STATE_SELECTED:
8267 flags = GTK_STATE_FLAG_SELECTED;
8269 case GTK_STATE_INSENSITIVE:
8270 flags = GTK_STATE_FLAG_INSENSITIVE;
8272 case GTK_STATE_NORMAL:
8279 rgba.red = color->red / 65535.;
8280 rgba.green = color->green / 65535.;
8281 rgba.blue = color->blue / 65535.;
8284 gtk_widget_override_color (widget, state, &rgba);
8287 gtk_widget_override_color (widget, state, NULL);
8291 * gtk_widget_modify_bg:
8292 * @widget: a #GtkWidget
8293 * @state: the state for which to set the background color
8294 * @color: (allow-none): the color to assign (does not need to be allocated),
8295 * or %NULL to undo the effect of previous calls to
8296 * of gtk_widget_modify_bg().
8298 * Sets the background color for a widget in a particular state.
8299 * All other style values are left untouched. See also
8300 * gtk_widget_modify_style().
8302 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
8303 * draw on their parent container's window and thus may not draw any
8304 * background themselves. This is the case for e.g. #GtkLabel. To modify
8305 * the background of such widgets, you have to set the background color
8306 * on their parent; if you want to set the background of a rectangular
8307 * area around a label, try placing the label in a #GtkEventBox widget
8308 * and setting the background color on that.
8310 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8313 gtk_widget_modify_bg (GtkWidget *widget,
8315 const GdkColor *color)
8317 GtkStateFlags flags;
8320 g_return_if_fail (GTK_IS_WIDGET (widget));
8321 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8325 case GTK_STATE_ACTIVE:
8326 flags = GTK_STATE_FLAG_ACTIVE;
8328 case GTK_STATE_PRELIGHT:
8329 flags = GTK_STATE_FLAG_PRELIGHT;
8331 case GTK_STATE_SELECTED:
8332 flags = GTK_STATE_FLAG_SELECTED;
8334 case GTK_STATE_INSENSITIVE:
8335 flags = GTK_STATE_FLAG_INSENSITIVE;
8337 case GTK_STATE_NORMAL:
8344 rgba.red = color->red / 65535.;
8345 rgba.green = color->green / 65535.;
8346 rgba.blue = color->blue / 65535.;
8349 gtk_widget_override_background_color (widget, state, &rgba);
8352 gtk_widget_override_background_color (widget, state, NULL);
8356 * gtk_widget_modify_text:
8357 * @widget: a #GtkWidget
8358 * @state: the state for which to set the text color
8359 * @color: (allow-none): the color to assign (does not need to be allocated),
8360 * or %NULL to undo the effect of previous calls to
8361 * of gtk_widget_modify_text().
8363 * Sets the text color for a widget in a particular state. All other
8364 * style values are left untouched. The text color is the foreground
8365 * color used along with the base color (see gtk_widget_modify_base())
8366 * for widgets such as #GtkEntry and #GtkTextView. See also
8367 * gtk_widget_modify_style().
8369 * Deprecated:3.0: Use gtk_widget_override_color() instead
8372 gtk_widget_modify_text (GtkWidget *widget,
8374 const GdkColor *color)
8376 g_return_if_fail (GTK_IS_WIDGET (widget));
8377 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8379 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
8383 * gtk_widget_modify_base:
8384 * @widget: a #GtkWidget
8385 * @state: the state for which to set the base color
8386 * @color: (allow-none): the color to assign (does not need to be allocated),
8387 * or %NULL to undo the effect of previous calls to
8388 * of gtk_widget_modify_base().
8390 * Sets the base color for a widget in a particular state.
8391 * All other style values are left untouched. The base color
8392 * is the background color used along with the text color
8393 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
8394 * and #GtkTextView. See also gtk_widget_modify_style().
8396 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
8397 * draw on their parent container's window and thus may not draw any
8398 * background themselves. This is the case for e.g. #GtkLabel. To modify
8399 * the background of such widgets, you have to set the base color on their
8400 * parent; if you want to set the background of a rectangular area around
8401 * a label, try placing the label in a #GtkEventBox widget and setting
8402 * the base color on that.
8404 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8407 gtk_widget_modify_base (GtkWidget *widget,
8409 const GdkColor *color)
8411 g_return_if_fail (GTK_IS_WIDGET (widget));
8412 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8414 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
8418 * gtk_widget_modify_cursor:
8419 * @widget: a #GtkWidget
8420 * @primary: the color to use for primary cursor (does not need to be
8421 * allocated), or %NULL to undo the effect of previous calls to
8422 * of gtk_widget_modify_cursor().
8423 * @secondary: the color to use for secondary cursor (does not need to be
8424 * allocated), or %NULL to undo the effect of previous calls to
8425 * of gtk_widget_modify_cursor().
8427 * Sets the cursor color to use in a widget, overriding the
8428 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8429 * style properties. All other style values are left untouched.
8430 * See also gtk_widget_modify_style().
8434 * Deprecated: 3.0. Use gtk_widget_override_cursor() instead.
8437 gtk_widget_modify_cursor (GtkWidget *widget,
8438 const GdkColor *primary,
8439 const GdkColor *secondary)
8441 GdkRGBA primary_rgba, secondary_rgba;
8443 g_return_if_fail (GTK_IS_WIDGET (widget));
8445 primary_rgba.red = primary->red / 65535.;
8446 primary_rgba.green = primary->green / 65535.;
8447 primary_rgba.blue = primary->blue / 65535.;
8448 primary_rgba.alpha = 1;
8450 secondary_rgba.red = secondary->red / 65535.;
8451 secondary_rgba.green = secondary->green / 65535.;
8452 secondary_rgba.blue = secondary->blue / 65535.;
8453 secondary_rgba.alpha = 1;
8455 gtk_widget_override_cursor (widget, &primary_rgba, &secondary_rgba);
8459 * gtk_widget_modify_font:
8460 * @widget: a #GtkWidget
8461 * @font_desc: (allow-none): the font description to use, or %NULL to undo
8462 * the effect of previous calls to gtk_widget_modify_font().
8464 * Sets the font to use for a widget. All other style values are left
8465 * untouched. See also gtk_widget_modify_style().
8467 * Deprecated:3.0: Use gtk_widget_override_font() instead
8470 gtk_widget_modify_font (GtkWidget *widget,
8471 PangoFontDescription *font_desc)
8473 g_return_if_fail (GTK_IS_WIDGET (widget));
8475 gtk_widget_override_font (widget, font_desc);
8479 gtk_widget_real_direction_changed (GtkWidget *widget,
8480 GtkTextDirection previous_direction)
8482 gtk_widget_queue_resize (widget);
8486 gtk_widget_real_style_set (GtkWidget *widget,
8487 GtkStyle *previous_style)
8492 GtkWidget *previous_toplevel;
8493 GdkScreen *previous_screen;
8494 GdkScreen *new_screen;
8495 } HierarchyChangedInfo;
8498 do_screen_change (GtkWidget *widget,
8499 GdkScreen *old_screen,
8500 GdkScreen *new_screen)
8502 if (old_screen != new_screen)
8504 GtkStyleContext *context;
8508 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8510 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8513 _gtk_tooltip_hide (widget);
8515 context = gtk_widget_get_style_context (widget);
8516 gtk_style_context_set_screen (context, gtk_widget_get_screen (widget));
8518 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8523 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8524 gpointer client_data)
8526 GtkWidgetPrivate *priv = widget->priv;
8527 HierarchyChangedInfo *info = client_data;
8528 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8529 (priv->parent && priv->parent->priv->anchored);
8531 if (priv->anchored != new_anchored)
8533 g_object_ref (widget);
8535 priv->anchored = new_anchored;
8537 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8538 do_screen_change (widget, info->previous_screen, info->new_screen);
8540 if (GTK_IS_CONTAINER (widget))
8541 gtk_container_forall (GTK_CONTAINER (widget),
8542 gtk_widget_propagate_hierarchy_changed_recurse,
8545 g_object_unref (widget);
8550 * _gtk_widget_propagate_hierarchy_changed:
8551 * @widget: a #GtkWidget
8552 * @previous_toplevel: Previous toplevel
8554 * Propagates changes in the anchored state to a widget and all
8555 * children, unsetting or setting the %ANCHORED flag, and
8556 * emitting #GtkWidget::hierarchy-changed.
8559 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8560 GtkWidget *previous_toplevel)
8562 GtkWidgetPrivate *priv = widget->priv;
8563 HierarchyChangedInfo info;
8565 info.previous_toplevel = previous_toplevel;
8566 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8568 if (gtk_widget_is_toplevel (widget) ||
8569 (priv->parent && priv->parent->priv->anchored))
8570 info.new_screen = gtk_widget_get_screen (widget);
8572 info.new_screen = NULL;
8574 if (info.previous_screen)
8575 g_object_ref (info.previous_screen);
8576 if (previous_toplevel)
8577 g_object_ref (previous_toplevel);
8579 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8581 if (previous_toplevel)
8582 g_object_unref (previous_toplevel);
8583 if (info.previous_screen)
8584 g_object_unref (info.previous_screen);
8588 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8589 gpointer client_data)
8591 HierarchyChangedInfo *info = client_data;
8593 g_object_ref (widget);
8595 do_screen_change (widget, info->previous_screen, info->new_screen);
8597 if (GTK_IS_CONTAINER (widget))
8598 gtk_container_forall (GTK_CONTAINER (widget),
8599 gtk_widget_propagate_screen_changed_recurse,
8602 g_object_unref (widget);
8606 * gtk_widget_is_composited:
8607 * @widget: a #GtkWidget
8609 * Whether @widget can rely on having its alpha channel
8610 * drawn correctly. On X11 this function returns whether a
8611 * compositing manager is running for @widget's screen.
8613 * Please note that the semantics of this call will change
8614 * in the future if used on a widget that has a composited
8615 * window in its hierarchy (as set by gdk_window_set_composited()).
8617 * Return value: %TRUE if the widget can rely on its alpha
8618 * channel being drawn correctly.
8623 gtk_widget_is_composited (GtkWidget *widget)
8627 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8629 screen = gtk_widget_get_screen (widget);
8631 return gdk_screen_is_composited (screen);
8635 propagate_composited_changed (GtkWidget *widget,
8638 if (GTK_IS_CONTAINER (widget))
8640 gtk_container_forall (GTK_CONTAINER (widget),
8641 propagate_composited_changed,
8645 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8649 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8651 propagate_composited_changed (widget, NULL);
8655 * _gtk_widget_propagate_screen_changed:
8656 * @widget: a #GtkWidget
8657 * @previous_screen: Previous screen
8659 * Propagates changes in the screen for a widget to all
8660 * children, emitting #GtkWidget::screen-changed.
8663 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8664 GdkScreen *previous_screen)
8666 HierarchyChangedInfo info;
8668 info.previous_screen = previous_screen;
8669 info.new_screen = gtk_widget_get_screen (widget);
8671 if (previous_screen)
8672 g_object_ref (previous_screen);
8674 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8676 if (previous_screen)
8677 g_object_unref (previous_screen);
8681 reset_style_recurse (GtkWidget *widget, gpointer data)
8683 if (widget->priv->context)
8685 _gtk_widget_update_path (widget);
8686 gtk_style_context_set_path (widget->priv->context,
8687 widget->priv->path);
8690 if (GTK_IS_CONTAINER (widget))
8691 gtk_container_forall (GTK_CONTAINER (widget),
8692 reset_style_recurse,
8697 * gtk_widget_reset_style:
8698 * @widget: a #GtkWidget
8700 * Updates the style context of @widget and all descendents
8701 * by updating its widget path. #GtkContainer<!-- -->s may want
8702 * to use this on a child when reordering it in a way that a different
8703 * style might apply to it. See also gtk_container_get_path_for_child().
8708 gtk_widget_reset_style (GtkWidget *widget)
8710 g_return_if_fail (GTK_IS_WIDGET (widget));
8712 reset_style_recurse (widget, NULL);
8716 * gtk_widget_reset_rc_styles:
8717 * @widget: a #GtkWidget.
8719 * Reset the styles of @widget and all descendents, so when
8720 * they are looked up again, they get the correct values
8721 * for the currently loaded RC file settings.
8723 * This function is not useful for applications.
8725 * Deprecated:3.0: Use #GtkStyleContext instead
8728 gtk_widget_reset_rc_styles (GtkWidget *widget)
8730 g_return_if_fail (GTK_IS_WIDGET (widget));
8732 reset_style_recurse (widget, NULL);
8736 * gtk_widget_get_default_style:
8738 * Returns the default style used by all widgets initially.
8740 * Returns: (transfer none): the default style. This #GtkStyle
8741 * object is owned by GTK+ and should not be modified or freed.
8743 * Deprecated:3.0: Use #GtkStyleContext instead
8746 gtk_widget_get_default_style (void)
8748 if (!gtk_default_style)
8750 gtk_default_style = gtk_style_new ();
8751 g_object_ref (gtk_default_style);
8754 return gtk_default_style;
8757 #ifdef G_ENABLE_DEBUG
8759 /* Verify invariants, see docs/widget_system.txt for notes on much of
8760 * this. Invariants may be temporarily broken while we're in the
8761 * process of updating state, of course, so you can only
8762 * verify_invariants() after a given operation is complete.
8763 * Use push/pop_verify_invariants to help with that.
8766 gtk_widget_verify_invariants (GtkWidget *widget)
8770 if (widget->priv->verifying_invariants_count > 0)
8773 parent = widget->priv->parent;
8775 if (widget->priv->mapped)
8777 /* Mapped implies ... */
8779 if (!widget->priv->realized)
8780 g_warning ("%s %p is mapped but not realized",
8781 G_OBJECT_TYPE_NAME (widget), widget);
8783 if (!widget->priv->visible)
8784 g_warning ("%s %p is mapped but not visible",
8785 G_OBJECT_TYPE_NAME (widget), widget);
8787 if (!widget->priv->toplevel)
8789 if (!widget->priv->child_visible)
8790 g_warning ("%s %p is mapped but not child_visible",
8791 G_OBJECT_TYPE_NAME (widget), widget);
8796 /* Not mapped implies... */
8799 /* This check makes sense for normal toplevels, but for
8800 * something like a toplevel that is embedded within a clutter
8801 * state, mapping may depend on external factors.
8803 if (widget->priv->toplevel)
8805 if (widget->priv->visible)
8806 g_warning ("%s %p toplevel is visible but not mapped",
8807 G_OBJECT_TYPE_NAME (widget), widget);
8812 /* Parent related checks aren't possible if parent has
8813 * verifying_invariants_count > 0 because parent needs to recurse
8814 * children first before the invariants will hold.
8816 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8819 parent->priv->realized)
8821 /* Parent realized implies... */
8824 /* This is in widget_system.txt but appears to fail
8825 * because there's no gtk_container_realize() that
8826 * realizes all children... instead we just lazily
8827 * wait for map to fix things up.
8829 if (!widget->priv->realized)
8830 g_warning ("%s %p is realized but child %s %p is not realized",
8831 G_OBJECT_TYPE_NAME (parent), parent,
8832 G_OBJECT_TYPE_NAME (widget), widget);
8835 else if (!widget->priv->toplevel)
8837 /* No parent or parent not realized on non-toplevel implies... */
8839 if (widget->priv->realized && !widget->priv->in_reparent)
8840 g_warning ("%s %p is not realized but child %s %p is realized",
8841 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8842 G_OBJECT_TYPE_NAME (widget), widget);
8846 parent->priv->mapped &&
8847 widget->priv->visible &&
8848 widget->priv->child_visible)
8850 /* Parent mapped and we are visible implies... */
8852 if (!widget->priv->mapped)
8853 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8854 G_OBJECT_TYPE_NAME (parent), parent,
8855 G_OBJECT_TYPE_NAME (widget), widget);
8857 else if (!widget->priv->toplevel)
8859 /* No parent or parent not mapped on non-toplevel implies... */
8861 if (widget->priv->mapped && !widget->priv->in_reparent)
8862 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8863 G_OBJECT_TYPE_NAME (widget), widget,
8864 widget->priv->visible,
8865 widget->priv->child_visible,
8866 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8867 parent ? parent->priv->mapped : FALSE);
8871 if (!widget->priv->realized)
8873 /* Not realized implies... */
8876 /* widget_system.txt says these hold, but they don't. */
8877 if (widget->priv->resize_pending)
8878 g_warning ("%s %p resize pending but not realized",
8879 G_OBJECT_TYPE_NAME (widget), widget);
8881 if (widget->priv->alloc_needed)
8882 g_warning ("%s %p alloc needed but not realized",
8883 G_OBJECT_TYPE_NAME (widget), widget);
8885 if (widget->priv->width_request_needed)
8886 g_warning ("%s %p width request needed but not realized",
8887 G_OBJECT_TYPE_NAME (widget), widget);
8889 if (widget->priv->height_request_needed)
8890 g_warning ("%s %p height request needed but not realized",
8891 G_OBJECT_TYPE_NAME (widget), widget);
8896 /* The point of this push/pop is that invariants may not hold while
8897 * we're busy making changes. So we only check at the outermost call
8898 * on the call stack, after we finish updating everything.
8901 gtk_widget_push_verify_invariants (GtkWidget *widget)
8903 widget->priv->verifying_invariants_count += 1;
8907 gtk_widget_verify_child_invariants (GtkWidget *widget,
8908 gpointer client_data)
8910 /* We don't recurse further; this is a one-level check. */
8911 gtk_widget_verify_invariants (widget);
8915 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8917 g_assert (widget->priv->verifying_invariants_count > 0);
8919 widget->priv->verifying_invariants_count -= 1;
8921 if (widget->priv->verifying_invariants_count == 0)
8923 gtk_widget_verify_invariants (widget);
8925 if (GTK_IS_CONTAINER (widget))
8927 /* Check one level of children, because our
8928 * push_verify_invariants() will have prevented some of the
8929 * checks. This does not recurse because if recursion is
8930 * needed, it will happen naturally as each child has a
8931 * push/pop on that child. For example if we're recursively
8932 * mapping children, we'll push/pop on each child as we map
8935 gtk_container_forall (GTK_CONTAINER (widget),
8936 gtk_widget_verify_child_invariants,
8941 #endif /* G_ENABLE_DEBUG */
8943 static PangoContext *
8944 gtk_widget_peek_pango_context (GtkWidget *widget)
8946 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8950 * gtk_widget_get_pango_context:
8951 * @widget: a #GtkWidget
8953 * Gets a #PangoContext with the appropriate font map, font description,
8954 * and base direction for this widget. Unlike the context returned
8955 * by gtk_widget_create_pango_context(), this context is owned by
8956 * the widget (it can be used until the screen for the widget changes
8957 * or the widget is removed from its toplevel), and will be updated to
8958 * match any changes to the widget's attributes.
8960 * If you create and keep a #PangoLayout using this context, you must
8961 * deal with changes to the context by calling pango_layout_context_changed()
8962 * on the layout in response to the #GtkWidget::style-updated and
8963 * #GtkWidget::direction-changed signals for the widget.
8965 * Return value: (transfer none): the #PangoContext for the widget.
8968 gtk_widget_get_pango_context (GtkWidget *widget)
8970 PangoContext *context;
8972 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8974 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8977 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8978 g_object_set_qdata_full (G_OBJECT (widget),
8979 quark_pango_context,
8988 update_pango_context (GtkWidget *widget,
8989 PangoContext *context)
8991 PangoFontDescription *font_desc;
8992 GtkStyleContext *style_context;
8994 style_context = gtk_widget_get_style_context (widget);
8996 gtk_style_context_get (style_context,
8997 gtk_widget_get_state_flags (widget),
9001 pango_context_set_font_description (context, font_desc);
9002 pango_context_set_base_dir (context,
9003 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
9004 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
9006 pango_font_description_free (font_desc);
9010 gtk_widget_update_pango_context (GtkWidget *widget)
9012 PangoContext *context = gtk_widget_peek_pango_context (widget);
9018 update_pango_context (widget, context);
9020 screen = gtk_widget_get_screen_unchecked (widget);
9023 pango_cairo_context_set_resolution (context,
9024 gdk_screen_get_resolution (screen));
9025 pango_cairo_context_set_font_options (context,
9026 gdk_screen_get_font_options (screen));
9032 * gtk_widget_create_pango_context:
9033 * @widget: a #GtkWidget
9035 * Creates a new #PangoContext with the appropriate font map,
9036 * font description, and base direction for drawing text for
9037 * this widget. See also gtk_widget_get_pango_context().
9039 * Return value: (transfer full): the new #PangoContext
9042 gtk_widget_create_pango_context (GtkWidget *widget)
9045 PangoContext *context;
9047 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9049 screen = gtk_widget_get_screen_unchecked (widget);
9052 GTK_NOTE (MULTIHEAD,
9053 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
9055 screen = gdk_screen_get_default ();
9058 context = gdk_pango_context_get_for_screen (screen);
9060 update_pango_context (widget, context);
9061 pango_context_set_language (context, gtk_get_default_language ());
9067 * gtk_widget_create_pango_layout:
9068 * @widget: a #GtkWidget
9069 * @text: text to set on the layout (can be %NULL)
9071 * Creates a new #PangoLayout with the appropriate font map,
9072 * font description, and base direction for drawing text for
9075 * If you keep a #PangoLayout created in this way around, in order to
9076 * notify the layout of changes to the base direction or font of this
9077 * widget, you must call pango_layout_context_changed() in response to
9078 * the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
9081 * Return value: (transfer full): the new #PangoLayout
9084 gtk_widget_create_pango_layout (GtkWidget *widget,
9087 PangoLayout *layout;
9088 PangoContext *context;
9090 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9092 context = gtk_widget_get_pango_context (widget);
9093 layout = pango_layout_new (context);
9096 pango_layout_set_text (layout, text, -1);
9102 * gtk_widget_render_icon_pixbuf:
9103 * @widget: a #GtkWidget
9104 * @stock_id: a stock ID
9105 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
9106 * render at the size of the source and don't scale (if there are
9107 * multiple source sizes, GTK+ picks one of the available sizes).
9109 * A convenience function that uses the theme engine and style
9110 * settings for @widget to look up @stock_id and render it to
9111 * a pixbuf. @stock_id should be a stock icon ID such as
9112 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
9113 * such as #GTK_ICON_SIZE_MENU.
9115 * The pixels in the returned #GdkPixbuf are shared with the rest of
9116 * the application and should not be modified. The pixbuf should be freed
9117 * after use with g_object_unref().
9119 * Return value: (transfer full): a new pixbuf, or %NULL if the
9120 * stock ID wasn't known
9125 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
9126 const gchar *stock_id,
9129 GtkStyleContext *context;
9130 GtkIconSet *icon_set;
9132 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9133 g_return_val_if_fail (stock_id != NULL, NULL);
9134 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
9136 context = gtk_widget_get_style_context (widget);
9137 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
9139 if (icon_set == NULL)
9142 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
9146 * gtk_widget_render_icon:
9147 * @widget: a #GtkWidget
9148 * @stock_id: a stock ID
9149 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
9150 * render at the size of the source and don't scale (if there are
9151 * multiple source sizes, GTK+ picks one of the available sizes).
9152 * @detail: (allow-none): render detail to pass to theme engine
9154 * A convenience function that uses the theme engine and RC file
9155 * settings for @widget to look up @stock_id and render it to
9156 * a pixbuf. @stock_id should be a stock icon ID such as
9157 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
9158 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
9159 * identifies the widget or code doing the rendering, so that
9160 * theme engines can special-case rendering for that widget or code.
9162 * The pixels in the returned #GdkPixbuf are shared with the rest of
9163 * the application and should not be modified. The pixbuf should be freed
9164 * after use with g_object_unref().
9166 * Return value: (transfer full): a new pixbuf, or %NULL if the
9167 * stock ID wasn't known
9169 * Deprecated: 3.0: Use gtk_widget_render_icon_pixbuf() instead.
9172 gtk_widget_render_icon (GtkWidget *widget,
9173 const gchar *stock_id,
9175 const gchar *detail)
9177 return gtk_widget_render_icon_pixbuf (widget, stock_id, size);
9181 * gtk_widget_set_parent_window:
9182 * @widget: a #GtkWidget.
9183 * @parent_window: the new parent window.
9185 * Sets a non default parent window for @widget.
9187 * For GtkWindow classes, setting a @parent_window effects whether
9188 * the window is a toplevel window or can be embedded into other
9192 * For GtkWindow classes, this needs to be called before the
9193 * window is realized.
9198 gtk_widget_set_parent_window (GtkWidget *widget,
9199 GdkWindow *parent_window)
9201 GdkWindow *old_parent_window;
9203 g_return_if_fail (GTK_IS_WIDGET (widget));
9205 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
9206 quark_parent_window);
9208 if (parent_window != old_parent_window)
9210 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
9212 if (old_parent_window)
9213 g_object_unref (old_parent_window);
9215 g_object_ref (parent_window);
9217 /* Unset toplevel flag when adding a parent window to a widget,
9218 * this is the primary entry point to allow toplevels to be
9221 if (GTK_IS_WINDOW (widget) && !GTK_IS_PLUG (widget))
9222 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
9227 * gtk_widget_get_parent_window:
9228 * @widget: a #GtkWidget.
9230 * Gets @widget's parent window.
9232 * Returns: (transfer none): the parent window of @widget.
9235 gtk_widget_get_parent_window (GtkWidget *widget)
9237 GtkWidgetPrivate *priv;
9238 GdkWindow *parent_window;
9240 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9242 priv = widget->priv;
9244 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
9246 return (parent_window != NULL) ? parent_window :
9247 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
9252 * gtk_widget_set_child_visible:
9253 * @widget: a #GtkWidget
9254 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
9256 * Sets whether @widget should be mapped along with its when its parent
9257 * is mapped and @widget has been shown with gtk_widget_show().
9259 * The child visibility can be set for widget before it is added to
9260 * a container with gtk_widget_set_parent(), to avoid mapping
9261 * children unnecessary before immediately unmapping them. However
9262 * it will be reset to its default state of %TRUE when the widget
9263 * is removed from a container.
9265 * Note that changing the child visibility of a widget does not
9266 * queue a resize on the widget. Most of the time, the size of
9267 * a widget is computed from all visible children, whether or
9268 * not they are mapped. If this is not the case, the container
9269 * can queue a resize itself.
9271 * This function is only useful for container implementations and
9272 * never should be called by an application.
9275 gtk_widget_set_child_visible (GtkWidget *widget,
9276 gboolean is_visible)
9278 GtkWidgetPrivate *priv;
9280 g_return_if_fail (GTK_IS_WIDGET (widget));
9281 g_return_if_fail (!gtk_widget_is_toplevel (widget));
9283 priv = widget->priv;
9285 g_object_ref (widget);
9286 gtk_widget_verify_invariants (widget);
9289 priv->child_visible = TRUE;
9292 GtkWidget *toplevel;
9294 priv->child_visible = FALSE;
9296 toplevel = gtk_widget_get_toplevel (widget);
9297 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
9298 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
9301 if (priv->parent && gtk_widget_get_realized (priv->parent))
9303 if (gtk_widget_get_mapped (priv->parent) &&
9304 priv->child_visible &&
9305 gtk_widget_get_visible (widget))
9306 gtk_widget_map (widget);
9308 gtk_widget_unmap (widget);
9311 gtk_widget_verify_invariants (widget);
9312 g_object_unref (widget);
9316 * gtk_widget_get_child_visible:
9317 * @widget: a #GtkWidget
9319 * Gets the value set with gtk_widget_set_child_visible().
9320 * If you feel a need to use this function, your code probably
9321 * needs reorganization.
9323 * This function is only useful for container implementations and
9324 * never should be called by an application.
9326 * Return value: %TRUE if the widget is mapped with the parent.
9329 gtk_widget_get_child_visible (GtkWidget *widget)
9331 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9333 return widget->priv->child_visible;
9337 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9339 GtkWidget *toplevel;
9341 toplevel = gtk_widget_get_toplevel (widget);
9343 if (gtk_widget_is_toplevel (toplevel))
9345 if (GTK_IS_WINDOW (toplevel))
9346 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9347 else if (GTK_IS_INVISIBLE (toplevel))
9348 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9355 * gtk_widget_get_screen:
9356 * @widget: a #GtkWidget
9358 * Get the #GdkScreen from the toplevel window associated with
9359 * this widget. This function can only be called after the widget
9360 * has been added to a widget hierarchy with a #GtkWindow
9363 * In general, you should only create screen specific
9364 * resources when a widget has been realized, and you should
9365 * free those resources when the widget is unrealized.
9367 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9372 gtk_widget_get_screen (GtkWidget *widget)
9376 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9378 screen = gtk_widget_get_screen_unchecked (widget);
9385 g_warning (G_STRLOC ": Can't get associated screen"
9386 " for a widget unless it is inside a toplevel GtkWindow\n"
9387 " widget type is %s associated top level type is %s",
9388 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9389 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9391 return gdk_screen_get_default ();
9396 * gtk_widget_has_screen:
9397 * @widget: a #GtkWidget
9399 * Checks whether there is a #GdkScreen is associated with
9400 * this widget. All toplevel widgets have an associated
9401 * screen, and all widgets added into a hierarchy with a toplevel
9402 * window at the top.
9404 * Return value: %TRUE if there is a #GdkScreen associcated
9410 gtk_widget_has_screen (GtkWidget *widget)
9412 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9414 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9418 * gtk_widget_get_display:
9419 * @widget: a #GtkWidget
9421 * Get the #GdkDisplay for the toplevel window associated with
9422 * this widget. This function can only be called after the widget
9423 * has been added to a widget hierarchy with a #GtkWindow at the top.
9425 * In general, you should only create display specific
9426 * resources when a widget has been realized, and you should
9427 * free those resources when the widget is unrealized.
9429 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9434 gtk_widget_get_display (GtkWidget *widget)
9436 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9438 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9442 * gtk_widget_get_root_window:
9443 * @widget: a #GtkWidget
9445 * Get the root window where this widget is located. This function can
9446 * only be called after the widget has been added to a widget
9447 * hierarchy with #GtkWindow at the top.
9449 * The root window is useful for such purposes as creating a popup
9450 * #GdkWindow associated with the window. In general, you should only
9451 * create display specific resources when a widget has been realized,
9452 * and you should free those resources when the widget is unrealized.
9454 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9459 gtk_widget_get_root_window (GtkWidget *widget)
9461 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9463 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9467 * gtk_widget_child_focus:
9468 * @widget: a #GtkWidget
9469 * @direction: direction of focus movement
9471 * This function is used by custom widget implementations; if you're
9472 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9473 * to a particular widget, and gtk_container_set_focus_chain() to
9474 * change the focus tab order. So you may want to investigate those
9475 * functions instead.
9477 * gtk_widget_child_focus() is called by containers as the user moves
9478 * around the window using keyboard shortcuts. @direction indicates
9479 * what kind of motion is taking place (up, down, left, right, tab
9480 * forward, tab backward). gtk_widget_child_focus() emits the
9481 * #GtkWidget::focus signal; widgets override the default handler
9482 * for this signal in order to implement appropriate focus behavior.
9484 * The default ::focus handler for a widget should return %TRUE if
9485 * moving in @direction left the focus on a focusable location inside
9486 * that widget, and %FALSE if moving in @direction moved the focus
9487 * outside the widget. If returning %TRUE, widgets normally
9488 * call gtk_widget_grab_focus() to place the focus accordingly;
9489 * if returning %FALSE, they don't modify the current focus location.
9491 * Return value: %TRUE if focus ended up inside @widget
9494 gtk_widget_child_focus (GtkWidget *widget,
9495 GtkDirectionType direction)
9497 gboolean return_val;
9499 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9501 if (!gtk_widget_get_visible (widget) ||
9502 !gtk_widget_is_sensitive (widget))
9505 /* child widgets must set CAN_FOCUS, containers
9506 * don't have to though.
9508 if (!GTK_IS_CONTAINER (widget) &&
9509 !gtk_widget_get_can_focus (widget))
9512 g_signal_emit (widget,
9513 widget_signals[FOCUS],
9515 direction, &return_val);
9521 * gtk_widget_keynav_failed:
9522 * @widget: a #GtkWidget
9523 * @direction: direction of focus movement
9525 * This function should be called whenever keyboard navigation within
9526 * a single widget hits a boundary. The function emits the
9527 * #GtkWidget::keynav-failed signal on the widget and its return
9528 * value should be interpreted in a way similar to the return value of
9529 * gtk_widget_child_focus():
9531 * When %TRUE is returned, stay in the widget, the failed keyboard
9532 * navigation is Ok and/or there is nowhere we can/should move the
9535 * When %FALSE is returned, the caller should continue with keyboard
9536 * navigation outside the widget, e.g. by calling
9537 * gtk_widget_child_focus() on the widget's toplevel.
9539 * The default ::keynav-failed handler returns %TRUE for
9540 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9541 * values of #GtkDirectionType, it looks at the
9542 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9543 * if the setting is %TRUE. This way the entire user interface
9544 * becomes cursor-navigatable on input devices such as mobile phones
9545 * which only have cursor keys but no tab key.
9547 * Whenever the default handler returns %TRUE, it also calls
9548 * gtk_widget_error_bell() to notify the user of the failed keyboard
9551 * A use case for providing an own implementation of ::keynav-failed
9552 * (either by connecting to it or by overriding it) would be a row of
9553 * #GtkEntry widgets where the user should be able to navigate the
9554 * entire row with the cursor keys, as e.g. known from user interfaces
9555 * that require entering license keys.
9557 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9558 * if the emitting widget should try to handle the keyboard
9559 * navigation attempt in its parent container(s).
9564 gtk_widget_keynav_failed (GtkWidget *widget,
9565 GtkDirectionType direction)
9567 gboolean return_val;
9569 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9571 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9572 direction, &return_val);
9578 * gtk_widget_error_bell:
9579 * @widget: a #GtkWidget
9581 * Notifies the user about an input-related error on this widget.
9582 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9583 * gdk_window_beep(), otherwise it does nothing.
9585 * Note that the effect of gdk_window_beep() can be configured in many
9586 * ways, depending on the windowing backend and the desktop environment
9587 * or window manager that is used.
9592 gtk_widget_error_bell (GtkWidget *widget)
9594 GtkWidgetPrivate *priv;
9595 GtkSettings* settings;
9598 g_return_if_fail (GTK_IS_WIDGET (widget));
9600 priv = widget->priv;
9602 settings = gtk_widget_get_settings (widget);
9606 g_object_get (settings,
9607 "gtk-error-bell", &beep,
9610 if (beep && priv->window)
9611 gdk_window_beep (priv->window);
9615 gtk_widget_set_usize_internal (GtkWidget *widget,
9618 GtkQueueResizeFlags flags)
9620 GtkWidgetAuxInfo *aux_info;
9621 gboolean changed = FALSE;
9623 g_object_freeze_notify (G_OBJECT (widget));
9625 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
9627 if (width > -2 && aux_info->width != width)
9629 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9630 g_object_notify (G_OBJECT (widget), "width-request");
9631 aux_info->width = width;
9634 if (height > -2 && aux_info->height != height)
9636 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9637 g_object_notify (G_OBJECT (widget), "height-request");
9638 aux_info->height = height;
9642 if (gtk_widget_get_visible (widget) && changed)
9644 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9645 gtk_widget_queue_resize (widget);
9647 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9650 g_object_thaw_notify (G_OBJECT (widget));
9654 * gtk_widget_set_size_request:
9655 * @widget: a #GtkWidget
9656 * @width: width @widget should request, or -1 to unset
9657 * @height: height @widget should request, or -1 to unset
9659 * Sets the minimum size of a widget; that is, the widget's size
9660 * request will be @width by @height. You can use this function to
9661 * force a widget to be either larger or smaller than it normally
9664 * In most cases, gtk_window_set_default_size() is a better choice for
9665 * toplevel windows than this function; setting the default size will
9666 * still allow users to shrink the window. Setting the size request
9667 * will force them to leave the window at least as large as the size
9668 * request. When dealing with window sizes,
9669 * gtk_window_set_geometry_hints() can be a useful function as well.
9671 * Note the inherent danger of setting any fixed size - themes,
9672 * translations into other languages, different fonts, and user action
9673 * can all change the appropriate size for a given widget. So, it's
9674 * basically impossible to hardcode a size that will always be
9677 * The size request of a widget is the smallest size a widget can
9678 * accept while still functioning well and drawing itself correctly.
9679 * However in some strange cases a widget may be allocated less than
9680 * its requested size, and in many cases a widget may be allocated more
9681 * space than it requested.
9683 * If the size request in a given direction is -1 (unset), then
9684 * the "natural" size request of the widget will be used instead.
9686 * Widgets can't actually be allocated a size less than 1 by 1, but
9687 * you can pass 0,0 to this function to mean "as small as possible."
9689 * The size request set here does not include any margin from the
9690 * #GtkWidget properties margin-left, margin-right, margin-top, and
9691 * margin-bottom, but it does include pretty much all other padding
9692 * or border properties set by any subclass of #GtkWidget.
9695 gtk_widget_set_size_request (GtkWidget *widget,
9699 g_return_if_fail (GTK_IS_WIDGET (widget));
9700 g_return_if_fail (width >= -1);
9701 g_return_if_fail (height >= -1);
9708 gtk_widget_set_usize_internal (widget, width, height, 0);
9713 * gtk_widget_get_size_request:
9714 * @widget: a #GtkWidget
9715 * @width: (out) (allow-none): return location for width, or %NULL
9716 * @height: (out) (allow-none): return location for height, or %NULL
9718 * Gets the size request that was explicitly set for the widget using
9719 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9720 * @height indicates that that dimension has not been set explicitly
9721 * and the natural requisition of the widget will be used intead. See
9722 * gtk_widget_set_size_request(). To get the size a widget will
9723 * actually request, call gtk_widget_get_preferred_size() instead of
9727 gtk_widget_get_size_request (GtkWidget *widget,
9731 const GtkWidgetAuxInfo *aux_info;
9733 g_return_if_fail (GTK_IS_WIDGET (widget));
9735 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9738 *width = aux_info->width;
9741 *height = aux_info->height;
9745 * _gtk_widget_override_size_request:
9746 * @widget: a #GtkWidget
9747 * @width: new forced minimum width
9748 * @height: new forced minimum height
9749 * @old_width: location to store previous forced minimum width
9750 * @old_width: location to store previous forced minumum height
9752 * Temporarily establishes a forced minimum size for a widget; this
9753 * is used by GtkWindow when calculating the size to add to the
9754 * window's geometry widget. Cached sizes for the widget and its
9755 * parents are invalidated, so that subsequent calls to the size
9756 * negotiation machinery produce the overriden result, but the
9757 * widget is not queued for relayout or redraw. The old size must
9758 * be restored with _gtk_widget_restore_size_request() or things
9762 _gtk_widget_override_size_request (GtkWidget *widget,
9768 gtk_widget_get_size_request (widget, old_width, old_height);
9769 gtk_widget_set_usize_internal (widget, width, height,
9770 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9774 * _gtk_widget_restore_size_request:
9775 * @widget: a #GtkWidget
9776 * @old_width: saved forced minimum size
9777 * @old_height: saved forced minimum size
9779 * Undoes the operation of_gtk_widget_override_size_request().
9782 _gtk_widget_restore_size_request (GtkWidget *widget,
9786 gtk_widget_set_usize_internal (widget, old_width, old_height,
9787 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9791 * gtk_widget_set_events:
9792 * @widget: a #GtkWidget
9793 * @events: event mask
9795 * Sets the event mask (see #GdkEventMask) for a widget. The event
9796 * mask determines which events a widget will receive. Keep in mind
9797 * that different widgets have different default event masks, and by
9798 * changing the event mask you may disrupt a widget's functionality,
9799 * so be careful. This function must be called while a widget is
9800 * unrealized. Consider gtk_widget_add_events() for widgets that are
9801 * already realized, or if you want to preserve the existing event
9802 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9803 * to get events on those widgets, place them inside a #GtkEventBox
9804 * and receive events on the event box.
9807 gtk_widget_set_events (GtkWidget *widget,
9810 g_return_if_fail (GTK_IS_WIDGET (widget));
9811 g_return_if_fail (!gtk_widget_get_realized (widget));
9813 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9814 GINT_TO_POINTER (events));
9815 g_object_notify (G_OBJECT (widget), "events");
9819 * gtk_widget_set_device_events:
9820 * @widget: a #GtkWidget
9821 * @device: a #GdkDevice
9822 * @events: event mask
9824 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9825 * mask determines which events a widget will receive from @device. Keep
9826 * in mind that different widgets have different default event masks, and by
9827 * changing the event mask you may disrupt a widget's functionality,
9828 * so be careful. This function must be called while a widget is
9829 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9830 * already realized, or if you want to preserve the existing event
9831 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9832 * to get events on those widgets, place them inside a #GtkEventBox
9833 * and receive events on the event box.
9838 gtk_widget_set_device_events (GtkWidget *widget,
9840 GdkEventMask events)
9842 GHashTable *device_events;
9844 g_return_if_fail (GTK_IS_WIDGET (widget));
9845 g_return_if_fail (GDK_IS_DEVICE (device));
9846 g_return_if_fail (!gtk_widget_get_realized (widget));
9848 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9850 if (G_UNLIKELY (!device_events))
9852 device_events = g_hash_table_new (NULL, NULL);
9853 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9854 (GDestroyNotify) g_hash_table_unref);
9857 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9861 * gtk_widget_enable_device:
9862 * @widget: a #GtkWidget
9863 * @device: a #GdkDevice
9865 * Enables a #GdkDevice to interact with @widget and
9866 * all its children, it does so by descending through
9867 * the #GdkWindow hierarchy and enabling the same mask
9868 * that is has for core events (i.e. the one that
9869 * gdk_window_get_events() returns).
9874 gtk_widget_set_device_enabled (GtkWidget *widget,
9878 GList *enabled_devices;
9880 g_return_if_fail (GTK_IS_WIDGET (widget));
9881 g_return_if_fail (GDK_IS_DEVICE (device));
9883 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9884 enabled_devices = g_list_append (enabled_devices, device);
9886 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9887 enabled_devices, (GDestroyNotify) g_list_free);;
9889 if (gtk_widget_get_realized (widget))
9890 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9894 gtk_widget_get_device_enabled (GtkWidget *widget,
9897 GList *enabled_devices;
9899 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9900 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9902 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9904 return g_list_find (enabled_devices, device) != NULL;
9908 gtk_widget_add_events_internal_list (GtkWidget *widget,
9915 for (l = window_list; l != NULL; l = l->next)
9917 GdkWindow *window = l->data;
9920 gdk_window_get_user_data (window, &user_data);
9921 if (user_data == widget)
9926 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9928 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9930 children = gdk_window_get_children (window);
9931 gtk_widget_add_events_internal_list (widget, device, events, children);
9932 g_list_free (children);
9938 gtk_widget_add_events_internal (GtkWidget *widget,
9942 GtkWidgetPrivate *priv = widget->priv;
9945 if (!gtk_widget_get_has_window (widget))
9946 window_list = gdk_window_get_children (priv->window);
9948 window_list = g_list_prepend (NULL, priv->window);
9950 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9952 g_list_free (window_list);
9956 * gtk_widget_add_events:
9957 * @widget: a #GtkWidget
9958 * @events: an event mask, see #GdkEventMask
9960 * Adds the events in the bitfield @events to the event mask for
9961 * @widget. See gtk_widget_set_events() for details.
9964 gtk_widget_add_events (GtkWidget *widget,
9969 g_return_if_fail (GTK_IS_WIDGET (widget));
9971 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9972 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9973 GINT_TO_POINTER (old_events | events));
9975 if (gtk_widget_get_realized (widget))
9977 gtk_widget_add_events_internal (widget, NULL, events);
9978 gtk_widget_update_devices_mask (widget, FALSE);
9981 g_object_notify (G_OBJECT (widget), "events");
9985 * gtk_widget_add_device_events:
9986 * @widget: a #GtkWidget
9987 * @device: a #GdkDevice
9988 * @events: an event mask, see #GdkEventMask
9990 * Adds the device events in the bitfield @events to the event mask for
9991 * @widget. See gtk_widget_set_device_events() for details.
9996 gtk_widget_add_device_events (GtkWidget *widget,
9998 GdkEventMask events)
10000 GdkEventMask old_events;
10001 GHashTable *device_events;
10003 g_return_if_fail (GTK_IS_WIDGET (widget));
10004 g_return_if_fail (GDK_IS_DEVICE (device));
10006 old_events = gtk_widget_get_device_events (widget, device);
10008 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10010 if (G_UNLIKELY (!device_events))
10012 device_events = g_hash_table_new (NULL, NULL);
10013 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
10014 (GDestroyNotify) g_hash_table_unref);
10017 g_hash_table_insert (device_events, device,
10018 GUINT_TO_POINTER (old_events | events));
10020 if (gtk_widget_get_realized (widget))
10021 gtk_widget_add_events_internal (widget, device, events);
10023 g_object_notify (G_OBJECT (widget), "events");
10027 * gtk_widget_get_toplevel:
10028 * @widget: a #GtkWidget
10030 * This function returns the topmost widget in the container hierarchy
10031 * @widget is a part of. If @widget has no parent widgets, it will be
10032 * returned as the topmost widget. No reference will be added to the
10033 * returned widget; it should not be unreferenced.
10035 * Note the difference in behavior vs. gtk_widget_get_ancestor();
10036 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
10038 * %NULL if @widget wasn't inside a toplevel window, and if the
10039 * window was inside a #GtkWindow-derived widget which was in turn
10040 * inside the toplevel #GtkWindow. While the second case may
10041 * seem unlikely, it actually happens when a #GtkPlug is embedded
10042 * inside a #GtkSocket within the same application.
10044 * To reliably find the toplevel #GtkWindow, use
10045 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
10046 * is set on the result.
10048 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
10049 * if (gtk_widget_is_toplevel (toplevel))
10051 * /* Perform action on toplevel. */
10055 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
10056 * if there's no ancestor.
10059 gtk_widget_get_toplevel (GtkWidget *widget)
10061 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10063 while (widget->priv->parent)
10064 widget = widget->priv->parent;
10070 * gtk_widget_get_ancestor:
10071 * @widget: a #GtkWidget
10072 * @widget_type: ancestor type
10074 * Gets the first ancestor of @widget with type @widget_type. For example,
10075 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
10076 * the first #GtkBox that's an ancestor of @widget. No reference will be
10077 * added to the returned widget; it should not be unreferenced. See note
10078 * about checking for a toplevel #GtkWindow in the docs for
10079 * gtk_widget_get_toplevel().
10081 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
10082 * considers @widget to be an ancestor of itself.
10084 * Return value: (transfer none): the ancestor widget, or %NULL if not found
10087 gtk_widget_get_ancestor (GtkWidget *widget,
10090 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10092 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
10093 widget = widget->priv->parent;
10095 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
10102 * gtk_widget_set_visual:
10103 * @widget: a #GtkWidget
10104 * @visual: visual to be used or %NULL to unset a previous one
10106 * Sets the visual that should be used for by widget and its children for
10107 * creating #GdkWindows. The visual must be on the same #GdkScreen as
10108 * returned by gdk_widget_get_screen(), so handling the
10109 * #GtkWidget::screen-changed signal is necessary.
10111 * Setting a new @visual will not cause @widget to recreate its windows,
10112 * so you should call this function before @widget is realized.
10115 gtk_widget_set_visual (GtkWidget *widget,
10118 g_return_if_fail (GTK_IS_WIDGET (widget));
10119 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
10122 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
10125 g_object_set_qdata_full (G_OBJECT (widget),
10127 g_object_ref (visual),
10132 * gtk_widget_get_visual:
10133 * @widget: a #GtkWidget
10135 * Gets the visual that will be used to render @widget.
10137 * Return value: (transfer none): the visual for @widget
10140 gtk_widget_get_visual (GtkWidget *widget)
10146 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10148 if (gtk_widget_get_has_window (widget) &&
10149 widget->priv->window)
10150 return gdk_window_get_visual (widget->priv->window);
10152 screen = gtk_widget_get_screen (widget);
10154 for (w = widget; w != NULL; w = w->priv->parent)
10156 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
10159 if (gdk_visual_get_screen (visual) == screen)
10162 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
10163 gtk_widget_get_name (widget));
10167 return gdk_screen_get_system_visual (screen);
10171 * gtk_widget_get_settings:
10172 * @widget: a #GtkWidget
10174 * Gets the settings object holding the settings (global property
10175 * settings, RC file information, etc) used for this widget.
10177 * Note that this function can only be called when the #GtkWidget
10178 * is attached to a toplevel, since the settings object is specific
10179 * to a particular #GdkScreen.
10181 * Return value: (transfer none): the relevant #GtkSettings object
10184 gtk_widget_get_settings (GtkWidget *widget)
10186 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10188 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
10192 * gtk_widget_get_events:
10193 * @widget: a #GtkWidget
10195 * Returns the event mask for the widget (a bitfield containing flags
10196 * from the #GdkEventMask enumeration). These are the events that the widget
10199 * Return value: event mask for @widget
10202 gtk_widget_get_events (GtkWidget *widget)
10204 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10206 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10210 * gtk_widget_get_device_events:
10211 * @widget: a #GtkWidget
10212 * @device: a #GdkDevice
10214 * Returns the events mask for the widget corresponding to an specific device. These
10215 * are the events that the widget will receive when @device operates on it.
10217 * Returns: device event mask for @widget
10222 gtk_widget_get_device_events (GtkWidget *widget,
10225 GHashTable *device_events;
10227 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10228 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
10230 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10232 if (!device_events)
10235 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
10239 * gtk_widget_get_pointer:
10240 * @widget: a #GtkWidget
10241 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
10242 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
10244 * Obtains the location of the mouse pointer in widget coordinates.
10245 * Widget coordinates are a bit odd; for historical reasons, they are
10246 * defined as @widget->window coordinates for widgets that are not
10247 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
10248 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
10251 gtk_widget_get_pointer (GtkWidget *widget,
10255 GtkWidgetPrivate *priv;
10257 g_return_if_fail (GTK_IS_WIDGET (widget));
10259 priv = widget->priv;
10266 if (gtk_widget_get_realized (widget))
10268 gdk_window_get_pointer (priv->window, x, y, NULL);
10270 if (!gtk_widget_get_has_window (widget))
10273 *x -= priv->allocation.x;
10275 *y -= priv->allocation.y;
10281 * gtk_widget_is_ancestor:
10282 * @widget: a #GtkWidget
10283 * @ancestor: another #GtkWidget
10285 * Determines whether @widget is somewhere inside @ancestor, possibly with
10286 * intermediate containers.
10288 * Return value: %TRUE if @ancestor contains @widget as a child,
10289 * grandchild, great grandchild, etc.
10292 gtk_widget_is_ancestor (GtkWidget *widget,
10293 GtkWidget *ancestor)
10295 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10296 g_return_val_if_fail (ancestor != NULL, FALSE);
10300 if (widget->priv->parent == ancestor)
10302 widget = widget->priv->parent;
10308 static GQuark quark_composite_name = 0;
10311 * gtk_widget_set_composite_name:
10312 * @widget: a #GtkWidget.
10313 * @name: the name to set
10315 * Sets a widgets composite name. The widget must be
10316 * a composite child of its parent; see gtk_widget_push_composite_child().
10319 gtk_widget_set_composite_name (GtkWidget *widget,
10322 g_return_if_fail (GTK_IS_WIDGET (widget));
10323 g_return_if_fail (widget->priv->composite_child);
10324 g_return_if_fail (name != NULL);
10326 if (!quark_composite_name)
10327 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10329 g_object_set_qdata_full (G_OBJECT (widget),
10330 quark_composite_name,
10336 * gtk_widget_get_composite_name:
10337 * @widget: a #GtkWidget
10339 * Obtains the composite name of a widget.
10341 * Returns: the composite name of @widget, or %NULL if @widget is not
10342 * a composite child. The string should be freed when it is no
10346 gtk_widget_get_composite_name (GtkWidget *widget)
10348 GtkWidgetPrivate *priv;
10350 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10352 priv = widget->priv;
10354 if (widget->priv->composite_child && priv->parent)
10355 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10362 * gtk_widget_push_composite_child:
10364 * Makes all newly-created widgets as composite children until
10365 * the corresponding gtk_widget_pop_composite_child() call.
10367 * A composite child is a child that's an implementation detail of the
10368 * container it's inside and should not be visible to people using the
10369 * container. Composite children aren't treated differently by GTK (but
10370 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10371 * builders might want to treat them in a different way.
10373 * Here is a simple example:
10375 * gtk_widget_push_composite_child ();
10376 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10377 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10378 * gtk_widget_pop_composite_child ();
10379 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10380 * GTK_WIDGET (scrolled_window));
10381 * g_object_ref (scrolled_window->hscrollbar);
10385 gtk_widget_push_composite_child (void)
10387 composite_child_stack++;
10391 * gtk_widget_pop_composite_child:
10393 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10396 gtk_widget_pop_composite_child (void)
10398 if (composite_child_stack)
10399 composite_child_stack--;
10403 gtk_widget_emit_direction_changed (GtkWidget *widget,
10404 GtkTextDirection old_dir)
10406 gtk_widget_update_pango_context (widget);
10408 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10412 * gtk_widget_set_direction:
10413 * @widget: a #GtkWidget
10414 * @dir: the new direction
10416 * Sets the reading direction on a particular widget. This direction
10417 * controls the primary direction for widgets containing text,
10418 * and also the direction in which the children of a container are
10419 * packed. The ability to set the direction is present in order
10420 * so that correct localization into languages with right-to-left
10421 * reading directions can be done. Generally, applications will
10422 * let the default reading direction present, except for containers
10423 * where the containers are arranged in an order that is explicitely
10424 * visual rather than logical (such as buttons for text justification).
10426 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10427 * set by gtk_widget_set_default_direction() will be used.
10430 gtk_widget_set_direction (GtkWidget *widget,
10431 GtkTextDirection dir)
10433 GtkTextDirection old_dir;
10435 g_return_if_fail (GTK_IS_WIDGET (widget));
10436 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10438 old_dir = gtk_widget_get_direction (widget);
10440 widget->priv->direction = dir;
10442 if (old_dir != gtk_widget_get_direction (widget))
10444 if (widget->priv->context)
10445 gtk_style_context_set_direction (widget->priv->context,
10446 gtk_widget_get_direction (widget));
10448 gtk_widget_emit_direction_changed (widget, old_dir);
10453 * gtk_widget_get_direction:
10454 * @widget: a #GtkWidget
10456 * Gets the reading direction for a particular widget. See
10457 * gtk_widget_set_direction().
10459 * Return value: the reading direction for the widget.
10462 gtk_widget_get_direction (GtkWidget *widget)
10464 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10466 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10467 return gtk_default_direction;
10469 return widget->priv->direction;
10473 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10475 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10477 g_object_ref (widget);
10479 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10480 gtk_widget_emit_direction_changed (widget, old_dir);
10482 if (GTK_IS_CONTAINER (widget))
10483 gtk_container_forall (GTK_CONTAINER (widget),
10484 gtk_widget_set_default_direction_recurse,
10487 g_object_unref (widget);
10491 * gtk_widget_set_default_direction:
10492 * @dir: the new default direction. This cannot be
10493 * %GTK_TEXT_DIR_NONE.
10495 * Sets the default reading direction for widgets where the
10496 * direction has not been explicitly set by gtk_widget_set_direction().
10499 gtk_widget_set_default_direction (GtkTextDirection dir)
10501 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10503 if (dir != gtk_default_direction)
10505 GList *toplevels, *tmp_list;
10506 GtkTextDirection old_dir = gtk_default_direction;
10508 gtk_default_direction = dir;
10510 tmp_list = toplevels = gtk_window_list_toplevels ();
10511 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10515 gtk_widget_set_default_direction_recurse (tmp_list->data,
10516 GUINT_TO_POINTER (old_dir));
10517 g_object_unref (tmp_list->data);
10518 tmp_list = tmp_list->next;
10521 g_list_free (toplevels);
10526 * gtk_widget_get_default_direction:
10528 * Obtains the current default reading direction. See
10529 * gtk_widget_set_default_direction().
10531 * Return value: the current default direction.
10534 gtk_widget_get_default_direction (void)
10536 return gtk_default_direction;
10540 gtk_widget_dispose (GObject *object)
10542 GtkWidget *widget = GTK_WIDGET (object);
10543 GtkWidgetPrivate *priv = widget->priv;
10546 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10547 else if (gtk_widget_get_visible (widget))
10548 gtk_widget_hide (widget);
10550 priv->visible = FALSE;
10551 if (gtk_widget_get_realized (widget))
10552 gtk_widget_unrealize (widget);
10554 if (!priv->in_destruction)
10556 priv->in_destruction = TRUE;
10557 g_signal_emit (object, widget_signals[DESTROY], 0);
10558 priv->in_destruction = FALSE;
10561 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10565 gtk_widget_real_destroy (GtkWidget *object)
10567 /* gtk_object_destroy() will already hold a refcount on object */
10568 GtkWidget *widget = GTK_WIDGET (object);
10569 GtkWidgetPrivate *priv = widget->priv;
10571 /* wipe accelerator closures (keep order) */
10572 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10573 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10575 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10576 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10578 gtk_grab_remove (widget);
10580 g_object_unref (priv->style);
10581 priv->style = gtk_widget_get_default_style ();
10582 g_object_ref (priv->style);
10586 gtk_widget_finalize (GObject *object)
10588 GtkWidget *widget = GTK_WIDGET (object);
10589 GtkWidgetPrivate *priv = widget->priv;
10590 GtkWidgetAuxInfo *aux_info;
10591 GtkAccessible *accessible;
10593 gtk_grab_remove (widget);
10595 g_object_unref (priv->style);
10596 priv->style = NULL;
10598 g_free (priv->name);
10600 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
10602 gtk_widget_aux_info_destroy (aux_info);
10604 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10606 g_object_unref (accessible);
10609 gtk_widget_path_free (priv->path);
10612 g_object_unref (priv->context);
10614 if (g_object_is_floating (object))
10615 g_warning ("A floating object was finalized. This means that someone\n"
10616 "called g_object_unref() on an object that had only a floating\n"
10617 "reference; the initial floating reference is not owned by anyone\n"
10618 "and must be removed with g_object_ref_sink().");
10620 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10623 /*****************************************
10624 * gtk_widget_real_map:
10629 *****************************************/
10632 gtk_widget_real_map (GtkWidget *widget)
10634 GtkWidgetPrivate *priv = widget->priv;
10636 g_assert (gtk_widget_get_realized (widget));
10638 if (!gtk_widget_get_mapped (widget))
10640 gtk_widget_set_mapped (widget, TRUE);
10642 if (gtk_widget_get_has_window (widget))
10643 gdk_window_show (priv->window);
10647 /*****************************************
10648 * gtk_widget_real_unmap:
10653 *****************************************/
10656 gtk_widget_real_unmap (GtkWidget *widget)
10658 GtkWidgetPrivate *priv = widget->priv;
10660 if (gtk_widget_get_mapped (widget))
10662 gtk_widget_set_mapped (widget, FALSE);
10664 if (gtk_widget_get_has_window (widget))
10665 gdk_window_hide (priv->window);
10669 /*****************************************
10670 * gtk_widget_real_realize:
10675 *****************************************/
10678 gtk_widget_real_realize (GtkWidget *widget)
10680 GtkWidgetPrivate *priv = widget->priv;
10682 g_assert (!gtk_widget_get_has_window (widget));
10684 gtk_widget_set_realized (widget, TRUE);
10687 priv->window = gtk_widget_get_parent_window (widget);
10688 g_object_ref (priv->window);
10690 priv->style = gtk_style_attach (priv->style, priv->window);
10693 /*****************************************
10694 * gtk_widget_real_unrealize:
10699 *****************************************/
10702 gtk_widget_real_unrealize (GtkWidget *widget)
10704 GtkWidgetPrivate *priv = widget->priv;
10706 g_assert (!widget->priv->mapped);
10708 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10711 /* We must do unrealize child widget BEFORE container widget.
10712 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10713 * So, unrealizing container widget bofore its children causes the problem
10714 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10717 if (GTK_IS_CONTAINER (widget))
10718 gtk_container_forall (GTK_CONTAINER (widget),
10719 (GtkCallback) gtk_widget_unrealize,
10722 gtk_style_detach (priv->style);
10723 if (gtk_widget_get_has_window (widget))
10725 gdk_window_set_user_data (priv->window, NULL);
10726 gdk_window_destroy (priv->window);
10727 priv->window = NULL;
10731 g_object_unref (priv->window);
10732 priv->window = NULL;
10735 gtk_selection_remove_all (widget);
10737 gtk_widget_set_realized (widget, FALSE);
10741 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10742 GtkOrientation orientation,
10743 gint *minimum_size,
10744 gint *natural_size)
10746 const GtkWidgetAuxInfo *aux_info;
10748 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10750 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10751 aux_info->width > 0)
10753 *minimum_size = MAX (*minimum_size, aux_info->width);
10755 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10756 aux_info->height > 0)
10758 *minimum_size = MAX (*minimum_size, aux_info->height);
10761 /* Fix it if set_size_request made natural size smaller than min size.
10762 * This would also silently fix broken widgets, but we warn about them
10763 * in gtksizerequest.c when calling their size request vfuncs.
10765 *natural_size = MAX (*natural_size, *minimum_size);
10767 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10769 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10770 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10774 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10775 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10780 * _gtk_widget_peek_request_cache:
10782 * Returns the address of the widget's request cache (strictly for
10783 * internal use in gtksizerequest.c)
10785 * Return value: the address of @widget's size request cache.
10788 _gtk_widget_peek_request_cache (GtkWidget *widget)
10790 /* Don't bother slowing things down with the return_if_fail guards here */
10791 return &widget->priv->requests;
10795 * _gtk_widget_set_device_window:
10796 * @widget: a #GtkWidget.
10797 * @device: a #GdkDevice.
10798 * @window: the new device window.
10800 * Sets pointer window for @widget and @device. Does not ref @window.
10801 * Actually stores it on the #GdkScreen, but you don't need to know that.
10804 _gtk_widget_set_device_window (GtkWidget *widget,
10808 GtkWidgetPrivate *priv;
10810 GHashTable *device_window;
10812 g_return_if_fail (GTK_IS_WIDGET (widget));
10813 g_return_if_fail (GDK_IS_DEVICE (device));
10814 g_return_if_fail (!window || GDK_IS_WINDOW (window));
10816 priv = widget->priv;
10818 if (!gtk_widget_get_realized (widget))
10821 screen = gdk_window_get_screen (priv->window);
10822 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10824 if (G_UNLIKELY (!device_window))
10826 device_window = g_hash_table_new (NULL, NULL);
10827 g_object_set_qdata_full (G_OBJECT (screen),
10828 quark_pointer_window,
10830 (GDestroyNotify) g_hash_table_destroy);
10834 g_hash_table_insert (device_window, device, window);
10836 g_hash_table_remove (device_window, device);
10840 * _gtk_widget_get_device_window:
10841 * @widget: a #GtkWidget.
10842 * @device: a #GdkDevice.
10844 * Return value: the device window set on the #GdkScreen @widget is attached
10848 _gtk_widget_get_device_window (GtkWidget *widget,
10851 GtkWidgetPrivate *priv;
10853 GHashTable *device_window;
10857 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10858 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10860 priv = widget->priv;
10862 if (!gtk_widget_get_realized (widget))
10865 screen = gdk_window_get_screen (priv->window);
10866 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10868 if (G_UNLIKELY (!device_window))
10871 window = g_hash_table_lookup (device_window, device);
10876 gdk_window_get_user_data (window, (gpointer *) &w);
10885 * _gtk_widget_list_devices:
10886 * @widget: a #GtkWidget.
10888 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
10889 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
10893 _gtk_widget_list_devices (GtkWidget *widget)
10895 GtkWidgetPrivate *priv;
10897 GHashTableIter iter;
10898 GHashTable *device_window;
10899 GList *devices = NULL;
10900 gpointer key, value;
10902 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10904 priv = widget->priv;
10906 if (!gtk_widget_get_realized (widget))
10909 screen = gdk_window_get_screen (priv->window);
10910 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10912 if (G_UNLIKELY (!device_window))
10915 g_hash_table_iter_init (&iter, device_window);
10917 while (g_hash_table_iter_next (&iter, &key, &value))
10919 GdkDevice *device = key;
10920 GdkWindow *window = value;
10925 gdk_window_get_user_data (window, (gpointer *) &w);
10928 devices = g_list_prepend (devices, device);
10936 synth_crossing (GtkWidget *widget,
10940 GdkCrossingMode mode,
10941 GdkNotifyType detail)
10945 event = gdk_event_new (type);
10947 event->crossing.window = g_object_ref (window);
10948 event->crossing.send_event = TRUE;
10949 event->crossing.subwindow = g_object_ref (window);
10950 event->crossing.time = GDK_CURRENT_TIME;
10951 event->crossing.x = event->crossing.y = 0;
10952 event->crossing.x_root = event->crossing.y_root = 0;
10953 event->crossing.mode = mode;
10954 event->crossing.detail = detail;
10955 event->crossing.focus = FALSE;
10956 event->crossing.state = 0;
10957 gdk_event_set_device (event, device);
10960 widget = gtk_get_event_widget (event);
10963 gtk_widget_event_internal (widget, event);
10965 gdk_event_free (event);
10969 * _gtk_widget_synthesize_crossing:
10970 * @from: the #GtkWidget the virtual pointer is leaving.
10971 * @to: the #GtkWidget the virtual pointer is moving to.
10972 * @mode: the #GdkCrossingMode to place on the synthesized events.
10974 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10976 * The real pointer window is the window that most recently received an enter notify
10977 * event. Windows that don't select for crossing events can't become the real
10978 * poiner window. The real pointer widget that owns the real pointer window. The
10979 * effective pointer window is the same as the real pointer window unless the real
10980 * pointer widget is either insensitive or there is a grab on a widget that is not
10981 * an ancestor of the real pointer widget (in which case the effective pointer
10982 * window should be the root window).
10984 * When the effective pointer window is the same as the real poiner window, we
10985 * receive crossing events from the windowing system. When the effective pointer
10986 * window changes to become different from the real pointer window we synthesize
10987 * crossing events, attempting to follow X protocol rules:
10989 * When the root window becomes the effective pointer window:
10990 * - leave notify on real pointer window, detail Ancestor
10991 * - leave notify on all of its ancestors, detail Virtual
10992 * - enter notify on root window, detail Inferior
10994 * When the root window ceases to be the effective pointer window:
10995 * - leave notify on root window, detail Inferior
10996 * - enter notify on all ancestors of real pointer window, detail Virtual
10997 * - enter notify on real pointer window, detail Ancestor
11000 _gtk_widget_synthesize_crossing (GtkWidget *from,
11003 GdkCrossingMode mode)
11005 GdkWindow *from_window = NULL, *to_window = NULL;
11007 g_return_if_fail (from != NULL || to != NULL);
11011 from_window = _gtk_widget_get_device_window (from, device);
11014 from_window = from->priv->window;
11019 to_window = _gtk_widget_get_device_window (to, device);
11022 to_window = to->priv->window;
11025 if (from_window == NULL && to_window == NULL)
11027 else if (from_window != NULL && to_window == NULL)
11029 GList *from_ancestors = NULL, *list;
11030 GdkWindow *from_ancestor = from_window;
11032 while (from_ancestor != NULL)
11034 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
11035 if (from_ancestor == NULL)
11037 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
11040 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11041 device, mode, GDK_NOTIFY_ANCESTOR);
11042 for (list = g_list_last (from_ancestors); list; list = list->prev)
11044 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11045 device, mode, GDK_NOTIFY_VIRTUAL);
11048 /* XXX: enter/inferior on root window? */
11050 g_list_free (from_ancestors);
11052 else if (from_window == NULL && to_window != NULL)
11054 GList *to_ancestors = NULL, *list;
11055 GdkWindow *to_ancestor = to_window;
11057 while (to_ancestor != NULL)
11059 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
11060 if (to_ancestor == NULL)
11062 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
11065 /* XXX: leave/inferior on root window? */
11067 for (list = to_ancestors; list; list = list->next)
11069 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11070 device, mode, GDK_NOTIFY_VIRTUAL);
11072 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11073 device, mode, GDK_NOTIFY_ANCESTOR);
11075 g_list_free (to_ancestors);
11077 else if (from_window == to_window)
11081 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
11082 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
11084 while (from_ancestor != NULL || to_ancestor != NULL)
11086 if (from_ancestor != NULL)
11088 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
11089 if (from_ancestor == to_window)
11092 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
11094 if (to_ancestor != NULL)
11096 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
11097 if (to_ancestor == from_window)
11100 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
11103 if (to_ancestor == from_window)
11105 if (mode != GDK_CROSSING_GTK_UNGRAB)
11106 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11107 device, mode, GDK_NOTIFY_INFERIOR);
11108 for (list = to_ancestors; list; list = list->next)
11109 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11110 device, mode, GDK_NOTIFY_VIRTUAL);
11111 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11112 device, mode, GDK_NOTIFY_ANCESTOR);
11114 else if (from_ancestor == to_window)
11116 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11117 device, mode, GDK_NOTIFY_ANCESTOR);
11118 for (list = g_list_last (from_ancestors); list; list = list->prev)
11120 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11121 device, mode, GDK_NOTIFY_VIRTUAL);
11123 if (mode != GDK_CROSSING_GTK_GRAB)
11124 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11125 device, mode, GDK_NOTIFY_INFERIOR);
11129 while (from_ancestors != NULL && to_ancestors != NULL
11130 && from_ancestors->data == to_ancestors->data)
11132 from_ancestors = g_list_delete_link (from_ancestors,
11134 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
11137 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11138 device, mode, GDK_NOTIFY_NONLINEAR);
11140 for (list = g_list_last (from_ancestors); list; list = list->prev)
11142 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11143 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11145 for (list = to_ancestors; list; list = list->next)
11147 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11148 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11150 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11151 device, mode, GDK_NOTIFY_NONLINEAR);
11153 g_list_free (from_ancestors);
11154 g_list_free (to_ancestors);
11159 gtk_widget_propagate_state (GtkWidget *widget,
11160 GtkStateData *data)
11162 GtkWidgetPrivate *priv = widget->priv;
11163 GtkStateFlags new_flags, old_flags = priv->state_flags;
11164 GtkStateType old_state;
11166 old_state = gtk_widget_get_state (widget);
11168 if (!priv->parent_sensitive)
11169 old_flags |= GTK_STATE_FLAG_INSENSITIVE;
11171 priv->parent_sensitive = data->parent_sensitive;
11173 switch (data->operation)
11175 case STATE_CHANGE_REPLACE:
11176 priv->state_flags = data->flags;
11178 case STATE_CHANGE_SET:
11179 priv->state_flags |= data->flags;
11181 case STATE_CHANGE_UNSET:
11182 priv->state_flags &= ~(data->flags);
11186 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
11190 window = gtk_widget_get_toplevel (widget);
11192 if (window && gtk_widget_is_toplevel (window))
11193 gtk_window_set_focus (GTK_WINDOW (window), NULL);
11196 new_flags = gtk_widget_get_state_flags (widget);
11198 if (old_flags != new_flags)
11200 g_object_ref (widget);
11202 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
11203 gtk_grab_remove (widget);
11205 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
11206 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
11208 if (!priv->shadowed)
11210 GList *event_windows = NULL;
11211 GList *devices, *d;
11213 devices = _gtk_widget_list_devices (widget);
11215 for (d = devices; d; d = d->next)
11221 window = _gtk_widget_get_device_window (widget, device);
11223 /* Do not propagate more than once to the
11224 * same window if non-multidevice aware.
11226 if (!gdk_window_get_support_multidevice (window) &&
11227 g_list_find (event_windows, window))
11230 if (!gtk_widget_is_sensitive (widget))
11231 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
11232 GDK_CROSSING_STATE_CHANGED);
11233 else if (old_flags & GTK_STATE_FLAG_INSENSITIVE)
11234 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
11235 GDK_CROSSING_STATE_CHANGED);
11237 event_windows = g_list_prepend (event_windows, window);
11240 g_list_free (event_windows);
11241 g_list_free (devices);
11244 if (GTK_IS_CONTAINER (widget))
11246 data->parent_sensitive = gtk_widget_is_sensitive (widget);
11248 /* Do not propagate insensitive state further */
11249 data->flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
11251 if (data->use_forall)
11252 gtk_container_forall (GTK_CONTAINER (widget),
11253 (GtkCallback) gtk_widget_propagate_state,
11256 gtk_container_foreach (GTK_CONTAINER (widget),
11257 (GtkCallback) gtk_widget_propagate_state,
11261 /* Trigger state change transitions for the widget */
11262 if (priv->context &&
11263 gtk_widget_get_mapped (widget))
11265 gint diff, flag = 1;
11268 diff = old_flags ^ new_flags;
11269 window = gtk_widget_get_window (widget);
11273 if ((diff & flag) != 0)
11277 target = ((new_flags & flag) != 0);
11278 _gtk_widget_notify_state_change (widget, flag, target);
11287 g_object_unref (widget);
11291 static const GtkWidgetAuxInfo default_aux_info = {
11299 * _gtk_widget_get_aux_info:
11300 * @widget: a #GtkWidget
11301 * @create: if %TRUE, create the structure if it doesn't exist
11303 * Get the #GtkWidgetAuxInfo structure for the widget.
11305 * Return value: the #GtkAuxInfo structure for the widget, or
11306 * %NULL if @create is %FALSE and one doesn't already exist.
11309 _gtk_widget_get_aux_info (GtkWidget *widget,
11312 GtkWidgetAuxInfo *aux_info;
11314 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
11315 if (!aux_info && create)
11317 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
11319 *aux_info = default_aux_info;
11321 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
11327 static const GtkWidgetAuxInfo*
11328 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11330 GtkWidgetAuxInfo *aux_info;
11332 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
11333 if (aux_info == NULL)
11335 return &default_aux_info;
11343 /*****************************************
11344 * gtk_widget_aux_info_destroy:
11349 *****************************************/
11352 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11354 g_slice_free (GtkWidgetAuxInfo, aux_info);
11358 * gtk_widget_shape_combine_region:
11359 * @widget: a #GtkWidget
11360 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11362 * Sets a shape for this widget's GDK window. This allows for
11363 * transparent windows etc., see gdk_window_shape_combine_region()
11364 * for more information.
11369 gtk_widget_shape_combine_region (GtkWidget *widget,
11370 cairo_region_t *region)
11372 GtkWidgetPrivate *priv;
11374 g_return_if_fail (GTK_IS_WIDGET (widget));
11375 /* set_shape doesn't work on widgets without gdk window */
11376 g_return_if_fail (gtk_widget_get_has_window (widget));
11378 priv = widget->priv;
11380 if (region == NULL)
11382 priv->has_shape_mask = FALSE;
11385 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11387 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11391 priv->has_shape_mask = TRUE;
11393 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11394 cairo_region_copy (region),
11395 (GDestroyNotify) cairo_region_destroy);
11397 /* set shape if widget has a gdk window already.
11398 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11401 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11406 * gtk_widget_input_shape_combine_region:
11407 * @widget: a #GtkWidget
11408 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11410 * Sets an input shape for this widget's GDK window. This allows for
11411 * windows which react to mouse click in a nonrectangular region, see
11412 * gdk_window_input_shape_combine_region() for more information.
11417 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11418 cairo_region_t *region)
11420 GtkWidgetPrivate *priv;
11422 g_return_if_fail (GTK_IS_WIDGET (widget));
11423 /* set_shape doesn't work on widgets without gdk window */
11424 g_return_if_fail (gtk_widget_get_has_window (widget));
11426 priv = widget->priv;
11428 if (region == NULL)
11431 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11433 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11437 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11438 cairo_region_copy (region),
11439 (GDestroyNotify) cairo_region_destroy);
11441 /* set shape if widget has a gdk window already.
11442 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11445 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11450 /* style properties
11454 * gtk_widget_class_install_style_property_parser:
11455 * @klass: a #GtkWidgetClass
11456 * @pspec: the #GParamSpec for the style property
11457 * @parser: the parser for the style property
11459 * Installs a style property on a widget class.
11462 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11464 GtkRcPropertyParser parser)
11466 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11467 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11468 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11469 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11471 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11473 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11474 G_OBJECT_CLASS_NAME (klass),
11479 g_param_spec_ref_sink (pspec);
11480 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11481 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11485 * gtk_widget_class_install_style_property:
11486 * @klass: a #GtkWidgetClass
11487 * @pspec: the #GParamSpec for the property
11489 * Installs a style property on a widget class. The parser for the
11490 * style property is determined by the value type of @pspec.
11493 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11496 GtkRcPropertyParser parser;
11498 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11499 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11501 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11503 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11507 * gtk_widget_class_find_style_property:
11508 * @klass: a #GtkWidgetClass
11509 * @property_name: the name of the style property to find
11510 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
11511 * style property with that name.
11513 * Finds a style property of a widget class by name.
11518 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11519 const gchar *property_name)
11521 g_return_val_if_fail (property_name != NULL, NULL);
11523 return g_param_spec_pool_lookup (style_property_spec_pool,
11525 G_OBJECT_CLASS_TYPE (klass),
11530 * gtk_widget_class_list_style_properties:
11531 * @klass: a #GtkWidgetClass
11532 * @n_properties: location to return the number of style properties found
11533 * @returns: an newly allocated array of #GParamSpec*. The array must
11534 * be freed with g_free().
11536 * Returns all style properties of a widget class.
11541 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11542 guint *n_properties)
11544 GParamSpec **pspecs;
11547 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11548 G_OBJECT_CLASS_TYPE (klass),
11557 * gtk_widget_style_get_property:
11558 * @widget: a #GtkWidget
11559 * @property_name: the name of a style property
11560 * @value: location to return the property value
11562 * Gets the value of a style property of @widget.
11565 gtk_widget_style_get_property (GtkWidget *widget,
11566 const gchar *property_name,
11571 g_return_if_fail (GTK_IS_WIDGET (widget));
11572 g_return_if_fail (property_name != NULL);
11573 g_return_if_fail (G_IS_VALUE (value));
11575 g_object_ref (widget);
11576 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11578 G_OBJECT_TYPE (widget),
11581 g_warning ("%s: widget class `%s' has no property named `%s'",
11583 G_OBJECT_TYPE_NAME (widget),
11587 GtkStyleContext *context;
11588 const GValue *peek_value;
11589 GtkStateFlags state;
11591 context = gtk_widget_get_style_context (widget);
11592 state = gtk_widget_get_state_flags (widget);
11594 peek_value = _gtk_style_context_peek_style_property (context,
11595 G_OBJECT_TYPE (widget),
11598 /* auto-conversion of the caller's value type
11600 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11601 g_value_copy (peek_value, value);
11602 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11603 g_value_transform (peek_value, value);
11605 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11607 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11608 G_VALUE_TYPE_NAME (value));
11610 g_object_unref (widget);
11614 * gtk_widget_style_get_valist:
11615 * @widget: a #GtkWidget
11616 * @first_property_name: the name of the first property to get
11617 * @var_args: a <type>va_list</type> of pairs of property names and
11618 * locations to return the property values, starting with the location
11619 * for @first_property_name.
11621 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11625 gtk_widget_style_get_valist (GtkWidget *widget,
11626 const gchar *first_property_name,
11629 GtkStyleContext *context;
11630 GtkStateFlags state;
11633 g_return_if_fail (GTK_IS_WIDGET (widget));
11635 g_object_ref (widget);
11636 context = gtk_widget_get_style_context (widget);
11637 state = gtk_widget_get_state_flags (widget);
11639 name = first_property_name;
11642 const GValue *peek_value;
11646 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11648 G_OBJECT_TYPE (widget),
11652 g_warning ("%s: widget class `%s' has no property named `%s'",
11654 G_OBJECT_TYPE_NAME (widget),
11658 /* style pspecs are always readable so we can spare that check here */
11660 peek_value = _gtk_style_context_peek_style_property (context,
11661 G_OBJECT_TYPE (widget),
11664 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11667 g_warning ("%s: %s", G_STRLOC, error);
11672 name = va_arg (var_args, gchar*);
11675 g_object_unref (widget);
11679 * gtk_widget_style_get:
11680 * @widget: a #GtkWidget
11681 * @first_property_name: the name of the first property to get
11682 * @Varargs: pairs of property names and locations to
11683 * return the property values, starting with the location for
11684 * @first_property_name, terminated by %NULL.
11686 * Gets the values of a multiple style properties of @widget.
11689 gtk_widget_style_get (GtkWidget *widget,
11690 const gchar *first_property_name,
11695 g_return_if_fail (GTK_IS_WIDGET (widget));
11697 va_start (var_args, first_property_name);
11698 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11704 * @widget: a #GtkWidget
11705 * @path_length: (out) (allow-none): location to store length of the path,
11707 * @path: (out) (allow-none): location to store allocated path string,
11709 * @path_reversed: (out) (allow-none): location to store allocated reverse
11710 * path string, or %NULL
11712 * Obtains the full path to @widget. The path is simply the name of a
11713 * widget and all its parents in the container hierarchy, separated by
11714 * periods. The name of a widget comes from
11715 * gtk_widget_get_name(). Paths are used to apply styles to a widget
11716 * in gtkrc configuration files. Widget names are the type of the
11717 * widget by default (e.g. "GtkButton") or can be set to an
11718 * application-specific value with gtk_widget_set_name(). By setting
11719 * the name of a widget, you allow users or theme authors to apply
11720 * styles to that specific widget in their gtkrc
11721 * file. @path_reversed_p fills in the path in reverse order,
11722 * i.e. starting with @widget's name instead of starting with the name
11723 * of @widget's outermost ancestor.
11725 * Deprecated:3.0: Use gtk_widget_get_path() instead
11728 gtk_widget_path (GtkWidget *widget,
11729 guint *path_length,
11731 gchar **path_reversed)
11733 static gchar *rev_path = NULL;
11734 static guint tmp_path_len = 0;
11737 g_return_if_fail (GTK_IS_WIDGET (widget));
11742 const gchar *string;
11747 string = gtk_widget_get_name (widget);
11748 l = strlen (string);
11749 while (tmp_path_len <= len + l + 1)
11751 tmp_path_len += INIT_PATH_SIZE;
11752 rev_path = g_realloc (rev_path, tmp_path_len);
11754 s = string + l - 1;
11755 d = rev_path + len;
11756 while (s >= string)
11760 widget = widget->priv->parent;
11763 rev_path[len++] = '.';
11765 rev_path[len++] = 0;
11770 *path_length = len - 1;
11772 *path_reversed = g_strdup (rev_path);
11775 *path = g_strdup (rev_path);
11776 g_strreverse (*path);
11781 * gtk_widget_class_path:
11782 * @widget: a #GtkWidget
11783 * @path_length: (out) (allow-none): location to store the length of the
11784 * class path, or %NULL
11785 * @path: (out) (allow-none): location to store the class path as an
11786 * allocated string, or %NULL
11787 * @path_reversed: (out) (allow-none): location to store the reverse
11788 * class path as an allocated string, or %NULL
11790 * Same as gtk_widget_path(), but always uses the name of a widget's type,
11791 * never uses a custom name set with gtk_widget_set_name().
11793 * Deprecated:3.0: Use gtk_widget_get_path() instead
11796 gtk_widget_class_path (GtkWidget *widget,
11797 guint *path_length,
11799 gchar **path_reversed)
11801 static gchar *rev_path = NULL;
11802 static guint tmp_path_len = 0;
11805 g_return_if_fail (GTK_IS_WIDGET (widget));
11810 const gchar *string;
11815 string = g_type_name (G_OBJECT_TYPE (widget));
11816 l = strlen (string);
11817 while (tmp_path_len <= len + l + 1)
11819 tmp_path_len += INIT_PATH_SIZE;
11820 rev_path = g_realloc (rev_path, tmp_path_len);
11822 s = string + l - 1;
11823 d = rev_path + len;
11824 while (s >= string)
11828 widget = widget->priv->parent;
11831 rev_path[len++] = '.';
11833 rev_path[len++] = 0;
11838 *path_length = len - 1;
11840 *path_reversed = g_strdup (rev_path);
11843 *path = g_strdup (rev_path);
11844 g_strreverse (*path);
11849 * gtk_requisition_new:
11851 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11853 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11854 * be freed with gtk_requisition_free().
11859 gtk_requisition_new (void)
11861 return g_slice_new0 (GtkRequisition);
11865 * gtk_requisition_copy:
11866 * @requisition: a #GtkRequisition
11868 * Copies a #GtkRequisition.
11870 * Returns: a copy of @requisition
11873 gtk_requisition_copy (const GtkRequisition *requisition)
11875 return g_slice_dup (GtkRequisition, requisition);
11879 * gtk_requisition_free:
11880 * @requisition: a #GtkRequisition
11882 * Frees a #GtkRequisition.
11885 gtk_requisition_free (GtkRequisition *requisition)
11887 g_slice_free (GtkRequisition, requisition);
11890 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11891 gtk_requisition_copy,
11892 gtk_requisition_free)
11895 * gtk_widget_get_accessible:
11896 * @widget: a #GtkWidget
11898 * Returns the accessible object that describes the widget to an
11899 * assistive technology.
11901 * If no accessibility library is loaded (i.e. no ATK implementation library is
11902 * loaded via <envar>GTK_MODULES</envar> or via another application library,
11903 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
11904 * if no class-specific #AtkObject implementation is available for the widget
11905 * instance in question, it will inherit an #AtkObject implementation from the
11906 * first ancestor class for which such an implementation is defined.
11908 * The documentation of the
11909 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
11910 * library contains more information about accessible objects and their uses.
11912 * Returns: (transfer none): the #AtkObject associated with @widget
11915 gtk_widget_get_accessible (GtkWidget *widget)
11917 GtkWidgetClass *klass;
11919 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11921 klass = GTK_WIDGET_GET_CLASS (widget);
11923 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11925 return klass->get_accessible (widget);
11929 gtk_widget_real_get_accessible (GtkWidget *widget)
11931 AtkObject* accessible;
11933 accessible = g_object_get_qdata (G_OBJECT (widget),
11934 quark_accessible_object);
11937 AtkObjectFactory *factory;
11938 AtkRegistry *default_registry;
11940 default_registry = atk_get_default_registry ();
11941 factory = atk_registry_get_factory (default_registry,
11942 G_TYPE_FROM_INSTANCE (widget));
11944 atk_object_factory_create_accessible (factory,
11945 G_OBJECT (widget));
11946 g_object_set_qdata (G_OBJECT (widget),
11947 quark_accessible_object,
11954 * Initialize a AtkImplementorIface instance's virtual pointers as
11955 * appropriate to this implementor's class (GtkWidget).
11958 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11960 iface->ref_accessible = gtk_widget_ref_accessible;
11964 gtk_widget_ref_accessible (AtkImplementor *implementor)
11966 AtkObject *accessible;
11968 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11970 g_object_ref (accessible);
11975 * Expand flag management
11979 gtk_widget_update_computed_expand (GtkWidget *widget)
11981 GtkWidgetPrivate *priv;
11983 priv = widget->priv;
11985 if (priv->need_compute_expand)
11989 if (priv->hexpand_set)
11994 if (priv->vexpand_set)
11999 /* we don't need to use compute_expand if both expands are
12000 * forced by the app
12002 if (!(priv->hexpand_set && priv->vexpand_set))
12004 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
12008 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
12009 priv->hexpand_set ? &ignored : &h,
12010 priv->vexpand_set ? &ignored : &v);
12014 priv->need_compute_expand = FALSE;
12015 priv->computed_hexpand = h != FALSE;
12016 priv->computed_vexpand = v != FALSE;
12021 * gtk_widget_queue_compute_expand:
12022 * @widget: a #GtkWidget
12024 * Mark @widget as needing to recompute its expand flags. Call
12025 * this function when setting legacy expand child properties
12026 * on the child of a container.
12028 * See gtk_widget_compute_expand().
12031 gtk_widget_queue_compute_expand (GtkWidget *widget)
12034 gboolean changed_anything;
12036 if (widget->priv->need_compute_expand)
12039 changed_anything = FALSE;
12041 while (parent != NULL)
12043 if (!parent->priv->need_compute_expand)
12045 parent->priv->need_compute_expand = TRUE;
12046 changed_anything = TRUE;
12049 /* Note: if we had an invariant that "if a child needs to
12050 * compute expand, its parents also do" then we could stop going
12051 * up when we got to a parent that already needed to
12052 * compute. However, in general we compute expand lazily (as
12053 * soon as we see something in a subtree that is expand, we know
12054 * we're expanding) and so this invariant does not hold and we
12055 * have to always walk all the way up in case some ancestor
12056 * is not currently need_compute_expand.
12059 parent = parent->priv->parent;
12062 /* recomputing expand always requires
12063 * a relayout as well
12065 if (changed_anything)
12066 gtk_widget_queue_resize (widget);
12070 * gtk_widget_compute_expand:
12071 * @widget: the widget
12072 * @orientation: expand direction
12074 * Computes whether a container should give this widget extra space
12075 * when possible. Containers should check this, rather than
12076 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
12078 * This function already checks whether the widget is visible, so
12079 * visibility does not need to be checked separately. Non-visible
12080 * widgets are not expanded.
12082 * The computed expand value uses either the expand setting explicitly
12083 * set on the widget itself, or, if none has been explicitly set,
12084 * the widget may expand if some of its children do.
12086 * Return value: whether widget tree rooted here should be expanded
12089 gtk_widget_compute_expand (GtkWidget *widget,
12090 GtkOrientation orientation)
12092 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12094 /* We never make a widget expand if not even showing. */
12095 if (!gtk_widget_get_visible (widget))
12098 gtk_widget_update_computed_expand (widget);
12100 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12102 return widget->priv->computed_hexpand;
12106 return widget->priv->computed_vexpand;
12111 gtk_widget_set_expand (GtkWidget *widget,
12112 GtkOrientation orientation,
12115 const char *expand_prop;
12116 const char *expand_set_prop;
12118 GtkWidgetPrivate *priv;
12120 g_return_if_fail (GTK_IS_WIDGET (widget));
12122 priv = widget->priv;
12124 expand = expand != FALSE;
12126 was_both = priv->hexpand && priv->vexpand;
12128 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12130 if (priv->hexpand_set &&
12131 priv->hexpand == expand)
12134 priv->hexpand_set = TRUE;
12135 priv->hexpand = expand;
12137 expand_prop = "hexpand";
12138 expand_set_prop = "hexpand-set";
12142 if (priv->vexpand_set &&
12143 priv->vexpand == expand)
12146 priv->vexpand_set = TRUE;
12147 priv->vexpand = expand;
12149 expand_prop = "vexpand";
12150 expand_set_prop = "vexpand-set";
12153 gtk_widget_queue_compute_expand (widget);
12155 g_object_freeze_notify (G_OBJECT (widget));
12156 g_object_notify (G_OBJECT (widget), expand_prop);
12157 g_object_notify (G_OBJECT (widget), expand_set_prop);
12158 if (was_both != (priv->hexpand && priv->vexpand))
12159 g_object_notify (G_OBJECT (widget), "expand");
12160 g_object_thaw_notify (G_OBJECT (widget));
12164 gtk_widget_set_expand_set (GtkWidget *widget,
12165 GtkOrientation orientation,
12168 GtkWidgetPrivate *priv;
12171 priv = widget->priv;
12173 set = set != FALSE;
12175 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12177 if (set == priv->hexpand_set)
12180 priv->hexpand_set = set;
12181 prop = "hexpand-set";
12185 if (set == priv->vexpand_set)
12188 priv->vexpand_set = set;
12189 prop = "vexpand-set";
12192 gtk_widget_queue_compute_expand (widget);
12194 g_object_notify (G_OBJECT (widget), prop);
12198 * gtk_widget_get_hexpand:
12199 * @widget: the widget
12201 * Gets whether the widget would like any available extra horizontal
12202 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12203 * generally receive the extra space. For example, a list or
12204 * scrollable area or document in your window would often be set to
12207 * Containers should use gtk_widget_compute_expand() rather than
12208 * this function, to see whether a widget, or any of its children,
12209 * has the expand flag set. If any child of a widget wants to
12210 * expand, the parent may ask to expand also.
12212 * This function only looks at the widget's own hexpand flag, rather
12213 * than computing whether the entire widget tree rooted at this widget
12216 * Return value: whether hexpand flag is set
12219 gtk_widget_get_hexpand (GtkWidget *widget)
12221 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12223 return widget->priv->hexpand;
12227 * gtk_widget_set_hexpand:
12228 * @widget: the widget
12229 * @expand: whether to expand
12231 * Sets whether the widget would like any available extra horizontal
12232 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12233 * generally receive the extra space. For example, a list or
12234 * scrollable area or document in your window would often be set to
12237 * Call this function to set the expand flag if you would like your
12238 * widget to become larger horizontally when the window has extra
12241 * By default, widgets automatically expand if any of their children
12242 * want to expand. (To see if a widget will automatically expand given
12243 * its current children and state, call gtk_widget_compute_expand(). A
12244 * container can decide how the expandability of children affects the
12245 * expansion of the container by overriding the compute_expand virtual
12246 * method on #GtkWidget.).
12248 * Setting hexpand explicitly with this function will override the
12249 * automatic expand behavior.
12251 * This function forces the widget to expand or not to expand,
12252 * regardless of children. The override occurs because
12253 * gtk_widget_set_hexpand() sets the hexpand-set property (see
12254 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
12255 * value to be used, rather than looking at children and widget state.
12258 gtk_widget_set_hexpand (GtkWidget *widget,
12261 g_return_if_fail (GTK_IS_WIDGET (widget));
12263 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
12267 * gtk_widget_get_hexpand_set:
12268 * @widget: the widget
12270 * Gets whether gtk_widget_set_hexpand() has been used to
12271 * explicitly set the expand flag on this widget.
12273 * If hexpand is set, then it overrides any computed
12274 * expand value based on child widgets. If hexpand is not
12275 * set, then the expand value depends on whether any
12276 * children of the widget would like to expand.
12278 * There are few reasons to use this function, but it's here
12279 * for completeness and consistency.
12281 * Return value: whether hexpand has been explicitly set
12284 gtk_widget_get_hexpand_set (GtkWidget *widget)
12286 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12288 return widget->priv->hexpand_set;
12292 * gtk_widget_set_hexpand_set:
12293 * @widget: the widget
12294 * @set: value for hexpand-set property
12296 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
12299 * The hexpand-set property will be set automatically when you call
12300 * gtk_widget_set_hexpand() to set hexpand, so the most likely
12301 * reason to use this function would be to unset an explicit expand
12304 * If hexpand is set, then it overrides any computed
12305 * expand value based on child widgets. If hexpand is not
12306 * set, then the expand value depends on whether any
12307 * children of the widget would like to expand.
12309 * There are few reasons to use this function, but it's here
12310 * for completeness and consistency.
12313 gtk_widget_set_hexpand_set (GtkWidget *widget,
12316 g_return_if_fail (GTK_IS_WIDGET (widget));
12318 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
12323 * gtk_widget_get_vexpand:
12324 * @widget: the widget
12326 * Gets whether the widget would like any available extra vertical
12329 * See gtk_widget_get_hexpand() for more detail.
12331 * Return value: whether vexpand flag is set
12334 gtk_widget_get_vexpand (GtkWidget *widget)
12336 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12338 return widget->priv->vexpand;
12342 * gtk_widget_set_vexpand:
12343 * @widget: the widget
12344 * @expand: whether to expand
12346 * Sets whether the widget would like any available extra vertical
12349 * See gtk_widget_set_hexpand() for more detail.
12352 gtk_widget_set_vexpand (GtkWidget *widget,
12355 g_return_if_fail (GTK_IS_WIDGET (widget));
12357 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12361 * gtk_widget_get_vexpand_set:
12362 * @widget: the widget
12364 * Gets whether gtk_widget_set_vexpand() has been used to
12365 * explicitly set the expand flag on this widget.
12367 * See gtk_widget_get_hexpand_set() for more detail.
12369 * Return value: whether vexpand has been explicitly set
12372 gtk_widget_get_vexpand_set (GtkWidget *widget)
12374 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12376 return widget->priv->vexpand_set;
12380 * gtk_widget_set_vexpand_set:
12381 * @widget: the widget
12382 * @set: value for vexpand-set property
12384 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12387 * See gtk_widget_set_hexpand_set() for more detail.
12390 gtk_widget_set_vexpand_set (GtkWidget *widget,
12393 g_return_if_fail (GTK_IS_WIDGET (widget));
12395 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12399 * GtkBuildable implementation
12401 static GQuark quark_builder_has_default = 0;
12402 static GQuark quark_builder_has_focus = 0;
12403 static GQuark quark_builder_atk_relations = 0;
12404 static GQuark quark_builder_set_name = 0;
12407 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12409 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12410 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12411 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12412 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12414 iface->set_name = gtk_widget_buildable_set_name;
12415 iface->get_name = gtk_widget_buildable_get_name;
12416 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12417 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12418 iface->parser_finished = gtk_widget_buildable_parser_finished;
12419 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12420 iface->custom_finished = gtk_widget_buildable_custom_finished;
12424 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12427 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12428 g_strdup (name), g_free);
12431 static const gchar *
12432 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12434 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12438 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12439 GtkBuilder *builder,
12440 const gchar *childname)
12442 if (strcmp (childname, "accessible") == 0)
12443 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12449 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12450 GtkBuilder *builder,
12452 const GValue *value)
12454 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12455 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12456 GINT_TO_POINTER (TRUE));
12457 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12458 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12459 GINT_TO_POINTER (TRUE));
12461 g_object_set_property (G_OBJECT (buildable), name, value);
12466 gchar *action_name;
12467 GString *description;
12469 gboolean translatable;
12479 free_action (AtkActionData *data, gpointer user_data)
12481 g_free (data->action_name);
12482 g_string_free (data->description, TRUE);
12483 g_free (data->context);
12484 g_slice_free (AtkActionData, data);
12488 free_relation (AtkRelationData *data, gpointer user_data)
12490 g_free (data->target);
12491 g_free (data->type);
12492 g_slice_free (AtkRelationData, data);
12496 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12497 GtkBuilder *builder)
12499 GSList *atk_relations;
12501 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12502 gtk_widget_grab_default (GTK_WIDGET (buildable));
12503 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12504 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12506 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12507 quark_builder_atk_relations);
12510 AtkObject *accessible;
12511 AtkRelationSet *relation_set;
12514 AtkRelationType relation_type;
12515 AtkObject *target_accessible;
12517 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12518 relation_set = atk_object_ref_relation_set (accessible);
12520 for (l = atk_relations; l; l = l->next)
12522 AtkRelationData *relation = (AtkRelationData*)l->data;
12524 target = gtk_builder_get_object (builder, relation->target);
12527 g_warning ("Target object %s in <relation> does not exist",
12531 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12532 g_assert (target_accessible != NULL);
12534 relation_type = atk_relation_type_for_name (relation->type);
12535 if (relation_type == ATK_RELATION_NULL)
12537 g_warning ("<relation> type %s not found",
12541 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12542 target_accessible);
12544 g_object_unref (relation_set);
12546 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
12547 g_slist_free (atk_relations);
12548 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12557 } AccessibilitySubParserData;
12560 accessibility_start_element (GMarkupParseContext *context,
12561 const gchar *element_name,
12562 const gchar **names,
12563 const gchar **values,
12564 gpointer user_data,
12567 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12569 gint line_number, char_number;
12571 if (strcmp (element_name, "relation") == 0)
12573 gchar *target = NULL;
12574 gchar *type = NULL;
12575 AtkRelationData *relation;
12577 for (i = 0; names[i]; i++)
12579 if (strcmp (names[i], "target") == 0)
12580 target = g_strdup (values[i]);
12581 else if (strcmp (names[i], "type") == 0)
12582 type = g_strdup (values[i]);
12585 g_markup_parse_context_get_position (context,
12588 g_set_error (error,
12590 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12591 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12593 line_number, char_number, names[i], "relation");
12600 if (!target || !type)
12602 g_markup_parse_context_get_position (context,
12605 g_set_error (error,
12607 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12608 "%s:%d:%d <%s> requires attribute \"%s\"",
12610 line_number, char_number, "relation",
12611 type ? "target" : "type");
12617 relation = g_slice_new (AtkRelationData);
12618 relation->target = target;
12619 relation->type = type;
12621 data->relations = g_slist_prepend (data->relations, relation);
12623 else if (strcmp (element_name, "action") == 0)
12625 const gchar *action_name = NULL;
12626 const gchar *description = NULL;
12627 const gchar *msg_context = NULL;
12628 gboolean translatable = FALSE;
12629 AtkActionData *action;
12631 for (i = 0; names[i]; i++)
12633 if (strcmp (names[i], "action_name") == 0)
12634 action_name = values[i];
12635 else if (strcmp (names[i], "description") == 0)
12636 description = values[i];
12637 else if (strcmp (names[i], "translatable") == 0)
12639 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12642 else if (strcmp (names[i], "comments") == 0)
12644 /* do nothing, comments are for translators */
12646 else if (strcmp (names[i], "context") == 0)
12647 msg_context = values[i];
12650 g_markup_parse_context_get_position (context,
12653 g_set_error (error,
12655 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12656 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12658 line_number, char_number, names[i], "action");
12665 g_markup_parse_context_get_position (context,
12668 g_set_error (error,
12670 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12671 "%s:%d:%d <%s> requires attribute \"%s\"",
12673 line_number, char_number, "action",
12678 action = g_slice_new (AtkActionData);
12679 action->action_name = g_strdup (action_name);
12680 action->description = g_string_new (description);
12681 action->context = g_strdup (msg_context);
12682 action->translatable = translatable;
12684 data->actions = g_slist_prepend (data->actions, action);
12686 else if (strcmp (element_name, "accessibility") == 0)
12689 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12693 accessibility_text (GMarkupParseContext *context,
12696 gpointer user_data,
12699 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12701 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12703 AtkActionData *action = data->actions->data;
12705 g_string_append_len (action->description, text, text_len);
12709 static const GMarkupParser accessibility_parser =
12711 accessibility_start_element,
12713 accessibility_text,
12722 } AccelGroupParserData;
12725 accel_group_start_element (GMarkupParseContext *context,
12726 const gchar *element_name,
12727 const gchar **names,
12728 const gchar **values,
12729 gpointer user_data,
12734 guint modifiers = 0;
12735 gchar *signal = NULL;
12736 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12738 for (i = 0; names[i]; i++)
12740 if (strcmp (names[i], "key") == 0)
12741 key = gdk_keyval_from_name (values[i]);
12742 else if (strcmp (names[i], "modifiers") == 0)
12744 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12750 else if (strcmp (names[i], "signal") == 0)
12751 signal = g_strdup (values[i]);
12754 if (key == 0 || signal == NULL)
12756 g_warning ("<accelerator> requires key and signal attributes");
12759 parser_data->key = key;
12760 parser_data->modifiers = modifiers;
12761 parser_data->signal = signal;
12764 static const GMarkupParser accel_group_parser =
12766 accel_group_start_element,
12770 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12771 GtkBuilder *builder,
12773 const gchar *tagname,
12774 GMarkupParser *parser,
12777 g_assert (buildable);
12779 if (strcmp (tagname, "accelerator") == 0)
12781 AccelGroupParserData *parser_data;
12783 parser_data = g_slice_new0 (AccelGroupParserData);
12784 parser_data->object = g_object_ref (buildable);
12785 *parser = accel_group_parser;
12786 *data = parser_data;
12789 if (strcmp (tagname, "accessibility") == 0)
12791 AccessibilitySubParserData *parser_data;
12793 parser_data = g_slice_new0 (AccessibilitySubParserData);
12794 *parser = accessibility_parser;
12795 *data = parser_data;
12802 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12803 GtkWidget *toplevel,
12804 gpointer user_data)
12806 AccelGroupParserData *accel_data;
12807 GSList *accel_groups;
12808 GtkAccelGroup *accel_group;
12810 g_return_if_fail (GTK_IS_WIDGET (widget));
12811 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12812 g_return_if_fail (user_data != NULL);
12814 accel_data = (AccelGroupParserData*)user_data;
12815 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12816 if (g_slist_length (accel_groups) == 0)
12818 accel_group = gtk_accel_group_new ();
12819 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12823 g_assert (g_slist_length (accel_groups) == 1);
12824 accel_group = g_slist_nth_data (accel_groups, 0);
12827 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12828 accel_data->signal,
12831 accel_data->modifiers,
12832 GTK_ACCEL_VISIBLE);
12834 g_object_unref (accel_data->object);
12835 g_free (accel_data->signal);
12836 g_slice_free (AccelGroupParserData, accel_data);
12840 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12841 GtkBuilder *builder,
12843 const gchar *tagname,
12844 gpointer user_data)
12846 AccelGroupParserData *accel_data;
12847 AccessibilitySubParserData *a11y_data;
12848 GtkWidget *toplevel;
12850 if (strcmp (tagname, "accelerator") == 0)
12852 accel_data = (AccelGroupParserData*)user_data;
12853 g_assert (accel_data->object);
12855 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12857 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12859 else if (strcmp (tagname, "accessibility") == 0)
12861 a11y_data = (AccessibilitySubParserData*)user_data;
12863 if (a11y_data->actions)
12865 AtkObject *accessible;
12870 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12872 action = ATK_ACTION (accessible);
12873 n_actions = atk_action_get_n_actions (action);
12875 for (l = a11y_data->actions; l; l = l->next)
12877 AtkActionData *action_data = (AtkActionData*)l->data;
12879 for (i = 0; i < n_actions; i++)
12880 if (strcmp (atk_action_get_name (action, i),
12881 action_data->action_name) == 0)
12886 gchar *description;
12888 if (action_data->translatable && action_data->description->len)
12889 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12890 action_data->context,
12891 action_data->description->str);
12893 description = action_data->description->str;
12895 atk_action_set_description (action, i, description);
12899 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
12900 g_slist_free (a11y_data->actions);
12903 if (a11y_data->relations)
12904 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12905 a11y_data->relations);
12907 g_slice_free (AccessibilitySubParserData, a11y_data);
12912 gtk_widget_real_get_width (GtkWidget *widget,
12913 gint *minimum_size,
12914 gint *natural_size)
12924 gtk_widget_real_get_height (GtkWidget *widget,
12925 gint *minimum_size,
12926 gint *natural_size)
12936 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12938 gint *minimum_height,
12939 gint *natural_height)
12941 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12945 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12947 gint *minimum_width,
12948 gint *natural_width)
12950 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12954 * gtk_widget_get_halign:
12955 * @widget: a #GtkWidget
12957 * Gets the value of the #GtkWidget:halign property.
12959 * Returns: the horizontal alignment of @widget
12962 gtk_widget_get_halign (GtkWidget *widget)
12964 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12965 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12969 * gtk_widget_set_halign:
12970 * @widget: a #GtkWidget
12971 * @align: the horizontal alignment
12973 * Sets the horizontal alignment of @widget.
12974 * See the #GtkWidget:halign property.
12977 gtk_widget_set_halign (GtkWidget *widget,
12980 GtkWidgetAuxInfo *aux_info;
12982 g_return_if_fail (GTK_IS_WIDGET (widget));
12984 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12986 if (aux_info->halign == align)
12989 aux_info->halign = align;
12990 gtk_widget_queue_resize (widget);
12991 g_object_notify (G_OBJECT (widget), "halign");
12995 * gtk_widget_get_valign:
12996 * @widget: a #GtkWidget
12998 * Gets the value of the #GtkWidget:valign property.
13000 * Returns: the vertical alignment of @widget
13003 gtk_widget_get_valign (GtkWidget *widget)
13005 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
13006 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
13010 * gtk_widget_set_valign:
13011 * @widget: a #GtkWidget
13012 * @align: the vertical alignment
13014 * Sets the vertical alignment of @widget.
13015 * See the #GtkWidget:valign property.
13018 gtk_widget_set_valign (GtkWidget *widget,
13021 GtkWidgetAuxInfo *aux_info;
13023 g_return_if_fail (GTK_IS_WIDGET (widget));
13025 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
13027 if (aux_info->valign == align)
13030 aux_info->valign = align;
13031 gtk_widget_queue_resize (widget);
13032 g_object_notify (G_OBJECT (widget), "valign");
13036 * gtk_widget_get_margin_left:
13037 * @widget: a #GtkWidget
13039 * Gets the value of the #GtkWidget:margin-left property.
13041 * Returns: The left margin of @widget
13044 gtk_widget_get_margin_left (GtkWidget *widget)
13046 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13048 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
13052 * gtk_widget_set_margin_left:
13053 * @widget: a #GtkWidget
13054 * @margin: the left margin
13056 * Sets the left margin of @widget.
13057 * See the #GtkWidget:margin-left property.
13060 gtk_widget_set_margin_left (GtkWidget *widget,
13063 GtkWidgetAuxInfo *aux_info;
13065 g_return_if_fail (GTK_IS_WIDGET (widget));
13066 g_return_if_fail (margin <= G_MAXINT16);
13068 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
13070 if (aux_info->margin.left == margin)
13073 aux_info->margin.left = margin;
13074 gtk_widget_queue_resize (widget);
13075 g_object_notify (G_OBJECT (widget), "margin-left");
13079 * gtk_widget_get_margin_right:
13080 * @widget: a #GtkWidget
13082 * Gets the value of the #GtkWidget:margin-right property.
13084 * Returns: The left margin of @widget
13087 gtk_widget_get_margin_right (GtkWidget *widget)
13089 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13091 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
13095 * gtk_widget_set_margin_right:
13096 * @widget: a #GtkWidget
13097 * @margin: the right margin
13099 * Sets the right margin of @widget.
13100 * See the #GtkWidget:margin-right property.
13103 gtk_widget_set_margin_right (GtkWidget *widget,
13106 GtkWidgetAuxInfo *aux_info;
13108 g_return_if_fail (GTK_IS_WIDGET (widget));
13109 g_return_if_fail (margin <= G_MAXINT16);
13111 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
13113 if (aux_info->margin.right == margin)
13116 aux_info->margin.right = margin;
13117 gtk_widget_queue_resize (widget);
13118 g_object_notify (G_OBJECT (widget), "margin-right");
13122 * gtk_widget_get_margin_top:
13123 * @widget: a #GtkWidget
13125 * Gets the value of the #GtkWidget:margin-top property.
13127 * Returns: The top margin of @widget
13130 gtk_widget_get_margin_top (GtkWidget *widget)
13132 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13134 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
13138 * gtk_widget_set_margin_top:
13139 * @widget: a #GtkWidget
13140 * @margin: the top margin
13142 * Sets the top margin of @widget.
13143 * See the #GtkWidget:margin-top property.
13146 gtk_widget_set_margin_top (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.top == margin)
13159 aux_info->margin.top = margin;
13160 gtk_widget_queue_resize (widget);
13161 g_object_notify (G_OBJECT (widget), "margin-top");
13165 * gtk_widget_get_margin_bottom:
13166 * @widget: a #GtkWidget
13168 * Gets the value of the #GtkWidget:margin-bottom property.
13170 * Returns: The bottom margin of @widget
13173 gtk_widget_get_margin_bottom (GtkWidget *widget)
13175 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13177 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
13181 * gtk_widget_set_margin_bottom:
13182 * @widget: a #GtkWidget
13183 * @margin: the bottom margin
13185 * Sets the bottom margin of @widget.
13186 * See the #GtkWidget:margin-bottom property.
13189 gtk_widget_set_margin_bottom (GtkWidget *widget,
13192 GtkWidgetAuxInfo *aux_info;
13194 g_return_if_fail (GTK_IS_WIDGET (widget));
13195 g_return_if_fail (margin <= G_MAXINT16);
13197 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
13199 if (aux_info->margin.bottom == margin)
13202 aux_info->margin.bottom = margin;
13203 gtk_widget_queue_resize (widget);
13204 g_object_notify (G_OBJECT (widget), "margin-bottom");
13208 * gtk_widget_get_clipboard:
13209 * @widget: a #GtkWidget
13210 * @selection: a #GdkAtom which identifies the clipboard
13211 * to use. %GDK_SELECTION_CLIPBOARD gives the
13212 * default clipboard. Another common value
13213 * is %GDK_SELECTION_PRIMARY, which gives
13214 * the primary X selection.
13216 * Returns the clipboard object for the given selection to
13217 * be used with @widget. @widget must have a #GdkDisplay
13218 * associated with it, so must be attached to a toplevel
13221 * Return value: (transfer none): the appropriate clipboard object. If no
13222 * clipboard already exists, a new one will
13223 * be created. Once a clipboard object has
13224 * been created, it is persistent for all time.
13229 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
13231 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13232 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
13234 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
13239 * gtk_widget_list_mnemonic_labels:
13240 * @widget: a #GtkWidget
13242 * Returns a newly allocated list of the widgets, normally labels, for
13243 * which this widget is the target of a mnemonic (see for example,
13244 * gtk_label_set_mnemonic_widget()).
13246 * The widgets in the list are not individually referenced. If you
13247 * want to iterate through the list and perform actions involving
13248 * callbacks that might destroy the widgets, you
13249 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
13250 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
13251 * widgets afterwards.
13253 * Return value: (element-type GtkWidget) (transfer container): the list of
13254 * mnemonic labels; free this list
13255 * with g_list_free() when you are done with it.
13260 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
13262 GList *list = NULL;
13265 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13267 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13268 list = g_list_prepend (list, l->data);
13274 * gtk_widget_add_mnemonic_label:
13275 * @widget: a #GtkWidget
13276 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13278 * Adds a widget to the list of mnemonic labels for
13279 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13280 * list of mnemonic labels for the widget is cleared when the
13281 * widget is destroyed, so the caller must make sure to update
13282 * its internal state at this point as well, by using a connection
13283 * to the #GtkWidget::destroy signal or a weak notifier.
13288 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13291 GSList *old_list, *new_list;
13293 g_return_if_fail (GTK_IS_WIDGET (widget));
13294 g_return_if_fail (GTK_IS_WIDGET (label));
13296 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13297 new_list = g_slist_prepend (old_list, label);
13299 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13300 new_list, (GDestroyNotify) g_slist_free);
13304 * gtk_widget_remove_mnemonic_label:
13305 * @widget: a #GtkWidget
13306 * @label: a #GtkWidget that was previously set as a mnemnic label for
13307 * @widget with gtk_widget_add_mnemonic_label().
13309 * Removes a widget from the list of mnemonic labels for
13310 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13311 * must have previously been added to the list with
13312 * gtk_widget_add_mnemonic_label().
13317 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13320 GSList *old_list, *new_list;
13322 g_return_if_fail (GTK_IS_WIDGET (widget));
13323 g_return_if_fail (GTK_IS_WIDGET (label));
13325 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13326 new_list = g_slist_remove (old_list, label);
13329 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13330 new_list, (GDestroyNotify) g_slist_free);
13334 * gtk_widget_get_no_show_all:
13335 * @widget: a #GtkWidget
13337 * Returns the current value of the #GtkWidget:no-show-all property,
13338 * which determines whether calls to gtk_widget_show_all()
13339 * will affect this widget.
13341 * Return value: the current value of the "no-show-all" property.
13346 gtk_widget_get_no_show_all (GtkWidget *widget)
13348 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13350 return widget->priv->no_show_all;
13354 * gtk_widget_set_no_show_all:
13355 * @widget: a #GtkWidget
13356 * @no_show_all: the new value for the "no-show-all" property
13358 * Sets the #GtkWidget:no-show-all property, which determines whether
13359 * calls to gtk_widget_show_all() will affect this widget.
13361 * This is mostly for use in constructing widget hierarchies with externally
13362 * controlled visibility, see #GtkUIManager.
13367 gtk_widget_set_no_show_all (GtkWidget *widget,
13368 gboolean no_show_all)
13370 g_return_if_fail (GTK_IS_WIDGET (widget));
13372 no_show_all = (no_show_all != FALSE);
13374 if (widget->priv->no_show_all != no_show_all)
13376 widget->priv->no_show_all = no_show_all;
13378 g_object_notify (G_OBJECT (widget), "no-show-all");
13384 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13385 gboolean has_tooltip,
13388 GtkWidgetPrivate *priv = widget->priv;
13389 gboolean priv_has_tooltip;
13391 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13392 quark_has_tooltip));
13394 if (priv_has_tooltip != has_tooltip || force)
13396 priv_has_tooltip = has_tooltip;
13398 if (priv_has_tooltip)
13400 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13401 gdk_window_set_events (priv->window,
13402 gdk_window_get_events (priv->window) |
13403 GDK_LEAVE_NOTIFY_MASK |
13404 GDK_POINTER_MOTION_MASK |
13405 GDK_POINTER_MOTION_HINT_MASK);
13407 if (gtk_widget_get_has_window (widget))
13408 gtk_widget_add_events (widget,
13409 GDK_LEAVE_NOTIFY_MASK |
13410 GDK_POINTER_MOTION_MASK |
13411 GDK_POINTER_MOTION_HINT_MASK);
13414 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13415 GUINT_TO_POINTER (priv_has_tooltip));
13420 * gtk_widget_set_tooltip_window:
13421 * @widget: a #GtkWidget
13422 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13424 * Replaces the default, usually yellow, window used for displaying
13425 * tooltips with @custom_window. GTK+ will take care of showing and
13426 * hiding @custom_window at the right moment, to behave likewise as
13427 * the default tooltip window. If @custom_window is %NULL, the default
13428 * tooltip window will be used.
13430 * If the custom window should have the default theming it needs to
13431 * have the name "gtk-tooltip", see gtk_widget_set_name().
13436 gtk_widget_set_tooltip_window (GtkWidget *widget,
13437 GtkWindow *custom_window)
13439 gboolean has_tooltip;
13440 gchar *tooltip_markup;
13442 g_return_if_fail (GTK_IS_WIDGET (widget));
13443 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13445 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13448 g_object_ref (custom_window);
13450 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13451 custom_window, g_object_unref);
13453 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13454 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13456 if (has_tooltip && gtk_widget_get_visible (widget))
13457 gtk_widget_queue_tooltip_query (widget);
13461 * gtk_widget_get_tooltip_window:
13462 * @widget: a #GtkWidget
13464 * Returns the #GtkWindow of the current tooltip. This can be the
13465 * GtkWindow created by default, or the custom tooltip window set
13466 * using gtk_widget_set_tooltip_window().
13468 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13473 gtk_widget_get_tooltip_window (GtkWidget *widget)
13475 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13477 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13481 * gtk_widget_trigger_tooltip_query:
13482 * @widget: a #GtkWidget
13484 * Triggers a tooltip query on the display where the toplevel of @widget
13485 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13491 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13493 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13496 static guint tooltip_query_id;
13497 static GSList *tooltip_query_displays;
13500 tooltip_query_idle (gpointer data)
13502 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13503 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13504 g_slist_free (tooltip_query_displays);
13506 tooltip_query_displays = NULL;
13507 tooltip_query_id = 0;
13513 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13515 GdkDisplay *display;
13517 display = gtk_widget_get_display (widget);
13519 if (!g_slist_find (tooltip_query_displays, display))
13520 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13522 if (tooltip_query_id == 0)
13523 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13527 * gtk_widget_set_tooltip_text:
13528 * @widget: a #GtkWidget
13529 * @text: the contents of the tooltip for @widget
13531 * Sets @text as the contents of the tooltip. This function will take
13532 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13533 * handler for the #GtkWidget::query-tooltip signal.
13535 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13540 gtk_widget_set_tooltip_text (GtkWidget *widget,
13543 g_return_if_fail (GTK_IS_WIDGET (widget));
13545 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13549 * gtk_widget_get_tooltip_text:
13550 * @widget: a #GtkWidget
13552 * Gets the contents of the tooltip for @widget.
13554 * Return value: the tooltip text, or %NULL. You should free the
13555 * returned string with g_free() when done.
13560 gtk_widget_get_tooltip_text (GtkWidget *widget)
13562 gchar *text = NULL;
13564 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13566 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13572 * gtk_widget_set_tooltip_markup:
13573 * @widget: a #GtkWidget
13574 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13576 * Sets @markup as the contents of the tooltip, which is marked up with
13577 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13579 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13580 * and of the default handler for the #GtkWidget::query-tooltip signal.
13582 * See also the #GtkWidget:tooltip-markup property and
13583 * gtk_tooltip_set_markup().
13588 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13589 const gchar *markup)
13591 g_return_if_fail (GTK_IS_WIDGET (widget));
13593 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13597 * gtk_widget_get_tooltip_markup:
13598 * @widget: a #GtkWidget
13600 * Gets the contents of the tooltip for @widget.
13602 * Return value: the tooltip text, or %NULL. You should free the
13603 * returned string with g_free() when done.
13608 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13610 gchar *text = NULL;
13612 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13614 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13620 * gtk_widget_set_has_tooltip:
13621 * @widget: a #GtkWidget
13622 * @has_tooltip: whether or not @widget has a tooltip.
13624 * Sets the has-tooltip property on @widget to @has_tooltip. See
13625 * #GtkWidget:has-tooltip for more information.
13630 gtk_widget_set_has_tooltip (GtkWidget *widget,
13631 gboolean has_tooltip)
13633 g_return_if_fail (GTK_IS_WIDGET (widget));
13635 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13639 * gtk_widget_get_has_tooltip:
13640 * @widget: a #GtkWidget
13642 * Returns the current value of the has-tooltip property. See
13643 * #GtkWidget:has-tooltip for more information.
13645 * Return value: current value of has-tooltip on @widget.
13650 gtk_widget_get_has_tooltip (GtkWidget *widget)
13652 gboolean has_tooltip = FALSE;
13654 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13656 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13658 return has_tooltip;
13662 * gtk_widget_get_allocation:
13663 * @widget: a #GtkWidget
13664 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13666 * Retrieves the widget's allocation.
13668 * Note, when implementing a #GtkContainer: a widget's allocation will
13669 * be its "adjusted" allocation, that is, the widget's parent
13670 * container typically calls gtk_widget_size_allocate() with an
13671 * allocation, and that allocation is then adjusted (to handle margin
13672 * and alignment for example) before assignment to the widget.
13673 * gtk_widget_get_allocation() returns the adjusted allocation that
13674 * was actually assigned to the widget. The adjusted allocation is
13675 * guaranteed to be completely contained within the
13676 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13677 * is guaranteed that its children stay inside the assigned bounds,
13678 * but not that they have exactly the bounds the container assigned.
13679 * There is no way to get the original allocation assigned by
13680 * gtk_widget_size_allocate(), since it isn't stored; if a container
13681 * implementation needs that information it will have to track it itself.
13686 gtk_widget_get_allocation (GtkWidget *widget,
13687 GtkAllocation *allocation)
13689 GtkWidgetPrivate *priv;
13691 g_return_if_fail (GTK_IS_WIDGET (widget));
13692 g_return_if_fail (allocation != NULL);
13694 priv = widget->priv;
13696 *allocation = priv->allocation;
13700 * gtk_widget_set_allocation:
13701 * @widget: a #GtkWidget
13702 * @allocation: a pointer to a #GtkAllocation to copy from
13704 * Sets the widget's allocation. This should not be used
13705 * directly, but from within a widget's size_allocate method.
13707 * The allocation set should be the "adjusted" or actual
13708 * allocation. If you're implementing a #GtkContainer, you want to use
13709 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13710 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13711 * allocation inside gtk_widget_size_allocate() to create an adjusted
13717 gtk_widget_set_allocation (GtkWidget *widget,
13718 const GtkAllocation *allocation)
13720 GtkWidgetPrivate *priv;
13722 g_return_if_fail (GTK_IS_WIDGET (widget));
13723 g_return_if_fail (allocation != NULL);
13725 priv = widget->priv;
13727 priv->allocation = *allocation;
13731 * gtk_widget_get_allocated_width:
13732 * @widget: the widget to query
13734 * Returns the width that has currently been allocated to @widget.
13735 * This function is intended to be used when implementing handlers
13736 * for the #GtkWidget::draw function.
13738 * Returns: the width of the @widget
13741 gtk_widget_get_allocated_width (GtkWidget *widget)
13743 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13745 return widget->priv->allocation.width;
13749 * gtk_widget_get_allocated_height:
13750 * @widget: the widget to query
13752 * Returns the height that has currently been allocated to @widget.
13753 * This function is intended to be used when implementing handlers
13754 * for the #GtkWidget::draw function.
13756 * Returns: the height of the @widget
13759 gtk_widget_get_allocated_height (GtkWidget *widget)
13761 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13763 return widget->priv->allocation.height;
13767 * gtk_widget_get_requisition:
13768 * @widget: a #GtkWidget
13769 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13771 * Retrieves the widget's requisition.
13773 * This function should only be used by widget implementations in
13774 * order to figure whether the widget's requisition has actually
13775 * changed after some internal state change (so that they can call
13776 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13778 * Normally, gtk_widget_size_request() should be used.
13782 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13783 * removed, If you need to cache sizes across requests and allocations,
13784 * add an explicit cache to the widget in question instead.
13787 gtk_widget_get_requisition (GtkWidget *widget,
13788 GtkRequisition *requisition)
13790 g_return_if_fail (GTK_IS_WIDGET (widget));
13791 g_return_if_fail (requisition != NULL);
13793 gtk_widget_get_preferred_size (widget, requisition, NULL);
13797 * gtk_widget_set_window:
13798 * @widget: a #GtkWidget
13799 * @window: a #GdkWindow
13801 * Sets a widget's window. This function should only be used in a
13802 * widget's #GtkWidget::realize implementation. The %window passed is
13803 * usually either new window created with gdk_window_new(), or the
13804 * window of its parent widget as returned by
13805 * gtk_widget_get_parent_window().
13807 * Widgets must indicate whether they will create their own #GdkWindow
13808 * by calling gtk_widget_set_has_window(). This is usually done in the
13809 * widget's init() function.
13811 * <note><para>This function does not add any reference to @window.</para></note>
13816 gtk_widget_set_window (GtkWidget *widget,
13819 GtkWidgetPrivate *priv;
13821 g_return_if_fail (GTK_IS_WIDGET (widget));
13822 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13824 priv = widget->priv;
13826 if (priv->window != window)
13828 priv->window = window;
13829 g_object_notify (G_OBJECT (widget), "window");
13834 * gtk_widget_get_window:
13835 * @widget: a #GtkWidget
13837 * Returns the widget's window if it is realized, %NULL otherwise
13839 * Return value: (transfer none): @widget's window.
13844 gtk_widget_get_window (GtkWidget *widget)
13846 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13848 return widget->priv->window;
13852 * gtk_widget_get_support_multidevice:
13853 * @widget: a #GtkWidget
13855 * Returns %TRUE if @widget is multiple pointer aware. See
13856 * gtk_widget_set_support_multidevice() for more information.
13858 * Returns: %TRUE if @widget is multidevice aware.
13861 gtk_widget_get_support_multidevice (GtkWidget *widget)
13863 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13865 return widget->priv->multidevice;
13869 * gtk_widget_set_support_multidevice:
13870 * @widget: a #GtkWidget
13871 * @support_multidevice: %TRUE to support input from multiple devices.
13873 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13874 * @widget will start receiving multiple, per device enter/leave events. Note
13875 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13876 * gdk_window_set_support_multidevice() will have to be called manually on them.
13881 gtk_widget_set_support_multidevice (GtkWidget *widget,
13882 gboolean support_multidevice)
13884 GtkWidgetPrivate *priv;
13886 g_return_if_fail (GTK_IS_WIDGET (widget));
13888 priv = widget->priv;
13889 priv->multidevice = (support_multidevice == TRUE);
13891 if (gtk_widget_get_realized (widget))
13892 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13896 _gtk_widget_set_has_focus (GtkWidget *widget,
13897 gboolean has_focus)
13899 widget->priv->has_focus = has_focus;
13903 * gtk_widget_send_focus_change:
13904 * @widget: a #GtkWidget
13905 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13907 * Sends the focus change @event to @widget
13909 * This function is not meant to be used by applications. The only time it
13910 * should be used is when it is necessary for a #GtkWidget to assign focus
13911 * to a widget that is semantically owned by the first widget even though
13912 * it's not a direct child - for instance, a search entry in a floating
13913 * window similar to the quick search in #GtkTreeView.
13915 * An example of its usage is:
13918 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13920 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13921 * fevent->focus_change.in = TRUE;
13922 * fevent->focus_change.window = gtk_widget_get_window (widget);
13923 * if (fevent->focus_change.window != NULL)
13924 * g_object_ref (fevent->focus_change.window);
13926 * gtk_widget_send_focus_change (widget, fevent);
13928 * gdk_event_free (event);
13931 * Return value: the return value from the event signal emission: %TRUE
13932 * if the event was handled, and %FALSE otherwise
13937 gtk_widget_send_focus_change (GtkWidget *widget,
13942 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13943 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13945 g_object_ref (widget);
13947 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13949 res = gtk_widget_event (widget, event);
13951 g_object_notify (G_OBJECT (widget), "has-focus");
13953 g_object_unref (widget);
13959 * gtk_widget_in_destruction:
13960 * @widget: a #GtkWidget
13962 * Returns whether the widget is currently being destroyed.
13963 * This information can sometimes be used to avoid doing
13964 * unnecessary work.
13966 * Returns: %TRUE if @widget is being destroyed
13969 gtk_widget_in_destruction (GtkWidget *widget)
13971 return widget->priv->in_destruction;
13975 _gtk_widget_get_resize_pending (GtkWidget *widget)
13977 return widget->priv->resize_pending;
13981 _gtk_widget_set_resize_pending (GtkWidget *widget,
13982 gboolean resize_pending)
13984 widget->priv->resize_pending = resize_pending;
13988 _gtk_widget_get_in_reparent (GtkWidget *widget)
13990 return widget->priv->in_reparent;
13994 _gtk_widget_set_in_reparent (GtkWidget *widget,
13995 gboolean in_reparent)
13997 widget->priv->in_reparent = in_reparent;
14001 _gtk_widget_get_anchored (GtkWidget *widget)
14003 return widget->priv->anchored;
14007 _gtk_widget_set_anchored (GtkWidget *widget,
14010 widget->priv->anchored = anchored;
14014 _gtk_widget_get_shadowed (GtkWidget *widget)
14016 return widget->priv->shadowed;
14020 _gtk_widget_set_shadowed (GtkWidget *widget,
14023 widget->priv->shadowed = shadowed;
14027 _gtk_widget_get_alloc_needed (GtkWidget *widget)
14029 return widget->priv->alloc_needed;
14033 _gtk_widget_set_alloc_needed (GtkWidget *widget,
14034 gboolean alloc_needed)
14036 widget->priv->alloc_needed = alloc_needed;
14040 _gtk_widget_get_width_request_needed (GtkWidget *widget)
14042 return widget->priv->width_request_needed;
14046 _gtk_widget_set_width_request_needed (GtkWidget *widget,
14047 gboolean width_request_needed)
14049 widget->priv->width_request_needed = width_request_needed;
14053 _gtk_widget_get_height_request_needed (GtkWidget *widget)
14055 return widget->priv->height_request_needed;
14059 _gtk_widget_set_height_request_needed (GtkWidget *widget,
14060 gboolean height_request_needed)
14062 widget->priv->height_request_needed = height_request_needed;
14066 * gtk_widget_get_path:
14067 * @widget: a #GtkWidget
14069 * Returns the #GtkWidgetPath representing @widget, if the widget
14070 * is not connected to a toplevel widget, a partial path will be
14073 * Returns: (transfer none): The #GtkWidgetPath representing @widget
14076 gtk_widget_get_path (GtkWidget *widget)
14078 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14080 /* As strange as it may seem, this may happen on object construction.
14081 * init() implementations of parent types may eventually call this function,
14082 * each with its corresponding GType, which could leave a child
14083 * implementation with a wrong widget type in the widget path
14085 if (widget->priv->path &&
14086 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (widget->priv->path))
14088 gtk_widget_path_free (widget->priv->path);
14089 widget->priv->path = NULL;
14092 if (!widget->priv->path)
14097 parent = widget->priv->parent;
14100 widget->priv->path = gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
14103 /* Widget is either toplevel or unparented, treat both
14104 * as toplevels style wise, since there are situations
14105 * where style properties might be retrieved on that
14108 widget->priv->path = gtk_widget_path_new ();
14111 pos = gtk_widget_path_append_type (widget->priv->path, G_OBJECT_TYPE (widget));
14113 if (widget->priv->name)
14114 gtk_widget_path_iter_set_name (widget->priv->path, pos, widget->priv->name);
14116 if (widget->priv->context)
14117 gtk_style_context_set_path (widget->priv->context,
14118 widget->priv->path);
14121 return widget->priv->path;
14125 style_context_changed (GtkStyleContext *context,
14126 gpointer user_data)
14128 GtkWidget *widget = user_data;
14130 gtk_widget_update_pango_context (widget);
14132 if (gtk_widget_get_realized (widget))
14133 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
14136 /* Compress all style updates so it
14137 * is only emitted once pre-realize.
14139 widget->priv->style_update_pending = TRUE;
14142 if (widget->priv->anchored)
14143 gtk_widget_queue_resize (widget);
14147 * gtk_widget_get_style_context:
14148 * @widget: a #GtkWidget
14150 * Returns the style context associated to @widget.
14152 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
14153 * must not be freed.
14156 gtk_widget_get_style_context (GtkWidget *widget)
14158 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14160 if (G_UNLIKELY (!widget->priv->context))
14162 widget->priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
14163 "direction", gtk_widget_get_direction (widget),
14166 g_signal_connect (widget->priv->context, "changed",
14167 G_CALLBACK (style_context_changed), widget);
14169 gtk_style_context_set_screen (widget->priv->context,
14170 gtk_widget_get_screen (widget));
14172 _gtk_widget_update_path (widget);
14173 gtk_style_context_set_path (widget->priv->context,
14174 widget->priv->path);
14178 /* Force widget path regeneration if needed, the
14179 * context will be updated within this function.
14181 gtk_widget_get_path (widget);
14184 return widget->priv->context;