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.
361 /* The widget's allocated size.
363 GtkAllocation allocation;
365 /* The widget's requested sizes */
366 SizeRequestCache requests;
368 /* The widget's window or its parent window if it does
369 * not have a window. (Which will be indicated by the
370 * GTK_NO_WINDOW flag being set).
374 /* The widget's parent.
404 BUTTON_RELEASE_EVENT,
419 PROPERTY_NOTIFY_EVENT,
420 SELECTION_CLEAR_EVENT,
421 SELECTION_REQUEST_EVENT,
422 SELECTION_NOTIFY_EVENT,
428 VISIBILITY_NOTIFY_EVENT,
442 ACCEL_CLOSURES_CHANGED,
466 PROP_RECEIVES_DEFAULT,
467 PROP_COMPOSITE_CHILD,
470 PROP_EXTENSION_EVENTS,
476 PROP_DOUBLE_BUFFERED,
491 typedef struct _GtkStateData GtkStateData;
496 guint state_restoration : 1;
497 guint parent_sensitive : 1;
498 guint use_forall : 1;
501 /* --- prototypes --- */
502 static void gtk_widget_class_init (GtkWidgetClass *klass);
503 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
504 static void gtk_widget_init (GtkWidget *widget);
505 static void gtk_widget_set_property (GObject *object,
509 static void gtk_widget_get_property (GObject *object,
513 static void gtk_widget_dispose (GObject *object);
514 static void gtk_widget_real_destroy (GtkWidget *object);
515 static void gtk_widget_finalize (GObject *object);
516 static void gtk_widget_real_show (GtkWidget *widget);
517 static void gtk_widget_real_hide (GtkWidget *widget);
518 static void gtk_widget_real_map (GtkWidget *widget);
519 static void gtk_widget_real_unmap (GtkWidget *widget);
520 static void gtk_widget_real_realize (GtkWidget *widget);
521 static void gtk_widget_real_unrealize (GtkWidget *widget);
522 static void gtk_widget_real_size_allocate (GtkWidget *widget,
523 GtkAllocation *allocation);
524 static void gtk_widget_real_style_set (GtkWidget *widget,
525 GtkStyle *previous_style);
526 static void gtk_widget_real_direction_changed(GtkWidget *widget,
527 GtkTextDirection previous_direction);
529 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
530 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
533 gboolean keyboard_tip,
534 GtkTooltip *tooltip);
535 static void gtk_widget_real_style_updated (GtkWidget *widget);
536 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
537 GtkWidgetHelpType help_type);
539 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
541 GParamSpec **pspecs);
542 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
544 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
546 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
547 GdkEventFocus *event);
548 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
549 GdkEventFocus *event);
550 static gboolean gtk_widget_real_focus (GtkWidget *widget,
551 GtkDirectionType direction);
552 static void gtk_widget_real_move_focus (GtkWidget *widget,
553 GtkDirectionType direction);
554 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
555 GtkDirectionType direction);
556 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
557 static void gtk_widget_update_pango_context (GtkWidget *widget);
558 static void gtk_widget_propagate_state (GtkWidget *widget,
560 static void gtk_widget_reset_rc_style (GtkWidget *widget);
561 static void gtk_widget_set_style_internal (GtkWidget *widget,
563 gboolean initial_emission);
564 static gint gtk_widget_event_internal (GtkWidget *widget,
566 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
567 gboolean group_cycling);
568 static void gtk_widget_real_get_width (GtkWidget *widget,
571 static void gtk_widget_real_get_height (GtkWidget *widget,
574 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
576 gint *minimum_height,
577 gint *natural_height);
578 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
581 gint *natural_width);
582 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
583 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
584 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
585 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
586 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
587 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
588 cairo_region_t *region);
589 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
590 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
591 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
594 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
595 gboolean has_tooltip,
597 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
598 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
600 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
601 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
603 const gchar *childname);
604 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
607 const GValue *value);
608 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
611 const gchar *tagname,
612 GMarkupParser *parser,
614 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
617 const gchar *tagname,
619 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
620 GtkBuilder *builder);
622 static void gtk_widget_real_get_width (GtkWidget *widget,
625 static void gtk_widget_real_get_height (GtkWidget *widget,
629 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
632 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
633 GtkOrientation orientation,
636 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
637 GtkOrientation orientation,
640 gint *allocated_size);
642 static void gtk_widget_set_usize_internal (GtkWidget *widget,
645 GtkQueueResizeFlags flags);
647 static void gtk_widget_add_events_internal (GtkWidget *widget,
651 /* --- variables --- */
652 static gpointer gtk_widget_parent_class = NULL;
653 static guint widget_signals[LAST_SIGNAL] = { 0 };
654 static GtkStyle *gtk_default_style = NULL;
655 static guint composite_child_stack = 0;
656 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
657 static GParamSpecPool *style_property_spec_pool = NULL;
659 static GQuark quark_property_parser = 0;
660 static GQuark quark_aux_info = 0;
661 static GQuark quark_accel_path = 0;
662 static GQuark quark_accel_closures = 0;
663 static GQuark quark_event_mask = 0;
664 static GQuark quark_device_event_mask = 0;
665 static GQuark quark_extension_event_mode = 0;
666 static GQuark quark_parent_window = 0;
667 static GQuark quark_pointer_window = 0;
668 static GQuark quark_shape_info = 0;
669 static GQuark quark_input_shape_info = 0;
670 static GQuark quark_pango_context = 0;
671 static GQuark quark_rc_style = 0;
672 static GQuark quark_accessible_object = 0;
673 static GQuark quark_mnemonic_labels = 0;
674 static GQuark quark_tooltip_markup = 0;
675 static GQuark quark_has_tooltip = 0;
676 static GQuark quark_tooltip_window = 0;
677 static GQuark quark_visual = 0;
678 static GQuark quark_style_context = 0;
679 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
680 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
682 /* --- functions --- */
684 gtk_widget_get_type (void)
686 static GType widget_type = 0;
688 if (G_UNLIKELY (widget_type == 0))
690 const GTypeInfo widget_info =
692 sizeof (GtkWidgetClass),
693 NULL, /* base_init */
694 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
695 (GClassInitFunc) gtk_widget_class_init,
696 NULL, /* class_finalize */
697 NULL, /* class_init */
700 (GInstanceInitFunc) gtk_widget_init,
701 NULL, /* value_table */
704 const GInterfaceInfo accessibility_info =
706 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
707 (GInterfaceFinalizeFunc) NULL,
708 NULL /* interface data */
711 const GInterfaceInfo buildable_info =
713 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
714 (GInterfaceFinalizeFunc) NULL,
715 NULL /* interface data */
718 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
719 &widget_info, G_TYPE_FLAG_ABSTRACT);
721 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
722 &accessibility_info) ;
723 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
731 child_property_notify_dispatcher (GObject *object,
735 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
738 /* We guard against the draw signal callbacks modifying the state of the
739 * cairo context by surounding it with save/restore.
740 * Maybe we should also cairo_new_path() just to be sure?
743 gtk_widget_draw_marshaller (GClosure *closure,
744 GValue *return_value,
745 guint n_param_values,
746 const GValue *param_values,
747 gpointer invocation_hint,
748 gpointer marshal_data)
750 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
754 _gtk_marshal_BOOLEAN__BOXED (closure,
765 gtk_widget_class_init (GtkWidgetClass *klass)
767 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
768 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
769 GtkBindingSet *binding_set;
771 gtk_widget_parent_class = g_type_class_peek_parent (klass);
773 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
774 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
775 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
776 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
777 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
778 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
779 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
780 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
781 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
782 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
783 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
784 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
785 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
786 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
787 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
788 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
789 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
790 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
791 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
792 quark_style_context = g_quark_from_static_string ("gtk-style-context");
794 style_property_spec_pool = g_param_spec_pool_new (FALSE);
795 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
796 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
797 cpn_context.dispatcher = child_property_notify_dispatcher;
798 _gtk_widget_child_property_notify_context = &cpn_context;
800 gobject_class->dispose = gtk_widget_dispose;
801 gobject_class->finalize = gtk_widget_finalize;
802 gobject_class->set_property = gtk_widget_set_property;
803 gobject_class->get_property = gtk_widget_get_property;
805 klass->destroy = gtk_widget_real_destroy;
807 klass->activate_signal = 0;
808 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
809 klass->show = gtk_widget_real_show;
810 klass->show_all = gtk_widget_show;
811 klass->hide = gtk_widget_real_hide;
812 klass->map = gtk_widget_real_map;
813 klass->unmap = gtk_widget_real_unmap;
814 klass->realize = gtk_widget_real_realize;
815 klass->unrealize = gtk_widget_real_unrealize;
816 klass->size_allocate = gtk_widget_real_size_allocate;
817 klass->get_preferred_width = gtk_widget_real_get_width;
818 klass->get_preferred_height = gtk_widget_real_get_height;
819 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
820 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
821 klass->state_changed = NULL;
822 klass->parent_set = NULL;
823 klass->hierarchy_changed = NULL;
824 klass->style_set = gtk_widget_real_style_set;
825 klass->direction_changed = gtk_widget_real_direction_changed;
826 klass->grab_notify = NULL;
827 klass->child_notify = NULL;
829 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
830 klass->grab_focus = gtk_widget_real_grab_focus;
831 klass->focus = gtk_widget_real_focus;
832 klass->move_focus = gtk_widget_real_move_focus;
833 klass->keynav_failed = gtk_widget_real_keynav_failed;
835 klass->button_press_event = NULL;
836 klass->button_release_event = NULL;
837 klass->motion_notify_event = NULL;
838 klass->delete_event = NULL;
839 klass->destroy_event = NULL;
840 klass->key_press_event = gtk_widget_real_key_press_event;
841 klass->key_release_event = gtk_widget_real_key_release_event;
842 klass->enter_notify_event = NULL;
843 klass->leave_notify_event = NULL;
844 klass->configure_event = NULL;
845 klass->focus_in_event = gtk_widget_real_focus_in_event;
846 klass->focus_out_event = gtk_widget_real_focus_out_event;
847 klass->map_event = NULL;
848 klass->unmap_event = NULL;
849 klass->window_state_event = NULL;
850 klass->property_notify_event = _gtk_selection_property_notify;
851 klass->selection_clear_event = _gtk_selection_clear;
852 klass->selection_request_event = _gtk_selection_request;
853 klass->selection_notify_event = _gtk_selection_notify;
854 klass->selection_received = NULL;
855 klass->proximity_in_event = NULL;
856 klass->proximity_out_event = NULL;
857 klass->drag_begin = NULL;
858 klass->drag_end = NULL;
859 klass->drag_data_delete = NULL;
860 klass->drag_leave = NULL;
861 klass->drag_motion = NULL;
862 klass->drag_drop = NULL;
863 klass->drag_data_received = NULL;
864 klass->screen_changed = NULL;
865 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
866 klass->grab_broken_event = NULL;
867 klass->query_tooltip = gtk_widget_real_query_tooltip;
868 klass->style_updated = gtk_widget_real_style_updated;
870 klass->show_help = gtk_widget_real_show_help;
872 /* Accessibility support */
873 klass->get_accessible = gtk_widget_real_get_accessible;
875 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
876 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
878 g_object_class_install_property (gobject_class,
880 g_param_spec_string ("name",
882 P_("The name of the widget"),
884 GTK_PARAM_READWRITE));
885 g_object_class_install_property (gobject_class,
887 g_param_spec_object ("parent",
889 P_("The parent widget of this widget. Must be a Container widget"),
891 GTK_PARAM_READWRITE));
893 g_object_class_install_property (gobject_class,
895 g_param_spec_int ("width-request",
897 P_("Override for width request of the widget, or -1 if natural request should be used"),
901 GTK_PARAM_READWRITE));
902 g_object_class_install_property (gobject_class,
904 g_param_spec_int ("height-request",
905 P_("Height request"),
906 P_("Override for height request of the widget, or -1 if natural request should be used"),
910 GTK_PARAM_READWRITE));
911 g_object_class_install_property (gobject_class,
913 g_param_spec_boolean ("visible",
915 P_("Whether the widget is visible"),
917 GTK_PARAM_READWRITE));
918 g_object_class_install_property (gobject_class,
920 g_param_spec_boolean ("sensitive",
922 P_("Whether the widget responds to input"),
924 GTK_PARAM_READWRITE));
925 g_object_class_install_property (gobject_class,
927 g_param_spec_boolean ("app-paintable",
928 P_("Application paintable"),
929 P_("Whether the application will paint directly on the widget"),
931 GTK_PARAM_READWRITE));
932 g_object_class_install_property (gobject_class,
934 g_param_spec_boolean ("can-focus",
936 P_("Whether the widget can accept the input focus"),
938 GTK_PARAM_READWRITE));
939 g_object_class_install_property (gobject_class,
941 g_param_spec_boolean ("has-focus",
943 P_("Whether the widget has the input focus"),
945 GTK_PARAM_READWRITE));
946 g_object_class_install_property (gobject_class,
948 g_param_spec_boolean ("is-focus",
950 P_("Whether the widget is the focus widget within the toplevel"),
952 GTK_PARAM_READWRITE));
953 g_object_class_install_property (gobject_class,
955 g_param_spec_boolean ("can-default",
957 P_("Whether the widget can be the default widget"),
959 GTK_PARAM_READWRITE));
960 g_object_class_install_property (gobject_class,
962 g_param_spec_boolean ("has-default",
964 P_("Whether the widget is the default widget"),
966 GTK_PARAM_READWRITE));
967 g_object_class_install_property (gobject_class,
968 PROP_RECEIVES_DEFAULT,
969 g_param_spec_boolean ("receives-default",
970 P_("Receives default"),
971 P_("If TRUE, the widget will receive the default action when it is focused"),
973 GTK_PARAM_READWRITE));
974 g_object_class_install_property (gobject_class,
975 PROP_COMPOSITE_CHILD,
976 g_param_spec_boolean ("composite-child",
977 P_("Composite child"),
978 P_("Whether the widget is part of a composite widget"),
980 GTK_PARAM_READABLE));
981 g_object_class_install_property (gobject_class,
983 g_param_spec_object ("style",
985 P_("The style of the widget, which contains information about how it will look (colors etc)"),
987 GTK_PARAM_READWRITE));
988 g_object_class_install_property (gobject_class,
990 g_param_spec_flags ("events",
992 P_("The event mask that decides what kind of GdkEvents this widget gets"),
995 GTK_PARAM_READWRITE));
996 g_object_class_install_property (gobject_class,
997 PROP_EXTENSION_EVENTS,
998 g_param_spec_enum ("extension-events",
999 P_("Extension events"),
1000 P_("The mask that decides what kind of extension events this widget gets"),
1001 GDK_TYPE_EXTENSION_MODE,
1002 GDK_EXTENSION_EVENTS_NONE,
1003 GTK_PARAM_READWRITE));
1004 g_object_class_install_property (gobject_class,
1006 g_param_spec_boolean ("no-show-all",
1008 P_("Whether gtk_widget_show_all() should not affect this widget"),
1010 GTK_PARAM_READWRITE));
1013 * GtkWidget:has-tooltip:
1015 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1016 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1017 * the widget will be queried using #GtkWidget::query-tooltip to determine
1018 * whether it will provide a tooltip or not.
1020 * Note that setting this property to %TRUE for the first time will change
1021 * the event masks of the GdkWindows of this widget to include leave-notify
1022 * and motion-notify events. This cannot and will not be undone when the
1023 * property is set to %FALSE again.
1027 g_object_class_install_property (gobject_class,
1029 g_param_spec_boolean ("has-tooltip",
1031 P_("Whether this widget has a tooltip"),
1033 GTK_PARAM_READWRITE));
1035 * GtkWidget:tooltip-text:
1037 * Sets the text of tooltip to be the given string.
1039 * Also see gtk_tooltip_set_text().
1041 * This is a convenience property which will take care of getting the
1042 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1043 * will automatically be set to %TRUE and there will be taken care of
1044 * #GtkWidget::query-tooltip in the default signal handler.
1048 g_object_class_install_property (gobject_class,
1050 g_param_spec_string ("tooltip-text",
1052 P_("The contents of the tooltip for this widget"),
1054 GTK_PARAM_READWRITE));
1056 * GtkWidget:tooltip-markup:
1058 * Sets the text of tooltip to be the given string, which is marked up
1059 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1060 * Also see gtk_tooltip_set_markup().
1062 * This is a convenience property which will take care of getting the
1063 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1064 * will automatically be set to %TRUE and there will be taken care of
1065 * #GtkWidget::query-tooltip in the default signal handler.
1069 g_object_class_install_property (gobject_class,
1070 PROP_TOOLTIP_MARKUP,
1071 g_param_spec_string ("tooltip-markup",
1072 P_("Tooltip markup"),
1073 P_("The contents of the tooltip for this widget"),
1075 GTK_PARAM_READWRITE));
1080 * The widget's window if it is realized, %NULL otherwise.
1084 g_object_class_install_property (gobject_class,
1086 g_param_spec_object ("window",
1088 P_("The widget's window if it is realized"),
1090 GTK_PARAM_READABLE));
1093 * GtkWidget:double-buffered
1095 * Whether the widget is double buffered.
1099 g_object_class_install_property (gobject_class,
1100 PROP_DOUBLE_BUFFERED,
1101 g_param_spec_boolean ("double-buffered",
1102 P_("Double Buffered"),
1103 P_("Whether the widget is double buffered"),
1105 GTK_PARAM_READWRITE));
1110 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1114 g_object_class_install_property (gobject_class,
1116 g_param_spec_enum ("halign",
1117 P_("Horizontal Alignment"),
1118 P_("How to position in extra horizontal space"),
1121 GTK_PARAM_READWRITE));
1126 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1130 g_object_class_install_property (gobject_class,
1132 g_param_spec_enum ("valign",
1133 P_("Vertical Alignment"),
1134 P_("How to position in extra vertical space"),
1137 GTK_PARAM_READWRITE));
1140 * GtkWidget:margin-left
1142 * Margin on left side of widget.
1144 * This property adds margin outside of the widget's normal size
1145 * request, the margin will be added in addition to the size from
1146 * gtk_widget_set_size_request() for example.
1150 g_object_class_install_property (gobject_class,
1152 g_param_spec_int ("margin-left",
1153 P_("Margin on Left"),
1154 P_("Pixels of extra space on the left side"),
1158 GTK_PARAM_READWRITE));
1161 * GtkWidget:margin-right
1163 * Margin on right side of widget.
1165 * This property adds margin outside of the widget's normal size
1166 * request, the margin will be added in addition to the size from
1167 * gtk_widget_set_size_request() for example.
1171 g_object_class_install_property (gobject_class,
1173 g_param_spec_int ("margin-right",
1174 P_("Margin on Right"),
1175 P_("Pixels of extra space on the right side"),
1179 GTK_PARAM_READWRITE));
1182 * GtkWidget:margin-top
1184 * Margin on top side of widget.
1186 * This property adds margin outside of the widget's normal size
1187 * request, the margin will be added in addition to the size from
1188 * gtk_widget_set_size_request() for example.
1192 g_object_class_install_property (gobject_class,
1194 g_param_spec_int ("margin-top",
1195 P_("Margin on Top"),
1196 P_("Pixels of extra space on the top side"),
1200 GTK_PARAM_READWRITE));
1203 * GtkWidget:margin-bottom
1205 * Margin on bottom side of widget.
1207 * This property adds margin outside of the widget's normal size
1208 * request, the margin will be added in addition to the size from
1209 * gtk_widget_set_size_request() for example.
1213 g_object_class_install_property (gobject_class,
1215 g_param_spec_int ("margin-bottom",
1216 P_("Margin on Bottom"),
1217 P_("Pixels of extra space on the bottom side"),
1221 GTK_PARAM_READWRITE));
1226 * Sets all four sides' margin at once. If read, returns max
1227 * margin on any side.
1231 g_object_class_install_property (gobject_class,
1233 g_param_spec_int ("margin",
1235 P_("Pixels of extra space on all four sides"),
1239 GTK_PARAM_READWRITE));
1242 * GtkWidget::destroy:
1243 * @object: the object which received the signal
1245 * Signals that all holders of a reference to the widget should release
1246 * the reference that they hold. May result in finalization of the widget
1247 * if all references are released.
1249 widget_signals[DESTROY] =
1250 g_signal_new (I_("destroy"),
1251 G_TYPE_FROM_CLASS (gobject_class),
1252 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1253 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1255 _gtk_marshal_VOID__VOID,
1261 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1265 g_object_class_install_property (gobject_class,
1267 g_param_spec_boolean ("hexpand",
1268 P_("Horizontal Expand"),
1269 P_("Whether widget wants more horizontal space"),
1271 GTK_PARAM_READWRITE));
1274 * GtkWidget:hexpand-set
1276 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1280 g_object_class_install_property (gobject_class,
1282 g_param_spec_boolean ("hexpand-set",
1283 P_("Horizontal Expand Set"),
1284 P_("Whether to use the hexpand property"),
1286 GTK_PARAM_READWRITE));
1291 * Whether to expand vertically. See gtk_widget_set_vexpand().
1295 g_object_class_install_property (gobject_class,
1297 g_param_spec_boolean ("vexpand",
1298 P_("Vertical Expand"),
1299 P_("Whether widget wants more vertical space"),
1301 GTK_PARAM_READWRITE));
1304 * GtkWidget:vexpand-set
1306 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1310 g_object_class_install_property (gobject_class,
1312 g_param_spec_boolean ("vexpand-set",
1313 P_("Vertical Expand Set"),
1314 P_("Whether to use the vexpand property"),
1316 GTK_PARAM_READWRITE));
1321 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1325 g_object_class_install_property (gobject_class,
1327 g_param_spec_boolean ("expand",
1329 P_("Whether widget wants to expand in both directions"),
1331 GTK_PARAM_READWRITE));
1335 * @widget: the object which received the signal.
1337 widget_signals[SHOW] =
1338 g_signal_new (I_("show"),
1339 G_TYPE_FROM_CLASS (gobject_class),
1341 G_STRUCT_OFFSET (GtkWidgetClass, show),
1343 _gtk_marshal_VOID__VOID,
1348 * @widget: the object which received the signal.
1350 widget_signals[HIDE] =
1351 g_signal_new (I_("hide"),
1352 G_TYPE_FROM_CLASS (gobject_class),
1354 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1356 _gtk_marshal_VOID__VOID,
1361 * @widget: the object which received the signal.
1363 widget_signals[MAP] =
1364 g_signal_new (I_("map"),
1365 G_TYPE_FROM_CLASS (gobject_class),
1367 G_STRUCT_OFFSET (GtkWidgetClass, map),
1369 _gtk_marshal_VOID__VOID,
1374 * @widget: the object which received the signal.
1376 widget_signals[UNMAP] =
1377 g_signal_new (I_("unmap"),
1378 G_TYPE_FROM_CLASS (gobject_class),
1380 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1382 _gtk_marshal_VOID__VOID,
1386 * GtkWidget::realize:
1387 * @widget: the object which received the signal.
1389 widget_signals[REALIZE] =
1390 g_signal_new (I_("realize"),
1391 G_TYPE_FROM_CLASS (gobject_class),
1393 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1395 _gtk_marshal_VOID__VOID,
1399 * GtkWidget::unrealize:
1400 * @widget: the object which received the signal.
1402 widget_signals[UNREALIZE] =
1403 g_signal_new (I_("unrealize"),
1404 G_TYPE_FROM_CLASS (gobject_class),
1406 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1408 _gtk_marshal_VOID__VOID,
1412 * GtkWidget::size-allocate:
1413 * @widget: the object which received the signal.
1416 widget_signals[SIZE_ALLOCATE] =
1417 g_signal_new (I_("size-allocate"),
1418 G_TYPE_FROM_CLASS (gobject_class),
1420 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1422 _gtk_marshal_VOID__BOXED,
1424 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1427 * GtkWidget::state-changed:
1428 * @widget: the object which received the signal.
1429 * @state: the previous state
1431 * The ::state-changed signal is emitted when the widget state changes.
1432 * See gtk_widget_get_state().
1434 widget_signals[STATE_CHANGED] =
1435 g_signal_new (I_("state-changed"),
1436 G_TYPE_FROM_CLASS (gobject_class),
1438 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1440 _gtk_marshal_VOID__ENUM,
1442 GTK_TYPE_STATE_TYPE);
1445 * GtkWidget::parent-set:
1446 * @widget: the object on which the signal is emitted
1447 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1448 * just got its initial parent.
1450 * The ::parent-set signal is emitted when a new parent
1451 * has been set on a widget.
1453 widget_signals[PARENT_SET] =
1454 g_signal_new (I_("parent-set"),
1455 G_TYPE_FROM_CLASS (gobject_class),
1457 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1459 _gtk_marshal_VOID__OBJECT,
1464 * GtkWidget::hierarchy-changed:
1465 * @widget: the object on which the signal is emitted
1466 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1467 * if the widget was previously unanchored
1469 * The ::hierarchy-changed signal is emitted when the
1470 * anchored state of a widget changes. A widget is
1471 * <firstterm>anchored</firstterm> when its toplevel
1472 * ancestor is a #GtkWindow. This signal is emitted when
1473 * a widget changes from un-anchored to anchored or vice-versa.
1475 widget_signals[HIERARCHY_CHANGED] =
1476 g_signal_new (I_("hierarchy-changed"),
1477 G_TYPE_FROM_CLASS (gobject_class),
1479 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1481 _gtk_marshal_VOID__OBJECT,
1486 * GtkWidget::style-set:
1487 * @widget: the object on which the signal is emitted
1488 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1489 * just got its initial style
1491 * The ::style-set signal is emitted when a new style has been set
1492 * on a widget. Note that style-modifying functions like
1493 * gtk_widget_modify_base() also cause this signal to be emitted.
1495 widget_signals[STYLE_SET] =
1496 g_signal_new (I_("style-set"),
1497 G_TYPE_FROM_CLASS (gobject_class),
1499 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1501 _gtk_marshal_VOID__OBJECT,
1505 widget_signals[STYLE_UPDATED] =
1506 g_signal_new (I_("style-updated"),
1507 G_TYPE_FROM_CLASS (gobject_class),
1509 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1511 g_cclosure_marshal_VOID__VOID,
1515 * GtkWidget::direction-changed:
1516 * @widget: the object on which the signal is emitted
1517 * @previous_direction: the previous text direction of @widget
1519 * The ::direction-changed signal is emitted when the text direction
1520 * of a widget changes.
1522 widget_signals[DIRECTION_CHANGED] =
1523 g_signal_new (I_("direction-changed"),
1524 G_TYPE_FROM_CLASS (gobject_class),
1526 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1528 _gtk_marshal_VOID__ENUM,
1530 GTK_TYPE_TEXT_DIRECTION);
1533 * GtkWidget::grab-notify:
1534 * @widget: the object which received the signal
1535 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1536 * if it becomes unshadowed
1538 * The ::grab-notify signal is emitted when a widget becomes
1539 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1540 * another widget, or when it becomes unshadowed due to a grab
1543 * A widget is shadowed by a gtk_grab_add() when the topmost
1544 * grab widget in the grab stack of its window group is not
1547 widget_signals[GRAB_NOTIFY] =
1548 g_signal_new (I_("grab-notify"),
1549 G_TYPE_FROM_CLASS (gobject_class),
1551 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1553 _gtk_marshal_VOID__BOOLEAN,
1558 * GtkWidget::child-notify:
1559 * @widget: the object which received the signal
1560 * @pspec: the #GParamSpec of the changed child property
1562 * The ::child-notify signal is emitted for each
1563 * <link linkend="child-properties">child property</link> that has
1564 * changed on an object. The signal's detail holds the property name.
1566 widget_signals[CHILD_NOTIFY] =
1567 g_signal_new (I_("child-notify"),
1568 G_TYPE_FROM_CLASS (gobject_class),
1569 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1570 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1572 g_cclosure_marshal_VOID__PARAM,
1578 * @widget: the object which received the signal
1579 * @cr: the cairo context to draw to
1581 * This signal is emitted when a widget is supposed to render itself.
1582 * The @widget's top left corner must be painted at the origin of
1583 * the passed in context and be sized to the values returned by
1584 * gtk_widget_get_allocated_width() and
1585 * gtk_widget_get_allocated_height().
1587 * Signal handlers connected to this signal can modify the cairo
1588 * context passed as @cr in any way they like and don't need to
1589 * restore it. The signal emission takes care of calling cairo_save()
1590 * before and cairo_restore() after invoking the handler.
1592 widget_signals[DRAW] =
1593 g_signal_new (I_("draw"),
1594 G_TYPE_FROM_CLASS (gobject_class),
1596 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1597 _gtk_boolean_handled_accumulator, NULL,
1598 gtk_widget_draw_marshaller,
1600 CAIRO_GOBJECT_TYPE_CONTEXT);
1603 * GtkWidget::mnemonic-activate:
1604 * @widget: the object which received the signal.
1607 widget_signals[MNEMONIC_ACTIVATE] =
1608 g_signal_new (I_("mnemonic-activate"),
1609 G_TYPE_FROM_CLASS (gobject_class),
1611 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1612 _gtk_boolean_handled_accumulator, NULL,
1613 _gtk_marshal_BOOLEAN__BOOLEAN,
1618 * GtkWidget::grab-focus:
1619 * @widget: the object which received the signal.
1621 widget_signals[GRAB_FOCUS] =
1622 g_signal_new (I_("grab-focus"),
1623 G_TYPE_FROM_CLASS (gobject_class),
1624 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1625 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1627 _gtk_marshal_VOID__VOID,
1632 * @widget: the object which received the signal.
1635 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1637 widget_signals[FOCUS] =
1638 g_signal_new (I_("focus"),
1639 G_TYPE_FROM_CLASS (klass),
1641 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1642 _gtk_boolean_handled_accumulator, NULL,
1643 _gtk_marshal_BOOLEAN__ENUM,
1645 GTK_TYPE_DIRECTION_TYPE);
1648 * GtkWidget::move-focus:
1649 * @widget: the object which received the signal.
1652 widget_signals[MOVE_FOCUS] =
1653 g_signal_new (I_("move-focus"),
1654 G_TYPE_FROM_CLASS (klass),
1655 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1656 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1658 _gtk_marshal_VOID__ENUM,
1661 GTK_TYPE_DIRECTION_TYPE);
1664 * GtkWidget::keynav-failed:
1665 * @widget: the object which received the signal
1666 * @direction: the direction of movement
1668 * Gets emitted if keyboard navigation fails.
1669 * See gtk_widget_keynav_failed() for details.
1671 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1672 * if the emitting widget should try to handle the keyboard
1673 * navigation attempt in its parent container(s).
1677 widget_signals[KEYNAV_FAILED] =
1678 g_signal_new (I_("keynav-failed"),
1679 G_TYPE_FROM_CLASS (klass),
1681 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1682 _gtk_boolean_handled_accumulator, NULL,
1683 _gtk_marshal_BOOLEAN__ENUM,
1685 GTK_TYPE_DIRECTION_TYPE);
1689 * @widget: the object which received the signal.
1690 * @event: the #GdkEvent which triggered this signal
1692 * The GTK+ main loop will emit three signals for each GDK event delivered
1693 * to a widget: one generic ::event signal, another, more specific,
1694 * signal that matches the type of event delivered (e.g.
1695 * #GtkWidget::key-press-event) and finally a generic
1696 * #GtkWidget::event-after signal.
1698 * Returns: %TRUE to stop other handlers from being invoked for the event
1699 * and to cancel the emission of the second specific ::event signal.
1700 * %FALSE to propagate the event further and to allow the emission of
1701 * the second signal. The ::event-after signal is emitted regardless of
1704 widget_signals[EVENT] =
1705 g_signal_new (I_("event"),
1706 G_TYPE_FROM_CLASS (klass),
1708 G_STRUCT_OFFSET (GtkWidgetClass, event),
1709 _gtk_boolean_handled_accumulator, NULL,
1710 _gtk_marshal_BOOLEAN__BOXED,
1712 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1715 * GtkWidget::event-after:
1716 * @widget: the object which received the signal.
1717 * @event: the #GdkEvent which triggered this signal
1719 * After the emission of the #GtkWidget::event signal and (optionally)
1720 * the second more specific signal, ::event-after will be emitted
1721 * regardless of the previous two signals handlers return values.
1724 widget_signals[EVENT_AFTER] =
1725 g_signal_new (I_("event-after"),
1726 G_TYPE_FROM_CLASS (klass),
1730 _gtk_marshal_VOID__BOXED,
1732 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1735 * GtkWidget::button-press-event:
1736 * @widget: the object which received the signal.
1737 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1740 * The ::button-press-event signal will be emitted when a button
1741 * (typically from a mouse) is pressed.
1743 * To receive this signal, the #GdkWindow associated to the
1744 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1746 * This signal will be sent to the grab widget if there is one.
1748 * Returns: %TRUE to stop other handlers from being invoked for the event.
1749 * %FALSE to propagate the event further.
1751 widget_signals[BUTTON_PRESS_EVENT] =
1752 g_signal_new (I_("button-press-event"),
1753 G_TYPE_FROM_CLASS (klass),
1755 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1756 _gtk_boolean_handled_accumulator, NULL,
1757 _gtk_marshal_BOOLEAN__BOXED,
1759 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1762 * GtkWidget::button-release-event:
1763 * @widget: the object which received the signal.
1764 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1767 * The ::button-release-event signal will be emitted when a button
1768 * (typically from a mouse) is released.
1770 * To receive this signal, the #GdkWindow associated to the
1771 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1773 * This signal will be sent to the grab widget if there is one.
1775 * Returns: %TRUE to stop other handlers from being invoked for the event.
1776 * %FALSE to propagate the event further.
1778 widget_signals[BUTTON_RELEASE_EVENT] =
1779 g_signal_new (I_("button-release-event"),
1780 G_TYPE_FROM_CLASS (klass),
1782 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1783 _gtk_boolean_handled_accumulator, NULL,
1784 _gtk_marshal_BOOLEAN__BOXED,
1786 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1789 * GtkWidget::scroll-event:
1790 * @widget: the object which received the signal.
1791 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1794 * The ::scroll-event signal is emitted when a button in the 4 to 7
1795 * range is pressed. Wheel mice are usually configured to generate
1796 * button press events for buttons 4 and 5 when the wheel is turned.
1798 * To receive this signal, the #GdkWindow associated to the widget needs
1799 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1801 * This signal will be sent to the grab widget if there is one.
1803 * Returns: %TRUE to stop other handlers from being invoked for the event.
1804 * %FALSE to propagate the event further.
1806 widget_signals[SCROLL_EVENT] =
1807 g_signal_new (I_("scroll-event"),
1808 G_TYPE_FROM_CLASS (klass),
1810 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1811 _gtk_boolean_handled_accumulator, NULL,
1812 _gtk_marshal_BOOLEAN__BOXED,
1814 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1817 * GtkWidget::motion-notify-event:
1818 * @widget: the object which received the signal.
1819 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1822 * The ::motion-notify-event signal is emitted when the pointer moves
1823 * over the widget's #GdkWindow.
1825 * To receive this signal, the #GdkWindow associated to the widget
1826 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1828 * This signal will be sent to the grab widget if there is one.
1830 * Returns: %TRUE to stop other handlers from being invoked for the event.
1831 * %FALSE to propagate the event further.
1833 widget_signals[MOTION_NOTIFY_EVENT] =
1834 g_signal_new (I_("motion-notify-event"),
1835 G_TYPE_FROM_CLASS (klass),
1837 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1838 _gtk_boolean_handled_accumulator, NULL,
1839 _gtk_marshal_BOOLEAN__BOXED,
1841 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1844 * GtkWidget::composited-changed:
1845 * @widget: the object on which the signal is emitted
1847 * The ::composited-changed signal is emitted when the composited
1848 * status of @widget<!-- -->s screen changes.
1849 * See gdk_screen_is_composited().
1851 widget_signals[COMPOSITED_CHANGED] =
1852 g_signal_new (I_("composited-changed"),
1853 G_TYPE_FROM_CLASS (klass),
1854 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1855 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1857 _gtk_marshal_VOID__VOID,
1861 * GtkWidget::delete-event:
1862 * @widget: the object which received the signal
1863 * @event: the event which triggered this signal
1865 * The ::delete-event signal is emitted if a user requests that
1866 * a toplevel window is closed. The default handler for this signal
1867 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1868 * this signal will cause the window to be hidden instead, so that
1869 * it can later be shown again without reconstructing it.
1871 * Returns: %TRUE to stop other handlers from being invoked for the event.
1872 * %FALSE to propagate the event further.
1874 widget_signals[DELETE_EVENT] =
1875 g_signal_new (I_("delete-event"),
1876 G_TYPE_FROM_CLASS (klass),
1878 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1879 _gtk_boolean_handled_accumulator, NULL,
1880 _gtk_marshal_BOOLEAN__BOXED,
1882 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1885 * GtkWidget::destroy-event:
1886 * @widget: the object which received the signal.
1887 * @event: the event which triggered this signal
1889 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1890 * You rarely get this signal, because most widgets disconnect themselves
1891 * from their window before they destroy it, so no widget owns the
1892 * window at destroy time.
1894 * To receive this signal, the #GdkWindow associated to the widget needs
1895 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1896 * automatically for all new windows.
1898 * Returns: %TRUE to stop other handlers from being invoked for the event.
1899 * %FALSE to propagate the event further.
1901 widget_signals[DESTROY_EVENT] =
1902 g_signal_new (I_("destroy-event"),
1903 G_TYPE_FROM_CLASS (klass),
1905 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1906 _gtk_boolean_handled_accumulator, NULL,
1907 _gtk_marshal_BOOLEAN__BOXED,
1909 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1912 * GtkWidget::key-press-event:
1913 * @widget: the object which received the signal
1914 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1916 * The ::key-press-event signal is emitted when a key is pressed.
1918 * To receive this signal, the #GdkWindow associated to the widget needs
1919 * to enable the #GDK_KEY_PRESS_MASK mask.
1921 * This signal will be sent to the grab widget if there is one.
1923 * Returns: %TRUE to stop other handlers from being invoked for the event.
1924 * %FALSE to propagate the event further.
1926 widget_signals[KEY_PRESS_EVENT] =
1927 g_signal_new (I_("key-press-event"),
1928 G_TYPE_FROM_CLASS (klass),
1930 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1931 _gtk_boolean_handled_accumulator, NULL,
1932 _gtk_marshal_BOOLEAN__BOXED,
1934 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1937 * GtkWidget::key-release-event:
1938 * @widget: the object which received the signal
1939 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1941 * The ::key-release-event signal is emitted when a key is pressed.
1943 * To receive this signal, the #GdkWindow associated to the widget needs
1944 * to enable the #GDK_KEY_RELEASE_MASK mask.
1946 * This signal will be sent to the grab widget if there is one.
1948 * Returns: %TRUE to stop other handlers from being invoked for the event.
1949 * %FALSE to propagate the event further.
1951 widget_signals[KEY_RELEASE_EVENT] =
1952 g_signal_new (I_("key-release-event"),
1953 G_TYPE_FROM_CLASS (klass),
1955 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1956 _gtk_boolean_handled_accumulator, NULL,
1957 _gtk_marshal_BOOLEAN__BOXED,
1959 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1962 * GtkWidget::enter-notify-event:
1963 * @widget: the object which received the signal
1964 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1967 * The ::enter-notify-event will be emitted when the pointer enters
1968 * the @widget's window.
1970 * To receive this signal, the #GdkWindow associated to the widget needs
1971 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1973 * This signal will be sent to the grab widget if there is one.
1975 * Returns: %TRUE to stop other handlers from being invoked for the event.
1976 * %FALSE to propagate the event further.
1978 widget_signals[ENTER_NOTIFY_EVENT] =
1979 g_signal_new (I_("enter-notify-event"),
1980 G_TYPE_FROM_CLASS (klass),
1982 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1983 _gtk_boolean_handled_accumulator, NULL,
1984 _gtk_marshal_BOOLEAN__BOXED,
1986 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1989 * GtkWidget::leave-notify-event:
1990 * @widget: the object which received the signal
1991 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1994 * The ::leave-notify-event will be emitted when the pointer leaves
1995 * the @widget's window.
1997 * To receive this signal, the #GdkWindow associated to the widget needs
1998 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2000 * This signal will be sent to the grab widget if there is one.
2002 * Returns: %TRUE to stop other handlers from being invoked for the event.
2003 * %FALSE to propagate the event further.
2005 widget_signals[LEAVE_NOTIFY_EVENT] =
2006 g_signal_new (I_("leave-notify-event"),
2007 G_TYPE_FROM_CLASS (klass),
2009 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2010 _gtk_boolean_handled_accumulator, NULL,
2011 _gtk_marshal_BOOLEAN__BOXED,
2013 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2016 * GtkWidget::configure-event:
2017 * @widget: the object which received the signal
2018 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2021 * The ::configure-event signal will be emitted when the size, position or
2022 * stacking of the @widget's window has changed.
2024 * To receive this signal, the #GdkWindow associated to the widget needs
2025 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2026 * automatically for all new windows.
2028 * Returns: %TRUE to stop other handlers from being invoked for the event.
2029 * %FALSE to propagate the event further.
2031 widget_signals[CONFIGURE_EVENT] =
2032 g_signal_new (I_("configure-event"),
2033 G_TYPE_FROM_CLASS (klass),
2035 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2036 _gtk_boolean_handled_accumulator, NULL,
2037 _gtk_marshal_BOOLEAN__BOXED,
2039 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2042 * GtkWidget::focus-in-event:
2043 * @widget: the object which received the signal
2044 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2047 * The ::focus-in-event signal will be emitted when the keyboard focus
2048 * enters the @widget's window.
2050 * To receive this signal, the #GdkWindow associated to the widget needs
2051 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2053 * Returns: %TRUE to stop other handlers from being invoked for the event.
2054 * %FALSE to propagate the event further.
2056 widget_signals[FOCUS_IN_EVENT] =
2057 g_signal_new (I_("focus-in-event"),
2058 G_TYPE_FROM_CLASS (klass),
2060 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2061 _gtk_boolean_handled_accumulator, NULL,
2062 _gtk_marshal_BOOLEAN__BOXED,
2064 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2067 * GtkWidget::focus-out-event:
2068 * @widget: the object which received the signal
2069 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2072 * The ::focus-out-event signal will be emitted when the keyboard focus
2073 * leaves the @widget's window.
2075 * To receive this signal, the #GdkWindow associated to the widget needs
2076 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2078 * Returns: %TRUE to stop other handlers from being invoked for the event.
2079 * %FALSE to propagate the event further.
2081 widget_signals[FOCUS_OUT_EVENT] =
2082 g_signal_new (I_("focus-out-event"),
2083 G_TYPE_FROM_CLASS (klass),
2085 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2086 _gtk_boolean_handled_accumulator, NULL,
2087 _gtk_marshal_BOOLEAN__BOXED,
2089 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2092 * GtkWidget::map-event:
2093 * @widget: the object which received the signal
2094 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2096 * The ::map-event signal will be emitted when the @widget's window is
2097 * mapped. A window is mapped when it becomes visible on the screen.
2099 * To receive this signal, the #GdkWindow associated to the widget needs
2100 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2101 * automatically for all new windows.
2103 * Returns: %TRUE to stop other handlers from being invoked for the event.
2104 * %FALSE to propagate the event further.
2106 widget_signals[MAP_EVENT] =
2107 g_signal_new (I_("map-event"),
2108 G_TYPE_FROM_CLASS (klass),
2110 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2111 _gtk_boolean_handled_accumulator, NULL,
2112 _gtk_marshal_BOOLEAN__BOXED,
2114 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2117 * GtkWidget::unmap-event:
2118 * @widget: the object which received the signal
2119 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2121 * The ::unmap-event signal may be emitted when the @widget's window is
2122 * unmapped. A window is unmapped when it becomes invisible on the screen.
2124 * For performance reasons GTK+ may not emit ::unmap-event, so one
2125 * should always also implement ::unrealize in order to release
2126 * resources and disconnect signal handlers.
2128 * To receive this signal, the #GdkWindow associated to the widget needs
2129 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2130 * automatically for all new windows.
2132 * Returns: %TRUE to stop other handlers from being invoked for the event.
2133 * %FALSE to propagate the event further.
2135 widget_signals[UNMAP_EVENT] =
2136 g_signal_new (I_("unmap-event"),
2137 G_TYPE_FROM_CLASS (klass),
2139 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2140 _gtk_boolean_handled_accumulator, NULL,
2141 _gtk_marshal_BOOLEAN__BOXED,
2143 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2146 * GtkWidget::property-notify-event:
2147 * @widget: the object which received the signal
2148 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2151 * The ::property-notify-event signal will be emitted when a property on
2152 * the @widget's window has been changed or deleted.
2154 * To receive this signal, the #GdkWindow associated to the widget needs
2155 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2157 * Returns: %TRUE to stop other handlers from being invoked for the event.
2158 * %FALSE to propagate the event further.
2160 widget_signals[PROPERTY_NOTIFY_EVENT] =
2161 g_signal_new (I_("property-notify-event"),
2162 G_TYPE_FROM_CLASS (klass),
2164 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2165 _gtk_boolean_handled_accumulator, NULL,
2166 _gtk_marshal_BOOLEAN__BOXED,
2168 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2171 * GtkWidget::selection-clear-event:
2172 * @widget: the object which received the signal
2173 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2176 * The ::selection-clear-event signal will be emitted when the
2177 * the @widget's window has lost ownership of a selection.
2179 * Returns: %TRUE to stop other handlers from being invoked for the event.
2180 * %FALSE to propagate the event further.
2182 widget_signals[SELECTION_CLEAR_EVENT] =
2183 g_signal_new (I_("selection-clear-event"),
2184 G_TYPE_FROM_CLASS (klass),
2186 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2187 _gtk_boolean_handled_accumulator, NULL,
2188 _gtk_marshal_BOOLEAN__BOXED,
2190 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2193 * GtkWidget::selection-request-event:
2194 * @widget: the object which received the signal
2195 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2198 * The ::selection-request-event signal will be emitted when
2199 * another client requests ownership of the selection owned by
2200 * the @widget's window.
2202 * Returns: %TRUE to stop other handlers from being invoked for the event.
2203 * %FALSE to propagate the event further.
2205 widget_signals[SELECTION_REQUEST_EVENT] =
2206 g_signal_new (I_("selection-request-event"),
2207 G_TYPE_FROM_CLASS (klass),
2209 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2210 _gtk_boolean_handled_accumulator, NULL,
2211 _gtk_marshal_BOOLEAN__BOXED,
2213 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2216 * GtkWidget::selection-notify-event:
2217 * @widget: the object which received the signal.
2220 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2222 widget_signals[SELECTION_NOTIFY_EVENT] =
2223 g_signal_new (I_("selection-notify-event"),
2224 G_TYPE_FROM_CLASS (klass),
2226 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2227 _gtk_boolean_handled_accumulator, NULL,
2228 _gtk_marshal_BOOLEAN__BOXED,
2230 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2233 * GtkWidget::selection-received:
2234 * @widget: the object which received the signal.
2238 widget_signals[SELECTION_RECEIVED] =
2239 g_signal_new (I_("selection-received"),
2240 G_TYPE_FROM_CLASS (klass),
2242 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2244 _gtk_marshal_VOID__BOXED_UINT,
2246 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2250 * GtkWidget::selection-get:
2251 * @widget: the object which received the signal.
2256 widget_signals[SELECTION_GET] =
2257 g_signal_new (I_("selection-get"),
2258 G_TYPE_FROM_CLASS (klass),
2260 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2262 _gtk_marshal_VOID__BOXED_UINT_UINT,
2264 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2269 * GtkWidget::proximity-in-event:
2270 * @widget: the object which received the signal
2271 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2274 * To receive this signal the #GdkWindow associated to the widget needs
2275 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2277 * This signal will be sent to the grab widget if there is one.
2279 * Returns: %TRUE to stop other handlers from being invoked for the event.
2280 * %FALSE to propagate the event further.
2282 widget_signals[PROXIMITY_IN_EVENT] =
2283 g_signal_new (I_("proximity-in-event"),
2284 G_TYPE_FROM_CLASS (klass),
2286 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2287 _gtk_boolean_handled_accumulator, NULL,
2288 _gtk_marshal_BOOLEAN__BOXED,
2290 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2293 * GtkWidget::proximity-out-event:
2294 * @widget: the object which received the signal
2295 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2298 * To receive this signal the #GdkWindow associated to the widget needs
2299 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2301 * This signal will be sent to the grab widget if there is one.
2303 * Returns: %TRUE to stop other handlers from being invoked for the event.
2304 * %FALSE to propagate the event further.
2306 widget_signals[PROXIMITY_OUT_EVENT] =
2307 g_signal_new (I_("proximity-out-event"),
2308 G_TYPE_FROM_CLASS (klass),
2310 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2311 _gtk_boolean_handled_accumulator, NULL,
2312 _gtk_marshal_BOOLEAN__BOXED,
2314 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2317 * GtkWidget::drag-leave:
2318 * @widget: the object which received the signal.
2319 * @drag_context: the drag context
2320 * @time: the timestamp of the motion event
2322 * The ::drag-leave signal is emitted on the drop site when the cursor
2323 * leaves the widget. A typical reason to connect to this signal is to
2324 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2325 * with gtk_drag_unhighlight()
2327 widget_signals[DRAG_LEAVE] =
2328 g_signal_new (I_("drag-leave"),
2329 G_TYPE_FROM_CLASS (klass),
2331 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2333 _gtk_marshal_VOID__OBJECT_UINT,
2335 GDK_TYPE_DRAG_CONTEXT,
2339 * GtkWidget::drag-begin:
2340 * @widget: the object which received the signal
2341 * @drag_context: the drag context
2343 * The ::drag-begin signal is emitted on the drag source when a drag is
2344 * started. A typical reason to connect to this signal is to set up a
2345 * custom drag icon with gtk_drag_source_set_icon().
2347 * Note that some widgets set up a drag icon in the default handler of
2348 * this signal, so you may have to use g_signal_connect_after() to
2349 * override what the default handler did.
2351 widget_signals[DRAG_BEGIN] =
2352 g_signal_new (I_("drag-begin"),
2353 G_TYPE_FROM_CLASS (klass),
2355 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2357 _gtk_marshal_VOID__OBJECT,
2359 GDK_TYPE_DRAG_CONTEXT);
2362 * GtkWidget::drag-end:
2363 * @widget: the object which received the signal
2364 * @drag_context: the drag context
2366 * The ::drag-end signal is emitted on the drag source when a drag is
2367 * finished. A typical reason to connect to this signal is to undo
2368 * things done in #GtkWidget::drag-begin.
2370 widget_signals[DRAG_END] =
2371 g_signal_new (I_("drag-end"),
2372 G_TYPE_FROM_CLASS (klass),
2374 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2376 _gtk_marshal_VOID__OBJECT,
2378 GDK_TYPE_DRAG_CONTEXT);
2381 * GtkWidget::drag-data-delete:
2382 * @widget: the object which received the signal
2383 * @drag_context: the drag context
2385 * The ::drag-data-delete signal is emitted on the drag source when a drag
2386 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2387 * handler is responsible for deleting the data that has been dropped. What
2388 * "delete" means depends on the context of the drag operation.
2390 widget_signals[DRAG_DATA_DELETE] =
2391 g_signal_new (I_("drag-data-delete"),
2392 G_TYPE_FROM_CLASS (klass),
2394 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2396 _gtk_marshal_VOID__OBJECT,
2398 GDK_TYPE_DRAG_CONTEXT);
2401 * GtkWidget::drag-failed:
2402 * @widget: the object which received the signal
2403 * @drag_context: the drag context
2404 * @result: the result of the drag operation
2406 * The ::drag-failed signal is emitted on the drag source when a drag has
2407 * failed. The signal handler may hook custom code to handle a failed DND
2408 * operation based on the type of error, it returns %TRUE is the failure has
2409 * been already handled (not showing the default "drag operation failed"
2410 * animation), otherwise it returns %FALSE.
2412 * Return value: %TRUE if the failed drag operation has been already handled.
2416 widget_signals[DRAG_FAILED] =
2417 g_signal_new (I_("drag-failed"),
2418 G_TYPE_FROM_CLASS (klass),
2420 0, _gtk_boolean_handled_accumulator, NULL,
2421 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2423 GDK_TYPE_DRAG_CONTEXT,
2424 GTK_TYPE_DRAG_RESULT);
2427 * GtkWidget::drag-motion:
2428 * @widget: the object which received the signal
2429 * @drag_context: the drag context
2430 * @x: the x coordinate of the current cursor position
2431 * @y: the y coordinate of the current cursor position
2432 * @time: the timestamp of the motion event
2433 * @returns: whether the cursor position is in a drop zone
2435 * The drag-motion signal is emitted on the drop site when the user
2436 * moves the cursor over the widget during a drag. The signal handler
2437 * must determine whether the cursor position is in a drop zone or not.
2438 * If it is not in a drop zone, it returns %FALSE and no further processing
2439 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2440 * handler is responsible for providing the necessary information for
2441 * displaying feedback to the user, by calling gdk_drag_status().
2443 * If the decision whether the drop will be accepted or rejected can't be
2444 * made based solely on the cursor position and the type of the data, the
2445 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2446 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2447 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2448 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2449 * when using the drag-motion signal that way.
2451 * Also note that there is no drag-enter signal. The drag receiver has to
2452 * keep track of whether he has received any drag-motion signals since the
2453 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2454 * an "enter" signal. Upon an "enter", the handler will typically highlight
2455 * the drop site with gtk_drag_highlight().
2458 * drag_motion (GtkWidget *widget,
2459 * GdkDragContext *context,
2466 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2468 * if (!private_data->drag_highlight)
2470 * private_data->drag_highlight = 1;
2471 * gtk_drag_highlight (widget);
2474 * target = gtk_drag_dest_find_target (widget, context, NULL);
2475 * if (target == GDK_NONE)
2476 * gdk_drag_status (context, 0, time);
2479 * private_data->pending_status = context->suggested_action;
2480 * gtk_drag_get_data (widget, context, target, time);
2487 * drag_data_received (GtkWidget *widget,
2488 * GdkDragContext *context,
2491 * GtkSelectionData *selection_data,
2495 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2497 * if (private_data->suggested_action)
2499 * private_data->suggested_action = 0;
2501 * /* We are getting this data due to a request in drag_motion,
2502 * * rather than due to a request in drag_drop, so we are just
2503 * * supposed to call gdk_drag_status (), not actually paste in
2506 * str = gtk_selection_data_get_text (selection_data);
2507 * if (!data_is_acceptable (str))
2508 * gdk_drag_status (context, 0, time);
2510 * gdk_drag_status (context, private_data->suggested_action, time);
2514 * /* accept the drop */
2519 widget_signals[DRAG_MOTION] =
2520 g_signal_new (I_("drag-motion"),
2521 G_TYPE_FROM_CLASS (klass),
2523 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2524 _gtk_boolean_handled_accumulator, NULL,
2525 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2527 GDK_TYPE_DRAG_CONTEXT,
2533 * GtkWidget::drag-drop:
2534 * @widget: the object which received the signal
2535 * @drag_context: the drag context
2536 * @x: the x coordinate of the current cursor position
2537 * @y: the y coordinate of the current cursor position
2538 * @time: the timestamp of the motion event
2539 * @returns: whether the cursor position is in a drop zone
2541 * The ::drag-drop signal is emitted on the drop site when the user drops
2542 * the data onto the widget. The signal handler must determine whether
2543 * the cursor position is in a drop zone or not. If it is not in a drop
2544 * zone, it returns %FALSE and no further processing is necessary.
2545 * Otherwise, the handler returns %TRUE. In this case, the handler must
2546 * ensure that gtk_drag_finish() is called to let the source know that
2547 * the drop is done. The call to gtk_drag_finish() can be done either
2548 * directly or in a #GtkWidget::drag-data-received handler which gets
2549 * triggered by calling gtk_drag_get_data() to receive the data for one
2550 * or more of the supported targets.
2552 widget_signals[DRAG_DROP] =
2553 g_signal_new (I_("drag-drop"),
2554 G_TYPE_FROM_CLASS (klass),
2556 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2557 _gtk_boolean_handled_accumulator, NULL,
2558 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2560 GDK_TYPE_DRAG_CONTEXT,
2566 * GtkWidget::drag-data-get:
2567 * @widget: the object which received the signal
2568 * @drag_context: the drag context
2569 * @data: the #GtkSelectionData to be filled with the dragged data
2570 * @info: the info that has been registered with the target in the
2572 * @time: the timestamp at which the data was requested
2574 * The ::drag-data-get signal is emitted on the drag source when the drop
2575 * site requests the data which is dragged. It is the responsibility of
2576 * the signal handler to fill @data with the data in the format which
2577 * is indicated by @info. See gtk_selection_data_set() and
2578 * gtk_selection_data_set_text().
2580 widget_signals[DRAG_DATA_GET] =
2581 g_signal_new (I_("drag-data-get"),
2582 G_TYPE_FROM_CLASS (klass),
2584 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2586 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2588 GDK_TYPE_DRAG_CONTEXT,
2589 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2594 * GtkWidget::drag-data-received:
2595 * @widget: the object which received the signal
2596 * @drag_context: the drag context
2597 * @x: where the drop happened
2598 * @y: where the drop happened
2599 * @data: the received data
2600 * @info: the info that has been registered with the target in the
2602 * @time: the timestamp at which the data was received
2604 * The ::drag-data-received signal is emitted on the drop site when the
2605 * dragged data has been received. If the data was received in order to
2606 * determine whether the drop will be accepted, the handler is expected
2607 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2608 * If the data was received in response to a #GtkWidget::drag-drop signal
2609 * (and this is the last target to be received), the handler for this
2610 * signal is expected to process the received data and then call
2611 * gtk_drag_finish(), setting the @success parameter depending on whether
2612 * the data was processed successfully.
2614 * The handler may inspect and modify @drag_context->action before calling
2615 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2616 * following example:
2619 * drag_data_received (GtkWidget *widget,
2620 * GdkDragContext *drag_context,
2623 * GtkSelectionData *data,
2627 * if ((data->length >= 0) && (data->format == 8))
2629 * if (drag_context->action == GDK_ACTION_ASK)
2631 * GtkWidget *dialog;
2634 * dialog = gtk_message_dialog_new (NULL,
2635 * GTK_DIALOG_MODAL |
2636 * GTK_DIALOG_DESTROY_WITH_PARENT,
2638 * GTK_BUTTONS_YES_NO,
2639 * "Move the data ?\n");
2640 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2641 * gtk_widget_destroy (dialog);
2643 * if (response == GTK_RESPONSE_YES)
2644 * drag_context->action = GDK_ACTION_MOVE;
2646 * drag_context->action = GDK_ACTION_COPY;
2649 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2653 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2657 widget_signals[DRAG_DATA_RECEIVED] =
2658 g_signal_new (I_("drag-data-received"),
2659 G_TYPE_FROM_CLASS (klass),
2661 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2663 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2665 GDK_TYPE_DRAG_CONTEXT,
2668 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2673 * GtkWidget::visibility-notify-event:
2674 * @widget: the object which received the signal
2675 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2676 * triggered this signal.
2678 * The ::visibility-notify-event will be emitted when the @widget's window
2679 * is obscured or unobscured.
2681 * To receive this signal the #GdkWindow associated to the widget needs
2682 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2684 * Returns: %TRUE to stop other handlers from being invoked for the event.
2685 * %FALSE to propagate the event further.
2687 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2688 g_signal_new (I_("visibility-notify-event"),
2689 G_TYPE_FROM_CLASS (klass),
2691 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2692 _gtk_boolean_handled_accumulator, NULL,
2693 _gtk_marshal_BOOLEAN__BOXED,
2695 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2698 * GtkWidget::client-event:
2699 * @widget: the object which received the signal
2700 * @event: (type Gdk.EventClient): the #GdkEventClient which triggered
2703 * The ::client-event will be emitted when the @widget's window
2704 * receives a message (via a ClientMessage event) from another
2707 * Returns: %TRUE to stop other handlers from being invoked for
2708 * the event. %FALSE to propagate the event further.
2710 widget_signals[CLIENT_EVENT] =
2711 g_signal_new (I_("client-event"),
2712 G_TYPE_FROM_CLASS (klass),
2714 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2715 _gtk_boolean_handled_accumulator, NULL,
2716 _gtk_marshal_BOOLEAN__BOXED,
2718 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2721 * GtkWidget::window-state-event:
2722 * @widget: the object which received the signal
2723 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2724 * triggered this signal.
2726 * The ::window-state-event will be emitted when the state of the
2727 * toplevel window associated to the @widget changes.
2729 * To receive this signal the #GdkWindow associated to the widget
2730 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2731 * this mask automatically for all new windows.
2733 * Returns: %TRUE to stop other handlers from being invoked for the
2734 * event. %FALSE to propagate the event further.
2736 widget_signals[WINDOW_STATE_EVENT] =
2737 g_signal_new (I_("window-state-event"),
2738 G_TYPE_FROM_CLASS (klass),
2740 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2741 _gtk_boolean_handled_accumulator, NULL,
2742 _gtk_marshal_BOOLEAN__BOXED,
2744 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2747 * GtkWidget::damage-event:
2748 * @widget: the object which received the signal
2749 * @event: the #GdkEventExpose event
2751 * Emitted when a redirected window belonging to @widget gets drawn into.
2752 * The region/area members of the event shows what area of the redirected
2753 * drawable was drawn into.
2755 * Returns: %TRUE to stop other handlers from being invoked for the event.
2756 * %FALSE to propagate the event further.
2760 widget_signals[DAMAGE_EVENT] =
2761 g_signal_new (I_("damage-event"),
2762 G_TYPE_FROM_CLASS (klass),
2764 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2765 _gtk_boolean_handled_accumulator, NULL,
2766 _gtk_marshal_BOOLEAN__BOXED,
2768 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2771 * GtkWidget::grab-broken-event:
2772 * @widget: the object which received the signal
2773 * @event: the #GdkEventGrabBroken event
2775 * Emitted when a pointer or keyboard grab on a window belonging
2776 * to @widget gets broken.
2778 * On X11, this happens when the grab window becomes unviewable
2779 * (i.e. it or one of its ancestors is unmapped), or if the same
2780 * application grabs the pointer or keyboard again.
2782 * Returns: %TRUE to stop other handlers from being invoked for
2783 * the event. %FALSE to propagate the event further.
2787 widget_signals[GRAB_BROKEN_EVENT] =
2788 g_signal_new (I_("grab-broken-event"),
2789 G_TYPE_FROM_CLASS (klass),
2791 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2792 _gtk_boolean_handled_accumulator, NULL,
2793 _gtk_marshal_BOOLEAN__BOXED,
2795 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2798 * GtkWidget::query-tooltip:
2799 * @widget: the object which received the signal
2800 * @x: the x coordinate of the cursor position where the request has
2801 * been emitted, relative to @widget->window
2802 * @y: the y coordinate of the cursor position where the request has
2803 * been emitted, relative to @widget->window
2804 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2805 * @tooltip: a #GtkTooltip
2807 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2808 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2809 * focus in keyboard mode.
2811 * Using the given coordinates, the signal handler should determine
2812 * whether a tooltip should be shown for @widget. If this is the case
2813 * %TRUE should be returned, %FALSE otherwise. Note that if
2814 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2815 * should not be used.
2817 * The signal handler is free to manipulate @tooltip with the therefore
2818 * destined function calls.
2820 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2824 widget_signals[QUERY_TOOLTIP] =
2825 g_signal_new (I_("query-tooltip"),
2826 G_TYPE_FROM_CLASS (klass),
2828 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2829 _gtk_boolean_handled_accumulator, NULL,
2830 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2838 * GtkWidget::popup-menu
2839 * @widget: the object which received the signal
2841 * This signal gets emitted whenever a widget should pop up a context
2842 * menu. This usually happens through the standard key binding mechanism;
2843 * by pressing a certain key while a widget is focused, the user can cause
2844 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2845 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2846 * for an example of how to use this signal.
2848 * Returns: %TRUE if a menu was activated
2850 widget_signals[POPUP_MENU] =
2851 g_signal_new (I_("popup-menu"),
2852 G_TYPE_FROM_CLASS (klass),
2853 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2854 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2855 _gtk_boolean_handled_accumulator, NULL,
2856 _gtk_marshal_BOOLEAN__VOID,
2860 * GtkWidget::show-help:
2861 * @widget: the object which received the signal.
2864 widget_signals[SHOW_HELP] =
2865 g_signal_new (I_("show-help"),
2866 G_TYPE_FROM_CLASS (klass),
2867 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2868 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2869 _gtk_boolean_handled_accumulator, NULL,
2870 _gtk_marshal_BOOLEAN__ENUM,
2872 GTK_TYPE_WIDGET_HELP_TYPE);
2875 * GtkWidget::accel-closures-changed:
2876 * @widget: the object which received the signal.
2878 widget_signals[ACCEL_CLOSURES_CHANGED] =
2879 g_signal_new (I_("accel-closures-changed"),
2880 G_TYPE_FROM_CLASS (klass),
2884 _gtk_marshal_VOID__VOID,
2888 * GtkWidget::screen-changed:
2889 * @widget: the object on which the signal is emitted
2890 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2891 * widget was not associated with a screen before
2893 * The ::screen-changed signal gets emitted when the
2894 * screen of a widget has changed.
2896 widget_signals[SCREEN_CHANGED] =
2897 g_signal_new (I_("screen-changed"),
2898 G_TYPE_FROM_CLASS (klass),
2900 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2902 _gtk_marshal_VOID__OBJECT,
2907 * GtkWidget::can-activate-accel:
2908 * @widget: the object which received the signal
2909 * @signal_id: the ID of a signal installed on @widget
2911 * Determines whether an accelerator that activates the signal
2912 * identified by @signal_id can currently be activated.
2913 * This signal is present to allow applications and derived
2914 * widgets to override the default #GtkWidget handling
2915 * for determining whether an accelerator can be activated.
2917 * Returns: %TRUE if the signal can be activated.
2919 widget_signals[CAN_ACTIVATE_ACCEL] =
2920 g_signal_new (I_("can-activate-accel"),
2921 G_TYPE_FROM_CLASS (klass),
2923 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2924 _gtk_boolean_handled_accumulator, NULL,
2925 _gtk_marshal_BOOLEAN__UINT,
2926 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2928 binding_set = gtk_binding_set_by_class (klass);
2929 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
2931 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
2934 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
2936 GTK_TYPE_WIDGET_HELP_TYPE,
2937 GTK_WIDGET_HELP_TOOLTIP);
2938 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
2940 GTK_TYPE_WIDGET_HELP_TYPE,
2941 GTK_WIDGET_HELP_TOOLTIP);
2942 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
2944 GTK_TYPE_WIDGET_HELP_TYPE,
2945 GTK_WIDGET_HELP_WHATS_THIS);
2946 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
2948 GTK_TYPE_WIDGET_HELP_TYPE,
2949 GTK_WIDGET_HELP_WHATS_THIS);
2951 gtk_widget_class_install_style_property (klass,
2952 g_param_spec_boolean ("interior-focus",
2953 P_("Interior Focus"),
2954 P_("Whether to draw the focus indicator inside widgets"),
2956 GTK_PARAM_READABLE));
2958 gtk_widget_class_install_style_property (klass,
2959 g_param_spec_int ("focus-line-width",
2960 P_("Focus linewidth"),
2961 P_("Width, in pixels, of the focus indicator line"),
2963 GTK_PARAM_READABLE));
2965 gtk_widget_class_install_style_property (klass,
2966 g_param_spec_string ("focus-line-pattern",
2967 P_("Focus line dash pattern"),
2968 P_("Dash pattern used to draw the focus indicator"),
2970 GTK_PARAM_READABLE));
2971 gtk_widget_class_install_style_property (klass,
2972 g_param_spec_int ("focus-padding",
2973 P_("Focus padding"),
2974 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2976 GTK_PARAM_READABLE));
2977 gtk_widget_class_install_style_property (klass,
2978 g_param_spec_boxed ("cursor-color",
2980 P_("Color with which to draw insertion cursor"),
2982 GTK_PARAM_READABLE));
2983 gtk_widget_class_install_style_property (klass,
2984 g_param_spec_boxed ("secondary-cursor-color",
2985 P_("Secondary cursor color"),
2986 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2988 GTK_PARAM_READABLE));
2989 gtk_widget_class_install_style_property (klass,
2990 g_param_spec_float ("cursor-aspect-ratio",
2991 P_("Cursor line aspect ratio"),
2992 P_("Aspect ratio with which to draw insertion cursor"),
2994 GTK_PARAM_READABLE));
2996 gtk_widget_class_install_style_property (klass,
2997 g_param_spec_boolean ("window-dragging",
2998 P_("Window dragging"),
2999 P_("Whether windows can be dragged by clicking on empty areas"),
3001 GTK_PARAM_READABLE));
3004 * GtkWidget:link-color:
3006 * The "link-color" style property defines the color of unvisited links.
3010 gtk_widget_class_install_style_property (klass,
3011 g_param_spec_boxed ("link-color",
3012 P_("Unvisited Link Color"),
3013 P_("Color of unvisited links"),
3015 GTK_PARAM_READABLE));
3018 * GtkWidget:visited-link-color:
3020 * The "visited-link-color" style property defines the color of visited links.
3024 gtk_widget_class_install_style_property (klass,
3025 g_param_spec_boxed ("visited-link-color",
3026 P_("Visited Link Color"),
3027 P_("Color of visited links"),
3029 GTK_PARAM_READABLE));
3032 * GtkWidget:wide-separators:
3034 * The "wide-separators" style property defines whether separators have
3035 * configurable width and should be drawn using a box instead of a line.
3039 gtk_widget_class_install_style_property (klass,
3040 g_param_spec_boolean ("wide-separators",
3041 P_("Wide Separators"),
3042 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3044 GTK_PARAM_READABLE));
3047 * GtkWidget:separator-width:
3049 * The "separator-width" style property defines the width of separators.
3050 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3054 gtk_widget_class_install_style_property (klass,
3055 g_param_spec_int ("separator-width",
3056 P_("Separator Width"),
3057 P_("The width of separators if wide-separators is TRUE"),
3059 GTK_PARAM_READABLE));
3062 * GtkWidget:separator-height:
3064 * The "separator-height" style property defines the height of separators.
3065 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3069 gtk_widget_class_install_style_property (klass,
3070 g_param_spec_int ("separator-height",
3071 P_("Separator Height"),
3072 P_("The height of separators if \"wide-separators\" is TRUE"),
3074 GTK_PARAM_READABLE));
3077 * GtkWidget:scroll-arrow-hlength:
3079 * The "scroll-arrow-hlength" style property defines the length of
3080 * horizontal scroll arrows.
3084 gtk_widget_class_install_style_property (klass,
3085 g_param_spec_int ("scroll-arrow-hlength",
3086 P_("Horizontal Scroll Arrow Length"),
3087 P_("The length of horizontal scroll arrows"),
3089 GTK_PARAM_READABLE));
3092 * GtkWidget:scroll-arrow-vlength:
3094 * The "scroll-arrow-vlength" style property defines the length of
3095 * vertical scroll arrows.
3099 gtk_widget_class_install_style_property (klass,
3100 g_param_spec_int ("scroll-arrow-vlength",
3101 P_("Vertical Scroll Arrow Length"),
3102 P_("The length of vertical scroll arrows"),
3104 GTK_PARAM_READABLE));
3106 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3110 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3114 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3115 for (node = list; node; node = node->next)
3117 GParamSpec *pspec = node->data;
3119 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3120 g_param_spec_unref (pspec);
3126 gtk_widget_set_property (GObject *object,
3128 const GValue *value,
3131 GtkWidget *widget = GTK_WIDGET (object);
3136 gchar *tooltip_markup;
3137 const gchar *tooltip_text;
3138 GtkWindow *tooltip_window;
3141 gtk_widget_set_name (widget, g_value_get_string (value));
3144 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3146 case PROP_WIDTH_REQUEST:
3147 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3149 case PROP_HEIGHT_REQUEST:
3150 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3153 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3155 case PROP_SENSITIVE:
3156 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3158 case PROP_APP_PAINTABLE:
3159 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3161 case PROP_CAN_FOCUS:
3162 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3164 case PROP_HAS_FOCUS:
3165 if (g_value_get_boolean (value))
3166 gtk_widget_grab_focus (widget);
3169 if (g_value_get_boolean (value))
3170 gtk_widget_grab_focus (widget);
3172 case PROP_CAN_DEFAULT:
3173 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3175 case PROP_HAS_DEFAULT:
3176 if (g_value_get_boolean (value))
3177 gtk_widget_grab_default (widget);
3179 case PROP_RECEIVES_DEFAULT:
3180 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3183 gtk_widget_set_style (widget, g_value_get_object (value));
3186 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3187 gtk_widget_set_events (widget, g_value_get_flags (value));
3189 case PROP_EXTENSION_EVENTS:
3190 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
3192 case PROP_NO_SHOW_ALL:
3193 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3195 case PROP_HAS_TOOLTIP:
3196 gtk_widget_real_set_has_tooltip (widget,
3197 g_value_get_boolean (value), FALSE);
3199 case PROP_TOOLTIP_MARKUP:
3200 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3201 tooltip_markup = g_value_dup_string (value);
3203 /* Treat an empty string as a NULL string,
3204 * because an empty string would be useless for a tooltip:
3206 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3208 g_free (tooltip_markup);
3209 tooltip_markup = NULL;
3212 g_object_set_qdata_full (object, quark_tooltip_markup,
3213 tooltip_markup, g_free);
3215 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3216 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3217 if (gtk_widget_get_visible (widget))
3218 gtk_widget_queue_tooltip_query (widget);
3220 case PROP_TOOLTIP_TEXT:
3221 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3223 tooltip_text = g_value_get_string (value);
3225 /* Treat an empty string as a NULL string,
3226 * because an empty string would be useless for a tooltip:
3228 if (tooltip_text && (strlen (tooltip_text) == 0))
3229 tooltip_text = NULL;
3231 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3233 g_object_set_qdata_full (object, quark_tooltip_markup,
3234 tooltip_markup, g_free);
3236 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3237 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3238 if (gtk_widget_get_visible (widget))
3239 gtk_widget_queue_tooltip_query (widget);
3241 case PROP_DOUBLE_BUFFERED:
3242 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3245 gtk_widget_set_halign (widget, g_value_get_enum (value));
3248 gtk_widget_set_valign (widget, g_value_get_enum (value));
3250 case PROP_MARGIN_LEFT:
3251 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3253 case PROP_MARGIN_RIGHT:
3254 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3256 case PROP_MARGIN_TOP:
3257 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3259 case PROP_MARGIN_BOTTOM:
3260 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3263 g_object_freeze_notify (G_OBJECT (widget));
3264 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3265 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3266 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3267 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3268 g_object_thaw_notify (G_OBJECT (widget));
3271 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3273 case PROP_HEXPAND_SET:
3274 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3277 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3279 case PROP_VEXPAND_SET:
3280 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3283 g_object_freeze_notify (G_OBJECT (widget));
3284 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3285 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3286 g_object_thaw_notify (G_OBJECT (widget));
3289 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3295 gtk_widget_get_property (GObject *object,
3300 GtkWidget *widget = GTK_WIDGET (object);
3301 GtkWidgetPrivate *priv = widget->priv;
3310 g_value_set_string (value, priv->name);
3312 g_value_set_static_string (value, "");
3315 g_value_set_object (value, priv->parent);
3317 case PROP_WIDTH_REQUEST:
3320 gtk_widget_get_size_request (widget, &w, NULL);
3321 g_value_set_int (value, w);
3324 case PROP_HEIGHT_REQUEST:
3327 gtk_widget_get_size_request (widget, NULL, &h);
3328 g_value_set_int (value, h);
3332 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3334 case PROP_SENSITIVE:
3335 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3337 case PROP_APP_PAINTABLE:
3338 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3340 case PROP_CAN_FOCUS:
3341 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3343 case PROP_HAS_FOCUS:
3344 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3347 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3349 case PROP_CAN_DEFAULT:
3350 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3352 case PROP_HAS_DEFAULT:
3353 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3355 case PROP_RECEIVES_DEFAULT:
3356 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3358 case PROP_COMPOSITE_CHILD:
3359 g_value_set_boolean (value, widget->priv->composite_child);
3362 g_value_set_object (value, gtk_widget_get_style (widget));
3365 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3366 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3368 case PROP_EXTENSION_EVENTS:
3369 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
3370 g_value_set_enum (value, GPOINTER_TO_INT (modep));
3372 case PROP_NO_SHOW_ALL:
3373 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3375 case PROP_HAS_TOOLTIP:
3376 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3378 case PROP_TOOLTIP_TEXT:
3380 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3383 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3384 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3386 g_value_take_string (value, text);
3389 case PROP_TOOLTIP_MARKUP:
3390 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3393 g_value_set_object (value, gtk_widget_get_window (widget));
3395 case PROP_DOUBLE_BUFFERED:
3396 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3399 g_value_set_enum (value, gtk_widget_get_halign (widget));
3402 g_value_set_enum (value, gtk_widget_get_valign (widget));
3404 case PROP_MARGIN_LEFT:
3405 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3407 case PROP_MARGIN_RIGHT:
3408 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3410 case PROP_MARGIN_TOP:
3411 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3413 case PROP_MARGIN_BOTTOM:
3414 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3418 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3419 if (aux_info == NULL)
3421 g_value_set_int (value, 0);
3425 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3426 aux_info->margin.right),
3427 MAX (aux_info->margin.top,
3428 aux_info->margin.bottom)));
3433 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3435 case PROP_HEXPAND_SET:
3436 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3439 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3441 case PROP_VEXPAND_SET:
3442 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3445 g_value_set_boolean (value,
3446 gtk_widget_get_hexpand (widget) &&
3447 gtk_widget_get_vexpand (widget));
3450 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3456 gtk_widget_init (GtkWidget *widget)
3458 GtkWidgetPrivate *priv;
3460 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3463 priv = widget->priv;
3465 priv->child_visible = TRUE;
3466 priv->state = GTK_STATE_NORMAL;
3467 priv->saved_state = GTK_STATE_NORMAL;
3469 priv->allocation.x = -1;
3470 priv->allocation.y = -1;
3471 priv->allocation.width = 1;
3472 priv->allocation.height = 1;
3473 priv->window = NULL;
3474 priv->parent = NULL;
3476 priv->sensitive = TRUE;
3477 priv->parent_sensitive = TRUE;
3478 priv->composite_child = composite_child_stack != 0;
3479 priv->double_buffered = TRUE;
3480 priv->redraw_on_alloc = TRUE;
3481 priv->width_request_needed = TRUE;
3482 priv->height_request_needed = TRUE;
3483 priv->alloc_needed = TRUE;
3485 /* this will be set to TRUE if the widget gets a child or if the
3486 * expand flag is set on the widget, but until one of those happen
3487 * we know the expand is already properly FALSE.
3489 * We really want to default FALSE here to avoid computing expand
3490 * all over the place while initially building a widget tree.
3492 priv->need_compute_expand = FALSE;
3494 priv->style = gtk_widget_get_default_style ();
3495 g_object_ref (priv->style);
3500 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3502 GParamSpec **pspecs)
3504 GtkWidgetPrivate *priv = widget->priv;
3505 GtkWidget *container = priv->parent;
3508 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3509 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3513 * gtk_widget_freeze_child_notify:
3514 * @widget: a #GtkWidget
3516 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3517 * signals are queued until gtk_widget_thaw_child_notify() is called
3520 * This is the analogue of g_object_freeze_notify() for child properties.
3523 gtk_widget_freeze_child_notify (GtkWidget *widget)
3525 g_return_if_fail (GTK_IS_WIDGET (widget));
3527 if (!G_OBJECT (widget)->ref_count)
3530 g_object_ref (widget);
3531 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3532 g_object_unref (widget);
3536 * gtk_widget_child_notify:
3537 * @widget: a #GtkWidget
3538 * @child_property: the name of a child property installed on the
3539 * class of @widget<!-- -->'s parent
3541 * Emits a #GtkWidget::child-notify signal for the
3542 * <link linkend="child-properties">child property</link> @child_property
3545 * This is the analogue of g_object_notify() for child properties.
3548 gtk_widget_child_notify (GtkWidget *widget,
3549 const gchar *child_property)
3551 GtkWidgetPrivate *priv = widget->priv;
3554 g_return_if_fail (GTK_IS_WIDGET (widget));
3555 g_return_if_fail (child_property != NULL);
3556 if (!G_OBJECT (widget)->ref_count || !priv->parent)
3559 g_object_ref (widget);
3560 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3562 G_OBJECT_TYPE (priv->parent),
3565 g_warning ("%s: container class `%s' has no child property named `%s'",
3567 G_OBJECT_TYPE_NAME (priv->parent),
3571 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3573 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3574 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3576 g_object_unref (widget);
3580 * gtk_widget_thaw_child_notify:
3581 * @widget: a #GtkWidget
3583 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3584 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3588 gtk_widget_thaw_child_notify (GtkWidget *widget)
3590 GObjectNotifyQueue *nqueue;
3592 g_return_if_fail (GTK_IS_WIDGET (widget));
3594 if (!G_OBJECT (widget)->ref_count)
3597 g_object_ref (widget);
3598 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3599 if (!nqueue || !nqueue->freeze_count)
3600 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3601 G_OBJECT_TYPE_NAME (widget), widget);
3603 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3604 g_object_unref (widget);
3610 * @type: type ID of the widget to create
3611 * @first_property_name: name of first property to set
3612 * @Varargs: value of first property, followed by more properties,
3615 * This is a convenience function for creating a widget and setting
3616 * its properties in one go. For example you might write:
3617 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3618 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3619 * g_object_new(), but returns a widget so you don't have to
3620 * cast the object yourself.
3622 * Return value: a new #GtkWidget of type @widget_type
3625 gtk_widget_new (GType type,
3626 const gchar *first_property_name,
3632 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3634 va_start (var_args, first_property_name);
3635 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3642 gtk_widget_queue_draw_child (GtkWidget *widget)
3644 GtkWidgetPrivate *priv = widget->priv;
3647 parent = priv->parent;
3648 if (parent && gtk_widget_is_drawable (parent))
3649 gtk_widget_queue_draw_area (parent,
3652 priv->allocation.width,
3653 priv->allocation.height);
3657 * gtk_widget_unparent:
3658 * @widget: a #GtkWidget
3660 * This function is only for use in widget implementations.
3661 * Should be called by implementations of the remove method
3662 * on #GtkContainer, to dissociate a child from the container.
3665 gtk_widget_unparent (GtkWidget *widget)
3667 GtkWidgetPrivate *priv;
3668 GObjectNotifyQueue *nqueue;
3669 GtkWidget *toplevel;
3670 GtkWidget *old_parent;
3672 g_return_if_fail (GTK_IS_WIDGET (widget));
3674 priv = widget->priv;
3676 if (priv->parent == NULL)
3679 /* keep this function in sync with gtk_menu_detach()
3682 g_object_freeze_notify (G_OBJECT (widget));
3683 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3685 toplevel = gtk_widget_get_toplevel (widget);
3686 if (gtk_widget_is_toplevel (toplevel))
3687 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3689 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3690 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3692 /* If we are unanchoring the child, we save around the toplevel
3693 * to emit hierarchy changed
3695 if (priv->parent->priv->anchored)
3696 g_object_ref (toplevel);
3700 gtk_widget_queue_draw_child (widget);
3702 /* Reset the width and height here, to force reallocation if we
3703 * get added back to a new parent. This won't work if our new
3704 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3705 * (would 0x0 be OK here?)
3707 priv->allocation.width = 1;
3708 priv->allocation.height = 1;
3710 if (gtk_widget_get_realized (widget))
3712 if (priv->in_reparent)
3713 gtk_widget_unmap (widget);
3715 gtk_widget_unrealize (widget);
3718 /* Removing a widget from a container restores the child visible
3719 * flag to the default state, so it doesn't affect the child
3720 * in the next parent.
3722 priv->child_visible = TRUE;
3724 old_parent = priv->parent;
3725 priv->parent = NULL;
3726 gtk_widget_set_parent_window (widget, NULL);
3728 /* parent may no longer expand if the removed
3729 * child was expand=TRUE and could therefore
3732 if (gtk_widget_get_visible (widget) &&
3733 (priv->need_compute_expand ||
3734 priv->computed_hexpand ||
3735 priv->computed_vexpand))
3737 gtk_widget_queue_compute_expand (old_parent);
3740 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3743 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3744 g_object_unref (toplevel);
3747 g_object_notify (G_OBJECT (widget), "parent");
3748 g_object_thaw_notify (G_OBJECT (widget));
3750 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3751 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3752 g_object_unref (widget);
3756 * gtk_widget_destroy:
3757 * @widget: a #GtkWidget
3759 * Destroys a widget.
3762 * destroyed, it will break any references it holds to other objects.
3763 * If the widget is inside a container, the widget will be removed
3764 * from the container. If the widget is a toplevel (derived from
3765 * #GtkWindow), it will be removed from the list of toplevels, and the
3766 * reference GTK+ holds to it will be removed. Removing a
3767 * widget from its container or the list of toplevels results in the
3768 * widget being finalized, unless you've added additional references
3769 * to the widget with g_object_ref().
3771 * In most cases, only toplevel widgets (windows) require explicit
3772 * destruction, because when you destroy a toplevel its children will
3773 * be destroyed as well.
3776 gtk_widget_destroy (GtkWidget *widget)
3778 g_return_if_fail (GTK_IS_WIDGET (widget));
3780 if (!widget->priv->in_destruction)
3781 g_object_run_dispose (G_OBJECT (widget));
3785 * gtk_widget_destroyed:
3786 * @widget: a #GtkWidget
3787 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3789 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3790 * %NULL. It's intended to be used as a callback connected to the
3791 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3792 * as a signal handler, and pass the address of your widget variable
3793 * as user data. Then when the widget is destroyed, the variable will
3794 * be set to %NULL. Useful for example to avoid multiple copies
3795 * of the same dialog.
3798 gtk_widget_destroyed (GtkWidget *widget,
3799 GtkWidget **widget_pointer)
3801 /* Don't make any assumptions about the
3803 * Even check widget_pointer.
3806 *widget_pointer = NULL;
3811 * @widget: a #GtkWidget
3813 * Flags a widget to be displayed. Any widget that isn't shown will
3814 * not appear on the screen. If you want to show all the widgets in a
3815 * container, it's easier to call gtk_widget_show_all() on the
3816 * container, instead of individually showing the widgets.
3818 * Remember that you have to show the containers containing a widget,
3819 * in addition to the widget itself, before it will appear onscreen.
3821 * When a toplevel container is shown, it is immediately realized and
3822 * mapped; other shown widgets are realized and mapped when their
3823 * toplevel container is realized and mapped.
3826 gtk_widget_show (GtkWidget *widget)
3828 g_return_if_fail (GTK_IS_WIDGET (widget));
3830 if (!gtk_widget_get_visible (widget))
3832 g_object_ref (widget);
3833 if (!gtk_widget_is_toplevel (widget))
3834 gtk_widget_queue_resize (widget);
3836 /* see comment in set_parent() for why this should and can be
3839 if (widget->priv->need_compute_expand ||
3840 widget->priv->computed_hexpand ||
3841 widget->priv->computed_vexpand)
3843 if (widget->priv->parent != NULL)
3844 gtk_widget_queue_compute_expand (widget->priv->parent);
3847 g_signal_emit (widget, widget_signals[SHOW], 0);
3848 g_object_notify (G_OBJECT (widget), "visible");
3849 g_object_unref (widget);
3854 gtk_widget_real_show (GtkWidget *widget)
3856 GtkWidgetPrivate *priv = widget->priv;
3858 if (!gtk_widget_get_visible (widget))
3860 priv->visible = TRUE;
3863 gtk_widget_get_mapped (priv->parent) &&
3864 gtk_widget_get_child_visible (widget) &&
3865 !gtk_widget_get_mapped (widget))
3866 gtk_widget_map (widget);
3871 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3874 g_signal_handlers_disconnect_by_func (widget,
3875 gtk_widget_show_map_callback,
3880 * gtk_widget_show_now:
3881 * @widget: a #GtkWidget
3883 * Shows a widget. If the widget is an unmapped toplevel widget
3884 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3885 * loop and wait for the window to actually be mapped. Be careful;
3886 * because the main loop is running, anything can happen during
3890 gtk_widget_show_now (GtkWidget *widget)
3894 g_return_if_fail (GTK_IS_WIDGET (widget));
3896 /* make sure we will get event */
3897 if (!gtk_widget_get_mapped (widget) &&
3898 gtk_widget_is_toplevel (widget))
3900 gtk_widget_show (widget);
3902 g_signal_connect (widget, "map-event",
3903 G_CALLBACK (gtk_widget_show_map_callback),
3907 gtk_main_iteration ();
3910 gtk_widget_show (widget);
3915 * @widget: a #GtkWidget
3917 * Reverses the effects of gtk_widget_show(), causing the widget to be
3918 * hidden (invisible to the user).
3921 gtk_widget_hide (GtkWidget *widget)
3923 g_return_if_fail (GTK_IS_WIDGET (widget));
3925 if (gtk_widget_get_visible (widget))
3927 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3929 g_object_ref (widget);
3930 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3931 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3933 /* a parent may now be expand=FALSE since we're hidden. */
3934 if (widget->priv->need_compute_expand ||
3935 widget->priv->computed_hexpand ||
3936 widget->priv->computed_vexpand)
3938 gtk_widget_queue_compute_expand (widget);
3941 g_signal_emit (widget, widget_signals[HIDE], 0);
3942 if (!gtk_widget_is_toplevel (widget))
3943 gtk_widget_queue_resize (widget);
3944 g_object_notify (G_OBJECT (widget), "visible");
3945 g_object_unref (widget);
3950 gtk_widget_real_hide (GtkWidget *widget)
3952 if (gtk_widget_get_visible (widget))
3954 widget->priv->visible = FALSE;
3956 if (gtk_widget_get_mapped (widget))
3957 gtk_widget_unmap (widget);
3962 * gtk_widget_hide_on_delete:
3963 * @widget: a #GtkWidget
3965 * Utility function; intended to be connected to the #GtkWidget::delete-event
3966 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3967 * argument, then returns %TRUE. If connected to ::delete-event, the
3968 * result is that clicking the close button for a window (on the
3969 * window frame, top right corner usually) will hide but not destroy
3970 * the window. By default, GTK+ destroys windows when ::delete-event
3973 * Return value: %TRUE
3976 gtk_widget_hide_on_delete (GtkWidget *widget)
3978 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3980 gtk_widget_hide (widget);
3986 * gtk_widget_show_all:
3987 * @widget: a #GtkWidget
3989 * Recursively shows a widget, and any child widgets (if the widget is
3993 gtk_widget_show_all (GtkWidget *widget)
3995 GtkWidgetClass *class;
3997 g_return_if_fail (GTK_IS_WIDGET (widget));
3999 if (gtk_widget_get_no_show_all (widget))
4002 class = GTK_WIDGET_GET_CLASS (widget);
4004 if (class->show_all)
4005 class->show_all (widget);
4010 * @widget: a #GtkWidget
4012 * This function is only for use in widget implementations. Causes
4013 * a widget to be mapped if it isn't already.
4016 gtk_widget_map (GtkWidget *widget)
4018 GtkWidgetPrivate *priv;
4020 g_return_if_fail (GTK_IS_WIDGET (widget));
4021 g_return_if_fail (gtk_widget_get_visible (widget));
4022 g_return_if_fail (gtk_widget_get_child_visible (widget));
4024 priv = widget->priv;
4026 if (!gtk_widget_get_mapped (widget))
4028 if (!gtk_widget_get_realized (widget))
4029 gtk_widget_realize (widget);
4031 g_signal_emit (widget, widget_signals[MAP], 0);
4033 if (!gtk_widget_get_has_window (widget))
4034 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4040 * @widget: a #GtkWidget
4042 * This function is only for use in widget implementations. Causes
4043 * a widget to be unmapped if it's currently mapped.
4046 gtk_widget_unmap (GtkWidget *widget)
4048 GtkWidgetPrivate *priv;
4050 g_return_if_fail (GTK_IS_WIDGET (widget));
4052 priv = widget->priv;
4054 if (gtk_widget_get_mapped (widget))
4056 if (!gtk_widget_get_has_window (widget))
4057 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4058 _gtk_tooltip_hide (widget);
4059 g_signal_emit (widget, widget_signals[UNMAP], 0);
4064 gtk_widget_set_extension_events_internal (GtkWidget *widget,
4065 GdkExtensionMode mode,
4068 GtkWidgetPrivate *priv = widget->priv;
4069 GList *free_list = NULL;
4072 if (window_list == NULL)
4074 if (gtk_widget_get_has_window (widget))
4075 window_list = g_list_prepend (NULL, priv->window);
4077 window_list = gdk_window_get_children (priv->window);
4079 free_list = window_list;
4082 for (l = window_list; l != NULL; l = l->next)
4084 GdkWindow *window = l->data;
4087 gdk_window_get_user_data (window, &user_data);
4088 if (user_data == widget)
4092 gdk_input_set_extension_events (window,
4093 gdk_window_get_events (window),
4096 children = gdk_window_get_children (window);
4099 gtk_widget_set_extension_events_internal (widget, mode, children);
4100 g_list_free (children);
4106 g_list_free (free_list);
4110 _gtk_widget_enable_device_events (GtkWidget *widget)
4112 GHashTable *device_events;
4113 GHashTableIter iter;
4114 gpointer key, value;
4116 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4121 g_hash_table_iter_init (&iter, device_events);
4123 while (g_hash_table_iter_next (&iter, &key, &value))
4126 GdkEventMask event_mask;
4129 event_mask = GPOINTER_TO_UINT (value);
4130 gtk_widget_add_events_internal (widget, device, event_mask);
4135 * gtk_widget_realize:
4136 * @widget: a #GtkWidget
4138 * Creates the GDK (windowing system) resources associated with a
4139 * widget. For example, @widget->window will be created when a widget
4140 * is realized. Normally realization happens implicitly; if you show
4141 * a widget and all its parent containers, then the widget will be
4142 * realized and mapped automatically.
4144 * Realizing a widget requires all
4145 * the widget's parent widgets to be realized; calling
4146 * gtk_widget_realize() realizes the widget's parents in addition to
4147 * @widget itself. If a widget is not yet inside a toplevel window
4148 * when you realize it, bad things will happen.
4150 * This function is primarily used in widget implementations, and
4151 * isn't very useful otherwise. Many times when you think you might
4152 * need it, a better approach is to connect to a signal that will be
4153 * called after the widget is realized automatically, such as
4154 * #GtkWidget::expose-event. Or simply g_signal_connect () to the
4155 * #GtkWidget::realize signal.
4158 gtk_widget_realize (GtkWidget *widget)
4160 GtkWidgetPrivate *priv;
4161 GdkExtensionMode mode;
4162 cairo_region_t *region;
4163 GtkStyleContext *context;
4165 g_return_if_fail (GTK_IS_WIDGET (widget));
4166 g_return_if_fail (widget->priv->anchored ||
4167 GTK_IS_INVISIBLE (widget));
4169 priv = widget->priv;
4171 if (!gtk_widget_get_realized (widget))
4174 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4175 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4178 if (priv->parent == NULL &&
4179 !gtk_widget_is_toplevel (widget))
4180 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4181 "inside a toplevel window is not going to work very well. "
4182 "Widgets must be inside a toplevel container before realizing them.");
4184 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4185 gtk_widget_realize (priv->parent);
4187 gtk_widget_ensure_style (widget);
4189 g_signal_emit (widget, widget_signals[REALIZE], 0);
4191 gtk_widget_real_set_has_tooltip (widget,
4192 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4195 if (priv->has_shape_mask)
4197 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4198 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4201 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4203 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4205 mode = gtk_widget_get_extension_events (widget);
4206 if (mode != GDK_EXTENSION_EVENTS_NONE)
4207 gtk_widget_set_extension_events_internal (widget, mode, NULL);
4209 if (priv->multidevice)
4210 gdk_window_set_support_multidevice (priv->window, TRUE);
4212 _gtk_widget_enable_device_events (widget);
4217 * gtk_widget_unrealize:
4218 * @widget: a #GtkWidget
4220 * This function is only useful in widget implementations.
4221 * Causes a widget to be unrealized (frees all GDK resources
4222 * associated with the widget, such as @widget->window).
4225 gtk_widget_unrealize (GtkWidget *widget)
4227 g_return_if_fail (GTK_IS_WIDGET (widget));
4229 if (widget->priv->has_shape_mask)
4230 gtk_widget_shape_combine_region (widget, NULL);
4232 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4233 gtk_widget_input_shape_combine_region (widget, NULL);
4235 if (gtk_widget_get_realized (widget))
4237 g_object_ref (widget);
4238 _gtk_tooltip_hide (widget);
4239 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4240 gtk_widget_set_realized (widget, FALSE);
4241 gtk_widget_set_mapped (widget, FALSE);
4242 g_object_unref (widget);
4246 /*****************************************
4248 *****************************************/
4251 * gtk_widget_queue_draw_region:
4252 * @widget: a #GtkWidget
4253 * @region: region to draw
4255 * Invalidates the rectangular area of @widget defined by @region by
4256 * calling gdk_window_invalidate_region() on the widget's window and
4257 * all its child windows. Once the main loop becomes idle (after the
4258 * current batch of events has been processed, roughly), the window
4259 * will receive expose events for the union of all regions that have
4262 * Normally you would only use this function in widget
4263 * implementations. You might also use it to schedule a redraw of a
4264 * #GtkDrawingArea or some portion thereof.
4267 gtk_widget_queue_draw_region (GtkWidget *widget,
4268 cairo_region_t *region)
4270 GtkWidgetPrivate *priv;
4273 g_return_if_fail (GTK_IS_WIDGET (widget));
4275 priv = widget->priv;
4277 if (!gtk_widget_get_realized (widget))
4280 /* Just return if the widget or one of its ancestors isn't mapped */
4281 for (w = widget; w != NULL; w = w->priv->parent)
4282 if (!gtk_widget_get_mapped (w))
4285 gdk_window_invalidate_region (priv->window, region, TRUE);
4289 * gtk_widget_queue_draw_area:
4290 * @widget: a #GtkWidget
4291 * @x: x coordinate of upper-left corner of rectangle to redraw
4292 * @y: y coordinate of upper-left corner of rectangle to redraw
4293 * @width: width of region to draw
4294 * @height: height of region to draw
4296 * Convenience function that calls gtk_widget_queue_draw_region() on
4297 * the region created from the given coordinates.
4300 gtk_widget_queue_draw_area (GtkWidget *widget,
4307 cairo_region_t *region;
4309 g_return_if_fail (GTK_IS_WIDGET (widget));
4314 rect.height = height;
4316 region = cairo_region_create_rectangle (&rect);
4317 gtk_widget_queue_draw_region (widget, region);
4318 cairo_region_destroy (region);
4322 * gtk_widget_queue_draw:
4323 * @widget: a #GtkWidget
4325 * Equivalent to calling gtk_widget_queue_draw_area() for the
4326 * entire area of a widget.
4329 gtk_widget_queue_draw (GtkWidget *widget)
4333 g_return_if_fail (GTK_IS_WIDGET (widget));
4335 gtk_widget_get_allocation (widget, &rect);
4337 if (!gtk_widget_get_has_window (widget))
4338 gtk_widget_queue_draw_area (widget,
4339 rect.x, rect.y, rect.width, rect.height);
4341 gtk_widget_queue_draw_area (widget,
4342 0, 0, rect.width, rect.height);
4346 * gtk_widget_queue_resize:
4347 * @widget: a #GtkWidget
4349 * This function is only for use in widget implementations.
4350 * Flags a widget to have its size renegotiated; should
4351 * be called when a widget for some reason has a new size request.
4352 * For example, when you change the text in a #GtkLabel, #GtkLabel
4353 * queues a resize to ensure there's enough space for the new text.
4355 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4356 * from inside it's implementation of the GtkWidgetClass::size_allocate
4357 * virtual method. Calls to gtk_widget_queue_resize() from inside
4358 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4361 gtk_widget_queue_resize (GtkWidget *widget)
4363 g_return_if_fail (GTK_IS_WIDGET (widget));
4365 if (gtk_widget_get_realized (widget))
4366 gtk_widget_queue_shallow_draw (widget);
4368 _gtk_size_group_queue_resize (widget, 0);
4372 * gtk_widget_queue_resize_no_redraw:
4373 * @widget: a #GtkWidget
4375 * This function works like gtk_widget_queue_resize(),
4376 * except that the widget is not invalidated.
4381 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4383 g_return_if_fail (GTK_IS_WIDGET (widget));
4385 _gtk_size_group_queue_resize (widget, 0);
4389 * gtk_widget_size_request:
4390 * @widget: a #GtkWidget
4391 * @requisition: (out): a #GtkRequisition to be filled in
4393 * This function is typically used when implementing a #GtkContainer
4394 * subclass. Obtains the preferred size of a widget. The container
4395 * uses this information to arrange its child widgets and decide what
4396 * size allocations to give them with gtk_widget_size_allocate().
4398 * You can also call this function from an application, with some
4399 * caveats. Most notably, getting a size request requires the widget
4400 * to be associated with a screen, because font information may be
4401 * needed. Multihead-aware applications should keep this in mind.
4403 * Also remember that the size request is not necessarily the size
4404 * a widget will actually be allocated.
4406 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4409 gtk_widget_size_request (GtkWidget *widget,
4410 GtkRequisition *requisition)
4412 g_return_if_fail (GTK_IS_WIDGET (widget));
4414 gtk_widget_get_preferred_size (widget, requisition, NULL);
4418 * gtk_widget_get_child_requisition:
4419 * @widget: a #GtkWidget
4420 * @requisition: (out): a #GtkRequisition to be filled in
4422 * This function is only for use in widget implementations. Obtains
4423 * @widget->requisition, unless someone has forced a particular
4424 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4425 * in which case it returns that geometry instead of the widget's
4428 * This function differs from gtk_widget_size_request() in that
4429 * it retrieves the last size request value from @widget->requisition,
4430 * while gtk_widget_size_request() actually calls the "size_request" method
4431 * on @widget to compute the size request and fill in @widget->requisition,
4432 * and only then returns @widget->requisition.
4434 * Because this function does not call the "size_request" method, it
4435 * can only be used when you know that @widget->requisition is
4436 * up-to-date, that is, gtk_widget_size_request() has been called
4437 * since the last time a resize was queued. In general, only container
4438 * implementations have this information; applications should use
4439 * gtk_widget_size_request().
4442 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4445 gtk_widget_get_child_requisition (GtkWidget *widget,
4446 GtkRequisition *requisition)
4448 gtk_widget_get_preferred_size (widget, requisition, NULL);
4452 invalidate_predicate (GdkWindow *window,
4457 gdk_window_get_user_data (window, &user_data);
4459 return (user_data == data);
4462 /* Invalidate @region in widget->window and all children
4463 * of widget->window owned by widget. @region is in the
4464 * same coordinates as widget->allocation and will be
4465 * modified by this call.
4468 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4469 cairo_region_t *region)
4471 GtkWidgetPrivate *priv = widget->priv;
4473 if (!gtk_widget_get_realized (widget))
4476 if (gtk_widget_get_has_window (widget) && priv->parent)
4480 gdk_window_get_position (priv->window, &x, &y);
4481 cairo_region_translate (region, -x, -y);
4484 gdk_window_invalidate_maybe_recurse (priv->window, region,
4485 invalidate_predicate, widget);
4489 * gtk_widget_queue_shallow_draw:
4490 * @widget: a #GtkWidget
4492 * Like gtk_widget_queue_draw(), but only windows owned
4493 * by @widget are invalidated.
4496 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4499 cairo_region_t *region;
4501 if (!gtk_widget_get_realized (widget))
4504 gtk_widget_get_allocation (widget, &rect);
4506 region = cairo_region_create_rectangle (&rect);
4507 gtk_widget_invalidate_widget_windows (widget, region);
4508 cairo_region_destroy (region);
4512 * gtk_widget_size_allocate:
4513 * @widget: a #GtkWidget
4514 * @allocation: (inout): position and size to be allocated to @widget
4516 * This function is only used by #GtkContainer subclasses, to assign a size
4517 * and position to their child widgets.
4519 * In this function, the allocation may be adjusted. It will be forced
4520 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4521 * method on the child will be used to adjust the allocation. Standard
4522 * adjustments include removing the widget's margins, and applying the
4523 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4526 gtk_widget_size_allocate (GtkWidget *widget,
4527 GtkAllocation *allocation)
4529 GtkWidgetPrivate *priv;
4530 GdkRectangle real_allocation;
4531 GdkRectangle old_allocation;
4532 GdkRectangle adjusted_allocation;
4533 gboolean alloc_needed;
4534 gboolean size_changed;
4535 gboolean position_changed;
4536 gint natural_width, natural_height;
4537 gint min_width, min_height;
4539 priv = widget->priv;
4541 g_return_if_fail (GTK_IS_WIDGET (widget));
4543 #ifdef G_ENABLE_DEBUG
4544 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4555 parent = gtk_widget_get_parent (parent);
4558 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4559 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4560 2 * depth, " ", name,
4561 allocation->width, allocation->height);
4563 #endif /* G_ENABLE_DEBUG */
4565 alloc_needed = priv->alloc_needed;
4566 if (!priv->width_request_needed && !priv->height_request_needed)
4567 /* Preserve request/allocate ordering */
4568 priv->alloc_needed = FALSE;
4570 old_allocation = priv->allocation;
4571 real_allocation = *allocation;
4573 adjusted_allocation = real_allocation;
4574 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4576 /* Go ahead and request the height for allocated width, note that the internals
4577 * of get_height_for_width will internally limit the for_size to natural size
4578 * when aligning implicitly.
4580 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4581 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, NULL, &natural_height);
4585 /* Go ahead and request the width for allocated height, note that the internals
4586 * of get_width_for_height will internally limit the for_size to natural size
4587 * when aligning implicitly.
4589 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4590 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, NULL, &natural_width);
4593 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4594 * allocated sizes and possibly limit them to the natural sizes */
4595 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4596 GTK_ORIENTATION_HORIZONTAL,
4598 &adjusted_allocation.x,
4599 &adjusted_allocation.width);
4600 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4601 GTK_ORIENTATION_VERTICAL,
4603 &adjusted_allocation.y,
4604 &adjusted_allocation.height);
4606 if (adjusted_allocation.x < real_allocation.x ||
4607 adjusted_allocation.y < real_allocation.y ||
4608 (adjusted_allocation.x + adjusted_allocation.width) >
4609 (real_allocation.x + real_allocation.width) ||
4610 (adjusted_allocation.y + adjusted_allocation.height >
4611 real_allocation.y + real_allocation.height))
4613 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",
4614 G_OBJECT_TYPE_NAME (widget), widget,
4615 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4616 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4617 adjusted_allocation = real_allocation; /* veto it */
4621 real_allocation = adjusted_allocation;
4624 if (real_allocation.width < 0 || real_allocation.height < 0)
4626 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4627 real_allocation.width,
4628 real_allocation.height);
4631 real_allocation.width = MAX (real_allocation.width, 1);
4632 real_allocation.height = MAX (real_allocation.height, 1);
4634 size_changed = (old_allocation.width != real_allocation.width ||
4635 old_allocation.height != real_allocation.height);
4636 position_changed = (old_allocation.x != real_allocation.x ||
4637 old_allocation.y != real_allocation.y);
4639 if (!alloc_needed && !size_changed && !position_changed)
4642 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4644 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4645 priv->width_request_needed = FALSE;
4646 priv->height_request_needed = FALSE;
4647 priv->alloc_needed = FALSE;
4649 if (gtk_widget_get_mapped (widget))
4651 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4653 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4655 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4656 cairo_region_union_rectangle (invalidate, &old_allocation);
4658 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4659 cairo_region_destroy (invalidate);
4664 if (priv->redraw_on_alloc)
4666 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4668 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4669 cairo_region_union_rectangle (invalidate, &old_allocation);
4671 gtk_widget_invalidate_widget_windows (widget, invalidate);
4672 cairo_region_destroy (invalidate);
4676 if (size_changed || position_changed)
4678 GtkStyleContext *context;
4680 context = gtk_widget_get_style_context (widget);
4681 _gtk_style_context_invalidate_animation_areas (context);
4685 if ((size_changed || position_changed) && priv->parent &&
4686 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4688 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4689 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4690 cairo_region_destroy (invalidate);
4695 * gtk_widget_common_ancestor:
4696 * @widget_a: a #GtkWidget
4697 * @widget_b: a #GtkWidget
4699 * Find the common ancestor of @widget_a and @widget_b that
4700 * is closest to the two widgets.
4702 * Return value: the closest common ancestor of @widget_a and
4703 * @widget_b or %NULL if @widget_a and @widget_b do not
4704 * share a common ancestor.
4707 gtk_widget_common_ancestor (GtkWidget *widget_a,
4708 GtkWidget *widget_b)
4710 GtkWidget *parent_a;
4711 GtkWidget *parent_b;
4715 parent_a = widget_a;
4716 while (parent_a->priv->parent)
4718 parent_a = parent_a->priv->parent;
4722 parent_b = widget_b;
4723 while (parent_b->priv->parent)
4725 parent_b = parent_b->priv->parent;
4729 if (parent_a != parent_b)
4732 while (depth_a > depth_b)
4734 widget_a = widget_a->priv->parent;
4738 while (depth_b > depth_a)
4740 widget_b = widget_b->priv->parent;
4744 while (widget_a != widget_b)
4746 widget_a = widget_a->priv->parent;
4747 widget_b = widget_b->priv->parent;
4754 * gtk_widget_translate_coordinates:
4755 * @src_widget: a #GtkWidget
4756 * @dest_widget: a #GtkWidget
4757 * @src_x: X position relative to @src_widget
4758 * @src_y: Y position relative to @src_widget
4759 * @dest_x: (out): location to store X position relative to @dest_widget
4760 * @dest_y: (out): location to store Y position relative to @dest_widget
4762 * Translate coordinates relative to @src_widget's allocation to coordinates
4763 * relative to @dest_widget's allocations. In order to perform this
4764 * operation, both widgets must be realized, and must share a common
4767 * Return value: %FALSE if either widget was not realized, or there
4768 * was no common ancestor. In this case, nothing is stored in
4769 * *@dest_x and *@dest_y. Otherwise %TRUE.
4772 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4773 GtkWidget *dest_widget,
4779 GtkWidgetPrivate *src_priv = src_widget->priv;
4780 GtkWidgetPrivate *dest_priv = dest_widget->priv;
4781 GtkWidget *ancestor;
4783 GList *dest_list = NULL;
4785 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4786 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4788 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4789 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4792 /* Translate from allocation relative to window relative */
4793 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
4796 gdk_window_get_position (src_priv->window, &wx, &wy);
4798 src_x -= wx - src_priv->allocation.x;
4799 src_y -= wy - src_priv->allocation.y;
4803 src_x += src_priv->allocation.x;
4804 src_y += src_priv->allocation.y;
4807 /* Translate to the common ancestor */
4808 window = src_priv->window;
4809 while (window != ancestor->priv->window)
4813 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4818 window = gdk_window_get_effective_parent (window);
4820 if (!window) /* Handle GtkHandleBox */
4825 window = dest_priv->window;
4826 while (window != ancestor->priv->window)
4828 dest_list = g_list_prepend (dest_list, window);
4830 window = gdk_window_get_effective_parent (window);
4832 if (!window) /* Handle GtkHandleBox */
4834 g_list_free (dest_list);
4843 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4848 dest_list = g_list_remove (dest_list, dest_list->data);
4851 /* Translate from window relative to allocation relative */
4852 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
4855 gdk_window_get_position (dest_priv->window, &wx, &wy);
4857 src_x += wx - dest_priv->allocation.x;
4858 src_y += wy - dest_priv->allocation.y;
4862 src_x -= dest_priv->allocation.x;
4863 src_y -= dest_priv->allocation.y;
4875 gtk_widget_real_size_allocate (GtkWidget *widget,
4876 GtkAllocation *allocation)
4878 GtkWidgetPrivate *priv = widget->priv;
4880 priv->allocation = *allocation;
4882 if (gtk_widget_get_realized (widget) &&
4883 gtk_widget_get_has_window (widget))
4885 gdk_window_move_resize (priv->window,
4886 allocation->x, allocation->y,
4887 allocation->width, allocation->height);
4892 adjust_for_align(GtkAlign align,
4894 gint *allocated_pos,
4895 gint *allocated_size)
4899 case GTK_ALIGN_FILL:
4900 /* change nothing */
4902 case GTK_ALIGN_START:
4903 /* keep *allocated_pos where it is */
4904 *allocated_size = MIN (*allocated_size, *natural_size);
4907 if (*allocated_size > *natural_size)
4909 *allocated_pos += (*allocated_size - *natural_size);
4910 *allocated_size = *natural_size;
4913 case GTK_ALIGN_CENTER:
4914 if (*allocated_size > *natural_size)
4916 *allocated_pos += (*allocated_size - *natural_size) / 2;
4917 *allocated_size = MIN (*allocated_size, *natural_size);
4924 adjust_for_margin(gint start_margin,
4927 gint *allocated_pos,
4928 gint *allocated_size)
4930 *natural_size -= (start_margin + end_margin);
4931 *allocated_pos += start_margin;
4932 *allocated_size -= (start_margin + end_margin);
4936 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
4937 GtkOrientation orientation,
4939 gint *allocated_pos,
4940 gint *allocated_size)
4942 const GtkWidgetAuxInfo *aux_info;
4944 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
4946 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4948 adjust_for_margin (aux_info->margin.left,
4949 aux_info->margin.right,
4950 natural_size, allocated_pos, allocated_size);
4951 adjust_for_align (aux_info->halign,
4952 natural_size, allocated_pos, allocated_size);
4956 adjust_for_margin (aux_info->margin.top,
4957 aux_info->margin.bottom,
4958 natural_size, allocated_pos, allocated_size);
4959 adjust_for_align (aux_info->valign,
4960 natural_size, allocated_pos, allocated_size);
4965 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4968 GtkWidgetPrivate *priv = widget->priv;
4970 /* widgets must be onscreen for accels to take effect */
4971 return gtk_widget_is_sensitive (widget) &&
4972 gtk_widget_is_drawable (widget) &&
4973 gdk_window_is_viewable (priv->window);
4977 * gtk_widget_can_activate_accel:
4978 * @widget: a #GtkWidget
4979 * @signal_id: the ID of a signal installed on @widget
4981 * Determines whether an accelerator that activates the signal
4982 * identified by @signal_id can currently be activated.
4983 * This is done by emitting the #GtkWidget::can-activate-accel
4984 * signal on @widget; if the signal isn't overridden by a
4985 * handler or in a derived widget, then the default check is
4986 * that the widget must be sensitive, and the widget and all
4987 * its ancestors mapped.
4989 * Return value: %TRUE if the accelerator can be activated.
4994 gtk_widget_can_activate_accel (GtkWidget *widget,
4997 gboolean can_activate = FALSE;
4998 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4999 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5000 return can_activate;
5009 closure_accel_activate (GClosure *closure,
5010 GValue *return_value,
5011 guint n_param_values,
5012 const GValue *param_values,
5013 gpointer invocation_hint,
5014 gpointer marshal_data)
5016 AccelClosure *aclosure = (AccelClosure*) closure;
5017 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5020 g_signal_emit (closure->data, aclosure->signal_id, 0);
5022 /* whether accelerator was handled */
5023 g_value_set_boolean (return_value, can_activate);
5027 closures_destroy (gpointer data)
5029 GSList *slist, *closures = data;
5031 for (slist = closures; slist; slist = slist->next)
5033 g_closure_invalidate (slist->data);
5034 g_closure_unref (slist->data);
5036 g_slist_free (closures);
5040 widget_new_accel_closure (GtkWidget *widget,
5043 AccelClosure *aclosure;
5044 GClosure *closure = NULL;
5045 GSList *slist, *closures;
5047 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5048 for (slist = closures; slist; slist = slist->next)
5049 if (!gtk_accel_group_from_accel_closure (slist->data))
5051 /* reuse this closure */
5052 closure = slist->data;
5057 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5058 closures = g_slist_prepend (closures, g_closure_ref (closure));
5059 g_closure_sink (closure);
5060 g_closure_set_marshal (closure, closure_accel_activate);
5062 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5064 aclosure = (AccelClosure*) closure;
5065 g_assert (closure->data == widget);
5066 g_assert (closure->marshal == closure_accel_activate);
5067 aclosure->signal_id = signal_id;
5073 * gtk_widget_add_accelerator
5074 * @widget: widget to install an accelerator on
5075 * @accel_signal: widget signal to emit on accelerator activation
5076 * @accel_group: accel group for this widget, added to its toplevel
5077 * @accel_key: GDK keyval of the accelerator
5078 * @accel_mods: modifier key combination of the accelerator
5079 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5081 * Installs an accelerator for this @widget in @accel_group that causes
5082 * @accel_signal to be emitted if the accelerator is activated.
5083 * The @accel_group needs to be added to the widget's toplevel via
5084 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5085 * Accelerators added through this function are not user changeable during
5086 * runtime. If you want to support accelerators that can be changed by the
5087 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5088 * gtk_menu_item_set_accel_path() instead.
5091 gtk_widget_add_accelerator (GtkWidget *widget,
5092 const gchar *accel_signal,
5093 GtkAccelGroup *accel_group,
5095 GdkModifierType accel_mods,
5096 GtkAccelFlags accel_flags)
5101 g_return_if_fail (GTK_IS_WIDGET (widget));
5102 g_return_if_fail (accel_signal != NULL);
5103 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5105 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5106 if (!query.signal_id ||
5107 !(query.signal_flags & G_SIGNAL_ACTION) ||
5108 query.return_type != G_TYPE_NONE ||
5111 /* hmm, should be elaborate enough */
5112 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5113 G_OBJECT_TYPE_NAME (widget), accel_signal);
5117 closure = widget_new_accel_closure (widget, query.signal_id);
5119 g_object_ref (widget);
5121 /* install the accelerator. since we don't map this onto an accel_path,
5122 * the accelerator will automatically be locked.
5124 gtk_accel_group_connect (accel_group,
5127 accel_flags | GTK_ACCEL_LOCKED,
5130 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5132 g_object_unref (widget);
5136 * gtk_widget_remove_accelerator:
5137 * @widget: widget to install an accelerator on
5138 * @accel_group: accel group for this widget
5139 * @accel_key: GDK keyval of the accelerator
5140 * @accel_mods: modifier key combination of the accelerator
5141 * @returns: whether an accelerator was installed and could be removed
5143 * Removes an accelerator from @widget, previously installed with
5144 * gtk_widget_add_accelerator().
5147 gtk_widget_remove_accelerator (GtkWidget *widget,
5148 GtkAccelGroup *accel_group,
5150 GdkModifierType accel_mods)
5152 GtkAccelGroupEntry *ag_entry;
5153 GList *slist, *clist;
5156 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5157 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5159 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5160 clist = gtk_widget_list_accel_closures (widget);
5161 for (slist = clist; slist; slist = slist->next)
5165 for (i = 0; i < n; i++)
5166 if (slist->data == (gpointer) ag_entry[i].closure)
5168 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5170 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5172 g_list_free (clist);
5177 g_list_free (clist);
5179 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5180 accel_key, accel_mods, accel_group,
5181 G_OBJECT_TYPE_NAME (widget), widget);
5187 * gtk_widget_list_accel_closures:
5188 * @widget: widget to list accelerator closures for
5190 * Lists the closures used by @widget for accelerator group connections
5191 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5192 * The closures can be used to monitor accelerator changes on @widget,
5193 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5194 * #GtkAccelGroup of a closure which can be found out with
5195 * gtk_accel_group_from_accel_closure().
5197 * Return value: (transfer container) (element-type GClosure):
5198 * a newly allocated #GList of closures
5201 gtk_widget_list_accel_closures (GtkWidget *widget)
5204 GList *clist = NULL;
5206 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5208 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5209 if (gtk_accel_group_from_accel_closure (slist->data))
5210 clist = g_list_prepend (clist, slist->data);
5216 GtkAccelGroup *accel_group;
5221 destroy_accel_path (gpointer data)
5223 AccelPath *apath = data;
5225 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5227 /* closures_destroy takes care of unrefing the closure */
5228 g_object_unref (apath->accel_group);
5230 g_slice_free (AccelPath, apath);
5235 * gtk_widget_set_accel_path:
5236 * @widget: a #GtkWidget
5237 * @accel_path: (allow-none): path used to look up the accelerator
5238 * @accel_group: (allow-none): a #GtkAccelGroup.
5240 * Given an accelerator group, @accel_group, and an accelerator path,
5241 * @accel_path, sets up an accelerator in @accel_group so whenever the
5242 * key binding that is defined for @accel_path is pressed, @widget
5243 * will be activated. This removes any accelerators (for any
5244 * accelerator group) installed by previous calls to
5245 * gtk_widget_set_accel_path(). Associating accelerators with
5246 * paths allows them to be modified by the user and the modifications
5247 * to be saved for future use. (See gtk_accel_map_save().)
5249 * This function is a low level function that would most likely
5250 * be used by a menu creation system like #GtkUIManager. If you
5251 * use #GtkUIManager, setting up accelerator paths will be done
5254 * Even when you you aren't using #GtkUIManager, if you only want to
5255 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5256 * provides a somewhat more convenient interface.
5258 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5259 * pass a static string, you can save some memory by interning it first with
5260 * g_intern_static_string().
5263 gtk_widget_set_accel_path (GtkWidget *widget,
5264 const gchar *accel_path,
5265 GtkAccelGroup *accel_group)
5269 g_return_if_fail (GTK_IS_WIDGET (widget));
5270 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5274 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5275 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5277 gtk_accel_map_add_entry (accel_path, 0, 0);
5278 apath = g_slice_new (AccelPath);
5279 apath->accel_group = g_object_ref (accel_group);
5280 apath->path_quark = g_quark_from_string (accel_path);
5281 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5286 /* also removes possible old settings */
5287 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5290 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5292 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5296 _gtk_widget_get_accel_path (GtkWidget *widget,
5301 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5303 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5305 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5306 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5310 * gtk_widget_mnemonic_activate:
5311 * @widget: a #GtkWidget
5312 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5314 * Emits the #GtkWidget::mnemonic-activate signal.
5316 * The default handler for this signal activates the @widget if
5317 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5320 * Returns: %TRUE if the signal has been handled
5323 gtk_widget_mnemonic_activate (GtkWidget *widget,
5324 gboolean group_cycling)
5328 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5330 group_cycling = group_cycling != FALSE;
5331 if (!gtk_widget_is_sensitive (widget))
5334 g_signal_emit (widget,
5335 widget_signals[MNEMONIC_ACTIVATE],
5343 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5344 gboolean group_cycling)
5346 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5347 gtk_widget_activate (widget);
5348 else if (gtk_widget_get_can_focus (widget))
5349 gtk_widget_grab_focus (widget);
5352 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5353 G_OBJECT_TYPE_NAME (widget));
5354 gtk_widget_error_bell (widget);
5359 static const cairo_user_data_key_t event_key;
5362 _gtk_cairo_get_event (cairo_t *cr)
5364 g_return_val_if_fail (cr != NULL, NULL);
5366 return cairo_get_user_data (cr, &event_key);
5370 gtk_cairo_set_event (cairo_t *cr,
5371 GdkEventExpose *event)
5373 cairo_set_user_data (cr, &event_key, event, NULL);
5377 * gtk_cairo_should_draw_window:
5378 * @cr: a cairo context
5379 * @window: the window to check
5381 * This function is supposed to be called in #GtkWidget::draw
5382 * implementations for widgets that support multiple windows.
5383 * @cr must be untransformed from invoking of the draw function.
5384 * This function will return %TRUE if the contents of the given
5385 * @window are supposed to be drawn and %FALSE otherwise. Note
5386 * that when the drawing was not initiated by the windowing
5387 * system this function will return %TRUE for all windows, so
5388 * you need to draw the bottommost window first. Also, do not
5389 * use "else if" statements to check which window should be drawn.
5391 * Returns: %TRUE if @window should be drawn
5394 gtk_cairo_should_draw_window (cairo_t *cr,
5397 GdkEventExpose *event;
5399 g_return_val_if_fail (cr != NULL, FALSE);
5400 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5402 event = _gtk_cairo_get_event (cr);
5404 return event == NULL ||
5405 event->window == window;
5408 /* code shared by gtk_container_propagate_draw() and
5412 _gtk_widget_draw_internal (GtkWidget *widget,
5414 gboolean clip_to_size)
5416 if (!gtk_widget_is_drawable (widget))
5421 cairo_rectangle (cr,
5423 widget->priv->allocation.width,
5424 widget->priv->allocation.height);
5428 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5432 g_signal_emit (widget, widget_signals[DRAW],
5440 * @widget: the widget to draw. It must be drawable (see
5441 * gtk_widget_is_drawable()) and a size must have been allocated.
5442 * @cr: a cairo context to draw to
5444 * Draws @widget to @cr. The top left corner of the widget will be
5445 * drawn to the currently set origin point of @cr.
5447 * You should pass a cairo context as @cr argument that is in an
5448 * original state. Otherwise the resulting drawing is undefined. For
5449 * example changing the operator using cairo_set_operator() or the
5450 * line width using cairo_set_line_width() might have unwanted side
5452 * You may however change the context's transform matrix - like with
5453 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5454 * region with cairo_clip() prior to calling this function. Also, it
5455 * is fine to modify the context with cairo_save() and
5456 * cairo_push_group() prior to calling this function.
5458 * <note><para>Special purpose widgets may contain special code for
5459 * rendering to the screen and might appear differently on screen
5460 * and when rendered using gtk_widget_draw().</para></note>
5463 gtk_widget_draw (GtkWidget *widget,
5466 GdkEventExpose *tmp_event;
5468 g_return_if_fail (GTK_IS_WIDGET (widget));
5469 g_return_if_fail (!widget->priv->alloc_needed);
5470 g_return_if_fail (cr != NULL);
5473 /* We have to reset the event here so that draw functions can call
5474 * gtk_widget_draw() on random other widgets and get the desired
5475 * effect: Drawing all contents, not just the current window.
5477 tmp_event = _gtk_cairo_get_event (cr);
5478 gtk_cairo_set_event (cr, NULL);
5480 _gtk_widget_draw_internal (widget, cr, TRUE);
5482 gtk_cairo_set_event (cr, tmp_event);
5487 gtk_widget_real_key_press_event (GtkWidget *widget,
5490 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5494 gtk_widget_real_key_release_event (GtkWidget *widget,
5497 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5501 gtk_widget_real_focus_in_event (GtkWidget *widget,
5502 GdkEventFocus *event)
5504 gtk_widget_queue_shallow_draw (widget);
5510 gtk_widget_real_focus_out_event (GtkWidget *widget,
5511 GdkEventFocus *event)
5513 gtk_widget_queue_shallow_draw (widget);
5518 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5519 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5523 * @widget: a #GtkWidget
5524 * @event: a #GdkEvent
5526 * Rarely-used function. This function is used to emit
5527 * the event signals on a widget (those signals should never
5528 * be emitted without using this function to do so).
5529 * If you want to synthesize an event though, don't use this function;
5530 * instead, use gtk_main_do_event() so the event will behave as if
5531 * it were in the event queue. Don't synthesize expose events; instead,
5532 * use gdk_window_invalidate_rect() to invalidate a region of the
5535 * Return value: return from the event signal emission (%TRUE if
5536 * the event was handled)
5539 gtk_widget_event (GtkWidget *widget,
5542 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5543 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5545 if (event->type == GDK_EXPOSE)
5547 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5548 "the same effect, call gdk_window_invalidate_rect/region(), "
5549 "followed by gdk_window_process_updates().");
5553 return gtk_widget_event_internal (widget, event);
5556 /* Returns TRUE if a translation should be done */
5558 gtk_widget_get_translation_to_window (GtkWidget *widget,
5563 GdkWindow *w, *widget_window;
5565 if (!gtk_widget_get_has_window (widget))
5567 *x = -widget->priv->allocation.x;
5568 *y = -widget->priv->allocation.y;
5576 widget_window = gtk_widget_get_window (widget);
5578 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5581 gdk_window_get_position (w, &wx, &wy);
5598 * gtk_cairo_transform_to_window:
5599 * @cr: the cairo context to transform
5600 * @widget: the widget the context is currently centered for
5601 * @window: the window to transform the context to
5603 * Transforms the given cairo context @cr that from @widget-relative
5604 * coordinates to @window-relative coordinates.
5605 * If the @widget's window is not an ancestor of @window, no
5606 * modification will be applied.
5608 * This is the inverse to the transformation GTK applies when
5609 * preparing an expose event to be emitted with the #GtkWidget::draw
5610 * signal. It is intended to help porting multiwindow widgets from
5611 * GTK+ 2 to the rendering architecture of GTK+ 3.
5614 gtk_cairo_transform_to_window (cairo_t *cr,
5620 g_return_if_fail (cr != NULL);
5621 g_return_if_fail (GTK_IS_WIDGET (widget));
5622 g_return_if_fail (GDK_IS_WINDOW (window));
5624 if (gtk_widget_get_translation_to_window (widget, window, &x, &y))
5625 cairo_translate (cr, x, y);
5629 * gtk_widget_send_expose:
5630 * @widget: a #GtkWidget
5631 * @event: a expose #GdkEvent
5633 * Very rarely-used function. This function is used to emit
5634 * an expose event on a widget. This function is not normally used
5635 * directly. The only time it is used is when propagating an expose
5636 * event to a child %NO_WINDOW widget, and that is normally done
5637 * using gtk_container_propagate_draw().
5639 * If you want to force an area of a window to be redrawn,
5640 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5641 * To cause the redraw to be done immediately, follow that call
5642 * with a call to gdk_window_process_updates().
5644 * Return value: return from the event signal emission (%TRUE if
5645 * the event was handled)
5648 gtk_widget_send_expose (GtkWidget *widget,
5651 gboolean result = FALSE;
5655 GtkStyleContext *context;
5657 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5658 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5659 g_return_val_if_fail (event != NULL, TRUE);
5660 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5662 cr = gdk_cairo_create (event->expose.window);
5663 gtk_cairo_set_event (cr, &event->expose);
5665 gdk_cairo_region (cr, event->expose.region);
5668 do_clip = gtk_widget_get_translation_to_window (widget,
5669 event->expose.window,
5671 cairo_translate (cr, -x, -y);
5673 _gtk_widget_draw_internal (widget, cr, do_clip);
5675 /* unset here, so if someone keeps a reference to cr we
5676 * don't leak the window. */
5677 gtk_cairo_set_event (cr, NULL);
5680 context = gtk_widget_get_style_context (widget);
5681 _gtk_style_context_coalesce_animation_areas (context);
5687 event_window_is_still_viewable (GdkEvent *event)
5689 /* Check that we think the event's window is viewable before
5690 * delivering the event, to prevent suprises. We do this here
5691 * at the last moment, since the event may have been queued
5692 * up behind other events, held over a recursive main loop, etc.
5694 switch (event->type)
5697 case GDK_MOTION_NOTIFY:
5698 case GDK_BUTTON_PRESS:
5699 case GDK_2BUTTON_PRESS:
5700 case GDK_3BUTTON_PRESS:
5702 case GDK_ENTER_NOTIFY:
5703 case GDK_PROXIMITY_IN:
5705 return event->any.window && gdk_window_is_viewable (event->any.window);
5708 /* The following events are the second half of paired events;
5709 * we always deliver them to deal with widgets that clean up
5710 * on the second half.
5712 case GDK_BUTTON_RELEASE:
5713 case GDK_KEY_RELEASE:
5714 case GDK_LEAVE_NOTIFY:
5715 case GDK_PROXIMITY_OUT:
5719 /* Remaining events would make sense on an not-viewable window,
5720 * or don't have an associated window.
5727 gtk_widget_event_internal (GtkWidget *widget,
5730 gboolean return_val = FALSE;
5732 /* We check only once for is-still-visible; if someone
5733 * hides the window in on of the signals on the widget,
5734 * they are responsible for returning TRUE to terminate
5737 if (!event_window_is_still_viewable (event))
5740 g_object_ref (widget);
5742 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5743 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5748 switch (event->type)
5753 case GDK_BUTTON_PRESS:
5754 case GDK_2BUTTON_PRESS:
5755 case GDK_3BUTTON_PRESS:
5756 signal_num = BUTTON_PRESS_EVENT;
5759 signal_num = SCROLL_EVENT;
5761 case GDK_BUTTON_RELEASE:
5762 signal_num = BUTTON_RELEASE_EVENT;
5764 case GDK_MOTION_NOTIFY:
5765 signal_num = MOTION_NOTIFY_EVENT;
5768 signal_num = DELETE_EVENT;
5771 signal_num = DESTROY_EVENT;
5772 _gtk_tooltip_hide (widget);
5775 signal_num = KEY_PRESS_EVENT;
5777 case GDK_KEY_RELEASE:
5778 signal_num = KEY_RELEASE_EVENT;
5780 case GDK_ENTER_NOTIFY:
5781 signal_num = ENTER_NOTIFY_EVENT;
5783 case GDK_LEAVE_NOTIFY:
5784 signal_num = LEAVE_NOTIFY_EVENT;
5786 case GDK_FOCUS_CHANGE:
5787 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
5788 if (event->focus_change.in)
5789 _gtk_tooltip_focus_in (widget);
5791 _gtk_tooltip_focus_out (widget);
5794 signal_num = CONFIGURE_EVENT;
5797 signal_num = MAP_EVENT;
5800 signal_num = UNMAP_EVENT;
5802 case GDK_WINDOW_STATE:
5803 signal_num = WINDOW_STATE_EVENT;
5805 case GDK_PROPERTY_NOTIFY:
5806 signal_num = PROPERTY_NOTIFY_EVENT;
5808 case GDK_SELECTION_CLEAR:
5809 signal_num = SELECTION_CLEAR_EVENT;
5811 case GDK_SELECTION_REQUEST:
5812 signal_num = SELECTION_REQUEST_EVENT;
5814 case GDK_SELECTION_NOTIFY:
5815 signal_num = SELECTION_NOTIFY_EVENT;
5817 case GDK_PROXIMITY_IN:
5818 signal_num = PROXIMITY_IN_EVENT;
5820 case GDK_PROXIMITY_OUT:
5821 signal_num = PROXIMITY_OUT_EVENT;
5823 case GDK_CLIENT_EVENT:
5824 signal_num = CLIENT_EVENT;
5827 signal_num = EXPOSE_EVENT;
5829 case GDK_VISIBILITY_NOTIFY:
5830 signal_num = VISIBILITY_NOTIFY_EVENT;
5832 case GDK_GRAB_BROKEN:
5833 signal_num = GRAB_BROKEN_EVENT;
5836 signal_num = DAMAGE_EVENT;
5839 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
5843 if (signal_num != -1)
5844 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
5846 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
5847 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
5851 g_object_unref (widget);
5857 * gtk_widget_activate:
5858 * @widget: a #GtkWidget that's activatable
5860 * For widgets that can be "activated" (buttons, menu items, etc.)
5861 * this function activates them. Activation is what happens when you
5862 * press Enter on a widget during key navigation. If @widget isn't
5863 * activatable, the function returns %FALSE.
5865 * Return value: %TRUE if the widget was activatable
5868 gtk_widget_activate (GtkWidget *widget)
5870 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5872 if (WIDGET_CLASS (widget)->activate_signal)
5874 /* FIXME: we should eventually check the signals signature here */
5875 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5884 gtk_widget_reparent_subwindows (GtkWidget *widget,
5885 GdkWindow *new_window)
5887 GtkWidgetPrivate *priv = widget->priv;
5889 if (!gtk_widget_get_has_window (widget))
5891 GList *children = gdk_window_get_children (priv->window);
5894 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5896 GdkWindow *window = tmp_list->data;
5899 gdk_window_get_user_data (window, &child);
5900 while (child && child != widget)
5901 child = ((GtkWidget*) child)->priv->parent;
5904 gdk_window_reparent (window, new_window, 0, 0);
5907 g_list_free (children);
5912 GList *tmp_list, *children;
5914 parent = gdk_window_get_parent (priv->window);
5917 gdk_window_reparent (priv->window, new_window, 0, 0);
5920 children = gdk_window_get_children (parent);
5922 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5924 GdkWindow *window = tmp_list->data;
5927 gdk_window_get_user_data (window, &child);
5929 if (child == widget)
5930 gdk_window_reparent (window, new_window, 0, 0);
5933 g_list_free (children);
5939 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5940 gpointer client_data)
5942 GtkWidgetPrivate *priv = widget->priv;
5944 g_assert (client_data != NULL);
5946 if (!gtk_widget_get_has_window (widget))
5949 g_object_unref (priv->window);
5950 priv->window = (GdkWindow*) client_data;
5952 g_object_ref (priv->window);
5954 if (GTK_IS_CONTAINER (widget))
5955 gtk_container_forall (GTK_CONTAINER (widget),
5956 gtk_widget_reparent_fixup_child,
5962 * gtk_widget_reparent:
5963 * @widget: a #GtkWidget
5964 * @new_parent: a #GtkContainer to move the widget into
5966 * Moves a widget from one #GtkContainer to another, handling reference
5967 * count issues to avoid destroying the widget.
5970 gtk_widget_reparent (GtkWidget *widget,
5971 GtkWidget *new_parent)
5973 GtkWidgetPrivate *priv;
5975 g_return_if_fail (GTK_IS_WIDGET (widget));
5976 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
5977 priv = widget->priv;
5978 g_return_if_fail (priv->parent != NULL);
5980 if (priv->parent != new_parent)
5982 /* First try to see if we can get away without unrealizing
5983 * the widget as we reparent it. if so we set a flag so
5984 * that gtk_widget_unparent doesn't unrealize widget
5986 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
5987 priv->in_reparent = TRUE;
5989 g_object_ref (widget);
5990 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
5991 gtk_container_add (GTK_CONTAINER (new_parent), widget);
5992 g_object_unref (widget);
5994 if (priv->in_reparent)
5996 priv->in_reparent = FALSE;
5998 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
5999 gtk_widget_reparent_fixup_child (widget,
6000 gtk_widget_get_parent_window (widget));
6003 g_object_notify (G_OBJECT (widget), "parent");
6008 * gtk_widget_intersect:
6009 * @widget: a #GtkWidget
6010 * @area: a rectangle
6011 * @intersection: rectangle to store intersection of @widget and @area
6013 * Computes the intersection of a @widget's area and @area, storing
6014 * the intersection in @intersection, and returns %TRUE if there was
6015 * an intersection. @intersection may be %NULL if you're only
6016 * interested in whether there was an intersection.
6018 * Return value: %TRUE if there was an intersection
6021 gtk_widget_intersect (GtkWidget *widget,
6022 const GdkRectangle *area,
6023 GdkRectangle *intersection)
6025 GtkWidgetPrivate *priv;
6030 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6031 g_return_val_if_fail (area != NULL, FALSE);
6033 priv = widget->priv;
6036 dest = intersection;
6040 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6042 if (return_val && intersection && gtk_widget_get_has_window (widget))
6044 intersection->x -= priv->allocation.x;
6045 intersection->y -= priv->allocation.y;
6052 * gtk_widget_region_intersect:
6053 * @widget: a #GtkWidget
6054 * @region: a #cairo_region_t, in the same coordinate system as
6055 * @widget->allocation. That is, relative to @widget->window
6056 * for %NO_WINDOW widgets; relative to the parent window
6057 * of @widget->window for widgets with their own window.
6058 * @returns: A newly allocated region holding the intersection of @widget
6059 * and @region. The coordinates of the return value are
6060 * relative to @widget->window for %NO_WINDOW widgets, and
6061 * relative to the parent window of @widget->window for
6062 * widgets with their own window.
6064 * Computes the intersection of a @widget's area and @region, returning
6065 * the intersection. The result may be empty, use cairo_region_is_empty() to
6069 gtk_widget_region_intersect (GtkWidget *widget,
6070 const cairo_region_t *region)
6073 cairo_region_t *dest;
6075 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6076 g_return_val_if_fail (region != NULL, NULL);
6078 gtk_widget_get_allocation (widget, &rect);
6080 dest = cairo_region_create_rectangle (&rect);
6082 cairo_region_intersect (dest, region);
6088 * _gtk_widget_grab_notify:
6089 * @widget: a #GtkWidget
6090 * @was_grabbed: whether a grab is now in effect
6092 * Emits the #GtkWidget::grab-notify signal on @widget.
6097 _gtk_widget_grab_notify (GtkWidget *widget,
6098 gboolean was_grabbed)
6100 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6104 * gtk_widget_grab_focus:
6105 * @widget: a #GtkWidget
6107 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6108 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6109 * something like #GtkFrame won't work.
6111 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6112 * gtk_widget_set_can_focus() to modify that flag.
6114 * The widget also needs to be realized and mapped. This is indicated by the
6115 * related signals. Grabbing the focus immediately after creating the widget
6116 * will likely fail and cause critical warnings.
6119 gtk_widget_grab_focus (GtkWidget *widget)
6121 g_return_if_fail (GTK_IS_WIDGET (widget));
6123 if (!gtk_widget_is_sensitive (widget))
6126 g_object_ref (widget);
6127 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6128 g_object_notify (G_OBJECT (widget), "has-focus");
6129 g_object_unref (widget);
6133 reset_focus_recurse (GtkWidget *widget,
6136 if (GTK_IS_CONTAINER (widget))
6138 GtkContainer *container;
6140 container = GTK_CONTAINER (widget);
6141 gtk_container_set_focus_child (container, NULL);
6143 gtk_container_foreach (container,
6144 reset_focus_recurse,
6150 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6152 if (gtk_widget_get_can_focus (focus_widget))
6154 GtkWidget *toplevel;
6157 /* clear the current focus setting, break if the current widget
6158 * is the focus widget's parent, since containers above that will
6159 * be set by the next loop.
6161 toplevel = gtk_widget_get_toplevel (focus_widget);
6162 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6164 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6166 if (widget == focus_widget)
6168 /* We call _gtk_window_internal_set_focus() here so that the
6169 * toplevel window can request the focus if necessary.
6170 * This is needed when the toplevel is a GtkPlug
6172 if (!gtk_widget_has_focus (widget))
6173 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6180 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
6182 widget = widget->priv->parent;
6183 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6187 else if (toplevel != focus_widget)
6189 /* gtk_widget_grab_focus() operates on a tree without window...
6190 * actually, this is very questionable behaviour.
6193 gtk_container_foreach (GTK_CONTAINER (toplevel),
6194 reset_focus_recurse,
6198 /* now propagate the new focus up the widget tree and finally
6199 * set it on the window
6201 widget = focus_widget;
6202 while (widget->priv->parent)
6204 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6205 widget = widget->priv->parent;
6207 if (GTK_IS_WINDOW (widget))
6208 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6213 gtk_widget_real_query_tooltip (GtkWidget *widget,
6216 gboolean keyboard_tip,
6217 GtkTooltip *tooltip)
6219 gchar *tooltip_markup;
6220 gboolean has_tooltip;
6222 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6223 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6225 if (has_tooltip && tooltip_markup)
6227 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6235 gtk_widget_real_style_updated (GtkWidget *widget)
6237 GtkStyleContext *context;
6239 context = g_object_get_qdata (G_OBJECT (widget),
6240 quark_style_context);
6242 gtk_style_context_invalidate (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_set_parent:
7232 * @widget: a #GtkWidget
7233 * @parent: parent container
7235 * This function is useful only when implementing subclasses of
7237 * Sets the container as the parent of @widget, and takes care of
7238 * some details such as updating the state and style of the child
7239 * to reflect its new location. The opposite function is
7240 * gtk_widget_unparent().
7243 gtk_widget_set_parent (GtkWidget *widget,
7246 GtkWidgetPrivate *priv;
7248 GtkStyleContext *context;
7250 g_return_if_fail (GTK_IS_WIDGET (widget));
7251 g_return_if_fail (GTK_IS_WIDGET (parent));
7252 g_return_if_fail (widget != parent);
7254 priv = widget->priv;
7256 if (priv->parent != NULL)
7258 g_warning ("Can't set a parent on widget which has a parent\n");
7261 if (gtk_widget_is_toplevel (widget))
7263 g_warning ("Can't set a parent on a toplevel widget\n");
7267 /* keep this function in sync with gtk_menu_attach_to_widget()
7270 g_object_ref_sink (widget);
7271 priv->parent = parent;
7273 if (gtk_widget_get_state (parent) != GTK_STATE_NORMAL)
7274 data.state = gtk_widget_get_state (parent);
7276 data.state = gtk_widget_get_state (widget);
7277 data.state_restoration = FALSE;
7278 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
7279 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7281 gtk_widget_propagate_state (widget, &data);
7283 gtk_widget_reset_rc_styles (widget);
7285 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7286 if (priv->parent->priv->anchored)
7287 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7288 g_object_notify (G_OBJECT (widget), "parent");
7290 /* Enforce realized/mapped invariants
7292 if (gtk_widget_get_realized (priv->parent))
7293 gtk_widget_realize (widget);
7295 if (gtk_widget_get_visible (priv->parent) &&
7296 gtk_widget_get_visible (widget))
7298 if (gtk_widget_get_child_visible (widget) &&
7299 gtk_widget_get_mapped (priv->parent))
7300 gtk_widget_map (widget);
7302 gtk_widget_queue_resize (widget);
7305 /* child may cause parent's expand to change, if the child is
7306 * expanded. If child is not expanded, then it can't modify the
7307 * parent's expand. If the child becomes expanded later then it will
7308 * queue compute_expand then. This optimization plus defaulting
7309 * newly-constructed widgets to need_compute_expand=FALSE should
7310 * mean that initially building a widget tree doesn't have to keep
7311 * walking up setting need_compute_expand on parents over and over.
7313 * We can't change a parent to need to expand unless we're visible.
7315 if (gtk_widget_get_visible (widget) &&
7316 (priv->need_compute_expand ||
7317 priv->computed_hexpand ||
7318 priv->computed_vexpand))
7320 gtk_widget_queue_compute_expand (parent);
7323 context = g_object_get_qdata (G_OBJECT (widget),
7324 quark_style_context);
7327 GtkWidgetPath *path;
7329 path = gtk_widget_get_path (widget);
7330 gtk_style_context_set_path (context, path);
7331 gtk_widget_path_free (path);
7333 gtk_style_context_set_screen (context,
7334 gtk_widget_get_screen (widget));
7339 * gtk_widget_get_parent:
7340 * @widget: a #GtkWidget
7342 * Returns the parent container of @widget.
7344 * Return value: (transfer none): the parent container of @widget, or %NULL
7347 gtk_widget_get_parent (GtkWidget *widget)
7349 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7351 return widget->priv->parent;
7354 /*****************************************
7356 * see docs/styles.txt
7357 *****************************************/
7360 * gtk_widget_style_attach:
7361 * @widget: a #GtkWidget
7363 * This function attaches the widget's #GtkStyle to the widget's
7364 * #GdkWindow. It is a replacement for
7367 * widget->style = gtk_style_attach (widget->style, widget->window);
7370 * and should only ever be called in a derived widget's "realize"
7371 * implementation which does not chain up to its parent class'
7372 * "realize" implementation, because one of the parent classes
7373 * (finally #GtkWidget) would attach the style itself.
7378 gtk_widget_style_attach (GtkWidget *widget)
7380 GtkWidgetPrivate *priv;
7382 g_return_if_fail (GTK_IS_WIDGET (widget));
7383 g_return_if_fail (gtk_widget_get_realized (widget));
7385 priv = widget->priv;
7387 priv->style = gtk_style_attach (priv->style, priv->window);
7391 * gtk_widget_has_rc_style:
7392 * @widget: a #GtkWidget
7394 * Determines if the widget style has been looked up through the rc mechanism.
7396 * Returns: %TRUE if the widget has been looked up through the rc
7397 * mechanism, %FALSE otherwise.
7402 gtk_widget_has_rc_style (GtkWidget *widget)
7404 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7406 return widget->priv->rc_style;
7410 * gtk_widget_set_style:
7411 * @widget: a #GtkWidget
7412 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
7413 * gtk_widget_set_style() and go back to the default style
7415 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
7416 * want to use this function; it interacts badly with themes, because
7417 * themes work by replacing the #GtkStyle. Instead, use
7418 * gtk_widget_modify_style().
7421 gtk_widget_set_style (GtkWidget *widget,
7424 g_return_if_fail (GTK_IS_WIDGET (widget));
7428 gboolean initial_emission;
7430 initial_emission = !widget->priv->rc_style && !widget->priv->user_style;
7432 widget->priv->rc_style = FALSE;
7433 widget->priv->user_style = TRUE;
7435 gtk_widget_set_style_internal (widget, style, initial_emission);
7439 if (widget->priv->user_style)
7440 gtk_widget_reset_rc_style (widget);
7445 * gtk_widget_ensure_style:
7446 * @widget: a #GtkWidget
7448 * Ensures that @widget has a style (@widget->style). Not a very useful
7449 * function; most of the time, if you want the style, the widget is
7450 * realized, and realized widgets are guaranteed to have a style
7454 gtk_widget_ensure_style (GtkWidget *widget)
7456 g_return_if_fail (GTK_IS_WIDGET (widget));
7458 if (!widget->priv->style ||
7459 !gtk_style_has_context (widget->priv->style))
7463 style = g_object_new (GTK_TYPE_STYLE,
7464 "context", gtk_widget_get_style_context (widget),
7467 gtk_widget_set_style_internal (widget, style, TRUE);
7468 g_object_unref (style);
7472 if (!widget->priv->rc_style && !widget->priv->user_style)
7473 gtk_widget_reset_rc_style (widget);
7477 /* Look up the RC style for this widget, unsetting any user style that
7478 * may be in effect currently
7481 gtk_widget_reset_rc_style (GtkWidget *widget)
7483 GtkWidgetPrivate *priv = widget->priv;
7484 GtkStyle *new_style = NULL;
7485 gboolean initial_emission;
7487 initial_emission = !priv->rc_style && !priv->user_style;
7489 priv->user_style = FALSE;
7490 priv->rc_style = TRUE;
7492 if (gtk_widget_has_screen (widget))
7493 new_style = gtk_rc_get_style (widget);
7495 new_style = gtk_widget_get_default_style ();
7497 if (initial_emission || new_style != priv->style)
7498 gtk_widget_set_style_internal (widget, new_style, initial_emission);
7502 * gtk_widget_get_style:
7503 * @widget: a #GtkWidget
7505 * Simply an accessor function that returns @widget->style.
7507 * Return value: (transfer none): the widget's #GtkStyle
7510 gtk_widget_get_style (GtkWidget *widget)
7512 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7514 return widget->priv->style;
7518 * gtk_widget_modify_style:
7519 * @widget: a #GtkWidget
7520 * @style: the #GtkRcStyle holding the style modifications
7522 * Modifies style values on the widget. Modifications made using this
7523 * technique take precedence over style values set via an RC file,
7524 * however, they will be overriden if a style is explicitely set on
7525 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
7526 * is designed so each field can either be set or unset, so it is
7527 * possible, using this function, to modify some style values and
7528 * leave the others unchanged.
7530 * Note that modifications made with this function are not cumulative
7531 * with previous calls to gtk_widget_modify_style() or with such
7532 * functions as gtk_widget_modify_fg(). If you wish to retain
7533 * previous values, you must first call gtk_widget_get_modifier_style(),
7534 * make your modifications to the returned style, then call
7535 * gtk_widget_modify_style() with that style. On the other hand,
7536 * if you first call gtk_widget_modify_style(), subsequent calls
7537 * to such functions gtk_widget_modify_fg() will have a cumulative
7538 * effect with the initial modifications.
7541 gtk_widget_modify_style (GtkWidget *widget,
7544 g_return_if_fail (GTK_IS_WIDGET (widget));
7545 g_return_if_fail (GTK_IS_RC_STYLE (style));
7547 g_object_set_qdata_full (G_OBJECT (widget),
7549 gtk_rc_style_copy (style),
7550 (GDestroyNotify) g_object_unref);
7552 /* note that "style" may be invalid here if it was the old
7553 * modifier style and the only reference was our own.
7556 if (widget->priv->rc_style)
7557 gtk_widget_reset_rc_style (widget);
7561 * gtk_widget_get_modifier_style:
7562 * @widget: a #GtkWidget
7564 * Returns the current modifier style for the widget. (As set by
7565 * gtk_widget_modify_style().) If no style has previously set, a new
7566 * #GtkRcStyle will be created with all values unset, and set as the
7567 * modifier style for the widget. If you make changes to this rc
7568 * style, you must call gtk_widget_modify_style(), passing in the
7569 * returned rc style, to make sure that your changes take effect.
7571 * Caution: passing the style back to gtk_widget_modify_style() will
7572 * normally end up destroying it, because gtk_widget_modify_style() copies
7573 * the passed-in style and sets the copy as the new modifier style,
7574 * thus dropping any reference to the old modifier style. Add a reference
7575 * to the modifier style if you want to keep it alive.
7577 * Return value: (transfer none): the modifier style for the widget. This rc style is
7578 * owned by the widget. If you want to keep a pointer to value this
7579 * around, you must add a refcount using g_object_ref().
7582 gtk_widget_get_modifier_style (GtkWidget *widget)
7584 GtkRcStyle *rc_style;
7586 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7588 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7592 rc_style = gtk_rc_style_new ();
7593 g_object_set_qdata_full (G_OBJECT (widget),
7596 (GDestroyNotify) g_object_unref);
7603 gtk_widget_modify_color_component (GtkWidget *widget,
7604 GtkRcFlags component,
7606 const GdkColor *color)
7608 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7615 rc_style->fg[state] = *color;
7618 rc_style->bg[state] = *color;
7621 rc_style->text[state] = *color;
7624 rc_style->base[state] = *color;
7627 g_assert_not_reached();
7630 rc_style->color_flags[state] |= component;
7633 rc_style->color_flags[state] &= ~component;
7635 gtk_widget_modify_style (widget, rc_style);
7639 * gtk_widget_modify_symbolic_color:
7640 * @widget: a #GtkWidget
7641 * @name: the name of the symbolic color to modify
7642 * @color: (allow-none): the color to assign (does not need to be allocated),
7643 * or %NULL to undo the effect of previous calls to
7644 * of gtk_widget_modify_symbolic_color().
7646 * Sets a symbolic color for a widget.
7647 * All other style values are left untouched. See also
7648 * gtk_widget_modify_style().
7653 gtk_widget_modify_symbolic_color (GtkWidget *widget,
7655 const GdkColor *color)
7657 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7659 _gtk_rc_style_set_symbolic_color (rc_style, name, color);
7661 gtk_widget_modify_style (widget, rc_style);
7665 * gtk_widget_modify_fg:
7666 * @widget: a #GtkWidget
7667 * @state: the state for which to set the foreground color
7668 * @color: (allow-none): the color to assign (does not need to be allocated),
7669 * or %NULL to undo the effect of previous calls to
7670 * of gtk_widget_modify_fg().
7672 * Sets the foreground color for a widget in a particular state.
7673 * All other style values are left untouched. See also
7674 * gtk_widget_modify_style().
7677 gtk_widget_modify_fg (GtkWidget *widget,
7679 const GdkColor *color)
7681 g_return_if_fail (GTK_IS_WIDGET (widget));
7682 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7684 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
7688 * gtk_widget_modify_bg:
7689 * @widget: a #GtkWidget
7690 * @state: the state for which to set the background color
7691 * @color: (allow-none): the color to assign (does not need to be allocated),
7692 * or %NULL to undo the effect of previous calls to
7693 * of gtk_widget_modify_bg().
7695 * Sets the background color for a widget in a particular state.
7696 * All other style values are left untouched. See also
7697 * gtk_widget_modify_style().
7699 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7700 * draw on their parent container's window and thus may not draw any
7701 * background themselves. This is the case for e.g. #GtkLabel. To modify
7702 * the background of such widgets, you have to set the background color
7703 * on their parent; if you want to set the background of a rectangular
7704 * area around a label, try placing the label in a #GtkEventBox widget
7705 * and setting the background color on that.
7708 gtk_widget_modify_bg (GtkWidget *widget,
7710 const GdkColor *color)
7712 g_return_if_fail (GTK_IS_WIDGET (widget));
7713 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7715 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
7719 * gtk_widget_modify_text:
7720 * @widget: a #GtkWidget
7721 * @state: the state for which to set the text color
7722 * @color: (allow-none): the color to assign (does not need to be allocated),
7723 * or %NULL to undo the effect of previous calls to
7724 * of gtk_widget_modify_text().
7726 * Sets the text color for a widget in a particular state. All other
7727 * style values are left untouched. The text color is the foreground
7728 * color used along with the base color (see gtk_widget_modify_base())
7729 * for widgets such as #GtkEntry and #GtkTextView. See also
7730 * gtk_widget_modify_style().
7733 gtk_widget_modify_text (GtkWidget *widget,
7735 const GdkColor *color)
7737 g_return_if_fail (GTK_IS_WIDGET (widget));
7738 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7740 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
7744 * gtk_widget_modify_base:
7745 * @widget: a #GtkWidget
7746 * @state: the state for which to set the base color
7747 * @color: (allow-none): the color to assign (does not need to be allocated),
7748 * or %NULL to undo the effect of previous calls to
7749 * of gtk_widget_modify_base().
7751 * Sets the base color for a widget in a particular state.
7752 * All other style values are left untouched. The base color
7753 * is the background color used along with the text color
7754 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
7755 * and #GtkTextView. See also gtk_widget_modify_style().
7757 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7758 * draw on their parent container's window and thus may not draw any
7759 * background themselves. This is the case for e.g. #GtkLabel. To modify
7760 * the background of such widgets, you have to set the base color on their
7761 * parent; if you want to set the background of a rectangular area around
7762 * a label, try placing the label in a #GtkEventBox widget and setting
7763 * the base color on that.
7766 gtk_widget_modify_base (GtkWidget *widget,
7768 const GdkColor *color)
7770 g_return_if_fail (GTK_IS_WIDGET (widget));
7771 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7773 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
7777 modify_color_property (GtkWidget *widget,
7778 GtkRcStyle *rc_style,
7780 const GdkColor *color)
7782 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
7783 GQuark property_name = g_quark_from_string (name);
7787 GtkRcProperty rc_property = {0};
7790 rc_property.type_name = type_name;
7791 rc_property.property_name = property_name;
7792 rc_property.origin = NULL;
7794 color_name = gdk_color_to_string (color);
7795 g_value_init (&rc_property.value, G_TYPE_STRING);
7796 g_value_take_string (&rc_property.value, color_name);
7798 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
7800 g_value_unset (&rc_property.value);
7803 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
7807 * gtk_widget_modify_cursor:
7808 * @widget: a #GtkWidget
7809 * @primary: the color to use for primary cursor (does not need to be
7810 * allocated), or %NULL to undo the effect of previous calls to
7811 * of gtk_widget_modify_cursor().
7812 * @secondary: the color to use for secondary cursor (does not need to be
7813 * allocated), or %NULL to undo the effect of previous calls to
7814 * of gtk_widget_modify_cursor().
7816 * Sets the cursor color to use in a widget, overriding the
7817 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
7818 * style properties. All other style values are left untouched.
7819 * See also gtk_widget_modify_style().
7824 gtk_widget_modify_cursor (GtkWidget *widget,
7825 const GdkColor *primary,
7826 const GdkColor *secondary)
7828 GtkRcStyle *rc_style;
7830 g_return_if_fail (GTK_IS_WIDGET (widget));
7832 rc_style = gtk_widget_get_modifier_style (widget);
7834 modify_color_property (widget, rc_style, "cursor-color", primary);
7835 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
7837 gtk_widget_modify_style (widget, rc_style);
7841 * gtk_widget_modify_font:
7842 * @widget: a #GtkWidget
7843 * @font_desc: (allow-none): the font description to use, or %NULL to undo
7844 * the effect of previous calls to gtk_widget_modify_font().
7846 * Sets the font to use for a widget. All other style values are left
7847 * untouched. See also gtk_widget_modify_style().
7850 gtk_widget_modify_font (GtkWidget *widget,
7851 PangoFontDescription *font_desc)
7853 GtkRcStyle *rc_style;
7855 g_return_if_fail (GTK_IS_WIDGET (widget));
7857 rc_style = gtk_widget_get_modifier_style (widget);
7859 if (rc_style->font_desc)
7860 pango_font_description_free (rc_style->font_desc);
7863 rc_style->font_desc = pango_font_description_copy (font_desc);
7865 rc_style->font_desc = NULL;
7867 gtk_widget_modify_style (widget, rc_style);
7871 gtk_widget_real_direction_changed (GtkWidget *widget,
7872 GtkTextDirection previous_direction)
7874 gtk_widget_queue_resize (widget);
7878 gtk_widget_real_style_set (GtkWidget *widget,
7879 GtkStyle *previous_style)
7881 GtkWidgetPrivate *priv = widget->priv;
7883 if (gtk_widget_get_realized (widget) &&
7884 gtk_widget_get_has_window (widget))
7885 gtk_style_set_background (priv->style, priv->window, priv->state);
7889 gtk_widget_set_style_internal (GtkWidget *widget,
7891 gboolean initial_emission)
7893 GtkWidgetPrivate *priv = widget->priv;
7895 g_object_ref (widget);
7896 g_object_freeze_notify (G_OBJECT (widget));
7898 if (priv->style != style)
7900 GtkStyle *previous_style;
7902 if (gtk_widget_get_realized (widget))
7904 gtk_widget_reset_shapes (widget);
7905 gtk_style_detach (priv->style);
7908 previous_style = priv->style;
7909 priv->style = style;
7910 g_object_ref (priv->style);
7912 if (gtk_widget_get_realized (widget))
7913 priv->style = gtk_style_attach (priv->style, priv->window);
7915 gtk_widget_update_pango_context (widget);
7916 g_signal_emit (widget,
7917 widget_signals[STYLE_SET],
7919 initial_emission ? NULL : previous_style);
7920 g_object_unref (previous_style);
7922 if (priv->anchored && !initial_emission)
7923 gtk_widget_queue_resize (widget);
7925 else if (initial_emission)
7927 gtk_widget_update_pango_context (widget);
7928 g_signal_emit (widget,
7929 widget_signals[STYLE_SET],
7933 g_object_notify (G_OBJECT (widget), "style");
7934 g_object_thaw_notify (G_OBJECT (widget));
7935 g_object_unref (widget);
7939 GtkWidget *previous_toplevel;
7940 GdkScreen *previous_screen;
7941 GdkScreen *new_screen;
7942 } HierarchyChangedInfo;
7945 do_screen_change (GtkWidget *widget,
7946 GdkScreen *old_screen,
7947 GdkScreen *new_screen)
7949 if (old_screen != new_screen)
7951 GtkStyleContext *context;
7955 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7957 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
7960 _gtk_tooltip_hide (widget);
7962 context = gtk_widget_get_style_context (widget);
7963 gtk_style_context_set_screen (context, new_screen);
7965 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
7970 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
7971 gpointer client_data)
7973 GtkWidgetPrivate *priv = widget->priv;
7974 HierarchyChangedInfo *info = client_data;
7975 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
7976 (priv->parent && priv->parent->priv->anchored);
7978 if (priv->anchored != new_anchored)
7980 g_object_ref (widget);
7982 priv->anchored = new_anchored;
7984 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
7985 do_screen_change (widget, info->previous_screen, info->new_screen);
7987 if (GTK_IS_CONTAINER (widget))
7988 gtk_container_forall (GTK_CONTAINER (widget),
7989 gtk_widget_propagate_hierarchy_changed_recurse,
7992 g_object_unref (widget);
7997 * _gtk_widget_propagate_hierarchy_changed:
7998 * @widget: a #GtkWidget
7999 * @previous_toplevel: Previous toplevel
8001 * Propagates changes in the anchored state to a widget and all
8002 * children, unsetting or setting the %ANCHORED flag, and
8003 * emitting #GtkWidget::hierarchy-changed.
8006 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8007 GtkWidget *previous_toplevel)
8009 GtkWidgetPrivate *priv = widget->priv;
8010 HierarchyChangedInfo info;
8012 info.previous_toplevel = previous_toplevel;
8013 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8015 if (gtk_widget_is_toplevel (widget) ||
8016 (priv->parent && priv->parent->priv->anchored))
8017 info.new_screen = gtk_widget_get_screen (widget);
8019 info.new_screen = NULL;
8021 if (info.previous_screen)
8022 g_object_ref (info.previous_screen);
8023 if (previous_toplevel)
8024 g_object_ref (previous_toplevel);
8026 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8028 if (previous_toplevel)
8029 g_object_unref (previous_toplevel);
8030 if (info.previous_screen)
8031 g_object_unref (info.previous_screen);
8035 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8036 gpointer client_data)
8038 HierarchyChangedInfo *info = client_data;
8040 g_object_ref (widget);
8042 do_screen_change (widget, info->previous_screen, info->new_screen);
8044 if (GTK_IS_CONTAINER (widget))
8045 gtk_container_forall (GTK_CONTAINER (widget),
8046 gtk_widget_propagate_screen_changed_recurse,
8049 g_object_unref (widget);
8053 * gtk_widget_is_composited:
8054 * @widget: a #GtkWidget
8056 * Whether @widget can rely on having its alpha channel
8057 * drawn correctly. On X11 this function returns whether a
8058 * compositing manager is running for @widget's screen.
8060 * Please note that the semantics of this call will change
8061 * in the future if used on a widget that has a composited
8062 * window in its hierarchy (as set by gdk_window_set_composited()).
8064 * Return value: %TRUE if the widget can rely on its alpha
8065 * channel being drawn correctly.
8070 gtk_widget_is_composited (GtkWidget *widget)
8074 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8076 screen = gtk_widget_get_screen (widget);
8078 return gdk_screen_is_composited (screen);
8082 propagate_composited_changed (GtkWidget *widget,
8085 if (GTK_IS_CONTAINER (widget))
8087 gtk_container_forall (GTK_CONTAINER (widget),
8088 propagate_composited_changed,
8092 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8096 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8098 propagate_composited_changed (widget, NULL);
8102 * _gtk_widget_propagate_screen_changed:
8103 * @widget: a #GtkWidget
8104 * @previous_screen: Previous screen
8106 * Propagates changes in the screen for a widget to all
8107 * children, emitting #GtkWidget::screen-changed.
8110 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8111 GdkScreen *previous_screen)
8113 HierarchyChangedInfo info;
8115 info.previous_screen = previous_screen;
8116 info.new_screen = gtk_widget_get_screen (widget);
8118 if (previous_screen)
8119 g_object_ref (previous_screen);
8121 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8123 if (previous_screen)
8124 g_object_unref (previous_screen);
8128 reset_style_recurse (GtkWidget *widget, gpointer data)
8130 GtkStyleContext *context;
8133 if (widget->priv->rc_style)
8134 gtk_widget_reset_rc_style (widget);
8137 context = g_object_get_qdata (G_OBJECT (widget),
8138 quark_style_context);
8140 gtk_style_context_invalidate (context);
8142 if (GTK_IS_CONTAINER (widget))
8143 gtk_container_forall (GTK_CONTAINER (widget),
8144 reset_style_recurse,
8149 gtk_widget_reset_style (GtkWidget *widget)
8151 g_return_if_fail (GTK_IS_WIDGET (widget));
8153 reset_style_recurse (widget, NULL);
8157 * gtk_widget_reset_rc_styles:
8158 * @widget: a #GtkWidget.
8160 * Reset the styles of @widget and all descendents, so when
8161 * they are looked up again, they get the correct values
8162 * for the currently loaded RC file settings.
8164 * This function is not useful for applications.
8167 gtk_widget_reset_rc_styles (GtkWidget *widget)
8169 g_return_if_fail (GTK_IS_WIDGET (widget));
8171 reset_style_recurse (widget, NULL);
8175 * gtk_widget_get_default_style:
8177 * Returns the default style used by all widgets initially.
8179 * Returns: (transfer none): the default style. This #GtkStyle object is owned
8180 * by GTK+ and should not be modified or freed.
8183 gtk_widget_get_default_style (void)
8185 if (!gtk_default_style)
8187 gtk_default_style = gtk_style_new ();
8188 g_object_ref (gtk_default_style);
8191 return gtk_default_style;
8194 static PangoContext *
8195 gtk_widget_peek_pango_context (GtkWidget *widget)
8197 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8201 * gtk_widget_get_pango_context:
8202 * @widget: a #GtkWidget
8204 * Gets a #PangoContext with the appropriate font map, font description,
8205 * and base direction for this widget. Unlike the context returned
8206 * by gtk_widget_create_pango_context(), this context is owned by
8207 * the widget (it can be used until the screen for the widget changes
8208 * or the widget is removed from its toplevel), and will be updated to
8209 * match any changes to the widget's attributes.
8211 * If you create and keep a #PangoLayout using this context, you must
8212 * deal with changes to the context by calling pango_layout_context_changed()
8213 * on the layout in response to the #GtkWidget::style-set and
8214 * #GtkWidget::direction-changed signals for the widget.
8216 * Return value: (transfer none): the #PangoContext for the widget.
8219 gtk_widget_get_pango_context (GtkWidget *widget)
8221 PangoContext *context;
8223 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8225 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8228 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8229 g_object_set_qdata_full (G_OBJECT (widget),
8230 quark_pango_context,
8239 update_pango_context (GtkWidget *widget,
8240 PangoContext *context)
8242 GtkWidgetPrivate *priv = widget->priv;
8244 pango_context_set_font_description (context, priv->style->font_desc);
8245 pango_context_set_base_dir (context,
8246 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8247 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8251 gtk_widget_update_pango_context (GtkWidget *widget)
8253 PangoContext *context = gtk_widget_peek_pango_context (widget);
8259 update_pango_context (widget, context);
8261 screen = gtk_widget_get_screen_unchecked (widget);
8264 pango_cairo_context_set_resolution (context,
8265 gdk_screen_get_resolution (screen));
8266 pango_cairo_context_set_font_options (context,
8267 gdk_screen_get_font_options (screen));
8273 * gtk_widget_create_pango_context:
8274 * @widget: a #GtkWidget
8276 * Creates a new #PangoContext with the appropriate font map,
8277 * font description, and base direction for drawing text for
8278 * this widget. See also gtk_widget_get_pango_context().
8280 * Return value: (transfer full): the new #PangoContext
8283 gtk_widget_create_pango_context (GtkWidget *widget)
8286 PangoContext *context;
8288 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8290 screen = gtk_widget_get_screen_unchecked (widget);
8293 GTK_NOTE (MULTIHEAD,
8294 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8296 screen = gdk_screen_get_default ();
8299 context = gdk_pango_context_get_for_screen (screen);
8301 update_pango_context (widget, context);
8302 pango_context_set_language (context, gtk_get_default_language ());
8308 * gtk_widget_create_pango_layout:
8309 * @widget: a #GtkWidget
8310 * @text: text to set on the layout (can be %NULL)
8312 * Creates a new #PangoLayout with the appropriate font map,
8313 * font description, and base direction for drawing text for
8316 * If you keep a #PangoLayout created in this way around, in order to
8317 * notify the layout of changes to the base direction or font of this
8318 * widget, you must call pango_layout_context_changed() in response to
8319 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
8322 * Return value: (transfer full): the new #PangoLayout
8325 gtk_widget_create_pango_layout (GtkWidget *widget,
8328 PangoLayout *layout;
8329 PangoContext *context;
8331 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8333 context = gtk_widget_get_pango_context (widget);
8334 layout = pango_layout_new (context);
8337 pango_layout_set_text (layout, text, -1);
8343 * gtk_widget_render_icon:
8344 * @widget: a #GtkWidget
8345 * @stock_id: a stock ID
8346 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8347 * render at the size of the source and don't scale (if there are
8348 * multiple source sizes, GTK+ picks one of the available sizes).
8349 * @detail: (allow-none): render detail to pass to theme engine
8351 * A convenience function that uses the theme engine and RC file
8352 * settings for @widget to look up @stock_id and render it to
8353 * a pixbuf. @stock_id should be a stock icon ID such as
8354 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8355 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
8356 * identifies the widget or code doing the rendering, so that
8357 * theme engines can special-case rendering for that widget or code.
8359 * The pixels in the returned #GdkPixbuf are shared with the rest of
8360 * the application and should not be modified. The pixbuf should be freed
8361 * after use with g_object_unref().
8363 * Return value: (transfer full): a new pixbuf, or %NULL if the
8364 * stock ID wasn't known
8367 gtk_widget_render_icon (GtkWidget *widget,
8368 const gchar *stock_id,
8370 const gchar *detail)
8372 GtkWidgetPrivate *priv;
8373 GtkIconSet *icon_set;
8376 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8377 g_return_val_if_fail (stock_id != NULL, NULL);
8378 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8380 priv = widget->priv;
8382 gtk_widget_ensure_style (widget);
8384 icon_set = gtk_style_lookup_icon_set (priv->style, stock_id);
8386 if (icon_set == NULL)
8389 retval = gtk_icon_set_render_icon (icon_set,
8391 gtk_widget_get_direction (widget),
8392 gtk_widget_get_state (widget),
8401 * gtk_widget_set_parent_window:
8402 * @widget: a #GtkWidget.
8403 * @parent_window: the new parent window.
8405 * Sets a non default parent window for @widget.
8408 gtk_widget_set_parent_window (GtkWidget *widget,
8409 GdkWindow *parent_window)
8411 GdkWindow *old_parent_window;
8413 g_return_if_fail (GTK_IS_WIDGET (widget));
8415 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8416 quark_parent_window);
8418 if (parent_window != old_parent_window)
8420 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8422 if (old_parent_window)
8423 g_object_unref (old_parent_window);
8425 g_object_ref (parent_window);
8430 * gtk_widget_get_parent_window:
8431 * @widget: a #GtkWidget.
8433 * Gets @widget's parent window.
8435 * Returns: (transfer none): the parent window of @widget.
8438 gtk_widget_get_parent_window (GtkWidget *widget)
8440 GtkWidgetPrivate *priv;
8441 GdkWindow *parent_window;
8443 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8445 priv = widget->priv;
8447 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8449 return (parent_window != NULL) ? parent_window :
8450 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8455 * gtk_widget_set_child_visible:
8456 * @widget: a #GtkWidget
8457 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8459 * Sets whether @widget should be mapped along with its when its parent
8460 * is mapped and @widget has been shown with gtk_widget_show().
8462 * The child visibility can be set for widget before it is added to
8463 * a container with gtk_widget_set_parent(), to avoid mapping
8464 * children unnecessary before immediately unmapping them. However
8465 * it will be reset to its default state of %TRUE when the widget
8466 * is removed from a container.
8468 * Note that changing the child visibility of a widget does not
8469 * queue a resize on the widget. Most of the time, the size of
8470 * a widget is computed from all visible children, whether or
8471 * not they are mapped. If this is not the case, the container
8472 * can queue a resize itself.
8474 * This function is only useful for container implementations and
8475 * never should be called by an application.
8478 gtk_widget_set_child_visible (GtkWidget *widget,
8479 gboolean is_visible)
8481 GtkWidgetPrivate *priv;
8483 g_return_if_fail (GTK_IS_WIDGET (widget));
8484 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8486 priv = widget->priv;
8488 g_object_ref (widget);
8491 priv->child_visible = TRUE;
8494 GtkWidget *toplevel;
8496 priv->child_visible = FALSE;
8498 toplevel = gtk_widget_get_toplevel (widget);
8499 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8500 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8503 if (priv->parent && gtk_widget_get_realized (priv->parent))
8505 if (gtk_widget_get_mapped (priv->parent) &&
8506 priv->child_visible &&
8507 gtk_widget_get_visible (widget))
8508 gtk_widget_map (widget);
8510 gtk_widget_unmap (widget);
8513 g_object_unref (widget);
8517 * gtk_widget_get_child_visible:
8518 * @widget: a #GtkWidget
8520 * Gets the value set with gtk_widget_set_child_visible().
8521 * If you feel a need to use this function, your code probably
8522 * needs reorganization.
8524 * This function is only useful for container implementations and
8525 * never should be called by an application.
8527 * Return value: %TRUE if the widget is mapped with the parent.
8530 gtk_widget_get_child_visible (GtkWidget *widget)
8532 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8534 return widget->priv->child_visible;
8538 gtk_widget_get_screen_unchecked (GtkWidget *widget)
8540 GtkWidget *toplevel;
8542 toplevel = gtk_widget_get_toplevel (widget);
8544 if (gtk_widget_is_toplevel (toplevel))
8546 if (GTK_IS_WINDOW (toplevel))
8547 return gtk_window_get_screen (GTK_WINDOW (toplevel));
8548 else if (GTK_IS_INVISIBLE (toplevel))
8549 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
8556 * gtk_widget_get_screen:
8557 * @widget: a #GtkWidget
8559 * Get the #GdkScreen from the toplevel window associated with
8560 * this widget. This function can only be called after the widget
8561 * has been added to a widget hierarchy with a #GtkWindow
8564 * In general, you should only create screen specific
8565 * resources when a widget has been realized, and you should
8566 * free those resources when the widget is unrealized.
8568 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
8573 gtk_widget_get_screen (GtkWidget *widget)
8577 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8579 screen = gtk_widget_get_screen_unchecked (widget);
8586 g_warning (G_STRLOC ": Can't get associated screen"
8587 " for a widget unless it is inside a toplevel GtkWindow\n"
8588 " widget type is %s associated top level type is %s",
8589 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
8590 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
8592 return gdk_screen_get_default ();
8597 * gtk_widget_has_screen:
8598 * @widget: a #GtkWidget
8600 * Checks whether there is a #GdkScreen is associated with
8601 * this widget. All toplevel widgets have an associated
8602 * screen, and all widgets added into a hierarchy with a toplevel
8603 * window at the top.
8605 * Return value: %TRUE if there is a #GdkScreen associcated
8611 gtk_widget_has_screen (GtkWidget *widget)
8613 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8615 return (gtk_widget_get_screen_unchecked (widget) != NULL);
8619 * gtk_widget_get_display:
8620 * @widget: a #GtkWidget
8622 * Get the #GdkDisplay for the toplevel window associated with
8623 * this widget. This function can only be called after the widget
8624 * has been added to a widget hierarchy with a #GtkWindow at the top.
8626 * In general, you should only create display specific
8627 * resources when a widget has been realized, and you should
8628 * free those resources when the widget is unrealized.
8630 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
8635 gtk_widget_get_display (GtkWidget *widget)
8637 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8639 return gdk_screen_get_display (gtk_widget_get_screen (widget));
8643 * gtk_widget_get_root_window:
8644 * @widget: a #GtkWidget
8646 * Get the root window where this widget is located. This function can
8647 * only be called after the widget has been added to a widget
8648 * hierarchy with #GtkWindow at the top.
8650 * The root window is useful for such purposes as creating a popup
8651 * #GdkWindow associated with the window. In general, you should only
8652 * create display specific resources when a widget has been realized,
8653 * and you should free those resources when the widget is unrealized.
8655 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
8660 gtk_widget_get_root_window (GtkWidget *widget)
8662 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8664 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
8668 * gtk_widget_child_focus:
8669 * @widget: a #GtkWidget
8670 * @direction: direction of focus movement
8672 * This function is used by custom widget implementations; if you're
8673 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
8674 * to a particular widget, and gtk_container_set_focus_chain() to
8675 * change the focus tab order. So you may want to investigate those
8676 * functions instead.
8678 * gtk_widget_child_focus() is called by containers as the user moves
8679 * around the window using keyboard shortcuts. @direction indicates
8680 * what kind of motion is taking place (up, down, left, right, tab
8681 * forward, tab backward). gtk_widget_child_focus() emits the
8682 * #GtkWidget::focus signal; widgets override the default handler
8683 * for this signal in order to implement appropriate focus behavior.
8685 * The default ::focus handler for a widget should return %TRUE if
8686 * moving in @direction left the focus on a focusable location inside
8687 * that widget, and %FALSE if moving in @direction moved the focus
8688 * outside the widget. If returning %TRUE, widgets normally
8689 * call gtk_widget_grab_focus() to place the focus accordingly;
8690 * if returning %FALSE, they don't modify the current focus location.
8692 * Return value: %TRUE if focus ended up inside @widget
8695 gtk_widget_child_focus (GtkWidget *widget,
8696 GtkDirectionType direction)
8698 gboolean return_val;
8700 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8702 if (!gtk_widget_get_visible (widget) ||
8703 !gtk_widget_is_sensitive (widget))
8706 /* child widgets must set CAN_FOCUS, containers
8707 * don't have to though.
8709 if (!GTK_IS_CONTAINER (widget) &&
8710 !gtk_widget_get_can_focus (widget))
8713 g_signal_emit (widget,
8714 widget_signals[FOCUS],
8716 direction, &return_val);
8722 * gtk_widget_keynav_failed:
8723 * @widget: a #GtkWidget
8724 * @direction: direction of focus movement
8726 * This function should be called whenever keyboard navigation within
8727 * a single widget hits a boundary. The function emits the
8728 * #GtkWidget::keynav-failed signal on the widget and its return
8729 * value should be interpreted in a way similar to the return value of
8730 * gtk_widget_child_focus():
8732 * When %TRUE is returned, stay in the widget, the failed keyboard
8733 * navigation is Ok and/or there is nowhere we can/should move the
8736 * When %FALSE is returned, the caller should continue with keyboard
8737 * navigation outside the widget, e.g. by calling
8738 * gtk_widget_child_focus() on the widget's toplevel.
8740 * The default ::keynav-failed handler returns %TRUE for
8741 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
8742 * values of #GtkDirectionType, it looks at the
8743 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
8744 * if the setting is %TRUE. This way the entire user interface
8745 * becomes cursor-navigatable on input devices such as mobile phones
8746 * which only have cursor keys but no tab key.
8748 * Whenever the default handler returns %TRUE, it also calls
8749 * gtk_widget_error_bell() to notify the user of the failed keyboard
8752 * A use case for providing an own implementation of ::keynav-failed
8753 * (either by connecting to it or by overriding it) would be a row of
8754 * #GtkEntry widgets where the user should be able to navigate the
8755 * entire row with the cursor keys, as e.g. known from user interfaces
8756 * that require entering license keys.
8758 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
8759 * if the emitting widget should try to handle the keyboard
8760 * navigation attempt in its parent container(s).
8765 gtk_widget_keynav_failed (GtkWidget *widget,
8766 GtkDirectionType direction)
8768 gboolean return_val;
8770 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8772 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
8773 direction, &return_val);
8779 * gtk_widget_error_bell:
8780 * @widget: a #GtkWidget
8782 * Notifies the user about an input-related error on this widget.
8783 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
8784 * gdk_window_beep(), otherwise it does nothing.
8786 * Note that the effect of gdk_window_beep() can be configured in many
8787 * ways, depending on the windowing backend and the desktop environment
8788 * or window manager that is used.
8793 gtk_widget_error_bell (GtkWidget *widget)
8795 GtkWidgetPrivate *priv;
8796 GtkSettings* settings;
8799 g_return_if_fail (GTK_IS_WIDGET (widget));
8801 priv = widget->priv;
8803 settings = gtk_widget_get_settings (widget);
8807 g_object_get (settings,
8808 "gtk-error-bell", &beep,
8811 if (beep && priv->window)
8812 gdk_window_beep (priv->window);
8816 gtk_widget_set_usize_internal (GtkWidget *widget,
8819 GtkQueueResizeFlags flags)
8821 GtkWidgetAuxInfo *aux_info;
8822 gboolean changed = FALSE;
8824 g_object_freeze_notify (G_OBJECT (widget));
8826 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
8828 if (width > -2 && aux_info->width != width)
8830 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
8831 g_object_notify (G_OBJECT (widget), "width-request");
8832 aux_info->width = width;
8835 if (height > -2 && aux_info->height != height)
8837 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
8838 g_object_notify (G_OBJECT (widget), "height-request");
8839 aux_info->height = height;
8843 if (gtk_widget_get_visible (widget) && changed)
8845 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
8846 gtk_widget_queue_resize (widget);
8848 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
8851 g_object_thaw_notify (G_OBJECT (widget));
8855 * gtk_widget_set_size_request:
8856 * @widget: a #GtkWidget
8857 * @width: width @widget should request, or -1 to unset
8858 * @height: height @widget should request, or -1 to unset
8860 * Sets the minimum size of a widget; that is, the widget's size
8861 * request will be @width by @height. You can use this function to
8862 * force a widget to be either larger or smaller than it normally
8865 * In most cases, gtk_window_set_default_size() is a better choice for
8866 * toplevel windows than this function; setting the default size will
8867 * still allow users to shrink the window. Setting the size request
8868 * will force them to leave the window at least as large as the size
8869 * request. When dealing with window sizes,
8870 * gtk_window_set_geometry_hints() can be a useful function as well.
8872 * Note the inherent danger of setting any fixed size - themes,
8873 * translations into other languages, different fonts, and user action
8874 * can all change the appropriate size for a given widget. So, it's
8875 * basically impossible to hardcode a size that will always be
8878 * The size request of a widget is the smallest size a widget can
8879 * accept while still functioning well and drawing itself correctly.
8880 * However in some strange cases a widget may be allocated less than
8881 * its requested size, and in many cases a widget may be allocated more
8882 * space than it requested.
8884 * If the size request in a given direction is -1 (unset), then
8885 * the "natural" size request of the widget will be used instead.
8887 * Widgets can't actually be allocated a size less than 1 by 1, but
8888 * you can pass 0,0 to this function to mean "as small as possible."
8890 * The size request set here does not include any margin from the
8891 * #GtkWidget properties margin-left, margin-right, margin-top, and
8892 * margin-bottom, but it does include pretty much all other padding
8893 * or border properties set by any subclass of #GtkWidget.
8896 gtk_widget_set_size_request (GtkWidget *widget,
8900 g_return_if_fail (GTK_IS_WIDGET (widget));
8901 g_return_if_fail (width >= -1);
8902 g_return_if_fail (height >= -1);
8909 gtk_widget_set_usize_internal (widget, width, height, 0);
8914 * gtk_widget_get_size_request:
8915 * @widget: a #GtkWidget
8916 * @width: (out) (allow-none): return location for width, or %NULL
8917 * @height: (out) (allow-none): return location for height, or %NULL
8919 * Gets the size request that was explicitly set for the widget using
8920 * gtk_widget_set_size_request(). A value of -1 stored in @width or
8921 * @height indicates that that dimension has not been set explicitly
8922 * and the natural requisition of the widget will be used intead. See
8923 * gtk_widget_set_size_request(). To get the size a widget will
8924 * actually request, call gtk_widget_get_preferred_size() instead of
8928 gtk_widget_get_size_request (GtkWidget *widget,
8932 const GtkWidgetAuxInfo *aux_info;
8934 g_return_if_fail (GTK_IS_WIDGET (widget));
8936 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
8939 *width = aux_info->width;
8942 *height = aux_info->height;
8946 * _gtk_widget_override_size_request:
8947 * @widget: a #GtkWidget
8948 * @width: new forced minimum width
8949 * @height: new forced minimum height
8950 * @old_width: location to store previous forced minimum width
8951 * @old_width: location to store previous forced minumum height
8953 * Temporarily establishes a forced minimum size for a widget; this
8954 * is used by GtkWindow when calculating the size to add to the
8955 * window's geometry widget. Cached sizes for the widget and its
8956 * parents are invalidated, so that subsequent calls to the size
8957 * negotiation machinery produce the overriden result, but the
8958 * widget is not queued for relayout or redraw. The old size must
8959 * be restored with _gtk_widget_restore_size_request() or things
8963 _gtk_widget_override_size_request (GtkWidget *widget,
8969 gtk_widget_get_size_request (widget, old_width, old_height);
8970 gtk_widget_set_usize_internal (widget, width, height,
8971 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
8975 * _gtk_widget_restore_size_request:
8976 * @widget: a #GtkWidget
8977 * @old_width: saved forced minimum size
8978 * @old_height: saved forced minimum size
8980 * Undoes the operation of_gtk_widget_override_size_request().
8983 _gtk_widget_restore_size_request (GtkWidget *widget,
8987 gtk_widget_set_usize_internal (widget, old_width, old_height,
8988 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
8992 * gtk_widget_set_events:
8993 * @widget: a #GtkWidget
8994 * @events: event mask
8996 * Sets the event mask (see #GdkEventMask) for a widget. The event
8997 * mask determines which events a widget will receive. Keep in mind
8998 * that different widgets have different default event masks, and by
8999 * changing the event mask you may disrupt a widget's functionality,
9000 * so be careful. This function must be called while a widget is
9001 * unrealized. Consider gtk_widget_add_events() for widgets that are
9002 * already realized, or if you want to preserve the existing event
9003 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9004 * to get events on those widgets, place them inside a #GtkEventBox
9005 * and receive events on the event box.
9008 gtk_widget_set_events (GtkWidget *widget,
9011 g_return_if_fail (GTK_IS_WIDGET (widget));
9012 g_return_if_fail (!gtk_widget_get_realized (widget));
9014 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9015 GINT_TO_POINTER (events));
9016 g_object_notify (G_OBJECT (widget), "events");
9020 * gtk_widget_set_device_events:
9021 * @widget: a #GtkWidget
9022 * @device: a #GdkDevice
9023 * @events: event mask
9025 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9026 * mask determines which events a widget will receive from @device. Keep
9027 * in mind that different widgets have different default event masks, and by
9028 * changing the event mask you may disrupt a widget's functionality,
9029 * so be careful. This function must be called while a widget is
9030 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9031 * already realized, or if you want to preserve the existing event
9032 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9033 * to get events on those widgets, place them inside a #GtkEventBox
9034 * and receive events on the event box.
9039 gtk_widget_set_device_events (GtkWidget *widget,
9041 GdkEventMask events)
9043 GHashTable *device_events;
9045 g_return_if_fail (GTK_IS_WIDGET (widget));
9046 g_return_if_fail (GDK_IS_DEVICE (device));
9047 g_return_if_fail (!gtk_widget_get_realized (widget));
9049 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9051 if (G_UNLIKELY (!device_events))
9053 device_events = g_hash_table_new (NULL, NULL);
9054 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9055 (GDestroyNotify) g_hash_table_unref);
9058 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9062 gtk_widget_add_events_internal_list (GtkWidget *widget,
9069 for (l = window_list; l != NULL; l = l->next)
9071 GdkWindow *window = l->data;
9074 gdk_window_get_user_data (window, &user_data);
9075 if (user_data == widget)
9080 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9082 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9084 children = gdk_window_get_children (window);
9085 gtk_widget_add_events_internal_list (widget, device, events, children);
9086 g_list_free (children);
9092 gtk_widget_add_events_internal (GtkWidget *widget,
9096 GtkWidgetPrivate *priv = widget->priv;
9099 if (!gtk_widget_get_has_window (widget))
9100 window_list = gdk_window_get_children (priv->window);
9102 window_list = g_list_prepend (NULL, priv->window);
9104 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9106 g_list_free (window_list);
9110 * gtk_widget_add_events:
9111 * @widget: a #GtkWidget
9112 * @events: an event mask, see #GdkEventMask
9114 * Adds the events in the bitfield @events to the event mask for
9115 * @widget. See gtk_widget_set_events() for details.
9118 gtk_widget_add_events (GtkWidget *widget,
9123 g_return_if_fail (GTK_IS_WIDGET (widget));
9125 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9126 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9127 GINT_TO_POINTER (old_events | events));
9129 if (gtk_widget_get_realized (widget))
9130 gtk_widget_add_events_internal (widget, NULL, events);
9132 g_object_notify (G_OBJECT (widget), "events");
9136 * gtk_widget_add_device_events:
9137 * @widget: a #GtkWidget
9138 * @device: a #GdkDevice
9139 * @events: an event mask, see #GdkEventMask
9141 * Adds the device events in the bitfield @events to the event mask for
9142 * @widget. See gtk_widget_set_device_events() for details.
9147 gtk_widget_add_device_events (GtkWidget *widget,
9149 GdkEventMask events)
9151 GdkEventMask old_events;
9152 GHashTable *device_events;
9154 g_return_if_fail (GTK_IS_WIDGET (widget));
9155 g_return_if_fail (GDK_IS_DEVICE (device));
9157 old_events = gtk_widget_get_device_events (widget, device);
9159 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9161 if (G_UNLIKELY (!device_events))
9163 device_events = g_hash_table_new (NULL, NULL);
9164 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9165 (GDestroyNotify) g_hash_table_unref);
9168 g_hash_table_insert (device_events, device,
9169 GUINT_TO_POINTER (old_events | events));
9171 if (gtk_widget_get_realized (widget))
9172 gtk_widget_add_events_internal (widget, device, events);
9174 g_object_notify (G_OBJECT (widget), "events");
9178 * gtk_widget_set_extension_events:
9179 * @widget: a #GtkWidget
9180 * @mode: bitfield of extension events to receive
9182 * Sets the extension events mask to @mode. See #GdkExtensionMode
9183 * and gdk_input_set_extension_events().
9186 gtk_widget_set_extension_events (GtkWidget *widget,
9187 GdkExtensionMode mode)
9189 g_return_if_fail (GTK_IS_WIDGET (widget));
9191 if (gtk_widget_get_realized (widget))
9192 gtk_widget_set_extension_events_internal (widget, mode, NULL);
9194 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
9195 GINT_TO_POINTER (mode));
9196 g_object_notify (G_OBJECT (widget), "extension-events");
9200 * gtk_widget_get_toplevel:
9201 * @widget: a #GtkWidget
9203 * This function returns the topmost widget in the container hierarchy
9204 * @widget is a part of. If @widget has no parent widgets, it will be
9205 * returned as the topmost widget. No reference will be added to the
9206 * returned widget; it should not be unreferenced.
9208 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9209 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9211 * %NULL if @widget wasn't inside a toplevel window, and if the
9212 * window was inside a #GtkWindow-derived widget which was in turn
9213 * inside the toplevel #GtkWindow. While the second case may
9214 * seem unlikely, it actually happens when a #GtkPlug is embedded
9215 * inside a #GtkSocket within the same application.
9217 * To reliably find the toplevel #GtkWindow, use
9218 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9219 * is set on the result.
9221 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9222 * if (gtk_widget_is_toplevel (toplevel))
9224 * /* Perform action on toplevel. */
9228 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9229 * if there's no ancestor.
9232 gtk_widget_get_toplevel (GtkWidget *widget)
9234 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9236 while (widget->priv->parent)
9237 widget = widget->priv->parent;
9243 * gtk_widget_get_ancestor:
9244 * @widget: a #GtkWidget
9245 * @widget_type: ancestor type
9247 * Gets the first ancestor of @widget with type @widget_type. For example,
9248 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9249 * the first #GtkBox that's an ancestor of @widget. No reference will be
9250 * added to the returned widget; it should not be unreferenced. See note
9251 * about checking for a toplevel #GtkWindow in the docs for
9252 * gtk_widget_get_toplevel().
9254 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9255 * considers @widget to be an ancestor of itself.
9257 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9260 gtk_widget_get_ancestor (GtkWidget *widget,
9263 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9265 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9266 widget = widget->priv->parent;
9268 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9275 * gtk_widget_set_visual:
9276 * @widget: a #GtkWidget
9277 * @visual: visual to be used or %NULL to unset a previous one
9279 * Sets the visual that should be used for by widget and its children for
9280 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9281 * returned by gdk_widget_get_screen(), so handling the
9282 * #GtkWidget::screen-changed signal is necessary.
9284 * Setting a new @visual will not cause @widget to recreate its windows,
9285 * so you should call this function before @widget is realized.
9288 gtk_widget_set_visual (GtkWidget *widget,
9291 g_return_if_fail (GTK_IS_WIDGET (widget));
9292 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9295 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9298 g_object_set_qdata_full (G_OBJECT (widget),
9300 g_object_ref (visual),
9305 * gtk_widget_get_visual:
9306 * @widget: a #GtkWidget
9308 * Gets the visual that will be used to render @widget.
9310 * Return value: (transfer none): the visual for @widget
9313 gtk_widget_get_visual (GtkWidget *widget)
9319 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9321 if (gtk_widget_get_has_window (widget) &&
9322 widget->priv->window)
9323 return gdk_window_get_visual (widget->priv->window);
9325 screen = gtk_widget_get_screen (widget);
9327 for (w = widget; w != NULL; w = w->priv->parent)
9329 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9332 if (gdk_visual_get_screen (visual) == screen)
9335 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9336 gtk_widget_get_name (widget));
9340 return gdk_screen_get_system_visual (screen);
9344 * gtk_widget_get_settings:
9345 * @widget: a #GtkWidget
9347 * Gets the settings object holding the settings (global property
9348 * settings, RC file information, etc) used for this widget.
9350 * Note that this function can only be called when the #GtkWidget
9351 * is attached to a toplevel, since the settings object is specific
9352 * to a particular #GdkScreen.
9354 * Return value: (transfer none): the relevant #GtkSettings object
9357 gtk_widget_get_settings (GtkWidget *widget)
9359 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9361 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9365 * gtk_widget_get_events:
9366 * @widget: a #GtkWidget
9368 * Returns the event mask for the widget (a bitfield containing flags
9369 * from the #GdkEventMask enumeration). These are the events that the widget
9372 * Return value: event mask for @widget
9375 gtk_widget_get_events (GtkWidget *widget)
9377 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9379 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9383 * gtk_widget_get_device_events:
9384 * @widget: a #GtkWidget
9385 * @device: a #GdkDevice
9387 * Returns the events mask for the widget corresponding to an specific device. These
9388 * are the events that the widget will receive when @device operates on it.
9390 * Returns: device event mask for @widget
9395 gtk_widget_get_device_events (GtkWidget *widget,
9398 GHashTable *device_events;
9400 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9401 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9403 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9408 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9412 * gtk_widget_get_extension_events:
9413 * @widget: a #GtkWidget
9415 * Retrieves the extension events the widget will receive; see
9416 * gdk_input_set_extension_events().
9418 * Return value: extension events for @widget
9421 gtk_widget_get_extension_events (GtkWidget *widget)
9423 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9425 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
9429 * gtk_widget_get_pointer:
9430 * @widget: a #GtkWidget
9431 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9432 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9434 * Obtains the location of the mouse pointer in widget coordinates.
9435 * Widget coordinates are a bit odd; for historical reasons, they are
9436 * defined as @widget->window coordinates for widgets that are not
9437 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9438 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9441 gtk_widget_get_pointer (GtkWidget *widget,
9445 GtkWidgetPrivate *priv;
9447 g_return_if_fail (GTK_IS_WIDGET (widget));
9449 priv = widget->priv;
9456 if (gtk_widget_get_realized (widget))
9458 gdk_window_get_pointer (priv->window, x, y, NULL);
9460 if (!gtk_widget_get_has_window (widget))
9463 *x -= priv->allocation.x;
9465 *y -= priv->allocation.y;
9471 * gtk_widget_is_ancestor:
9472 * @widget: a #GtkWidget
9473 * @ancestor: another #GtkWidget
9475 * Determines whether @widget is somewhere inside @ancestor, possibly with
9476 * intermediate containers.
9478 * Return value: %TRUE if @ancestor contains @widget as a child,
9479 * grandchild, great grandchild, etc.
9482 gtk_widget_is_ancestor (GtkWidget *widget,
9483 GtkWidget *ancestor)
9485 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9486 g_return_val_if_fail (ancestor != NULL, FALSE);
9490 if (widget->priv->parent == ancestor)
9492 widget = widget->priv->parent;
9498 static GQuark quark_composite_name = 0;
9501 * gtk_widget_set_composite_name:
9502 * @widget: a #GtkWidget.
9503 * @name: the name to set
9505 * Sets a widgets composite name. The widget must be
9506 * a composite child of its parent; see gtk_widget_push_composite_child().
9509 gtk_widget_set_composite_name (GtkWidget *widget,
9512 g_return_if_fail (GTK_IS_WIDGET (widget));
9513 g_return_if_fail (widget->priv->composite_child);
9514 g_return_if_fail (name != NULL);
9516 if (!quark_composite_name)
9517 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
9519 g_object_set_qdata_full (G_OBJECT (widget),
9520 quark_composite_name,
9526 * gtk_widget_get_composite_name:
9527 * @widget: a #GtkWidget
9529 * Obtains the composite name of a widget.
9531 * Returns: the composite name of @widget, or %NULL if @widget is not
9532 * a composite child. The string should be freed when it is no
9536 gtk_widget_get_composite_name (GtkWidget *widget)
9538 GtkWidgetPrivate *priv;
9540 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9542 priv = widget->priv;
9544 if (widget->priv->composite_child && priv->parent)
9545 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
9552 * gtk_widget_push_composite_child:
9554 * Makes all newly-created widgets as composite children until
9555 * the corresponding gtk_widget_pop_composite_child() call.
9557 * A composite child is a child that's an implementation detail of the
9558 * container it's inside and should not be visible to people using the
9559 * container. Composite children aren't treated differently by GTK (but
9560 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
9561 * builders might want to treat them in a different way.
9563 * Here is a simple example:
9565 * gtk_widget_push_composite_child ();
9566 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
9567 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
9568 * gtk_widget_pop_composite_child ();
9569 * gtk_widget_set_parent (scrolled_window->hscrollbar,
9570 * GTK_WIDGET (scrolled_window));
9571 * g_object_ref (scrolled_window->hscrollbar);
9575 gtk_widget_push_composite_child (void)
9577 composite_child_stack++;
9581 * gtk_widget_pop_composite_child:
9583 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
9586 gtk_widget_pop_composite_child (void)
9588 if (composite_child_stack)
9589 composite_child_stack--;
9593 gtk_widget_emit_direction_changed (GtkWidget *widget,
9594 GtkTextDirection old_dir)
9596 gtk_widget_update_pango_context (widget);
9598 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
9602 * gtk_widget_set_direction:
9603 * @widget: a #GtkWidget
9604 * @dir: the new direction
9606 * Sets the reading direction on a particular widget. This direction
9607 * controls the primary direction for widgets containing text,
9608 * and also the direction in which the children of a container are
9609 * packed. The ability to set the direction is present in order
9610 * so that correct localization into languages with right-to-left
9611 * reading directions can be done. Generally, applications will
9612 * let the default reading direction present, except for containers
9613 * where the containers are arranged in an order that is explicitely
9614 * visual rather than logical (such as buttons for text justification).
9616 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
9617 * set by gtk_widget_set_default_direction() will be used.
9620 gtk_widget_set_direction (GtkWidget *widget,
9621 GtkTextDirection dir)
9623 GtkTextDirection old_dir;
9625 g_return_if_fail (GTK_IS_WIDGET (widget));
9626 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
9628 old_dir = gtk_widget_get_direction (widget);
9630 widget->priv->direction = dir;
9632 if (old_dir != gtk_widget_get_direction (widget))
9634 GtkStyleContext *context;
9636 context = g_object_get_qdata (G_OBJECT (widget), quark_style_context);
9639 gtk_style_context_set_direction (context,
9640 gtk_widget_get_direction (widget));
9642 gtk_widget_emit_direction_changed (widget, old_dir);
9647 * gtk_widget_get_direction:
9648 * @widget: a #GtkWidget
9650 * Gets the reading direction for a particular widget. See
9651 * gtk_widget_set_direction().
9653 * Return value: the reading direction for the widget.
9656 gtk_widget_get_direction (GtkWidget *widget)
9658 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
9660 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
9661 return gtk_default_direction;
9663 return widget->priv->direction;
9667 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
9669 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
9671 g_object_ref (widget);
9673 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
9674 gtk_widget_emit_direction_changed (widget, old_dir);
9676 if (GTK_IS_CONTAINER (widget))
9677 gtk_container_forall (GTK_CONTAINER (widget),
9678 gtk_widget_set_default_direction_recurse,
9681 g_object_unref (widget);
9685 * gtk_widget_set_default_direction:
9686 * @dir: the new default direction. This cannot be
9687 * %GTK_TEXT_DIR_NONE.
9689 * Sets the default reading direction for widgets where the
9690 * direction has not been explicitly set by gtk_widget_set_direction().
9693 gtk_widget_set_default_direction (GtkTextDirection dir)
9695 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
9697 if (dir != gtk_default_direction)
9699 GList *toplevels, *tmp_list;
9700 GtkTextDirection old_dir = gtk_default_direction;
9702 gtk_default_direction = dir;
9704 tmp_list = toplevels = gtk_window_list_toplevels ();
9705 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
9709 gtk_widget_set_default_direction_recurse (tmp_list->data,
9710 GUINT_TO_POINTER (old_dir));
9711 g_object_unref (tmp_list->data);
9712 tmp_list = tmp_list->next;
9715 g_list_free (toplevels);
9720 * gtk_widget_get_default_direction:
9722 * Obtains the current default reading direction. See
9723 * gtk_widget_set_default_direction().
9725 * Return value: the current default direction.
9728 gtk_widget_get_default_direction (void)
9730 return gtk_default_direction;
9734 gtk_widget_dispose (GObject *object)
9736 GtkWidget *widget = GTK_WIDGET (object);
9737 GtkWidgetPrivate *priv = widget->priv;
9740 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
9741 else if (gtk_widget_get_visible (widget))
9742 gtk_widget_hide (widget);
9744 priv->visible = FALSE;
9745 if (gtk_widget_get_realized (widget))
9746 gtk_widget_unrealize (widget);
9748 if (!priv->in_destruction)
9750 priv->in_destruction = TRUE;
9751 g_signal_emit (object, widget_signals[DESTROY], 0);
9752 priv->in_destruction = FALSE;
9755 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
9759 gtk_widget_real_destroy (GtkWidget *object)
9761 /* gtk_object_destroy() will already hold a refcount on object */
9762 GtkWidget *widget = GTK_WIDGET (object);
9763 GtkWidgetPrivate *priv = widget->priv;
9765 /* wipe accelerator closures (keep order) */
9766 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
9767 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
9769 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
9770 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
9772 gtk_grab_remove (widget);
9774 g_object_unref (priv->style);
9775 priv->style = gtk_widget_get_default_style ();
9776 g_object_ref (priv->style);
9780 gtk_widget_finalize (GObject *object)
9782 GtkWidget *widget = GTK_WIDGET (object);
9783 GtkWidgetPrivate *priv = widget->priv;
9784 GtkWidgetAuxInfo *aux_info;
9785 GtkAccessible *accessible;
9787 gtk_grab_remove (widget);
9789 g_object_unref (priv->style);
9792 g_free (priv->name);
9794 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
9796 gtk_widget_aux_info_destroy (aux_info);
9798 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
9800 g_object_unref (accessible);
9802 if (g_object_is_floating (object))
9803 g_warning ("A floating object was finalized. This means that someone\n"
9804 "called g_object_unref() on an object that had only a floating\n"
9805 "reference; the initial floating reference is not owned by anyone\n"
9806 "and must be removed with g_object_ref_sink().");
9808 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
9811 /*****************************************
9812 * gtk_widget_real_map:
9817 *****************************************/
9820 gtk_widget_real_map (GtkWidget *widget)
9822 GtkWidgetPrivate *priv = widget->priv;
9824 g_assert (gtk_widget_get_realized (widget));
9826 if (!gtk_widget_get_mapped (widget))
9828 gtk_widget_set_mapped (widget, TRUE);
9830 if (gtk_widget_get_has_window (widget))
9831 gdk_window_show (priv->window);
9835 /*****************************************
9836 * gtk_widget_real_unmap:
9841 *****************************************/
9844 gtk_widget_real_unmap (GtkWidget *widget)
9846 GtkWidgetPrivate *priv = widget->priv;
9848 if (gtk_widget_get_mapped (widget))
9850 gtk_widget_set_mapped (widget, FALSE);
9852 if (gtk_widget_get_has_window (widget))
9853 gdk_window_hide (priv->window);
9857 /*****************************************
9858 * gtk_widget_real_realize:
9863 *****************************************/
9866 gtk_widget_real_realize (GtkWidget *widget)
9868 GtkWidgetPrivate *priv = widget->priv;
9870 g_assert (!gtk_widget_get_has_window (widget));
9872 gtk_widget_set_realized (widget, TRUE);
9875 priv->window = gtk_widget_get_parent_window (widget);
9876 g_object_ref (priv->window);
9878 priv->style = gtk_style_attach (priv->style, priv->window);
9881 /*****************************************
9882 * gtk_widget_real_unrealize:
9887 *****************************************/
9890 gtk_widget_real_unrealize (GtkWidget *widget)
9892 GtkWidgetPrivate *priv = widget->priv;
9894 if (gtk_widget_get_mapped (widget))
9895 gtk_widget_real_unmap (widget);
9897 gtk_widget_set_mapped (widget, FALSE);
9899 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
9902 /* We must do unrealize child widget BEFORE container widget.
9903 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
9904 * So, unrealizing container widget bofore its children causes the problem
9905 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
9908 if (GTK_IS_CONTAINER (widget))
9909 gtk_container_forall (GTK_CONTAINER (widget),
9910 (GtkCallback) gtk_widget_unrealize,
9913 gtk_style_detach (priv->style);
9914 if (gtk_widget_get_has_window (widget))
9916 gdk_window_set_user_data (priv->window, NULL);
9917 gdk_window_destroy (priv->window);
9918 priv->window = NULL;
9922 g_object_unref (priv->window);
9923 priv->window = NULL;
9926 gtk_selection_remove_all (widget);
9928 gtk_widget_set_realized (widget, FALSE);
9932 gtk_widget_real_adjust_size_request (GtkWidget *widget,
9933 GtkOrientation orientation,
9937 const GtkWidgetAuxInfo *aux_info;
9939 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
9941 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
9942 aux_info->width > 0)
9944 *minimum_size = MAX (*minimum_size, aux_info->width);
9946 else if (orientation == GTK_ORIENTATION_VERTICAL &&
9947 aux_info->height > 0)
9949 *minimum_size = MAX (*minimum_size, aux_info->height);
9952 /* Fix it if set_size_request made natural size smaller than min size.
9953 * This would also silently fix broken widgets, but we warn about them
9954 * in gtksizerequest.c when calling their size request vfuncs.
9956 *natural_size = MAX (*natural_size, *minimum_size);
9958 if (orientation == GTK_ORIENTATION_HORIZONTAL)
9960 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
9961 *natural_size += (aux_info->margin.left + aux_info->margin.right);
9965 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
9966 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
9971 * _gtk_widget_peek_request_cache:
9973 * Returns the address of the widget's request cache (strictly for
9974 * internal use in gtksizerequest.c)
9976 * Return value: the address of @widget's size request cache.
9979 _gtk_widget_peek_request_cache (GtkWidget *widget)
9981 /* Don't bother slowing things down with the return_if_fail guards here */
9982 return &widget->priv->requests;
9986 * _gtk_widget_set_device_window:
9987 * @widget: a #GtkWidget.
9988 * @device: a #GdkDevice.
9989 * @window: the new device window.
9991 * Sets pointer window for @widget and @device. Does not ref @window.
9992 * Actually stores it on the #GdkScreen, but you don't need to know that.
9995 _gtk_widget_set_device_window (GtkWidget *widget,
9999 GtkWidgetPrivate *priv;
10001 GHashTable *device_window;
10003 g_return_if_fail (GTK_IS_WIDGET (widget));
10004 g_return_if_fail (GDK_IS_DEVICE (device));
10005 g_return_if_fail (!window || GDK_IS_WINDOW (window));
10007 priv = widget->priv;
10009 if (!gtk_widget_get_realized (widget))
10012 screen = gdk_window_get_screen (priv->window);
10013 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10015 if (G_UNLIKELY (!device_window))
10017 device_window = g_hash_table_new (NULL, NULL);
10018 g_object_set_qdata_full (G_OBJECT (screen),
10019 quark_pointer_window,
10021 (GDestroyNotify) g_hash_table_destroy);
10025 g_hash_table_insert (device_window, device, window);
10027 g_hash_table_remove (device_window, device);
10031 * _gtk_widget_get_device_window:
10032 * @widget: a #GtkWidget.
10033 * @device: a #GdkDevice.
10035 * Return value: the device window set on the #GdkScreen @widget is attached
10039 _gtk_widget_get_device_window (GtkWidget *widget,
10042 GtkWidgetPrivate *priv;
10044 GHashTable *device_window;
10048 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10049 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10051 priv = widget->priv;
10053 if (!gtk_widget_get_realized (widget))
10056 screen = gdk_window_get_screen (priv->window);
10057 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10059 if (G_UNLIKELY (!device_window))
10062 window = g_hash_table_lookup (device_window, device);
10067 gdk_window_get_user_data (window, (gpointer *) &w);
10076 * _gtk_widget_list_devices:
10077 * @widget: a #GtkWidget.
10079 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
10080 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
10084 _gtk_widget_list_devices (GtkWidget *widget)
10086 GtkWidgetPrivate *priv;
10088 GHashTableIter iter;
10089 GHashTable *device_window;
10090 GList *devices = NULL;
10091 gpointer key, value;
10093 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10095 priv = widget->priv;
10097 if (!gtk_widget_get_realized (widget))
10100 screen = gdk_window_get_screen (priv->window);
10101 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10103 if (G_UNLIKELY (!device_window))
10106 g_hash_table_iter_init (&iter, device_window);
10108 while (g_hash_table_iter_next (&iter, &key, &value))
10110 GdkDevice *device = key;
10111 GdkWindow *window = value;
10116 gdk_window_get_user_data (window, (gpointer *) &w);
10119 devices = g_list_prepend (devices, device);
10127 synth_crossing (GtkWidget *widget,
10131 GdkCrossingMode mode,
10132 GdkNotifyType detail)
10136 event = gdk_event_new (type);
10138 event->crossing.window = g_object_ref (window);
10139 event->crossing.send_event = TRUE;
10140 event->crossing.subwindow = g_object_ref (window);
10141 event->crossing.time = GDK_CURRENT_TIME;
10142 event->crossing.x = event->crossing.y = 0;
10143 event->crossing.x_root = event->crossing.y_root = 0;
10144 event->crossing.mode = mode;
10145 event->crossing.detail = detail;
10146 event->crossing.focus = FALSE;
10147 event->crossing.state = 0;
10148 gdk_event_set_device (event, device);
10151 widget = gtk_get_event_widget (event);
10154 gtk_widget_event_internal (widget, event);
10156 gdk_event_free (event);
10160 * _gtk_widget_synthesize_crossing:
10161 * @from: the #GtkWidget the virtual pointer is leaving.
10162 * @to: the #GtkWidget the virtual pointer is moving to.
10163 * @mode: the #GdkCrossingMode to place on the synthesized events.
10165 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10167 * The real pointer window is the window that most recently received an enter notify
10168 * event. Windows that don't select for crossing events can't become the real
10169 * poiner window. The real pointer widget that owns the real pointer window. The
10170 * effective pointer window is the same as the real pointer window unless the real
10171 * pointer widget is either insensitive or there is a grab on a widget that is not
10172 * an ancestor of the real pointer widget (in which case the effective pointer
10173 * window should be the root window).
10175 * When the effective pointer window is the same as the real poiner window, we
10176 * receive crossing events from the windowing system. When the effective pointer
10177 * window changes to become different from the real pointer window we synthesize
10178 * crossing events, attempting to follow X protocol rules:
10180 * When the root window becomes the effective pointer window:
10181 * - leave notify on real pointer window, detail Ancestor
10182 * - leave notify on all of its ancestors, detail Virtual
10183 * - enter notify on root window, detail Inferior
10185 * When the root window ceases to be the effective pointer window:
10186 * - leave notify on root window, detail Inferior
10187 * - enter notify on all ancestors of real pointer window, detail Virtual
10188 * - enter notify on real pointer window, detail Ancestor
10191 _gtk_widget_synthesize_crossing (GtkWidget *from,
10194 GdkCrossingMode mode)
10196 GdkWindow *from_window = NULL, *to_window = NULL;
10198 g_return_if_fail (from != NULL || to != NULL);
10202 from_window = _gtk_widget_get_device_window (from, device);
10205 from_window = from->priv->window;
10210 to_window = _gtk_widget_get_device_window (to, device);
10213 to_window = to->priv->window;
10216 if (from_window == NULL && to_window == NULL)
10218 else if (from_window != NULL && to_window == NULL)
10220 GList *from_ancestors = NULL, *list;
10221 GdkWindow *from_ancestor = from_window;
10223 while (from_ancestor != NULL)
10225 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10226 if (from_ancestor == NULL)
10228 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10231 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10232 device, mode, GDK_NOTIFY_ANCESTOR);
10233 for (list = g_list_last (from_ancestors); list; list = list->prev)
10235 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10236 device, mode, GDK_NOTIFY_VIRTUAL);
10239 /* XXX: enter/inferior on root window? */
10241 g_list_free (from_ancestors);
10243 else if (from_window == NULL && to_window != NULL)
10245 GList *to_ancestors = NULL, *list;
10246 GdkWindow *to_ancestor = to_window;
10248 while (to_ancestor != NULL)
10250 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10251 if (to_ancestor == NULL)
10253 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10256 /* XXX: leave/inferior on root window? */
10258 for (list = to_ancestors; list; list = list->next)
10260 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10261 device, mode, GDK_NOTIFY_VIRTUAL);
10263 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10264 device, mode, GDK_NOTIFY_ANCESTOR);
10266 g_list_free (to_ancestors);
10268 else if (from_window == to_window)
10272 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10273 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10275 while (from_ancestor != NULL || to_ancestor != NULL)
10277 if (from_ancestor != NULL)
10279 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10280 if (from_ancestor == to_window)
10283 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10285 if (to_ancestor != NULL)
10287 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10288 if (to_ancestor == from_window)
10291 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10294 if (to_ancestor == from_window)
10296 if (mode != GDK_CROSSING_GTK_UNGRAB)
10297 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10298 device, mode, GDK_NOTIFY_INFERIOR);
10299 for (list = to_ancestors; list; list = list->next)
10300 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10301 device, mode, GDK_NOTIFY_VIRTUAL);
10302 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10303 device, mode, GDK_NOTIFY_ANCESTOR);
10305 else if (from_ancestor == to_window)
10307 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10308 device, mode, GDK_NOTIFY_ANCESTOR);
10309 for (list = g_list_last (from_ancestors); list; list = list->prev)
10311 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10312 device, mode, GDK_NOTIFY_VIRTUAL);
10314 if (mode != GDK_CROSSING_GTK_GRAB)
10315 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10316 device, mode, GDK_NOTIFY_INFERIOR);
10320 while (from_ancestors != NULL && to_ancestors != NULL
10321 && from_ancestors->data == to_ancestors->data)
10323 from_ancestors = g_list_delete_link (from_ancestors,
10325 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10328 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10329 device, mode, GDK_NOTIFY_NONLINEAR);
10331 for (list = g_list_last (from_ancestors); list; list = list->prev)
10333 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10334 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10336 for (list = to_ancestors; list; list = list->next)
10338 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10339 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10341 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10342 device, mode, GDK_NOTIFY_NONLINEAR);
10344 g_list_free (from_ancestors);
10345 g_list_free (to_ancestors);
10350 gtk_widget_propagate_state (GtkWidget *widget,
10351 GtkStateData *data)
10353 GtkWidgetPrivate *priv = widget->priv;
10354 guint8 old_state = gtk_widget_get_state (widget);
10355 guint8 old_saved_state = priv->saved_state;
10357 /* don't call this function with state==GTK_STATE_INSENSITIVE,
10358 * parent_sensitive==TRUE on a sensitive widget
10362 priv->parent_sensitive = data->parent_sensitive;
10364 if (gtk_widget_is_sensitive (widget))
10366 if (data->state_restoration)
10367 priv->state = priv->saved_state;
10369 priv->state = data->state;
10373 if (!data->state_restoration)
10375 if (data->state != GTK_STATE_INSENSITIVE)
10376 priv->saved_state = data->state;
10378 else if (gtk_widget_get_state (widget) != GTK_STATE_INSENSITIVE)
10379 priv->saved_state = gtk_widget_get_state (widget);
10380 priv->state = GTK_STATE_INSENSITIVE;
10383 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10387 window = gtk_widget_get_toplevel (widget);
10388 if (window && gtk_widget_is_toplevel (window))
10389 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10392 if (old_state != gtk_widget_get_state (widget) ||
10393 old_saved_state != priv->saved_state)
10395 g_object_ref (widget);
10397 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10398 gtk_grab_remove (widget);
10400 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10402 if (!priv->shadowed)
10404 GList *event_windows = NULL;
10405 GList *devices, *d;
10407 devices = _gtk_widget_list_devices (widget);
10409 for (d = devices; d; d = d->next)
10415 window = _gtk_widget_get_device_window (widget, device);
10417 /* Do not propagate more than once to the
10418 * same window if non-multidevice aware.
10420 if (!gdk_window_get_support_multidevice (window) &&
10421 g_list_find (event_windows, window))
10424 if (!gtk_widget_is_sensitive (widget))
10425 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10426 GDK_CROSSING_STATE_CHANGED);
10427 else if (old_state == GTK_STATE_INSENSITIVE)
10428 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10429 GDK_CROSSING_STATE_CHANGED);
10431 event_windows = g_list_prepend (event_windows, window);
10434 g_list_free (event_windows);
10435 g_list_free (devices);
10438 if (GTK_IS_CONTAINER (widget))
10440 data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
10441 if (data->use_forall)
10442 gtk_container_forall (GTK_CONTAINER (widget),
10443 (GtkCallback) gtk_widget_propagate_state,
10446 gtk_container_foreach (GTK_CONTAINER (widget),
10447 (GtkCallback) gtk_widget_propagate_state,
10450 g_object_unref (widget);
10454 static const GtkWidgetAuxInfo default_aux_info = {
10462 * _gtk_widget_get_aux_info:
10463 * @widget: a #GtkWidget
10464 * @create: if %TRUE, create the structure if it doesn't exist
10466 * Get the #GtkWidgetAuxInfo structure for the widget.
10468 * Return value: the #GtkAuxInfo structure for the widget, or
10469 * %NULL if @create is %FALSE and one doesn't already exist.
10472 _gtk_widget_get_aux_info (GtkWidget *widget,
10475 GtkWidgetAuxInfo *aux_info;
10477 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
10478 if (!aux_info && create)
10480 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
10482 *aux_info = default_aux_info;
10484 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
10490 static const GtkWidgetAuxInfo*
10491 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
10493 GtkWidgetAuxInfo *aux_info;
10495 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
10496 if (aux_info == NULL)
10498 return &default_aux_info;
10506 /*****************************************
10507 * gtk_widget_aux_info_destroy:
10512 *****************************************/
10515 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
10517 g_slice_free (GtkWidgetAuxInfo, aux_info);
10521 * gtk_widget_shape_combine_region:
10522 * @widget: a #GtkWidget
10523 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10525 * Sets a shape for this widget's GDK window. This allows for
10526 * transparent windows etc., see gdk_window_shape_combine_region()
10527 * for more information.
10532 gtk_widget_shape_combine_region (GtkWidget *widget,
10533 cairo_region_t *region)
10535 GtkWidgetPrivate *priv;
10537 g_return_if_fail (GTK_IS_WIDGET (widget));
10538 /* set_shape doesn't work on widgets without gdk window */
10539 g_return_if_fail (gtk_widget_get_has_window (widget));
10541 priv = widget->priv;
10543 if (region == NULL)
10545 priv->has_shape_mask = FALSE;
10548 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
10550 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
10554 priv->has_shape_mask = TRUE;
10556 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
10557 cairo_region_copy (region),
10558 (GDestroyNotify) cairo_region_destroy);
10560 /* set shape if widget has a gdk window already.
10561 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10564 gdk_window_shape_combine_region (priv->window, region, 0, 0);
10569 * gtk_widget_input_shape_combine_region:
10570 * @widget: a #GtkWidget
10571 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10573 * Sets an input shape for this widget's GDK window. This allows for
10574 * windows which react to mouse click in a nonrectangular region, see
10575 * gdk_window_input_shape_combine_region() for more information.
10580 gtk_widget_input_shape_combine_region (GtkWidget *widget,
10581 cairo_region_t *region)
10583 GtkWidgetPrivate *priv;
10585 g_return_if_fail (GTK_IS_WIDGET (widget));
10586 /* set_shape doesn't work on widgets without gdk window */
10587 g_return_if_fail (gtk_widget_get_has_window (widget));
10589 priv = widget->priv;
10591 if (region == NULL)
10594 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
10596 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
10600 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
10601 cairo_region_copy (region),
10602 (GDestroyNotify) cairo_region_destroy);
10604 /* set shape if widget has a gdk window already.
10605 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10608 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
10614 gtk_reset_shapes_recurse (GtkWidget *widget,
10620 gdk_window_get_user_data (window, &data);
10621 if (data != widget)
10624 gdk_window_shape_combine_region (window, NULL, 0, 0);
10625 for (list = gdk_window_peek_children (window); list; list = list->next)
10626 gtk_reset_shapes_recurse (widget, list->data);
10630 * gtk_widget_reset_shapes:
10631 * @widget: a #GtkWidget
10633 * Recursively resets the shape on this widget and its descendants.
10636 gtk_widget_reset_shapes (GtkWidget *widget)
10638 GtkWidgetPrivate *priv;
10640 g_return_if_fail (GTK_IS_WIDGET (widget));
10641 g_return_if_fail (gtk_widget_get_realized (widget));
10643 priv = widget->priv;
10645 if (!priv->has_shape_mask)
10646 gtk_reset_shapes_recurse (widget, priv->window);
10649 /* style properties
10653 * gtk_widget_class_install_style_property_parser:
10654 * @klass: a #GtkWidgetClass
10655 * @pspec: the #GParamSpec for the style property
10656 * @parser: the parser for the style property
10658 * Installs a style property on a widget class.
10661 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
10663 GtkRcPropertyParser parser)
10665 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10666 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10667 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
10668 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
10670 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
10672 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
10673 G_OBJECT_CLASS_NAME (klass),
10678 g_param_spec_ref_sink (pspec);
10679 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
10680 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
10684 * gtk_widget_class_install_style_property:
10685 * @klass: a #GtkWidgetClass
10686 * @pspec: the #GParamSpec for the property
10688 * Installs a style property on a widget class. The parser for the
10689 * style property is determined by the value type of @pspec.
10692 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
10695 GtkRcPropertyParser parser;
10697 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10698 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10700 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
10702 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
10706 * gtk_widget_class_find_style_property:
10707 * @klass: a #GtkWidgetClass
10708 * @property_name: the name of the style property to find
10709 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
10710 * style property with that name.
10712 * Finds a style property of a widget class by name.
10717 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
10718 const gchar *property_name)
10720 g_return_val_if_fail (property_name != NULL, NULL);
10722 return g_param_spec_pool_lookup (style_property_spec_pool,
10724 G_OBJECT_CLASS_TYPE (klass),
10729 * gtk_widget_class_list_style_properties:
10730 * @klass: a #GtkWidgetClass
10731 * @n_properties: location to return the number of style properties found
10732 * @returns: an newly allocated array of #GParamSpec*. The array must
10733 * be freed with g_free().
10735 * Returns all style properties of a widget class.
10740 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
10741 guint *n_properties)
10743 GParamSpec **pspecs;
10746 pspecs = g_param_spec_pool_list (style_property_spec_pool,
10747 G_OBJECT_CLASS_TYPE (klass),
10756 * gtk_widget_style_get_property:
10757 * @widget: a #GtkWidget
10758 * @property_name: the name of a style property
10759 * @value: location to return the property value
10761 * Gets the value of a style property of @widget.
10764 gtk_widget_style_get_property (GtkWidget *widget,
10765 const gchar *property_name,
10770 g_return_if_fail (GTK_IS_WIDGET (widget));
10771 g_return_if_fail (property_name != NULL);
10772 g_return_if_fail (G_IS_VALUE (value));
10774 g_object_ref (widget);
10775 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10777 G_OBJECT_TYPE (widget),
10780 g_warning ("%s: widget class `%s' has no property named `%s'",
10782 G_OBJECT_TYPE_NAME (widget),
10786 GtkStyleContext *context;
10787 const GValue *peek_value;
10789 context = gtk_widget_get_style_context (widget);
10790 peek_value = _gtk_style_context_peek_style_property (context,
10791 G_OBJECT_TYPE (widget),
10794 /* auto-conversion of the caller's value type
10796 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
10797 g_value_copy (peek_value, value);
10798 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
10799 g_value_transform (peek_value, value);
10801 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
10803 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
10804 G_VALUE_TYPE_NAME (value));
10806 g_object_unref (widget);
10810 * gtk_widget_style_get_valist:
10811 * @widget: a #GtkWidget
10812 * @first_property_name: the name of the first property to get
10813 * @var_args: a <type>va_list</type> of pairs of property names and
10814 * locations to return the property values, starting with the location
10815 * for @first_property_name.
10817 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
10821 gtk_widget_style_get_valist (GtkWidget *widget,
10822 const gchar *first_property_name,
10825 GtkStyleContext *context;
10828 g_return_if_fail (GTK_IS_WIDGET (widget));
10830 g_object_ref (widget);
10831 context = gtk_widget_get_style_context (widget);
10833 name = first_property_name;
10836 const GValue *peek_value;
10840 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10842 G_OBJECT_TYPE (widget),
10846 g_warning ("%s: widget class `%s' has no property named `%s'",
10848 G_OBJECT_TYPE_NAME (widget),
10852 /* style pspecs are always readable so we can spare that check here */
10854 peek_value = _gtk_style_context_peek_style_property (context,
10855 G_OBJECT_TYPE (widget),
10858 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
10861 g_warning ("%s: %s", G_STRLOC, error);
10866 name = va_arg (var_args, gchar*);
10869 g_object_unref (widget);
10873 * gtk_widget_style_get:
10874 * @widget: a #GtkWidget
10875 * @first_property_name: the name of the first property to get
10876 * @Varargs: pairs of property names and locations to
10877 * return the property values, starting with the location for
10878 * @first_property_name, terminated by %NULL.
10880 * Gets the values of a multiple style properties of @widget.
10883 gtk_widget_style_get (GtkWidget *widget,
10884 const gchar *first_property_name,
10889 g_return_if_fail (GTK_IS_WIDGET (widget));
10891 va_start (var_args, first_property_name);
10892 gtk_widget_style_get_valist (widget, first_property_name, var_args);
10898 * @widget: a #GtkWidget
10899 * @path_length: (out) (allow-none): location to store length of the path, or %NULL
10900 * @path: (out) (allow-none): location to store allocated path string, or %NULL
10901 * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL
10903 * Obtains the full path to @widget. The path is simply the name of a
10904 * widget and all its parents in the container hierarchy, separated by
10905 * periods. The name of a widget comes from
10906 * gtk_widget_get_name(). Paths are used to apply styles to a widget
10907 * in gtkrc configuration files. Widget names are the type of the
10908 * widget by default (e.g. "GtkButton") or can be set to an
10909 * application-specific value with gtk_widget_set_name(). By setting
10910 * the name of a widget, you allow users or theme authors to apply
10911 * styles to that specific widget in their gtkrc
10912 * file. @path_reversed_p fills in the path in reverse order,
10913 * i.e. starting with @widget's name instead of starting with the name
10914 * of @widget's outermost ancestor.
10917 gtk_widget_path (GtkWidget *widget,
10918 guint *path_length,
10920 gchar **path_reversed)
10922 static gchar *rev_path = NULL;
10923 static guint tmp_path_len = 0;
10926 g_return_if_fail (GTK_IS_WIDGET (widget));
10931 const gchar *string;
10936 string = gtk_widget_get_name (widget);
10937 l = strlen (string);
10938 while (tmp_path_len <= len + l + 1)
10940 tmp_path_len += INIT_PATH_SIZE;
10941 rev_path = g_realloc (rev_path, tmp_path_len);
10943 s = string + l - 1;
10944 d = rev_path + len;
10945 while (s >= string)
10949 widget = widget->priv->parent;
10952 rev_path[len++] = '.';
10954 rev_path[len++] = 0;
10959 *path_length = len - 1;
10961 *path_reversed = g_strdup (rev_path);
10964 *path = g_strdup (rev_path);
10965 g_strreverse (*path);
10970 * gtk_widget_class_path:
10971 * @widget: a #GtkWidget
10972 * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10973 * @path: (out) (allow-none): location to store the class path as an allocated string, or %NULL
10974 * @path_reversed: (out) (allow-none): location to store the reverse class path as an allocated
10977 * Same as gtk_widget_path(), but always uses the name of a widget's type,
10978 * never uses a custom name set with gtk_widget_set_name().
10982 gtk_widget_class_path (GtkWidget *widget,
10983 guint *path_length,
10985 gchar **path_reversed)
10987 static gchar *rev_path = NULL;
10988 static guint tmp_path_len = 0;
10991 g_return_if_fail (GTK_IS_WIDGET (widget));
10996 const gchar *string;
11001 string = g_type_name (G_OBJECT_TYPE (widget));
11002 l = strlen (string);
11003 while (tmp_path_len <= len + l + 1)
11005 tmp_path_len += INIT_PATH_SIZE;
11006 rev_path = g_realloc (rev_path, tmp_path_len);
11008 s = string + l - 1;
11009 d = rev_path + len;
11010 while (s >= string)
11014 widget = widget->priv->parent;
11017 rev_path[len++] = '.';
11019 rev_path[len++] = 0;
11024 *path_length = len - 1;
11026 *path_reversed = g_strdup (rev_path);
11029 *path = g_strdup (rev_path);
11030 g_strreverse (*path);
11035 * gtk_requisition_new:
11037 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11039 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11040 * be freed with gtk_requisition_free().
11045 gtk_requisition_new (void)
11047 return g_slice_new0 (GtkRequisition);
11051 * gtk_requisition_copy:
11052 * @requisition: a #GtkRequisition
11054 * Copies a #GtkRequisition.
11056 * Returns: a copy of @requisition
11059 gtk_requisition_copy (const GtkRequisition *requisition)
11061 return g_slice_dup (GtkRequisition, requisition);
11065 * gtk_requisition_free:
11066 * @requisition: a #GtkRequisition
11068 * Frees a #GtkRequisition.
11071 gtk_requisition_free (GtkRequisition *requisition)
11073 g_slice_free (GtkRequisition, requisition);
11076 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11077 gtk_requisition_copy,
11078 gtk_requisition_free)
11081 * gtk_widget_get_accessible:
11082 * @widget: a #GtkWidget
11084 * Returns the accessible object that describes the widget to an
11085 * assistive technology.
11087 * If no accessibility library is loaded (i.e. no ATK implementation library is
11088 * loaded via <envar>GTK_MODULES</envar> or via another application library,
11089 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
11090 * if no class-specific #AtkObject implementation is available for the widget
11091 * instance in question, it will inherit an #AtkObject implementation from the
11092 * first ancestor class for which such an implementation is defined.
11094 * The documentation of the
11095 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
11096 * library contains more information about accessible objects and their uses.
11098 * Returns: (transfer none): the #AtkObject associated with @widget
11101 gtk_widget_get_accessible (GtkWidget *widget)
11103 GtkWidgetClass *klass;
11105 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11107 klass = GTK_WIDGET_GET_CLASS (widget);
11109 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11111 return klass->get_accessible (widget);
11115 gtk_widget_real_get_accessible (GtkWidget *widget)
11117 AtkObject* accessible;
11119 accessible = g_object_get_qdata (G_OBJECT (widget),
11120 quark_accessible_object);
11123 AtkObjectFactory *factory;
11124 AtkRegistry *default_registry;
11126 default_registry = atk_get_default_registry ();
11127 factory = atk_registry_get_factory (default_registry,
11128 G_TYPE_FROM_INSTANCE (widget));
11130 atk_object_factory_create_accessible (factory,
11131 G_OBJECT (widget));
11132 g_object_set_qdata (G_OBJECT (widget),
11133 quark_accessible_object,
11140 * Initialize a AtkImplementorIface instance's virtual pointers as
11141 * appropriate to this implementor's class (GtkWidget).
11144 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11146 iface->ref_accessible = gtk_widget_ref_accessible;
11150 gtk_widget_ref_accessible (AtkImplementor *implementor)
11152 AtkObject *accessible;
11154 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11156 g_object_ref (accessible);
11161 * Expand flag management
11165 gtk_widget_update_computed_expand (GtkWidget *widget)
11167 GtkWidgetPrivate *priv;
11169 priv = widget->priv;
11171 if (priv->need_compute_expand)
11175 if (priv->hexpand_set)
11180 if (priv->vexpand_set)
11185 /* we don't need to use compute_expand if both expands are
11186 * forced by the app
11188 if (!(priv->hexpand_set && priv->vexpand_set))
11190 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11194 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11195 priv->hexpand_set ? &ignored : &h,
11196 priv->vexpand_set ? &ignored : &v);
11200 priv->need_compute_expand = FALSE;
11201 priv->computed_hexpand = h != FALSE;
11202 priv->computed_vexpand = v != FALSE;
11207 * gtk_widget_queue_compute_expand:
11208 * @widget: a #GtkWidget
11210 * Mark @widget as needing to recompute its expand flags. Call
11211 * this function when setting legacy expand child properties
11212 * on the child of a container.
11214 * See gtk_widget_compute_expand().
11217 gtk_widget_queue_compute_expand (GtkWidget *widget)
11220 gboolean changed_anything;
11222 if (widget->priv->need_compute_expand)
11225 changed_anything = FALSE;
11227 while (parent != NULL)
11229 if (!parent->priv->need_compute_expand)
11231 parent->priv->need_compute_expand = TRUE;
11232 changed_anything = TRUE;
11235 /* Note: if we had an invariant that "if a child needs to
11236 * compute expand, its parents also do" then we could stop going
11237 * up when we got to a parent that already needed to
11238 * compute. However, in general we compute expand lazily (as
11239 * soon as we see something in a subtree that is expand, we know
11240 * we're expanding) and so this invariant does not hold and we
11241 * have to always walk all the way up in case some ancestor
11242 * is not currently need_compute_expand.
11245 parent = parent->priv->parent;
11248 /* recomputing expand always requires
11249 * a relayout as well
11251 if (changed_anything)
11252 gtk_widget_queue_resize (widget);
11256 * gtk_widget_compute_expand:
11257 * @widget: the widget
11258 * @orientation: expand direction
11260 * Computes whether a container should give this widget extra space
11261 * when possible. Containers should check this, rather than
11262 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11264 * This function already checks whether the widget is visible, so
11265 * visibility does not need to be checked separately. Non-visible
11266 * widgets are not expanded.
11268 * The computed expand value uses either the expand setting explicitly
11269 * set on the widget itself, or, if none has been explicitly set,
11270 * the widget may expand if some of its children do.
11272 * Return value: whether widget tree rooted here should be expanded
11275 gtk_widget_compute_expand (GtkWidget *widget,
11276 GtkOrientation orientation)
11278 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11280 /* We never make a widget expand if not even showing. */
11281 if (!gtk_widget_get_visible (widget))
11284 gtk_widget_update_computed_expand (widget);
11286 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11288 return widget->priv->computed_hexpand;
11292 return widget->priv->computed_vexpand;
11297 gtk_widget_set_expand (GtkWidget *widget,
11298 GtkOrientation orientation,
11301 const char *expand_prop;
11302 const char *expand_set_prop;
11304 GtkWidgetPrivate *priv;
11306 g_return_if_fail (GTK_IS_WIDGET (widget));
11308 priv = widget->priv;
11310 expand = expand != FALSE;
11312 was_both = priv->hexpand && priv->vexpand;
11314 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11316 if (priv->hexpand_set &&
11317 priv->hexpand == expand)
11320 priv->hexpand_set = TRUE;
11321 priv->hexpand = expand;
11323 expand_prop = "hexpand";
11324 expand_set_prop = "hexpand-set";
11328 if (priv->vexpand_set &&
11329 priv->vexpand == expand)
11332 priv->vexpand_set = TRUE;
11333 priv->vexpand = expand;
11335 expand_prop = "vexpand";
11336 expand_set_prop = "vexpand-set";
11339 gtk_widget_queue_compute_expand (widget);
11341 g_object_freeze_notify (G_OBJECT (widget));
11342 g_object_notify (G_OBJECT (widget), expand_prop);
11343 g_object_notify (G_OBJECT (widget), expand_set_prop);
11344 if (was_both != (priv->hexpand && priv->vexpand))
11345 g_object_notify (G_OBJECT (widget), "expand");
11346 g_object_thaw_notify (G_OBJECT (widget));
11350 gtk_widget_set_expand_set (GtkWidget *widget,
11351 GtkOrientation orientation,
11354 GtkWidgetPrivate *priv;
11357 priv = widget->priv;
11359 set = set != FALSE;
11361 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11363 if (set == priv->hexpand_set)
11366 priv->hexpand_set = set;
11367 prop = "hexpand-set";
11371 if (set == priv->vexpand_set)
11374 priv->vexpand_set = set;
11375 prop = "vexpand-set";
11378 gtk_widget_queue_compute_expand (widget);
11380 g_object_notify (G_OBJECT (widget), prop);
11384 * gtk_widget_get_hexpand:
11385 * @widget: the widget
11387 * Gets whether the widget would like any available extra horizontal
11388 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11389 * generally receive the extra space. For example, a list or
11390 * scrollable area or document in your window would often be set to
11393 * Containers should use gtk_widget_compute_expand() rather than
11394 * this function, to see whether a widget, or any of its children,
11395 * has the expand flag set. If any child of a widget wants to
11396 * expand, the parent may ask to expand also.
11398 * This function only looks at the widget's own hexpand flag, rather
11399 * than computing whether the entire widget tree rooted at this widget
11402 * Return value: whether hexpand flag is set
11405 gtk_widget_get_hexpand (GtkWidget *widget)
11407 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11409 return widget->priv->hexpand;
11413 * gtk_widget_set_hexpand:
11414 * @widget: the widget
11415 * @expand: whether to expand
11417 * Sets whether the widget would like any available extra horizontal
11418 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11419 * generally receive the extra space. For example, a list or
11420 * scrollable area or document in your window would often be set to
11423 * Call this function to set the expand flag if you would like your
11424 * widget to become larger horizontally when the window has extra
11427 * By default, widgets automatically expand if any of their children
11428 * want to expand. (To see if a widget will automatically expand given
11429 * its current children and state, call gtk_widget_compute_expand(). A
11430 * container can decide how the expandability of children affects the
11431 * expansion of the container by overriding the compute_expand virtual
11432 * method on #GtkWidget.).
11434 * Setting hexpand explicitly with this function will override the
11435 * automatic expand behavior.
11437 * This function forces the widget to expand or not to expand,
11438 * regardless of children. The override occurs because
11439 * gtk_widget_set_hexpand() sets the hexpand-set property (see
11440 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
11441 * value to be used, rather than looking at children and widget state.
11444 gtk_widget_set_hexpand (GtkWidget *widget,
11447 g_return_if_fail (GTK_IS_WIDGET (widget));
11449 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
11453 * gtk_widget_get_hexpand_set:
11454 * @widget: the widget
11456 * Gets whether gtk_widget_set_hexpand() has been used to
11457 * explicitly set the expand flag on this widget.
11459 * If hexpand is set, then it overrides any computed
11460 * expand value based on child widgets. If hexpand is not
11461 * set, then the expand value depends on whether any
11462 * children of the widget would like to expand.
11464 * There are few reasons to use this function, but it's here
11465 * for completeness and consistency.
11467 * Return value: whether hexpand has been explicitly set
11470 gtk_widget_get_hexpand_set (GtkWidget *widget)
11472 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11474 return widget->priv->hexpand_set;
11478 * gtk_widget_set_hexpand_set:
11479 * @widget: the widget
11480 * @set: value for hexpand-set property
11482 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
11485 * The hexpand-set property will be set automatically when you call
11486 * gtk_widget_set_hexpand() to set hexpand, so the most likely
11487 * reason to use this function would be to unset an explicit expand
11490 * If hexpand is set, then it overrides any computed
11491 * expand value based on child widgets. If hexpand is not
11492 * set, then the expand value depends on whether any
11493 * children of the widget would like to expand.
11495 * There are few reasons to use this function, but it's here
11496 * for completeness and consistency.
11498 * Return value: whether hexpand has been explicitly set
11501 gtk_widget_set_hexpand_set (GtkWidget *widget,
11504 g_return_if_fail (GTK_IS_WIDGET (widget));
11506 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
11511 * gtk_widget_get_vexpand:
11512 * @widget: the widget
11514 * Gets whether the widget would like any available extra vertical
11517 * See gtk_widget_get_hexpand() for more detail.
11519 * Return value: whether vexpand flag is set
11522 gtk_widget_get_vexpand (GtkWidget *widget)
11524 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11526 return widget->priv->vexpand;
11530 * gtk_widget_set_vexpand:
11531 * @widget: the widget
11532 * @expand: whether to expand
11534 * Sets whether the widget would like any available extra vertical
11537 * See gtk_widget_set_hexpand() for more detail.
11540 gtk_widget_set_vexpand (GtkWidget *widget,
11543 g_return_if_fail (GTK_IS_WIDGET (widget));
11545 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
11549 * gtk_widget_get_vexpand_set:
11550 * @widget: the widget
11552 * Gets whether gtk_widget_set_vexpand() has been used to
11553 * explicitly set the expand flag on this widget.
11555 * See gtk_widget_get_hexpand_set() for more detail.
11557 * Return value: whether vexpand has been explicitly set
11560 gtk_widget_get_vexpand_set (GtkWidget *widget)
11562 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11564 return widget->priv->vexpand_set;
11568 * gtk_widget_set_vexpand_set:
11569 * @widget: the widget
11570 * @set: value for vexpand-set property
11572 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
11575 * See gtk_widget_set_hexpand_set() for more detail.
11577 * Return value: whether vexpand has been explicitly set
11580 gtk_widget_set_vexpand_set (GtkWidget *widget,
11583 g_return_if_fail (GTK_IS_WIDGET (widget));
11585 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
11589 * GtkBuildable implementation
11591 static GQuark quark_builder_has_default = 0;
11592 static GQuark quark_builder_has_focus = 0;
11593 static GQuark quark_builder_atk_relations = 0;
11594 static GQuark quark_builder_set_name = 0;
11597 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
11599 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
11600 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
11601 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
11602 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
11604 iface->set_name = gtk_widget_buildable_set_name;
11605 iface->get_name = gtk_widget_buildable_get_name;
11606 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
11607 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
11608 iface->parser_finished = gtk_widget_buildable_parser_finished;
11609 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
11610 iface->custom_finished = gtk_widget_buildable_custom_finished;
11614 gtk_widget_buildable_set_name (GtkBuildable *buildable,
11617 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
11618 g_strdup (name), g_free);
11621 static const gchar *
11622 gtk_widget_buildable_get_name (GtkBuildable *buildable)
11624 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
11628 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
11629 GtkBuilder *builder,
11630 const gchar *childname)
11632 if (strcmp (childname, "accessible") == 0)
11633 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
11639 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
11640 GtkBuilder *builder,
11642 const GValue *value)
11644 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
11645 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
11646 GINT_TO_POINTER (TRUE));
11647 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
11648 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
11649 GINT_TO_POINTER (TRUE));
11651 g_object_set_property (G_OBJECT (buildable), name, value);
11656 gchar *action_name;
11657 GString *description;
11659 gboolean translatable;
11669 free_action (AtkActionData *data, gpointer user_data)
11671 g_free (data->action_name);
11672 g_string_free (data->description, TRUE);
11673 g_free (data->context);
11674 g_slice_free (AtkActionData, data);
11678 free_relation (AtkRelationData *data, gpointer user_data)
11680 g_free (data->target);
11681 g_free (data->type);
11682 g_slice_free (AtkRelationData, data);
11686 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
11687 GtkBuilder *builder)
11689 GSList *atk_relations;
11691 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
11692 gtk_widget_grab_default (GTK_WIDGET (buildable));
11693 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
11694 gtk_widget_grab_focus (GTK_WIDGET (buildable));
11696 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
11697 quark_builder_atk_relations);
11700 AtkObject *accessible;
11701 AtkRelationSet *relation_set;
11704 AtkRelationType relation_type;
11705 AtkObject *target_accessible;
11707 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11708 relation_set = atk_object_ref_relation_set (accessible);
11710 for (l = atk_relations; l; l = l->next)
11712 AtkRelationData *relation = (AtkRelationData*)l->data;
11714 target = gtk_builder_get_object (builder, relation->target);
11717 g_warning ("Target object %s in <relation> does not exist",
11721 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
11722 g_assert (target_accessible != NULL);
11724 relation_type = atk_relation_type_for_name (relation->type);
11725 if (relation_type == ATK_RELATION_NULL)
11727 g_warning ("<relation> type %s not found",
11731 atk_relation_set_add_relation_by_type (relation_set, relation_type,
11732 target_accessible);
11734 g_object_unref (relation_set);
11736 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
11737 g_slist_free (atk_relations);
11738 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
11747 } AccessibilitySubParserData;
11750 accessibility_start_element (GMarkupParseContext *context,
11751 const gchar *element_name,
11752 const gchar **names,
11753 const gchar **values,
11754 gpointer user_data,
11757 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
11759 gint line_number, char_number;
11761 if (strcmp (element_name, "relation") == 0)
11763 gchar *target = NULL;
11764 gchar *type = NULL;
11765 AtkRelationData *relation;
11767 for (i = 0; names[i]; i++)
11769 if (strcmp (names[i], "target") == 0)
11770 target = g_strdup (values[i]);
11771 else if (strcmp (names[i], "type") == 0)
11772 type = g_strdup (values[i]);
11775 g_markup_parse_context_get_position (context,
11778 g_set_error (error,
11780 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
11781 "%s:%d:%d '%s' is not a valid attribute of <%s>",
11783 line_number, char_number, names[i], "relation");
11790 if (!target || !type)
11792 g_markup_parse_context_get_position (context,
11795 g_set_error (error,
11797 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
11798 "%s:%d:%d <%s> requires attribute \"%s\"",
11800 line_number, char_number, "relation",
11801 type ? "target" : "type");
11807 relation = g_slice_new (AtkRelationData);
11808 relation->target = target;
11809 relation->type = type;
11811 data->relations = g_slist_prepend (data->relations, relation);
11813 else if (strcmp (element_name, "action") == 0)
11815 const gchar *action_name = NULL;
11816 const gchar *description = NULL;
11817 const gchar *msg_context = NULL;
11818 gboolean translatable = FALSE;
11819 AtkActionData *action;
11821 for (i = 0; names[i]; i++)
11823 if (strcmp (names[i], "action_name") == 0)
11824 action_name = values[i];
11825 else if (strcmp (names[i], "description") == 0)
11826 description = values[i];
11827 else if (strcmp (names[i], "translatable") == 0)
11829 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
11832 else if (strcmp (names[i], "comments") == 0)
11834 /* do nothing, comments are for translators */
11836 else if (strcmp (names[i], "context") == 0)
11837 msg_context = values[i];
11840 g_markup_parse_context_get_position (context,
11843 g_set_error (error,
11845 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
11846 "%s:%d:%d '%s' is not a valid attribute of <%s>",
11848 line_number, char_number, names[i], "action");
11855 g_markup_parse_context_get_position (context,
11858 g_set_error (error,
11860 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
11861 "%s:%d:%d <%s> requires attribute \"%s\"",
11863 line_number, char_number, "action",
11868 action = g_slice_new (AtkActionData);
11869 action->action_name = g_strdup (action_name);
11870 action->description = g_string_new (description);
11871 action->context = g_strdup (msg_context);
11872 action->translatable = translatable;
11874 data->actions = g_slist_prepend (data->actions, action);
11876 else if (strcmp (element_name, "accessibility") == 0)
11879 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
11883 accessibility_text (GMarkupParseContext *context,
11886 gpointer user_data,
11889 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
11891 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
11893 AtkActionData *action = data->actions->data;
11895 g_string_append_len (action->description, text, text_len);
11899 static const GMarkupParser accessibility_parser =
11901 accessibility_start_element,
11903 accessibility_text,
11912 } AccelGroupParserData;
11915 accel_group_start_element (GMarkupParseContext *context,
11916 const gchar *element_name,
11917 const gchar **names,
11918 const gchar **values,
11919 gpointer user_data,
11924 guint modifiers = 0;
11925 gchar *signal = NULL;
11926 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
11928 for (i = 0; names[i]; i++)
11930 if (strcmp (names[i], "key") == 0)
11931 key = gdk_keyval_from_name (values[i]);
11932 else if (strcmp (names[i], "modifiers") == 0)
11934 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
11940 else if (strcmp (names[i], "signal") == 0)
11941 signal = g_strdup (values[i]);
11944 if (key == 0 || signal == NULL)
11946 g_warning ("<accelerator> requires key and signal attributes");
11949 parser_data->key = key;
11950 parser_data->modifiers = modifiers;
11951 parser_data->signal = signal;
11954 static const GMarkupParser accel_group_parser =
11956 accel_group_start_element,
11960 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
11961 GtkBuilder *builder,
11963 const gchar *tagname,
11964 GMarkupParser *parser,
11967 g_assert (buildable);
11969 if (strcmp (tagname, "accelerator") == 0)
11971 AccelGroupParserData *parser_data;
11973 parser_data = g_slice_new0 (AccelGroupParserData);
11974 parser_data->object = g_object_ref (buildable);
11975 *parser = accel_group_parser;
11976 *data = parser_data;
11979 if (strcmp (tagname, "accessibility") == 0)
11981 AccessibilitySubParserData *parser_data;
11983 parser_data = g_slice_new0 (AccessibilitySubParserData);
11984 *parser = accessibility_parser;
11985 *data = parser_data;
11992 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
11993 GtkWidget *toplevel,
11994 gpointer user_data)
11996 AccelGroupParserData *accel_data;
11997 GSList *accel_groups;
11998 GtkAccelGroup *accel_group;
12000 g_return_if_fail (GTK_IS_WIDGET (widget));
12001 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12002 g_return_if_fail (user_data != NULL);
12004 accel_data = (AccelGroupParserData*)user_data;
12005 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12006 if (g_slist_length (accel_groups) == 0)
12008 accel_group = gtk_accel_group_new ();
12009 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12013 g_assert (g_slist_length (accel_groups) == 1);
12014 accel_group = g_slist_nth_data (accel_groups, 0);
12017 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12018 accel_data->signal,
12021 accel_data->modifiers,
12022 GTK_ACCEL_VISIBLE);
12024 g_object_unref (accel_data->object);
12025 g_free (accel_data->signal);
12026 g_slice_free (AccelGroupParserData, accel_data);
12030 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12031 GtkBuilder *builder,
12033 const gchar *tagname,
12034 gpointer user_data)
12036 AccelGroupParserData *accel_data;
12037 AccessibilitySubParserData *a11y_data;
12038 GtkWidget *toplevel;
12040 if (strcmp (tagname, "accelerator") == 0)
12042 accel_data = (AccelGroupParserData*)user_data;
12043 g_assert (accel_data->object);
12045 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12047 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12049 else if (strcmp (tagname, "accessibility") == 0)
12051 a11y_data = (AccessibilitySubParserData*)user_data;
12053 if (a11y_data->actions)
12055 AtkObject *accessible;
12060 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12062 action = ATK_ACTION (accessible);
12063 n_actions = atk_action_get_n_actions (action);
12065 for (l = a11y_data->actions; l; l = l->next)
12067 AtkActionData *action_data = (AtkActionData*)l->data;
12069 for (i = 0; i < n_actions; i++)
12070 if (strcmp (atk_action_get_name (action, i),
12071 action_data->action_name) == 0)
12076 gchar *description;
12078 if (action_data->translatable && action_data->description->len)
12079 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12080 action_data->context,
12081 action_data->description->str);
12083 description = action_data->description->str;
12085 atk_action_set_description (action, i, description);
12089 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
12090 g_slist_free (a11y_data->actions);
12093 if (a11y_data->relations)
12094 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12095 a11y_data->relations);
12097 g_slice_free (AccessibilitySubParserData, a11y_data);
12102 gtk_widget_real_get_width (GtkWidget *widget,
12103 gint *minimum_size,
12104 gint *natural_size)
12114 gtk_widget_real_get_height (GtkWidget *widget,
12115 gint *minimum_size,
12116 gint *natural_size)
12126 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12128 gint *minimum_height,
12129 gint *natural_height)
12131 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12135 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12137 gint *minimum_width,
12138 gint *natural_width)
12140 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12144 * gtk_widget_get_halign:
12145 * @widget: a #GtkWidget
12147 * Gets the value of the #GtkWidget:halign property.
12149 * Returns: the horizontal alignment of @widget
12152 gtk_widget_get_halign (GtkWidget *widget)
12154 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12155 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12159 * gtk_widget_set_halign:
12160 * @widget: a #GtkWidget
12161 * @align: the horizontal alignment
12163 * Sets the horizontal alignment of @widget.
12164 * See the #GtkWidget:halign property.
12167 gtk_widget_set_halign (GtkWidget *widget,
12170 GtkWidgetAuxInfo *aux_info;
12172 g_return_if_fail (GTK_IS_WIDGET (widget));
12174 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12176 if (aux_info->halign == align)
12179 aux_info->halign = align;
12180 gtk_widget_queue_resize (widget);
12181 g_object_notify (G_OBJECT (widget), "halign");
12185 * gtk_widget_get_valign:
12186 * @widget: a #GtkWidget
12188 * Gets the value of the #GtkWidget:valign property.
12190 * Returns: the vertical alignment of @widget
12193 gtk_widget_get_valign (GtkWidget *widget)
12195 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12196 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12200 * gtk_widget_set_valign:
12201 * @widget: a #GtkWidget
12202 * @align: the vertical alignment
12204 * Sets the vertical alignment of @widget.
12205 * See the #GtkWidget:valign property.
12208 gtk_widget_set_valign (GtkWidget *widget,
12211 GtkWidgetAuxInfo *aux_info;
12213 g_return_if_fail (GTK_IS_WIDGET (widget));
12215 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12217 if (aux_info->valign == align)
12220 aux_info->valign = align;
12221 gtk_widget_queue_resize (widget);
12222 g_object_notify (G_OBJECT (widget), "valign");
12226 * gtk_widget_get_margin_left:
12227 * @widget: a #GtkWidget
12229 * Gets the value of the #GtkWidget:margin-left property.
12231 * Returns: The left margin of @widget
12234 gtk_widget_get_margin_left (GtkWidget *widget)
12236 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12238 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12242 * gtk_widget_set_margin_left:
12243 * @widget: a #GtkWidget
12244 * @margin: the left margin
12246 * Sets the left margin of @widget.
12247 * See the #GtkWidget:margin-left property.
12250 gtk_widget_set_margin_left (GtkWidget *widget,
12253 GtkWidgetAuxInfo *aux_info;
12255 g_return_if_fail (GTK_IS_WIDGET (widget));
12256 g_return_if_fail (margin <= G_MAXINT16);
12258 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12260 if (aux_info->margin.left == margin)
12263 aux_info->margin.left = margin;
12264 gtk_widget_queue_resize (widget);
12265 g_object_notify (G_OBJECT (widget), "margin-left");
12269 * gtk_widget_get_margin_right:
12270 * @widget: a #GtkWidget
12272 * Gets the value of the #GtkWidget:margin-right property.
12274 * Returns: The left margin of @widget
12277 gtk_widget_get_margin_right (GtkWidget *widget)
12279 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12281 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12285 * gtk_widget_set_margin_right:
12286 * @widget: a #GtkWidget
12287 * @margin: the right margin
12289 * Sets the right margin of @widget.
12290 * See the #GtkWidget:margin-right property.
12293 gtk_widget_set_margin_right (GtkWidget *widget,
12296 GtkWidgetAuxInfo *aux_info;
12298 g_return_if_fail (GTK_IS_WIDGET (widget));
12299 g_return_if_fail (margin <= G_MAXINT16);
12301 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12303 if (aux_info->margin.right == margin)
12306 aux_info->margin.right = margin;
12307 gtk_widget_queue_resize (widget);
12308 g_object_notify (G_OBJECT (widget), "margin-right");
12312 * gtk_widget_get_margin_top:
12313 * @widget: a #GtkWidget
12315 * Gets the value of the #GtkWidget:margin-top property.
12317 * Returns: The top margin of @widget
12320 gtk_widget_get_margin_top (GtkWidget *widget)
12322 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12324 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12328 * gtk_widget_set_margin_top:
12329 * @widget: a #GtkWidget
12330 * @margin: the top margin
12332 * Sets the top margin of @widget.
12333 * See the #GtkWidget:margin-top property.
12336 gtk_widget_set_margin_top (GtkWidget *widget,
12339 GtkWidgetAuxInfo *aux_info;
12341 g_return_if_fail (GTK_IS_WIDGET (widget));
12342 g_return_if_fail (margin <= G_MAXINT16);
12344 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12346 if (aux_info->margin.top == margin)
12349 aux_info->margin.top = margin;
12350 gtk_widget_queue_resize (widget);
12351 g_object_notify (G_OBJECT (widget), "margin-top");
12355 * gtk_widget_get_margin_bottom:
12356 * @widget: a #GtkWidget
12358 * Gets the value of the #GtkWidget:margin-bottom property.
12360 * Returns: The bottom margin of @widget
12363 gtk_widget_get_margin_bottom (GtkWidget *widget)
12365 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12367 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
12371 * gtk_widget_set_margin_bottom:
12372 * @widget: a #GtkWidget
12373 * @margin: the bottom margin
12375 * Sets the bottom margin of @widget.
12376 * See the #GtkWidget:margin-bottom property.
12379 gtk_widget_set_margin_bottom (GtkWidget *widget,
12382 GtkWidgetAuxInfo *aux_info;
12384 g_return_if_fail (GTK_IS_WIDGET (widget));
12385 g_return_if_fail (margin <= G_MAXINT16);
12387 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12389 if (aux_info->margin.bottom == margin)
12392 aux_info->margin.bottom = margin;
12393 gtk_widget_queue_resize (widget);
12394 g_object_notify (G_OBJECT (widget), "margin-bottom");
12398 * gtk_widget_get_clipboard:
12399 * @widget: a #GtkWidget
12400 * @selection: a #GdkAtom which identifies the clipboard
12401 * to use. %GDK_SELECTION_CLIPBOARD gives the
12402 * default clipboard. Another common value
12403 * is %GDK_SELECTION_PRIMARY, which gives
12404 * the primary X selection.
12406 * Returns the clipboard object for the given selection to
12407 * be used with @widget. @widget must have a #GdkDisplay
12408 * associated with it, so must be attached to a toplevel
12411 * Return value: (transfer none): the appropriate clipboard object. If no
12412 * clipboard already exists, a new one will
12413 * be created. Once a clipboard object has
12414 * been created, it is persistent for all time.
12419 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
12421 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12422 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
12424 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
12429 * gtk_widget_list_mnemonic_labels:
12430 * @widget: a #GtkWidget
12432 * Returns a newly allocated list of the widgets, normally labels, for
12433 * which this widget is the target of a mnemonic (see for example,
12434 * gtk_label_set_mnemonic_widget()).
12436 * The widgets in the list are not individually referenced. If you
12437 * want to iterate through the list and perform actions involving
12438 * callbacks that might destroy the widgets, you
12439 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
12440 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
12441 * widgets afterwards.
12443 * Return value: (element-type GtkWidget) (transfer container): the list of
12444 * mnemonic labels; free this list
12445 * with g_list_free() when you are done with it.
12450 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
12452 GList *list = NULL;
12455 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12457 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
12458 list = g_list_prepend (list, l->data);
12464 * gtk_widget_add_mnemonic_label:
12465 * @widget: a #GtkWidget
12466 * @label: a #GtkWidget that acts as a mnemonic label for @widget
12468 * Adds a widget to the list of mnemonic labels for
12469 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
12470 * list of mnemonic labels for the widget is cleared when the
12471 * widget is destroyed, so the caller must make sure to update
12472 * its internal state at this point as well, by using a connection
12473 * to the #GtkWidget::destroy signal or a weak notifier.
12478 gtk_widget_add_mnemonic_label (GtkWidget *widget,
12481 GSList *old_list, *new_list;
12483 g_return_if_fail (GTK_IS_WIDGET (widget));
12484 g_return_if_fail (GTK_IS_WIDGET (label));
12486 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12487 new_list = g_slist_prepend (old_list, label);
12489 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12490 new_list, (GDestroyNotify) g_slist_free);
12494 * gtk_widget_remove_mnemonic_label:
12495 * @widget: a #GtkWidget
12496 * @label: a #GtkWidget that was previously set as a mnemnic label for
12497 * @widget with gtk_widget_add_mnemonic_label().
12499 * Removes a widget from the list of mnemonic labels for
12500 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
12501 * must have previously been added to the list with
12502 * gtk_widget_add_mnemonic_label().
12507 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
12510 GSList *old_list, *new_list;
12512 g_return_if_fail (GTK_IS_WIDGET (widget));
12513 g_return_if_fail (GTK_IS_WIDGET (label));
12515 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12516 new_list = g_slist_remove (old_list, label);
12519 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12520 new_list, (GDestroyNotify) g_slist_free);
12524 * gtk_widget_get_no_show_all:
12525 * @widget: a #GtkWidget
12527 * Returns the current value of the #GtkWidget:no-show-all property,
12528 * which determines whether calls to gtk_widget_show_all()
12529 * will affect this widget.
12531 * Return value: the current value of the "no-show-all" property.
12536 gtk_widget_get_no_show_all (GtkWidget *widget)
12538 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12540 return widget->priv->no_show_all;
12544 * gtk_widget_set_no_show_all:
12545 * @widget: a #GtkWidget
12546 * @no_show_all: the new value for the "no-show-all" property
12548 * Sets the #GtkWidget:no-show-all property, which determines whether
12549 * calls to gtk_widget_show_all() will affect this widget.
12551 * This is mostly for use in constructing widget hierarchies with externally
12552 * controlled visibility, see #GtkUIManager.
12557 gtk_widget_set_no_show_all (GtkWidget *widget,
12558 gboolean no_show_all)
12560 g_return_if_fail (GTK_IS_WIDGET (widget));
12562 no_show_all = (no_show_all != FALSE);
12564 if (widget->priv->no_show_all != no_show_all)
12566 widget->priv->no_show_all = no_show_all;
12568 g_object_notify (G_OBJECT (widget), "no-show-all");
12574 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
12575 gboolean has_tooltip,
12578 GtkWidgetPrivate *priv = widget->priv;
12579 gboolean priv_has_tooltip;
12581 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
12582 quark_has_tooltip));
12584 if (priv_has_tooltip != has_tooltip || force)
12586 priv_has_tooltip = has_tooltip;
12588 if (priv_has_tooltip)
12590 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
12591 gdk_window_set_events (priv->window,
12592 gdk_window_get_events (priv->window) |
12593 GDK_LEAVE_NOTIFY_MASK |
12594 GDK_POINTER_MOTION_MASK |
12595 GDK_POINTER_MOTION_HINT_MASK);
12597 if (gtk_widget_get_has_window (widget))
12598 gtk_widget_add_events (widget,
12599 GDK_LEAVE_NOTIFY_MASK |
12600 GDK_POINTER_MOTION_MASK |
12601 GDK_POINTER_MOTION_HINT_MASK);
12604 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
12605 GUINT_TO_POINTER (priv_has_tooltip));
12610 * gtk_widget_set_tooltip_window:
12611 * @widget: a #GtkWidget
12612 * @custom_window: (allow-none): a #GtkWindow, or %NULL
12614 * Replaces the default, usually yellow, window used for displaying
12615 * tooltips with @custom_window. GTK+ will take care of showing and
12616 * hiding @custom_window at the right moment, to behave likewise as
12617 * the default tooltip window. If @custom_window is %NULL, the default
12618 * tooltip window will be used.
12620 * If the custom window should have the default theming it needs to
12621 * have the name "gtk-tooltip", see gtk_widget_set_name().
12626 gtk_widget_set_tooltip_window (GtkWidget *widget,
12627 GtkWindow *custom_window)
12629 gboolean has_tooltip;
12630 gchar *tooltip_markup;
12632 g_return_if_fail (GTK_IS_WIDGET (widget));
12633 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
12635 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
12638 g_object_ref (custom_window);
12640 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
12641 custom_window, g_object_unref);
12643 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
12644 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
12646 if (has_tooltip && gtk_widget_get_visible (widget))
12647 gtk_widget_queue_tooltip_query (widget);
12651 * gtk_widget_get_tooltip_window:
12652 * @widget: a #GtkWidget
12654 * Returns the #GtkWindow of the current tooltip. This can be the
12655 * GtkWindow created by default, or the custom tooltip window set
12656 * using gtk_widget_set_tooltip_window().
12658 * Return value: (transfer none): The #GtkWindow of the current tooltip.
12663 gtk_widget_get_tooltip_window (GtkWidget *widget)
12665 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12667 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
12671 * gtk_widget_trigger_tooltip_query:
12672 * @widget: a #GtkWidget
12674 * Triggers a tooltip query on the display where the toplevel of @widget
12675 * is located. See gtk_tooltip_trigger_tooltip_query() for more
12681 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
12683 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
12686 static guint tooltip_query_id;
12687 static GSList *tooltip_query_displays;
12690 tooltip_query_idle (gpointer data)
12692 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
12693 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
12694 g_slist_free (tooltip_query_displays);
12696 tooltip_query_displays = NULL;
12697 tooltip_query_id = 0;
12703 gtk_widget_queue_tooltip_query (GtkWidget *widget)
12705 GdkDisplay *display;
12707 display = gtk_widget_get_display (widget);
12709 if (!g_slist_find (tooltip_query_displays, display))
12710 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
12712 if (tooltip_query_id == 0)
12713 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
12717 * gtk_widget_set_tooltip_text:
12718 * @widget: a #GtkWidget
12719 * @text: the contents of the tooltip for @widget
12721 * Sets @text as the contents of the tooltip. This function will take
12722 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
12723 * handler for the #GtkWidget::query-tooltip signal.
12725 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
12730 gtk_widget_set_tooltip_text (GtkWidget *widget,
12733 g_return_if_fail (GTK_IS_WIDGET (widget));
12735 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
12739 * gtk_widget_get_tooltip_text:
12740 * @widget: a #GtkWidget
12742 * Gets the contents of the tooltip for @widget.
12744 * Return value: the tooltip text, or %NULL. You should free the
12745 * returned string with g_free() when done.
12750 gtk_widget_get_tooltip_text (GtkWidget *widget)
12752 gchar *text = NULL;
12754 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12756 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
12762 * gtk_widget_set_tooltip_markup:
12763 * @widget: a #GtkWidget
12764 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
12766 * Sets @markup as the contents of the tooltip, which is marked up with
12767 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
12769 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
12770 * and of the default handler for the #GtkWidget::query-tooltip signal.
12772 * See also the #GtkWidget:tooltip-markup property and
12773 * gtk_tooltip_set_markup().
12778 gtk_widget_set_tooltip_markup (GtkWidget *widget,
12779 const gchar *markup)
12781 g_return_if_fail (GTK_IS_WIDGET (widget));
12783 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
12787 * gtk_widget_get_tooltip_markup:
12788 * @widget: a #GtkWidget
12790 * Gets the contents of the tooltip for @widget.
12792 * Return value: the tooltip text, or %NULL. You should free the
12793 * returned string with g_free() when done.
12798 gtk_widget_get_tooltip_markup (GtkWidget *widget)
12800 gchar *text = NULL;
12802 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12804 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
12810 * gtk_widget_set_has_tooltip:
12811 * @widget: a #GtkWidget
12812 * @has_tooltip: whether or not @widget has a tooltip.
12814 * Sets the has-tooltip property on @widget to @has_tooltip. See
12815 * #GtkWidget:has-tooltip for more information.
12820 gtk_widget_set_has_tooltip (GtkWidget *widget,
12821 gboolean has_tooltip)
12823 g_return_if_fail (GTK_IS_WIDGET (widget));
12825 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
12829 * gtk_widget_get_has_tooltip:
12830 * @widget: a #GtkWidget
12832 * Returns the current value of the has-tooltip property. See
12833 * #GtkWidget:has-tooltip for more information.
12835 * Return value: current value of has-tooltip on @widget.
12840 gtk_widget_get_has_tooltip (GtkWidget *widget)
12842 gboolean has_tooltip = FALSE;
12844 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12846 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
12848 return has_tooltip;
12852 * gtk_widget_get_allocation:
12853 * @widget: a #GtkWidget
12854 * @allocation: (out): a pointer to a #GtkAllocation to copy to
12856 * Retrieves the widget's allocation.
12858 * Note, when implementing a #GtkContainer: a widget's allocation will
12859 * be its "adjusted" allocation, that is, the widget's parent
12860 * container typically calls gtk_widget_size_allocate() with an
12861 * allocation, and that allocation is then adjusted (to handle margin
12862 * and alignment for example) before assignment to the widget.
12863 * gtk_widget_get_allocation() returns the adjusted allocation that
12864 * was actually assigned to the widget. The adjusted allocation is
12865 * guaranteed to be completely contained within the
12866 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
12867 * is guaranteed that its children stay inside the assigned bounds,
12868 * but not that they have exactly the bounds the container assigned.
12869 * There is no way to get the original allocation assigned by
12870 * gtk_widget_size_allocate(), since it isn't stored; if a container
12871 * implementation needs that information it will have to track it itself.
12876 gtk_widget_get_allocation (GtkWidget *widget,
12877 GtkAllocation *allocation)
12879 GtkWidgetPrivate *priv;
12881 g_return_if_fail (GTK_IS_WIDGET (widget));
12882 g_return_if_fail (allocation != NULL);
12884 priv = widget->priv;
12886 *allocation = priv->allocation;
12890 * gtk_widget_set_allocation:
12891 * @widget: a #GtkWidget
12892 * @allocation: a pointer to a #GtkAllocation to copy from
12894 * Sets the widget's allocation. This should not be used
12895 * directly, but from within a widget's size_allocate method.
12897 * The allocation set should be the "adjusted" or actual
12898 * allocation. If you're implementing a #GtkContainer, you want to use
12899 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
12900 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
12901 * allocation inside gtk_widget_size_allocate() to create an adjusted
12907 gtk_widget_set_allocation (GtkWidget *widget,
12908 const GtkAllocation *allocation)
12910 GtkWidgetPrivate *priv;
12912 g_return_if_fail (GTK_IS_WIDGET (widget));
12913 g_return_if_fail (allocation != NULL);
12915 priv = widget->priv;
12917 priv->allocation = *allocation;
12921 * gtk_widget_get_allocated_width:
12922 * @widget: the widget to query
12924 * Returns the width that has currently been allocated to @widget.
12925 * This function is intended to be used when implementing handlers
12926 * for the #GtkWidget::draw function.
12928 * Returns: the width of the @widget
12931 gtk_widget_get_allocated_width (GtkWidget *widget)
12933 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12935 return widget->priv->allocation.width;
12939 * gtk_widget_get_allocated_height:
12940 * @widget: the widget to query
12942 * Returns the height that has currently been allocated to @widget.
12943 * This function is intended to be used when implementing handlers
12944 * for the #GtkWidget::draw function.
12946 * Returns: the height of the @widget
12949 gtk_widget_get_allocated_height (GtkWidget *widget)
12951 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12953 return widget->priv->allocation.height;
12957 * gtk_widget_get_requisition:
12958 * @widget: a #GtkWidget
12959 * @requisition: (out): a pointer to a #GtkRequisition to copy to
12961 * Retrieves the widget's requisition.
12963 * This function should only be used by widget implementations in
12964 * order to figure whether the widget's requisition has actually
12965 * changed after some internal state change (so that they can call
12966 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
12968 * Normally, gtk_widget_size_request() should be used.
12972 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
12973 * removed, If you need to cache sizes across requests and allocations,
12974 * add an explicit cache to the widget in question instead.
12977 gtk_widget_get_requisition (GtkWidget *widget,
12978 GtkRequisition *requisition)
12980 g_return_if_fail (GTK_IS_WIDGET (widget));
12981 g_return_if_fail (requisition != NULL);
12983 gtk_widget_get_preferred_size (widget, requisition, NULL);
12987 * gtk_widget_set_window:
12988 * @widget: a #GtkWidget
12989 * @window: a #GdkWindow
12991 * Sets a widget's window. This function should only be used in a
12992 * widget's #GtkWidget::realize implementation. The %window passed is
12993 * usually either new window created with gdk_window_new(), or the
12994 * window of its parent widget as returned by
12995 * gtk_widget_get_parent_window().
12997 * Widgets must indicate whether they will create their own #GdkWindow
12998 * by calling gtk_widget_set_has_window(). This is usually done in the
12999 * widget's init() function.
13001 * <note><para>This function does not add any reference to @window.</para></note>
13006 gtk_widget_set_window (GtkWidget *widget,
13009 GtkWidgetPrivate *priv;
13011 g_return_if_fail (GTK_IS_WIDGET (widget));
13012 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13014 priv = widget->priv;
13016 if (priv->window != window)
13018 priv->window = window;
13019 g_object_notify (G_OBJECT (widget), "window");
13024 * gtk_widget_get_window:
13025 * @widget: a #GtkWidget
13027 * Returns the widget's window if it is realized, %NULL otherwise
13029 * Return value: (transfer none): @widget's window.
13034 gtk_widget_get_window (GtkWidget *widget)
13036 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13038 return widget->priv->window;
13042 * gtk_widget_get_support_multidevice:
13043 * @widget: a #GtkWidget
13045 * Returns %TRUE if @widget is multiple pointer aware. See
13046 * gtk_widget_set_support_multidevice() for more information.
13048 * Returns: %TRUE is @widget is multidevice aware.
13051 gtk_widget_get_support_multidevice (GtkWidget *widget)
13053 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13055 return widget->priv->multidevice;
13059 * gtk_widget_set_support_multidevice:
13060 * @widget: a #GtkWidget
13061 * @support_multidevice: %TRUE to support input from multiple devices.
13063 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13064 * @widget will start receiving multiple, per device enter/leave events. Note
13065 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13066 * gdk_window_set_support_multidevice() will have to be called manually on them.
13071 gtk_widget_set_support_multidevice (GtkWidget *widget,
13072 gboolean support_multidevice)
13074 GtkWidgetPrivate *priv;
13076 g_return_if_fail (GTK_IS_WIDGET (widget));
13078 priv = widget->priv;
13080 if (support_multidevice)
13082 priv->multidevice = TRUE;
13083 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
13087 priv->multidevice = FALSE;
13088 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
13091 if (gtk_widget_get_realized (widget))
13092 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13096 _gtk_widget_set_has_focus (GtkWidget *widget,
13097 gboolean has_focus)
13099 widget->priv->has_focus = has_focus;
13103 * gtk_widget_send_focus_change:
13104 * @widget: a #GtkWidget
13105 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13107 * Sends the focus change @event to @widget
13109 * This function is not meant to be used by applications. The only time it
13110 * should be used is when it is necessary for a #GtkWidget to assign focus
13111 * to a widget that is semantically owned by the first widget even though
13112 * it's not a direct child - for instance, a search entry in a floating
13113 * window similar to the quick search in #GtkTreeView.
13115 * An example of its usage is:
13118 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13120 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13121 * fevent->focus_change.in = TRUE;
13122 * fevent->focus_change.window = gtk_widget_get_window (widget);
13123 * if (fevent->focus_change.window != NULL)
13124 * g_object_ref (fevent->focus_change.window);
13126 * gtk_widget_send_focus_change (widget, fevent);
13128 * gdk_event_free (event);
13131 * Return value: the return value from the event signal emission: %TRUE
13132 * if the event was handled, and %FALSE otherwise
13137 gtk_widget_send_focus_change (GtkWidget *widget,
13142 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13143 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13145 g_object_ref (widget);
13147 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13149 res = gtk_widget_event (widget, event);
13151 g_object_notify (G_OBJECT (widget), "has-focus");
13153 g_object_unref (widget);
13159 * gtk_widget_in_destruction:
13160 * @widget: a #GtkWidget
13162 * Returns whether the widget is currently being destroyed.
13163 * This information can sometimes be used to avoid doing
13164 * unnecessary work.
13166 * Returns: %TRUE if @widget is being destroyed
13169 gtk_widget_in_destruction (GtkWidget *widget)
13171 return widget->priv->in_destruction;
13175 _gtk_widget_get_resize_pending (GtkWidget *widget)
13177 return widget->priv->resize_pending;
13181 _gtk_widget_set_resize_pending (GtkWidget *widget,
13182 gboolean resize_pending)
13184 widget->priv->resize_pending = resize_pending;
13188 _gtk_widget_get_in_reparent (GtkWidget *widget)
13190 return widget->priv->in_reparent;
13194 _gtk_widget_set_in_reparent (GtkWidget *widget,
13195 gboolean in_reparent)
13197 widget->priv->in_reparent = in_reparent;
13201 _gtk_widget_get_anchored (GtkWidget *widget)
13203 return widget->priv->anchored;
13207 _gtk_widget_set_anchored (GtkWidget *widget,
13210 widget->priv->anchored = anchored;
13214 _gtk_widget_get_shadowed (GtkWidget *widget)
13216 return widget->priv->shadowed;
13220 _gtk_widget_set_shadowed (GtkWidget *widget,
13223 widget->priv->shadowed = shadowed;
13227 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13229 return widget->priv->alloc_needed;
13233 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13234 gboolean alloc_needed)
13236 widget->priv->alloc_needed = alloc_needed;
13240 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13242 return widget->priv->width_request_needed;
13246 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13247 gboolean width_request_needed)
13249 widget->priv->width_request_needed = width_request_needed;
13253 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13255 return widget->priv->height_request_needed;
13259 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13260 gboolean height_request_needed)
13262 widget->priv->height_request_needed = height_request_needed;
13266 gtk_widget_get_path (GtkWidget *widget)
13268 GtkStyleContext *context;
13269 GtkWidgetPath *path;
13272 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13274 parent = widget->priv->parent;
13276 path = gtk_widget_path_new ();
13277 gtk_widget_path_prepend_type (path, G_OBJECT_TYPE (widget));
13279 if (widget->priv->name)
13280 gtk_widget_path_iter_set_name (path, 0, widget->priv->name);
13282 context = g_object_get_qdata (G_OBJECT (widget),
13283 quark_style_context);
13289 list = l = gtk_style_context_list_regions (context);
13293 GtkRegionFlags flags;
13294 const gchar *region_name;
13296 region_name = l->data;
13299 gtk_style_context_has_region (context, region_name, &flags);
13300 gtk_widget_path_iter_add_region (path, 0, region_name, flags);
13303 g_list_free (list);
13305 list = l = gtk_style_context_list_classes (context);
13309 const gchar *class_name;
13311 class_name = l->data;
13314 gtk_widget_path_iter_add_class (path, 0, class_name);
13317 g_list_free (list);
13324 position = gtk_widget_path_prepend_type (path, G_OBJECT_TYPE (parent));
13326 if (parent->priv->name)
13327 gtk_widget_path_iter_set_name (path, position, parent->priv->name);
13329 parent = parent->priv->parent;
13336 style_context_changed (GtkStyleContext *context,
13337 gpointer user_data)
13339 GtkWidget *widget = user_data;
13341 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
13345 gtk_widget_get_style_context (GtkWidget *widget)
13347 GtkStyleContext *context;
13349 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13351 context = g_object_get_qdata (G_OBJECT (widget),
13352 quark_style_context);
13354 if (G_UNLIKELY (!context))
13356 GtkWidgetPath *path;
13358 context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
13359 "direction", gtk_widget_get_direction (widget),
13362 g_signal_connect (context, "changed",
13363 G_CALLBACK (style_context_changed), widget);
13365 g_object_set_qdata_full (G_OBJECT (widget),
13366 quark_style_context, context,
13367 (GDestroyNotify) g_object_unref);
13369 gtk_style_context_set_screen (context,
13370 gtk_widget_get_screen (widget));
13372 path = gtk_widget_get_path (widget);
13373 gtk_style_context_set_path (context, path);
13374 gtk_widget_path_free (path);