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/.
27 #undef GDK_DISABLE_DEPRECATED /* gdk_input_set_extension_events() */
33 #include "gtkcontainer.h"
34 #include "gtkaccelmap.h"
35 #include "gtkclipboard.h"
36 #include "gtkiconfactory.h"
39 #include "gtkmarshalers.h"
41 #include "gtkselection.h"
42 #include "gtksettings.h"
43 #include "gtksizegroup-private.h"
44 #include "gtkwidget.h"
45 #include "gtkwidgetprivate.h"
46 #include "gtkwindow.h"
47 #include "gtkbindings.h"
48 #include "gtkprivate.h"
50 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
51 #include <gobject/gvaluecollector.h>
52 #include <gobject/gobjectnotifyqueue.c>
53 #include <cairo-gobject.h>
54 #include "gdk/gdkkeysyms.h"
55 #include "gtkaccessible.h"
56 #include "gtktooltip.h"
57 #include "gtkinvisible.h"
58 #include "gtkbuildable.h"
59 #include "gtkbuilderprivate.h"
60 #include "gtksizerequest.h"
61 #include "gtkstylecontext.h"
62 #include "gtkcssprovider.h"
63 #include "gtkversion.h"
69 * @Short_description: Base class for all widgets
72 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
73 * widget lifecycle, states and style.
75 * <refsect2 id="geometry-management">
76 * <title>Height-for-width Geometry Management</title>
78 * GTK+ uses a height-for-width (and width-for-height) geometry management
79 * system. Height-for-width means that a widget can change how much
80 * vertical space it needs, depending on the amount of horizontal space
81 * that it is given (and similar for width-for-height). The most common
82 * example is a label that reflows to fill up the available width, wraps
83 * to fewer lines, and therefore needs less height.
85 * Height-for-width geometry management is implemented in GTK+ by way
86 * of five virtual methods:
88 * <listitem>#GtkWidgetClass.get_request_mode()</listitem>
89 * <listitem>#GtkWidgetClass.get_preferred_width()</listitem>
90 * <listitem>#GtkWidgetClass.get_preferred_height()</listitem>
91 * <listitem>#GtkWidgetClass.get_preferred_height_for_width()</listitem>
92 * <listitem>#GtkWidgetClass.get_preferred_width_for_height()</listitem>
95 * There are some important things to keep in mind when implementing
96 * height-for-width and when using it in container implementations.
98 * The geometry management system will query a widget hierarchy in
99 * only one orientation at a time. When widgets are initially queried
100 * for their minimum sizes it is generally done in two initial passes
101 * in the #GtkSizeRequestMode chosen by the toplevel.
103 * For example, when queried in the normal
104 * %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode:
105 * First, the default minimum and natural width for each widget
106 * in the interface will be computed using gtk_width_get_preferred_width().
107 * Because the preferred widths for each container depend on the preferred
108 * widths of their children, this information propagates up the hierarchy,
109 * and finally a minimum and natural width is determined for the entire
110 * toplevel. Next, the toplevel will use the minimum width to query for the
111 * minimum height contextual to that width using
112 * gtk_widget_get_preferred_height_for_width(), which will also be a highly
113 * recursive operation. The minimum height for the minimum width is normally
114 * used to set the minimum size constraint on the toplevel
115 * (unless gtk_window_set_geometry_hints() is explicitly used instead).
117 * After the toplevel window has initially requested its size in both
118 * dimensions it can go on to allocate itself a reasonable size (or a size
119 * previously specified with gtk_window_set_default_size()). During the
120 * recursive allocation process it's important to note that request cycles
121 * will be recursively executed while container widgets allocate their children.
122 * Each container widget, once allocated a size, will go on to first share the
123 * space in one orientation among its children and then request each child's
124 * height for its target allocated width or its width for allocated height,
125 * depending. In this way a #GtkWidget will typically be requested its size
126 * a number of times before actually being allocated a size. The size a
127 * widget is finally allocated can of course differ from the size it has
128 * requested. For this reason, #GtkWidget caches a small number of results
129 * to avoid re-querying for the same sizes in one allocation cycle.
131 * See <link linkend="container-geometry-management">GtkContainer's
132 * geometry management section</link>
133 * to learn more about how height-for-width allocations are performed
134 * by container widgets.
136 * If a widget does move content around to intelligently use up the
137 * allocated size then it must support the request in both
138 * #GtkSizeRequestModes even if the widget in question only
139 * trades sizes in a single orientation.
141 * For instance, a #GtkLabel that does height-for-width word wrapping
142 * will not expect to have #GtkWidgetClass.get_preferred_height() called
143 * because that call is specific to a width-for-height request. In this
144 * case the label must return the height required for its own minimum
145 * possible width. By following this rule any widget that handles
146 * height-for-width or width-for-height requests will always be allocated
147 * at least enough space to fit its own content.
149 * Here are some examples of how a %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH widget
150 * generally deals with width-for-height requests, for #GtkWidgetClass.get_preferred_height()
152 * <programlisting><![CDATA[
154 * foo_widget_get_preferred_height (GtkWidget *widget, gint *min_height, gint *nat_height)
156 * if (i_am_in_height_for_width_mode)
160 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
161 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width,
162 * min_height, nat_height);
166 * ... some widgets do both. For instance, if a GtkLabel is rotated to 90 degrees
167 * it will return the minimum and natural height for the rotated label here.
170 * ]]></programlisting>
172 * And in #GtkWidgetClass.get_preferred_width_for_height() it will simply return
173 * the minimum and natural width:
175 * <programlisting><![CDATA[
177 * foo_widget_get_preferred_width_for_height (GtkWidget *widget, gint for_height,
178 * gint *min_width, gint *nat_width)
180 * if (i_am_in_height_for_width_mode)
182 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, min_width, nat_width);
186 * ... again if a widget is sometimes operating in width-for-height mode
187 * (like a rotated GtkLabel) it can go ahead and do its real width for
188 * height calculation here.
191 * ]]></programlisting>
193 * Often a widget needs to get its own request during size request or
194 * allocation. For example, when computing height it may need to also
195 * compute width. Or when deciding how to use an allocation, the widget
196 * may need to know its natural size. In these cases, the widget should
197 * be careful to call its virtual methods directly, like this:
199 * <title>Widget calling its own size request method.</title>
201 * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget),
206 * It will not work to use the wrapper functions, such as
207 * gtk_widget_get_preferred_width() inside your own size request
208 * implementation. These return a request adjusted by #GtkSizeGroup
209 * and by the #GtkWidgetClass.adjust_size_request() virtual method. If a
210 * widget used the wrappers inside its virtual method implementations,
211 * then the adjustments (such as widget margins) would be applied
212 * twice. GTK+ therefore does not allow this and will warn if you try
215 * Of course if you are getting the size request for
216 * <emphasis>another</emphasis> widget, such as a child of a
217 * container, you <emphasis>must</emphasis> use the wrapper APIs.
218 * Otherwise, you would not properly consider widget margins,
219 * #GtkSizeGroup, and so forth.
222 * <refsect2 id="style-properties">
223 * <title>Style Properties</title>
225 * <structname>GtkWidget</structname> introduces <firstterm>style
226 * properties</firstterm> - these are basically object properties that are stored
227 * not on the object, but in the style object associated to the widget. Style
228 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
229 * This mechanism is used for configuring such things as the location of the
230 * scrollbar arrows through the theme, giving theme authors more control over the
231 * look of applications without the need to write a theme engine in C.
234 * Use gtk_widget_class_install_style_property() to install style properties for
235 * a widget class, gtk_widget_class_find_style_property() or
236 * gtk_widget_class_list_style_properties() to get information about existing
237 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
238 * gtk_widget_style_get_valist() to obtain the value of a style property.
241 * <refsect2 id="GtkWidget-BUILDER-UI">
242 * <title>GtkWidget as GtkBuildable</title>
244 * The GtkWidget implementation of the GtkBuildable interface supports a
245 * custom <accelerator> element, which has attributes named key,
246 * modifiers and signal and allows to specify accelerators.
249 * <title>A UI definition fragment specifying an accelerator</title>
250 * <programlisting><![CDATA[
251 * <object class="GtkButton">
252 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
254 * ]]></programlisting>
257 * In addition to accelerators, <structname>GtkWidget</structname> also support a
258 * custom <accessible> element, which supports actions and relations.
259 * Properties on the accessible implementation of an object can be set by accessing the
260 * internal child "accessible" of a <structname>GtkWidget</structname>.
263 * <title>A UI definition fragment specifying an accessible</title>
264 * <programlisting><![CDATA[
265 * <object class="GtkButton" id="label1"/>
266 * <property name="label">I am a Label for a Button</property>
268 * <object class="GtkButton" id="button1">
270 * <action action_name="click" translatable="yes">Click the button.</action>
271 * <relation target="label1" type="labelled-by"/>
273 * <child internal-child="accessible">
274 * <object class="AtkObject" id="a11y-button1">
275 * <property name="AtkObject::name">Clickable Button</property>
279 * ]]></programlisting>
284 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
285 #define INIT_PATH_SIZE (512)
287 struct _GtkWidgetPrivate
289 /* The state of the widget. There are actually only
290 * 5 widget states (defined in "gtkenums.h")
295 /* The saved state of the widget. When a widget's state
296 * is changed to GTK_STATE_INSENSITIVE via
297 * "gtk_widget_set_state" or "gtk_widget_set_sensitive"
298 * the old state is kept around in this field. The state
299 * will be restored once the widget gets sensitive again.
301 guint saved_state : 3;
305 guint in_destruction : 1;
308 guint composite_child : 1;
314 guint parent_sensitive : 1;
317 guint can_default : 1;
318 guint has_default : 1;
319 guint receives_default : 1;
323 guint user_style : 1;
324 guint app_paintable : 1;
325 guint double_buffered : 1;
326 guint redraw_on_alloc : 1;
327 guint no_show_all : 1;
328 guint child_visible : 1;
329 guint multidevice : 1;
330 guint has_shape_mask : 1;
331 guint in_reparent : 1;
332 guint resize_pending : 1;
333 guint alloc_needed : 1;
334 guint width_request_needed : 1;
335 guint height_request_needed : 1;
337 /* Expand-related flags */
338 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
339 guint computed_hexpand : 1; /* computed results (composite of child flags) */
340 guint computed_vexpand : 1;
341 guint hexpand : 1; /* application-forced expand */
343 guint hexpand_set : 1; /* whether to use application-forced */
344 guint vexpand_set : 1; /* instead of computing from children */
346 /* The widget's name. If the widget does not have a name
347 * (the name is NULL), then its name (as returned by
348 * "gtk_widget_get_name") is its class's name.
349 * Among other things, the widget name is used to determine
350 * the style to use for a widget.
354 /* The style for the widget. The style contains the
355 * colors the widget should be drawn in for each state
356 * along with graphics contexts used to draw with and
357 * the font to use for text.
360 GtkStyleContext *context;
362 /* The widget's allocated size.
364 GtkAllocation allocation;
366 /* The widget's requested sizes */
367 SizeRequestCache requests;
369 /* The widget's window or its parent window if it does
370 * not have a window. (Which will be indicated by the
371 * GTK_NO_WINDOW flag being set).
375 /* The widget's parent.
379 /* 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,
474 PROP_EXTENSION_EVENTS,
480 PROP_DOUBLE_BUFFERED,
495 typedef struct _GtkStateData GtkStateData;
500 guint state_restoration : 1;
501 guint parent_sensitive : 1;
502 guint use_forall : 1;
505 /* --- prototypes --- */
506 static void gtk_widget_class_init (GtkWidgetClass *klass);
507 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
508 static void gtk_widget_init (GtkWidget *widget);
509 static void gtk_widget_set_property (GObject *object,
513 static void gtk_widget_get_property (GObject *object,
517 static void gtk_widget_dispose (GObject *object);
518 static void gtk_widget_real_destroy (GtkWidget *object);
519 static void gtk_widget_finalize (GObject *object);
520 static void gtk_widget_real_show (GtkWidget *widget);
521 static void gtk_widget_real_hide (GtkWidget *widget);
522 static void gtk_widget_real_map (GtkWidget *widget);
523 static void gtk_widget_real_unmap (GtkWidget *widget);
524 static void gtk_widget_real_realize (GtkWidget *widget);
525 static void gtk_widget_real_unrealize (GtkWidget *widget);
526 static void gtk_widget_real_size_allocate (GtkWidget *widget,
527 GtkAllocation *allocation);
528 static void gtk_widget_real_style_set (GtkWidget *widget,
529 GtkStyle *previous_style);
530 static void gtk_widget_real_direction_changed(GtkWidget *widget,
531 GtkTextDirection previous_direction);
533 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
534 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
537 gboolean keyboard_tip,
538 GtkTooltip *tooltip);
539 static void gtk_widget_real_style_updated (GtkWidget *widget);
540 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
541 GtkWidgetHelpType help_type);
543 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
545 GParamSpec **pspecs);
546 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
548 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
550 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
551 GdkEventFocus *event);
552 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
553 GdkEventFocus *event);
554 static gboolean gtk_widget_real_focus (GtkWidget *widget,
555 GtkDirectionType direction);
556 static void gtk_widget_real_move_focus (GtkWidget *widget,
557 GtkDirectionType direction);
558 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
559 GtkDirectionType direction);
560 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
561 static void gtk_widget_update_pango_context (GtkWidget *widget);
562 static void gtk_widget_propagate_state (GtkWidget *widget,
564 static void gtk_widget_reset_rc_style (GtkWidget *widget);
565 static void gtk_widget_set_style_internal (GtkWidget *widget,
567 gboolean initial_emission);
568 static gint gtk_widget_event_internal (GtkWidget *widget,
570 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
571 gboolean group_cycling);
572 static void gtk_widget_real_get_width (GtkWidget *widget,
575 static void gtk_widget_real_get_height (GtkWidget *widget,
578 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
580 gint *minimum_height,
581 gint *natural_height);
582 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
585 gint *natural_width);
586 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
587 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
588 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
589 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
590 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
591 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
592 cairo_region_t *region);
593 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
594 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
595 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
598 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
599 gboolean has_tooltip,
601 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
602 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
604 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
605 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
607 const gchar *childname);
608 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
611 const GValue *value);
612 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
615 const gchar *tagname,
616 GMarkupParser *parser,
618 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
621 const gchar *tagname,
623 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
624 GtkBuilder *builder);
626 static void gtk_widget_real_get_width (GtkWidget *widget,
629 static void gtk_widget_real_get_height (GtkWidget *widget,
633 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
636 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
637 GtkOrientation orientation,
640 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
641 GtkOrientation orientation,
644 gint *allocated_size);
646 static void gtk_widget_set_usize_internal (GtkWidget *widget,
649 GtkQueueResizeFlags flags);
651 static void gtk_widget_add_events_internal (GtkWidget *widget,
655 /* --- variables --- */
656 static gpointer gtk_widget_parent_class = NULL;
657 static guint widget_signals[LAST_SIGNAL] = { 0 };
658 static GtkStyle *gtk_default_style = NULL;
659 static guint composite_child_stack = 0;
660 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
661 static GParamSpecPool *style_property_spec_pool = NULL;
663 static GQuark quark_property_parser = 0;
664 static GQuark quark_aux_info = 0;
665 static GQuark quark_accel_path = 0;
666 static GQuark quark_accel_closures = 0;
667 static GQuark quark_event_mask = 0;
668 static GQuark quark_device_event_mask = 0;
669 static GQuark quark_extension_event_mode = 0;
670 static GQuark quark_parent_window = 0;
671 static GQuark quark_pointer_window = 0;
672 static GQuark quark_shape_info = 0;
673 static GQuark quark_input_shape_info = 0;
674 static GQuark quark_pango_context = 0;
675 static GQuark quark_rc_style = 0;
676 static GQuark quark_accessible_object = 0;
677 static GQuark quark_mnemonic_labels = 0;
678 static GQuark quark_tooltip_markup = 0;
679 static GQuark quark_has_tooltip = 0;
680 static GQuark quark_tooltip_window = 0;
681 static GQuark quark_visual = 0;
682 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
683 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
685 /* --- functions --- */
687 gtk_widget_get_type (void)
689 static GType widget_type = 0;
691 if (G_UNLIKELY (widget_type == 0))
693 const GTypeInfo widget_info =
695 sizeof (GtkWidgetClass),
696 NULL, /* base_init */
697 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
698 (GClassInitFunc) gtk_widget_class_init,
699 NULL, /* class_finalize */
700 NULL, /* class_init */
703 (GInstanceInitFunc) gtk_widget_init,
704 NULL, /* value_table */
707 const GInterfaceInfo accessibility_info =
709 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
710 (GInterfaceFinalizeFunc) NULL,
711 NULL /* interface data */
714 const GInterfaceInfo buildable_info =
716 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
717 (GInterfaceFinalizeFunc) NULL,
718 NULL /* interface data */
721 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
722 &widget_info, G_TYPE_FLAG_ABSTRACT);
724 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
725 &accessibility_info) ;
726 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
734 child_property_notify_dispatcher (GObject *object,
738 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
741 /* We guard against the draw signal callbacks modifying the state of the
742 * cairo context by surounding it with save/restore.
743 * Maybe we should also cairo_new_path() just to be sure?
746 gtk_widget_draw_marshaller (GClosure *closure,
747 GValue *return_value,
748 guint n_param_values,
749 const GValue *param_values,
750 gpointer invocation_hint,
751 gpointer marshal_data)
753 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
757 _gtk_marshal_BOOLEAN__BOXED (closure,
768 gtk_widget_class_init (GtkWidgetClass *klass)
770 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
771 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
772 GtkBindingSet *binding_set;
774 gtk_widget_parent_class = g_type_class_peek_parent (klass);
776 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
777 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
778 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
779 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
780 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
781 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
782 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
783 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
784 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
785 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
786 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
787 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
788 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
789 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
790 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
791 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
792 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
793 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
794 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
796 style_property_spec_pool = g_param_spec_pool_new (FALSE);
797 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
798 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
799 cpn_context.dispatcher = child_property_notify_dispatcher;
800 _gtk_widget_child_property_notify_context = &cpn_context;
802 gobject_class->dispose = gtk_widget_dispose;
803 gobject_class->finalize = gtk_widget_finalize;
804 gobject_class->set_property = gtk_widget_set_property;
805 gobject_class->get_property = gtk_widget_get_property;
807 klass->destroy = gtk_widget_real_destroy;
809 klass->activate_signal = 0;
810 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
811 klass->show = gtk_widget_real_show;
812 klass->show_all = gtk_widget_show;
813 klass->hide = gtk_widget_real_hide;
814 klass->map = gtk_widget_real_map;
815 klass->unmap = gtk_widget_real_unmap;
816 klass->realize = gtk_widget_real_realize;
817 klass->unrealize = gtk_widget_real_unrealize;
818 klass->size_allocate = gtk_widget_real_size_allocate;
819 klass->get_preferred_width = gtk_widget_real_get_width;
820 klass->get_preferred_height = gtk_widget_real_get_height;
821 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
822 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
823 klass->state_changed = NULL;
824 klass->parent_set = NULL;
825 klass->hierarchy_changed = NULL;
826 klass->style_set = gtk_widget_real_style_set;
827 klass->direction_changed = gtk_widget_real_direction_changed;
828 klass->grab_notify = NULL;
829 klass->child_notify = NULL;
831 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
832 klass->grab_focus = gtk_widget_real_grab_focus;
833 klass->focus = gtk_widget_real_focus;
834 klass->move_focus = gtk_widget_real_move_focus;
835 klass->keynav_failed = gtk_widget_real_keynav_failed;
837 klass->button_press_event = NULL;
838 klass->button_release_event = NULL;
839 klass->motion_notify_event = NULL;
840 klass->delete_event = NULL;
841 klass->destroy_event = NULL;
842 klass->key_press_event = gtk_widget_real_key_press_event;
843 klass->key_release_event = gtk_widget_real_key_release_event;
844 klass->enter_notify_event = NULL;
845 klass->leave_notify_event = NULL;
846 klass->configure_event = NULL;
847 klass->focus_in_event = gtk_widget_real_focus_in_event;
848 klass->focus_out_event = gtk_widget_real_focus_out_event;
849 klass->map_event = NULL;
850 klass->unmap_event = NULL;
851 klass->window_state_event = NULL;
852 klass->property_notify_event = _gtk_selection_property_notify;
853 klass->selection_clear_event = _gtk_selection_clear;
854 klass->selection_request_event = _gtk_selection_request;
855 klass->selection_notify_event = _gtk_selection_notify;
856 klass->selection_received = NULL;
857 klass->proximity_in_event = NULL;
858 klass->proximity_out_event = NULL;
859 klass->drag_begin = NULL;
860 klass->drag_end = NULL;
861 klass->drag_data_delete = NULL;
862 klass->drag_leave = NULL;
863 klass->drag_motion = NULL;
864 klass->drag_drop = NULL;
865 klass->drag_data_received = NULL;
866 klass->screen_changed = NULL;
867 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
868 klass->grab_broken_event = NULL;
869 klass->query_tooltip = gtk_widget_real_query_tooltip;
870 klass->style_updated = gtk_widget_real_style_updated;
872 klass->show_help = gtk_widget_real_show_help;
874 /* Accessibility support */
875 klass->get_accessible = gtk_widget_real_get_accessible;
877 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
878 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
880 g_object_class_install_property (gobject_class,
882 g_param_spec_string ("name",
884 P_("The name of the widget"),
886 GTK_PARAM_READWRITE));
887 g_object_class_install_property (gobject_class,
889 g_param_spec_object ("parent",
891 P_("The parent widget of this widget. Must be a Container widget"),
893 GTK_PARAM_READWRITE));
895 g_object_class_install_property (gobject_class,
897 g_param_spec_int ("width-request",
899 P_("Override for width request of the widget, or -1 if natural request should be used"),
903 GTK_PARAM_READWRITE));
904 g_object_class_install_property (gobject_class,
906 g_param_spec_int ("height-request",
907 P_("Height request"),
908 P_("Override for height request of the widget, or -1 if natural request should be used"),
912 GTK_PARAM_READWRITE));
913 g_object_class_install_property (gobject_class,
915 g_param_spec_boolean ("visible",
917 P_("Whether the widget is visible"),
919 GTK_PARAM_READWRITE));
920 g_object_class_install_property (gobject_class,
922 g_param_spec_boolean ("sensitive",
924 P_("Whether the widget responds to input"),
926 GTK_PARAM_READWRITE));
927 g_object_class_install_property (gobject_class,
929 g_param_spec_boolean ("app-paintable",
930 P_("Application paintable"),
931 P_("Whether the application will paint directly on the widget"),
933 GTK_PARAM_READWRITE));
934 g_object_class_install_property (gobject_class,
936 g_param_spec_boolean ("can-focus",
938 P_("Whether the widget can accept the input focus"),
940 GTK_PARAM_READWRITE));
941 g_object_class_install_property (gobject_class,
943 g_param_spec_boolean ("has-focus",
945 P_("Whether the widget has the input focus"),
947 GTK_PARAM_READWRITE));
948 g_object_class_install_property (gobject_class,
950 g_param_spec_boolean ("is-focus",
952 P_("Whether the widget is the focus widget within the toplevel"),
954 GTK_PARAM_READWRITE));
955 g_object_class_install_property (gobject_class,
957 g_param_spec_boolean ("can-default",
959 P_("Whether the widget can be the default widget"),
961 GTK_PARAM_READWRITE));
962 g_object_class_install_property (gobject_class,
964 g_param_spec_boolean ("has-default",
966 P_("Whether the widget is the default widget"),
968 GTK_PARAM_READWRITE));
969 g_object_class_install_property (gobject_class,
970 PROP_RECEIVES_DEFAULT,
971 g_param_spec_boolean ("receives-default",
972 P_("Receives default"),
973 P_("If TRUE, the widget will receive the default action when it is focused"),
975 GTK_PARAM_READWRITE));
976 g_object_class_install_property (gobject_class,
977 PROP_COMPOSITE_CHILD,
978 g_param_spec_boolean ("composite-child",
979 P_("Composite child"),
980 P_("Whether the widget is part of a composite widget"),
982 GTK_PARAM_READABLE));
983 g_object_class_install_property (gobject_class,
985 g_param_spec_object ("style",
987 P_("The style of the widget, which contains information about how it will look (colors etc)"),
989 GTK_PARAM_READWRITE));
990 g_object_class_install_property (gobject_class,
992 g_param_spec_flags ("events",
994 P_("The event mask that decides what kind of GdkEvents this widget gets"),
997 GTK_PARAM_READWRITE));
998 g_object_class_install_property (gobject_class,
999 PROP_EXTENSION_EVENTS,
1000 g_param_spec_enum ("extension-events",
1001 P_("Extension events"),
1002 P_("The mask that decides what kind of extension events this widget gets"),
1003 GDK_TYPE_EXTENSION_MODE,
1004 GDK_EXTENSION_EVENTS_NONE,
1005 GTK_PARAM_READWRITE));
1006 g_object_class_install_property (gobject_class,
1008 g_param_spec_boolean ("no-show-all",
1010 P_("Whether gtk_widget_show_all() should not affect this widget"),
1012 GTK_PARAM_READWRITE));
1015 * GtkWidget:has-tooltip:
1017 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1018 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1019 * the widget will be queried using #GtkWidget::query-tooltip to determine
1020 * whether it will provide a tooltip or not.
1022 * Note that setting this property to %TRUE for the first time will change
1023 * the event masks of the GdkWindows of this widget to include leave-notify
1024 * and motion-notify events. This cannot and will not be undone when the
1025 * property is set to %FALSE again.
1029 g_object_class_install_property (gobject_class,
1031 g_param_spec_boolean ("has-tooltip",
1033 P_("Whether this widget has a tooltip"),
1035 GTK_PARAM_READWRITE));
1037 * GtkWidget:tooltip-text:
1039 * Sets the text of tooltip to be the given string.
1041 * Also see gtk_tooltip_set_text().
1043 * This is a convenience property which will take care of getting the
1044 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1045 * will automatically be set to %TRUE and there will be taken care of
1046 * #GtkWidget::query-tooltip in the default signal handler.
1050 g_object_class_install_property (gobject_class,
1052 g_param_spec_string ("tooltip-text",
1054 P_("The contents of the tooltip for this widget"),
1056 GTK_PARAM_READWRITE));
1058 * GtkWidget:tooltip-markup:
1060 * Sets the text of tooltip to be the given string, which is marked up
1061 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1062 * Also see gtk_tooltip_set_markup().
1064 * This is a convenience property which will take care of getting the
1065 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1066 * will automatically be set to %TRUE and there will be taken care of
1067 * #GtkWidget::query-tooltip in the default signal handler.
1071 g_object_class_install_property (gobject_class,
1072 PROP_TOOLTIP_MARKUP,
1073 g_param_spec_string ("tooltip-markup",
1074 P_("Tooltip markup"),
1075 P_("The contents of the tooltip for this widget"),
1077 GTK_PARAM_READWRITE));
1082 * The widget's window if it is realized, %NULL otherwise.
1086 g_object_class_install_property (gobject_class,
1088 g_param_spec_object ("window",
1090 P_("The widget's window if it is realized"),
1092 GTK_PARAM_READABLE));
1095 * GtkWidget:double-buffered
1097 * Whether the widget is double buffered.
1101 g_object_class_install_property (gobject_class,
1102 PROP_DOUBLE_BUFFERED,
1103 g_param_spec_boolean ("double-buffered",
1104 P_("Double Buffered"),
1105 P_("Whether the widget is double buffered"),
1107 GTK_PARAM_READWRITE));
1112 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1116 g_object_class_install_property (gobject_class,
1118 g_param_spec_enum ("halign",
1119 P_("Horizontal Alignment"),
1120 P_("How to position in extra horizontal space"),
1123 GTK_PARAM_READWRITE));
1128 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1132 g_object_class_install_property (gobject_class,
1134 g_param_spec_enum ("valign",
1135 P_("Vertical Alignment"),
1136 P_("How to position in extra vertical space"),
1139 GTK_PARAM_READWRITE));
1142 * GtkWidget:margin-left
1144 * Margin on left side of widget.
1146 * This property adds margin outside of the widget's normal size
1147 * request, the margin will be added in addition to the size from
1148 * gtk_widget_set_size_request() for example.
1152 g_object_class_install_property (gobject_class,
1154 g_param_spec_int ("margin-left",
1155 P_("Margin on Left"),
1156 P_("Pixels of extra space on the left side"),
1160 GTK_PARAM_READWRITE));
1163 * GtkWidget:margin-right
1165 * Margin on right side of widget.
1167 * This property adds margin outside of the widget's normal size
1168 * request, the margin will be added in addition to the size from
1169 * gtk_widget_set_size_request() for example.
1173 g_object_class_install_property (gobject_class,
1175 g_param_spec_int ("margin-right",
1176 P_("Margin on Right"),
1177 P_("Pixels of extra space on the right side"),
1181 GTK_PARAM_READWRITE));
1184 * GtkWidget:margin-top
1186 * Margin on top side of widget.
1188 * This property adds margin outside of the widget's normal size
1189 * request, the margin will be added in addition to the size from
1190 * gtk_widget_set_size_request() for example.
1194 g_object_class_install_property (gobject_class,
1196 g_param_spec_int ("margin-top",
1197 P_("Margin on Top"),
1198 P_("Pixels of extra space on the top side"),
1202 GTK_PARAM_READWRITE));
1205 * GtkWidget:margin-bottom
1207 * Margin on bottom side of widget.
1209 * This property adds margin outside of the widget's normal size
1210 * request, the margin will be added in addition to the size from
1211 * gtk_widget_set_size_request() for example.
1215 g_object_class_install_property (gobject_class,
1217 g_param_spec_int ("margin-bottom",
1218 P_("Margin on Bottom"),
1219 P_("Pixels of extra space on the bottom side"),
1223 GTK_PARAM_READWRITE));
1228 * Sets all four sides' margin at once. If read, returns max
1229 * margin on any side.
1233 g_object_class_install_property (gobject_class,
1235 g_param_spec_int ("margin",
1237 P_("Pixels of extra space on all four sides"),
1241 GTK_PARAM_READWRITE));
1244 * GtkWidget::destroy:
1245 * @object: the object which received the signal
1247 * Signals that all holders of a reference to the widget should release
1248 * the reference that they hold. May result in finalization of the widget
1249 * if all references are released.
1251 widget_signals[DESTROY] =
1252 g_signal_new (I_("destroy"),
1253 G_TYPE_FROM_CLASS (gobject_class),
1254 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1255 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1257 _gtk_marshal_VOID__VOID,
1263 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1267 g_object_class_install_property (gobject_class,
1269 g_param_spec_boolean ("hexpand",
1270 P_("Horizontal Expand"),
1271 P_("Whether widget wants more horizontal space"),
1273 GTK_PARAM_READWRITE));
1276 * GtkWidget:hexpand-set
1278 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1282 g_object_class_install_property (gobject_class,
1284 g_param_spec_boolean ("hexpand-set",
1285 P_("Horizontal Expand Set"),
1286 P_("Whether to use the hexpand property"),
1288 GTK_PARAM_READWRITE));
1293 * Whether to expand vertically. See gtk_widget_set_vexpand().
1297 g_object_class_install_property (gobject_class,
1299 g_param_spec_boolean ("vexpand",
1300 P_("Vertical Expand"),
1301 P_("Whether widget wants more vertical space"),
1303 GTK_PARAM_READWRITE));
1306 * GtkWidget:vexpand-set
1308 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1312 g_object_class_install_property (gobject_class,
1314 g_param_spec_boolean ("vexpand-set",
1315 P_("Vertical Expand Set"),
1316 P_("Whether to use the vexpand property"),
1318 GTK_PARAM_READWRITE));
1323 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1327 g_object_class_install_property (gobject_class,
1329 g_param_spec_boolean ("expand",
1331 P_("Whether widget wants to expand in both directions"),
1333 GTK_PARAM_READWRITE));
1337 * @widget: the object which received the signal.
1339 widget_signals[SHOW] =
1340 g_signal_new (I_("show"),
1341 G_TYPE_FROM_CLASS (gobject_class),
1343 G_STRUCT_OFFSET (GtkWidgetClass, show),
1345 _gtk_marshal_VOID__VOID,
1350 * @widget: the object which received the signal.
1352 widget_signals[HIDE] =
1353 g_signal_new (I_("hide"),
1354 G_TYPE_FROM_CLASS (gobject_class),
1356 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1358 _gtk_marshal_VOID__VOID,
1363 * @widget: the object which received the signal.
1365 widget_signals[MAP] =
1366 g_signal_new (I_("map"),
1367 G_TYPE_FROM_CLASS (gobject_class),
1369 G_STRUCT_OFFSET (GtkWidgetClass, map),
1371 _gtk_marshal_VOID__VOID,
1376 * @widget: the object which received the signal.
1378 widget_signals[UNMAP] =
1379 g_signal_new (I_("unmap"),
1380 G_TYPE_FROM_CLASS (gobject_class),
1382 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1384 _gtk_marshal_VOID__VOID,
1388 * GtkWidget::realize:
1389 * @widget: the object which received the signal.
1391 widget_signals[REALIZE] =
1392 g_signal_new (I_("realize"),
1393 G_TYPE_FROM_CLASS (gobject_class),
1395 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1397 _gtk_marshal_VOID__VOID,
1401 * GtkWidget::unrealize:
1402 * @widget: the object which received the signal.
1404 widget_signals[UNREALIZE] =
1405 g_signal_new (I_("unrealize"),
1406 G_TYPE_FROM_CLASS (gobject_class),
1408 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1410 _gtk_marshal_VOID__VOID,
1414 * GtkWidget::size-allocate:
1415 * @widget: the object which received the signal.
1418 widget_signals[SIZE_ALLOCATE] =
1419 g_signal_new (I_("size-allocate"),
1420 G_TYPE_FROM_CLASS (gobject_class),
1422 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1424 _gtk_marshal_VOID__BOXED,
1426 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1429 * GtkWidget::state-changed:
1430 * @widget: the object which received the signal.
1431 * @state: the previous state
1433 * The ::state-changed signal is emitted when the widget state changes.
1434 * See gtk_widget_get_state().
1436 widget_signals[STATE_CHANGED] =
1437 g_signal_new (I_("state-changed"),
1438 G_TYPE_FROM_CLASS (gobject_class),
1440 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1442 _gtk_marshal_VOID__ENUM,
1444 GTK_TYPE_STATE_TYPE);
1447 * GtkWidget::parent-set:
1448 * @widget: the object on which the signal is emitted
1449 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1450 * just got its initial parent.
1452 * The ::parent-set signal is emitted when a new parent
1453 * has been set on a widget.
1455 widget_signals[PARENT_SET] =
1456 g_signal_new (I_("parent-set"),
1457 G_TYPE_FROM_CLASS (gobject_class),
1459 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1461 _gtk_marshal_VOID__OBJECT,
1466 * GtkWidget::hierarchy-changed:
1467 * @widget: the object on which the signal is emitted
1468 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1469 * if the widget was previously unanchored
1471 * The ::hierarchy-changed signal is emitted when the
1472 * anchored state of a widget changes. A widget is
1473 * <firstterm>anchored</firstterm> when its toplevel
1474 * ancestor is a #GtkWindow. This signal is emitted when
1475 * a widget changes from un-anchored to anchored or vice-versa.
1477 widget_signals[HIERARCHY_CHANGED] =
1478 g_signal_new (I_("hierarchy-changed"),
1479 G_TYPE_FROM_CLASS (gobject_class),
1481 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1483 _gtk_marshal_VOID__OBJECT,
1488 * GtkWidget::style-set:
1489 * @widget: the object on which the signal is emitted
1490 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1491 * just got its initial style
1493 * The ::style-set signal is emitted when a new style has been set
1494 * on a widget. Note that style-modifying functions like
1495 * gtk_widget_modify_base() also cause this signal to be emitted.
1497 widget_signals[STYLE_SET] =
1498 g_signal_new (I_("style-set"),
1499 G_TYPE_FROM_CLASS (gobject_class),
1501 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1503 _gtk_marshal_VOID__OBJECT,
1507 widget_signals[STYLE_UPDATED] =
1508 g_signal_new (I_("style-updated"),
1509 G_TYPE_FROM_CLASS (gobject_class),
1511 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1513 g_cclosure_marshal_VOID__VOID,
1517 * GtkWidget::direction-changed:
1518 * @widget: the object on which the signal is emitted
1519 * @previous_direction: the previous text direction of @widget
1521 * The ::direction-changed signal is emitted when the text direction
1522 * of a widget changes.
1524 widget_signals[DIRECTION_CHANGED] =
1525 g_signal_new (I_("direction-changed"),
1526 G_TYPE_FROM_CLASS (gobject_class),
1528 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1530 _gtk_marshal_VOID__ENUM,
1532 GTK_TYPE_TEXT_DIRECTION);
1535 * GtkWidget::grab-notify:
1536 * @widget: the object which received the signal
1537 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1538 * if it becomes unshadowed
1540 * The ::grab-notify signal is emitted when a widget becomes
1541 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1542 * another widget, or when it becomes unshadowed due to a grab
1545 * A widget is shadowed by a gtk_grab_add() when the topmost
1546 * grab widget in the grab stack of its window group is not
1549 widget_signals[GRAB_NOTIFY] =
1550 g_signal_new (I_("grab-notify"),
1551 G_TYPE_FROM_CLASS (gobject_class),
1553 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1555 _gtk_marshal_VOID__BOOLEAN,
1560 * GtkWidget::child-notify:
1561 * @widget: the object which received the signal
1562 * @pspec: the #GParamSpec of the changed child property
1564 * The ::child-notify signal is emitted for each
1565 * <link linkend="child-properties">child property</link> that has
1566 * changed on an object. The signal's detail holds the property name.
1568 widget_signals[CHILD_NOTIFY] =
1569 g_signal_new (I_("child-notify"),
1570 G_TYPE_FROM_CLASS (gobject_class),
1571 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1572 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1574 g_cclosure_marshal_VOID__PARAM,
1580 * @widget: the object which received the signal
1581 * @cr: the cairo context to draw to
1583 * This signal is emitted when a widget is supposed to render itself.
1584 * The @widget's top left corner must be painted at the origin of
1585 * the passed in context and be sized to the values returned by
1586 * gtk_widget_get_allocated_width() and
1587 * gtk_widget_get_allocated_height().
1589 * Signal handlers connected to this signal can modify the cairo
1590 * context passed as @cr in any way they like and don't need to
1591 * restore it. The signal emission takes care of calling cairo_save()
1592 * before and cairo_restore() after invoking the handler.
1594 widget_signals[DRAW] =
1595 g_signal_new (I_("draw"),
1596 G_TYPE_FROM_CLASS (gobject_class),
1598 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1599 _gtk_boolean_handled_accumulator, NULL,
1600 gtk_widget_draw_marshaller,
1602 CAIRO_GOBJECT_TYPE_CONTEXT);
1605 * GtkWidget::mnemonic-activate:
1606 * @widget: the object which received the signal.
1609 widget_signals[MNEMONIC_ACTIVATE] =
1610 g_signal_new (I_("mnemonic-activate"),
1611 G_TYPE_FROM_CLASS (gobject_class),
1613 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1614 _gtk_boolean_handled_accumulator, NULL,
1615 _gtk_marshal_BOOLEAN__BOOLEAN,
1620 * GtkWidget::grab-focus:
1621 * @widget: the object which received the signal.
1623 widget_signals[GRAB_FOCUS] =
1624 g_signal_new (I_("grab-focus"),
1625 G_TYPE_FROM_CLASS (gobject_class),
1626 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1627 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1629 _gtk_marshal_VOID__VOID,
1634 * @widget: the object which received the signal.
1637 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1639 widget_signals[FOCUS] =
1640 g_signal_new (I_("focus"),
1641 G_TYPE_FROM_CLASS (klass),
1643 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1644 _gtk_boolean_handled_accumulator, NULL,
1645 _gtk_marshal_BOOLEAN__ENUM,
1647 GTK_TYPE_DIRECTION_TYPE);
1650 * GtkWidget::move-focus:
1651 * @widget: the object which received the signal.
1654 widget_signals[MOVE_FOCUS] =
1655 g_signal_new (I_("move-focus"),
1656 G_TYPE_FROM_CLASS (klass),
1657 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1658 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1660 _gtk_marshal_VOID__ENUM,
1663 GTK_TYPE_DIRECTION_TYPE);
1666 * GtkWidget::keynav-failed:
1667 * @widget: the object which received the signal
1668 * @direction: the direction of movement
1670 * Gets emitted if keyboard navigation fails.
1671 * See gtk_widget_keynav_failed() for details.
1673 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1674 * if the emitting widget should try to handle the keyboard
1675 * navigation attempt in its parent container(s).
1679 widget_signals[KEYNAV_FAILED] =
1680 g_signal_new (I_("keynav-failed"),
1681 G_TYPE_FROM_CLASS (klass),
1683 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1684 _gtk_boolean_handled_accumulator, NULL,
1685 _gtk_marshal_BOOLEAN__ENUM,
1687 GTK_TYPE_DIRECTION_TYPE);
1691 * @widget: the object which received the signal.
1692 * @event: the #GdkEvent which triggered this signal
1694 * The GTK+ main loop will emit three signals for each GDK event delivered
1695 * to a widget: one generic ::event signal, another, more specific,
1696 * signal that matches the type of event delivered (e.g.
1697 * #GtkWidget::key-press-event) and finally a generic
1698 * #GtkWidget::event-after signal.
1700 * Returns: %TRUE to stop other handlers from being invoked for the event
1701 * and to cancel the emission of the second specific ::event signal.
1702 * %FALSE to propagate the event further and to allow the emission of
1703 * the second signal. The ::event-after signal is emitted regardless of
1706 widget_signals[EVENT] =
1707 g_signal_new (I_("event"),
1708 G_TYPE_FROM_CLASS (klass),
1710 G_STRUCT_OFFSET (GtkWidgetClass, event),
1711 _gtk_boolean_handled_accumulator, NULL,
1712 _gtk_marshal_BOOLEAN__BOXED,
1714 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1717 * GtkWidget::event-after:
1718 * @widget: the object which received the signal.
1719 * @event: the #GdkEvent which triggered this signal
1721 * After the emission of the #GtkWidget::event signal and (optionally)
1722 * the second more specific signal, ::event-after will be emitted
1723 * regardless of the previous two signals handlers return values.
1726 widget_signals[EVENT_AFTER] =
1727 g_signal_new (I_("event-after"),
1728 G_TYPE_FROM_CLASS (klass),
1732 _gtk_marshal_VOID__BOXED,
1734 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1737 * GtkWidget::button-press-event:
1738 * @widget: the object which received the signal.
1739 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1742 * The ::button-press-event signal will be emitted when a button
1743 * (typically from a mouse) is pressed.
1745 * To receive this signal, the #GdkWindow associated to the
1746 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1748 * This signal will be sent to the grab widget if there is one.
1750 * Returns: %TRUE to stop other handlers from being invoked for the event.
1751 * %FALSE to propagate the event further.
1753 widget_signals[BUTTON_PRESS_EVENT] =
1754 g_signal_new (I_("button-press-event"),
1755 G_TYPE_FROM_CLASS (klass),
1757 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1758 _gtk_boolean_handled_accumulator, NULL,
1759 _gtk_marshal_BOOLEAN__BOXED,
1761 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1764 * GtkWidget::button-release-event:
1765 * @widget: the object which received the signal.
1766 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1769 * The ::button-release-event signal will be emitted when a button
1770 * (typically from a mouse) is released.
1772 * To receive this signal, the #GdkWindow associated to the
1773 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1775 * This signal will be sent to the grab widget if there is one.
1777 * Returns: %TRUE to stop other handlers from being invoked for the event.
1778 * %FALSE to propagate the event further.
1780 widget_signals[BUTTON_RELEASE_EVENT] =
1781 g_signal_new (I_("button-release-event"),
1782 G_TYPE_FROM_CLASS (klass),
1784 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1785 _gtk_boolean_handled_accumulator, NULL,
1786 _gtk_marshal_BOOLEAN__BOXED,
1788 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1791 * GtkWidget::scroll-event:
1792 * @widget: the object which received the signal.
1793 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1796 * The ::scroll-event signal is emitted when a button in the 4 to 7
1797 * range is pressed. Wheel mice are usually configured to generate
1798 * button press events for buttons 4 and 5 when the wheel is turned.
1800 * To receive this signal, the #GdkWindow associated to the widget needs
1801 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1803 * This signal will be sent to the grab widget if there is one.
1805 * Returns: %TRUE to stop other handlers from being invoked for the event.
1806 * %FALSE to propagate the event further.
1808 widget_signals[SCROLL_EVENT] =
1809 g_signal_new (I_("scroll-event"),
1810 G_TYPE_FROM_CLASS (klass),
1812 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1813 _gtk_boolean_handled_accumulator, NULL,
1814 _gtk_marshal_BOOLEAN__BOXED,
1816 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1819 * GtkWidget::motion-notify-event:
1820 * @widget: the object which received the signal.
1821 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1824 * The ::motion-notify-event signal is emitted when the pointer moves
1825 * over the widget's #GdkWindow.
1827 * To receive this signal, the #GdkWindow associated to the widget
1828 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1830 * This signal will be sent to the grab widget if there is one.
1832 * Returns: %TRUE to stop other handlers from being invoked for the event.
1833 * %FALSE to propagate the event further.
1835 widget_signals[MOTION_NOTIFY_EVENT] =
1836 g_signal_new (I_("motion-notify-event"),
1837 G_TYPE_FROM_CLASS (klass),
1839 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1840 _gtk_boolean_handled_accumulator, NULL,
1841 _gtk_marshal_BOOLEAN__BOXED,
1843 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1846 * GtkWidget::composited-changed:
1847 * @widget: the object on which the signal is emitted
1849 * The ::composited-changed signal is emitted when the composited
1850 * status of @widget<!-- -->s screen changes.
1851 * See gdk_screen_is_composited().
1853 widget_signals[COMPOSITED_CHANGED] =
1854 g_signal_new (I_("composited-changed"),
1855 G_TYPE_FROM_CLASS (klass),
1856 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1857 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1859 _gtk_marshal_VOID__VOID,
1863 * GtkWidget::delete-event:
1864 * @widget: the object which received the signal
1865 * @event: the event which triggered this signal
1867 * The ::delete-event signal is emitted if a user requests that
1868 * a toplevel window is closed. The default handler for this signal
1869 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1870 * this signal will cause the window to be hidden instead, so that
1871 * it can later be shown again without reconstructing it.
1873 * Returns: %TRUE to stop other handlers from being invoked for the event.
1874 * %FALSE to propagate the event further.
1876 widget_signals[DELETE_EVENT] =
1877 g_signal_new (I_("delete-event"),
1878 G_TYPE_FROM_CLASS (klass),
1880 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1881 _gtk_boolean_handled_accumulator, NULL,
1882 _gtk_marshal_BOOLEAN__BOXED,
1884 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1887 * GtkWidget::destroy-event:
1888 * @widget: the object which received the signal.
1889 * @event: the event which triggered this signal
1891 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1892 * You rarely get this signal, because most widgets disconnect themselves
1893 * from their window before they destroy it, so no widget owns the
1894 * window at destroy time.
1896 * To receive this signal, the #GdkWindow associated to the widget needs
1897 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1898 * automatically for all new windows.
1900 * Returns: %TRUE to stop other handlers from being invoked for the event.
1901 * %FALSE to propagate the event further.
1903 widget_signals[DESTROY_EVENT] =
1904 g_signal_new (I_("destroy-event"),
1905 G_TYPE_FROM_CLASS (klass),
1907 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1908 _gtk_boolean_handled_accumulator, NULL,
1909 _gtk_marshal_BOOLEAN__BOXED,
1911 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1914 * GtkWidget::key-press-event:
1915 * @widget: the object which received the signal
1916 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1918 * The ::key-press-event signal is emitted when a key is pressed.
1920 * To receive this signal, the #GdkWindow associated to the widget needs
1921 * to enable the #GDK_KEY_PRESS_MASK mask.
1923 * This signal will be sent to the grab widget if there is one.
1925 * Returns: %TRUE to stop other handlers from being invoked for the event.
1926 * %FALSE to propagate the event further.
1928 widget_signals[KEY_PRESS_EVENT] =
1929 g_signal_new (I_("key-press-event"),
1930 G_TYPE_FROM_CLASS (klass),
1932 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1933 _gtk_boolean_handled_accumulator, NULL,
1934 _gtk_marshal_BOOLEAN__BOXED,
1936 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1939 * GtkWidget::key-release-event:
1940 * @widget: the object which received the signal
1941 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1943 * The ::key-release-event signal is emitted when a key is pressed.
1945 * To receive this signal, the #GdkWindow associated to the widget needs
1946 * to enable the #GDK_KEY_RELEASE_MASK mask.
1948 * This signal will be sent to the grab widget if there is one.
1950 * Returns: %TRUE to stop other handlers from being invoked for the event.
1951 * %FALSE to propagate the event further.
1953 widget_signals[KEY_RELEASE_EVENT] =
1954 g_signal_new (I_("key-release-event"),
1955 G_TYPE_FROM_CLASS (klass),
1957 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1958 _gtk_boolean_handled_accumulator, NULL,
1959 _gtk_marshal_BOOLEAN__BOXED,
1961 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1964 * GtkWidget::enter-notify-event:
1965 * @widget: the object which received the signal
1966 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1969 * The ::enter-notify-event will be emitted when the pointer enters
1970 * the @widget's window.
1972 * To receive this signal, the #GdkWindow associated to the widget needs
1973 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1975 * This signal will be sent to the grab widget if there is one.
1977 * Returns: %TRUE to stop other handlers from being invoked for the event.
1978 * %FALSE to propagate the event further.
1980 widget_signals[ENTER_NOTIFY_EVENT] =
1981 g_signal_new (I_("enter-notify-event"),
1982 G_TYPE_FROM_CLASS (klass),
1984 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1985 _gtk_boolean_handled_accumulator, NULL,
1986 _gtk_marshal_BOOLEAN__BOXED,
1988 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1991 * GtkWidget::leave-notify-event:
1992 * @widget: the object which received the signal
1993 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1996 * The ::leave-notify-event will be emitted when the pointer leaves
1997 * the @widget's window.
1999 * To receive this signal, the #GdkWindow associated to the widget needs
2000 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2002 * This signal will be sent to the grab widget if there is one.
2004 * Returns: %TRUE to stop other handlers from being invoked for the event.
2005 * %FALSE to propagate the event further.
2007 widget_signals[LEAVE_NOTIFY_EVENT] =
2008 g_signal_new (I_("leave-notify-event"),
2009 G_TYPE_FROM_CLASS (klass),
2011 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2012 _gtk_boolean_handled_accumulator, NULL,
2013 _gtk_marshal_BOOLEAN__BOXED,
2015 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2018 * GtkWidget::configure-event:
2019 * @widget: the object which received the signal
2020 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2023 * The ::configure-event signal will be emitted when the size, position or
2024 * stacking of the @widget's window has changed.
2026 * To receive this signal, the #GdkWindow associated to the widget needs
2027 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2028 * automatically for all new windows.
2030 * Returns: %TRUE to stop other handlers from being invoked for the event.
2031 * %FALSE to propagate the event further.
2033 widget_signals[CONFIGURE_EVENT] =
2034 g_signal_new (I_("configure-event"),
2035 G_TYPE_FROM_CLASS (klass),
2037 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2038 _gtk_boolean_handled_accumulator, NULL,
2039 _gtk_marshal_BOOLEAN__BOXED,
2041 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2044 * GtkWidget::focus-in-event:
2045 * @widget: the object which received the signal
2046 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2049 * The ::focus-in-event signal will be emitted when the keyboard focus
2050 * enters the @widget's window.
2052 * To receive this signal, the #GdkWindow associated to the widget needs
2053 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2055 * Returns: %TRUE to stop other handlers from being invoked for the event.
2056 * %FALSE to propagate the event further.
2058 widget_signals[FOCUS_IN_EVENT] =
2059 g_signal_new (I_("focus-in-event"),
2060 G_TYPE_FROM_CLASS (klass),
2062 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2063 _gtk_boolean_handled_accumulator, NULL,
2064 _gtk_marshal_BOOLEAN__BOXED,
2066 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2069 * GtkWidget::focus-out-event:
2070 * @widget: the object which received the signal
2071 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2074 * The ::focus-out-event signal will be emitted when the keyboard focus
2075 * leaves the @widget's window.
2077 * To receive this signal, the #GdkWindow associated to the widget needs
2078 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2080 * Returns: %TRUE to stop other handlers from being invoked for the event.
2081 * %FALSE to propagate the event further.
2083 widget_signals[FOCUS_OUT_EVENT] =
2084 g_signal_new (I_("focus-out-event"),
2085 G_TYPE_FROM_CLASS (klass),
2087 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2088 _gtk_boolean_handled_accumulator, NULL,
2089 _gtk_marshal_BOOLEAN__BOXED,
2091 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2094 * GtkWidget::map-event:
2095 * @widget: the object which received the signal
2096 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2098 * The ::map-event signal will be emitted when the @widget's window is
2099 * mapped. A window is mapped when it becomes visible on the screen.
2101 * To receive this signal, the #GdkWindow associated to the widget needs
2102 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2103 * automatically for all new windows.
2105 * Returns: %TRUE to stop other handlers from being invoked for the event.
2106 * %FALSE to propagate the event further.
2108 widget_signals[MAP_EVENT] =
2109 g_signal_new (I_("map-event"),
2110 G_TYPE_FROM_CLASS (klass),
2112 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2113 _gtk_boolean_handled_accumulator, NULL,
2114 _gtk_marshal_BOOLEAN__BOXED,
2116 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2119 * GtkWidget::unmap-event:
2120 * @widget: the object which received the signal
2121 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2123 * The ::unmap-event signal may be emitted when the @widget's window is
2124 * unmapped. A window is unmapped when it becomes invisible on the screen.
2126 * For performance reasons GTK+ may not emit ::unmap-event, so one
2127 * should always also implement ::unrealize in order to release
2128 * resources and disconnect signal handlers.
2130 * To receive this signal, the #GdkWindow associated to the widget needs
2131 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2132 * automatically for all new windows.
2134 * Returns: %TRUE to stop other handlers from being invoked for the event.
2135 * %FALSE to propagate the event further.
2137 widget_signals[UNMAP_EVENT] =
2138 g_signal_new (I_("unmap-event"),
2139 G_TYPE_FROM_CLASS (klass),
2141 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2142 _gtk_boolean_handled_accumulator, NULL,
2143 _gtk_marshal_BOOLEAN__BOXED,
2145 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2148 * GtkWidget::property-notify-event:
2149 * @widget: the object which received the signal
2150 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2153 * The ::property-notify-event signal will be emitted when a property on
2154 * the @widget's window has been changed or deleted.
2156 * To receive this signal, the #GdkWindow associated to the widget needs
2157 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2159 * Returns: %TRUE to stop other handlers from being invoked for the event.
2160 * %FALSE to propagate the event further.
2162 widget_signals[PROPERTY_NOTIFY_EVENT] =
2163 g_signal_new (I_("property-notify-event"),
2164 G_TYPE_FROM_CLASS (klass),
2166 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2167 _gtk_boolean_handled_accumulator, NULL,
2168 _gtk_marshal_BOOLEAN__BOXED,
2170 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2173 * GtkWidget::selection-clear-event:
2174 * @widget: the object which received the signal
2175 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2178 * The ::selection-clear-event signal will be emitted when the
2179 * the @widget's window has lost ownership of a selection.
2181 * Returns: %TRUE to stop other handlers from being invoked for the event.
2182 * %FALSE to propagate the event further.
2184 widget_signals[SELECTION_CLEAR_EVENT] =
2185 g_signal_new (I_("selection-clear-event"),
2186 G_TYPE_FROM_CLASS (klass),
2188 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2189 _gtk_boolean_handled_accumulator, NULL,
2190 _gtk_marshal_BOOLEAN__BOXED,
2192 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2195 * GtkWidget::selection-request-event:
2196 * @widget: the object which received the signal
2197 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2200 * The ::selection-request-event signal will be emitted when
2201 * another client requests ownership of the selection owned by
2202 * the @widget's window.
2204 * Returns: %TRUE to stop other handlers from being invoked for the event.
2205 * %FALSE to propagate the event further.
2207 widget_signals[SELECTION_REQUEST_EVENT] =
2208 g_signal_new (I_("selection-request-event"),
2209 G_TYPE_FROM_CLASS (klass),
2211 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2212 _gtk_boolean_handled_accumulator, NULL,
2213 _gtk_marshal_BOOLEAN__BOXED,
2215 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2218 * GtkWidget::selection-notify-event:
2219 * @widget: the object which received the signal.
2222 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2224 widget_signals[SELECTION_NOTIFY_EVENT] =
2225 g_signal_new (I_("selection-notify-event"),
2226 G_TYPE_FROM_CLASS (klass),
2228 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2229 _gtk_boolean_handled_accumulator, NULL,
2230 _gtk_marshal_BOOLEAN__BOXED,
2232 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2235 * GtkWidget::selection-received:
2236 * @widget: the object which received the signal.
2240 widget_signals[SELECTION_RECEIVED] =
2241 g_signal_new (I_("selection-received"),
2242 G_TYPE_FROM_CLASS (klass),
2244 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2246 _gtk_marshal_VOID__BOXED_UINT,
2248 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2252 * GtkWidget::selection-get:
2253 * @widget: the object which received the signal.
2258 widget_signals[SELECTION_GET] =
2259 g_signal_new (I_("selection-get"),
2260 G_TYPE_FROM_CLASS (klass),
2262 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2264 _gtk_marshal_VOID__BOXED_UINT_UINT,
2266 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2271 * GtkWidget::proximity-in-event:
2272 * @widget: the object which received the signal
2273 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2276 * To receive this signal the #GdkWindow associated to the widget needs
2277 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2279 * This signal will be sent to the grab widget if there is one.
2281 * Returns: %TRUE to stop other handlers from being invoked for the event.
2282 * %FALSE to propagate the event further.
2284 widget_signals[PROXIMITY_IN_EVENT] =
2285 g_signal_new (I_("proximity-in-event"),
2286 G_TYPE_FROM_CLASS (klass),
2288 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2289 _gtk_boolean_handled_accumulator, NULL,
2290 _gtk_marshal_BOOLEAN__BOXED,
2292 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2295 * GtkWidget::proximity-out-event:
2296 * @widget: the object which received the signal
2297 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2300 * To receive this signal the #GdkWindow associated to the widget needs
2301 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2303 * This signal will be sent to the grab widget if there is one.
2305 * Returns: %TRUE to stop other handlers from being invoked for the event.
2306 * %FALSE to propagate the event further.
2308 widget_signals[PROXIMITY_OUT_EVENT] =
2309 g_signal_new (I_("proximity-out-event"),
2310 G_TYPE_FROM_CLASS (klass),
2312 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2313 _gtk_boolean_handled_accumulator, NULL,
2314 _gtk_marshal_BOOLEAN__BOXED,
2316 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2319 * GtkWidget::drag-leave:
2320 * @widget: the object which received the signal.
2321 * @drag_context: the drag context
2322 * @time: the timestamp of the motion event
2324 * The ::drag-leave signal is emitted on the drop site when the cursor
2325 * leaves the widget. A typical reason to connect to this signal is to
2326 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2327 * with gtk_drag_unhighlight()
2329 widget_signals[DRAG_LEAVE] =
2330 g_signal_new (I_("drag-leave"),
2331 G_TYPE_FROM_CLASS (klass),
2333 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2335 _gtk_marshal_VOID__OBJECT_UINT,
2337 GDK_TYPE_DRAG_CONTEXT,
2341 * GtkWidget::drag-begin:
2342 * @widget: the object which received the signal
2343 * @drag_context: the drag context
2345 * The ::drag-begin signal is emitted on the drag source when a drag is
2346 * started. A typical reason to connect to this signal is to set up a
2347 * custom drag icon with gtk_drag_source_set_icon().
2349 * Note that some widgets set up a drag icon in the default handler of
2350 * this signal, so you may have to use g_signal_connect_after() to
2351 * override what the default handler did.
2353 widget_signals[DRAG_BEGIN] =
2354 g_signal_new (I_("drag-begin"),
2355 G_TYPE_FROM_CLASS (klass),
2357 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2359 _gtk_marshal_VOID__OBJECT,
2361 GDK_TYPE_DRAG_CONTEXT);
2364 * GtkWidget::drag-end:
2365 * @widget: the object which received the signal
2366 * @drag_context: the drag context
2368 * The ::drag-end signal is emitted on the drag source when a drag is
2369 * finished. A typical reason to connect to this signal is to undo
2370 * things done in #GtkWidget::drag-begin.
2372 widget_signals[DRAG_END] =
2373 g_signal_new (I_("drag-end"),
2374 G_TYPE_FROM_CLASS (klass),
2376 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2378 _gtk_marshal_VOID__OBJECT,
2380 GDK_TYPE_DRAG_CONTEXT);
2383 * GtkWidget::drag-data-delete:
2384 * @widget: the object which received the signal
2385 * @drag_context: the drag context
2387 * The ::drag-data-delete signal is emitted on the drag source when a drag
2388 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2389 * handler is responsible for deleting the data that has been dropped. What
2390 * "delete" means depends on the context of the drag operation.
2392 widget_signals[DRAG_DATA_DELETE] =
2393 g_signal_new (I_("drag-data-delete"),
2394 G_TYPE_FROM_CLASS (klass),
2396 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2398 _gtk_marshal_VOID__OBJECT,
2400 GDK_TYPE_DRAG_CONTEXT);
2403 * GtkWidget::drag-failed:
2404 * @widget: the object which received the signal
2405 * @drag_context: the drag context
2406 * @result: the result of the drag operation
2408 * The ::drag-failed signal is emitted on the drag source when a drag has
2409 * failed. The signal handler may hook custom code to handle a failed DND
2410 * operation based on the type of error, it returns %TRUE is the failure has
2411 * been already handled (not showing the default "drag operation failed"
2412 * animation), otherwise it returns %FALSE.
2414 * Return value: %TRUE if the failed drag operation has been already handled.
2418 widget_signals[DRAG_FAILED] =
2419 g_signal_new (I_("drag-failed"),
2420 G_TYPE_FROM_CLASS (klass),
2422 0, _gtk_boolean_handled_accumulator, NULL,
2423 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2425 GDK_TYPE_DRAG_CONTEXT,
2426 GTK_TYPE_DRAG_RESULT);
2429 * GtkWidget::drag-motion:
2430 * @widget: the object which received the signal
2431 * @drag_context: the drag context
2432 * @x: the x coordinate of the current cursor position
2433 * @y: the y coordinate of the current cursor position
2434 * @time: the timestamp of the motion event
2435 * @returns: whether the cursor position is in a drop zone
2437 * The drag-motion signal is emitted on the drop site when the user
2438 * moves the cursor over the widget during a drag. The signal handler
2439 * must determine whether the cursor position is in a drop zone or not.
2440 * If it is not in a drop zone, it returns %FALSE and no further processing
2441 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2442 * handler is responsible for providing the necessary information for
2443 * displaying feedback to the user, by calling gdk_drag_status().
2445 * If the decision whether the drop will be accepted or rejected can't be
2446 * made based solely on the cursor position and the type of the data, the
2447 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2448 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2449 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2450 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2451 * when using the drag-motion signal that way.
2453 * Also note that there is no drag-enter signal. The drag receiver has to
2454 * keep track of whether he has received any drag-motion signals since the
2455 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2456 * an "enter" signal. Upon an "enter", the handler will typically highlight
2457 * the drop site with gtk_drag_highlight().
2460 * drag_motion (GtkWidget *widget,
2461 * GdkDragContext *context,
2468 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2470 * if (!private_data->drag_highlight)
2472 * private_data->drag_highlight = 1;
2473 * gtk_drag_highlight (widget);
2476 * target = gtk_drag_dest_find_target (widget, context, NULL);
2477 * if (target == GDK_NONE)
2478 * gdk_drag_status (context, 0, time);
2481 * private_data->pending_status = context->suggested_action;
2482 * gtk_drag_get_data (widget, context, target, time);
2489 * drag_data_received (GtkWidget *widget,
2490 * GdkDragContext *context,
2493 * GtkSelectionData *selection_data,
2497 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2499 * if (private_data->suggested_action)
2501 * private_data->suggested_action = 0;
2503 * /* We are getting this data due to a request in drag_motion,
2504 * * rather than due to a request in drag_drop, so we are just
2505 * * supposed to call gdk_drag_status (), not actually paste in
2508 * str = gtk_selection_data_get_text (selection_data);
2509 * if (!data_is_acceptable (str))
2510 * gdk_drag_status (context, 0, time);
2512 * gdk_drag_status (context, private_data->suggested_action, time);
2516 * /* accept the drop */
2521 widget_signals[DRAG_MOTION] =
2522 g_signal_new (I_("drag-motion"),
2523 G_TYPE_FROM_CLASS (klass),
2525 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2526 _gtk_boolean_handled_accumulator, NULL,
2527 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2529 GDK_TYPE_DRAG_CONTEXT,
2535 * GtkWidget::drag-drop:
2536 * @widget: the object which received the signal
2537 * @drag_context: the drag context
2538 * @x: the x coordinate of the current cursor position
2539 * @y: the y coordinate of the current cursor position
2540 * @time: the timestamp of the motion event
2541 * @returns: whether the cursor position is in a drop zone
2543 * The ::drag-drop signal is emitted on the drop site when the user drops
2544 * the data onto the widget. The signal handler must determine whether
2545 * the cursor position is in a drop zone or not. If it is not in a drop
2546 * zone, it returns %FALSE and no further processing is necessary.
2547 * Otherwise, the handler returns %TRUE. In this case, the handler must
2548 * ensure that gtk_drag_finish() is called to let the source know that
2549 * the drop is done. The call to gtk_drag_finish() can be done either
2550 * directly or in a #GtkWidget::drag-data-received handler which gets
2551 * triggered by calling gtk_drag_get_data() to receive the data for one
2552 * or more of the supported targets.
2554 widget_signals[DRAG_DROP] =
2555 g_signal_new (I_("drag-drop"),
2556 G_TYPE_FROM_CLASS (klass),
2558 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2559 _gtk_boolean_handled_accumulator, NULL,
2560 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2562 GDK_TYPE_DRAG_CONTEXT,
2568 * GtkWidget::drag-data-get:
2569 * @widget: the object which received the signal
2570 * @drag_context: the drag context
2571 * @data: the #GtkSelectionData to be filled with the dragged data
2572 * @info: the info that has been registered with the target in the
2574 * @time: the timestamp at which the data was requested
2576 * The ::drag-data-get signal is emitted on the drag source when the drop
2577 * site requests the data which is dragged. It is the responsibility of
2578 * the signal handler to fill @data with the data in the format which
2579 * is indicated by @info. See gtk_selection_data_set() and
2580 * gtk_selection_data_set_text().
2582 widget_signals[DRAG_DATA_GET] =
2583 g_signal_new (I_("drag-data-get"),
2584 G_TYPE_FROM_CLASS (klass),
2586 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2588 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2590 GDK_TYPE_DRAG_CONTEXT,
2591 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2596 * GtkWidget::drag-data-received:
2597 * @widget: the object which received the signal
2598 * @drag_context: the drag context
2599 * @x: where the drop happened
2600 * @y: where the drop happened
2601 * @data: the received data
2602 * @info: the info that has been registered with the target in the
2604 * @time: the timestamp at which the data was received
2606 * The ::drag-data-received signal is emitted on the drop site when the
2607 * dragged data has been received. If the data was received in order to
2608 * determine whether the drop will be accepted, the handler is expected
2609 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2610 * If the data was received in response to a #GtkWidget::drag-drop signal
2611 * (and this is the last target to be received), the handler for this
2612 * signal is expected to process the received data and then call
2613 * gtk_drag_finish(), setting the @success parameter depending on whether
2614 * the data was processed successfully.
2616 * The handler may inspect and modify @drag_context->action before calling
2617 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2618 * following example:
2621 * drag_data_received (GtkWidget *widget,
2622 * GdkDragContext *drag_context,
2625 * GtkSelectionData *data,
2629 * if ((data->length >= 0) && (data->format == 8))
2631 * if (drag_context->action == GDK_ACTION_ASK)
2633 * GtkWidget *dialog;
2636 * dialog = gtk_message_dialog_new (NULL,
2637 * GTK_DIALOG_MODAL |
2638 * GTK_DIALOG_DESTROY_WITH_PARENT,
2640 * GTK_BUTTONS_YES_NO,
2641 * "Move the data ?\n");
2642 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2643 * gtk_widget_destroy (dialog);
2645 * if (response == GTK_RESPONSE_YES)
2646 * drag_context->action = GDK_ACTION_MOVE;
2648 * drag_context->action = GDK_ACTION_COPY;
2651 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2655 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2659 widget_signals[DRAG_DATA_RECEIVED] =
2660 g_signal_new (I_("drag-data-received"),
2661 G_TYPE_FROM_CLASS (klass),
2663 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2665 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2667 GDK_TYPE_DRAG_CONTEXT,
2670 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2675 * GtkWidget::visibility-notify-event:
2676 * @widget: the object which received the signal
2677 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2678 * triggered this signal.
2680 * The ::visibility-notify-event will be emitted when the @widget's window
2681 * is obscured or unobscured.
2683 * To receive this signal the #GdkWindow associated to the widget needs
2684 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2686 * Returns: %TRUE to stop other handlers from being invoked for the event.
2687 * %FALSE to propagate the event further.
2689 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2690 g_signal_new (I_("visibility-notify-event"),
2691 G_TYPE_FROM_CLASS (klass),
2693 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2694 _gtk_boolean_handled_accumulator, NULL,
2695 _gtk_marshal_BOOLEAN__BOXED,
2697 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2700 * GtkWidget::client-event:
2701 * @widget: the object which received the signal
2702 * @event: (type Gdk.EventClient): the #GdkEventClient which triggered
2705 * The ::client-event will be emitted when the @widget's window
2706 * receives a message (via a ClientMessage event) from another
2709 * Returns: %TRUE to stop other handlers from being invoked for
2710 * the event. %FALSE to propagate the event further.
2712 widget_signals[CLIENT_EVENT] =
2713 g_signal_new (I_("client-event"),
2714 G_TYPE_FROM_CLASS (klass),
2716 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2717 _gtk_boolean_handled_accumulator, NULL,
2718 _gtk_marshal_BOOLEAN__BOXED,
2720 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2723 * GtkWidget::window-state-event:
2724 * @widget: the object which received the signal
2725 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2726 * triggered this signal.
2728 * The ::window-state-event will be emitted when the state of the
2729 * toplevel window associated to the @widget changes.
2731 * To receive this signal the #GdkWindow associated to the widget
2732 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2733 * this mask automatically for all new windows.
2735 * Returns: %TRUE to stop other handlers from being invoked for the
2736 * event. %FALSE to propagate the event further.
2738 widget_signals[WINDOW_STATE_EVENT] =
2739 g_signal_new (I_("window-state-event"),
2740 G_TYPE_FROM_CLASS (klass),
2742 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2743 _gtk_boolean_handled_accumulator, NULL,
2744 _gtk_marshal_BOOLEAN__BOXED,
2746 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2749 * GtkWidget::damage-event:
2750 * @widget: the object which received the signal
2751 * @event: the #GdkEventExpose event
2753 * Emitted when a redirected window belonging to @widget gets drawn into.
2754 * The region/area members of the event shows what area of the redirected
2755 * drawable was drawn into.
2757 * Returns: %TRUE to stop other handlers from being invoked for the event.
2758 * %FALSE to propagate the event further.
2762 widget_signals[DAMAGE_EVENT] =
2763 g_signal_new (I_("damage-event"),
2764 G_TYPE_FROM_CLASS (klass),
2766 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2767 _gtk_boolean_handled_accumulator, NULL,
2768 _gtk_marshal_BOOLEAN__BOXED,
2770 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2773 * GtkWidget::grab-broken-event:
2774 * @widget: the object which received the signal
2775 * @event: the #GdkEventGrabBroken event
2777 * Emitted when a pointer or keyboard grab on a window belonging
2778 * to @widget gets broken.
2780 * On X11, this happens when the grab window becomes unviewable
2781 * (i.e. it or one of its ancestors is unmapped), or if the same
2782 * application grabs the pointer or keyboard again.
2784 * Returns: %TRUE to stop other handlers from being invoked for
2785 * the event. %FALSE to propagate the event further.
2789 widget_signals[GRAB_BROKEN_EVENT] =
2790 g_signal_new (I_("grab-broken-event"),
2791 G_TYPE_FROM_CLASS (klass),
2793 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2794 _gtk_boolean_handled_accumulator, NULL,
2795 _gtk_marshal_BOOLEAN__BOXED,
2797 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2800 * GtkWidget::query-tooltip:
2801 * @widget: the object which received the signal
2802 * @x: the x coordinate of the cursor position where the request has
2803 * been emitted, relative to @widget->window
2804 * @y: the y coordinate of the cursor position where the request has
2805 * been emitted, relative to @widget->window
2806 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2807 * @tooltip: a #GtkTooltip
2809 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2810 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2811 * focus in keyboard mode.
2813 * Using the given coordinates, the signal handler should determine
2814 * whether a tooltip should be shown for @widget. If this is the case
2815 * %TRUE should be returned, %FALSE otherwise. Note that if
2816 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2817 * should not be used.
2819 * The signal handler is free to manipulate @tooltip with the therefore
2820 * destined function calls.
2822 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2826 widget_signals[QUERY_TOOLTIP] =
2827 g_signal_new (I_("query-tooltip"),
2828 G_TYPE_FROM_CLASS (klass),
2830 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2831 _gtk_boolean_handled_accumulator, NULL,
2832 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2840 * GtkWidget::popup-menu
2841 * @widget: the object which received the signal
2843 * This signal gets emitted whenever a widget should pop up a context
2844 * menu. This usually happens through the standard key binding mechanism;
2845 * by pressing a certain key while a widget is focused, the user can cause
2846 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2847 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2848 * for an example of how to use this signal.
2850 * Returns: %TRUE if a menu was activated
2852 widget_signals[POPUP_MENU] =
2853 g_signal_new (I_("popup-menu"),
2854 G_TYPE_FROM_CLASS (klass),
2855 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2856 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2857 _gtk_boolean_handled_accumulator, NULL,
2858 _gtk_marshal_BOOLEAN__VOID,
2862 * GtkWidget::show-help:
2863 * @widget: the object which received the signal.
2866 widget_signals[SHOW_HELP] =
2867 g_signal_new (I_("show-help"),
2868 G_TYPE_FROM_CLASS (klass),
2869 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2870 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2871 _gtk_boolean_handled_accumulator, NULL,
2872 _gtk_marshal_BOOLEAN__ENUM,
2874 GTK_TYPE_WIDGET_HELP_TYPE);
2877 * GtkWidget::accel-closures-changed:
2878 * @widget: the object which received the signal.
2880 widget_signals[ACCEL_CLOSURES_CHANGED] =
2881 g_signal_new (I_("accel-closures-changed"),
2882 G_TYPE_FROM_CLASS (klass),
2886 _gtk_marshal_VOID__VOID,
2890 * GtkWidget::screen-changed:
2891 * @widget: the object on which the signal is emitted
2892 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2893 * widget was not associated with a screen before
2895 * The ::screen-changed signal gets emitted when the
2896 * screen of a widget has changed.
2898 widget_signals[SCREEN_CHANGED] =
2899 g_signal_new (I_("screen-changed"),
2900 G_TYPE_FROM_CLASS (klass),
2902 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2904 _gtk_marshal_VOID__OBJECT,
2909 * GtkWidget::can-activate-accel:
2910 * @widget: the object which received the signal
2911 * @signal_id: the ID of a signal installed on @widget
2913 * Determines whether an accelerator that activates the signal
2914 * identified by @signal_id can currently be activated.
2915 * This signal is present to allow applications and derived
2916 * widgets to override the default #GtkWidget handling
2917 * for determining whether an accelerator can be activated.
2919 * Returns: %TRUE if the signal can be activated.
2921 widget_signals[CAN_ACTIVATE_ACCEL] =
2922 g_signal_new (I_("can-activate-accel"),
2923 G_TYPE_FROM_CLASS (klass),
2925 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2926 _gtk_boolean_handled_accumulator, NULL,
2927 _gtk_marshal_BOOLEAN__UINT,
2928 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2930 binding_set = gtk_binding_set_by_class (klass);
2931 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
2933 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
2936 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
2938 GTK_TYPE_WIDGET_HELP_TYPE,
2939 GTK_WIDGET_HELP_TOOLTIP);
2940 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
2942 GTK_TYPE_WIDGET_HELP_TYPE,
2943 GTK_WIDGET_HELP_TOOLTIP);
2944 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
2946 GTK_TYPE_WIDGET_HELP_TYPE,
2947 GTK_WIDGET_HELP_WHATS_THIS);
2948 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
2950 GTK_TYPE_WIDGET_HELP_TYPE,
2951 GTK_WIDGET_HELP_WHATS_THIS);
2953 gtk_widget_class_install_style_property (klass,
2954 g_param_spec_boolean ("interior-focus",
2955 P_("Interior Focus"),
2956 P_("Whether to draw the focus indicator inside widgets"),
2958 GTK_PARAM_READABLE));
2960 gtk_widget_class_install_style_property (klass,
2961 g_param_spec_int ("focus-line-width",
2962 P_("Focus linewidth"),
2963 P_("Width, in pixels, of the focus indicator line"),
2965 GTK_PARAM_READABLE));
2967 gtk_widget_class_install_style_property (klass,
2968 g_param_spec_string ("focus-line-pattern",
2969 P_("Focus line dash pattern"),
2970 P_("Dash pattern used to draw the focus indicator"),
2972 GTK_PARAM_READABLE));
2973 gtk_widget_class_install_style_property (klass,
2974 g_param_spec_int ("focus-padding",
2975 P_("Focus padding"),
2976 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2978 GTK_PARAM_READABLE));
2979 gtk_widget_class_install_style_property (klass,
2980 g_param_spec_boxed ("cursor-color",
2982 P_("Color with which to draw insertion cursor"),
2984 GTK_PARAM_READABLE));
2985 gtk_widget_class_install_style_property (klass,
2986 g_param_spec_boxed ("secondary-cursor-color",
2987 P_("Secondary cursor color"),
2988 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2990 GTK_PARAM_READABLE));
2991 gtk_widget_class_install_style_property (klass,
2992 g_param_spec_float ("cursor-aspect-ratio",
2993 P_("Cursor line aspect ratio"),
2994 P_("Aspect ratio with which to draw insertion cursor"),
2996 GTK_PARAM_READABLE));
2998 gtk_widget_class_install_style_property (klass,
2999 g_param_spec_boolean ("window-dragging",
3000 P_("Window dragging"),
3001 P_("Whether windows can be dragged by clicking on empty areas"),
3003 GTK_PARAM_READABLE));
3006 * GtkWidget:link-color:
3008 * The "link-color" style property defines the color of unvisited links.
3012 gtk_widget_class_install_style_property (klass,
3013 g_param_spec_boxed ("link-color",
3014 P_("Unvisited Link Color"),
3015 P_("Color of unvisited links"),
3017 GTK_PARAM_READABLE));
3020 * GtkWidget:visited-link-color:
3022 * The "visited-link-color" style property defines the color of visited links.
3026 gtk_widget_class_install_style_property (klass,
3027 g_param_spec_boxed ("visited-link-color",
3028 P_("Visited Link Color"),
3029 P_("Color of visited links"),
3031 GTK_PARAM_READABLE));
3034 * GtkWidget:wide-separators:
3036 * The "wide-separators" style property defines whether separators have
3037 * configurable width and should be drawn using a box instead of a line.
3041 gtk_widget_class_install_style_property (klass,
3042 g_param_spec_boolean ("wide-separators",
3043 P_("Wide Separators"),
3044 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3046 GTK_PARAM_READABLE));
3049 * GtkWidget:separator-width:
3051 * The "separator-width" style property defines the width of separators.
3052 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3056 gtk_widget_class_install_style_property (klass,
3057 g_param_spec_int ("separator-width",
3058 P_("Separator Width"),
3059 P_("The width of separators if wide-separators is TRUE"),
3061 GTK_PARAM_READABLE));
3064 * GtkWidget:separator-height:
3066 * The "separator-height" style property defines the height of separators.
3067 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3071 gtk_widget_class_install_style_property (klass,
3072 g_param_spec_int ("separator-height",
3073 P_("Separator Height"),
3074 P_("The height of separators if \"wide-separators\" is TRUE"),
3076 GTK_PARAM_READABLE));
3079 * GtkWidget:scroll-arrow-hlength:
3081 * The "scroll-arrow-hlength" style property defines the length of
3082 * horizontal scroll arrows.
3086 gtk_widget_class_install_style_property (klass,
3087 g_param_spec_int ("scroll-arrow-hlength",
3088 P_("Horizontal Scroll Arrow Length"),
3089 P_("The length of horizontal scroll arrows"),
3091 GTK_PARAM_READABLE));
3094 * GtkWidget:scroll-arrow-vlength:
3096 * The "scroll-arrow-vlength" style property defines the length of
3097 * vertical scroll arrows.
3101 gtk_widget_class_install_style_property (klass,
3102 g_param_spec_int ("scroll-arrow-vlength",
3103 P_("Vertical Scroll Arrow Length"),
3104 P_("The length of vertical scroll arrows"),
3106 GTK_PARAM_READABLE));
3108 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3112 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3116 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3117 for (node = list; node; node = node->next)
3119 GParamSpec *pspec = node->data;
3121 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3122 g_param_spec_unref (pspec);
3128 gtk_widget_set_property (GObject *object,
3130 const GValue *value,
3133 GtkWidget *widget = GTK_WIDGET (object);
3138 gchar *tooltip_markup;
3139 const gchar *tooltip_text;
3140 GtkWindow *tooltip_window;
3143 gtk_widget_set_name (widget, g_value_get_string (value));
3146 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3148 case PROP_WIDTH_REQUEST:
3149 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3151 case PROP_HEIGHT_REQUEST:
3152 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3155 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3157 case PROP_SENSITIVE:
3158 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3160 case PROP_APP_PAINTABLE:
3161 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3163 case PROP_CAN_FOCUS:
3164 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3166 case PROP_HAS_FOCUS:
3167 if (g_value_get_boolean (value))
3168 gtk_widget_grab_focus (widget);
3171 if (g_value_get_boolean (value))
3172 gtk_widget_grab_focus (widget);
3174 case PROP_CAN_DEFAULT:
3175 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3177 case PROP_HAS_DEFAULT:
3178 if (g_value_get_boolean (value))
3179 gtk_widget_grab_default (widget);
3181 case PROP_RECEIVES_DEFAULT:
3182 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3185 gtk_widget_set_style (widget, g_value_get_object (value));
3188 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3189 gtk_widget_set_events (widget, g_value_get_flags (value));
3191 case PROP_EXTENSION_EVENTS:
3192 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
3194 case PROP_NO_SHOW_ALL:
3195 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3197 case PROP_HAS_TOOLTIP:
3198 gtk_widget_real_set_has_tooltip (widget,
3199 g_value_get_boolean (value), FALSE);
3201 case PROP_TOOLTIP_MARKUP:
3202 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3203 tooltip_markup = g_value_dup_string (value);
3205 /* Treat an empty string as a NULL string,
3206 * because an empty string would be useless for a tooltip:
3208 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3210 g_free (tooltip_markup);
3211 tooltip_markup = NULL;
3214 g_object_set_qdata_full (object, quark_tooltip_markup,
3215 tooltip_markup, g_free);
3217 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3218 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3219 if (gtk_widget_get_visible (widget))
3220 gtk_widget_queue_tooltip_query (widget);
3222 case PROP_TOOLTIP_TEXT:
3223 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3225 tooltip_text = g_value_get_string (value);
3227 /* Treat an empty string as a NULL string,
3228 * because an empty string would be useless for a tooltip:
3230 if (tooltip_text && (strlen (tooltip_text) == 0))
3231 tooltip_text = NULL;
3233 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3235 g_object_set_qdata_full (object, quark_tooltip_markup,
3236 tooltip_markup, g_free);
3238 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3239 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3240 if (gtk_widget_get_visible (widget))
3241 gtk_widget_queue_tooltip_query (widget);
3243 case PROP_DOUBLE_BUFFERED:
3244 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3247 gtk_widget_set_halign (widget, g_value_get_enum (value));
3250 gtk_widget_set_valign (widget, g_value_get_enum (value));
3252 case PROP_MARGIN_LEFT:
3253 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3255 case PROP_MARGIN_RIGHT:
3256 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3258 case PROP_MARGIN_TOP:
3259 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3261 case PROP_MARGIN_BOTTOM:
3262 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3265 g_object_freeze_notify (G_OBJECT (widget));
3266 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3267 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3268 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3269 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3270 g_object_thaw_notify (G_OBJECT (widget));
3273 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3275 case PROP_HEXPAND_SET:
3276 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3279 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3281 case PROP_VEXPAND_SET:
3282 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3285 g_object_freeze_notify (G_OBJECT (widget));
3286 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3287 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3288 g_object_thaw_notify (G_OBJECT (widget));
3291 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3297 gtk_widget_get_property (GObject *object,
3302 GtkWidget *widget = GTK_WIDGET (object);
3303 GtkWidgetPrivate *priv = widget->priv;
3312 g_value_set_string (value, priv->name);
3314 g_value_set_static_string (value, "");
3317 g_value_set_object (value, priv->parent);
3319 case PROP_WIDTH_REQUEST:
3322 gtk_widget_get_size_request (widget, &w, NULL);
3323 g_value_set_int (value, w);
3326 case PROP_HEIGHT_REQUEST:
3329 gtk_widget_get_size_request (widget, NULL, &h);
3330 g_value_set_int (value, h);
3334 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3336 case PROP_SENSITIVE:
3337 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3339 case PROP_APP_PAINTABLE:
3340 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3342 case PROP_CAN_FOCUS:
3343 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3345 case PROP_HAS_FOCUS:
3346 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3349 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3351 case PROP_CAN_DEFAULT:
3352 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3354 case PROP_HAS_DEFAULT:
3355 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3357 case PROP_RECEIVES_DEFAULT:
3358 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3360 case PROP_COMPOSITE_CHILD:
3361 g_value_set_boolean (value, widget->priv->composite_child);
3364 g_value_set_object (value, gtk_widget_get_style (widget));
3367 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3368 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3370 case PROP_EXTENSION_EVENTS:
3371 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
3372 g_value_set_enum (value, GPOINTER_TO_INT (modep));
3374 case PROP_NO_SHOW_ALL:
3375 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3377 case PROP_HAS_TOOLTIP:
3378 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3380 case PROP_TOOLTIP_TEXT:
3382 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3385 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3386 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3388 g_value_take_string (value, text);
3391 case PROP_TOOLTIP_MARKUP:
3392 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3395 g_value_set_object (value, gtk_widget_get_window (widget));
3397 case PROP_DOUBLE_BUFFERED:
3398 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3401 g_value_set_enum (value, gtk_widget_get_halign (widget));
3404 g_value_set_enum (value, gtk_widget_get_valign (widget));
3406 case PROP_MARGIN_LEFT:
3407 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3409 case PROP_MARGIN_RIGHT:
3410 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3412 case PROP_MARGIN_TOP:
3413 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3415 case PROP_MARGIN_BOTTOM:
3416 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3420 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3421 if (aux_info == NULL)
3423 g_value_set_int (value, 0);
3427 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3428 aux_info->margin.right),
3429 MAX (aux_info->margin.top,
3430 aux_info->margin.bottom)));
3435 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3437 case PROP_HEXPAND_SET:
3438 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3441 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3443 case PROP_VEXPAND_SET:
3444 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3447 g_value_set_boolean (value,
3448 gtk_widget_get_hexpand (widget) &&
3449 gtk_widget_get_vexpand (widget));
3452 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3458 gtk_widget_init (GtkWidget *widget)
3460 GtkWidgetPrivate *priv;
3462 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3465 priv = widget->priv;
3467 priv->child_visible = TRUE;
3468 priv->state = GTK_STATE_NORMAL;
3469 priv->saved_state = GTK_STATE_NORMAL;
3471 priv->allocation.x = -1;
3472 priv->allocation.y = -1;
3473 priv->allocation.width = 1;
3474 priv->allocation.height = 1;
3475 priv->window = NULL;
3476 priv->parent = NULL;
3478 priv->sensitive = TRUE;
3479 priv->parent_sensitive = TRUE;
3480 priv->composite_child = composite_child_stack != 0;
3481 priv->double_buffered = TRUE;
3482 priv->redraw_on_alloc = TRUE;
3483 priv->width_request_needed = TRUE;
3484 priv->height_request_needed = TRUE;
3485 priv->alloc_needed = TRUE;
3487 /* this will be set to TRUE if the widget gets a child or if the
3488 * expand flag is set on the widget, but until one of those happen
3489 * we know the expand is already properly FALSE.
3491 * We really want to default FALSE here to avoid computing expand
3492 * all over the place while initially building a widget tree.
3494 priv->need_compute_expand = FALSE;
3496 priv->style = gtk_widget_get_default_style ();
3497 g_object_ref (priv->style);
3502 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3504 GParamSpec **pspecs)
3506 GtkWidgetPrivate *priv = widget->priv;
3507 GtkWidget *container = priv->parent;
3510 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3511 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3515 * gtk_widget_freeze_child_notify:
3516 * @widget: a #GtkWidget
3518 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3519 * signals are queued until gtk_widget_thaw_child_notify() is called
3522 * This is the analogue of g_object_freeze_notify() for child properties.
3525 gtk_widget_freeze_child_notify (GtkWidget *widget)
3527 g_return_if_fail (GTK_IS_WIDGET (widget));
3529 if (!G_OBJECT (widget)->ref_count)
3532 g_object_ref (widget);
3533 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3534 g_object_unref (widget);
3538 * gtk_widget_child_notify:
3539 * @widget: a #GtkWidget
3540 * @child_property: the name of a child property installed on the
3541 * class of @widget<!-- -->'s parent
3543 * Emits a #GtkWidget::child-notify signal for the
3544 * <link linkend="child-properties">child property</link> @child_property
3547 * This is the analogue of g_object_notify() for child properties.
3550 gtk_widget_child_notify (GtkWidget *widget,
3551 const gchar *child_property)
3553 GtkWidgetPrivate *priv = widget->priv;
3556 g_return_if_fail (GTK_IS_WIDGET (widget));
3557 g_return_if_fail (child_property != NULL);
3558 if (!G_OBJECT (widget)->ref_count || !priv->parent)
3561 g_object_ref (widget);
3562 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3564 G_OBJECT_TYPE (priv->parent),
3567 g_warning ("%s: container class `%s' has no child property named `%s'",
3569 G_OBJECT_TYPE_NAME (priv->parent),
3573 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3575 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3576 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3578 g_object_unref (widget);
3582 * gtk_widget_thaw_child_notify:
3583 * @widget: a #GtkWidget
3585 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3586 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3590 gtk_widget_thaw_child_notify (GtkWidget *widget)
3592 GObjectNotifyQueue *nqueue;
3594 g_return_if_fail (GTK_IS_WIDGET (widget));
3596 if (!G_OBJECT (widget)->ref_count)
3599 g_object_ref (widget);
3600 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3601 if (!nqueue || !nqueue->freeze_count)
3602 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3603 G_OBJECT_TYPE_NAME (widget), widget);
3605 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3606 g_object_unref (widget);
3612 * @type: type ID of the widget to create
3613 * @first_property_name: name of first property to set
3614 * @Varargs: value of first property, followed by more properties,
3617 * This is a convenience function for creating a widget and setting
3618 * its properties in one go. For example you might write:
3619 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3620 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3621 * g_object_new(), but returns a widget so you don't have to
3622 * cast the object yourself.
3624 * Return value: a new #GtkWidget of type @widget_type
3627 gtk_widget_new (GType type,
3628 const gchar *first_property_name,
3634 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3636 va_start (var_args, first_property_name);
3637 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3644 gtk_widget_queue_draw_child (GtkWidget *widget)
3646 GtkWidgetPrivate *priv = widget->priv;
3649 parent = priv->parent;
3650 if (parent && gtk_widget_is_drawable (parent))
3651 gtk_widget_queue_draw_area (parent,
3654 priv->allocation.width,
3655 priv->allocation.height);
3659 * gtk_widget_unparent:
3660 * @widget: a #GtkWidget
3662 * This function is only for use in widget implementations.
3663 * Should be called by implementations of the remove method
3664 * on #GtkContainer, to dissociate a child from the container.
3667 gtk_widget_unparent (GtkWidget *widget)
3669 GtkWidgetPrivate *priv;
3670 GObjectNotifyQueue *nqueue;
3671 GtkWidget *toplevel;
3672 GtkWidget *old_parent;
3674 g_return_if_fail (GTK_IS_WIDGET (widget));
3676 priv = widget->priv;
3678 if (priv->parent == NULL)
3681 /* keep this function in sync with gtk_menu_detach()
3684 g_object_freeze_notify (G_OBJECT (widget));
3685 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3687 toplevel = gtk_widget_get_toplevel (widget);
3688 if (gtk_widget_is_toplevel (toplevel))
3689 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3691 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3692 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3694 /* If we are unanchoring the child, we save around the toplevel
3695 * to emit hierarchy changed
3697 if (priv->parent->priv->anchored)
3698 g_object_ref (toplevel);
3702 gtk_widget_queue_draw_child (widget);
3704 /* Reset the width and height here, to force reallocation if we
3705 * get added back to a new parent. This won't work if our new
3706 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3707 * (would 0x0 be OK here?)
3709 priv->allocation.width = 1;
3710 priv->allocation.height = 1;
3712 if (gtk_widget_get_realized (widget))
3714 if (priv->in_reparent)
3715 gtk_widget_unmap (widget);
3717 gtk_widget_unrealize (widget);
3720 /* Removing a widget from a container restores the child visible
3721 * flag to the default state, so it doesn't affect the child
3722 * in the next parent.
3724 priv->child_visible = TRUE;
3726 old_parent = priv->parent;
3727 priv->parent = NULL;
3728 gtk_widget_set_parent_window (widget, NULL);
3730 /* parent may no longer expand if the removed
3731 * child was expand=TRUE and could therefore
3734 if (gtk_widget_get_visible (widget) &&
3735 (priv->need_compute_expand ||
3736 priv->computed_hexpand ||
3737 priv->computed_vexpand))
3739 gtk_widget_queue_compute_expand (old_parent);
3742 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3745 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3746 g_object_unref (toplevel);
3749 g_object_notify (G_OBJECT (widget), "parent");
3750 g_object_thaw_notify (G_OBJECT (widget));
3752 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3753 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3754 g_object_unref (widget);
3758 * gtk_widget_destroy:
3759 * @widget: a #GtkWidget
3761 * Destroys a widget.
3764 * destroyed, it will break any references it holds to other objects.
3765 * If the widget is inside a container, the widget will be removed
3766 * from the container. If the widget is a toplevel (derived from
3767 * #GtkWindow), it will be removed from the list of toplevels, and the
3768 * reference GTK+ holds to it will be removed. Removing a
3769 * widget from its container or the list of toplevels results in the
3770 * widget being finalized, unless you've added additional references
3771 * to the widget with g_object_ref().
3773 * In most cases, only toplevel widgets (windows) require explicit
3774 * destruction, because when you destroy a toplevel its children will
3775 * be destroyed as well.
3778 gtk_widget_destroy (GtkWidget *widget)
3780 g_return_if_fail (GTK_IS_WIDGET (widget));
3782 if (!widget->priv->in_destruction)
3783 g_object_run_dispose (G_OBJECT (widget));
3787 * gtk_widget_destroyed:
3788 * @widget: a #GtkWidget
3789 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3791 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3792 * %NULL. It's intended to be used as a callback connected to the
3793 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3794 * as a signal handler, and pass the address of your widget variable
3795 * as user data. Then when the widget is destroyed, the variable will
3796 * be set to %NULL. Useful for example to avoid multiple copies
3797 * of the same dialog.
3800 gtk_widget_destroyed (GtkWidget *widget,
3801 GtkWidget **widget_pointer)
3803 /* Don't make any assumptions about the
3805 * Even check widget_pointer.
3808 *widget_pointer = NULL;
3813 * @widget: a #GtkWidget
3815 * Flags a widget to be displayed. Any widget that isn't shown will
3816 * not appear on the screen. If you want to show all the widgets in a
3817 * container, it's easier to call gtk_widget_show_all() on the
3818 * container, instead of individually showing the widgets.
3820 * Remember that you have to show the containers containing a widget,
3821 * in addition to the widget itself, before it will appear onscreen.
3823 * When a toplevel container is shown, it is immediately realized and
3824 * mapped; other shown widgets are realized and mapped when their
3825 * toplevel container is realized and mapped.
3828 gtk_widget_show (GtkWidget *widget)
3830 g_return_if_fail (GTK_IS_WIDGET (widget));
3832 if (!gtk_widget_get_visible (widget))
3834 g_object_ref (widget);
3835 if (!gtk_widget_is_toplevel (widget))
3836 gtk_widget_queue_resize (widget);
3838 /* see comment in set_parent() for why this should and can be
3841 if (widget->priv->need_compute_expand ||
3842 widget->priv->computed_hexpand ||
3843 widget->priv->computed_vexpand)
3845 if (widget->priv->parent != NULL)
3846 gtk_widget_queue_compute_expand (widget->priv->parent);
3849 g_signal_emit (widget, widget_signals[SHOW], 0);
3850 g_object_notify (G_OBJECT (widget), "visible");
3851 g_object_unref (widget);
3856 gtk_widget_real_show (GtkWidget *widget)
3858 GtkWidgetPrivate *priv = widget->priv;
3860 if (!gtk_widget_get_visible (widget))
3862 priv->visible = TRUE;
3865 gtk_widget_get_mapped (priv->parent) &&
3866 gtk_widget_get_child_visible (widget) &&
3867 !gtk_widget_get_mapped (widget))
3868 gtk_widget_map (widget);
3873 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3876 g_signal_handlers_disconnect_by_func (widget,
3877 gtk_widget_show_map_callback,
3882 * gtk_widget_show_now:
3883 * @widget: a #GtkWidget
3885 * Shows a widget. If the widget is an unmapped toplevel widget
3886 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3887 * loop and wait for the window to actually be mapped. Be careful;
3888 * because the main loop is running, anything can happen during
3892 gtk_widget_show_now (GtkWidget *widget)
3896 g_return_if_fail (GTK_IS_WIDGET (widget));
3898 /* make sure we will get event */
3899 if (!gtk_widget_get_mapped (widget) &&
3900 gtk_widget_is_toplevel (widget))
3902 gtk_widget_show (widget);
3904 g_signal_connect (widget, "map-event",
3905 G_CALLBACK (gtk_widget_show_map_callback),
3909 gtk_main_iteration ();
3912 gtk_widget_show (widget);
3917 * @widget: a #GtkWidget
3919 * Reverses the effects of gtk_widget_show(), causing the widget to be
3920 * hidden (invisible to the user).
3923 gtk_widget_hide (GtkWidget *widget)
3925 g_return_if_fail (GTK_IS_WIDGET (widget));
3927 if (gtk_widget_get_visible (widget))
3929 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3931 g_object_ref (widget);
3932 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3933 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3935 /* a parent may now be expand=FALSE since we're hidden. */
3936 if (widget->priv->need_compute_expand ||
3937 widget->priv->computed_hexpand ||
3938 widget->priv->computed_vexpand)
3940 gtk_widget_queue_compute_expand (widget);
3943 g_signal_emit (widget, widget_signals[HIDE], 0);
3944 if (!gtk_widget_is_toplevel (widget))
3945 gtk_widget_queue_resize (widget);
3946 g_object_notify (G_OBJECT (widget), "visible");
3947 g_object_unref (widget);
3952 gtk_widget_real_hide (GtkWidget *widget)
3954 if (gtk_widget_get_visible (widget))
3956 widget->priv->visible = FALSE;
3958 if (gtk_widget_get_mapped (widget))
3959 gtk_widget_unmap (widget);
3964 * gtk_widget_hide_on_delete:
3965 * @widget: a #GtkWidget
3967 * Utility function; intended to be connected to the #GtkWidget::delete-event
3968 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3969 * argument, then returns %TRUE. If connected to ::delete-event, the
3970 * result is that clicking the close button for a window (on the
3971 * window frame, top right corner usually) will hide but not destroy
3972 * the window. By default, GTK+ destroys windows when ::delete-event
3975 * Return value: %TRUE
3978 gtk_widget_hide_on_delete (GtkWidget *widget)
3980 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3982 gtk_widget_hide (widget);
3988 * gtk_widget_show_all:
3989 * @widget: a #GtkWidget
3991 * Recursively shows a widget, and any child widgets (if the widget is
3995 gtk_widget_show_all (GtkWidget *widget)
3997 GtkWidgetClass *class;
3999 g_return_if_fail (GTK_IS_WIDGET (widget));
4001 if (gtk_widget_get_no_show_all (widget))
4004 class = GTK_WIDGET_GET_CLASS (widget);
4006 if (class->show_all)
4007 class->show_all (widget);
4012 * @widget: a #GtkWidget
4014 * This function is only for use in widget implementations. Causes
4015 * a widget to be mapped if it isn't already.
4018 gtk_widget_map (GtkWidget *widget)
4020 GtkWidgetPrivate *priv;
4022 g_return_if_fail (GTK_IS_WIDGET (widget));
4023 g_return_if_fail (gtk_widget_get_visible (widget));
4024 g_return_if_fail (gtk_widget_get_child_visible (widget));
4026 priv = widget->priv;
4028 if (!gtk_widget_get_mapped (widget))
4030 if (!gtk_widget_get_realized (widget))
4031 gtk_widget_realize (widget);
4033 g_signal_emit (widget, widget_signals[MAP], 0);
4035 if (!gtk_widget_get_has_window (widget))
4036 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4042 * @widget: a #GtkWidget
4044 * This function is only for use in widget implementations. Causes
4045 * a widget to be unmapped if it's currently mapped.
4048 gtk_widget_unmap (GtkWidget *widget)
4050 GtkWidgetPrivate *priv;
4052 g_return_if_fail (GTK_IS_WIDGET (widget));
4054 priv = widget->priv;
4056 if (gtk_widget_get_mapped (widget))
4058 if (!gtk_widget_get_has_window (widget))
4059 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4060 _gtk_tooltip_hide (widget);
4061 g_signal_emit (widget, widget_signals[UNMAP], 0);
4066 gtk_widget_set_extension_events_internal (GtkWidget *widget,
4067 GdkExtensionMode mode,
4070 GtkWidgetPrivate *priv = widget->priv;
4071 GList *free_list = NULL;
4074 if (window_list == NULL)
4076 if (gtk_widget_get_has_window (widget))
4077 window_list = g_list_prepend (NULL, priv->window);
4079 window_list = gdk_window_get_children (priv->window);
4081 free_list = window_list;
4084 for (l = window_list; l != NULL; l = l->next)
4086 GdkWindow *window = l->data;
4089 gdk_window_get_user_data (window, &user_data);
4090 if (user_data == widget)
4094 gdk_input_set_extension_events (window,
4095 gdk_window_get_events (window),
4098 children = gdk_window_get_children (window);
4101 gtk_widget_set_extension_events_internal (widget, mode, children);
4102 g_list_free (children);
4108 g_list_free (free_list);
4112 _gtk_widget_enable_device_events (GtkWidget *widget)
4114 GHashTable *device_events;
4115 GHashTableIter iter;
4116 gpointer key, value;
4118 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4123 g_hash_table_iter_init (&iter, device_events);
4125 while (g_hash_table_iter_next (&iter, &key, &value))
4128 GdkEventMask event_mask;
4131 event_mask = GPOINTER_TO_UINT (value);
4132 gtk_widget_add_events_internal (widget, device, event_mask);
4137 * gtk_widget_realize:
4138 * @widget: a #GtkWidget
4140 * Creates the GDK (windowing system) resources associated with a
4141 * widget. For example, @widget->window will be created when a widget
4142 * is realized. Normally realization happens implicitly; if you show
4143 * a widget and all its parent containers, then the widget will be
4144 * realized and mapped automatically.
4146 * Realizing a widget requires all
4147 * the widget's parent widgets to be realized; calling
4148 * gtk_widget_realize() realizes the widget's parents in addition to
4149 * @widget itself. If a widget is not yet inside a toplevel window
4150 * when you realize it, bad things will happen.
4152 * This function is primarily used in widget implementations, and
4153 * isn't very useful otherwise. Many times when you think you might
4154 * need it, a better approach is to connect to a signal that will be
4155 * called after the widget is realized automatically, such as
4156 * #GtkWidget::expose-event. Or simply g_signal_connect () to the
4157 * #GtkWidget::realize signal.
4160 gtk_widget_realize (GtkWidget *widget)
4162 GtkWidgetPrivate *priv;
4163 GdkExtensionMode mode;
4164 cairo_region_t *region;
4166 g_return_if_fail (GTK_IS_WIDGET (widget));
4167 g_return_if_fail (widget->priv->anchored ||
4168 GTK_IS_INVISIBLE (widget));
4170 priv = widget->priv;
4172 if (!gtk_widget_get_realized (widget))
4175 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4176 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4179 if (priv->parent == NULL &&
4180 !gtk_widget_is_toplevel (widget))
4181 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4182 "inside a toplevel window is not going to work very well. "
4183 "Widgets must be inside a toplevel container before realizing them.");
4185 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4186 gtk_widget_realize (priv->parent);
4188 gtk_widget_ensure_style (widget);
4190 g_signal_emit (widget, widget_signals[REALIZE], 0);
4192 gtk_widget_real_set_has_tooltip (widget,
4193 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4196 if (priv->has_shape_mask)
4198 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4199 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4202 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4204 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4206 mode = gtk_widget_get_extension_events (widget);
4207 if (mode != GDK_EXTENSION_EVENTS_NONE)
4208 gtk_widget_set_extension_events_internal (widget, mode, NULL);
4210 if (priv->multidevice)
4211 gdk_window_set_support_multidevice (priv->window, TRUE);
4213 _gtk_widget_enable_device_events (widget);
4218 * gtk_widget_unrealize:
4219 * @widget: a #GtkWidget
4221 * This function is only useful in widget implementations.
4222 * Causes a widget to be unrealized (frees all GDK resources
4223 * associated with the widget, such as @widget->window).
4226 gtk_widget_unrealize (GtkWidget *widget)
4228 g_return_if_fail (GTK_IS_WIDGET (widget));
4230 if (widget->priv->has_shape_mask)
4231 gtk_widget_shape_combine_region (widget, NULL);
4233 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4234 gtk_widget_input_shape_combine_region (widget, NULL);
4236 if (gtk_widget_get_realized (widget))
4238 g_object_ref (widget);
4239 _gtk_tooltip_hide (widget);
4240 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4241 gtk_widget_set_realized (widget, FALSE);
4242 gtk_widget_set_mapped (widget, FALSE);
4243 g_object_unref (widget);
4247 /*****************************************
4249 *****************************************/
4252 * gtk_widget_queue_draw_region:
4253 * @widget: a #GtkWidget
4254 * @region: region to draw
4256 * Invalidates the rectangular area of @widget defined by @region by
4257 * calling gdk_window_invalidate_region() on the widget's window and
4258 * all its child windows. Once the main loop becomes idle (after the
4259 * current batch of events has been processed, roughly), the window
4260 * will receive expose events for the union of all regions that have
4263 * Normally you would only use this function in widget
4264 * implementations. You might also use it to schedule a redraw of a
4265 * #GtkDrawingArea or some portion thereof.
4268 gtk_widget_queue_draw_region (GtkWidget *widget,
4269 cairo_region_t *region)
4271 GtkWidgetPrivate *priv;
4274 g_return_if_fail (GTK_IS_WIDGET (widget));
4276 priv = widget->priv;
4278 if (!gtk_widget_get_realized (widget))
4281 /* Just return if the widget or one of its ancestors isn't mapped */
4282 for (w = widget; w != NULL; w = w->priv->parent)
4283 if (!gtk_widget_get_mapped (w))
4286 gdk_window_invalidate_region (priv->window, region, TRUE);
4290 * gtk_widget_queue_draw_area:
4291 * @widget: a #GtkWidget
4292 * @x: x coordinate of upper-left corner of rectangle to redraw
4293 * @y: y coordinate of upper-left corner of rectangle to redraw
4294 * @width: width of region to draw
4295 * @height: height of region to draw
4297 * Convenience function that calls gtk_widget_queue_draw_region() on
4298 * the region created from the given coordinates.
4301 gtk_widget_queue_draw_area (GtkWidget *widget,
4308 cairo_region_t *region;
4310 g_return_if_fail (GTK_IS_WIDGET (widget));
4315 rect.height = height;
4317 region = cairo_region_create_rectangle (&rect);
4318 gtk_widget_queue_draw_region (widget, region);
4319 cairo_region_destroy (region);
4323 * gtk_widget_queue_draw:
4324 * @widget: a #GtkWidget
4326 * Equivalent to calling gtk_widget_queue_draw_area() for the
4327 * entire area of a widget.
4330 gtk_widget_queue_draw (GtkWidget *widget)
4334 g_return_if_fail (GTK_IS_WIDGET (widget));
4336 gtk_widget_get_allocation (widget, &rect);
4338 if (!gtk_widget_get_has_window (widget))
4339 gtk_widget_queue_draw_area (widget,
4340 rect.x, rect.y, rect.width, rect.height);
4342 gtk_widget_queue_draw_area (widget,
4343 0, 0, rect.width, rect.height);
4347 * gtk_widget_queue_resize:
4348 * @widget: a #GtkWidget
4350 * This function is only for use in widget implementations.
4351 * Flags a widget to have its size renegotiated; should
4352 * be called when a widget for some reason has a new size request.
4353 * For example, when you change the text in a #GtkLabel, #GtkLabel
4354 * queues a resize to ensure there's enough space for the new text.
4356 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4357 * from inside it's implementation of the GtkWidgetClass::size_allocate
4358 * virtual method. Calls to gtk_widget_queue_resize() from inside
4359 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4362 gtk_widget_queue_resize (GtkWidget *widget)
4364 g_return_if_fail (GTK_IS_WIDGET (widget));
4366 if (gtk_widget_get_realized (widget))
4367 gtk_widget_queue_shallow_draw (widget);
4369 _gtk_size_group_queue_resize (widget, 0);
4373 * gtk_widget_queue_resize_no_redraw:
4374 * @widget: a #GtkWidget
4376 * This function works like gtk_widget_queue_resize(),
4377 * except that the widget is not invalidated.
4382 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4384 g_return_if_fail (GTK_IS_WIDGET (widget));
4386 _gtk_size_group_queue_resize (widget, 0);
4390 * gtk_widget_size_request:
4391 * @widget: a #GtkWidget
4392 * @requisition: (out): a #GtkRequisition to be filled in
4394 * This function is typically used when implementing a #GtkContainer
4395 * subclass. Obtains the preferred size of a widget. The container
4396 * uses this information to arrange its child widgets and decide what
4397 * size allocations to give them with gtk_widget_size_allocate().
4399 * You can also call this function from an application, with some
4400 * caveats. Most notably, getting a size request requires the widget
4401 * to be associated with a screen, because font information may be
4402 * needed. Multihead-aware applications should keep this in mind.
4404 * Also remember that the size request is not necessarily the size
4405 * a widget will actually be allocated.
4407 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4410 gtk_widget_size_request (GtkWidget *widget,
4411 GtkRequisition *requisition)
4413 g_return_if_fail (GTK_IS_WIDGET (widget));
4415 gtk_widget_get_preferred_size (widget, requisition, NULL);
4419 * gtk_widget_get_child_requisition:
4420 * @widget: a #GtkWidget
4421 * @requisition: (out): a #GtkRequisition to be filled in
4423 * This function is only for use in widget implementations. Obtains
4424 * @widget->requisition, unless someone has forced a particular
4425 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4426 * in which case it returns that geometry instead of the widget's
4429 * This function differs from gtk_widget_size_request() in that
4430 * it retrieves the last size request value from @widget->requisition,
4431 * while gtk_widget_size_request() actually calls the "size_request" method
4432 * on @widget to compute the size request and fill in @widget->requisition,
4433 * and only then returns @widget->requisition.
4435 * Because this function does not call the "size_request" method, it
4436 * can only be used when you know that @widget->requisition is
4437 * up-to-date, that is, gtk_widget_size_request() has been called
4438 * since the last time a resize was queued. In general, only container
4439 * implementations have this information; applications should use
4440 * gtk_widget_size_request().
4443 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4446 gtk_widget_get_child_requisition (GtkWidget *widget,
4447 GtkRequisition *requisition)
4449 gtk_widget_get_preferred_size (widget, requisition, NULL);
4453 invalidate_predicate (GdkWindow *window,
4458 gdk_window_get_user_data (window, &user_data);
4460 return (user_data == data);
4463 /* Invalidate @region in widget->window and all children
4464 * of widget->window owned by widget. @region is in the
4465 * same coordinates as widget->allocation and will be
4466 * modified by this call.
4469 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4470 cairo_region_t *region)
4472 GtkWidgetPrivate *priv = widget->priv;
4474 if (!gtk_widget_get_realized (widget))
4477 if (gtk_widget_get_has_window (widget) && priv->parent)
4481 gdk_window_get_position (priv->window, &x, &y);
4482 cairo_region_translate (region, -x, -y);
4485 gdk_window_invalidate_maybe_recurse (priv->window, region,
4486 invalidate_predicate, widget);
4490 * gtk_widget_queue_shallow_draw:
4491 * @widget: a #GtkWidget
4493 * Like gtk_widget_queue_draw(), but only windows owned
4494 * by @widget are invalidated.
4497 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4500 cairo_region_t *region;
4502 if (!gtk_widget_get_realized (widget))
4505 gtk_widget_get_allocation (widget, &rect);
4507 region = cairo_region_create_rectangle (&rect);
4508 gtk_widget_invalidate_widget_windows (widget, region);
4509 cairo_region_destroy (region);
4513 * gtk_widget_size_allocate:
4514 * @widget: a #GtkWidget
4515 * @allocation: (inout): position and size to be allocated to @widget
4517 * This function is only used by #GtkContainer subclasses, to assign a size
4518 * and position to their child widgets.
4520 * In this function, the allocation may be adjusted. It will be forced
4521 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4522 * method on the child will be used to adjust the allocation. Standard
4523 * adjustments include removing the widget's margins, and applying the
4524 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4527 gtk_widget_size_allocate (GtkWidget *widget,
4528 GtkAllocation *allocation)
4530 GtkWidgetPrivate *priv;
4531 GdkRectangle real_allocation;
4532 GdkRectangle old_allocation;
4533 GdkRectangle adjusted_allocation;
4534 gboolean alloc_needed;
4535 gboolean size_changed;
4536 gboolean position_changed;
4537 gint natural_width, natural_height;
4538 gint min_width, min_height;
4540 priv = widget->priv;
4542 g_return_if_fail (GTK_IS_WIDGET (widget));
4544 #ifdef G_ENABLE_DEBUG
4545 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4556 parent = gtk_widget_get_parent (parent);
4559 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4560 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4561 2 * depth, " ", name,
4562 allocation->width, allocation->height);
4564 #endif /* G_ENABLE_DEBUG */
4566 alloc_needed = priv->alloc_needed;
4567 if (!priv->width_request_needed && !priv->height_request_needed)
4568 /* Preserve request/allocate ordering */
4569 priv->alloc_needed = FALSE;
4571 old_allocation = priv->allocation;
4572 real_allocation = *allocation;
4574 adjusted_allocation = real_allocation;
4575 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4577 /* Go ahead and request the height for allocated width, note that the internals
4578 * of get_height_for_width will internally limit the for_size to natural size
4579 * when aligning implicitly.
4581 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4582 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, NULL, &natural_height);
4586 /* Go ahead and request the width for allocated height, note that the internals
4587 * of get_width_for_height will internally limit the for_size to natural size
4588 * when aligning implicitly.
4590 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4591 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, NULL, &natural_width);
4594 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4595 * allocated sizes and possibly limit them to the natural sizes */
4596 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4597 GTK_ORIENTATION_HORIZONTAL,
4599 &adjusted_allocation.x,
4600 &adjusted_allocation.width);
4601 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4602 GTK_ORIENTATION_VERTICAL,
4604 &adjusted_allocation.y,
4605 &adjusted_allocation.height);
4607 if (adjusted_allocation.x < real_allocation.x ||
4608 adjusted_allocation.y < real_allocation.y ||
4609 (adjusted_allocation.x + adjusted_allocation.width) >
4610 (real_allocation.x + real_allocation.width) ||
4611 (adjusted_allocation.y + adjusted_allocation.height >
4612 real_allocation.y + real_allocation.height))
4614 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",
4615 G_OBJECT_TYPE_NAME (widget), widget,
4616 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4617 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4618 adjusted_allocation = real_allocation; /* veto it */
4622 real_allocation = adjusted_allocation;
4625 if (real_allocation.width < 0 || real_allocation.height < 0)
4627 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4628 real_allocation.width,
4629 real_allocation.height);
4632 real_allocation.width = MAX (real_allocation.width, 1);
4633 real_allocation.height = MAX (real_allocation.height, 1);
4635 size_changed = (old_allocation.width != real_allocation.width ||
4636 old_allocation.height != real_allocation.height);
4637 position_changed = (old_allocation.x != real_allocation.x ||
4638 old_allocation.y != real_allocation.y);
4640 if (!alloc_needed && !size_changed && !position_changed)
4643 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4645 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4646 priv->width_request_needed = FALSE;
4647 priv->height_request_needed = FALSE;
4648 priv->alloc_needed = FALSE;
4650 if (gtk_widget_get_mapped (widget))
4652 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4654 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4656 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4657 cairo_region_union_rectangle (invalidate, &old_allocation);
4659 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4660 cairo_region_destroy (invalidate);
4665 if (priv->redraw_on_alloc)
4667 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4669 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4670 cairo_region_union_rectangle (invalidate, &old_allocation);
4672 gtk_widget_invalidate_widget_windows (widget, invalidate);
4673 cairo_region_destroy (invalidate);
4677 if (size_changed || position_changed)
4679 GtkStyleContext *context;
4681 context = gtk_widget_get_style_context (widget);
4682 _gtk_style_context_invalidate_animation_areas (context);
4686 if ((size_changed || position_changed) && priv->parent &&
4687 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4689 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4690 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4691 cairo_region_destroy (invalidate);
4696 * gtk_widget_common_ancestor:
4697 * @widget_a: a #GtkWidget
4698 * @widget_b: a #GtkWidget
4700 * Find the common ancestor of @widget_a and @widget_b that
4701 * is closest to the two widgets.
4703 * Return value: the closest common ancestor of @widget_a and
4704 * @widget_b or %NULL if @widget_a and @widget_b do not
4705 * share a common ancestor.
4708 gtk_widget_common_ancestor (GtkWidget *widget_a,
4709 GtkWidget *widget_b)
4711 GtkWidget *parent_a;
4712 GtkWidget *parent_b;
4716 parent_a = widget_a;
4717 while (parent_a->priv->parent)
4719 parent_a = parent_a->priv->parent;
4723 parent_b = widget_b;
4724 while (parent_b->priv->parent)
4726 parent_b = parent_b->priv->parent;
4730 if (parent_a != parent_b)
4733 while (depth_a > depth_b)
4735 widget_a = widget_a->priv->parent;
4739 while (depth_b > depth_a)
4741 widget_b = widget_b->priv->parent;
4745 while (widget_a != widget_b)
4747 widget_a = widget_a->priv->parent;
4748 widget_b = widget_b->priv->parent;
4755 * gtk_widget_translate_coordinates:
4756 * @src_widget: a #GtkWidget
4757 * @dest_widget: a #GtkWidget
4758 * @src_x: X position relative to @src_widget
4759 * @src_y: Y position relative to @src_widget
4760 * @dest_x: (out): location to store X position relative to @dest_widget
4761 * @dest_y: (out): location to store Y position relative to @dest_widget
4763 * Translate coordinates relative to @src_widget's allocation to coordinates
4764 * relative to @dest_widget's allocations. In order to perform this
4765 * operation, both widgets must be realized, and must share a common
4768 * Return value: %FALSE if either widget was not realized, or there
4769 * was no common ancestor. In this case, nothing is stored in
4770 * *@dest_x and *@dest_y. Otherwise %TRUE.
4773 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4774 GtkWidget *dest_widget,
4780 GtkWidgetPrivate *src_priv = src_widget->priv;
4781 GtkWidgetPrivate *dest_priv = dest_widget->priv;
4782 GtkWidget *ancestor;
4784 GList *dest_list = NULL;
4786 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4787 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4789 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4790 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4793 /* Translate from allocation relative to window relative */
4794 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
4797 gdk_window_get_position (src_priv->window, &wx, &wy);
4799 src_x -= wx - src_priv->allocation.x;
4800 src_y -= wy - src_priv->allocation.y;
4804 src_x += src_priv->allocation.x;
4805 src_y += src_priv->allocation.y;
4808 /* Translate to the common ancestor */
4809 window = src_priv->window;
4810 while (window != ancestor->priv->window)
4814 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4819 window = gdk_window_get_effective_parent (window);
4821 if (!window) /* Handle GtkHandleBox */
4826 window = dest_priv->window;
4827 while (window != ancestor->priv->window)
4829 dest_list = g_list_prepend (dest_list, window);
4831 window = gdk_window_get_effective_parent (window);
4833 if (!window) /* Handle GtkHandleBox */
4835 g_list_free (dest_list);
4844 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4849 dest_list = g_list_remove (dest_list, dest_list->data);
4852 /* Translate from window relative to allocation relative */
4853 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
4856 gdk_window_get_position (dest_priv->window, &wx, &wy);
4858 src_x += wx - dest_priv->allocation.x;
4859 src_y += wy - dest_priv->allocation.y;
4863 src_x -= dest_priv->allocation.x;
4864 src_y -= dest_priv->allocation.y;
4876 gtk_widget_real_size_allocate (GtkWidget *widget,
4877 GtkAllocation *allocation)
4879 GtkWidgetPrivate *priv = widget->priv;
4881 priv->allocation = *allocation;
4883 if (gtk_widget_get_realized (widget) &&
4884 gtk_widget_get_has_window (widget))
4886 gdk_window_move_resize (priv->window,
4887 allocation->x, allocation->y,
4888 allocation->width, allocation->height);
4893 adjust_for_align(GtkAlign align,
4895 gint *allocated_pos,
4896 gint *allocated_size)
4900 case GTK_ALIGN_FILL:
4901 /* change nothing */
4903 case GTK_ALIGN_START:
4904 /* keep *allocated_pos where it is */
4905 *allocated_size = MIN (*allocated_size, *natural_size);
4908 if (*allocated_size > *natural_size)
4910 *allocated_pos += (*allocated_size - *natural_size);
4911 *allocated_size = *natural_size;
4914 case GTK_ALIGN_CENTER:
4915 if (*allocated_size > *natural_size)
4917 *allocated_pos += (*allocated_size - *natural_size) / 2;
4918 *allocated_size = MIN (*allocated_size, *natural_size);
4925 adjust_for_margin(gint start_margin,
4928 gint *allocated_pos,
4929 gint *allocated_size)
4931 *natural_size -= (start_margin + end_margin);
4932 *allocated_pos += start_margin;
4933 *allocated_size -= (start_margin + end_margin);
4937 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
4938 GtkOrientation orientation,
4940 gint *allocated_pos,
4941 gint *allocated_size)
4943 const GtkWidgetAuxInfo *aux_info;
4945 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
4947 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4949 adjust_for_margin (aux_info->margin.left,
4950 aux_info->margin.right,
4951 natural_size, allocated_pos, allocated_size);
4952 adjust_for_align (aux_info->halign,
4953 natural_size, allocated_pos, allocated_size);
4957 adjust_for_margin (aux_info->margin.top,
4958 aux_info->margin.bottom,
4959 natural_size, allocated_pos, allocated_size);
4960 adjust_for_align (aux_info->valign,
4961 natural_size, allocated_pos, allocated_size);
4966 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4969 GtkWidgetPrivate *priv = widget->priv;
4971 /* widgets must be onscreen for accels to take effect */
4972 return gtk_widget_is_sensitive (widget) &&
4973 gtk_widget_is_drawable (widget) &&
4974 gdk_window_is_viewable (priv->window);
4978 * gtk_widget_can_activate_accel:
4979 * @widget: a #GtkWidget
4980 * @signal_id: the ID of a signal installed on @widget
4982 * Determines whether an accelerator that activates the signal
4983 * identified by @signal_id can currently be activated.
4984 * This is done by emitting the #GtkWidget::can-activate-accel
4985 * signal on @widget; if the signal isn't overridden by a
4986 * handler or in a derived widget, then the default check is
4987 * that the widget must be sensitive, and the widget and all
4988 * its ancestors mapped.
4990 * Return value: %TRUE if the accelerator can be activated.
4995 gtk_widget_can_activate_accel (GtkWidget *widget,
4998 gboolean can_activate = FALSE;
4999 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5000 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5001 return can_activate;
5010 closure_accel_activate (GClosure *closure,
5011 GValue *return_value,
5012 guint n_param_values,
5013 const GValue *param_values,
5014 gpointer invocation_hint,
5015 gpointer marshal_data)
5017 AccelClosure *aclosure = (AccelClosure*) closure;
5018 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5021 g_signal_emit (closure->data, aclosure->signal_id, 0);
5023 /* whether accelerator was handled */
5024 g_value_set_boolean (return_value, can_activate);
5028 closures_destroy (gpointer data)
5030 GSList *slist, *closures = data;
5032 for (slist = closures; slist; slist = slist->next)
5034 g_closure_invalidate (slist->data);
5035 g_closure_unref (slist->data);
5037 g_slist_free (closures);
5041 widget_new_accel_closure (GtkWidget *widget,
5044 AccelClosure *aclosure;
5045 GClosure *closure = NULL;
5046 GSList *slist, *closures;
5048 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5049 for (slist = closures; slist; slist = slist->next)
5050 if (!gtk_accel_group_from_accel_closure (slist->data))
5052 /* reuse this closure */
5053 closure = slist->data;
5058 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5059 closures = g_slist_prepend (closures, g_closure_ref (closure));
5060 g_closure_sink (closure);
5061 g_closure_set_marshal (closure, closure_accel_activate);
5063 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5065 aclosure = (AccelClosure*) closure;
5066 g_assert (closure->data == widget);
5067 g_assert (closure->marshal == closure_accel_activate);
5068 aclosure->signal_id = signal_id;
5074 * gtk_widget_add_accelerator
5075 * @widget: widget to install an accelerator on
5076 * @accel_signal: widget signal to emit on accelerator activation
5077 * @accel_group: accel group for this widget, added to its toplevel
5078 * @accel_key: GDK keyval of the accelerator
5079 * @accel_mods: modifier key combination of the accelerator
5080 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5082 * Installs an accelerator for this @widget in @accel_group that causes
5083 * @accel_signal to be emitted if the accelerator is activated.
5084 * The @accel_group needs to be added to the widget's toplevel via
5085 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5086 * Accelerators added through this function are not user changeable during
5087 * runtime. If you want to support accelerators that can be changed by the
5088 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5089 * gtk_menu_item_set_accel_path() instead.
5092 gtk_widget_add_accelerator (GtkWidget *widget,
5093 const gchar *accel_signal,
5094 GtkAccelGroup *accel_group,
5096 GdkModifierType accel_mods,
5097 GtkAccelFlags accel_flags)
5102 g_return_if_fail (GTK_IS_WIDGET (widget));
5103 g_return_if_fail (accel_signal != NULL);
5104 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5106 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5107 if (!query.signal_id ||
5108 !(query.signal_flags & G_SIGNAL_ACTION) ||
5109 query.return_type != G_TYPE_NONE ||
5112 /* hmm, should be elaborate enough */
5113 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5114 G_OBJECT_TYPE_NAME (widget), accel_signal);
5118 closure = widget_new_accel_closure (widget, query.signal_id);
5120 g_object_ref (widget);
5122 /* install the accelerator. since we don't map this onto an accel_path,
5123 * the accelerator will automatically be locked.
5125 gtk_accel_group_connect (accel_group,
5128 accel_flags | GTK_ACCEL_LOCKED,
5131 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5133 g_object_unref (widget);
5137 * gtk_widget_remove_accelerator:
5138 * @widget: widget to install an accelerator on
5139 * @accel_group: accel group for this widget
5140 * @accel_key: GDK keyval of the accelerator
5141 * @accel_mods: modifier key combination of the accelerator
5142 * @returns: whether an accelerator was installed and could be removed
5144 * Removes an accelerator from @widget, previously installed with
5145 * gtk_widget_add_accelerator().
5148 gtk_widget_remove_accelerator (GtkWidget *widget,
5149 GtkAccelGroup *accel_group,
5151 GdkModifierType accel_mods)
5153 GtkAccelGroupEntry *ag_entry;
5154 GList *slist, *clist;
5157 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5158 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5160 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5161 clist = gtk_widget_list_accel_closures (widget);
5162 for (slist = clist; slist; slist = slist->next)
5166 for (i = 0; i < n; i++)
5167 if (slist->data == (gpointer) ag_entry[i].closure)
5169 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5171 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5173 g_list_free (clist);
5178 g_list_free (clist);
5180 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5181 accel_key, accel_mods, accel_group,
5182 G_OBJECT_TYPE_NAME (widget), widget);
5188 * gtk_widget_list_accel_closures:
5189 * @widget: widget to list accelerator closures for
5191 * Lists the closures used by @widget for accelerator group connections
5192 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5193 * The closures can be used to monitor accelerator changes on @widget,
5194 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5195 * #GtkAccelGroup of a closure which can be found out with
5196 * gtk_accel_group_from_accel_closure().
5198 * Return value: (transfer container) (element-type GClosure):
5199 * a newly allocated #GList of closures
5202 gtk_widget_list_accel_closures (GtkWidget *widget)
5205 GList *clist = NULL;
5207 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5209 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5210 if (gtk_accel_group_from_accel_closure (slist->data))
5211 clist = g_list_prepend (clist, slist->data);
5217 GtkAccelGroup *accel_group;
5222 destroy_accel_path (gpointer data)
5224 AccelPath *apath = data;
5226 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5228 /* closures_destroy takes care of unrefing the closure */
5229 g_object_unref (apath->accel_group);
5231 g_slice_free (AccelPath, apath);
5236 * gtk_widget_set_accel_path:
5237 * @widget: a #GtkWidget
5238 * @accel_path: (allow-none): path used to look up the accelerator
5239 * @accel_group: (allow-none): a #GtkAccelGroup.
5241 * Given an accelerator group, @accel_group, and an accelerator path,
5242 * @accel_path, sets up an accelerator in @accel_group so whenever the
5243 * key binding that is defined for @accel_path is pressed, @widget
5244 * will be activated. This removes any accelerators (for any
5245 * accelerator group) installed by previous calls to
5246 * gtk_widget_set_accel_path(). Associating accelerators with
5247 * paths allows them to be modified by the user and the modifications
5248 * to be saved for future use. (See gtk_accel_map_save().)
5250 * This function is a low level function that would most likely
5251 * be used by a menu creation system like #GtkUIManager. If you
5252 * use #GtkUIManager, setting up accelerator paths will be done
5255 * Even when you you aren't using #GtkUIManager, if you only want to
5256 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5257 * provides a somewhat more convenient interface.
5259 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5260 * pass a static string, you can save some memory by interning it first with
5261 * g_intern_static_string().
5264 gtk_widget_set_accel_path (GtkWidget *widget,
5265 const gchar *accel_path,
5266 GtkAccelGroup *accel_group)
5270 g_return_if_fail (GTK_IS_WIDGET (widget));
5271 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5275 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5276 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5278 gtk_accel_map_add_entry (accel_path, 0, 0);
5279 apath = g_slice_new (AccelPath);
5280 apath->accel_group = g_object_ref (accel_group);
5281 apath->path_quark = g_quark_from_string (accel_path);
5282 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5287 /* also removes possible old settings */
5288 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5291 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5293 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5297 _gtk_widget_get_accel_path (GtkWidget *widget,
5302 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5304 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5306 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5307 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5311 * gtk_widget_mnemonic_activate:
5312 * @widget: a #GtkWidget
5313 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5315 * Emits the #GtkWidget::mnemonic-activate signal.
5317 * The default handler for this signal activates the @widget if
5318 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5321 * Returns: %TRUE if the signal has been handled
5324 gtk_widget_mnemonic_activate (GtkWidget *widget,
5325 gboolean group_cycling)
5329 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5331 group_cycling = group_cycling != FALSE;
5332 if (!gtk_widget_is_sensitive (widget))
5335 g_signal_emit (widget,
5336 widget_signals[MNEMONIC_ACTIVATE],
5344 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5345 gboolean group_cycling)
5347 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5348 gtk_widget_activate (widget);
5349 else if (gtk_widget_get_can_focus (widget))
5350 gtk_widget_grab_focus (widget);
5353 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5354 G_OBJECT_TYPE_NAME (widget));
5355 gtk_widget_error_bell (widget);
5360 static const cairo_user_data_key_t event_key;
5363 _gtk_cairo_get_event (cairo_t *cr)
5365 g_return_val_if_fail (cr != NULL, NULL);
5367 return cairo_get_user_data (cr, &event_key);
5371 gtk_cairo_set_event (cairo_t *cr,
5372 GdkEventExpose *event)
5374 cairo_set_user_data (cr, &event_key, event, NULL);
5378 * gtk_cairo_should_draw_window:
5379 * @cr: a cairo context
5380 * @window: the window to check
5382 * This function is supposed to be called in #GtkWidget::draw
5383 * implementations for widgets that support multiple windows.
5384 * @cr must be untransformed from invoking of the draw function.
5385 * This function will return %TRUE if the contents of the given
5386 * @window are supposed to be drawn and %FALSE otherwise. Note
5387 * that when the drawing was not initiated by the windowing
5388 * system this function will return %TRUE for all windows, so
5389 * you need to draw the bottommost window first. Also, do not
5390 * use "else if" statements to check which window should be drawn.
5392 * Returns: %TRUE if @window should be drawn
5395 gtk_cairo_should_draw_window (cairo_t *cr,
5398 GdkEventExpose *event;
5400 g_return_val_if_fail (cr != NULL, FALSE);
5401 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5403 event = _gtk_cairo_get_event (cr);
5405 return event == NULL ||
5406 event->window == window;
5409 /* code shared by gtk_container_propagate_draw() and
5413 _gtk_widget_draw_internal (GtkWidget *widget,
5415 gboolean clip_to_size)
5417 GtkStyleContext *context;
5419 if (!gtk_widget_is_drawable (widget))
5424 cairo_rectangle (cr,
5426 widget->priv->allocation.width,
5427 widget->priv->allocation.height);
5431 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5435 g_signal_emit (widget, widget_signals[DRAW],
5440 context = gtk_widget_get_style_context (widget);
5441 _gtk_style_context_coalesce_animation_areas (context,
5442 widget->priv->allocation.x,
5443 widget->priv->allocation.y);
5448 * @widget: the widget to draw. It must be drawable (see
5449 * gtk_widget_is_drawable()) and a size must have been allocated.
5450 * @cr: a cairo context to draw to
5452 * Draws @widget to @cr. The top left corner of the widget will be
5453 * drawn to the currently set origin point of @cr.
5455 * You should pass a cairo context as @cr argument that is in an
5456 * original state. Otherwise the resulting drawing is undefined. For
5457 * example changing the operator using cairo_set_operator() or the
5458 * line width using cairo_set_line_width() might have unwanted side
5460 * You may however change the context's transform matrix - like with
5461 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5462 * region with cairo_clip() prior to calling this function. Also, it
5463 * is fine to modify the context with cairo_save() and
5464 * cairo_push_group() prior to calling this function.
5466 * <note><para>Special purpose widgets may contain special code for
5467 * rendering to the screen and might appear differently on screen
5468 * and when rendered using gtk_widget_draw().</para></note>
5471 gtk_widget_draw (GtkWidget *widget,
5474 GdkEventExpose *tmp_event;
5476 g_return_if_fail (GTK_IS_WIDGET (widget));
5477 g_return_if_fail (!widget->priv->alloc_needed);
5478 g_return_if_fail (cr != NULL);
5481 /* We have to reset the event here so that draw functions can call
5482 * gtk_widget_draw() on random other widgets and get the desired
5483 * effect: Drawing all contents, not just the current window.
5485 tmp_event = _gtk_cairo_get_event (cr);
5486 gtk_cairo_set_event (cr, NULL);
5488 _gtk_widget_draw_internal (widget, cr, TRUE);
5490 gtk_cairo_set_event (cr, tmp_event);
5495 gtk_widget_real_key_press_event (GtkWidget *widget,
5498 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5502 gtk_widget_real_key_release_event (GtkWidget *widget,
5505 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5509 gtk_widget_real_focus_in_event (GtkWidget *widget,
5510 GdkEventFocus *event)
5512 gtk_widget_queue_shallow_draw (widget);
5518 gtk_widget_real_focus_out_event (GtkWidget *widget,
5519 GdkEventFocus *event)
5521 gtk_widget_queue_shallow_draw (widget);
5526 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5527 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5531 * @widget: a #GtkWidget
5532 * @event: a #GdkEvent
5534 * Rarely-used function. This function is used to emit
5535 * the event signals on a widget (those signals should never
5536 * be emitted without using this function to do so).
5537 * If you want to synthesize an event though, don't use this function;
5538 * instead, use gtk_main_do_event() so the event will behave as if
5539 * it were in the event queue. Don't synthesize expose events; instead,
5540 * use gdk_window_invalidate_rect() to invalidate a region of the
5543 * Return value: return from the event signal emission (%TRUE if
5544 * the event was handled)
5547 gtk_widget_event (GtkWidget *widget,
5550 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5551 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5553 if (event->type == GDK_EXPOSE)
5555 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5556 "the same effect, call gdk_window_invalidate_rect/region(), "
5557 "followed by gdk_window_process_updates().");
5561 return gtk_widget_event_internal (widget, event);
5564 /* Returns TRUE if a translation should be done */
5566 gtk_widget_get_translation_to_window (GtkWidget *widget,
5571 GdkWindow *w, *widget_window;
5573 if (!gtk_widget_get_has_window (widget))
5575 *x = -widget->priv->allocation.x;
5576 *y = -widget->priv->allocation.y;
5584 widget_window = gtk_widget_get_window (widget);
5586 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5589 gdk_window_get_position (w, &wx, &wy);
5606 * gtk_cairo_transform_to_window:
5607 * @cr: the cairo context to transform
5608 * @widget: the widget the context is currently centered for
5609 * @window: the window to transform the context to
5611 * Transforms the given cairo context @cr that from @widget-relative
5612 * coordinates to @window-relative coordinates.
5613 * If the @widget's window is not an ancestor of @window, no
5614 * modification will be applied.
5616 * This is the inverse to the transformation GTK applies when
5617 * preparing an expose event to be emitted with the #GtkWidget::draw
5618 * signal. It is intended to help porting multiwindow widgets from
5619 * GTK+ 2 to the rendering architecture of GTK+ 3.
5622 gtk_cairo_transform_to_window (cairo_t *cr,
5628 g_return_if_fail (cr != NULL);
5629 g_return_if_fail (GTK_IS_WIDGET (widget));
5630 g_return_if_fail (GDK_IS_WINDOW (window));
5632 if (gtk_widget_get_translation_to_window (widget, window, &x, &y))
5633 cairo_translate (cr, x, y);
5637 * gtk_widget_send_expose:
5638 * @widget: a #GtkWidget
5639 * @event: a expose #GdkEvent
5641 * Very rarely-used function. This function is used to emit
5642 * an expose event on a widget. This function is not normally used
5643 * directly. The only time it is used is when propagating an expose
5644 * event to a child %NO_WINDOW widget, and that is normally done
5645 * using gtk_container_propagate_draw().
5647 * If you want to force an area of a window to be redrawn,
5648 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5649 * To cause the redraw to be done immediately, follow that call
5650 * with a call to gdk_window_process_updates().
5652 * Return value: return from the event signal emission (%TRUE if
5653 * the event was handled)
5656 gtk_widget_send_expose (GtkWidget *widget,
5659 gboolean result = FALSE;
5664 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5665 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5666 g_return_val_if_fail (event != NULL, TRUE);
5667 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5669 cr = gdk_cairo_create (event->expose.window);
5670 gtk_cairo_set_event (cr, &event->expose);
5672 gdk_cairo_region (cr, event->expose.region);
5675 do_clip = gtk_widget_get_translation_to_window (widget,
5676 event->expose.window,
5678 cairo_translate (cr, -x, -y);
5680 _gtk_widget_draw_internal (widget, cr, do_clip);
5682 /* unset here, so if someone keeps a reference to cr we
5683 * don't leak the window. */
5684 gtk_cairo_set_event (cr, NULL);
5691 event_window_is_still_viewable (GdkEvent *event)
5693 /* Check that we think the event's window is viewable before
5694 * delivering the event, to prevent suprises. We do this here
5695 * at the last moment, since the event may have been queued
5696 * up behind other events, held over a recursive main loop, etc.
5698 switch (event->type)
5701 case GDK_MOTION_NOTIFY:
5702 case GDK_BUTTON_PRESS:
5703 case GDK_2BUTTON_PRESS:
5704 case GDK_3BUTTON_PRESS:
5706 case GDK_ENTER_NOTIFY:
5707 case GDK_PROXIMITY_IN:
5709 return event->any.window && gdk_window_is_viewable (event->any.window);
5712 /* The following events are the second half of paired events;
5713 * we always deliver them to deal with widgets that clean up
5714 * on the second half.
5716 case GDK_BUTTON_RELEASE:
5717 case GDK_KEY_RELEASE:
5718 case GDK_LEAVE_NOTIFY:
5719 case GDK_PROXIMITY_OUT:
5723 /* Remaining events would make sense on an not-viewable window,
5724 * or don't have an associated window.
5731 gtk_widget_event_internal (GtkWidget *widget,
5734 gboolean return_val = FALSE;
5736 /* We check only once for is-still-visible; if someone
5737 * hides the window in on of the signals on the widget,
5738 * they are responsible for returning TRUE to terminate
5741 if (!event_window_is_still_viewable (event))
5744 g_object_ref (widget);
5746 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5747 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5752 switch (event->type)
5757 case GDK_BUTTON_PRESS:
5758 case GDK_2BUTTON_PRESS:
5759 case GDK_3BUTTON_PRESS:
5760 signal_num = BUTTON_PRESS_EVENT;
5763 signal_num = SCROLL_EVENT;
5765 case GDK_BUTTON_RELEASE:
5766 signal_num = BUTTON_RELEASE_EVENT;
5768 case GDK_MOTION_NOTIFY:
5769 signal_num = MOTION_NOTIFY_EVENT;
5772 signal_num = DELETE_EVENT;
5775 signal_num = DESTROY_EVENT;
5776 _gtk_tooltip_hide (widget);
5779 signal_num = KEY_PRESS_EVENT;
5781 case GDK_KEY_RELEASE:
5782 signal_num = KEY_RELEASE_EVENT;
5784 case GDK_ENTER_NOTIFY:
5785 signal_num = ENTER_NOTIFY_EVENT;
5787 case GDK_LEAVE_NOTIFY:
5788 signal_num = LEAVE_NOTIFY_EVENT;
5790 case GDK_FOCUS_CHANGE:
5791 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
5792 if (event->focus_change.in)
5793 _gtk_tooltip_focus_in (widget);
5795 _gtk_tooltip_focus_out (widget);
5798 signal_num = CONFIGURE_EVENT;
5801 signal_num = MAP_EVENT;
5804 signal_num = UNMAP_EVENT;
5806 case GDK_WINDOW_STATE:
5807 signal_num = WINDOW_STATE_EVENT;
5809 case GDK_PROPERTY_NOTIFY:
5810 signal_num = PROPERTY_NOTIFY_EVENT;
5812 case GDK_SELECTION_CLEAR:
5813 signal_num = SELECTION_CLEAR_EVENT;
5815 case GDK_SELECTION_REQUEST:
5816 signal_num = SELECTION_REQUEST_EVENT;
5818 case GDK_SELECTION_NOTIFY:
5819 signal_num = SELECTION_NOTIFY_EVENT;
5821 case GDK_PROXIMITY_IN:
5822 signal_num = PROXIMITY_IN_EVENT;
5824 case GDK_PROXIMITY_OUT:
5825 signal_num = PROXIMITY_OUT_EVENT;
5827 case GDK_CLIENT_EVENT:
5828 signal_num = CLIENT_EVENT;
5831 signal_num = EXPOSE_EVENT;
5833 case GDK_VISIBILITY_NOTIFY:
5834 signal_num = VISIBILITY_NOTIFY_EVENT;
5836 case GDK_GRAB_BROKEN:
5837 signal_num = GRAB_BROKEN_EVENT;
5840 signal_num = DAMAGE_EVENT;
5843 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
5847 if (signal_num != -1)
5848 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
5850 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
5851 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
5855 g_object_unref (widget);
5861 * gtk_widget_activate:
5862 * @widget: a #GtkWidget that's activatable
5864 * For widgets that can be "activated" (buttons, menu items, etc.)
5865 * this function activates them. Activation is what happens when you
5866 * press Enter on a widget during key navigation. If @widget isn't
5867 * activatable, the function returns %FALSE.
5869 * Return value: %TRUE if the widget was activatable
5872 gtk_widget_activate (GtkWidget *widget)
5874 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5876 if (WIDGET_CLASS (widget)->activate_signal)
5878 /* FIXME: we should eventually check the signals signature here */
5879 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5888 gtk_widget_reparent_subwindows (GtkWidget *widget,
5889 GdkWindow *new_window)
5891 GtkWidgetPrivate *priv = widget->priv;
5893 if (!gtk_widget_get_has_window (widget))
5895 GList *children = gdk_window_get_children (priv->window);
5898 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5900 GdkWindow *window = tmp_list->data;
5903 gdk_window_get_user_data (window, &child);
5904 while (child && child != widget)
5905 child = ((GtkWidget*) child)->priv->parent;
5908 gdk_window_reparent (window, new_window, 0, 0);
5911 g_list_free (children);
5916 GList *tmp_list, *children;
5918 parent = gdk_window_get_parent (priv->window);
5921 gdk_window_reparent (priv->window, new_window, 0, 0);
5924 children = gdk_window_get_children (parent);
5926 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5928 GdkWindow *window = tmp_list->data;
5931 gdk_window_get_user_data (window, &child);
5933 if (child == widget)
5934 gdk_window_reparent (window, new_window, 0, 0);
5937 g_list_free (children);
5943 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5944 gpointer client_data)
5946 GtkWidgetPrivate *priv = widget->priv;
5948 g_assert (client_data != NULL);
5950 if (!gtk_widget_get_has_window (widget))
5953 g_object_unref (priv->window);
5954 priv->window = (GdkWindow*) client_data;
5956 g_object_ref (priv->window);
5958 if (GTK_IS_CONTAINER (widget))
5959 gtk_container_forall (GTK_CONTAINER (widget),
5960 gtk_widget_reparent_fixup_child,
5966 * gtk_widget_reparent:
5967 * @widget: a #GtkWidget
5968 * @new_parent: a #GtkContainer to move the widget into
5970 * Moves a widget from one #GtkContainer to another, handling reference
5971 * count issues to avoid destroying the widget.
5974 gtk_widget_reparent (GtkWidget *widget,
5975 GtkWidget *new_parent)
5977 GtkWidgetPrivate *priv;
5979 g_return_if_fail (GTK_IS_WIDGET (widget));
5980 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
5981 priv = widget->priv;
5982 g_return_if_fail (priv->parent != NULL);
5984 if (priv->parent != new_parent)
5986 /* First try to see if we can get away without unrealizing
5987 * the widget as we reparent it. if so we set a flag so
5988 * that gtk_widget_unparent doesn't unrealize widget
5990 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
5991 priv->in_reparent = TRUE;
5993 g_object_ref (widget);
5994 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
5995 gtk_container_add (GTK_CONTAINER (new_parent), widget);
5996 g_object_unref (widget);
5998 if (priv->in_reparent)
6000 priv->in_reparent = FALSE;
6002 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6003 gtk_widget_reparent_fixup_child (widget,
6004 gtk_widget_get_parent_window (widget));
6007 g_object_notify (G_OBJECT (widget), "parent");
6012 * gtk_widget_intersect:
6013 * @widget: a #GtkWidget
6014 * @area: a rectangle
6015 * @intersection: rectangle to store intersection of @widget and @area
6017 * Computes the intersection of a @widget's area and @area, storing
6018 * the intersection in @intersection, and returns %TRUE if there was
6019 * an intersection. @intersection may be %NULL if you're only
6020 * interested in whether there was an intersection.
6022 * Return value: %TRUE if there was an intersection
6025 gtk_widget_intersect (GtkWidget *widget,
6026 const GdkRectangle *area,
6027 GdkRectangle *intersection)
6029 GtkWidgetPrivate *priv;
6034 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6035 g_return_val_if_fail (area != NULL, FALSE);
6037 priv = widget->priv;
6040 dest = intersection;
6044 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6046 if (return_val && intersection && gtk_widget_get_has_window (widget))
6048 intersection->x -= priv->allocation.x;
6049 intersection->y -= priv->allocation.y;
6056 * gtk_widget_region_intersect:
6057 * @widget: a #GtkWidget
6058 * @region: a #cairo_region_t, in the same coordinate system as
6059 * @widget->allocation. That is, relative to @widget->window
6060 * for %NO_WINDOW widgets; relative to the parent window
6061 * of @widget->window for widgets with their own window.
6062 * @returns: A newly allocated region holding the intersection of @widget
6063 * and @region. The coordinates of the return value are
6064 * relative to @widget->window for %NO_WINDOW widgets, and
6065 * relative to the parent window of @widget->window for
6066 * widgets with their own window.
6068 * Computes the intersection of a @widget's area and @region, returning
6069 * the intersection. The result may be empty, use cairo_region_is_empty() to
6073 gtk_widget_region_intersect (GtkWidget *widget,
6074 const cairo_region_t *region)
6077 cairo_region_t *dest;
6079 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6080 g_return_val_if_fail (region != NULL, NULL);
6082 gtk_widget_get_allocation (widget, &rect);
6084 dest = cairo_region_create_rectangle (&rect);
6086 cairo_region_intersect (dest, region);
6092 * _gtk_widget_grab_notify:
6093 * @widget: a #GtkWidget
6094 * @was_grabbed: whether a grab is now in effect
6096 * Emits the #GtkWidget::grab-notify signal on @widget.
6101 _gtk_widget_grab_notify (GtkWidget *widget,
6102 gboolean was_grabbed)
6104 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6108 * gtk_widget_grab_focus:
6109 * @widget: a #GtkWidget
6111 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6112 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6113 * something like #GtkFrame won't work.
6115 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6116 * gtk_widget_set_can_focus() to modify that flag.
6118 * The widget also needs to be realized and mapped. This is indicated by the
6119 * related signals. Grabbing the focus immediately after creating the widget
6120 * will likely fail and cause critical warnings.
6123 gtk_widget_grab_focus (GtkWidget *widget)
6125 g_return_if_fail (GTK_IS_WIDGET (widget));
6127 if (!gtk_widget_is_sensitive (widget))
6130 g_object_ref (widget);
6131 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6132 g_object_notify (G_OBJECT (widget), "has-focus");
6133 g_object_unref (widget);
6137 reset_focus_recurse (GtkWidget *widget,
6140 if (GTK_IS_CONTAINER (widget))
6142 GtkContainer *container;
6144 container = GTK_CONTAINER (widget);
6145 gtk_container_set_focus_child (container, NULL);
6147 gtk_container_foreach (container,
6148 reset_focus_recurse,
6154 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6156 if (gtk_widget_get_can_focus (focus_widget))
6158 GtkWidget *toplevel;
6161 /* clear the current focus setting, break if the current widget
6162 * is the focus widget's parent, since containers above that will
6163 * be set by the next loop.
6165 toplevel = gtk_widget_get_toplevel (focus_widget);
6166 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6168 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6170 if (widget == focus_widget)
6172 /* We call _gtk_window_internal_set_focus() here so that the
6173 * toplevel window can request the focus if necessary.
6174 * This is needed when the toplevel is a GtkPlug
6176 if (!gtk_widget_has_focus (widget))
6177 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6184 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
6186 widget = widget->priv->parent;
6187 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6191 else if (toplevel != focus_widget)
6193 /* gtk_widget_grab_focus() operates on a tree without window...
6194 * actually, this is very questionable behaviour.
6197 gtk_container_foreach (GTK_CONTAINER (toplevel),
6198 reset_focus_recurse,
6202 /* now propagate the new focus up the widget tree and finally
6203 * set it on the window
6205 widget = focus_widget;
6206 while (widget->priv->parent)
6208 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6209 widget = widget->priv->parent;
6211 if (GTK_IS_WINDOW (widget))
6212 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6217 gtk_widget_real_query_tooltip (GtkWidget *widget,
6220 gboolean keyboard_tip,
6221 GtkTooltip *tooltip)
6223 gchar *tooltip_markup;
6224 gboolean has_tooltip;
6226 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6227 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6229 if (has_tooltip && tooltip_markup)
6231 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6239 gtk_widget_real_style_updated (GtkWidget *widget)
6241 if (widget->priv->context)
6242 gtk_style_context_invalidate (widget->priv->context);
6246 gtk_widget_real_show_help (GtkWidget *widget,
6247 GtkWidgetHelpType help_type)
6249 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6251 _gtk_tooltip_toggle_keyboard_mode (widget);
6260 gtk_widget_real_focus (GtkWidget *widget,
6261 GtkDirectionType direction)
6263 if (!gtk_widget_get_can_focus (widget))
6266 if (!gtk_widget_is_focus (widget))
6268 gtk_widget_grab_focus (widget);
6276 gtk_widget_real_move_focus (GtkWidget *widget,
6277 GtkDirectionType direction)
6279 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6281 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6283 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6289 gtk_widget_real_keynav_failed (GtkWidget *widget,
6290 GtkDirectionType direction)
6292 gboolean cursor_only;
6296 case GTK_DIR_TAB_FORWARD:
6297 case GTK_DIR_TAB_BACKWARD:
6304 g_object_get (gtk_widget_get_settings (widget),
6305 "gtk-keynav-cursor-only", &cursor_only,
6312 gtk_widget_error_bell (widget);
6318 * gtk_widget_set_can_focus:
6319 * @widget: a #GtkWidget
6320 * @can_focus: whether or not @widget can own the input focus.
6322 * Specifies whether @widget can own the input focus. See
6323 * gtk_widget_grab_focus() for actually setting the input focus on a
6329 gtk_widget_set_can_focus (GtkWidget *widget,
6332 g_return_if_fail (GTK_IS_WIDGET (widget));
6334 if (widget->priv->can_focus != can_focus)
6336 widget->priv->can_focus = can_focus;
6338 gtk_widget_queue_resize (widget);
6339 g_object_notify (G_OBJECT (widget), "can-focus");
6344 * gtk_widget_get_can_focus:
6345 * @widget: a #GtkWidget
6347 * Determines whether @widget can own the input focus. See
6348 * gtk_widget_set_can_focus().
6350 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6355 gtk_widget_get_can_focus (GtkWidget *widget)
6357 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6359 return widget->priv->can_focus;
6363 * gtk_widget_has_focus:
6364 * @widget: a #GtkWidget
6366 * Determines if the widget has the global input focus. See
6367 * gtk_widget_is_focus() for the difference between having the global
6368 * input focus, and only having the focus within a toplevel.
6370 * Return value: %TRUE if the widget has the global input focus.
6375 gtk_widget_has_focus (GtkWidget *widget)
6377 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6379 return widget->priv->has_focus;
6383 * gtk_widget_is_focus:
6384 * @widget: a #GtkWidget
6386 * Determines if the widget is the focus widget within its
6387 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6388 * necessarily set; %HAS_FOCUS will only be set if the
6389 * toplevel widget additionally has the global input focus.)
6391 * Return value: %TRUE if the widget is the focus widget.
6394 gtk_widget_is_focus (GtkWidget *widget)
6396 GtkWidget *toplevel;
6398 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6400 toplevel = gtk_widget_get_toplevel (widget);
6402 if (GTK_IS_WINDOW (toplevel))
6403 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6409 * gtk_widget_set_can_default:
6410 * @widget: a #GtkWidget
6411 * @can_default: whether or not @widget can be a default widget.
6413 * Specifies whether @widget can be a default widget. See
6414 * gtk_widget_grab_default() for details about the meaning of
6420 gtk_widget_set_can_default (GtkWidget *widget,
6421 gboolean can_default)
6423 g_return_if_fail (GTK_IS_WIDGET (widget));
6425 if (widget->priv->can_default != can_default)
6427 widget->priv->can_default = can_default;
6429 gtk_widget_queue_resize (widget);
6430 g_object_notify (G_OBJECT (widget), "can-default");
6435 * gtk_widget_get_can_default:
6436 * @widget: a #GtkWidget
6438 * Determines whether @widget can be a default widget. See
6439 * gtk_widget_set_can_default().
6441 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6446 gtk_widget_get_can_default (GtkWidget *widget)
6448 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6450 return widget->priv->can_default;
6454 * gtk_widget_has_default:
6455 * @widget: a #GtkWidget
6457 * Determines whether @widget is the current default widget within its
6458 * toplevel. See gtk_widget_set_can_default().
6460 * Return value: %TRUE if @widget is the current default widget within
6461 * its toplevel, %FALSE otherwise
6466 gtk_widget_has_default (GtkWidget *widget)
6468 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6470 return widget->priv->has_default;
6474 _gtk_widget_set_has_default (GtkWidget *widget,
6475 gboolean has_default)
6477 widget->priv->has_default = has_default;
6481 * gtk_widget_grab_default:
6482 * @widget: a #GtkWidget
6484 * Causes @widget to become the default widget. @widget must have the
6485 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6486 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6487 * %TRUE)</literal>. The default widget is activated when
6488 * the user presses Enter in a window. Default widgets must be
6489 * activatable, that is, gtk_widget_activate() should affect them. Note
6490 * that #GtkEntry widgets require the "activates-default" property
6491 * set to %TRUE before they activate the default widget when Enter
6492 * is pressed and the #GtkEntry is focused.
6495 gtk_widget_grab_default (GtkWidget *widget)
6499 g_return_if_fail (GTK_IS_WIDGET (widget));
6500 g_return_if_fail (gtk_widget_get_can_default (widget));
6502 window = gtk_widget_get_toplevel (widget);
6504 if (window && gtk_widget_is_toplevel (window))
6505 gtk_window_set_default (GTK_WINDOW (window), widget);
6507 g_warning (G_STRLOC ": widget not within a GtkWindow");
6511 * gtk_widget_set_receives_default:
6512 * @widget: a #GtkWidget
6513 * @receives_default: whether or not @widget can be a default widget.
6515 * Specifies whether @widget will be treated as the default widget
6516 * within its toplevel when it has the focus, even if another widget
6519 * See gtk_widget_grab_default() for details about the meaning of
6525 gtk_widget_set_receives_default (GtkWidget *widget,
6526 gboolean receives_default)
6528 g_return_if_fail (GTK_IS_WIDGET (widget));
6530 if (widget->priv->receives_default != receives_default)
6532 widget->priv->receives_default = receives_default;
6534 g_object_notify (G_OBJECT (widget), "receives-default");
6539 * gtk_widget_get_receives_default:
6540 * @widget: a #GtkWidget
6542 * Determines whether @widget is alyways treated as default widget
6543 * withing its toplevel when it has the focus, even if another widget
6546 * See gtk_widget_set_receives_default().
6548 * Return value: %TRUE if @widget acts as default widget when focussed,
6554 gtk_widget_get_receives_default (GtkWidget *widget)
6556 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6558 return widget->priv->receives_default;
6562 * gtk_widget_has_grab:
6563 * @widget: a #GtkWidget
6565 * Determines whether the widget is currently grabbing events, so it
6566 * is the only widget receiving input events (keyboard and mouse).
6568 * See also gtk_grab_add().
6570 * Return value: %TRUE if the widget is in the grab_widgets stack
6575 gtk_widget_has_grab (GtkWidget *widget)
6577 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6579 return widget->priv->has_grab;
6583 _gtk_widget_set_has_grab (GtkWidget *widget,
6586 widget->priv->has_grab = has_grab;
6590 * gtk_widget_device_is_shadowed:
6591 * @widget: a #GtkWidget
6592 * @device: a #GdkDevice
6594 * Returns %TRUE if @device has been shadowed by a GTK+
6595 * device grab on another widget, so it would stop sending
6596 * events to @widget. This may be used in the
6597 * #GtkWidget::grab-notify signal to check for specific
6598 * devices. See gtk_device_grab_add().
6600 * Returns: %TRUE if there is an ongoing grab on @device
6601 * by another #GtkWidget than @widget.
6606 gtk_widget_device_is_shadowed (GtkWidget *widget,
6609 GtkWindowGroup *group;
6610 GtkWidget *grab_widget, *toplevel;
6612 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6613 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6615 if (!gtk_widget_get_realized (widget))
6618 toplevel = gtk_widget_get_toplevel (widget);
6620 if (GTK_IS_WINDOW (toplevel))
6621 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6623 group = gtk_window_get_group (NULL);
6625 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6627 /* Widget not inside the hierarchy of grab_widget */
6629 widget != grab_widget &&
6630 !gtk_widget_is_ancestor (widget, grab_widget))
6633 grab_widget = gtk_window_group_get_current_grab (group);
6634 if (grab_widget && widget != grab_widget &&
6635 !gtk_widget_is_ancestor (widget, grab_widget))
6642 * gtk_widget_set_name:
6643 * @widget: a #GtkWidget
6644 * @name: name for the widget
6646 * Widgets can be named, which allows you to refer to them from a
6647 * gtkrc file. You can apply a style to widgets with a particular name
6648 * in the gtkrc file. See the documentation for gtkrc files (on the
6649 * same page as the docs for #GtkRcStyle).
6651 * Note that widget names are separated by periods in paths (see
6652 * gtk_widget_path()), so names with embedded periods may cause confusion.
6655 gtk_widget_set_name (GtkWidget *widget,
6658 GtkWidgetPrivate *priv;
6661 g_return_if_fail (GTK_IS_WIDGET (widget));
6663 priv = widget->priv;
6665 new_name = g_strdup (name);
6666 g_free (priv->name);
6667 priv->name = new_name;
6670 gtk_widget_reset_rc_style (widget);
6672 g_object_notify (G_OBJECT (widget), "name");
6676 * gtk_widget_get_name:
6677 * @widget: a #GtkWidget
6679 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6680 * significance of widget names.
6682 * Return value: name of the widget. This string is owned by GTK+ and
6683 * should not be modified or freed
6685 G_CONST_RETURN gchar*
6686 gtk_widget_get_name (GtkWidget *widget)
6688 GtkWidgetPrivate *priv;
6690 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6692 priv = widget->priv;
6696 return G_OBJECT_TYPE_NAME (widget);
6700 * gtk_widget_set_state:
6701 * @widget: a #GtkWidget
6702 * @state: new state for @widget
6704 * This function is for use in widget implementations. Sets the state
6705 * of a widget (insensitive, prelighted, etc.) Usually you should set
6706 * the state using wrapper functions such as gtk_widget_set_sensitive().
6709 gtk_widget_set_state (GtkWidget *widget,
6712 GtkWidgetPrivate *priv;
6714 g_return_if_fail (GTK_IS_WIDGET (widget));
6716 priv = widget->priv;
6718 if (state == gtk_widget_get_state (widget))
6721 if (state == GTK_STATE_INSENSITIVE)
6722 gtk_widget_set_sensitive (widget, FALSE);
6728 data.state_restoration = FALSE;
6729 data.use_forall = FALSE;
6731 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6733 data.parent_sensitive = TRUE;
6735 gtk_widget_propagate_state (widget, &data);
6737 if (gtk_widget_is_drawable (widget))
6738 gtk_widget_queue_draw (widget);
6743 * gtk_widget_get_state:
6744 * @widget: a #GtkWidget
6746 * Returns the widget's state. See gtk_widget_set_state().
6748 * Returns: the state of @widget.
6753 gtk_widget_get_state (GtkWidget *widget)
6755 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
6757 return widget->priv->state;
6761 * gtk_widget_set_visible:
6762 * @widget: a #GtkWidget
6763 * @visible: whether the widget should be shown or not
6765 * Sets the visibility state of @widget. Note that setting this to
6766 * %TRUE doesn't mean the widget is actually viewable, see
6767 * gtk_widget_get_visible().
6769 * This function simply calls gtk_widget_show() or gtk_widget_hide()
6770 * but is nicer to use when the visibility of the widget depends on
6776 gtk_widget_set_visible (GtkWidget *widget,
6779 g_return_if_fail (GTK_IS_WIDGET (widget));
6781 if (visible != gtk_widget_get_visible (widget))
6784 gtk_widget_show (widget);
6786 gtk_widget_hide (widget);
6791 _gtk_widget_set_visible_flag (GtkWidget *widget,
6794 widget->priv->visible = visible;
6798 * gtk_widget_get_visible:
6799 * @widget: a #GtkWidget
6801 * Determines whether the widget is visible. Note that this doesn't
6802 * take into account whether the widget's parent is also visible
6803 * or the widget is obscured in any way.
6805 * See gtk_widget_set_visible().
6807 * Return value: %TRUE if the widget is visible
6812 gtk_widget_get_visible (GtkWidget *widget)
6814 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6816 return widget->priv->visible;
6820 * gtk_widget_set_has_window:
6821 * @widget: a #GtkWidget
6822 * @has_window: whether or not @widget has a window.
6824 * Specifies whether @widget has a #GdkWindow of its own. Note that
6825 * all realized widgets have a non-%NULL "window" pointer
6826 * (gtk_widget_get_window() never returns a %NULL window when a widget
6827 * is realized), but for many of them it's actually the #GdkWindow of
6828 * one of its parent widgets. Widgets that do not create a %window for
6829 * themselves in #GtkWidget::realize must announce this by
6830 * calling this function with @has_window = %FALSE.
6832 * This function should only be called by widget implementations,
6833 * and they should call it in their init() function.
6838 gtk_widget_set_has_window (GtkWidget *widget,
6839 gboolean has_window)
6841 g_return_if_fail (GTK_IS_WIDGET (widget));
6843 widget->priv->no_window = !has_window;
6847 * gtk_widget_get_has_window:
6848 * @widget: a #GtkWidget
6850 * Determines whether @widget has a #GdkWindow of its own. See
6851 * gtk_widget_set_has_window().
6853 * Return value: %TRUE if @widget has a window, %FALSE otherwise
6858 gtk_widget_get_has_window (GtkWidget *widget)
6860 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6862 return ! widget->priv->no_window;
6866 * gtk_widget_is_toplevel:
6867 * @widget: a #GtkWidget
6869 * Determines whether @widget is a toplevel widget. Currently only
6870 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
6871 * widgets have no parent widget.
6873 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
6878 gtk_widget_is_toplevel (GtkWidget *widget)
6880 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6882 return widget->priv->toplevel;
6886 _gtk_widget_set_is_toplevel (GtkWidget *widget,
6887 gboolean is_toplevel)
6889 widget->priv->toplevel = is_toplevel;
6893 * gtk_widget_is_drawable:
6894 * @widget: a #GtkWidget
6896 * Determines whether @widget can be drawn to. A widget can be drawn
6897 * to if it is mapped and visible.
6899 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
6904 gtk_widget_is_drawable (GtkWidget *widget)
6906 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6908 return (gtk_widget_get_visible (widget) &&
6909 gtk_widget_get_mapped (widget));
6913 * gtk_widget_get_realized:
6914 * @widget: a #GtkWidget
6916 * Determines whether @widget is realized.
6918 * Return value: %TRUE if @widget is realized, %FALSE otherwise
6923 gtk_widget_get_realized (GtkWidget *widget)
6925 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6927 return widget->priv->realized;
6931 * gtk_widget_set_realized:
6932 * @widget: a #GtkWidget
6933 * @realized: %TRUE to mark the widget as realized
6935 * Marks the widget as being realized.
6937 * This function should only ever be called in a derived widget's
6938 * "realize" or "unrealize" implementation.
6943 gtk_widget_set_realized (GtkWidget *widget,
6946 g_return_if_fail (GTK_IS_WIDGET (widget));
6948 widget->priv->realized = realized;
6952 * gtk_widget_get_mapped:
6953 * @widget: a #GtkWidget
6955 * Whether the widget is mapped.
6957 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
6962 gtk_widget_get_mapped (GtkWidget *widget)
6964 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6966 return widget->priv->mapped;
6970 * gtk_widget_set_mapped:
6971 * @widget: a #GtkWidget
6972 * @mapped: %TRUE to mark the widget as mapped
6974 * Marks the widget as being realized.
6976 * This function should only ever be called in a derived widget's
6977 * "map" or "unmap" implementation.
6982 gtk_widget_set_mapped (GtkWidget *widget,
6985 g_return_if_fail (GTK_IS_WIDGET (widget));
6987 widget->priv->mapped = mapped;
6991 * gtk_widget_set_app_paintable:
6992 * @widget: a #GtkWidget
6993 * @app_paintable: %TRUE if the application will paint on the widget
6995 * Sets whether the application intends to draw on the widget in
6996 * an #GtkWidget::draw handler.
6998 * This is a hint to the widget and does not affect the behavior of
6999 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7000 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7001 * the effect is to suppress default themed drawing of the widget's
7002 * background. (Children of the widget will still be drawn.) The application
7003 * is then entirely responsible for drawing the widget background.
7005 * Note that the background is still drawn when the widget is mapped.
7008 gtk_widget_set_app_paintable (GtkWidget *widget,
7009 gboolean app_paintable)
7011 g_return_if_fail (GTK_IS_WIDGET (widget));
7013 app_paintable = (app_paintable != FALSE);
7015 if (widget->priv->app_paintable != app_paintable)
7017 widget->priv->app_paintable = app_paintable;
7019 if (gtk_widget_is_drawable (widget))
7020 gtk_widget_queue_draw (widget);
7022 g_object_notify (G_OBJECT (widget), "app-paintable");
7027 * gtk_widget_get_app_paintable:
7028 * @widget: a #GtkWidget
7030 * Determines whether the application intends to draw on the widget in
7031 * an #GtkWidget::draw handler.
7033 * See gtk_widget_set_app_paintable()
7035 * Return value: %TRUE if the widget is app paintable
7040 gtk_widget_get_app_paintable (GtkWidget *widget)
7042 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7044 return widget->priv->app_paintable;
7048 * gtk_widget_set_double_buffered:
7049 * @widget: a #GtkWidget
7050 * @double_buffered: %TRUE to double-buffer a widget
7052 * Widgets are double buffered by default; you can use this function
7053 * to turn off the buffering. "Double buffered" simply means that
7054 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7055 * automatically around expose events sent to the
7056 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7057 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7058 * buffer to the screen. The result is that users see the window
7059 * update in one smooth step, and don't see individual graphics
7060 * primitives being rendered.
7062 * In very simple terms, double buffered widgets don't flicker,
7063 * so you would only use this function to turn off double buffering
7064 * if you had special needs and really knew what you were doing.
7066 * Note: if you turn off double-buffering, you have to handle
7067 * expose events, since even the clearing to the background color or
7068 * pixmap will not happen automatically (as it is done in
7069 * gdk_window_begin_paint()).
7072 gtk_widget_set_double_buffered (GtkWidget *widget,
7073 gboolean double_buffered)
7075 g_return_if_fail (GTK_IS_WIDGET (widget));
7077 double_buffered = (double_buffered != FALSE);
7079 if (widget->priv->double_buffered != double_buffered)
7081 widget->priv->double_buffered = double_buffered;
7083 g_object_notify (G_OBJECT (widget), "double-buffered");
7088 * gtk_widget_get_double_buffered:
7089 * @widget: a #GtkWidget
7091 * Determines whether the widget is double buffered.
7093 * See gtk_widget_set_double_buffered()
7095 * Return value: %TRUE if the widget is double buffered
7100 gtk_widget_get_double_buffered (GtkWidget *widget)
7102 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7104 return widget->priv->double_buffered;
7108 * gtk_widget_set_redraw_on_allocate:
7109 * @widget: a #GtkWidget
7110 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7111 * when it is allocated to a new size. Otherwise, only the
7112 * new portion of the widget will be redrawn.
7114 * Sets whether the entire widget is queued for drawing when its size
7115 * allocation changes. By default, this setting is %TRUE and
7116 * the entire widget is redrawn on every size change. If your widget
7117 * leaves the upper left unchanged when made bigger, turning this
7118 * setting off will improve performance.
7120 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7121 * off all allocation on resizing: the widget will not even redraw if
7122 * its position changes; this is to allow containers that don't draw
7123 * anything to avoid excess invalidations. If you set this flag on a
7124 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7125 * you are responsible for invalidating both the old and new allocation
7126 * of the widget when the widget is moved and responsible for invalidating
7127 * regions newly when the widget increases size.
7130 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7131 gboolean redraw_on_allocate)
7133 g_return_if_fail (GTK_IS_WIDGET (widget));
7135 widget->priv->redraw_on_alloc = redraw_on_allocate;
7139 * gtk_widget_set_sensitive:
7140 * @widget: a #GtkWidget
7141 * @sensitive: %TRUE to make the widget sensitive
7143 * Sets the sensitivity of a widget. A widget is sensitive if the user
7144 * can interact with it. Insensitive widgets are "grayed out" and the
7145 * user can't interact with them. Insensitive widgets are known as
7146 * "inactive", "disabled", or "ghosted" in some other toolkits.
7149 gtk_widget_set_sensitive (GtkWidget *widget,
7152 GtkWidgetPrivate *priv;
7155 g_return_if_fail (GTK_IS_WIDGET (widget));
7157 priv = widget->priv;
7159 sensitive = (sensitive != FALSE);
7161 if (widget->priv->sensitive == sensitive)
7166 widget->priv->sensitive = TRUE;
7167 data.state = priv->saved_state;
7171 widget->priv->sensitive = FALSE;
7172 data.state = gtk_widget_get_state (widget);
7174 data.state_restoration = TRUE;
7175 data.use_forall = TRUE;
7178 data.parent_sensitive = gtk_widget_is_sensitive (priv->parent);
7180 data.parent_sensitive = TRUE;
7182 gtk_widget_propagate_state (widget, &data);
7183 if (gtk_widget_is_drawable (widget))
7184 gtk_widget_queue_draw (widget);
7186 g_object_notify (G_OBJECT (widget), "sensitive");
7190 * gtk_widget_get_sensitive:
7191 * @widget: a #GtkWidget
7193 * Returns the widget's sensitivity (in the sense of returning
7194 * the value that has been set using gtk_widget_set_sensitive()).
7196 * The effective sensitivity of a widget is however determined by both its
7197 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7199 * Returns: %TRUE if the widget is sensitive
7204 gtk_widget_get_sensitive (GtkWidget *widget)
7206 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7208 return widget->priv->sensitive;
7212 * gtk_widget_is_sensitive:
7213 * @widget: a #GtkWidget
7215 * Returns the widget's effective sensitivity, which means
7216 * it is sensitive itself and also its parent widget is sensntive
7218 * Returns: %TRUE if the widget is effectively sensitive
7223 gtk_widget_is_sensitive (GtkWidget *widget)
7225 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7227 return widget->priv->sensitive && widget->priv->parent_sensitive;
7231 _gtk_widget_update_path (GtkWidget *widget)
7233 if (widget->priv->path)
7235 gtk_widget_path_free (widget->priv->path);
7236 widget->priv->path = NULL;
7239 gtk_widget_get_path (widget);
7243 * gtk_widget_set_parent:
7244 * @widget: a #GtkWidget
7245 * @parent: parent container
7247 * This function is useful only when implementing subclasses of
7249 * Sets the container as the parent of @widget, and takes care of
7250 * some details such as updating the state and style of the child
7251 * to reflect its new location. The opposite function is
7252 * gtk_widget_unparent().
7255 gtk_widget_set_parent (GtkWidget *widget,
7258 GtkWidgetPrivate *priv;
7261 g_return_if_fail (GTK_IS_WIDGET (widget));
7262 g_return_if_fail (GTK_IS_WIDGET (parent));
7263 g_return_if_fail (widget != parent);
7265 priv = widget->priv;
7267 if (priv->parent != NULL)
7269 g_warning ("Can't set a parent on widget which has a parent\n");
7272 if (gtk_widget_is_toplevel (widget))
7274 g_warning ("Can't set a parent on a toplevel widget\n");
7278 /* keep this function in sync with gtk_menu_attach_to_widget()
7281 g_object_ref_sink (widget);
7282 priv->parent = parent;
7284 if (gtk_widget_get_state (parent) != GTK_STATE_NORMAL)
7285 data.state = gtk_widget_get_state (parent);
7287 data.state = gtk_widget_get_state (widget);
7288 data.state_restoration = FALSE;
7289 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
7290 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7292 gtk_widget_propagate_state (widget, &data);
7294 gtk_widget_reset_rc_styles (widget);
7296 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7297 if (priv->parent->priv->anchored)
7298 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7299 g_object_notify (G_OBJECT (widget), "parent");
7301 /* Enforce realized/mapped invariants
7303 if (gtk_widget_get_realized (priv->parent))
7304 gtk_widget_realize (widget);
7306 if (gtk_widget_get_visible (priv->parent) &&
7307 gtk_widget_get_visible (widget))
7309 if (gtk_widget_get_child_visible (widget) &&
7310 gtk_widget_get_mapped (priv->parent))
7311 gtk_widget_map (widget);
7313 gtk_widget_queue_resize (widget);
7316 /* child may cause parent's expand to change, if the child is
7317 * expanded. If child is not expanded, then it can't modify the
7318 * parent's expand. If the child becomes expanded later then it will
7319 * queue compute_expand then. This optimization plus defaulting
7320 * newly-constructed widgets to need_compute_expand=FALSE should
7321 * mean that initially building a widget tree doesn't have to keep
7322 * walking up setting need_compute_expand on parents over and over.
7324 * We can't change a parent to need to expand unless we're visible.
7326 if (gtk_widget_get_visible (widget) &&
7327 (priv->need_compute_expand ||
7328 priv->computed_hexpand ||
7329 priv->computed_vexpand))
7331 gtk_widget_queue_compute_expand (parent);
7334 if (widget->priv->context)
7336 _gtk_widget_update_path (widget);
7337 gtk_style_context_set_path (widget->priv->context, widget->priv->path);
7339 gtk_style_context_set_screen (widget->priv->context,
7340 gtk_widget_get_screen (widget));
7345 * gtk_widget_get_parent:
7346 * @widget: a #GtkWidget
7348 * Returns the parent container of @widget.
7350 * Return value: (transfer none): the parent container of @widget, or %NULL
7353 gtk_widget_get_parent (GtkWidget *widget)
7355 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7357 return widget->priv->parent;
7360 /*****************************************
7362 * see docs/styles.txt
7363 *****************************************/
7366 * gtk_widget_style_attach:
7367 * @widget: a #GtkWidget
7369 * This function attaches the widget's #GtkStyle to the widget's
7370 * #GdkWindow. It is a replacement for
7373 * widget->style = gtk_style_attach (widget->style, widget->window);
7376 * and should only ever be called in a derived widget's "realize"
7377 * implementation which does not chain up to its parent class'
7378 * "realize" implementation, because one of the parent classes
7379 * (finally #GtkWidget) would attach the style itself.
7384 gtk_widget_style_attach (GtkWidget *widget)
7386 GtkWidgetPrivate *priv;
7388 g_return_if_fail (GTK_IS_WIDGET (widget));
7389 g_return_if_fail (gtk_widget_get_realized (widget));
7391 priv = widget->priv;
7393 priv->style = gtk_style_attach (priv->style, priv->window);
7397 * gtk_widget_has_rc_style:
7398 * @widget: a #GtkWidget
7400 * Determines if the widget style has been looked up through the rc mechanism.
7402 * Returns: %TRUE if the widget has been looked up through the rc
7403 * mechanism, %FALSE otherwise.
7408 gtk_widget_has_rc_style (GtkWidget *widget)
7410 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7412 return widget->priv->rc_style;
7416 * gtk_widget_set_style:
7417 * @widget: a #GtkWidget
7418 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
7419 * gtk_widget_set_style() and go back to the default style
7421 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
7422 * want to use this function; it interacts badly with themes, because
7423 * themes work by replacing the #GtkStyle. Instead, use
7424 * gtk_widget_modify_style().
7427 gtk_widget_set_style (GtkWidget *widget,
7430 g_return_if_fail (GTK_IS_WIDGET (widget));
7434 gboolean initial_emission;
7436 initial_emission = !widget->priv->rc_style && !widget->priv->user_style;
7438 widget->priv->rc_style = FALSE;
7439 widget->priv->user_style = TRUE;
7441 gtk_widget_set_style_internal (widget, style, initial_emission);
7445 if (widget->priv->user_style)
7446 gtk_widget_reset_rc_style (widget);
7451 * gtk_widget_ensure_style:
7452 * @widget: a #GtkWidget
7454 * Ensures that @widget has a style (@widget->style). Not a very useful
7455 * function; most of the time, if you want the style, the widget is
7456 * realized, and realized widgets are guaranteed to have a style
7460 gtk_widget_ensure_style (GtkWidget *widget)
7462 g_return_if_fail (GTK_IS_WIDGET (widget));
7464 if (!widget->priv->style ||
7465 !gtk_style_has_context (widget->priv->style))
7469 style = g_object_new (GTK_TYPE_STYLE,
7470 "context", gtk_widget_get_style_context (widget),
7473 gtk_widget_set_style_internal (widget, style, TRUE);
7474 g_object_unref (style);
7478 if (!widget->priv->rc_style && !widget->priv->user_style)
7479 gtk_widget_reset_rc_style (widget);
7483 /* Look up the RC style for this widget, unsetting any user style that
7484 * may be in effect currently
7487 gtk_widget_reset_rc_style (GtkWidget *widget)
7489 GtkWidgetPrivate *priv = widget->priv;
7490 GtkStyle *new_style = NULL;
7491 gboolean initial_emission;
7493 initial_emission = !priv->rc_style && !priv->user_style;
7495 priv->user_style = FALSE;
7496 priv->rc_style = TRUE;
7498 if (gtk_widget_has_screen (widget))
7499 new_style = gtk_rc_get_style (widget);
7501 new_style = gtk_widget_get_default_style ();
7503 if (initial_emission || new_style != priv->style)
7504 gtk_widget_set_style_internal (widget, new_style, initial_emission);
7508 * gtk_widget_get_style:
7509 * @widget: a #GtkWidget
7511 * Simply an accessor function that returns @widget->style.
7513 * Return value: (transfer none): the widget's #GtkStyle
7516 gtk_widget_get_style (GtkWidget *widget)
7518 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7520 return widget->priv->style;
7524 * gtk_widget_modify_style:
7525 * @widget: a #GtkWidget
7526 * @style: the #GtkRcStyle holding the style modifications
7528 * Modifies style values on the widget. Modifications made using this
7529 * technique take precedence over style values set via an RC file,
7530 * however, they will be overriden if a style is explicitely set on
7531 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
7532 * is designed so each field can either be set or unset, so it is
7533 * possible, using this function, to modify some style values and
7534 * leave the others unchanged.
7536 * Note that modifications made with this function are not cumulative
7537 * with previous calls to gtk_widget_modify_style() or with such
7538 * functions as gtk_widget_modify_fg(). If you wish to retain
7539 * previous values, you must first call gtk_widget_get_modifier_style(),
7540 * make your modifications to the returned style, then call
7541 * gtk_widget_modify_style() with that style. On the other hand,
7542 * if you first call gtk_widget_modify_style(), subsequent calls
7543 * to such functions gtk_widget_modify_fg() will have a cumulative
7544 * effect with the initial modifications.
7547 gtk_widget_modify_style (GtkWidget *widget,
7550 g_return_if_fail (GTK_IS_WIDGET (widget));
7551 g_return_if_fail (GTK_IS_RC_STYLE (style));
7553 g_object_set_qdata_full (G_OBJECT (widget),
7555 gtk_rc_style_copy (style),
7556 (GDestroyNotify) g_object_unref);
7558 /* note that "style" may be invalid here if it was the old
7559 * modifier style and the only reference was our own.
7562 if (widget->priv->rc_style)
7563 gtk_widget_reset_rc_style (widget);
7567 * gtk_widget_get_modifier_style:
7568 * @widget: a #GtkWidget
7570 * Returns the current modifier style for the widget. (As set by
7571 * gtk_widget_modify_style().) If no style has previously set, a new
7572 * #GtkRcStyle will be created with all values unset, and set as the
7573 * modifier style for the widget. If you make changes to this rc
7574 * style, you must call gtk_widget_modify_style(), passing in the
7575 * returned rc style, to make sure that your changes take effect.
7577 * Caution: passing the style back to gtk_widget_modify_style() will
7578 * normally end up destroying it, because gtk_widget_modify_style() copies
7579 * the passed-in style and sets the copy as the new modifier style,
7580 * thus dropping any reference to the old modifier style. Add a reference
7581 * to the modifier style if you want to keep it alive.
7583 * Return value: (transfer none): the modifier style for the widget. This rc style is
7584 * owned by the widget. If you want to keep a pointer to value this
7585 * around, you must add a refcount using g_object_ref().
7588 gtk_widget_get_modifier_style (GtkWidget *widget)
7590 GtkRcStyle *rc_style;
7592 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7594 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7598 rc_style = gtk_rc_style_new ();
7599 g_object_set_qdata_full (G_OBJECT (widget),
7602 (GDestroyNotify) g_object_unref);
7609 gtk_widget_modify_color_component (GtkWidget *widget,
7610 GtkRcFlags component,
7612 const GdkColor *color)
7614 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7621 rc_style->fg[state] = *color;
7624 rc_style->bg[state] = *color;
7627 rc_style->text[state] = *color;
7630 rc_style->base[state] = *color;
7633 g_assert_not_reached();
7636 rc_style->color_flags[state] |= component;
7639 rc_style->color_flags[state] &= ~component;
7641 gtk_widget_modify_style (widget, rc_style);
7645 * gtk_widget_modify_symbolic_color:
7646 * @widget: a #GtkWidget
7647 * @name: the name of the symbolic color to modify
7648 * @color: (allow-none): the color to assign (does not need to be allocated),
7649 * or %NULL to undo the effect of previous calls to
7650 * of gtk_widget_modify_symbolic_color().
7652 * Sets a symbolic color for a widget.
7653 * All other style values are left untouched. See also
7654 * gtk_widget_modify_style().
7659 gtk_widget_modify_symbolic_color (GtkWidget *widget,
7661 const GdkColor *color)
7663 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7665 _gtk_rc_style_set_symbolic_color (rc_style, name, color);
7667 gtk_widget_modify_style (widget, rc_style);
7671 * gtk_widget_modify_fg:
7672 * @widget: a #GtkWidget
7673 * @state: the state for which to set the foreground color
7674 * @color: (allow-none): the color to assign (does not need to be allocated),
7675 * or %NULL to undo the effect of previous calls to
7676 * of gtk_widget_modify_fg().
7678 * Sets the foreground color for a widget in a particular state.
7679 * All other style values are left untouched. See also
7680 * gtk_widget_modify_style().
7683 gtk_widget_modify_fg (GtkWidget *widget,
7685 const GdkColor *color)
7687 g_return_if_fail (GTK_IS_WIDGET (widget));
7688 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7690 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
7694 * gtk_widget_modify_bg:
7695 * @widget: a #GtkWidget
7696 * @state: the state for which to set the background color
7697 * @color: (allow-none): the color to assign (does not need to be allocated),
7698 * or %NULL to undo the effect of previous calls to
7699 * of gtk_widget_modify_bg().
7701 * Sets the background color for a widget in a particular state.
7702 * All other style values are left untouched. See also
7703 * gtk_widget_modify_style().
7705 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7706 * draw on their parent container's window and thus may not draw any
7707 * background themselves. This is the case for e.g. #GtkLabel. To modify
7708 * the background of such widgets, you have to set the background color
7709 * on their parent; if you want to set the background of a rectangular
7710 * area around a label, try placing the label in a #GtkEventBox widget
7711 * and setting the background color on that.
7714 gtk_widget_modify_bg (GtkWidget *widget,
7716 const GdkColor *color)
7718 g_return_if_fail (GTK_IS_WIDGET (widget));
7719 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7721 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
7725 * gtk_widget_modify_text:
7726 * @widget: a #GtkWidget
7727 * @state: the state for which to set the text color
7728 * @color: (allow-none): the color to assign (does not need to be allocated),
7729 * or %NULL to undo the effect of previous calls to
7730 * of gtk_widget_modify_text().
7732 * Sets the text color for a widget in a particular state. All other
7733 * style values are left untouched. The text color is the foreground
7734 * color used along with the base color (see gtk_widget_modify_base())
7735 * for widgets such as #GtkEntry and #GtkTextView. See also
7736 * gtk_widget_modify_style().
7739 gtk_widget_modify_text (GtkWidget *widget,
7741 const GdkColor *color)
7743 g_return_if_fail (GTK_IS_WIDGET (widget));
7744 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7746 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
7750 * gtk_widget_modify_base:
7751 * @widget: a #GtkWidget
7752 * @state: the state for which to set the base color
7753 * @color: (allow-none): the color to assign (does not need to be allocated),
7754 * or %NULL to undo the effect of previous calls to
7755 * of gtk_widget_modify_base().
7757 * Sets the base color for a widget in a particular state.
7758 * All other style values are left untouched. The base color
7759 * is the background color used along with the text color
7760 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
7761 * and #GtkTextView. See also gtk_widget_modify_style().
7763 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7764 * draw on their parent container's window and thus may not draw any
7765 * background themselves. This is the case for e.g. #GtkLabel. To modify
7766 * the background of such widgets, you have to set the base color on their
7767 * parent; if you want to set the background of a rectangular area around
7768 * a label, try placing the label in a #GtkEventBox widget and setting
7769 * the base color on that.
7772 gtk_widget_modify_base (GtkWidget *widget,
7774 const GdkColor *color)
7776 g_return_if_fail (GTK_IS_WIDGET (widget));
7777 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7779 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
7783 modify_color_property (GtkWidget *widget,
7784 GtkRcStyle *rc_style,
7786 const GdkColor *color)
7788 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
7789 GQuark property_name = g_quark_from_string (name);
7793 GtkRcProperty rc_property = {0};
7796 rc_property.type_name = type_name;
7797 rc_property.property_name = property_name;
7798 rc_property.origin = NULL;
7800 color_name = gdk_color_to_string (color);
7801 g_value_init (&rc_property.value, G_TYPE_STRING);
7802 g_value_take_string (&rc_property.value, color_name);
7804 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
7806 g_value_unset (&rc_property.value);
7809 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
7813 * gtk_widget_modify_cursor:
7814 * @widget: a #GtkWidget
7815 * @primary: the color to use for primary cursor (does not need to be
7816 * allocated), or %NULL to undo the effect of previous calls to
7817 * of gtk_widget_modify_cursor().
7818 * @secondary: the color to use for secondary cursor (does not need to be
7819 * allocated), or %NULL to undo the effect of previous calls to
7820 * of gtk_widget_modify_cursor().
7822 * Sets the cursor color to use in a widget, overriding the
7823 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
7824 * style properties. All other style values are left untouched.
7825 * See also gtk_widget_modify_style().
7830 gtk_widget_modify_cursor (GtkWidget *widget,
7831 const GdkColor *primary,
7832 const GdkColor *secondary)
7834 GtkRcStyle *rc_style;
7836 g_return_if_fail (GTK_IS_WIDGET (widget));
7838 rc_style = gtk_widget_get_modifier_style (widget);
7840 modify_color_property (widget, rc_style, "cursor-color", primary);
7841 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
7843 gtk_widget_modify_style (widget, rc_style);
7847 * gtk_widget_modify_font:
7848 * @widget: a #GtkWidget
7849 * @font_desc: (allow-none): the font description to use, or %NULL to undo
7850 * the effect of previous calls to gtk_widget_modify_font().
7852 * Sets the font to use for a widget. All other style values are left
7853 * untouched. See also gtk_widget_modify_style().
7856 gtk_widget_modify_font (GtkWidget *widget,
7857 PangoFontDescription *font_desc)
7859 GtkRcStyle *rc_style;
7861 g_return_if_fail (GTK_IS_WIDGET (widget));
7863 rc_style = gtk_widget_get_modifier_style (widget);
7865 if (rc_style->font_desc)
7866 pango_font_description_free (rc_style->font_desc);
7869 rc_style->font_desc = pango_font_description_copy (font_desc);
7871 rc_style->font_desc = NULL;
7873 gtk_widget_modify_style (widget, rc_style);
7877 gtk_widget_real_direction_changed (GtkWidget *widget,
7878 GtkTextDirection previous_direction)
7880 gtk_widget_queue_resize (widget);
7884 gtk_widget_real_style_set (GtkWidget *widget,
7885 GtkStyle *previous_style)
7887 GtkWidgetPrivate *priv = widget->priv;
7889 if (gtk_widget_get_realized (widget) &&
7890 gtk_widget_get_has_window (widget))
7891 gtk_style_set_background (priv->style, priv->window, priv->state);
7895 gtk_widget_set_style_internal (GtkWidget *widget,
7897 gboolean initial_emission)
7899 GtkWidgetPrivate *priv = widget->priv;
7901 g_object_ref (widget);
7902 g_object_freeze_notify (G_OBJECT (widget));
7904 if (priv->style != style)
7906 GtkStyle *previous_style;
7908 if (gtk_widget_get_realized (widget))
7910 gtk_widget_reset_shapes (widget);
7911 gtk_style_detach (priv->style);
7914 previous_style = priv->style;
7915 priv->style = style;
7916 g_object_ref (priv->style);
7918 if (gtk_widget_get_realized (widget))
7919 priv->style = gtk_style_attach (priv->style, priv->window);
7921 gtk_widget_update_pango_context (widget);
7922 g_signal_emit (widget,
7923 widget_signals[STYLE_SET],
7925 initial_emission ? NULL : previous_style);
7926 g_object_unref (previous_style);
7928 if (priv->anchored && !initial_emission)
7929 gtk_widget_queue_resize (widget);
7931 else if (initial_emission)
7933 gtk_widget_update_pango_context (widget);
7934 g_signal_emit (widget,
7935 widget_signals[STYLE_SET],
7939 g_object_notify (G_OBJECT (widget), "style");
7940 g_object_thaw_notify (G_OBJECT (widget));
7941 g_object_unref (widget);
7945 GtkWidget *previous_toplevel;
7946 GdkScreen *previous_screen;
7947 GdkScreen *new_screen;
7948 } HierarchyChangedInfo;
7951 do_screen_change (GtkWidget *widget,
7952 GdkScreen *old_screen,
7953 GdkScreen *new_screen)
7955 if (old_screen != new_screen)
7957 GtkStyleContext *context;
7961 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7963 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
7966 _gtk_tooltip_hide (widget);
7968 context = gtk_widget_get_style_context (widget);
7969 gtk_style_context_set_screen (context, new_screen);
7971 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
7976 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
7977 gpointer client_data)
7979 GtkWidgetPrivate *priv = widget->priv;
7980 HierarchyChangedInfo *info = client_data;
7981 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
7982 (priv->parent && priv->parent->priv->anchored);
7984 if (priv->anchored != new_anchored)
7986 g_object_ref (widget);
7988 priv->anchored = new_anchored;
7990 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
7991 do_screen_change (widget, info->previous_screen, info->new_screen);
7993 if (GTK_IS_CONTAINER (widget))
7994 gtk_container_forall (GTK_CONTAINER (widget),
7995 gtk_widget_propagate_hierarchy_changed_recurse,
7998 g_object_unref (widget);
8003 * _gtk_widget_propagate_hierarchy_changed:
8004 * @widget: a #GtkWidget
8005 * @previous_toplevel: Previous toplevel
8007 * Propagates changes in the anchored state to a widget and all
8008 * children, unsetting or setting the %ANCHORED flag, and
8009 * emitting #GtkWidget::hierarchy-changed.
8012 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8013 GtkWidget *previous_toplevel)
8015 GtkWidgetPrivate *priv = widget->priv;
8016 HierarchyChangedInfo info;
8018 info.previous_toplevel = previous_toplevel;
8019 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8021 if (gtk_widget_is_toplevel (widget) ||
8022 (priv->parent && priv->parent->priv->anchored))
8023 info.new_screen = gtk_widget_get_screen (widget);
8025 info.new_screen = NULL;
8027 if (info.previous_screen)
8028 g_object_ref (info.previous_screen);
8029 if (previous_toplevel)
8030 g_object_ref (previous_toplevel);
8032 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8034 if (previous_toplevel)
8035 g_object_unref (previous_toplevel);
8036 if (info.previous_screen)
8037 g_object_unref (info.previous_screen);
8041 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8042 gpointer client_data)
8044 HierarchyChangedInfo *info = client_data;
8046 g_object_ref (widget);
8048 do_screen_change (widget, info->previous_screen, info->new_screen);
8050 if (GTK_IS_CONTAINER (widget))
8051 gtk_container_forall (GTK_CONTAINER (widget),
8052 gtk_widget_propagate_screen_changed_recurse,
8055 g_object_unref (widget);
8059 * gtk_widget_is_composited:
8060 * @widget: a #GtkWidget
8062 * Whether @widget can rely on having its alpha channel
8063 * drawn correctly. On X11 this function returns whether a
8064 * compositing manager is running for @widget's screen.
8066 * Please note that the semantics of this call will change
8067 * in the future if used on a widget that has a composited
8068 * window in its hierarchy (as set by gdk_window_set_composited()).
8070 * Return value: %TRUE if the widget can rely on its alpha
8071 * channel being drawn correctly.
8076 gtk_widget_is_composited (GtkWidget *widget)
8080 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8082 screen = gtk_widget_get_screen (widget);
8084 return gdk_screen_is_composited (screen);
8088 propagate_composited_changed (GtkWidget *widget,
8091 if (GTK_IS_CONTAINER (widget))
8093 gtk_container_forall (GTK_CONTAINER (widget),
8094 propagate_composited_changed,
8098 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8102 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8104 propagate_composited_changed (widget, NULL);
8108 * _gtk_widget_propagate_screen_changed:
8109 * @widget: a #GtkWidget
8110 * @previous_screen: Previous screen
8112 * Propagates changes in the screen for a widget to all
8113 * children, emitting #GtkWidget::screen-changed.
8116 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8117 GdkScreen *previous_screen)
8119 HierarchyChangedInfo info;
8121 info.previous_screen = previous_screen;
8122 info.new_screen = gtk_widget_get_screen (widget);
8124 if (previous_screen)
8125 g_object_ref (previous_screen);
8127 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8129 if (previous_screen)
8130 g_object_unref (previous_screen);
8134 reset_style_recurse (GtkWidget *widget, gpointer data)
8137 if (widget->priv->rc_style)
8138 gtk_widget_reset_rc_style (widget);
8141 if (widget->priv->context)
8143 _gtk_widget_update_path (widget);
8144 gtk_style_context_set_path (widget->priv->context,
8145 widget->priv->path);
8148 if (GTK_IS_CONTAINER (widget))
8149 gtk_container_forall (GTK_CONTAINER (widget),
8150 reset_style_recurse,
8155 gtk_widget_reset_style (GtkWidget *widget)
8157 g_return_if_fail (GTK_IS_WIDGET (widget));
8159 reset_style_recurse (widget, NULL);
8163 * gtk_widget_reset_rc_styles:
8164 * @widget: a #GtkWidget.
8166 * Reset the styles of @widget and all descendents, so when
8167 * they are looked up again, they get the correct values
8168 * for the currently loaded RC file settings.
8170 * This function is not useful for applications.
8173 gtk_widget_reset_rc_styles (GtkWidget *widget)
8175 g_return_if_fail (GTK_IS_WIDGET (widget));
8177 reset_style_recurse (widget, NULL);
8181 * gtk_widget_get_default_style:
8183 * Returns the default style used by all widgets initially.
8185 * Returns: (transfer none): the default style. This #GtkStyle object is owned
8186 * by GTK+ and should not be modified or freed.
8189 gtk_widget_get_default_style (void)
8191 if (!gtk_default_style)
8193 gtk_default_style = gtk_style_new ();
8194 g_object_ref (gtk_default_style);
8197 return gtk_default_style;
8200 static PangoContext *
8201 gtk_widget_peek_pango_context (GtkWidget *widget)
8203 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8207 * gtk_widget_get_pango_context:
8208 * @widget: a #GtkWidget
8210 * Gets a #PangoContext with the appropriate font map, font description,
8211 * and base direction for this widget. Unlike the context returned
8212 * by gtk_widget_create_pango_context(), this context is owned by
8213 * the widget (it can be used until the screen for the widget changes
8214 * or the widget is removed from its toplevel), and will be updated to
8215 * match any changes to the widget's attributes.
8217 * If you create and keep a #PangoLayout using this context, you must
8218 * deal with changes to the context by calling pango_layout_context_changed()
8219 * on the layout in response to the #GtkWidget::style-set and
8220 * #GtkWidget::direction-changed signals for the widget.
8222 * Return value: (transfer none): the #PangoContext for the widget.
8225 gtk_widget_get_pango_context (GtkWidget *widget)
8227 PangoContext *context;
8229 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8231 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8234 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8235 g_object_set_qdata_full (G_OBJECT (widget),
8236 quark_pango_context,
8245 update_pango_context (GtkWidget *widget,
8246 PangoContext *context)
8248 GtkWidgetPrivate *priv = widget->priv;
8250 pango_context_set_font_description (context, priv->style->font_desc);
8251 pango_context_set_base_dir (context,
8252 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8253 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8257 gtk_widget_update_pango_context (GtkWidget *widget)
8259 PangoContext *context = gtk_widget_peek_pango_context (widget);
8265 update_pango_context (widget, context);
8267 screen = gtk_widget_get_screen_unchecked (widget);
8270 pango_cairo_context_set_resolution (context,
8271 gdk_screen_get_resolution (screen));
8272 pango_cairo_context_set_font_options (context,
8273 gdk_screen_get_font_options (screen));
8279 * gtk_widget_create_pango_context:
8280 * @widget: a #GtkWidget
8282 * Creates a new #PangoContext with the appropriate font map,
8283 * font description, and base direction for drawing text for
8284 * this widget. See also gtk_widget_get_pango_context().
8286 * Return value: (transfer full): the new #PangoContext
8289 gtk_widget_create_pango_context (GtkWidget *widget)
8292 PangoContext *context;
8294 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8296 screen = gtk_widget_get_screen_unchecked (widget);
8299 GTK_NOTE (MULTIHEAD,
8300 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8302 screen = gdk_screen_get_default ();
8305 context = gdk_pango_context_get_for_screen (screen);
8307 update_pango_context (widget, context);
8308 pango_context_set_language (context, gtk_get_default_language ());
8314 * gtk_widget_create_pango_layout:
8315 * @widget: a #GtkWidget
8316 * @text: text to set on the layout (can be %NULL)
8318 * Creates a new #PangoLayout with the appropriate font map,
8319 * font description, and base direction for drawing text for
8322 * If you keep a #PangoLayout created in this way around, in order to
8323 * notify the layout of changes to the base direction or font of this
8324 * widget, you must call pango_layout_context_changed() in response to
8325 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
8328 * Return value: (transfer full): the new #PangoLayout
8331 gtk_widget_create_pango_layout (GtkWidget *widget,
8334 PangoLayout *layout;
8335 PangoContext *context;
8337 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8339 context = gtk_widget_get_pango_context (widget);
8340 layout = pango_layout_new (context);
8343 pango_layout_set_text (layout, text, -1);
8349 * gtk_widget_render_icon:
8350 * @widget: a #GtkWidget
8351 * @stock_id: a stock ID
8352 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8353 * render at the size of the source and don't scale (if there are
8354 * multiple source sizes, GTK+ picks one of the available sizes).
8355 * @detail: (allow-none): render detail to pass to theme engine
8357 * A convenience function that uses the theme engine and RC file
8358 * settings for @widget to look up @stock_id and render it to
8359 * a pixbuf. @stock_id should be a stock icon ID such as
8360 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8361 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
8362 * identifies the widget or code doing the rendering, so that
8363 * theme engines can special-case rendering for that widget or code.
8365 * The pixels in the returned #GdkPixbuf are shared with the rest of
8366 * the application and should not be modified. The pixbuf should be freed
8367 * after use with g_object_unref().
8369 * Return value: (transfer full): a new pixbuf, or %NULL if the
8370 * stock ID wasn't known
8373 gtk_widget_render_icon (GtkWidget *widget,
8374 const gchar *stock_id,
8376 const gchar *detail)
8378 GtkWidgetPrivate *priv;
8379 GtkIconSet *icon_set;
8382 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8383 g_return_val_if_fail (stock_id != NULL, NULL);
8384 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8386 priv = widget->priv;
8388 gtk_widget_ensure_style (widget);
8390 icon_set = gtk_style_lookup_icon_set (priv->style, stock_id);
8392 if (icon_set == NULL)
8395 retval = gtk_icon_set_render_icon (icon_set,
8397 gtk_widget_get_direction (widget),
8398 gtk_widget_get_state (widget),
8407 * gtk_widget_set_parent_window:
8408 * @widget: a #GtkWidget.
8409 * @parent_window: the new parent window.
8411 * Sets a non default parent window for @widget.
8414 gtk_widget_set_parent_window (GtkWidget *widget,
8415 GdkWindow *parent_window)
8417 GdkWindow *old_parent_window;
8419 g_return_if_fail (GTK_IS_WIDGET (widget));
8421 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8422 quark_parent_window);
8424 if (parent_window != old_parent_window)
8426 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8428 if (old_parent_window)
8429 g_object_unref (old_parent_window);
8431 g_object_ref (parent_window);
8436 * gtk_widget_get_parent_window:
8437 * @widget: a #GtkWidget.
8439 * Gets @widget's parent window.
8441 * Returns: (transfer none): the parent window of @widget.
8444 gtk_widget_get_parent_window (GtkWidget *widget)
8446 GtkWidgetPrivate *priv;
8447 GdkWindow *parent_window;
8449 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8451 priv = widget->priv;
8453 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8455 return (parent_window != NULL) ? parent_window :
8456 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8461 * gtk_widget_set_child_visible:
8462 * @widget: a #GtkWidget
8463 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8465 * Sets whether @widget should be mapped along with its when its parent
8466 * is mapped and @widget has been shown with gtk_widget_show().
8468 * The child visibility can be set for widget before it is added to
8469 * a container with gtk_widget_set_parent(), to avoid mapping
8470 * children unnecessary before immediately unmapping them. However
8471 * it will be reset to its default state of %TRUE when the widget
8472 * is removed from a container.
8474 * Note that changing the child visibility of a widget does not
8475 * queue a resize on the widget. Most of the time, the size of
8476 * a widget is computed from all visible children, whether or
8477 * not they are mapped. If this is not the case, the container
8478 * can queue a resize itself.
8480 * This function is only useful for container implementations and
8481 * never should be called by an application.
8484 gtk_widget_set_child_visible (GtkWidget *widget,
8485 gboolean is_visible)
8487 GtkWidgetPrivate *priv;
8489 g_return_if_fail (GTK_IS_WIDGET (widget));
8490 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8492 priv = widget->priv;
8494 g_object_ref (widget);
8497 priv->child_visible = TRUE;
8500 GtkWidget *toplevel;
8502 priv->child_visible = FALSE;
8504 toplevel = gtk_widget_get_toplevel (widget);
8505 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8506 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8509 if (priv->parent && gtk_widget_get_realized (priv->parent))
8511 if (gtk_widget_get_mapped (priv->parent) &&
8512 priv->child_visible &&
8513 gtk_widget_get_visible (widget))
8514 gtk_widget_map (widget);
8516 gtk_widget_unmap (widget);
8519 g_object_unref (widget);
8523 * gtk_widget_get_child_visible:
8524 * @widget: a #GtkWidget
8526 * Gets the value set with gtk_widget_set_child_visible().
8527 * If you feel a need to use this function, your code probably
8528 * needs reorganization.
8530 * This function is only useful for container implementations and
8531 * never should be called by an application.
8533 * Return value: %TRUE if the widget is mapped with the parent.
8536 gtk_widget_get_child_visible (GtkWidget *widget)
8538 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8540 return widget->priv->child_visible;
8544 gtk_widget_get_screen_unchecked (GtkWidget *widget)
8546 GtkWidget *toplevel;
8548 toplevel = gtk_widget_get_toplevel (widget);
8550 if (gtk_widget_is_toplevel (toplevel))
8552 if (GTK_IS_WINDOW (toplevel))
8553 return gtk_window_get_screen (GTK_WINDOW (toplevel));
8554 else if (GTK_IS_INVISIBLE (toplevel))
8555 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
8562 * gtk_widget_get_screen:
8563 * @widget: a #GtkWidget
8565 * Get the #GdkScreen from the toplevel window associated with
8566 * this widget. This function can only be called after the widget
8567 * has been added to a widget hierarchy with a #GtkWindow
8570 * In general, you should only create screen specific
8571 * resources when a widget has been realized, and you should
8572 * free those resources when the widget is unrealized.
8574 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
8579 gtk_widget_get_screen (GtkWidget *widget)
8583 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8585 screen = gtk_widget_get_screen_unchecked (widget);
8592 g_warning (G_STRLOC ": Can't get associated screen"
8593 " for a widget unless it is inside a toplevel GtkWindow\n"
8594 " widget type is %s associated top level type is %s",
8595 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
8596 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
8598 return gdk_screen_get_default ();
8603 * gtk_widget_has_screen:
8604 * @widget: a #GtkWidget
8606 * Checks whether there is a #GdkScreen is associated with
8607 * this widget. All toplevel widgets have an associated
8608 * screen, and all widgets added into a hierarchy with a toplevel
8609 * window at the top.
8611 * Return value: %TRUE if there is a #GdkScreen associcated
8617 gtk_widget_has_screen (GtkWidget *widget)
8619 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8621 return (gtk_widget_get_screen_unchecked (widget) != NULL);
8625 * gtk_widget_get_display:
8626 * @widget: a #GtkWidget
8628 * Get the #GdkDisplay for the toplevel window associated with
8629 * this widget. This function can only be called after the widget
8630 * has been added to a widget hierarchy with a #GtkWindow at the top.
8632 * In general, you should only create display specific
8633 * resources when a widget has been realized, and you should
8634 * free those resources when the widget is unrealized.
8636 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
8641 gtk_widget_get_display (GtkWidget *widget)
8643 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8645 return gdk_screen_get_display (gtk_widget_get_screen (widget));
8649 * gtk_widget_get_root_window:
8650 * @widget: a #GtkWidget
8652 * Get the root window where this widget is located. This function can
8653 * only be called after the widget has been added to a widget
8654 * hierarchy with #GtkWindow at the top.
8656 * The root window is useful for such purposes as creating a popup
8657 * #GdkWindow associated with the window. In general, you should only
8658 * create display specific resources when a widget has been realized,
8659 * and you should free those resources when the widget is unrealized.
8661 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
8666 gtk_widget_get_root_window (GtkWidget *widget)
8668 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8670 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
8674 * gtk_widget_child_focus:
8675 * @widget: a #GtkWidget
8676 * @direction: direction of focus movement
8678 * This function is used by custom widget implementations; if you're
8679 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
8680 * to a particular widget, and gtk_container_set_focus_chain() to
8681 * change the focus tab order. So you may want to investigate those
8682 * functions instead.
8684 * gtk_widget_child_focus() is called by containers as the user moves
8685 * around the window using keyboard shortcuts. @direction indicates
8686 * what kind of motion is taking place (up, down, left, right, tab
8687 * forward, tab backward). gtk_widget_child_focus() emits the
8688 * #GtkWidget::focus signal; widgets override the default handler
8689 * for this signal in order to implement appropriate focus behavior.
8691 * The default ::focus handler for a widget should return %TRUE if
8692 * moving in @direction left the focus on a focusable location inside
8693 * that widget, and %FALSE if moving in @direction moved the focus
8694 * outside the widget. If returning %TRUE, widgets normally
8695 * call gtk_widget_grab_focus() to place the focus accordingly;
8696 * if returning %FALSE, they don't modify the current focus location.
8698 * Return value: %TRUE if focus ended up inside @widget
8701 gtk_widget_child_focus (GtkWidget *widget,
8702 GtkDirectionType direction)
8704 gboolean return_val;
8706 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8708 if (!gtk_widget_get_visible (widget) ||
8709 !gtk_widget_is_sensitive (widget))
8712 /* child widgets must set CAN_FOCUS, containers
8713 * don't have to though.
8715 if (!GTK_IS_CONTAINER (widget) &&
8716 !gtk_widget_get_can_focus (widget))
8719 g_signal_emit (widget,
8720 widget_signals[FOCUS],
8722 direction, &return_val);
8728 * gtk_widget_keynav_failed:
8729 * @widget: a #GtkWidget
8730 * @direction: direction of focus movement
8732 * This function should be called whenever keyboard navigation within
8733 * a single widget hits a boundary. The function emits the
8734 * #GtkWidget::keynav-failed signal on the widget and its return
8735 * value should be interpreted in a way similar to the return value of
8736 * gtk_widget_child_focus():
8738 * When %TRUE is returned, stay in the widget, the failed keyboard
8739 * navigation is Ok and/or there is nowhere we can/should move the
8742 * When %FALSE is returned, the caller should continue with keyboard
8743 * navigation outside the widget, e.g. by calling
8744 * gtk_widget_child_focus() on the widget's toplevel.
8746 * The default ::keynav-failed handler returns %TRUE for
8747 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
8748 * values of #GtkDirectionType, it looks at the
8749 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
8750 * if the setting is %TRUE. This way the entire user interface
8751 * becomes cursor-navigatable on input devices such as mobile phones
8752 * which only have cursor keys but no tab key.
8754 * Whenever the default handler returns %TRUE, it also calls
8755 * gtk_widget_error_bell() to notify the user of the failed keyboard
8758 * A use case for providing an own implementation of ::keynav-failed
8759 * (either by connecting to it or by overriding it) would be a row of
8760 * #GtkEntry widgets where the user should be able to navigate the
8761 * entire row with the cursor keys, as e.g. known from user interfaces
8762 * that require entering license keys.
8764 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
8765 * if the emitting widget should try to handle the keyboard
8766 * navigation attempt in its parent container(s).
8771 gtk_widget_keynav_failed (GtkWidget *widget,
8772 GtkDirectionType direction)
8774 gboolean return_val;
8776 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8778 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
8779 direction, &return_val);
8785 * gtk_widget_error_bell:
8786 * @widget: a #GtkWidget
8788 * Notifies the user about an input-related error on this widget.
8789 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
8790 * gdk_window_beep(), otherwise it does nothing.
8792 * Note that the effect of gdk_window_beep() can be configured in many
8793 * ways, depending on the windowing backend and the desktop environment
8794 * or window manager that is used.
8799 gtk_widget_error_bell (GtkWidget *widget)
8801 GtkWidgetPrivate *priv;
8802 GtkSettings* settings;
8805 g_return_if_fail (GTK_IS_WIDGET (widget));
8807 priv = widget->priv;
8809 settings = gtk_widget_get_settings (widget);
8813 g_object_get (settings,
8814 "gtk-error-bell", &beep,
8817 if (beep && priv->window)
8818 gdk_window_beep (priv->window);
8822 gtk_widget_set_usize_internal (GtkWidget *widget,
8825 GtkQueueResizeFlags flags)
8827 GtkWidgetAuxInfo *aux_info;
8828 gboolean changed = FALSE;
8830 g_object_freeze_notify (G_OBJECT (widget));
8832 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
8834 if (width > -2 && aux_info->width != width)
8836 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
8837 g_object_notify (G_OBJECT (widget), "width-request");
8838 aux_info->width = width;
8841 if (height > -2 && aux_info->height != height)
8843 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
8844 g_object_notify (G_OBJECT (widget), "height-request");
8845 aux_info->height = height;
8849 if (gtk_widget_get_visible (widget) && changed)
8851 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
8852 gtk_widget_queue_resize (widget);
8854 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
8857 g_object_thaw_notify (G_OBJECT (widget));
8861 * gtk_widget_set_size_request:
8862 * @widget: a #GtkWidget
8863 * @width: width @widget should request, or -1 to unset
8864 * @height: height @widget should request, or -1 to unset
8866 * Sets the minimum size of a widget; that is, the widget's size
8867 * request will be @width by @height. You can use this function to
8868 * force a widget to be either larger or smaller than it normally
8871 * In most cases, gtk_window_set_default_size() is a better choice for
8872 * toplevel windows than this function; setting the default size will
8873 * still allow users to shrink the window. Setting the size request
8874 * will force them to leave the window at least as large as the size
8875 * request. When dealing with window sizes,
8876 * gtk_window_set_geometry_hints() can be a useful function as well.
8878 * Note the inherent danger of setting any fixed size - themes,
8879 * translations into other languages, different fonts, and user action
8880 * can all change the appropriate size for a given widget. So, it's
8881 * basically impossible to hardcode a size that will always be
8884 * The size request of a widget is the smallest size a widget can
8885 * accept while still functioning well and drawing itself correctly.
8886 * However in some strange cases a widget may be allocated less than
8887 * its requested size, and in many cases a widget may be allocated more
8888 * space than it requested.
8890 * If the size request in a given direction is -1 (unset), then
8891 * the "natural" size request of the widget will be used instead.
8893 * Widgets can't actually be allocated a size less than 1 by 1, but
8894 * you can pass 0,0 to this function to mean "as small as possible."
8896 * The size request set here does not include any margin from the
8897 * #GtkWidget properties margin-left, margin-right, margin-top, and
8898 * margin-bottom, but it does include pretty much all other padding
8899 * or border properties set by any subclass of #GtkWidget.
8902 gtk_widget_set_size_request (GtkWidget *widget,
8906 g_return_if_fail (GTK_IS_WIDGET (widget));
8907 g_return_if_fail (width >= -1);
8908 g_return_if_fail (height >= -1);
8915 gtk_widget_set_usize_internal (widget, width, height, 0);
8920 * gtk_widget_get_size_request:
8921 * @widget: a #GtkWidget
8922 * @width: (out) (allow-none): return location for width, or %NULL
8923 * @height: (out) (allow-none): return location for height, or %NULL
8925 * Gets the size request that was explicitly set for the widget using
8926 * gtk_widget_set_size_request(). A value of -1 stored in @width or
8927 * @height indicates that that dimension has not been set explicitly
8928 * and the natural requisition of the widget will be used intead. See
8929 * gtk_widget_set_size_request(). To get the size a widget will
8930 * actually request, call gtk_widget_get_preferred_size() instead of
8934 gtk_widget_get_size_request (GtkWidget *widget,
8938 const GtkWidgetAuxInfo *aux_info;
8940 g_return_if_fail (GTK_IS_WIDGET (widget));
8942 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
8945 *width = aux_info->width;
8948 *height = aux_info->height;
8952 * _gtk_widget_override_size_request:
8953 * @widget: a #GtkWidget
8954 * @width: new forced minimum width
8955 * @height: new forced minimum height
8956 * @old_width: location to store previous forced minimum width
8957 * @old_width: location to store previous forced minumum height
8959 * Temporarily establishes a forced minimum size for a widget; this
8960 * is used by GtkWindow when calculating the size to add to the
8961 * window's geometry widget. Cached sizes for the widget and its
8962 * parents are invalidated, so that subsequent calls to the size
8963 * negotiation machinery produce the overriden result, but the
8964 * widget is not queued for relayout or redraw. The old size must
8965 * be restored with _gtk_widget_restore_size_request() or things
8969 _gtk_widget_override_size_request (GtkWidget *widget,
8975 gtk_widget_get_size_request (widget, old_width, old_height);
8976 gtk_widget_set_usize_internal (widget, width, height,
8977 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
8981 * _gtk_widget_restore_size_request:
8982 * @widget: a #GtkWidget
8983 * @old_width: saved forced minimum size
8984 * @old_height: saved forced minimum size
8986 * Undoes the operation of_gtk_widget_override_size_request().
8989 _gtk_widget_restore_size_request (GtkWidget *widget,
8993 gtk_widget_set_usize_internal (widget, old_width, old_height,
8994 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
8998 * gtk_widget_set_events:
8999 * @widget: a #GtkWidget
9000 * @events: event mask
9002 * Sets the event mask (see #GdkEventMask) for a widget. The event
9003 * mask determines which events a widget will receive. Keep in mind
9004 * that different widgets have different default event masks, and by
9005 * changing the event mask you may disrupt a widget's functionality,
9006 * so be careful. This function must be called while a widget is
9007 * unrealized. Consider gtk_widget_add_events() for widgets that are
9008 * already realized, or if you want to preserve the existing event
9009 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9010 * to get events on those widgets, place them inside a #GtkEventBox
9011 * and receive events on the event box.
9014 gtk_widget_set_events (GtkWidget *widget,
9017 g_return_if_fail (GTK_IS_WIDGET (widget));
9018 g_return_if_fail (!gtk_widget_get_realized (widget));
9020 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9021 GINT_TO_POINTER (events));
9022 g_object_notify (G_OBJECT (widget), "events");
9026 * gtk_widget_set_device_events:
9027 * @widget: a #GtkWidget
9028 * @device: a #GdkDevice
9029 * @events: event mask
9031 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9032 * mask determines which events a widget will receive from @device. Keep
9033 * in mind that different widgets have different default event masks, and by
9034 * changing the event mask you may disrupt a widget's functionality,
9035 * so be careful. This function must be called while a widget is
9036 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9037 * already realized, or if you want to preserve the existing event
9038 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9039 * to get events on those widgets, place them inside a #GtkEventBox
9040 * and receive events on the event box.
9045 gtk_widget_set_device_events (GtkWidget *widget,
9047 GdkEventMask events)
9049 GHashTable *device_events;
9051 g_return_if_fail (GTK_IS_WIDGET (widget));
9052 g_return_if_fail (GDK_IS_DEVICE (device));
9053 g_return_if_fail (!gtk_widget_get_realized (widget));
9055 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9057 if (G_UNLIKELY (!device_events))
9059 device_events = g_hash_table_new (NULL, NULL);
9060 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9061 (GDestroyNotify) g_hash_table_unref);
9064 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9068 gtk_widget_add_events_internal_list (GtkWidget *widget,
9075 for (l = window_list; l != NULL; l = l->next)
9077 GdkWindow *window = l->data;
9080 gdk_window_get_user_data (window, &user_data);
9081 if (user_data == widget)
9086 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9088 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9090 children = gdk_window_get_children (window);
9091 gtk_widget_add_events_internal_list (widget, device, events, children);
9092 g_list_free (children);
9098 gtk_widget_add_events_internal (GtkWidget *widget,
9102 GtkWidgetPrivate *priv = widget->priv;
9105 if (!gtk_widget_get_has_window (widget))
9106 window_list = gdk_window_get_children (priv->window);
9108 window_list = g_list_prepend (NULL, priv->window);
9110 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9112 g_list_free (window_list);
9116 * gtk_widget_add_events:
9117 * @widget: a #GtkWidget
9118 * @events: an event mask, see #GdkEventMask
9120 * Adds the events in the bitfield @events to the event mask for
9121 * @widget. See gtk_widget_set_events() for details.
9124 gtk_widget_add_events (GtkWidget *widget,
9129 g_return_if_fail (GTK_IS_WIDGET (widget));
9131 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9132 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9133 GINT_TO_POINTER (old_events | events));
9135 if (gtk_widget_get_realized (widget))
9136 gtk_widget_add_events_internal (widget, NULL, events);
9138 g_object_notify (G_OBJECT (widget), "events");
9142 * gtk_widget_add_device_events:
9143 * @widget: a #GtkWidget
9144 * @device: a #GdkDevice
9145 * @events: an event mask, see #GdkEventMask
9147 * Adds the device events in the bitfield @events to the event mask for
9148 * @widget. See gtk_widget_set_device_events() for details.
9153 gtk_widget_add_device_events (GtkWidget *widget,
9155 GdkEventMask events)
9157 GdkEventMask old_events;
9158 GHashTable *device_events;
9160 g_return_if_fail (GTK_IS_WIDGET (widget));
9161 g_return_if_fail (GDK_IS_DEVICE (device));
9163 old_events = gtk_widget_get_device_events (widget, device);
9165 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9167 if (G_UNLIKELY (!device_events))
9169 device_events = g_hash_table_new (NULL, NULL);
9170 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9171 (GDestroyNotify) g_hash_table_unref);
9174 g_hash_table_insert (device_events, device,
9175 GUINT_TO_POINTER (old_events | events));
9177 if (gtk_widget_get_realized (widget))
9178 gtk_widget_add_events_internal (widget, device, events);
9180 g_object_notify (G_OBJECT (widget), "events");
9184 * gtk_widget_set_extension_events:
9185 * @widget: a #GtkWidget
9186 * @mode: bitfield of extension events to receive
9188 * Sets the extension events mask to @mode. See #GdkExtensionMode
9189 * and gdk_input_set_extension_events().
9192 gtk_widget_set_extension_events (GtkWidget *widget,
9193 GdkExtensionMode mode)
9195 g_return_if_fail (GTK_IS_WIDGET (widget));
9197 if (gtk_widget_get_realized (widget))
9198 gtk_widget_set_extension_events_internal (widget, mode, NULL);
9200 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
9201 GINT_TO_POINTER (mode));
9202 g_object_notify (G_OBJECT (widget), "extension-events");
9206 * gtk_widget_get_toplevel:
9207 * @widget: a #GtkWidget
9209 * This function returns the topmost widget in the container hierarchy
9210 * @widget is a part of. If @widget has no parent widgets, it will be
9211 * returned as the topmost widget. No reference will be added to the
9212 * returned widget; it should not be unreferenced.
9214 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9215 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9217 * %NULL if @widget wasn't inside a toplevel window, and if the
9218 * window was inside a #GtkWindow-derived widget which was in turn
9219 * inside the toplevel #GtkWindow. While the second case may
9220 * seem unlikely, it actually happens when a #GtkPlug is embedded
9221 * inside a #GtkSocket within the same application.
9223 * To reliably find the toplevel #GtkWindow, use
9224 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9225 * is set on the result.
9227 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9228 * if (gtk_widget_is_toplevel (toplevel))
9230 * /* Perform action on toplevel. */
9234 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9235 * if there's no ancestor.
9238 gtk_widget_get_toplevel (GtkWidget *widget)
9240 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9242 while (widget->priv->parent)
9243 widget = widget->priv->parent;
9249 * gtk_widget_get_ancestor:
9250 * @widget: a #GtkWidget
9251 * @widget_type: ancestor type
9253 * Gets the first ancestor of @widget with type @widget_type. For example,
9254 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9255 * the first #GtkBox that's an ancestor of @widget. No reference will be
9256 * added to the returned widget; it should not be unreferenced. See note
9257 * about checking for a toplevel #GtkWindow in the docs for
9258 * gtk_widget_get_toplevel().
9260 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9261 * considers @widget to be an ancestor of itself.
9263 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9266 gtk_widget_get_ancestor (GtkWidget *widget,
9269 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9271 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9272 widget = widget->priv->parent;
9274 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9281 * gtk_widget_set_visual:
9282 * @widget: a #GtkWidget
9283 * @visual: visual to be used or %NULL to unset a previous one
9285 * Sets the visual that should be used for by widget and its children for
9286 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9287 * returned by gdk_widget_get_screen(), so handling the
9288 * #GtkWidget::screen-changed signal is necessary.
9290 * Setting a new @visual will not cause @widget to recreate its windows,
9291 * so you should call this function before @widget is realized.
9294 gtk_widget_set_visual (GtkWidget *widget,
9297 g_return_if_fail (GTK_IS_WIDGET (widget));
9298 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9301 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9304 g_object_set_qdata_full (G_OBJECT (widget),
9306 g_object_ref (visual),
9311 * gtk_widget_get_visual:
9312 * @widget: a #GtkWidget
9314 * Gets the visual that will be used to render @widget.
9316 * Return value: (transfer none): the visual for @widget
9319 gtk_widget_get_visual (GtkWidget *widget)
9325 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9327 if (gtk_widget_get_has_window (widget) &&
9328 widget->priv->window)
9329 return gdk_window_get_visual (widget->priv->window);
9331 screen = gtk_widget_get_screen (widget);
9333 for (w = widget; w != NULL; w = w->priv->parent)
9335 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9338 if (gdk_visual_get_screen (visual) == screen)
9341 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9342 gtk_widget_get_name (widget));
9346 return gdk_screen_get_system_visual (screen);
9350 * gtk_widget_get_settings:
9351 * @widget: a #GtkWidget
9353 * Gets the settings object holding the settings (global property
9354 * settings, RC file information, etc) used for this widget.
9356 * Note that this function can only be called when the #GtkWidget
9357 * is attached to a toplevel, since the settings object is specific
9358 * to a particular #GdkScreen.
9360 * Return value: (transfer none): the relevant #GtkSettings object
9363 gtk_widget_get_settings (GtkWidget *widget)
9365 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9367 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9371 * gtk_widget_get_events:
9372 * @widget: a #GtkWidget
9374 * Returns the event mask for the widget (a bitfield containing flags
9375 * from the #GdkEventMask enumeration). These are the events that the widget
9378 * Return value: event mask for @widget
9381 gtk_widget_get_events (GtkWidget *widget)
9383 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9385 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9389 * gtk_widget_get_device_events:
9390 * @widget: a #GtkWidget
9391 * @device: a #GdkDevice
9393 * Returns the events mask for the widget corresponding to an specific device. These
9394 * are the events that the widget will receive when @device operates on it.
9396 * Returns: device event mask for @widget
9401 gtk_widget_get_device_events (GtkWidget *widget,
9404 GHashTable *device_events;
9406 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9407 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9409 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9414 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9418 * gtk_widget_get_extension_events:
9419 * @widget: a #GtkWidget
9421 * Retrieves the extension events the widget will receive; see
9422 * gdk_input_set_extension_events().
9424 * Return value: extension events for @widget
9427 gtk_widget_get_extension_events (GtkWidget *widget)
9429 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9431 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
9435 * gtk_widget_get_pointer:
9436 * @widget: a #GtkWidget
9437 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9438 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9440 * Obtains the location of the mouse pointer in widget coordinates.
9441 * Widget coordinates are a bit odd; for historical reasons, they are
9442 * defined as @widget->window coordinates for widgets that are not
9443 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9444 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9447 gtk_widget_get_pointer (GtkWidget *widget,
9451 GtkWidgetPrivate *priv;
9453 g_return_if_fail (GTK_IS_WIDGET (widget));
9455 priv = widget->priv;
9462 if (gtk_widget_get_realized (widget))
9464 gdk_window_get_pointer (priv->window, x, y, NULL);
9466 if (!gtk_widget_get_has_window (widget))
9469 *x -= priv->allocation.x;
9471 *y -= priv->allocation.y;
9477 * gtk_widget_is_ancestor:
9478 * @widget: a #GtkWidget
9479 * @ancestor: another #GtkWidget
9481 * Determines whether @widget is somewhere inside @ancestor, possibly with
9482 * intermediate containers.
9484 * Return value: %TRUE if @ancestor contains @widget as a child,
9485 * grandchild, great grandchild, etc.
9488 gtk_widget_is_ancestor (GtkWidget *widget,
9489 GtkWidget *ancestor)
9491 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9492 g_return_val_if_fail (ancestor != NULL, FALSE);
9496 if (widget->priv->parent == ancestor)
9498 widget = widget->priv->parent;
9504 static GQuark quark_composite_name = 0;
9507 * gtk_widget_set_composite_name:
9508 * @widget: a #GtkWidget.
9509 * @name: the name to set
9511 * Sets a widgets composite name. The widget must be
9512 * a composite child of its parent; see gtk_widget_push_composite_child().
9515 gtk_widget_set_composite_name (GtkWidget *widget,
9518 g_return_if_fail (GTK_IS_WIDGET (widget));
9519 g_return_if_fail (widget->priv->composite_child);
9520 g_return_if_fail (name != NULL);
9522 if (!quark_composite_name)
9523 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
9525 g_object_set_qdata_full (G_OBJECT (widget),
9526 quark_composite_name,
9532 * gtk_widget_get_composite_name:
9533 * @widget: a #GtkWidget
9535 * Obtains the composite name of a widget.
9537 * Returns: the composite name of @widget, or %NULL if @widget is not
9538 * a composite child. The string should be freed when it is no
9542 gtk_widget_get_composite_name (GtkWidget *widget)
9544 GtkWidgetPrivate *priv;
9546 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9548 priv = widget->priv;
9550 if (widget->priv->composite_child && priv->parent)
9551 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
9558 * gtk_widget_push_composite_child:
9560 * Makes all newly-created widgets as composite children until
9561 * the corresponding gtk_widget_pop_composite_child() call.
9563 * A composite child is a child that's an implementation detail of the
9564 * container it's inside and should not be visible to people using the
9565 * container. Composite children aren't treated differently by GTK (but
9566 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
9567 * builders might want to treat them in a different way.
9569 * Here is a simple example:
9571 * gtk_widget_push_composite_child ();
9572 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
9573 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
9574 * gtk_widget_pop_composite_child ();
9575 * gtk_widget_set_parent (scrolled_window->hscrollbar,
9576 * GTK_WIDGET (scrolled_window));
9577 * g_object_ref (scrolled_window->hscrollbar);
9581 gtk_widget_push_composite_child (void)
9583 composite_child_stack++;
9587 * gtk_widget_pop_composite_child:
9589 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
9592 gtk_widget_pop_composite_child (void)
9594 if (composite_child_stack)
9595 composite_child_stack--;
9599 gtk_widget_emit_direction_changed (GtkWidget *widget,
9600 GtkTextDirection old_dir)
9602 gtk_widget_update_pango_context (widget);
9604 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
9608 * gtk_widget_set_direction:
9609 * @widget: a #GtkWidget
9610 * @dir: the new direction
9612 * Sets the reading direction on a particular widget. This direction
9613 * controls the primary direction for widgets containing text,
9614 * and also the direction in which the children of a container are
9615 * packed. The ability to set the direction is present in order
9616 * so that correct localization into languages with right-to-left
9617 * reading directions can be done. Generally, applications will
9618 * let the default reading direction present, except for containers
9619 * where the containers are arranged in an order that is explicitely
9620 * visual rather than logical (such as buttons for text justification).
9622 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
9623 * set by gtk_widget_set_default_direction() will be used.
9626 gtk_widget_set_direction (GtkWidget *widget,
9627 GtkTextDirection dir)
9629 GtkTextDirection old_dir;
9631 g_return_if_fail (GTK_IS_WIDGET (widget));
9632 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
9634 old_dir = gtk_widget_get_direction (widget);
9636 widget->priv->direction = dir;
9638 if (old_dir != gtk_widget_get_direction (widget))
9640 if (widget->priv->context)
9641 gtk_style_context_set_direction (widget->priv->context,
9642 gtk_widget_get_direction (widget));
9644 gtk_widget_emit_direction_changed (widget, old_dir);
9649 * gtk_widget_get_direction:
9650 * @widget: a #GtkWidget
9652 * Gets the reading direction for a particular widget. See
9653 * gtk_widget_set_direction().
9655 * Return value: the reading direction for the widget.
9658 gtk_widget_get_direction (GtkWidget *widget)
9660 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
9662 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
9663 return gtk_default_direction;
9665 return widget->priv->direction;
9669 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
9671 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
9673 g_object_ref (widget);
9675 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
9676 gtk_widget_emit_direction_changed (widget, old_dir);
9678 if (GTK_IS_CONTAINER (widget))
9679 gtk_container_forall (GTK_CONTAINER (widget),
9680 gtk_widget_set_default_direction_recurse,
9683 g_object_unref (widget);
9687 * gtk_widget_set_default_direction:
9688 * @dir: the new default direction. This cannot be
9689 * %GTK_TEXT_DIR_NONE.
9691 * Sets the default reading direction for widgets where the
9692 * direction has not been explicitly set by gtk_widget_set_direction().
9695 gtk_widget_set_default_direction (GtkTextDirection dir)
9697 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
9699 if (dir != gtk_default_direction)
9701 GList *toplevels, *tmp_list;
9702 GtkTextDirection old_dir = gtk_default_direction;
9704 gtk_default_direction = dir;
9706 tmp_list = toplevels = gtk_window_list_toplevels ();
9707 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
9711 gtk_widget_set_default_direction_recurse (tmp_list->data,
9712 GUINT_TO_POINTER (old_dir));
9713 g_object_unref (tmp_list->data);
9714 tmp_list = tmp_list->next;
9717 g_list_free (toplevels);
9722 * gtk_widget_get_default_direction:
9724 * Obtains the current default reading direction. See
9725 * gtk_widget_set_default_direction().
9727 * Return value: the current default direction.
9730 gtk_widget_get_default_direction (void)
9732 return gtk_default_direction;
9736 gtk_widget_dispose (GObject *object)
9738 GtkWidget *widget = GTK_WIDGET (object);
9739 GtkWidgetPrivate *priv = widget->priv;
9742 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
9743 else if (gtk_widget_get_visible (widget))
9744 gtk_widget_hide (widget);
9746 priv->visible = FALSE;
9747 if (gtk_widget_get_realized (widget))
9748 gtk_widget_unrealize (widget);
9750 if (!priv->in_destruction)
9752 priv->in_destruction = TRUE;
9753 g_signal_emit (object, widget_signals[DESTROY], 0);
9754 priv->in_destruction = FALSE;
9757 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
9761 gtk_widget_real_destroy (GtkWidget *object)
9763 /* gtk_object_destroy() will already hold a refcount on object */
9764 GtkWidget *widget = GTK_WIDGET (object);
9765 GtkWidgetPrivate *priv = widget->priv;
9767 /* wipe accelerator closures (keep order) */
9768 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
9769 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
9771 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
9772 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
9774 gtk_grab_remove (widget);
9776 g_object_unref (priv->style);
9777 priv->style = gtk_widget_get_default_style ();
9778 g_object_ref (priv->style);
9782 gtk_widget_finalize (GObject *object)
9784 GtkWidget *widget = GTK_WIDGET (object);
9785 GtkWidgetPrivate *priv = widget->priv;
9786 GtkWidgetAuxInfo *aux_info;
9787 GtkAccessible *accessible;
9789 gtk_grab_remove (widget);
9791 g_object_unref (priv->style);
9794 g_free (priv->name);
9796 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
9798 gtk_widget_aux_info_destroy (aux_info);
9800 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
9802 g_object_unref (accessible);
9805 gtk_widget_path_free (priv->path);
9808 g_object_unref (priv->context);
9810 if (g_object_is_floating (object))
9811 g_warning ("A floating object was finalized. This means that someone\n"
9812 "called g_object_unref() on an object that had only a floating\n"
9813 "reference; the initial floating reference is not owned by anyone\n"
9814 "and must be removed with g_object_ref_sink().");
9816 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
9819 /*****************************************
9820 * gtk_widget_real_map:
9825 *****************************************/
9828 gtk_widget_real_map (GtkWidget *widget)
9830 GtkWidgetPrivate *priv = widget->priv;
9832 g_assert (gtk_widget_get_realized (widget));
9834 if (!gtk_widget_get_mapped (widget))
9836 gtk_widget_set_mapped (widget, TRUE);
9838 if (gtk_widget_get_has_window (widget))
9839 gdk_window_show (priv->window);
9843 /*****************************************
9844 * gtk_widget_real_unmap:
9849 *****************************************/
9852 gtk_widget_real_unmap (GtkWidget *widget)
9854 GtkWidgetPrivate *priv = widget->priv;
9856 if (gtk_widget_get_mapped (widget))
9858 gtk_widget_set_mapped (widget, FALSE);
9860 if (gtk_widget_get_has_window (widget))
9861 gdk_window_hide (priv->window);
9865 /*****************************************
9866 * gtk_widget_real_realize:
9871 *****************************************/
9874 gtk_widget_real_realize (GtkWidget *widget)
9876 GtkWidgetPrivate *priv = widget->priv;
9878 g_assert (!gtk_widget_get_has_window (widget));
9880 gtk_widget_set_realized (widget, TRUE);
9883 priv->window = gtk_widget_get_parent_window (widget);
9884 g_object_ref (priv->window);
9886 priv->style = gtk_style_attach (priv->style, priv->window);
9889 /*****************************************
9890 * gtk_widget_real_unrealize:
9895 *****************************************/
9898 gtk_widget_real_unrealize (GtkWidget *widget)
9900 GtkWidgetPrivate *priv = widget->priv;
9902 if (gtk_widget_get_mapped (widget))
9903 gtk_widget_real_unmap (widget);
9905 gtk_widget_set_mapped (widget, FALSE);
9907 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
9910 /* We must do unrealize child widget BEFORE container widget.
9911 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
9912 * So, unrealizing container widget bofore its children causes the problem
9913 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
9916 if (GTK_IS_CONTAINER (widget))
9917 gtk_container_forall (GTK_CONTAINER (widget),
9918 (GtkCallback) gtk_widget_unrealize,
9921 gtk_style_detach (priv->style);
9922 if (gtk_widget_get_has_window (widget))
9924 gdk_window_set_user_data (priv->window, NULL);
9925 gdk_window_destroy (priv->window);
9926 priv->window = NULL;
9930 g_object_unref (priv->window);
9931 priv->window = NULL;
9934 gtk_selection_remove_all (widget);
9936 gtk_widget_set_realized (widget, FALSE);
9940 gtk_widget_real_adjust_size_request (GtkWidget *widget,
9941 GtkOrientation orientation,
9945 const GtkWidgetAuxInfo *aux_info;
9947 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
9949 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
9950 aux_info->width > 0)
9952 *minimum_size = MAX (*minimum_size, aux_info->width);
9954 else if (orientation == GTK_ORIENTATION_VERTICAL &&
9955 aux_info->height > 0)
9957 *minimum_size = MAX (*minimum_size, aux_info->height);
9960 /* Fix it if set_size_request made natural size smaller than min size.
9961 * This would also silently fix broken widgets, but we warn about them
9962 * in gtksizerequest.c when calling their size request vfuncs.
9964 *natural_size = MAX (*natural_size, *minimum_size);
9966 if (orientation == GTK_ORIENTATION_HORIZONTAL)
9968 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
9969 *natural_size += (aux_info->margin.left + aux_info->margin.right);
9973 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
9974 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
9979 * _gtk_widget_peek_request_cache:
9981 * Returns the address of the widget's request cache (strictly for
9982 * internal use in gtksizerequest.c)
9984 * Return value: the address of @widget's size request cache.
9987 _gtk_widget_peek_request_cache (GtkWidget *widget)
9989 /* Don't bother slowing things down with the return_if_fail guards here */
9990 return &widget->priv->requests;
9994 * _gtk_widget_set_device_window:
9995 * @widget: a #GtkWidget.
9996 * @device: a #GdkDevice.
9997 * @window: the new device window.
9999 * Sets pointer window for @widget and @device. Does not ref @window.
10000 * Actually stores it on the #GdkScreen, but you don't need to know that.
10003 _gtk_widget_set_device_window (GtkWidget *widget,
10007 GtkWidgetPrivate *priv;
10009 GHashTable *device_window;
10011 g_return_if_fail (GTK_IS_WIDGET (widget));
10012 g_return_if_fail (GDK_IS_DEVICE (device));
10013 g_return_if_fail (!window || GDK_IS_WINDOW (window));
10015 priv = widget->priv;
10017 if (!gtk_widget_get_realized (widget))
10020 screen = gdk_window_get_screen (priv->window);
10021 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10023 if (G_UNLIKELY (!device_window))
10025 device_window = g_hash_table_new (NULL, NULL);
10026 g_object_set_qdata_full (G_OBJECT (screen),
10027 quark_pointer_window,
10029 (GDestroyNotify) g_hash_table_destroy);
10033 g_hash_table_insert (device_window, device, window);
10035 g_hash_table_remove (device_window, device);
10039 * _gtk_widget_get_device_window:
10040 * @widget: a #GtkWidget.
10041 * @device: a #GdkDevice.
10043 * Return value: the device window set on the #GdkScreen @widget is attached
10047 _gtk_widget_get_device_window (GtkWidget *widget,
10050 GtkWidgetPrivate *priv;
10052 GHashTable *device_window;
10056 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10057 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10059 priv = widget->priv;
10061 if (!gtk_widget_get_realized (widget))
10064 screen = gdk_window_get_screen (priv->window);
10065 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10067 if (G_UNLIKELY (!device_window))
10070 window = g_hash_table_lookup (device_window, device);
10075 gdk_window_get_user_data (window, (gpointer *) &w);
10084 * _gtk_widget_list_devices:
10085 * @widget: a #GtkWidget.
10087 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
10088 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
10092 _gtk_widget_list_devices (GtkWidget *widget)
10094 GtkWidgetPrivate *priv;
10096 GHashTableIter iter;
10097 GHashTable *device_window;
10098 GList *devices = NULL;
10099 gpointer key, value;
10101 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10103 priv = widget->priv;
10105 if (!gtk_widget_get_realized (widget))
10108 screen = gdk_window_get_screen (priv->window);
10109 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10111 if (G_UNLIKELY (!device_window))
10114 g_hash_table_iter_init (&iter, device_window);
10116 while (g_hash_table_iter_next (&iter, &key, &value))
10118 GdkDevice *device = key;
10119 GdkWindow *window = value;
10124 gdk_window_get_user_data (window, (gpointer *) &w);
10127 devices = g_list_prepend (devices, device);
10135 synth_crossing (GtkWidget *widget,
10139 GdkCrossingMode mode,
10140 GdkNotifyType detail)
10144 event = gdk_event_new (type);
10146 event->crossing.window = g_object_ref (window);
10147 event->crossing.send_event = TRUE;
10148 event->crossing.subwindow = g_object_ref (window);
10149 event->crossing.time = GDK_CURRENT_TIME;
10150 event->crossing.x = event->crossing.y = 0;
10151 event->crossing.x_root = event->crossing.y_root = 0;
10152 event->crossing.mode = mode;
10153 event->crossing.detail = detail;
10154 event->crossing.focus = FALSE;
10155 event->crossing.state = 0;
10156 gdk_event_set_device (event, device);
10159 widget = gtk_get_event_widget (event);
10162 gtk_widget_event_internal (widget, event);
10164 gdk_event_free (event);
10168 * _gtk_widget_synthesize_crossing:
10169 * @from: the #GtkWidget the virtual pointer is leaving.
10170 * @to: the #GtkWidget the virtual pointer is moving to.
10171 * @mode: the #GdkCrossingMode to place on the synthesized events.
10173 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10175 * The real pointer window is the window that most recently received an enter notify
10176 * event. Windows that don't select for crossing events can't become the real
10177 * poiner window. The real pointer widget that owns the real pointer window. The
10178 * effective pointer window is the same as the real pointer window unless the real
10179 * pointer widget is either insensitive or there is a grab on a widget that is not
10180 * an ancestor of the real pointer widget (in which case the effective pointer
10181 * window should be the root window).
10183 * When the effective pointer window is the same as the real poiner window, we
10184 * receive crossing events from the windowing system. When the effective pointer
10185 * window changes to become different from the real pointer window we synthesize
10186 * crossing events, attempting to follow X protocol rules:
10188 * When the root window becomes the effective pointer window:
10189 * - leave notify on real pointer window, detail Ancestor
10190 * - leave notify on all of its ancestors, detail Virtual
10191 * - enter notify on root window, detail Inferior
10193 * When the root window ceases to be the effective pointer window:
10194 * - leave notify on root window, detail Inferior
10195 * - enter notify on all ancestors of real pointer window, detail Virtual
10196 * - enter notify on real pointer window, detail Ancestor
10199 _gtk_widget_synthesize_crossing (GtkWidget *from,
10202 GdkCrossingMode mode)
10204 GdkWindow *from_window = NULL, *to_window = NULL;
10206 g_return_if_fail (from != NULL || to != NULL);
10210 from_window = _gtk_widget_get_device_window (from, device);
10213 from_window = from->priv->window;
10218 to_window = _gtk_widget_get_device_window (to, device);
10221 to_window = to->priv->window;
10224 if (from_window == NULL && to_window == NULL)
10226 else if (from_window != NULL && to_window == NULL)
10228 GList *from_ancestors = NULL, *list;
10229 GdkWindow *from_ancestor = from_window;
10231 while (from_ancestor != NULL)
10233 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10234 if (from_ancestor == NULL)
10236 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10239 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10240 device, mode, GDK_NOTIFY_ANCESTOR);
10241 for (list = g_list_last (from_ancestors); list; list = list->prev)
10243 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10244 device, mode, GDK_NOTIFY_VIRTUAL);
10247 /* XXX: enter/inferior on root window? */
10249 g_list_free (from_ancestors);
10251 else if (from_window == NULL && to_window != NULL)
10253 GList *to_ancestors = NULL, *list;
10254 GdkWindow *to_ancestor = to_window;
10256 while (to_ancestor != NULL)
10258 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10259 if (to_ancestor == NULL)
10261 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10264 /* XXX: leave/inferior on root window? */
10266 for (list = to_ancestors; list; list = list->next)
10268 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10269 device, mode, GDK_NOTIFY_VIRTUAL);
10271 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10272 device, mode, GDK_NOTIFY_ANCESTOR);
10274 g_list_free (to_ancestors);
10276 else if (from_window == to_window)
10280 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10281 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10283 while (from_ancestor != NULL || to_ancestor != NULL)
10285 if (from_ancestor != NULL)
10287 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10288 if (from_ancestor == to_window)
10291 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10293 if (to_ancestor != NULL)
10295 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10296 if (to_ancestor == from_window)
10299 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10302 if (to_ancestor == from_window)
10304 if (mode != GDK_CROSSING_GTK_UNGRAB)
10305 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10306 device, mode, GDK_NOTIFY_INFERIOR);
10307 for (list = to_ancestors; list; list = list->next)
10308 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10309 device, mode, GDK_NOTIFY_VIRTUAL);
10310 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10311 device, mode, GDK_NOTIFY_ANCESTOR);
10313 else if (from_ancestor == to_window)
10315 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10316 device, mode, GDK_NOTIFY_ANCESTOR);
10317 for (list = g_list_last (from_ancestors); list; list = list->prev)
10319 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10320 device, mode, GDK_NOTIFY_VIRTUAL);
10322 if (mode != GDK_CROSSING_GTK_GRAB)
10323 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10324 device, mode, GDK_NOTIFY_INFERIOR);
10328 while (from_ancestors != NULL && to_ancestors != NULL
10329 && from_ancestors->data == to_ancestors->data)
10331 from_ancestors = g_list_delete_link (from_ancestors,
10333 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10336 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10337 device, mode, GDK_NOTIFY_NONLINEAR);
10339 for (list = g_list_last (from_ancestors); list; list = list->prev)
10341 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10342 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10344 for (list = to_ancestors; list; list = list->next)
10346 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10347 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10349 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10350 device, mode, GDK_NOTIFY_NONLINEAR);
10352 g_list_free (from_ancestors);
10353 g_list_free (to_ancestors);
10358 gtk_widget_propagate_state (GtkWidget *widget,
10359 GtkStateData *data)
10361 GtkWidgetPrivate *priv = widget->priv;
10362 guint8 old_state = gtk_widget_get_state (widget);
10363 guint8 old_saved_state = priv->saved_state;
10365 /* don't call this function with state==GTK_STATE_INSENSITIVE,
10366 * parent_sensitive==TRUE on a sensitive widget
10370 priv->parent_sensitive = data->parent_sensitive;
10372 if (gtk_widget_is_sensitive (widget))
10374 if (data->state_restoration)
10375 priv->state = priv->saved_state;
10377 priv->state = data->state;
10381 if (!data->state_restoration)
10383 if (data->state != GTK_STATE_INSENSITIVE)
10384 priv->saved_state = data->state;
10386 else if (gtk_widget_get_state (widget) != GTK_STATE_INSENSITIVE)
10387 priv->saved_state = gtk_widget_get_state (widget);
10388 priv->state = GTK_STATE_INSENSITIVE;
10391 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10395 window = gtk_widget_get_toplevel (widget);
10396 if (window && gtk_widget_is_toplevel (window))
10397 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10400 if (old_state != gtk_widget_get_state (widget) ||
10401 old_saved_state != priv->saved_state)
10403 g_object_ref (widget);
10405 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10406 gtk_grab_remove (widget);
10408 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10410 if (!priv->shadowed)
10412 GList *event_windows = NULL;
10413 GList *devices, *d;
10415 devices = _gtk_widget_list_devices (widget);
10417 for (d = devices; d; d = d->next)
10423 window = _gtk_widget_get_device_window (widget, device);
10425 /* Do not propagate more than once to the
10426 * same window if non-multidevice aware.
10428 if (!gdk_window_get_support_multidevice (window) &&
10429 g_list_find (event_windows, window))
10432 if (!gtk_widget_is_sensitive (widget))
10433 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10434 GDK_CROSSING_STATE_CHANGED);
10435 else if (old_state == GTK_STATE_INSENSITIVE)
10436 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10437 GDK_CROSSING_STATE_CHANGED);
10439 event_windows = g_list_prepend (event_windows, window);
10442 g_list_free (event_windows);
10443 g_list_free (devices);
10446 if (GTK_IS_CONTAINER (widget))
10448 data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
10449 if (data->use_forall)
10450 gtk_container_forall (GTK_CONTAINER (widget),
10451 (GtkCallback) gtk_widget_propagate_state,
10454 gtk_container_foreach (GTK_CONTAINER (widget),
10455 (GtkCallback) gtk_widget_propagate_state,
10458 g_object_unref (widget);
10462 static const GtkWidgetAuxInfo default_aux_info = {
10470 * _gtk_widget_get_aux_info:
10471 * @widget: a #GtkWidget
10472 * @create: if %TRUE, create the structure if it doesn't exist
10474 * Get the #GtkWidgetAuxInfo structure for the widget.
10476 * Return value: the #GtkAuxInfo structure for the widget, or
10477 * %NULL if @create is %FALSE and one doesn't already exist.
10480 _gtk_widget_get_aux_info (GtkWidget *widget,
10483 GtkWidgetAuxInfo *aux_info;
10485 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
10486 if (!aux_info && create)
10488 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
10490 *aux_info = default_aux_info;
10492 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
10498 static const GtkWidgetAuxInfo*
10499 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
10501 GtkWidgetAuxInfo *aux_info;
10503 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
10504 if (aux_info == NULL)
10506 return &default_aux_info;
10514 /*****************************************
10515 * gtk_widget_aux_info_destroy:
10520 *****************************************/
10523 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
10525 g_slice_free (GtkWidgetAuxInfo, aux_info);
10529 * gtk_widget_shape_combine_region:
10530 * @widget: a #GtkWidget
10531 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10533 * Sets a shape for this widget's GDK window. This allows for
10534 * transparent windows etc., see gdk_window_shape_combine_region()
10535 * for more information.
10540 gtk_widget_shape_combine_region (GtkWidget *widget,
10541 cairo_region_t *region)
10543 GtkWidgetPrivate *priv;
10545 g_return_if_fail (GTK_IS_WIDGET (widget));
10546 /* set_shape doesn't work on widgets without gdk window */
10547 g_return_if_fail (gtk_widget_get_has_window (widget));
10549 priv = widget->priv;
10551 if (region == NULL)
10553 priv->has_shape_mask = FALSE;
10556 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
10558 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
10562 priv->has_shape_mask = TRUE;
10564 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
10565 cairo_region_copy (region),
10566 (GDestroyNotify) cairo_region_destroy);
10568 /* set shape if widget has a gdk window already.
10569 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10572 gdk_window_shape_combine_region (priv->window, region, 0, 0);
10577 * gtk_widget_input_shape_combine_region:
10578 * @widget: a #GtkWidget
10579 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10581 * Sets an input shape for this widget's GDK window. This allows for
10582 * windows which react to mouse click in a nonrectangular region, see
10583 * gdk_window_input_shape_combine_region() for more information.
10588 gtk_widget_input_shape_combine_region (GtkWidget *widget,
10589 cairo_region_t *region)
10591 GtkWidgetPrivate *priv;
10593 g_return_if_fail (GTK_IS_WIDGET (widget));
10594 /* set_shape doesn't work on widgets without gdk window */
10595 g_return_if_fail (gtk_widget_get_has_window (widget));
10597 priv = widget->priv;
10599 if (region == NULL)
10602 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
10604 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
10608 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
10609 cairo_region_copy (region),
10610 (GDestroyNotify) cairo_region_destroy);
10612 /* set shape if widget has a gdk window already.
10613 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10616 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
10622 gtk_reset_shapes_recurse (GtkWidget *widget,
10628 gdk_window_get_user_data (window, &data);
10629 if (data != widget)
10632 gdk_window_shape_combine_region (window, NULL, 0, 0);
10633 for (list = gdk_window_peek_children (window); list; list = list->next)
10634 gtk_reset_shapes_recurse (widget, list->data);
10638 * gtk_widget_reset_shapes:
10639 * @widget: a #GtkWidget
10641 * Recursively resets the shape on this widget and its descendants.
10644 gtk_widget_reset_shapes (GtkWidget *widget)
10646 GtkWidgetPrivate *priv;
10648 g_return_if_fail (GTK_IS_WIDGET (widget));
10649 g_return_if_fail (gtk_widget_get_realized (widget));
10651 priv = widget->priv;
10653 if (!priv->has_shape_mask)
10654 gtk_reset_shapes_recurse (widget, priv->window);
10657 /* style properties
10661 * gtk_widget_class_install_style_property_parser:
10662 * @klass: a #GtkWidgetClass
10663 * @pspec: the #GParamSpec for the style property
10664 * @parser: the parser for the style property
10666 * Installs a style property on a widget class.
10669 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
10671 GtkRcPropertyParser parser)
10673 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10674 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10675 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
10676 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
10678 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
10680 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
10681 G_OBJECT_CLASS_NAME (klass),
10686 g_param_spec_ref_sink (pspec);
10687 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
10688 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
10692 * gtk_widget_class_install_style_property:
10693 * @klass: a #GtkWidgetClass
10694 * @pspec: the #GParamSpec for the property
10696 * Installs a style property on a widget class. The parser for the
10697 * style property is determined by the value type of @pspec.
10700 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
10703 GtkRcPropertyParser parser;
10705 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10706 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10708 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
10710 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
10714 * gtk_widget_class_find_style_property:
10715 * @klass: a #GtkWidgetClass
10716 * @property_name: the name of the style property to find
10717 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
10718 * style property with that name.
10720 * Finds a style property of a widget class by name.
10725 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
10726 const gchar *property_name)
10728 g_return_val_if_fail (property_name != NULL, NULL);
10730 return g_param_spec_pool_lookup (style_property_spec_pool,
10732 G_OBJECT_CLASS_TYPE (klass),
10737 * gtk_widget_class_list_style_properties:
10738 * @klass: a #GtkWidgetClass
10739 * @n_properties: location to return the number of style properties found
10740 * @returns: an newly allocated array of #GParamSpec*. The array must
10741 * be freed with g_free().
10743 * Returns all style properties of a widget class.
10748 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
10749 guint *n_properties)
10751 GParamSpec **pspecs;
10754 pspecs = g_param_spec_pool_list (style_property_spec_pool,
10755 G_OBJECT_CLASS_TYPE (klass),
10764 * gtk_widget_style_get_property:
10765 * @widget: a #GtkWidget
10766 * @property_name: the name of a style property
10767 * @value: location to return the property value
10769 * Gets the value of a style property of @widget.
10772 gtk_widget_style_get_property (GtkWidget *widget,
10773 const gchar *property_name,
10778 g_return_if_fail (GTK_IS_WIDGET (widget));
10779 g_return_if_fail (property_name != NULL);
10780 g_return_if_fail (G_IS_VALUE (value));
10782 g_object_ref (widget);
10783 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10785 G_OBJECT_TYPE (widget),
10788 g_warning ("%s: widget class `%s' has no property named `%s'",
10790 G_OBJECT_TYPE_NAME (widget),
10794 GtkStyleContext *context;
10795 const GValue *peek_value;
10797 context = gtk_widget_get_style_context (widget);
10798 peek_value = _gtk_style_context_peek_style_property (context,
10799 G_OBJECT_TYPE (widget),
10802 /* auto-conversion of the caller's value type
10804 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
10805 g_value_copy (peek_value, value);
10806 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
10807 g_value_transform (peek_value, value);
10809 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
10811 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
10812 G_VALUE_TYPE_NAME (value));
10814 g_object_unref (widget);
10818 * gtk_widget_style_get_valist:
10819 * @widget: a #GtkWidget
10820 * @first_property_name: the name of the first property to get
10821 * @var_args: a <type>va_list</type> of pairs of property names and
10822 * locations to return the property values, starting with the location
10823 * for @first_property_name.
10825 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
10829 gtk_widget_style_get_valist (GtkWidget *widget,
10830 const gchar *first_property_name,
10833 GtkStyleContext *context;
10836 g_return_if_fail (GTK_IS_WIDGET (widget));
10838 g_object_ref (widget);
10839 context = gtk_widget_get_style_context (widget);
10841 name = first_property_name;
10844 const GValue *peek_value;
10848 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10850 G_OBJECT_TYPE (widget),
10854 g_warning ("%s: widget class `%s' has no property named `%s'",
10856 G_OBJECT_TYPE_NAME (widget),
10860 /* style pspecs are always readable so we can spare that check here */
10862 peek_value = _gtk_style_context_peek_style_property (context,
10863 G_OBJECT_TYPE (widget),
10866 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
10869 g_warning ("%s: %s", G_STRLOC, error);
10874 name = va_arg (var_args, gchar*);
10877 g_object_unref (widget);
10881 * gtk_widget_style_get:
10882 * @widget: a #GtkWidget
10883 * @first_property_name: the name of the first property to get
10884 * @Varargs: pairs of property names and locations to
10885 * return the property values, starting with the location for
10886 * @first_property_name, terminated by %NULL.
10888 * Gets the values of a multiple style properties of @widget.
10891 gtk_widget_style_get (GtkWidget *widget,
10892 const gchar *first_property_name,
10897 g_return_if_fail (GTK_IS_WIDGET (widget));
10899 va_start (var_args, first_property_name);
10900 gtk_widget_style_get_valist (widget, first_property_name, var_args);
10906 * @widget: a #GtkWidget
10907 * @path_length: (out) (allow-none): location to store length of the path, or %NULL
10908 * @path: (out) (allow-none): location to store allocated path string, or %NULL
10909 * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL
10911 * Obtains the full path to @widget. The path is simply the name of a
10912 * widget and all its parents in the container hierarchy, separated by
10913 * periods. The name of a widget comes from
10914 * gtk_widget_get_name(). Paths are used to apply styles to a widget
10915 * in gtkrc configuration files. Widget names are the type of the
10916 * widget by default (e.g. "GtkButton") or can be set to an
10917 * application-specific value with gtk_widget_set_name(). By setting
10918 * the name of a widget, you allow users or theme authors to apply
10919 * styles to that specific widget in their gtkrc
10920 * file. @path_reversed_p fills in the path in reverse order,
10921 * i.e. starting with @widget's name instead of starting with the name
10922 * of @widget's outermost ancestor.
10925 gtk_widget_path (GtkWidget *widget,
10926 guint *path_length,
10928 gchar **path_reversed)
10930 static gchar *rev_path = NULL;
10931 static guint tmp_path_len = 0;
10934 g_return_if_fail (GTK_IS_WIDGET (widget));
10939 const gchar *string;
10944 string = gtk_widget_get_name (widget);
10945 l = strlen (string);
10946 while (tmp_path_len <= len + l + 1)
10948 tmp_path_len += INIT_PATH_SIZE;
10949 rev_path = g_realloc (rev_path, tmp_path_len);
10951 s = string + l - 1;
10952 d = rev_path + len;
10953 while (s >= string)
10957 widget = widget->priv->parent;
10960 rev_path[len++] = '.';
10962 rev_path[len++] = 0;
10967 *path_length = len - 1;
10969 *path_reversed = g_strdup (rev_path);
10972 *path = g_strdup (rev_path);
10973 g_strreverse (*path);
10978 * gtk_widget_class_path:
10979 * @widget: a #GtkWidget
10980 * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10981 * @path: (out) (allow-none): location to store the class path as an allocated string, or %NULL
10982 * @path_reversed: (out) (allow-none): location to store the reverse class path as an allocated
10985 * Same as gtk_widget_path(), but always uses the name of a widget's type,
10986 * never uses a custom name set with gtk_widget_set_name().
10990 gtk_widget_class_path (GtkWidget *widget,
10991 guint *path_length,
10993 gchar **path_reversed)
10995 static gchar *rev_path = NULL;
10996 static guint tmp_path_len = 0;
10999 g_return_if_fail (GTK_IS_WIDGET (widget));
11004 const gchar *string;
11009 string = g_type_name (G_OBJECT_TYPE (widget));
11010 l = strlen (string);
11011 while (tmp_path_len <= len + l + 1)
11013 tmp_path_len += INIT_PATH_SIZE;
11014 rev_path = g_realloc (rev_path, tmp_path_len);
11016 s = string + l - 1;
11017 d = rev_path + len;
11018 while (s >= string)
11022 widget = widget->priv->parent;
11025 rev_path[len++] = '.';
11027 rev_path[len++] = 0;
11032 *path_length = len - 1;
11034 *path_reversed = g_strdup (rev_path);
11037 *path = g_strdup (rev_path);
11038 g_strreverse (*path);
11043 * gtk_requisition_new:
11045 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11047 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11048 * be freed with gtk_requisition_free().
11053 gtk_requisition_new (void)
11055 return g_slice_new0 (GtkRequisition);
11059 * gtk_requisition_copy:
11060 * @requisition: a #GtkRequisition
11062 * Copies a #GtkRequisition.
11064 * Returns: a copy of @requisition
11067 gtk_requisition_copy (const GtkRequisition *requisition)
11069 return g_slice_dup (GtkRequisition, requisition);
11073 * gtk_requisition_free:
11074 * @requisition: a #GtkRequisition
11076 * Frees a #GtkRequisition.
11079 gtk_requisition_free (GtkRequisition *requisition)
11081 g_slice_free (GtkRequisition, requisition);
11084 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11085 gtk_requisition_copy,
11086 gtk_requisition_free)
11089 * gtk_widget_get_accessible:
11090 * @widget: a #GtkWidget
11092 * Returns the accessible object that describes the widget to an
11093 * assistive technology.
11095 * If no accessibility library is loaded (i.e. no ATK implementation library is
11096 * loaded via <envar>GTK_MODULES</envar> or via another application library,
11097 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
11098 * if no class-specific #AtkObject implementation is available for the widget
11099 * instance in question, it will inherit an #AtkObject implementation from the
11100 * first ancestor class for which such an implementation is defined.
11102 * The documentation of the
11103 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
11104 * library contains more information about accessible objects and their uses.
11106 * Returns: (transfer none): the #AtkObject associated with @widget
11109 gtk_widget_get_accessible (GtkWidget *widget)
11111 GtkWidgetClass *klass;
11113 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11115 klass = GTK_WIDGET_GET_CLASS (widget);
11117 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11119 return klass->get_accessible (widget);
11123 gtk_widget_real_get_accessible (GtkWidget *widget)
11125 AtkObject* accessible;
11127 accessible = g_object_get_qdata (G_OBJECT (widget),
11128 quark_accessible_object);
11131 AtkObjectFactory *factory;
11132 AtkRegistry *default_registry;
11134 default_registry = atk_get_default_registry ();
11135 factory = atk_registry_get_factory (default_registry,
11136 G_TYPE_FROM_INSTANCE (widget));
11138 atk_object_factory_create_accessible (factory,
11139 G_OBJECT (widget));
11140 g_object_set_qdata (G_OBJECT (widget),
11141 quark_accessible_object,
11148 * Initialize a AtkImplementorIface instance's virtual pointers as
11149 * appropriate to this implementor's class (GtkWidget).
11152 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11154 iface->ref_accessible = gtk_widget_ref_accessible;
11158 gtk_widget_ref_accessible (AtkImplementor *implementor)
11160 AtkObject *accessible;
11162 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11164 g_object_ref (accessible);
11169 * Expand flag management
11173 gtk_widget_update_computed_expand (GtkWidget *widget)
11175 GtkWidgetPrivate *priv;
11177 priv = widget->priv;
11179 if (priv->need_compute_expand)
11183 if (priv->hexpand_set)
11188 if (priv->vexpand_set)
11193 /* we don't need to use compute_expand if both expands are
11194 * forced by the app
11196 if (!(priv->hexpand_set && priv->vexpand_set))
11198 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11202 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11203 priv->hexpand_set ? &ignored : &h,
11204 priv->vexpand_set ? &ignored : &v);
11208 priv->need_compute_expand = FALSE;
11209 priv->computed_hexpand = h != FALSE;
11210 priv->computed_vexpand = v != FALSE;
11215 * gtk_widget_queue_compute_expand:
11216 * @widget: a #GtkWidget
11218 * Mark @widget as needing to recompute its expand flags. Call
11219 * this function when setting legacy expand child properties
11220 * on the child of a container.
11222 * See gtk_widget_compute_expand().
11225 gtk_widget_queue_compute_expand (GtkWidget *widget)
11228 gboolean changed_anything;
11230 if (widget->priv->need_compute_expand)
11233 changed_anything = FALSE;
11235 while (parent != NULL)
11237 if (!parent->priv->need_compute_expand)
11239 parent->priv->need_compute_expand = TRUE;
11240 changed_anything = TRUE;
11243 /* Note: if we had an invariant that "if a child needs to
11244 * compute expand, its parents also do" then we could stop going
11245 * up when we got to a parent that already needed to
11246 * compute. However, in general we compute expand lazily (as
11247 * soon as we see something in a subtree that is expand, we know
11248 * we're expanding) and so this invariant does not hold and we
11249 * have to always walk all the way up in case some ancestor
11250 * is not currently need_compute_expand.
11253 parent = parent->priv->parent;
11256 /* recomputing expand always requires
11257 * a relayout as well
11259 if (changed_anything)
11260 gtk_widget_queue_resize (widget);
11264 * gtk_widget_compute_expand:
11265 * @widget: the widget
11266 * @orientation: expand direction
11268 * Computes whether a container should give this widget extra space
11269 * when possible. Containers should check this, rather than
11270 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11272 * This function already checks whether the widget is visible, so
11273 * visibility does not need to be checked separately. Non-visible
11274 * widgets are not expanded.
11276 * The computed expand value uses either the expand setting explicitly
11277 * set on the widget itself, or, if none has been explicitly set,
11278 * the widget may expand if some of its children do.
11280 * Return value: whether widget tree rooted here should be expanded
11283 gtk_widget_compute_expand (GtkWidget *widget,
11284 GtkOrientation orientation)
11286 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11288 /* We never make a widget expand if not even showing. */
11289 if (!gtk_widget_get_visible (widget))
11292 gtk_widget_update_computed_expand (widget);
11294 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11296 return widget->priv->computed_hexpand;
11300 return widget->priv->computed_vexpand;
11305 gtk_widget_set_expand (GtkWidget *widget,
11306 GtkOrientation orientation,
11309 const char *expand_prop;
11310 const char *expand_set_prop;
11312 GtkWidgetPrivate *priv;
11314 g_return_if_fail (GTK_IS_WIDGET (widget));
11316 priv = widget->priv;
11318 expand = expand != FALSE;
11320 was_both = priv->hexpand && priv->vexpand;
11322 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11324 if (priv->hexpand_set &&
11325 priv->hexpand == expand)
11328 priv->hexpand_set = TRUE;
11329 priv->hexpand = expand;
11331 expand_prop = "hexpand";
11332 expand_set_prop = "hexpand-set";
11336 if (priv->vexpand_set &&
11337 priv->vexpand == expand)
11340 priv->vexpand_set = TRUE;
11341 priv->vexpand = expand;
11343 expand_prop = "vexpand";
11344 expand_set_prop = "vexpand-set";
11347 gtk_widget_queue_compute_expand (widget);
11349 g_object_freeze_notify (G_OBJECT (widget));
11350 g_object_notify (G_OBJECT (widget), expand_prop);
11351 g_object_notify (G_OBJECT (widget), expand_set_prop);
11352 if (was_both != (priv->hexpand && priv->vexpand))
11353 g_object_notify (G_OBJECT (widget), "expand");
11354 g_object_thaw_notify (G_OBJECT (widget));
11358 gtk_widget_set_expand_set (GtkWidget *widget,
11359 GtkOrientation orientation,
11362 GtkWidgetPrivate *priv;
11365 priv = widget->priv;
11367 set = set != FALSE;
11369 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11371 if (set == priv->hexpand_set)
11374 priv->hexpand_set = set;
11375 prop = "hexpand-set";
11379 if (set == priv->vexpand_set)
11382 priv->vexpand_set = set;
11383 prop = "vexpand-set";
11386 gtk_widget_queue_compute_expand (widget);
11388 g_object_notify (G_OBJECT (widget), prop);
11392 * gtk_widget_get_hexpand:
11393 * @widget: the widget
11395 * Gets whether the widget would like any available extra horizontal
11396 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11397 * generally receive the extra space. For example, a list or
11398 * scrollable area or document in your window would often be set to
11401 * Containers should use gtk_widget_compute_expand() rather than
11402 * this function, to see whether a widget, or any of its children,
11403 * has the expand flag set. If any child of a widget wants to
11404 * expand, the parent may ask to expand also.
11406 * This function only looks at the widget's own hexpand flag, rather
11407 * than computing whether the entire widget tree rooted at this widget
11410 * Return value: whether hexpand flag is set
11413 gtk_widget_get_hexpand (GtkWidget *widget)
11415 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11417 return widget->priv->hexpand;
11421 * gtk_widget_set_hexpand:
11422 * @widget: the widget
11423 * @expand: whether to expand
11425 * Sets whether the widget would like any available extra horizontal
11426 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11427 * generally receive the extra space. For example, a list or
11428 * scrollable area or document in your window would often be set to
11431 * Call this function to set the expand flag if you would like your
11432 * widget to become larger horizontally when the window has extra
11435 * By default, widgets automatically expand if any of their children
11436 * want to expand. (To see if a widget will automatically expand given
11437 * its current children and state, call gtk_widget_compute_expand(). A
11438 * container can decide how the expandability of children affects the
11439 * expansion of the container by overriding the compute_expand virtual
11440 * method on #GtkWidget.).
11442 * Setting hexpand explicitly with this function will override the
11443 * automatic expand behavior.
11445 * This function forces the widget to expand or not to expand,
11446 * regardless of children. The override occurs because
11447 * gtk_widget_set_hexpand() sets the hexpand-set property (see
11448 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
11449 * value to be used, rather than looking at children and widget state.
11452 gtk_widget_set_hexpand (GtkWidget *widget,
11455 g_return_if_fail (GTK_IS_WIDGET (widget));
11457 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
11461 * gtk_widget_get_hexpand_set:
11462 * @widget: the widget
11464 * Gets whether gtk_widget_set_hexpand() has been used to
11465 * explicitly set the expand flag on this widget.
11467 * If hexpand is set, then it overrides any computed
11468 * expand value based on child widgets. If hexpand is not
11469 * set, then the expand value depends on whether any
11470 * children of the widget would like to expand.
11472 * There are few reasons to use this function, but it's here
11473 * for completeness and consistency.
11475 * Return value: whether hexpand has been explicitly set
11478 gtk_widget_get_hexpand_set (GtkWidget *widget)
11480 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11482 return widget->priv->hexpand_set;
11486 * gtk_widget_set_hexpand_set:
11487 * @widget: the widget
11488 * @set: value for hexpand-set property
11490 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
11493 * The hexpand-set property will be set automatically when you call
11494 * gtk_widget_set_hexpand() to set hexpand, so the most likely
11495 * reason to use this function would be to unset an explicit expand
11498 * If hexpand is set, then it overrides any computed
11499 * expand value based on child widgets. If hexpand is not
11500 * set, then the expand value depends on whether any
11501 * children of the widget would like to expand.
11503 * There are few reasons to use this function, but it's here
11504 * for completeness and consistency.
11506 * Return value: whether hexpand has been explicitly set
11509 gtk_widget_set_hexpand_set (GtkWidget *widget,
11512 g_return_if_fail (GTK_IS_WIDGET (widget));
11514 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
11519 * gtk_widget_get_vexpand:
11520 * @widget: the widget
11522 * Gets whether the widget would like any available extra vertical
11525 * See gtk_widget_get_hexpand() for more detail.
11527 * Return value: whether vexpand flag is set
11530 gtk_widget_get_vexpand (GtkWidget *widget)
11532 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11534 return widget->priv->vexpand;
11538 * gtk_widget_set_vexpand:
11539 * @widget: the widget
11540 * @expand: whether to expand
11542 * Sets whether the widget would like any available extra vertical
11545 * See gtk_widget_set_hexpand() for more detail.
11548 gtk_widget_set_vexpand (GtkWidget *widget,
11551 g_return_if_fail (GTK_IS_WIDGET (widget));
11553 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
11557 * gtk_widget_get_vexpand_set:
11558 * @widget: the widget
11560 * Gets whether gtk_widget_set_vexpand() has been used to
11561 * explicitly set the expand flag on this widget.
11563 * See gtk_widget_get_hexpand_set() for more detail.
11565 * Return value: whether vexpand has been explicitly set
11568 gtk_widget_get_vexpand_set (GtkWidget *widget)
11570 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11572 return widget->priv->vexpand_set;
11576 * gtk_widget_set_vexpand_set:
11577 * @widget: the widget
11578 * @set: value for vexpand-set property
11580 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
11583 * See gtk_widget_set_hexpand_set() for more detail.
11585 * Return value: whether vexpand has been explicitly set
11588 gtk_widget_set_vexpand_set (GtkWidget *widget,
11591 g_return_if_fail (GTK_IS_WIDGET (widget));
11593 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
11597 * GtkBuildable implementation
11599 static GQuark quark_builder_has_default = 0;
11600 static GQuark quark_builder_has_focus = 0;
11601 static GQuark quark_builder_atk_relations = 0;
11602 static GQuark quark_builder_set_name = 0;
11605 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
11607 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
11608 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
11609 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
11610 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
11612 iface->set_name = gtk_widget_buildable_set_name;
11613 iface->get_name = gtk_widget_buildable_get_name;
11614 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
11615 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
11616 iface->parser_finished = gtk_widget_buildable_parser_finished;
11617 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
11618 iface->custom_finished = gtk_widget_buildable_custom_finished;
11622 gtk_widget_buildable_set_name (GtkBuildable *buildable,
11625 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
11626 g_strdup (name), g_free);
11629 static const gchar *
11630 gtk_widget_buildable_get_name (GtkBuildable *buildable)
11632 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
11636 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
11637 GtkBuilder *builder,
11638 const gchar *childname)
11640 if (strcmp (childname, "accessible") == 0)
11641 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
11647 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
11648 GtkBuilder *builder,
11650 const GValue *value)
11652 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
11653 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
11654 GINT_TO_POINTER (TRUE));
11655 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
11656 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
11657 GINT_TO_POINTER (TRUE));
11659 g_object_set_property (G_OBJECT (buildable), name, value);
11664 gchar *action_name;
11665 GString *description;
11667 gboolean translatable;
11677 free_action (AtkActionData *data, gpointer user_data)
11679 g_free (data->action_name);
11680 g_string_free (data->description, TRUE);
11681 g_free (data->context);
11682 g_slice_free (AtkActionData, data);
11686 free_relation (AtkRelationData *data, gpointer user_data)
11688 g_free (data->target);
11689 g_free (data->type);
11690 g_slice_free (AtkRelationData, data);
11694 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
11695 GtkBuilder *builder)
11697 GSList *atk_relations;
11699 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
11700 gtk_widget_grab_default (GTK_WIDGET (buildable));
11701 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
11702 gtk_widget_grab_focus (GTK_WIDGET (buildable));
11704 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
11705 quark_builder_atk_relations);
11708 AtkObject *accessible;
11709 AtkRelationSet *relation_set;
11712 AtkRelationType relation_type;
11713 AtkObject *target_accessible;
11715 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11716 relation_set = atk_object_ref_relation_set (accessible);
11718 for (l = atk_relations; l; l = l->next)
11720 AtkRelationData *relation = (AtkRelationData*)l->data;
11722 target = gtk_builder_get_object (builder, relation->target);
11725 g_warning ("Target object %s in <relation> does not exist",
11729 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
11730 g_assert (target_accessible != NULL);
11732 relation_type = atk_relation_type_for_name (relation->type);
11733 if (relation_type == ATK_RELATION_NULL)
11735 g_warning ("<relation> type %s not found",
11739 atk_relation_set_add_relation_by_type (relation_set, relation_type,
11740 target_accessible);
11742 g_object_unref (relation_set);
11744 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
11745 g_slist_free (atk_relations);
11746 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
11755 } AccessibilitySubParserData;
11758 accessibility_start_element (GMarkupParseContext *context,
11759 const gchar *element_name,
11760 const gchar **names,
11761 const gchar **values,
11762 gpointer user_data,
11765 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
11767 gint line_number, char_number;
11769 if (strcmp (element_name, "relation") == 0)
11771 gchar *target = NULL;
11772 gchar *type = NULL;
11773 AtkRelationData *relation;
11775 for (i = 0; names[i]; i++)
11777 if (strcmp (names[i], "target") == 0)
11778 target = g_strdup (values[i]);
11779 else if (strcmp (names[i], "type") == 0)
11780 type = g_strdup (values[i]);
11783 g_markup_parse_context_get_position (context,
11786 g_set_error (error,
11788 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
11789 "%s:%d:%d '%s' is not a valid attribute of <%s>",
11791 line_number, char_number, names[i], "relation");
11798 if (!target || !type)
11800 g_markup_parse_context_get_position (context,
11803 g_set_error (error,
11805 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
11806 "%s:%d:%d <%s> requires attribute \"%s\"",
11808 line_number, char_number, "relation",
11809 type ? "target" : "type");
11815 relation = g_slice_new (AtkRelationData);
11816 relation->target = target;
11817 relation->type = type;
11819 data->relations = g_slist_prepend (data->relations, relation);
11821 else if (strcmp (element_name, "action") == 0)
11823 const gchar *action_name = NULL;
11824 const gchar *description = NULL;
11825 const gchar *msg_context = NULL;
11826 gboolean translatable = FALSE;
11827 AtkActionData *action;
11829 for (i = 0; names[i]; i++)
11831 if (strcmp (names[i], "action_name") == 0)
11832 action_name = values[i];
11833 else if (strcmp (names[i], "description") == 0)
11834 description = values[i];
11835 else if (strcmp (names[i], "translatable") == 0)
11837 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
11840 else if (strcmp (names[i], "comments") == 0)
11842 /* do nothing, comments are for translators */
11844 else if (strcmp (names[i], "context") == 0)
11845 msg_context = values[i];
11848 g_markup_parse_context_get_position (context,
11851 g_set_error (error,
11853 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
11854 "%s:%d:%d '%s' is not a valid attribute of <%s>",
11856 line_number, char_number, names[i], "action");
11863 g_markup_parse_context_get_position (context,
11866 g_set_error (error,
11868 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
11869 "%s:%d:%d <%s> requires attribute \"%s\"",
11871 line_number, char_number, "action",
11876 action = g_slice_new (AtkActionData);
11877 action->action_name = g_strdup (action_name);
11878 action->description = g_string_new (description);
11879 action->context = g_strdup (msg_context);
11880 action->translatable = translatable;
11882 data->actions = g_slist_prepend (data->actions, action);
11884 else if (strcmp (element_name, "accessibility") == 0)
11887 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
11891 accessibility_text (GMarkupParseContext *context,
11894 gpointer user_data,
11897 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
11899 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
11901 AtkActionData *action = data->actions->data;
11903 g_string_append_len (action->description, text, text_len);
11907 static const GMarkupParser accessibility_parser =
11909 accessibility_start_element,
11911 accessibility_text,
11920 } AccelGroupParserData;
11923 accel_group_start_element (GMarkupParseContext *context,
11924 const gchar *element_name,
11925 const gchar **names,
11926 const gchar **values,
11927 gpointer user_data,
11932 guint modifiers = 0;
11933 gchar *signal = NULL;
11934 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
11936 for (i = 0; names[i]; i++)
11938 if (strcmp (names[i], "key") == 0)
11939 key = gdk_keyval_from_name (values[i]);
11940 else if (strcmp (names[i], "modifiers") == 0)
11942 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
11948 else if (strcmp (names[i], "signal") == 0)
11949 signal = g_strdup (values[i]);
11952 if (key == 0 || signal == NULL)
11954 g_warning ("<accelerator> requires key and signal attributes");
11957 parser_data->key = key;
11958 parser_data->modifiers = modifiers;
11959 parser_data->signal = signal;
11962 static const GMarkupParser accel_group_parser =
11964 accel_group_start_element,
11968 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
11969 GtkBuilder *builder,
11971 const gchar *tagname,
11972 GMarkupParser *parser,
11975 g_assert (buildable);
11977 if (strcmp (tagname, "accelerator") == 0)
11979 AccelGroupParserData *parser_data;
11981 parser_data = g_slice_new0 (AccelGroupParserData);
11982 parser_data->object = g_object_ref (buildable);
11983 *parser = accel_group_parser;
11984 *data = parser_data;
11987 if (strcmp (tagname, "accessibility") == 0)
11989 AccessibilitySubParserData *parser_data;
11991 parser_data = g_slice_new0 (AccessibilitySubParserData);
11992 *parser = accessibility_parser;
11993 *data = parser_data;
12000 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12001 GtkWidget *toplevel,
12002 gpointer user_data)
12004 AccelGroupParserData *accel_data;
12005 GSList *accel_groups;
12006 GtkAccelGroup *accel_group;
12008 g_return_if_fail (GTK_IS_WIDGET (widget));
12009 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12010 g_return_if_fail (user_data != NULL);
12012 accel_data = (AccelGroupParserData*)user_data;
12013 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12014 if (g_slist_length (accel_groups) == 0)
12016 accel_group = gtk_accel_group_new ();
12017 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12021 g_assert (g_slist_length (accel_groups) == 1);
12022 accel_group = g_slist_nth_data (accel_groups, 0);
12025 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12026 accel_data->signal,
12029 accel_data->modifiers,
12030 GTK_ACCEL_VISIBLE);
12032 g_object_unref (accel_data->object);
12033 g_free (accel_data->signal);
12034 g_slice_free (AccelGroupParserData, accel_data);
12038 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12039 GtkBuilder *builder,
12041 const gchar *tagname,
12042 gpointer user_data)
12044 AccelGroupParserData *accel_data;
12045 AccessibilitySubParserData *a11y_data;
12046 GtkWidget *toplevel;
12048 if (strcmp (tagname, "accelerator") == 0)
12050 accel_data = (AccelGroupParserData*)user_data;
12051 g_assert (accel_data->object);
12053 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12055 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12057 else if (strcmp (tagname, "accessibility") == 0)
12059 a11y_data = (AccessibilitySubParserData*)user_data;
12061 if (a11y_data->actions)
12063 AtkObject *accessible;
12068 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12070 action = ATK_ACTION (accessible);
12071 n_actions = atk_action_get_n_actions (action);
12073 for (l = a11y_data->actions; l; l = l->next)
12075 AtkActionData *action_data = (AtkActionData*)l->data;
12077 for (i = 0; i < n_actions; i++)
12078 if (strcmp (atk_action_get_name (action, i),
12079 action_data->action_name) == 0)
12084 gchar *description;
12086 if (action_data->translatable && action_data->description->len)
12087 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12088 action_data->context,
12089 action_data->description->str);
12091 description = action_data->description->str;
12093 atk_action_set_description (action, i, description);
12097 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
12098 g_slist_free (a11y_data->actions);
12101 if (a11y_data->relations)
12102 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12103 a11y_data->relations);
12105 g_slice_free (AccessibilitySubParserData, a11y_data);
12110 gtk_widget_real_get_width (GtkWidget *widget,
12111 gint *minimum_size,
12112 gint *natural_size)
12122 gtk_widget_real_get_height (GtkWidget *widget,
12123 gint *minimum_size,
12124 gint *natural_size)
12134 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12136 gint *minimum_height,
12137 gint *natural_height)
12139 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12143 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12145 gint *minimum_width,
12146 gint *natural_width)
12148 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12152 * gtk_widget_get_halign:
12153 * @widget: a #GtkWidget
12155 * Gets the value of the #GtkWidget:halign property.
12157 * Returns: the horizontal alignment of @widget
12160 gtk_widget_get_halign (GtkWidget *widget)
12162 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12163 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12167 * gtk_widget_set_halign:
12168 * @widget: a #GtkWidget
12169 * @align: the horizontal alignment
12171 * Sets the horizontal alignment of @widget.
12172 * See the #GtkWidget:halign property.
12175 gtk_widget_set_halign (GtkWidget *widget,
12178 GtkWidgetAuxInfo *aux_info;
12180 g_return_if_fail (GTK_IS_WIDGET (widget));
12182 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12184 if (aux_info->halign == align)
12187 aux_info->halign = align;
12188 gtk_widget_queue_resize (widget);
12189 g_object_notify (G_OBJECT (widget), "halign");
12193 * gtk_widget_get_valign:
12194 * @widget: a #GtkWidget
12196 * Gets the value of the #GtkWidget:valign property.
12198 * Returns: the vertical alignment of @widget
12201 gtk_widget_get_valign (GtkWidget *widget)
12203 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12204 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12208 * gtk_widget_set_valign:
12209 * @widget: a #GtkWidget
12210 * @align: the vertical alignment
12212 * Sets the vertical alignment of @widget.
12213 * See the #GtkWidget:valign property.
12216 gtk_widget_set_valign (GtkWidget *widget,
12219 GtkWidgetAuxInfo *aux_info;
12221 g_return_if_fail (GTK_IS_WIDGET (widget));
12223 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12225 if (aux_info->valign == align)
12228 aux_info->valign = align;
12229 gtk_widget_queue_resize (widget);
12230 g_object_notify (G_OBJECT (widget), "valign");
12234 * gtk_widget_get_margin_left:
12235 * @widget: a #GtkWidget
12237 * Gets the value of the #GtkWidget:margin-left property.
12239 * Returns: The left margin of @widget
12242 gtk_widget_get_margin_left (GtkWidget *widget)
12244 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12246 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12250 * gtk_widget_set_margin_left:
12251 * @widget: a #GtkWidget
12252 * @margin: the left margin
12254 * Sets the left margin of @widget.
12255 * See the #GtkWidget:margin-left property.
12258 gtk_widget_set_margin_left (GtkWidget *widget,
12261 GtkWidgetAuxInfo *aux_info;
12263 g_return_if_fail (GTK_IS_WIDGET (widget));
12264 g_return_if_fail (margin <= G_MAXINT16);
12266 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12268 if (aux_info->margin.left == margin)
12271 aux_info->margin.left = margin;
12272 gtk_widget_queue_resize (widget);
12273 g_object_notify (G_OBJECT (widget), "margin-left");
12277 * gtk_widget_get_margin_right:
12278 * @widget: a #GtkWidget
12280 * Gets the value of the #GtkWidget:margin-right property.
12282 * Returns: The left margin of @widget
12285 gtk_widget_get_margin_right (GtkWidget *widget)
12287 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12289 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12293 * gtk_widget_set_margin_right:
12294 * @widget: a #GtkWidget
12295 * @margin: the right margin
12297 * Sets the right margin of @widget.
12298 * See the #GtkWidget:margin-right property.
12301 gtk_widget_set_margin_right (GtkWidget *widget,
12304 GtkWidgetAuxInfo *aux_info;
12306 g_return_if_fail (GTK_IS_WIDGET (widget));
12307 g_return_if_fail (margin <= G_MAXINT16);
12309 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12311 if (aux_info->margin.right == margin)
12314 aux_info->margin.right = margin;
12315 gtk_widget_queue_resize (widget);
12316 g_object_notify (G_OBJECT (widget), "margin-right");
12320 * gtk_widget_get_margin_top:
12321 * @widget: a #GtkWidget
12323 * Gets the value of the #GtkWidget:margin-top property.
12325 * Returns: The top margin of @widget
12328 gtk_widget_get_margin_top (GtkWidget *widget)
12330 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12332 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12336 * gtk_widget_set_margin_top:
12337 * @widget: a #GtkWidget
12338 * @margin: the top margin
12340 * Sets the top margin of @widget.
12341 * See the #GtkWidget:margin-top property.
12344 gtk_widget_set_margin_top (GtkWidget *widget,
12347 GtkWidgetAuxInfo *aux_info;
12349 g_return_if_fail (GTK_IS_WIDGET (widget));
12350 g_return_if_fail (margin <= G_MAXINT16);
12352 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12354 if (aux_info->margin.top == margin)
12357 aux_info->margin.top = margin;
12358 gtk_widget_queue_resize (widget);
12359 g_object_notify (G_OBJECT (widget), "margin-top");
12363 * gtk_widget_get_margin_bottom:
12364 * @widget: a #GtkWidget
12366 * Gets the value of the #GtkWidget:margin-bottom property.
12368 * Returns: The bottom margin of @widget
12371 gtk_widget_get_margin_bottom (GtkWidget *widget)
12373 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12375 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
12379 * gtk_widget_set_margin_bottom:
12380 * @widget: a #GtkWidget
12381 * @margin: the bottom margin
12383 * Sets the bottom margin of @widget.
12384 * See the #GtkWidget:margin-bottom property.
12387 gtk_widget_set_margin_bottom (GtkWidget *widget,
12390 GtkWidgetAuxInfo *aux_info;
12392 g_return_if_fail (GTK_IS_WIDGET (widget));
12393 g_return_if_fail (margin <= G_MAXINT16);
12395 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12397 if (aux_info->margin.bottom == margin)
12400 aux_info->margin.bottom = margin;
12401 gtk_widget_queue_resize (widget);
12402 g_object_notify (G_OBJECT (widget), "margin-bottom");
12406 * gtk_widget_get_clipboard:
12407 * @widget: a #GtkWidget
12408 * @selection: a #GdkAtom which identifies the clipboard
12409 * to use. %GDK_SELECTION_CLIPBOARD gives the
12410 * default clipboard. Another common value
12411 * is %GDK_SELECTION_PRIMARY, which gives
12412 * the primary X selection.
12414 * Returns the clipboard object for the given selection to
12415 * be used with @widget. @widget must have a #GdkDisplay
12416 * associated with it, so must be attached to a toplevel
12419 * Return value: (transfer none): the appropriate clipboard object. If no
12420 * clipboard already exists, a new one will
12421 * be created. Once a clipboard object has
12422 * been created, it is persistent for all time.
12427 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
12429 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12430 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
12432 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
12437 * gtk_widget_list_mnemonic_labels:
12438 * @widget: a #GtkWidget
12440 * Returns a newly allocated list of the widgets, normally labels, for
12441 * which this widget is the target of a mnemonic (see for example,
12442 * gtk_label_set_mnemonic_widget()).
12444 * The widgets in the list are not individually referenced. If you
12445 * want to iterate through the list and perform actions involving
12446 * callbacks that might destroy the widgets, you
12447 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
12448 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
12449 * widgets afterwards.
12451 * Return value: (element-type GtkWidget) (transfer container): the list of
12452 * mnemonic labels; free this list
12453 * with g_list_free() when you are done with it.
12458 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
12460 GList *list = NULL;
12463 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12465 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
12466 list = g_list_prepend (list, l->data);
12472 * gtk_widget_add_mnemonic_label:
12473 * @widget: a #GtkWidget
12474 * @label: a #GtkWidget that acts as a mnemonic label for @widget
12476 * Adds a widget to the list of mnemonic labels for
12477 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
12478 * list of mnemonic labels for the widget is cleared when the
12479 * widget is destroyed, so the caller must make sure to update
12480 * its internal state at this point as well, by using a connection
12481 * to the #GtkWidget::destroy signal or a weak notifier.
12486 gtk_widget_add_mnemonic_label (GtkWidget *widget,
12489 GSList *old_list, *new_list;
12491 g_return_if_fail (GTK_IS_WIDGET (widget));
12492 g_return_if_fail (GTK_IS_WIDGET (label));
12494 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12495 new_list = g_slist_prepend (old_list, label);
12497 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12498 new_list, (GDestroyNotify) g_slist_free);
12502 * gtk_widget_remove_mnemonic_label:
12503 * @widget: a #GtkWidget
12504 * @label: a #GtkWidget that was previously set as a mnemnic label for
12505 * @widget with gtk_widget_add_mnemonic_label().
12507 * Removes a widget from the list of mnemonic labels for
12508 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
12509 * must have previously been added to the list with
12510 * gtk_widget_add_mnemonic_label().
12515 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
12518 GSList *old_list, *new_list;
12520 g_return_if_fail (GTK_IS_WIDGET (widget));
12521 g_return_if_fail (GTK_IS_WIDGET (label));
12523 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12524 new_list = g_slist_remove (old_list, label);
12527 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12528 new_list, (GDestroyNotify) g_slist_free);
12532 * gtk_widget_get_no_show_all:
12533 * @widget: a #GtkWidget
12535 * Returns the current value of the #GtkWidget:no-show-all property,
12536 * which determines whether calls to gtk_widget_show_all()
12537 * will affect this widget.
12539 * Return value: the current value of the "no-show-all" property.
12544 gtk_widget_get_no_show_all (GtkWidget *widget)
12546 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12548 return widget->priv->no_show_all;
12552 * gtk_widget_set_no_show_all:
12553 * @widget: a #GtkWidget
12554 * @no_show_all: the new value for the "no-show-all" property
12556 * Sets the #GtkWidget:no-show-all property, which determines whether
12557 * calls to gtk_widget_show_all() will affect this widget.
12559 * This is mostly for use in constructing widget hierarchies with externally
12560 * controlled visibility, see #GtkUIManager.
12565 gtk_widget_set_no_show_all (GtkWidget *widget,
12566 gboolean no_show_all)
12568 g_return_if_fail (GTK_IS_WIDGET (widget));
12570 no_show_all = (no_show_all != FALSE);
12572 if (widget->priv->no_show_all != no_show_all)
12574 widget->priv->no_show_all = no_show_all;
12576 g_object_notify (G_OBJECT (widget), "no-show-all");
12582 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
12583 gboolean has_tooltip,
12586 GtkWidgetPrivate *priv = widget->priv;
12587 gboolean priv_has_tooltip;
12589 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
12590 quark_has_tooltip));
12592 if (priv_has_tooltip != has_tooltip || force)
12594 priv_has_tooltip = has_tooltip;
12596 if (priv_has_tooltip)
12598 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
12599 gdk_window_set_events (priv->window,
12600 gdk_window_get_events (priv->window) |
12601 GDK_LEAVE_NOTIFY_MASK |
12602 GDK_POINTER_MOTION_MASK |
12603 GDK_POINTER_MOTION_HINT_MASK);
12605 if (gtk_widget_get_has_window (widget))
12606 gtk_widget_add_events (widget,
12607 GDK_LEAVE_NOTIFY_MASK |
12608 GDK_POINTER_MOTION_MASK |
12609 GDK_POINTER_MOTION_HINT_MASK);
12612 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
12613 GUINT_TO_POINTER (priv_has_tooltip));
12618 * gtk_widget_set_tooltip_window:
12619 * @widget: a #GtkWidget
12620 * @custom_window: (allow-none): a #GtkWindow, or %NULL
12622 * Replaces the default, usually yellow, window used for displaying
12623 * tooltips with @custom_window. GTK+ will take care of showing and
12624 * hiding @custom_window at the right moment, to behave likewise as
12625 * the default tooltip window. If @custom_window is %NULL, the default
12626 * tooltip window will be used.
12628 * If the custom window should have the default theming it needs to
12629 * have the name "gtk-tooltip", see gtk_widget_set_name().
12634 gtk_widget_set_tooltip_window (GtkWidget *widget,
12635 GtkWindow *custom_window)
12637 gboolean has_tooltip;
12638 gchar *tooltip_markup;
12640 g_return_if_fail (GTK_IS_WIDGET (widget));
12641 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
12643 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
12646 g_object_ref (custom_window);
12648 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
12649 custom_window, g_object_unref);
12651 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
12652 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
12654 if (has_tooltip && gtk_widget_get_visible (widget))
12655 gtk_widget_queue_tooltip_query (widget);
12659 * gtk_widget_get_tooltip_window:
12660 * @widget: a #GtkWidget
12662 * Returns the #GtkWindow of the current tooltip. This can be the
12663 * GtkWindow created by default, or the custom tooltip window set
12664 * using gtk_widget_set_tooltip_window().
12666 * Return value: (transfer none): The #GtkWindow of the current tooltip.
12671 gtk_widget_get_tooltip_window (GtkWidget *widget)
12673 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12675 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
12679 * gtk_widget_trigger_tooltip_query:
12680 * @widget: a #GtkWidget
12682 * Triggers a tooltip query on the display where the toplevel of @widget
12683 * is located. See gtk_tooltip_trigger_tooltip_query() for more
12689 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
12691 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
12694 static guint tooltip_query_id;
12695 static GSList *tooltip_query_displays;
12698 tooltip_query_idle (gpointer data)
12700 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
12701 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
12702 g_slist_free (tooltip_query_displays);
12704 tooltip_query_displays = NULL;
12705 tooltip_query_id = 0;
12711 gtk_widget_queue_tooltip_query (GtkWidget *widget)
12713 GdkDisplay *display;
12715 display = gtk_widget_get_display (widget);
12717 if (!g_slist_find (tooltip_query_displays, display))
12718 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
12720 if (tooltip_query_id == 0)
12721 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
12725 * gtk_widget_set_tooltip_text:
12726 * @widget: a #GtkWidget
12727 * @text: the contents of the tooltip for @widget
12729 * Sets @text as the contents of the tooltip. This function will take
12730 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
12731 * handler for the #GtkWidget::query-tooltip signal.
12733 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
12738 gtk_widget_set_tooltip_text (GtkWidget *widget,
12741 g_return_if_fail (GTK_IS_WIDGET (widget));
12743 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
12747 * gtk_widget_get_tooltip_text:
12748 * @widget: a #GtkWidget
12750 * Gets the contents of the tooltip for @widget.
12752 * Return value: the tooltip text, or %NULL. You should free the
12753 * returned string with g_free() when done.
12758 gtk_widget_get_tooltip_text (GtkWidget *widget)
12760 gchar *text = NULL;
12762 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12764 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
12770 * gtk_widget_set_tooltip_markup:
12771 * @widget: a #GtkWidget
12772 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
12774 * Sets @markup as the contents of the tooltip, which is marked up with
12775 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
12777 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
12778 * and of the default handler for the #GtkWidget::query-tooltip signal.
12780 * See also the #GtkWidget:tooltip-markup property and
12781 * gtk_tooltip_set_markup().
12786 gtk_widget_set_tooltip_markup (GtkWidget *widget,
12787 const gchar *markup)
12789 g_return_if_fail (GTK_IS_WIDGET (widget));
12791 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
12795 * gtk_widget_get_tooltip_markup:
12796 * @widget: a #GtkWidget
12798 * Gets the contents of the tooltip for @widget.
12800 * Return value: the tooltip text, or %NULL. You should free the
12801 * returned string with g_free() when done.
12806 gtk_widget_get_tooltip_markup (GtkWidget *widget)
12808 gchar *text = NULL;
12810 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12812 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
12818 * gtk_widget_set_has_tooltip:
12819 * @widget: a #GtkWidget
12820 * @has_tooltip: whether or not @widget has a tooltip.
12822 * Sets the has-tooltip property on @widget to @has_tooltip. See
12823 * #GtkWidget:has-tooltip for more information.
12828 gtk_widget_set_has_tooltip (GtkWidget *widget,
12829 gboolean has_tooltip)
12831 g_return_if_fail (GTK_IS_WIDGET (widget));
12833 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
12837 * gtk_widget_get_has_tooltip:
12838 * @widget: a #GtkWidget
12840 * Returns the current value of the has-tooltip property. See
12841 * #GtkWidget:has-tooltip for more information.
12843 * Return value: current value of has-tooltip on @widget.
12848 gtk_widget_get_has_tooltip (GtkWidget *widget)
12850 gboolean has_tooltip = FALSE;
12852 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12854 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
12856 return has_tooltip;
12860 * gtk_widget_get_allocation:
12861 * @widget: a #GtkWidget
12862 * @allocation: (out): a pointer to a #GtkAllocation to copy to
12864 * Retrieves the widget's allocation.
12866 * Note, when implementing a #GtkContainer: a widget's allocation will
12867 * be its "adjusted" allocation, that is, the widget's parent
12868 * container typically calls gtk_widget_size_allocate() with an
12869 * allocation, and that allocation is then adjusted (to handle margin
12870 * and alignment for example) before assignment to the widget.
12871 * gtk_widget_get_allocation() returns the adjusted allocation that
12872 * was actually assigned to the widget. The adjusted allocation is
12873 * guaranteed to be completely contained within the
12874 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
12875 * is guaranteed that its children stay inside the assigned bounds,
12876 * but not that they have exactly the bounds the container assigned.
12877 * There is no way to get the original allocation assigned by
12878 * gtk_widget_size_allocate(), since it isn't stored; if a container
12879 * implementation needs that information it will have to track it itself.
12884 gtk_widget_get_allocation (GtkWidget *widget,
12885 GtkAllocation *allocation)
12887 GtkWidgetPrivate *priv;
12889 g_return_if_fail (GTK_IS_WIDGET (widget));
12890 g_return_if_fail (allocation != NULL);
12892 priv = widget->priv;
12894 *allocation = priv->allocation;
12898 * gtk_widget_set_allocation:
12899 * @widget: a #GtkWidget
12900 * @allocation: a pointer to a #GtkAllocation to copy from
12902 * Sets the widget's allocation. This should not be used
12903 * directly, but from within a widget's size_allocate method.
12905 * The allocation set should be the "adjusted" or actual
12906 * allocation. If you're implementing a #GtkContainer, you want to use
12907 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
12908 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
12909 * allocation inside gtk_widget_size_allocate() to create an adjusted
12915 gtk_widget_set_allocation (GtkWidget *widget,
12916 const GtkAllocation *allocation)
12918 GtkWidgetPrivate *priv;
12920 g_return_if_fail (GTK_IS_WIDGET (widget));
12921 g_return_if_fail (allocation != NULL);
12923 priv = widget->priv;
12925 priv->allocation = *allocation;
12929 * gtk_widget_get_allocated_width:
12930 * @widget: the widget to query
12932 * Returns the width that has currently been allocated to @widget.
12933 * This function is intended to be used when implementing handlers
12934 * for the #GtkWidget::draw function.
12936 * Returns: the width of the @widget
12939 gtk_widget_get_allocated_width (GtkWidget *widget)
12941 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12943 return widget->priv->allocation.width;
12947 * gtk_widget_get_allocated_height:
12948 * @widget: the widget to query
12950 * Returns the height that has currently been allocated to @widget.
12951 * This function is intended to be used when implementing handlers
12952 * for the #GtkWidget::draw function.
12954 * Returns: the height of the @widget
12957 gtk_widget_get_allocated_height (GtkWidget *widget)
12959 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12961 return widget->priv->allocation.height;
12965 * gtk_widget_get_requisition:
12966 * @widget: a #GtkWidget
12967 * @requisition: (out): a pointer to a #GtkRequisition to copy to
12969 * Retrieves the widget's requisition.
12971 * This function should only be used by widget implementations in
12972 * order to figure whether the widget's requisition has actually
12973 * changed after some internal state change (so that they can call
12974 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
12976 * Normally, gtk_widget_size_request() should be used.
12980 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
12981 * removed, If you need to cache sizes across requests and allocations,
12982 * add an explicit cache to the widget in question instead.
12985 gtk_widget_get_requisition (GtkWidget *widget,
12986 GtkRequisition *requisition)
12988 g_return_if_fail (GTK_IS_WIDGET (widget));
12989 g_return_if_fail (requisition != NULL);
12991 gtk_widget_get_preferred_size (widget, requisition, NULL);
12995 * gtk_widget_set_window:
12996 * @widget: a #GtkWidget
12997 * @window: a #GdkWindow
12999 * Sets a widget's window. This function should only be used in a
13000 * widget's #GtkWidget::realize implementation. The %window passed is
13001 * usually either new window created with gdk_window_new(), or the
13002 * window of its parent widget as returned by
13003 * gtk_widget_get_parent_window().
13005 * Widgets must indicate whether they will create their own #GdkWindow
13006 * by calling gtk_widget_set_has_window(). This is usually done in the
13007 * widget's init() function.
13009 * <note><para>This function does not add any reference to @window.</para></note>
13014 gtk_widget_set_window (GtkWidget *widget,
13017 GtkWidgetPrivate *priv;
13019 g_return_if_fail (GTK_IS_WIDGET (widget));
13020 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13022 priv = widget->priv;
13024 if (priv->window != window)
13026 priv->window = window;
13027 g_object_notify (G_OBJECT (widget), "window");
13032 * gtk_widget_get_window:
13033 * @widget: a #GtkWidget
13035 * Returns the widget's window if it is realized, %NULL otherwise
13037 * Return value: (transfer none): @widget's window.
13042 gtk_widget_get_window (GtkWidget *widget)
13044 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13046 return widget->priv->window;
13050 * gtk_widget_get_support_multidevice:
13051 * @widget: a #GtkWidget
13053 * Returns %TRUE if @widget is multiple pointer aware. See
13054 * gtk_widget_set_support_multidevice() for more information.
13056 * Returns: %TRUE is @widget is multidevice aware.
13059 gtk_widget_get_support_multidevice (GtkWidget *widget)
13061 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13063 return widget->priv->multidevice;
13067 * gtk_widget_set_support_multidevice:
13068 * @widget: a #GtkWidget
13069 * @support_multidevice: %TRUE to support input from multiple devices.
13071 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13072 * @widget will start receiving multiple, per device enter/leave events. Note
13073 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13074 * gdk_window_set_support_multidevice() will have to be called manually on them.
13079 gtk_widget_set_support_multidevice (GtkWidget *widget,
13080 gboolean support_multidevice)
13082 GtkWidgetPrivate *priv;
13084 g_return_if_fail (GTK_IS_WIDGET (widget));
13086 priv = widget->priv;
13088 if (support_multidevice)
13090 priv->multidevice = TRUE;
13091 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
13095 priv->multidevice = FALSE;
13096 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
13099 if (gtk_widget_get_realized (widget))
13100 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13104 _gtk_widget_set_has_focus (GtkWidget *widget,
13105 gboolean has_focus)
13107 widget->priv->has_focus = has_focus;
13111 * gtk_widget_send_focus_change:
13112 * @widget: a #GtkWidget
13113 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13115 * Sends the focus change @event to @widget
13117 * This function is not meant to be used by applications. The only time it
13118 * should be used is when it is necessary for a #GtkWidget to assign focus
13119 * to a widget that is semantically owned by the first widget even though
13120 * it's not a direct child - for instance, a search entry in a floating
13121 * window similar to the quick search in #GtkTreeView.
13123 * An example of its usage is:
13126 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13128 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13129 * fevent->focus_change.in = TRUE;
13130 * fevent->focus_change.window = gtk_widget_get_window (widget);
13131 * if (fevent->focus_change.window != NULL)
13132 * g_object_ref (fevent->focus_change.window);
13134 * gtk_widget_send_focus_change (widget, fevent);
13136 * gdk_event_free (event);
13139 * Return value: the return value from the event signal emission: %TRUE
13140 * if the event was handled, and %FALSE otherwise
13145 gtk_widget_send_focus_change (GtkWidget *widget,
13150 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13151 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13153 g_object_ref (widget);
13155 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13157 res = gtk_widget_event (widget, event);
13159 g_object_notify (G_OBJECT (widget), "has-focus");
13161 g_object_unref (widget);
13167 * gtk_widget_in_destruction:
13168 * @widget: a #GtkWidget
13170 * Returns whether the widget is currently being destroyed.
13171 * This information can sometimes be used to avoid doing
13172 * unnecessary work.
13174 * Returns: %TRUE if @widget is being destroyed
13177 gtk_widget_in_destruction (GtkWidget *widget)
13179 return widget->priv->in_destruction;
13183 _gtk_widget_get_resize_pending (GtkWidget *widget)
13185 return widget->priv->resize_pending;
13189 _gtk_widget_set_resize_pending (GtkWidget *widget,
13190 gboolean resize_pending)
13192 widget->priv->resize_pending = resize_pending;
13196 _gtk_widget_get_in_reparent (GtkWidget *widget)
13198 return widget->priv->in_reparent;
13202 _gtk_widget_set_in_reparent (GtkWidget *widget,
13203 gboolean in_reparent)
13205 widget->priv->in_reparent = in_reparent;
13209 _gtk_widget_get_anchored (GtkWidget *widget)
13211 return widget->priv->anchored;
13215 _gtk_widget_set_anchored (GtkWidget *widget,
13218 widget->priv->anchored = anchored;
13222 _gtk_widget_get_shadowed (GtkWidget *widget)
13224 return widget->priv->shadowed;
13228 _gtk_widget_set_shadowed (GtkWidget *widget,
13231 widget->priv->shadowed = shadowed;
13235 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13237 return widget->priv->alloc_needed;
13241 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13242 gboolean alloc_needed)
13244 widget->priv->alloc_needed = alloc_needed;
13248 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13250 return widget->priv->width_request_needed;
13254 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13255 gboolean width_request_needed)
13257 widget->priv->width_request_needed = width_request_needed;
13261 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13263 return widget->priv->height_request_needed;
13267 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13268 gboolean height_request_needed)
13270 widget->priv->height_request_needed = height_request_needed;
13274 * gtk_widget_get_path:
13275 * @widget: a #GtkWidget
13277 * Returns the #GtkWidgetPath representing @widget, if the widget
13278 * is not connected to a toplevel widget, a partial path will be
13281 * Returns: (transfer none): The #GtkWidgetPath representing @widget
13284 gtk_widget_get_path (GtkWidget *widget)
13286 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13288 if (!widget->priv->path)
13293 parent = widget->priv->parent;
13296 widget->priv->path = gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
13299 /* Widget is either toplevel or unparented, treat both
13300 * as toplevels style wise, since there are situations
13301 * where style properties might be retrieved on that
13304 widget->priv->path = gtk_widget_path_new ();
13307 pos = gtk_widget_path_append_type (widget->priv->path, G_OBJECT_TYPE (widget));
13309 if (widget->priv->name)
13310 gtk_widget_path_iter_set_name (widget->priv->path, pos, widget->priv->name);
13313 return widget->priv->path;
13317 style_context_changed (GtkStyleContext *context,
13318 gpointer user_data)
13320 GtkWidget *widget = user_data;
13322 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
13326 * gtk_widget_get_style_context:
13327 * @widget: a #GtkWidget
13329 * Returns the style context associated to @widget.
13331 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
13332 * must not be freed.
13335 gtk_widget_get_style_context (GtkWidget *widget)
13337 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13339 if (G_UNLIKELY (!widget->priv->context))
13341 widget->priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
13342 "direction", gtk_widget_get_direction (widget),
13345 g_signal_connect (widget->priv->context, "changed",
13346 G_CALLBACK (style_context_changed), widget);
13348 gtk_style_context_set_screen (widget->priv->context,
13349 gtk_widget_get_screen (widget));
13351 _gtk_widget_update_path (widget);
13352 gtk_style_context_set_path (widget->priv->context,
13353 widget->priv->path);
13356 return widget->priv->context;