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/.
31 #include "gtkcontainer.h"
32 #include "gtkaccelmap.h"
33 #include "gtkclipboard.h"
34 #include "gtkiconfactory.h"
37 #include "gtkmarshalers.h"
39 #include "gtkselection.h"
40 #include "gtksettings.h"
41 #include "gtksizegroup-private.h"
42 #include "gtkwidget.h"
43 #include "gtkwidgetprivate.h"
44 #include "gtkwindowprivate.h"
45 #include "gtkbindings.h"
46 #include "gtkprivate.h"
48 #include <gobject/gvaluecollector.h>
49 #include <gobject/gobjectnotifyqueue.c>
50 #include <cairo-gobject.h>
51 #include "gdk/gdkkeysyms.h"
52 #include "gtkaccessible.h"
53 #include "gtktooltip.h"
54 #include "gtkinvisible.h"
55 #include "gtkbuildable.h"
56 #include "gtkbuilderprivate.h"
57 #include "gtksizerequest.h"
58 #include "gtkstylecontext.h"
59 #include "gtksymboliccolor.h"
60 #include "gtkcssprovider.h"
61 #include "gtkanimationdescription.h"
62 #include "gtkmodifierstyle.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")
293 guint state_flags : 6;
297 guint in_destruction : 1;
300 guint composite_child : 1;
306 guint parent_sensitive : 1;
309 guint can_default : 1;
310 guint has_default : 1;
311 guint receives_default : 1;
315 guint user_style : 1;
316 guint app_paintable : 1;
317 guint double_buffered : 1;
318 guint redraw_on_alloc : 1;
319 guint no_show_all : 1;
320 guint child_visible : 1;
321 guint multidevice : 1;
322 guint has_shape_mask : 1;
323 guint in_reparent : 1;
324 guint resize_pending : 1;
325 guint alloc_needed : 1;
326 guint width_request_needed : 1;
327 guint height_request_needed : 1;
329 /* Expand-related flags */
330 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
331 guint computed_hexpand : 1; /* computed results (composite of child flags) */
332 guint computed_vexpand : 1;
333 guint hexpand : 1; /* application-forced expand */
335 guint hexpand_set : 1; /* whether to use application-forced */
336 guint vexpand_set : 1; /* instead of computing from children */
338 /* The widget's name. If the widget does not have a name
339 * (the name is NULL), then its name (as returned by
340 * "gtk_widget_get_name") is its class's name.
341 * Among other things, the widget name is used to determine
342 * the style to use for a widget.
346 /* The style for the widget. The style contains the
347 * colors the widget should be drawn in for each state
348 * along with graphics contexts used to draw with and
349 * the font to use for text.
352 GtkStyleContext *context;
354 /* The widget's allocated size.
356 GtkAllocation allocation;
358 /* The widget's requested sizes */
359 SizeRequestCache requests;
361 /* The widget's window or its parent window if it does
362 * not have a window. (Which will be indicated by the
363 * GTK_NO_WINDOW flag being set).
367 /* The widget's parent.
371 /* Widget's path for styling */
401 BUTTON_RELEASE_EVENT,
416 PROPERTY_NOTIFY_EVENT,
417 SELECTION_CLEAR_EVENT,
418 SELECTION_REQUEST_EVENT,
419 SELECTION_NOTIFY_EVENT,
425 VISIBILITY_NOTIFY_EVENT,
439 ACCEL_CLOSURES_CHANGED,
463 PROP_RECEIVES_DEFAULT,
464 PROP_COMPOSITE_CHILD,
472 PROP_DOUBLE_BUFFERED,
487 typedef struct _GtkStateData GtkStateData;
490 STATE_CHANGE_REPLACE,
499 guint parent_sensitive : 1;
500 guint use_forall : 1;
503 /* --- prototypes --- */
504 static void gtk_widget_class_init (GtkWidgetClass *klass);
505 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
506 static void gtk_widget_init (GtkWidget *widget);
507 static void gtk_widget_set_property (GObject *object,
511 static void gtk_widget_get_property (GObject *object,
515 static void gtk_widget_dispose (GObject *object);
516 static void gtk_widget_real_destroy (GtkWidget *object);
517 static void gtk_widget_finalize (GObject *object);
518 static void gtk_widget_real_show (GtkWidget *widget);
519 static void gtk_widget_real_hide (GtkWidget *widget);
520 static void gtk_widget_real_map (GtkWidget *widget);
521 static void gtk_widget_real_unmap (GtkWidget *widget);
522 static void gtk_widget_real_realize (GtkWidget *widget);
523 static void gtk_widget_real_unrealize (GtkWidget *widget);
524 static void gtk_widget_real_size_allocate (GtkWidget *widget,
525 GtkAllocation *allocation);
526 static void gtk_widget_real_style_set (GtkWidget *widget,
527 GtkStyle *previous_style);
528 static void gtk_widget_real_direction_changed(GtkWidget *widget,
529 GtkTextDirection previous_direction);
531 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
532 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
535 gboolean keyboard_tip,
536 GtkTooltip *tooltip);
537 static void gtk_widget_real_style_updated (GtkWidget *widget);
538 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
539 GtkWidgetHelpType help_type);
541 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
543 GParamSpec **pspecs);
544 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
546 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
548 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
549 GdkEventFocus *event);
550 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
551 GdkEventFocus *event);
552 static gboolean gtk_widget_real_focus (GtkWidget *widget,
553 GtkDirectionType direction);
554 static void gtk_widget_real_move_focus (GtkWidget *widget,
555 GtkDirectionType direction);
556 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
557 GtkDirectionType direction);
558 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
559 static void gtk_widget_update_pango_context (GtkWidget *widget);
560 static void gtk_widget_propagate_state (GtkWidget *widget,
563 static gint gtk_widget_event_internal (GtkWidget *widget,
565 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
566 gboolean group_cycling);
567 static void gtk_widget_real_get_width (GtkWidget *widget,
570 static void gtk_widget_real_get_height (GtkWidget *widget,
573 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
575 gint *minimum_height,
576 gint *natural_height);
577 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
580 gint *natural_width);
581 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
582 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
583 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
584 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
585 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
586 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
587 cairo_region_t *region);
588 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
589 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
590 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
593 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
594 gboolean has_tooltip,
596 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
597 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
599 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
600 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
602 const gchar *childname);
603 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
606 const GValue *value);
607 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
610 const gchar *tagname,
611 GMarkupParser *parser,
613 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
616 const gchar *tagname,
618 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
619 GtkBuilder *builder);
621 static void gtk_widget_real_get_width (GtkWidget *widget,
624 static void gtk_widget_real_get_height (GtkWidget *widget,
628 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
631 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
632 GtkOrientation orientation,
635 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
636 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_parent_window = 0;
666 static GQuark quark_pointer_window = 0;
667 static GQuark quark_shape_info = 0;
668 static GQuark quark_input_shape_info = 0;
669 static GQuark quark_pango_context = 0;
670 static GQuark quark_rc_style = 0;
671 static GQuark quark_accessible_object = 0;
672 static GQuark quark_mnemonic_labels = 0;
673 static GQuark quark_tooltip_markup = 0;
674 static GQuark quark_has_tooltip = 0;
675 static GQuark quark_tooltip_window = 0;
676 static GQuark quark_visual = 0;
677 static GQuark quark_modifier_style = 0;
678 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
679 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
681 /* --- functions --- */
683 gtk_widget_get_type (void)
685 static GType widget_type = 0;
687 if (G_UNLIKELY (widget_type == 0))
689 const GTypeInfo widget_info =
691 sizeof (GtkWidgetClass),
692 NULL, /* base_init */
693 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
694 (GClassInitFunc) gtk_widget_class_init,
695 NULL, /* class_finalize */
696 NULL, /* class_init */
699 (GInstanceInitFunc) gtk_widget_init,
700 NULL, /* value_table */
703 const GInterfaceInfo accessibility_info =
705 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
706 (GInterfaceFinalizeFunc) NULL,
707 NULL /* interface data */
710 const GInterfaceInfo buildable_info =
712 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
713 (GInterfaceFinalizeFunc) NULL,
714 NULL /* interface data */
717 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
718 &widget_info, G_TYPE_FLAG_ABSTRACT);
720 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
721 &accessibility_info) ;
722 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
730 child_property_notify_dispatcher (GObject *object,
734 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
737 /* We guard against the draw signal callbacks modifying the state of the
738 * cairo context by surounding it with save/restore.
739 * Maybe we should also cairo_new_path() just to be sure?
742 gtk_widget_draw_marshaller (GClosure *closure,
743 GValue *return_value,
744 guint n_param_values,
745 const GValue *param_values,
746 gpointer invocation_hint,
747 gpointer marshal_data)
749 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
753 _gtk_marshal_BOOLEAN__BOXED (closure,
764 gtk_widget_class_init (GtkWidgetClass *klass)
766 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
767 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
768 GtkBindingSet *binding_set;
770 gtk_widget_parent_class = g_type_class_peek_parent (klass);
772 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
773 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
774 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
775 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
776 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
777 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
778 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
779 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
780 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
781 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
782 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
783 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
784 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
785 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
786 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
787 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
788 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
789 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
790 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
792 style_property_spec_pool = g_param_spec_pool_new (FALSE);
793 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
794 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
795 cpn_context.dispatcher = child_property_notify_dispatcher;
796 _gtk_widget_child_property_notify_context = &cpn_context;
798 gobject_class->dispose = gtk_widget_dispose;
799 gobject_class->finalize = gtk_widget_finalize;
800 gobject_class->set_property = gtk_widget_set_property;
801 gobject_class->get_property = gtk_widget_get_property;
803 klass->destroy = gtk_widget_real_destroy;
805 klass->activate_signal = 0;
806 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
807 klass->show = gtk_widget_real_show;
808 klass->show_all = gtk_widget_show;
809 klass->hide = gtk_widget_real_hide;
810 klass->map = gtk_widget_real_map;
811 klass->unmap = gtk_widget_real_unmap;
812 klass->realize = gtk_widget_real_realize;
813 klass->unrealize = gtk_widget_real_unrealize;
814 klass->size_allocate = gtk_widget_real_size_allocate;
815 klass->get_preferred_width = gtk_widget_real_get_width;
816 klass->get_preferred_height = gtk_widget_real_get_height;
817 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
818 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
819 klass->state_changed = NULL;
820 klass->parent_set = NULL;
821 klass->hierarchy_changed = NULL;
822 klass->style_set = gtk_widget_real_style_set;
823 klass->direction_changed = gtk_widget_real_direction_changed;
824 klass->grab_notify = NULL;
825 klass->child_notify = NULL;
827 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
828 klass->grab_focus = gtk_widget_real_grab_focus;
829 klass->focus = gtk_widget_real_focus;
830 klass->move_focus = gtk_widget_real_move_focus;
831 klass->keynav_failed = gtk_widget_real_keynav_failed;
833 klass->button_press_event = NULL;
834 klass->button_release_event = NULL;
835 klass->motion_notify_event = NULL;
836 klass->delete_event = NULL;
837 klass->destroy_event = NULL;
838 klass->key_press_event = gtk_widget_real_key_press_event;
839 klass->key_release_event = gtk_widget_real_key_release_event;
840 klass->enter_notify_event = NULL;
841 klass->leave_notify_event = NULL;
842 klass->configure_event = NULL;
843 klass->focus_in_event = gtk_widget_real_focus_in_event;
844 klass->focus_out_event = gtk_widget_real_focus_out_event;
845 klass->map_event = NULL;
846 klass->unmap_event = NULL;
847 klass->window_state_event = NULL;
848 klass->property_notify_event = _gtk_selection_property_notify;
849 klass->selection_clear_event = _gtk_selection_clear;
850 klass->selection_request_event = _gtk_selection_request;
851 klass->selection_notify_event = _gtk_selection_notify;
852 klass->selection_received = NULL;
853 klass->proximity_in_event = NULL;
854 klass->proximity_out_event = NULL;
855 klass->drag_begin = NULL;
856 klass->drag_end = NULL;
857 klass->drag_data_delete = NULL;
858 klass->drag_leave = NULL;
859 klass->drag_motion = NULL;
860 klass->drag_drop = NULL;
861 klass->drag_data_received = NULL;
862 klass->screen_changed = NULL;
863 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
864 klass->grab_broken_event = NULL;
865 klass->query_tooltip = gtk_widget_real_query_tooltip;
866 klass->style_updated = gtk_widget_real_style_updated;
868 klass->show_help = gtk_widget_real_show_help;
870 /* Accessibility support */
871 klass->get_accessible = gtk_widget_real_get_accessible;
873 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
874 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
876 g_object_class_install_property (gobject_class,
878 g_param_spec_string ("name",
880 P_("The name of the widget"),
882 GTK_PARAM_READWRITE));
883 g_object_class_install_property (gobject_class,
885 g_param_spec_object ("parent",
887 P_("The parent widget of this widget. Must be a Container widget"),
889 GTK_PARAM_READWRITE));
891 g_object_class_install_property (gobject_class,
893 g_param_spec_int ("width-request",
895 P_("Override for width request of the widget, or -1 if natural request should be used"),
899 GTK_PARAM_READWRITE));
900 g_object_class_install_property (gobject_class,
902 g_param_spec_int ("height-request",
903 P_("Height request"),
904 P_("Override for height request of the widget, or -1 if natural request should be used"),
908 GTK_PARAM_READWRITE));
909 g_object_class_install_property (gobject_class,
911 g_param_spec_boolean ("visible",
913 P_("Whether the widget is visible"),
915 GTK_PARAM_READWRITE));
916 g_object_class_install_property (gobject_class,
918 g_param_spec_boolean ("sensitive",
920 P_("Whether the widget responds to input"),
922 GTK_PARAM_READWRITE));
923 g_object_class_install_property (gobject_class,
925 g_param_spec_boolean ("app-paintable",
926 P_("Application paintable"),
927 P_("Whether the application will paint directly on the widget"),
929 GTK_PARAM_READWRITE));
930 g_object_class_install_property (gobject_class,
932 g_param_spec_boolean ("can-focus",
934 P_("Whether the widget can accept the input focus"),
936 GTK_PARAM_READWRITE));
937 g_object_class_install_property (gobject_class,
939 g_param_spec_boolean ("has-focus",
941 P_("Whether the widget has the input focus"),
943 GTK_PARAM_READWRITE));
944 g_object_class_install_property (gobject_class,
946 g_param_spec_boolean ("is-focus",
948 P_("Whether the widget is the focus widget within the toplevel"),
950 GTK_PARAM_READWRITE));
951 g_object_class_install_property (gobject_class,
953 g_param_spec_boolean ("can-default",
955 P_("Whether the widget can be the default widget"),
957 GTK_PARAM_READWRITE));
958 g_object_class_install_property (gobject_class,
960 g_param_spec_boolean ("has-default",
962 P_("Whether the widget is the default widget"),
964 GTK_PARAM_READWRITE));
965 g_object_class_install_property (gobject_class,
966 PROP_RECEIVES_DEFAULT,
967 g_param_spec_boolean ("receives-default",
968 P_("Receives default"),
969 P_("If TRUE, the widget will receive the default action when it is focused"),
971 GTK_PARAM_READWRITE));
972 g_object_class_install_property (gobject_class,
973 PROP_COMPOSITE_CHILD,
974 g_param_spec_boolean ("composite-child",
975 P_("Composite child"),
976 P_("Whether the widget is part of a composite widget"),
978 GTK_PARAM_READABLE));
979 g_object_class_install_property (gobject_class,
981 g_param_spec_object ("style",
983 P_("The style of the widget, which contains information about how it will look (colors etc)"),
985 GTK_PARAM_READWRITE));
986 g_object_class_install_property (gobject_class,
988 g_param_spec_flags ("events",
990 P_("The event mask that decides what kind of GdkEvents this widget gets"),
993 GTK_PARAM_READWRITE));
994 g_object_class_install_property (gobject_class,
996 g_param_spec_boolean ("no-show-all",
998 P_("Whether gtk_widget_show_all() should not affect this widget"),
1000 GTK_PARAM_READWRITE));
1003 * GtkWidget:has-tooltip:
1005 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1006 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1007 * the widget will be queried using #GtkWidget::query-tooltip to determine
1008 * whether it will provide a tooltip or not.
1010 * Note that setting this property to %TRUE for the first time will change
1011 * the event masks of the GdkWindows of this widget to include leave-notify
1012 * and motion-notify events. This cannot and will not be undone when the
1013 * property is set to %FALSE again.
1017 g_object_class_install_property (gobject_class,
1019 g_param_spec_boolean ("has-tooltip",
1021 P_("Whether this widget has a tooltip"),
1023 GTK_PARAM_READWRITE));
1025 * GtkWidget:tooltip-text:
1027 * Sets the text of tooltip to be the given string.
1029 * Also see gtk_tooltip_set_text().
1031 * This is a convenience property which will take care of getting the
1032 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1033 * will automatically be set to %TRUE and there will be taken care of
1034 * #GtkWidget::query-tooltip in the default signal handler.
1038 g_object_class_install_property (gobject_class,
1040 g_param_spec_string ("tooltip-text",
1042 P_("The contents of the tooltip for this widget"),
1044 GTK_PARAM_READWRITE));
1046 * GtkWidget:tooltip-markup:
1048 * Sets the text of tooltip to be the given string, which is marked up
1049 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1050 * Also see gtk_tooltip_set_markup().
1052 * This is a convenience property which will take care of getting the
1053 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1054 * will automatically be set to %TRUE and there will be taken care of
1055 * #GtkWidget::query-tooltip in the default signal handler.
1059 g_object_class_install_property (gobject_class,
1060 PROP_TOOLTIP_MARKUP,
1061 g_param_spec_string ("tooltip-markup",
1062 P_("Tooltip markup"),
1063 P_("The contents of the tooltip for this widget"),
1065 GTK_PARAM_READWRITE));
1070 * The widget's window if it is realized, %NULL otherwise.
1074 g_object_class_install_property (gobject_class,
1076 g_param_spec_object ("window",
1078 P_("The widget's window if it is realized"),
1080 GTK_PARAM_READABLE));
1083 * GtkWidget:double-buffered
1085 * Whether the widget is double buffered.
1089 g_object_class_install_property (gobject_class,
1090 PROP_DOUBLE_BUFFERED,
1091 g_param_spec_boolean ("double-buffered",
1092 P_("Double Buffered"),
1093 P_("Whether the widget is double buffered"),
1095 GTK_PARAM_READWRITE));
1100 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1104 g_object_class_install_property (gobject_class,
1106 g_param_spec_enum ("halign",
1107 P_("Horizontal Alignment"),
1108 P_("How to position in extra horizontal space"),
1111 GTK_PARAM_READWRITE));
1116 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1120 g_object_class_install_property (gobject_class,
1122 g_param_spec_enum ("valign",
1123 P_("Vertical Alignment"),
1124 P_("How to position in extra vertical space"),
1127 GTK_PARAM_READWRITE));
1130 * GtkWidget:margin-left
1132 * Margin on left side of widget.
1134 * This property adds margin outside of the widget's normal size
1135 * request, the margin will be added in addition to the size from
1136 * gtk_widget_set_size_request() for example.
1140 g_object_class_install_property (gobject_class,
1142 g_param_spec_int ("margin-left",
1143 P_("Margin on Left"),
1144 P_("Pixels of extra space on the left side"),
1148 GTK_PARAM_READWRITE));
1151 * GtkWidget:margin-right
1153 * Margin on right side of widget.
1155 * This property adds margin outside of the widget's normal size
1156 * request, the margin will be added in addition to the size from
1157 * gtk_widget_set_size_request() for example.
1161 g_object_class_install_property (gobject_class,
1163 g_param_spec_int ("margin-right",
1164 P_("Margin on Right"),
1165 P_("Pixels of extra space on the right side"),
1169 GTK_PARAM_READWRITE));
1172 * GtkWidget:margin-top
1174 * Margin on top side of widget.
1176 * This property adds margin outside of the widget's normal size
1177 * request, the margin will be added in addition to the size from
1178 * gtk_widget_set_size_request() for example.
1182 g_object_class_install_property (gobject_class,
1184 g_param_spec_int ("margin-top",
1185 P_("Margin on Top"),
1186 P_("Pixels of extra space on the top side"),
1190 GTK_PARAM_READWRITE));
1193 * GtkWidget:margin-bottom
1195 * Margin on bottom side of widget.
1197 * This property adds margin outside of the widget's normal size
1198 * request, the margin will be added in addition to the size from
1199 * gtk_widget_set_size_request() for example.
1203 g_object_class_install_property (gobject_class,
1205 g_param_spec_int ("margin-bottom",
1206 P_("Margin on Bottom"),
1207 P_("Pixels of extra space on the bottom side"),
1211 GTK_PARAM_READWRITE));
1216 * Sets all four sides' margin at once. If read, returns max
1217 * margin on any side.
1221 g_object_class_install_property (gobject_class,
1223 g_param_spec_int ("margin",
1225 P_("Pixels of extra space on all four sides"),
1229 GTK_PARAM_READWRITE));
1232 * GtkWidget::destroy:
1233 * @object: the object which received the signal
1235 * Signals that all holders of a reference to the widget should release
1236 * the reference that they hold. May result in finalization of the widget
1237 * if all references are released.
1239 widget_signals[DESTROY] =
1240 g_signal_new (I_("destroy"),
1241 G_TYPE_FROM_CLASS (gobject_class),
1242 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1243 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1245 _gtk_marshal_VOID__VOID,
1251 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1255 g_object_class_install_property (gobject_class,
1257 g_param_spec_boolean ("hexpand",
1258 P_("Horizontal Expand"),
1259 P_("Whether widget wants more horizontal space"),
1261 GTK_PARAM_READWRITE));
1264 * GtkWidget:hexpand-set
1266 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1270 g_object_class_install_property (gobject_class,
1272 g_param_spec_boolean ("hexpand-set",
1273 P_("Horizontal Expand Set"),
1274 P_("Whether to use the hexpand property"),
1276 GTK_PARAM_READWRITE));
1281 * Whether to expand vertically. See gtk_widget_set_vexpand().
1285 g_object_class_install_property (gobject_class,
1287 g_param_spec_boolean ("vexpand",
1288 P_("Vertical Expand"),
1289 P_("Whether widget wants more vertical space"),
1291 GTK_PARAM_READWRITE));
1294 * GtkWidget:vexpand-set
1296 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1300 g_object_class_install_property (gobject_class,
1302 g_param_spec_boolean ("vexpand-set",
1303 P_("Vertical Expand Set"),
1304 P_("Whether to use the vexpand property"),
1306 GTK_PARAM_READWRITE));
1311 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1315 g_object_class_install_property (gobject_class,
1317 g_param_spec_boolean ("expand",
1319 P_("Whether widget wants to expand in both directions"),
1321 GTK_PARAM_READWRITE));
1325 * @widget: the object which received the signal.
1327 widget_signals[SHOW] =
1328 g_signal_new (I_("show"),
1329 G_TYPE_FROM_CLASS (gobject_class),
1331 G_STRUCT_OFFSET (GtkWidgetClass, show),
1333 _gtk_marshal_VOID__VOID,
1338 * @widget: the object which received the signal.
1340 widget_signals[HIDE] =
1341 g_signal_new (I_("hide"),
1342 G_TYPE_FROM_CLASS (gobject_class),
1344 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1346 _gtk_marshal_VOID__VOID,
1351 * @widget: the object which received the signal.
1353 widget_signals[MAP] =
1354 g_signal_new (I_("map"),
1355 G_TYPE_FROM_CLASS (gobject_class),
1357 G_STRUCT_OFFSET (GtkWidgetClass, map),
1359 _gtk_marshal_VOID__VOID,
1364 * @widget: the object which received the signal.
1366 widget_signals[UNMAP] =
1367 g_signal_new (I_("unmap"),
1368 G_TYPE_FROM_CLASS (gobject_class),
1370 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1372 _gtk_marshal_VOID__VOID,
1376 * GtkWidget::realize:
1377 * @widget: the object which received the signal.
1379 widget_signals[REALIZE] =
1380 g_signal_new (I_("realize"),
1381 G_TYPE_FROM_CLASS (gobject_class),
1383 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1385 _gtk_marshal_VOID__VOID,
1389 * GtkWidget::unrealize:
1390 * @widget: the object which received the signal.
1392 widget_signals[UNREALIZE] =
1393 g_signal_new (I_("unrealize"),
1394 G_TYPE_FROM_CLASS (gobject_class),
1396 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1398 _gtk_marshal_VOID__VOID,
1402 * GtkWidget::size-allocate:
1403 * @widget: the object which received the signal.
1406 widget_signals[SIZE_ALLOCATE] =
1407 g_signal_new (I_("size-allocate"),
1408 G_TYPE_FROM_CLASS (gobject_class),
1410 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1412 _gtk_marshal_VOID__BOXED,
1414 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1417 * GtkWidget::state-changed:
1418 * @widget: the object which received the signal.
1419 * @state: the previous state
1421 * The ::state-changed signal is emitted when the widget state changes.
1422 * See gtk_widget_get_state().
1424 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1426 widget_signals[STATE_CHANGED] =
1427 g_signal_new (I_("state-changed"),
1428 G_TYPE_FROM_CLASS (gobject_class),
1430 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1432 _gtk_marshal_VOID__ENUM,
1434 GTK_TYPE_STATE_TYPE);
1437 * GtkWidget::state-flags-changed:
1438 * @widget: the object which received the signal.
1439 * @flags: The previous state flags.
1441 * The ::state-flags-changed signal is emitted when the widget state
1442 * changes, see gtk_widget_get_state_flags().
1446 widget_signals[STATE_FLAGS_CHANGED] =
1447 g_signal_new (I_("state-flags-changed"),
1448 G_TYPE_FROM_CLASS (gobject_class),
1450 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1452 _gtk_marshal_VOID__FLAGS,
1454 GTK_TYPE_STATE_FLAGS);
1457 * GtkWidget::parent-set:
1458 * @widget: the object on which the signal is emitted
1459 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1460 * just got its initial parent.
1462 * The ::parent-set signal is emitted when a new parent
1463 * has been set on a widget.
1465 widget_signals[PARENT_SET] =
1466 g_signal_new (I_("parent-set"),
1467 G_TYPE_FROM_CLASS (gobject_class),
1469 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1471 _gtk_marshal_VOID__OBJECT,
1476 * GtkWidget::hierarchy-changed:
1477 * @widget: the object on which the signal is emitted
1478 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1479 * if the widget was previously unanchored
1481 * The ::hierarchy-changed signal is emitted when the
1482 * anchored state of a widget changes. A widget is
1483 * <firstterm>anchored</firstterm> when its toplevel
1484 * ancestor is a #GtkWindow. This signal is emitted when
1485 * a widget changes from un-anchored to anchored or vice-versa.
1487 widget_signals[HIERARCHY_CHANGED] =
1488 g_signal_new (I_("hierarchy-changed"),
1489 G_TYPE_FROM_CLASS (gobject_class),
1491 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1493 _gtk_marshal_VOID__OBJECT,
1498 * GtkWidget::style-set:
1499 * @widget: the object on which the signal is emitted
1500 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1501 * just got its initial style
1503 * The ::style-set signal is emitted when a new style has been set
1504 * on a widget. Note that style-modifying functions like
1505 * gtk_widget_modify_base() also cause this signal to be emitted.
1507 * Note that this signal is emitted for changes to the deprecated
1508 * #GtkStyle. To track changes to the #GtkStyleContext associated
1509 * with a widget, use the #GtkWidget::style-updated signal.
1511 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1513 widget_signals[STYLE_SET] =
1514 g_signal_new (I_("style-set"),
1515 G_TYPE_FROM_CLASS (gobject_class),
1517 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1519 _gtk_marshal_VOID__OBJECT,
1524 * GtkWidget::style-updated:
1525 * @widget: the object on which the signal is emitted
1527 * The ::style-updated signal is emitted when the #GtkStyleContext
1528 * of a widget is changed. Note that style-modifying functions like
1529 * gtk_widget_override_color() also cause this signal to be emitted.
1533 widget_signals[STYLE_UPDATED] =
1534 g_signal_new (I_("style-updated"),
1535 G_TYPE_FROM_CLASS (gobject_class),
1537 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1539 g_cclosure_marshal_VOID__VOID,
1543 * GtkWidget::direction-changed:
1544 * @widget: the object on which the signal is emitted
1545 * @previous_direction: the previous text direction of @widget
1547 * The ::direction-changed signal is emitted when the text direction
1548 * of a widget changes.
1550 widget_signals[DIRECTION_CHANGED] =
1551 g_signal_new (I_("direction-changed"),
1552 G_TYPE_FROM_CLASS (gobject_class),
1554 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1556 _gtk_marshal_VOID__ENUM,
1558 GTK_TYPE_TEXT_DIRECTION);
1561 * GtkWidget::grab-notify:
1562 * @widget: the object which received the signal
1563 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1564 * if it becomes unshadowed
1566 * The ::grab-notify signal is emitted when a widget becomes
1567 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1568 * another widget, or when it becomes unshadowed due to a grab
1571 * A widget is shadowed by a gtk_grab_add() when the topmost
1572 * grab widget in the grab stack of its window group is not
1575 widget_signals[GRAB_NOTIFY] =
1576 g_signal_new (I_("grab-notify"),
1577 G_TYPE_FROM_CLASS (gobject_class),
1579 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1581 _gtk_marshal_VOID__BOOLEAN,
1586 * GtkWidget::child-notify:
1587 * @widget: the object which received the signal
1588 * @pspec: the #GParamSpec of the changed child property
1590 * The ::child-notify signal is emitted for each
1591 * <link linkend="child-properties">child property</link> that has
1592 * changed on an object. The signal's detail holds the property name.
1594 widget_signals[CHILD_NOTIFY] =
1595 g_signal_new (I_("child-notify"),
1596 G_TYPE_FROM_CLASS (gobject_class),
1597 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1598 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1600 g_cclosure_marshal_VOID__PARAM,
1606 * @widget: the object which received the signal
1607 * @cr: the cairo context to draw to
1609 * This signal is emitted when a widget is supposed to render itself.
1610 * The @widget's top left corner must be painted at the origin of
1611 * the passed in context and be sized to the values returned by
1612 * gtk_widget_get_allocated_width() and
1613 * gtk_widget_get_allocated_height().
1615 * Signal handlers connected to this signal can modify the cairo
1616 * context passed as @cr in any way they like and don't need to
1617 * restore it. The signal emission takes care of calling cairo_save()
1618 * before and cairo_restore() after invoking the handler.
1620 widget_signals[DRAW] =
1621 g_signal_new (I_("draw"),
1622 G_TYPE_FROM_CLASS (gobject_class),
1624 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1625 _gtk_boolean_handled_accumulator, NULL,
1626 gtk_widget_draw_marshaller,
1628 CAIRO_GOBJECT_TYPE_CONTEXT);
1631 * GtkWidget::mnemonic-activate:
1632 * @widget: the object which received the signal.
1635 widget_signals[MNEMONIC_ACTIVATE] =
1636 g_signal_new (I_("mnemonic-activate"),
1637 G_TYPE_FROM_CLASS (gobject_class),
1639 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1640 _gtk_boolean_handled_accumulator, NULL,
1641 _gtk_marshal_BOOLEAN__BOOLEAN,
1646 * GtkWidget::grab-focus:
1647 * @widget: the object which received the signal.
1649 widget_signals[GRAB_FOCUS] =
1650 g_signal_new (I_("grab-focus"),
1651 G_TYPE_FROM_CLASS (gobject_class),
1652 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1653 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1655 _gtk_marshal_VOID__VOID,
1660 * @widget: the object which received the signal.
1663 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1665 widget_signals[FOCUS] =
1666 g_signal_new (I_("focus"),
1667 G_TYPE_FROM_CLASS (klass),
1669 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1670 _gtk_boolean_handled_accumulator, NULL,
1671 _gtk_marshal_BOOLEAN__ENUM,
1673 GTK_TYPE_DIRECTION_TYPE);
1676 * GtkWidget::move-focus:
1677 * @widget: the object which received the signal.
1680 widget_signals[MOVE_FOCUS] =
1681 g_signal_new (I_("move-focus"),
1682 G_TYPE_FROM_CLASS (klass),
1683 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1684 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1686 _gtk_marshal_VOID__ENUM,
1689 GTK_TYPE_DIRECTION_TYPE);
1692 * GtkWidget::keynav-failed:
1693 * @widget: the object which received the signal
1694 * @direction: the direction of movement
1696 * Gets emitted if keyboard navigation fails.
1697 * See gtk_widget_keynav_failed() for details.
1699 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1700 * if the emitting widget should try to handle the keyboard
1701 * navigation attempt in its parent container(s).
1705 widget_signals[KEYNAV_FAILED] =
1706 g_signal_new (I_("keynav-failed"),
1707 G_TYPE_FROM_CLASS (klass),
1709 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1710 _gtk_boolean_handled_accumulator, NULL,
1711 _gtk_marshal_BOOLEAN__ENUM,
1713 GTK_TYPE_DIRECTION_TYPE);
1717 * @widget: the object which received the signal.
1718 * @event: the #GdkEvent which triggered this signal
1720 * The GTK+ main loop will emit three signals for each GDK event delivered
1721 * to a widget: one generic ::event signal, another, more specific,
1722 * signal that matches the type of event delivered (e.g.
1723 * #GtkWidget::key-press-event) and finally a generic
1724 * #GtkWidget::event-after signal.
1726 * Returns: %TRUE to stop other handlers from being invoked for the event
1727 * and to cancel the emission of the second specific ::event signal.
1728 * %FALSE to propagate the event further and to allow the emission of
1729 * the second signal. The ::event-after signal is emitted regardless of
1732 widget_signals[EVENT] =
1733 g_signal_new (I_("event"),
1734 G_TYPE_FROM_CLASS (klass),
1736 G_STRUCT_OFFSET (GtkWidgetClass, event),
1737 _gtk_boolean_handled_accumulator, NULL,
1738 _gtk_marshal_BOOLEAN__BOXED,
1740 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1743 * GtkWidget::event-after:
1744 * @widget: the object which received the signal.
1745 * @event: the #GdkEvent which triggered this signal
1747 * After the emission of the #GtkWidget::event signal and (optionally)
1748 * the second more specific signal, ::event-after will be emitted
1749 * regardless of the previous two signals handlers return values.
1752 widget_signals[EVENT_AFTER] =
1753 g_signal_new (I_("event-after"),
1754 G_TYPE_FROM_CLASS (klass),
1758 _gtk_marshal_VOID__BOXED,
1760 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1763 * GtkWidget::button-press-event:
1764 * @widget: the object which received the signal.
1765 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1768 * The ::button-press-event signal will be emitted when a button
1769 * (typically from a mouse) is pressed.
1771 * To receive this signal, the #GdkWindow associated to the
1772 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1774 * This signal will be sent to the grab widget if there is one.
1776 * Returns: %TRUE to stop other handlers from being invoked for the event.
1777 * %FALSE to propagate the event further.
1779 widget_signals[BUTTON_PRESS_EVENT] =
1780 g_signal_new (I_("button-press-event"),
1781 G_TYPE_FROM_CLASS (klass),
1783 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1784 _gtk_boolean_handled_accumulator, NULL,
1785 _gtk_marshal_BOOLEAN__BOXED,
1787 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1790 * GtkWidget::button-release-event:
1791 * @widget: the object which received the signal.
1792 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1795 * The ::button-release-event signal will be emitted when a button
1796 * (typically from a mouse) is released.
1798 * To receive this signal, the #GdkWindow associated to the
1799 * widget needs to enable the #GDK_BUTTON_RELEASE_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[BUTTON_RELEASE_EVENT] =
1807 g_signal_new (I_("button-release-event"),
1808 G_TYPE_FROM_CLASS (klass),
1810 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1811 _gtk_boolean_handled_accumulator, NULL,
1812 _gtk_marshal_BOOLEAN__BOXED,
1814 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1817 * GtkWidget::scroll-event:
1818 * @widget: the object which received the signal.
1819 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1822 * The ::scroll-event signal is emitted when a button in the 4 to 7
1823 * range is pressed. Wheel mice are usually configured to generate
1824 * button press events for buttons 4 and 5 when the wheel is turned.
1826 * To receive this signal, the #GdkWindow associated to the widget needs
1827 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1829 * This signal will be sent to the grab widget if there is one.
1831 * Returns: %TRUE to stop other handlers from being invoked for the event.
1832 * %FALSE to propagate the event further.
1834 widget_signals[SCROLL_EVENT] =
1835 g_signal_new (I_("scroll-event"),
1836 G_TYPE_FROM_CLASS (klass),
1838 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1839 _gtk_boolean_handled_accumulator, NULL,
1840 _gtk_marshal_BOOLEAN__BOXED,
1842 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1845 * GtkWidget::motion-notify-event:
1846 * @widget: the object which received the signal.
1847 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1850 * The ::motion-notify-event signal is emitted when the pointer moves
1851 * over the widget's #GdkWindow.
1853 * To receive this signal, the #GdkWindow associated to the widget
1854 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1856 * This signal will be sent to the grab widget if there is one.
1858 * Returns: %TRUE to stop other handlers from being invoked for the event.
1859 * %FALSE to propagate the event further.
1861 widget_signals[MOTION_NOTIFY_EVENT] =
1862 g_signal_new (I_("motion-notify-event"),
1863 G_TYPE_FROM_CLASS (klass),
1865 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1866 _gtk_boolean_handled_accumulator, NULL,
1867 _gtk_marshal_BOOLEAN__BOXED,
1869 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1872 * GtkWidget::composited-changed:
1873 * @widget: the object on which the signal is emitted
1875 * The ::composited-changed signal is emitted when the composited
1876 * status of @widget<!-- -->s screen changes.
1877 * See gdk_screen_is_composited().
1879 widget_signals[COMPOSITED_CHANGED] =
1880 g_signal_new (I_("composited-changed"),
1881 G_TYPE_FROM_CLASS (klass),
1882 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1883 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1885 _gtk_marshal_VOID__VOID,
1889 * GtkWidget::delete-event:
1890 * @widget: the object which received the signal
1891 * @event: the event which triggered this signal
1893 * The ::delete-event signal is emitted if a user requests that
1894 * a toplevel window is closed. The default handler for this signal
1895 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1896 * this signal will cause the window to be hidden instead, so that
1897 * it can later be shown again without reconstructing it.
1899 * Returns: %TRUE to stop other handlers from being invoked for the event.
1900 * %FALSE to propagate the event further.
1902 widget_signals[DELETE_EVENT] =
1903 g_signal_new (I_("delete-event"),
1904 G_TYPE_FROM_CLASS (klass),
1906 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1907 _gtk_boolean_handled_accumulator, NULL,
1908 _gtk_marshal_BOOLEAN__BOXED,
1910 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1913 * GtkWidget::destroy-event:
1914 * @widget: the object which received the signal.
1915 * @event: the event which triggered this signal
1917 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1918 * You rarely get this signal, because most widgets disconnect themselves
1919 * from their window before they destroy it, so no widget owns the
1920 * window at destroy time.
1922 * To receive this signal, the #GdkWindow associated to the widget needs
1923 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1924 * automatically for all new windows.
1926 * Returns: %TRUE to stop other handlers from being invoked for the event.
1927 * %FALSE to propagate the event further.
1929 widget_signals[DESTROY_EVENT] =
1930 g_signal_new (I_("destroy-event"),
1931 G_TYPE_FROM_CLASS (klass),
1933 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1934 _gtk_boolean_handled_accumulator, NULL,
1935 _gtk_marshal_BOOLEAN__BOXED,
1937 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1940 * GtkWidget::key-press-event:
1941 * @widget: the object which received the signal
1942 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1944 * The ::key-press-event signal is emitted when a key is pressed.
1946 * To receive this signal, the #GdkWindow associated to the widget needs
1947 * to enable the #GDK_KEY_PRESS_MASK mask.
1949 * This signal will be sent to the grab widget if there is one.
1951 * Returns: %TRUE to stop other handlers from being invoked for the event.
1952 * %FALSE to propagate the event further.
1954 widget_signals[KEY_PRESS_EVENT] =
1955 g_signal_new (I_("key-press-event"),
1956 G_TYPE_FROM_CLASS (klass),
1958 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1959 _gtk_boolean_handled_accumulator, NULL,
1960 _gtk_marshal_BOOLEAN__BOXED,
1962 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1965 * GtkWidget::key-release-event:
1966 * @widget: the object which received the signal
1967 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1969 * The ::key-release-event signal is emitted when a key is pressed.
1971 * To receive this signal, the #GdkWindow associated to the widget needs
1972 * to enable the #GDK_KEY_RELEASE_MASK mask.
1974 * This signal will be sent to the grab widget if there is one.
1976 * Returns: %TRUE to stop other handlers from being invoked for the event.
1977 * %FALSE to propagate the event further.
1979 widget_signals[KEY_RELEASE_EVENT] =
1980 g_signal_new (I_("key-release-event"),
1981 G_TYPE_FROM_CLASS (klass),
1983 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1984 _gtk_boolean_handled_accumulator, NULL,
1985 _gtk_marshal_BOOLEAN__BOXED,
1987 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1990 * GtkWidget::enter-notify-event:
1991 * @widget: the object which received the signal
1992 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1995 * The ::enter-notify-event will be emitted when the pointer enters
1996 * the @widget's window.
1998 * To receive this signal, the #GdkWindow associated to the widget needs
1999 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2001 * This signal will be sent to the grab widget if there is one.
2003 * Returns: %TRUE to stop other handlers from being invoked for the event.
2004 * %FALSE to propagate the event further.
2006 widget_signals[ENTER_NOTIFY_EVENT] =
2007 g_signal_new (I_("enter-notify-event"),
2008 G_TYPE_FROM_CLASS (klass),
2010 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2011 _gtk_boolean_handled_accumulator, NULL,
2012 _gtk_marshal_BOOLEAN__BOXED,
2014 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2017 * GtkWidget::leave-notify-event:
2018 * @widget: the object which received the signal
2019 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2022 * The ::leave-notify-event will be emitted when the pointer leaves
2023 * the @widget's window.
2025 * To receive this signal, the #GdkWindow associated to the widget needs
2026 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2028 * This signal will be sent to the grab widget if there is one.
2030 * Returns: %TRUE to stop other handlers from being invoked for the event.
2031 * %FALSE to propagate the event further.
2033 widget_signals[LEAVE_NOTIFY_EVENT] =
2034 g_signal_new (I_("leave-notify-event"),
2035 G_TYPE_FROM_CLASS (klass),
2037 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2038 _gtk_boolean_handled_accumulator, NULL,
2039 _gtk_marshal_BOOLEAN__BOXED,
2041 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2044 * GtkWidget::configure-event:
2045 * @widget: the object which received the signal
2046 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2049 * The ::configure-event signal will be emitted when the size, position or
2050 * stacking of the @widget's window has changed.
2052 * To receive this signal, the #GdkWindow associated to the widget needs
2053 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2054 * automatically for all new windows.
2056 * Returns: %TRUE to stop other handlers from being invoked for the event.
2057 * %FALSE to propagate the event further.
2059 widget_signals[CONFIGURE_EVENT] =
2060 g_signal_new (I_("configure-event"),
2061 G_TYPE_FROM_CLASS (klass),
2063 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2064 _gtk_boolean_handled_accumulator, NULL,
2065 _gtk_marshal_BOOLEAN__BOXED,
2067 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2070 * GtkWidget::focus-in-event:
2071 * @widget: the object which received the signal
2072 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2075 * The ::focus-in-event signal will be emitted when the keyboard focus
2076 * enters the @widget's window.
2078 * To receive this signal, the #GdkWindow associated to the widget needs
2079 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2081 * Returns: %TRUE to stop other handlers from being invoked for the event.
2082 * %FALSE to propagate the event further.
2084 widget_signals[FOCUS_IN_EVENT] =
2085 g_signal_new (I_("focus-in-event"),
2086 G_TYPE_FROM_CLASS (klass),
2088 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2089 _gtk_boolean_handled_accumulator, NULL,
2090 _gtk_marshal_BOOLEAN__BOXED,
2092 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2095 * GtkWidget::focus-out-event:
2096 * @widget: the object which received the signal
2097 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2100 * The ::focus-out-event signal will be emitted when the keyboard focus
2101 * leaves the @widget's window.
2103 * To receive this signal, the #GdkWindow associated to the widget needs
2104 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2106 * Returns: %TRUE to stop other handlers from being invoked for the event.
2107 * %FALSE to propagate the event further.
2109 widget_signals[FOCUS_OUT_EVENT] =
2110 g_signal_new (I_("focus-out-event"),
2111 G_TYPE_FROM_CLASS (klass),
2113 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2114 _gtk_boolean_handled_accumulator, NULL,
2115 _gtk_marshal_BOOLEAN__BOXED,
2117 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2120 * GtkWidget::map-event:
2121 * @widget: the object which received the signal
2122 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2124 * The ::map-event signal will be emitted when the @widget's window is
2125 * mapped. A window is mapped when it becomes visible on the screen.
2127 * To receive this signal, the #GdkWindow associated to the widget needs
2128 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2129 * automatically for all new windows.
2131 * Returns: %TRUE to stop other handlers from being invoked for the event.
2132 * %FALSE to propagate the event further.
2134 widget_signals[MAP_EVENT] =
2135 g_signal_new (I_("map-event"),
2136 G_TYPE_FROM_CLASS (klass),
2138 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2139 _gtk_boolean_handled_accumulator, NULL,
2140 _gtk_marshal_BOOLEAN__BOXED,
2142 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2145 * GtkWidget::unmap-event:
2146 * @widget: the object which received the signal
2147 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2149 * The ::unmap-event signal may be emitted when the @widget's window is
2150 * unmapped. A window is unmapped when it becomes invisible on the screen.
2152 * For performance reasons GTK+ may not emit ::unmap-event, so one
2153 * should always also implement ::unrealize in order to release
2154 * resources and disconnect signal handlers.
2156 * To receive this signal, the #GdkWindow associated to the widget needs
2157 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2158 * automatically for all new windows.
2160 * Returns: %TRUE to stop other handlers from being invoked for the event.
2161 * %FALSE to propagate the event further.
2163 widget_signals[UNMAP_EVENT] =
2164 g_signal_new (I_("unmap-event"),
2165 G_TYPE_FROM_CLASS (klass),
2167 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2168 _gtk_boolean_handled_accumulator, NULL,
2169 _gtk_marshal_BOOLEAN__BOXED,
2171 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2174 * GtkWidget::property-notify-event:
2175 * @widget: the object which received the signal
2176 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2179 * The ::property-notify-event signal will be emitted when a property on
2180 * the @widget's window has been changed or deleted.
2182 * To receive this signal, the #GdkWindow associated to the widget needs
2183 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2185 * Returns: %TRUE to stop other handlers from being invoked for the event.
2186 * %FALSE to propagate the event further.
2188 widget_signals[PROPERTY_NOTIFY_EVENT] =
2189 g_signal_new (I_("property-notify-event"),
2190 G_TYPE_FROM_CLASS (klass),
2192 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2193 _gtk_boolean_handled_accumulator, NULL,
2194 _gtk_marshal_BOOLEAN__BOXED,
2196 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2199 * GtkWidget::selection-clear-event:
2200 * @widget: the object which received the signal
2201 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2204 * The ::selection-clear-event signal will be emitted when the
2205 * the @widget's window has lost ownership of a selection.
2207 * Returns: %TRUE to stop other handlers from being invoked for the event.
2208 * %FALSE to propagate the event further.
2210 widget_signals[SELECTION_CLEAR_EVENT] =
2211 g_signal_new (I_("selection-clear-event"),
2212 G_TYPE_FROM_CLASS (klass),
2214 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2215 _gtk_boolean_handled_accumulator, NULL,
2216 _gtk_marshal_BOOLEAN__BOXED,
2218 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2221 * GtkWidget::selection-request-event:
2222 * @widget: the object which received the signal
2223 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2226 * The ::selection-request-event signal will be emitted when
2227 * another client requests ownership of the selection owned by
2228 * the @widget's window.
2230 * Returns: %TRUE to stop other handlers from being invoked for the event.
2231 * %FALSE to propagate the event further.
2233 widget_signals[SELECTION_REQUEST_EVENT] =
2234 g_signal_new (I_("selection-request-event"),
2235 G_TYPE_FROM_CLASS (klass),
2237 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2238 _gtk_boolean_handled_accumulator, NULL,
2239 _gtk_marshal_BOOLEAN__BOXED,
2241 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2244 * GtkWidget::selection-notify-event:
2245 * @widget: the object which received the signal.
2248 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2250 widget_signals[SELECTION_NOTIFY_EVENT] =
2251 g_signal_new (I_("selection-notify-event"),
2252 G_TYPE_FROM_CLASS (klass),
2254 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2255 _gtk_boolean_handled_accumulator, NULL,
2256 _gtk_marshal_BOOLEAN__BOXED,
2258 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2261 * GtkWidget::selection-received:
2262 * @widget: the object which received the signal.
2266 widget_signals[SELECTION_RECEIVED] =
2267 g_signal_new (I_("selection-received"),
2268 G_TYPE_FROM_CLASS (klass),
2270 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2272 _gtk_marshal_VOID__BOXED_UINT,
2274 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2278 * GtkWidget::selection-get:
2279 * @widget: the object which received the signal.
2284 widget_signals[SELECTION_GET] =
2285 g_signal_new (I_("selection-get"),
2286 G_TYPE_FROM_CLASS (klass),
2288 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2290 _gtk_marshal_VOID__BOXED_UINT_UINT,
2292 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2297 * GtkWidget::proximity-in-event:
2298 * @widget: the object which received the signal
2299 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2302 * To receive this signal the #GdkWindow associated to the widget needs
2303 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2305 * This signal will be sent to the grab widget if there is one.
2307 * Returns: %TRUE to stop other handlers from being invoked for the event.
2308 * %FALSE to propagate the event further.
2310 widget_signals[PROXIMITY_IN_EVENT] =
2311 g_signal_new (I_("proximity-in-event"),
2312 G_TYPE_FROM_CLASS (klass),
2314 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2315 _gtk_boolean_handled_accumulator, NULL,
2316 _gtk_marshal_BOOLEAN__BOXED,
2318 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2321 * GtkWidget::proximity-out-event:
2322 * @widget: the object which received the signal
2323 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2326 * To receive this signal the #GdkWindow associated to the widget needs
2327 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2329 * This signal will be sent to the grab widget if there is one.
2331 * Returns: %TRUE to stop other handlers from being invoked for the event.
2332 * %FALSE to propagate the event further.
2334 widget_signals[PROXIMITY_OUT_EVENT] =
2335 g_signal_new (I_("proximity-out-event"),
2336 G_TYPE_FROM_CLASS (klass),
2338 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2339 _gtk_boolean_handled_accumulator, NULL,
2340 _gtk_marshal_BOOLEAN__BOXED,
2342 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2345 * GtkWidget::drag-leave:
2346 * @widget: the object which received the signal.
2347 * @drag_context: the drag context
2348 * @time: the timestamp of the motion event
2350 * The ::drag-leave signal is emitted on the drop site when the cursor
2351 * leaves the widget. A typical reason to connect to this signal is to
2352 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2353 * with gtk_drag_unhighlight()
2355 widget_signals[DRAG_LEAVE] =
2356 g_signal_new (I_("drag-leave"),
2357 G_TYPE_FROM_CLASS (klass),
2359 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2361 _gtk_marshal_VOID__OBJECT_UINT,
2363 GDK_TYPE_DRAG_CONTEXT,
2367 * GtkWidget::drag-begin:
2368 * @widget: the object which received the signal
2369 * @drag_context: the drag context
2371 * The ::drag-begin signal is emitted on the drag source when a drag is
2372 * started. A typical reason to connect to this signal is to set up a
2373 * custom drag icon with gtk_drag_source_set_icon().
2375 * Note that some widgets set up a drag icon in the default handler of
2376 * this signal, so you may have to use g_signal_connect_after() to
2377 * override what the default handler did.
2379 widget_signals[DRAG_BEGIN] =
2380 g_signal_new (I_("drag-begin"),
2381 G_TYPE_FROM_CLASS (klass),
2383 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2385 _gtk_marshal_VOID__OBJECT,
2387 GDK_TYPE_DRAG_CONTEXT);
2390 * GtkWidget::drag-end:
2391 * @widget: the object which received the signal
2392 * @drag_context: the drag context
2394 * The ::drag-end signal is emitted on the drag source when a drag is
2395 * finished. A typical reason to connect to this signal is to undo
2396 * things done in #GtkWidget::drag-begin.
2398 widget_signals[DRAG_END] =
2399 g_signal_new (I_("drag-end"),
2400 G_TYPE_FROM_CLASS (klass),
2402 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2404 _gtk_marshal_VOID__OBJECT,
2406 GDK_TYPE_DRAG_CONTEXT);
2409 * GtkWidget::drag-data-delete:
2410 * @widget: the object which received the signal
2411 * @drag_context: the drag context
2413 * The ::drag-data-delete signal is emitted on the drag source when a drag
2414 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2415 * handler is responsible for deleting the data that has been dropped. What
2416 * "delete" means depends on the context of the drag operation.
2418 widget_signals[DRAG_DATA_DELETE] =
2419 g_signal_new (I_("drag-data-delete"),
2420 G_TYPE_FROM_CLASS (klass),
2422 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2424 _gtk_marshal_VOID__OBJECT,
2426 GDK_TYPE_DRAG_CONTEXT);
2429 * GtkWidget::drag-failed:
2430 * @widget: the object which received the signal
2431 * @drag_context: the drag context
2432 * @result: the result of the drag operation
2434 * The ::drag-failed signal is emitted on the drag source when a drag has
2435 * failed. The signal handler may hook custom code to handle a failed DND
2436 * operation based on the type of error, it returns %TRUE is the failure has
2437 * been already handled (not showing the default "drag operation failed"
2438 * animation), otherwise it returns %FALSE.
2440 * Return value: %TRUE if the failed drag operation has been already handled.
2444 widget_signals[DRAG_FAILED] =
2445 g_signal_new (I_("drag-failed"),
2446 G_TYPE_FROM_CLASS (klass),
2448 0, _gtk_boolean_handled_accumulator, NULL,
2449 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2451 GDK_TYPE_DRAG_CONTEXT,
2452 GTK_TYPE_DRAG_RESULT);
2455 * GtkWidget::drag-motion:
2456 * @widget: the object which received the signal
2457 * @drag_context: the drag context
2458 * @x: the x coordinate of the current cursor position
2459 * @y: the y coordinate of the current cursor position
2460 * @time: the timestamp of the motion event
2461 * @returns: whether the cursor position is in a drop zone
2463 * The drag-motion signal is emitted on the drop site when the user
2464 * moves the cursor over the widget during a drag. The signal handler
2465 * must determine whether the cursor position is in a drop zone or not.
2466 * If it is not in a drop zone, it returns %FALSE and no further processing
2467 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2468 * handler is responsible for providing the necessary information for
2469 * displaying feedback to the user, by calling gdk_drag_status().
2471 * If the decision whether the drop will be accepted or rejected can't be
2472 * made based solely on the cursor position and the type of the data, the
2473 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2474 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2475 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2476 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2477 * when using the drag-motion signal that way.
2479 * Also note that there is no drag-enter signal. The drag receiver has to
2480 * keep track of whether he has received any drag-motion signals since the
2481 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2482 * an "enter" signal. Upon an "enter", the handler will typically highlight
2483 * the drop site with gtk_drag_highlight().
2486 * drag_motion (GtkWidget *widget,
2487 * GdkDragContext *context,
2494 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2496 * if (!private_data->drag_highlight)
2498 * private_data->drag_highlight = 1;
2499 * gtk_drag_highlight (widget);
2502 * target = gtk_drag_dest_find_target (widget, context, NULL);
2503 * if (target == GDK_NONE)
2504 * gdk_drag_status (context, 0, time);
2507 * private_data->pending_status = context->suggested_action;
2508 * gtk_drag_get_data (widget, context, target, time);
2515 * drag_data_received (GtkWidget *widget,
2516 * GdkDragContext *context,
2519 * GtkSelectionData *selection_data,
2523 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2525 * if (private_data->suggested_action)
2527 * private_data->suggested_action = 0;
2529 * /* We are getting this data due to a request in drag_motion,
2530 * * rather than due to a request in drag_drop, so we are just
2531 * * supposed to call gdk_drag_status (), not actually paste in
2534 * str = gtk_selection_data_get_text (selection_data);
2535 * if (!data_is_acceptable (str))
2536 * gdk_drag_status (context, 0, time);
2538 * gdk_drag_status (context, private_data->suggested_action, time);
2542 * /* accept the drop */
2547 widget_signals[DRAG_MOTION] =
2548 g_signal_new (I_("drag-motion"),
2549 G_TYPE_FROM_CLASS (klass),
2551 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2552 _gtk_boolean_handled_accumulator, NULL,
2553 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2555 GDK_TYPE_DRAG_CONTEXT,
2561 * GtkWidget::drag-drop:
2562 * @widget: the object which received the signal
2563 * @drag_context: the drag context
2564 * @x: the x coordinate of the current cursor position
2565 * @y: the y coordinate of the current cursor position
2566 * @time: the timestamp of the motion event
2567 * @returns: whether the cursor position is in a drop zone
2569 * The ::drag-drop signal is emitted on the drop site when the user drops
2570 * the data onto the widget. The signal handler must determine whether
2571 * the cursor position is in a drop zone or not. If it is not in a drop
2572 * zone, it returns %FALSE and no further processing is necessary.
2573 * Otherwise, the handler returns %TRUE. In this case, the handler must
2574 * ensure that gtk_drag_finish() is called to let the source know that
2575 * the drop is done. The call to gtk_drag_finish() can be done either
2576 * directly or in a #GtkWidget::drag-data-received handler which gets
2577 * triggered by calling gtk_drag_get_data() to receive the data for one
2578 * or more of the supported targets.
2580 widget_signals[DRAG_DROP] =
2581 g_signal_new (I_("drag-drop"),
2582 G_TYPE_FROM_CLASS (klass),
2584 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2585 _gtk_boolean_handled_accumulator, NULL,
2586 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2588 GDK_TYPE_DRAG_CONTEXT,
2594 * GtkWidget::drag-data-get:
2595 * @widget: the object which received the signal
2596 * @drag_context: the drag context
2597 * @data: the #GtkSelectionData to be filled with the dragged data
2598 * @info: the info that has been registered with the target in the
2600 * @time: the timestamp at which the data was requested
2602 * The ::drag-data-get signal is emitted on the drag source when the drop
2603 * site requests the data which is dragged. It is the responsibility of
2604 * the signal handler to fill @data with the data in the format which
2605 * is indicated by @info. See gtk_selection_data_set() and
2606 * gtk_selection_data_set_text().
2608 widget_signals[DRAG_DATA_GET] =
2609 g_signal_new (I_("drag-data-get"),
2610 G_TYPE_FROM_CLASS (klass),
2612 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2614 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2616 GDK_TYPE_DRAG_CONTEXT,
2617 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2622 * GtkWidget::drag-data-received:
2623 * @widget: the object which received the signal
2624 * @drag_context: the drag context
2625 * @x: where the drop happened
2626 * @y: where the drop happened
2627 * @data: the received data
2628 * @info: the info that has been registered with the target in the
2630 * @time: the timestamp at which the data was received
2632 * The ::drag-data-received signal is emitted on the drop site when the
2633 * dragged data has been received. If the data was received in order to
2634 * determine whether the drop will be accepted, the handler is expected
2635 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2636 * If the data was received in response to a #GtkWidget::drag-drop signal
2637 * (and this is the last target to be received), the handler for this
2638 * signal is expected to process the received data and then call
2639 * gtk_drag_finish(), setting the @success parameter depending on whether
2640 * the data was processed successfully.
2642 * The handler may inspect and modify @drag_context->action before calling
2643 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2644 * following example:
2647 * drag_data_received (GtkWidget *widget,
2648 * GdkDragContext *drag_context,
2651 * GtkSelectionData *data,
2655 * if ((data->length >= 0) && (data->format == 8))
2657 * if (drag_context->action == GDK_ACTION_ASK)
2659 * GtkWidget *dialog;
2662 * dialog = gtk_message_dialog_new (NULL,
2663 * GTK_DIALOG_MODAL |
2664 * GTK_DIALOG_DESTROY_WITH_PARENT,
2666 * GTK_BUTTONS_YES_NO,
2667 * "Move the data ?\n");
2668 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2669 * gtk_widget_destroy (dialog);
2671 * if (response == GTK_RESPONSE_YES)
2672 * drag_context->action = GDK_ACTION_MOVE;
2674 * drag_context->action = GDK_ACTION_COPY;
2677 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2681 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2685 widget_signals[DRAG_DATA_RECEIVED] =
2686 g_signal_new (I_("drag-data-received"),
2687 G_TYPE_FROM_CLASS (klass),
2689 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2691 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2693 GDK_TYPE_DRAG_CONTEXT,
2696 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2701 * GtkWidget::visibility-notify-event:
2702 * @widget: the object which received the signal
2703 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2704 * triggered this signal.
2706 * The ::visibility-notify-event will be emitted when the @widget's window
2707 * is obscured or unobscured.
2709 * To receive this signal the #GdkWindow associated to the widget needs
2710 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2712 * Returns: %TRUE to stop other handlers from being invoked for the event.
2713 * %FALSE to propagate the event further.
2715 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2716 g_signal_new (I_("visibility-notify-event"),
2717 G_TYPE_FROM_CLASS (klass),
2719 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2720 _gtk_boolean_handled_accumulator, NULL,
2721 _gtk_marshal_BOOLEAN__BOXED,
2723 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2726 * GtkWidget::client-event:
2727 * @widget: the object which received the signal
2728 * @event: (type Gdk.EventClient): the #GdkEventClient which triggered
2731 * The ::client-event will be emitted when the @widget's window
2732 * receives a message (via a ClientMessage event) from another
2735 * Returns: %TRUE to stop other handlers from being invoked for
2736 * the event. %FALSE to propagate the event further.
2738 widget_signals[CLIENT_EVENT] =
2739 g_signal_new (I_("client-event"),
2740 G_TYPE_FROM_CLASS (klass),
2742 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2743 _gtk_boolean_handled_accumulator, NULL,
2744 _gtk_marshal_BOOLEAN__BOXED,
2746 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2749 * GtkWidget::window-state-event:
2750 * @widget: the object which received the signal
2751 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2752 * triggered this signal.
2754 * The ::window-state-event will be emitted when the state of the
2755 * toplevel window associated to the @widget changes.
2757 * To receive this signal the #GdkWindow associated to the widget
2758 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2759 * this mask automatically for all new windows.
2761 * Returns: %TRUE to stop other handlers from being invoked for the
2762 * event. %FALSE to propagate the event further.
2764 widget_signals[WINDOW_STATE_EVENT] =
2765 g_signal_new (I_("window-state-event"),
2766 G_TYPE_FROM_CLASS (klass),
2768 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2769 _gtk_boolean_handled_accumulator, NULL,
2770 _gtk_marshal_BOOLEAN__BOXED,
2772 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2775 * GtkWidget::damage-event:
2776 * @widget: the object which received the signal
2777 * @event: the #GdkEventExpose event
2779 * Emitted when a redirected window belonging to @widget gets drawn into.
2780 * The region/area members of the event shows what area of the redirected
2781 * drawable was drawn into.
2783 * Returns: %TRUE to stop other handlers from being invoked for the event.
2784 * %FALSE to propagate the event further.
2788 widget_signals[DAMAGE_EVENT] =
2789 g_signal_new (I_("damage-event"),
2790 G_TYPE_FROM_CLASS (klass),
2792 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2793 _gtk_boolean_handled_accumulator, NULL,
2794 _gtk_marshal_BOOLEAN__BOXED,
2796 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2799 * GtkWidget::grab-broken-event:
2800 * @widget: the object which received the signal
2801 * @event: the #GdkEventGrabBroken event
2803 * Emitted when a pointer or keyboard grab on a window belonging
2804 * to @widget gets broken.
2806 * On X11, this happens when the grab window becomes unviewable
2807 * (i.e. it or one of its ancestors is unmapped), or if the same
2808 * application grabs the pointer or keyboard again.
2810 * Returns: %TRUE to stop other handlers from being invoked for
2811 * the event. %FALSE to propagate the event further.
2815 widget_signals[GRAB_BROKEN_EVENT] =
2816 g_signal_new (I_("grab-broken-event"),
2817 G_TYPE_FROM_CLASS (klass),
2819 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2820 _gtk_boolean_handled_accumulator, NULL,
2821 _gtk_marshal_BOOLEAN__BOXED,
2823 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2826 * GtkWidget::query-tooltip:
2827 * @widget: the object which received the signal
2828 * @x: the x coordinate of the cursor position where the request has
2829 * been emitted, relative to @widget->window
2830 * @y: the y coordinate of the cursor position where the request has
2831 * been emitted, relative to @widget->window
2832 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2833 * @tooltip: a #GtkTooltip
2835 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2836 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2837 * focus in keyboard mode.
2839 * Using the given coordinates, the signal handler should determine
2840 * whether a tooltip should be shown for @widget. If this is the case
2841 * %TRUE should be returned, %FALSE otherwise. Note that if
2842 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2843 * should not be used.
2845 * The signal handler is free to manipulate @tooltip with the therefore
2846 * destined function calls.
2848 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2852 widget_signals[QUERY_TOOLTIP] =
2853 g_signal_new (I_("query-tooltip"),
2854 G_TYPE_FROM_CLASS (klass),
2856 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2857 _gtk_boolean_handled_accumulator, NULL,
2858 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2866 * GtkWidget::popup-menu
2867 * @widget: the object which received the signal
2869 * This signal gets emitted whenever a widget should pop up a context
2870 * menu. This usually happens through the standard key binding mechanism;
2871 * by pressing a certain key while a widget is focused, the user can cause
2872 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2873 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2874 * for an example of how to use this signal.
2876 * Returns: %TRUE if a menu was activated
2878 widget_signals[POPUP_MENU] =
2879 g_signal_new (I_("popup-menu"),
2880 G_TYPE_FROM_CLASS (klass),
2881 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2882 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2883 _gtk_boolean_handled_accumulator, NULL,
2884 _gtk_marshal_BOOLEAN__VOID,
2888 * GtkWidget::show-help:
2889 * @widget: the object which received the signal.
2892 widget_signals[SHOW_HELP] =
2893 g_signal_new (I_("show-help"),
2894 G_TYPE_FROM_CLASS (klass),
2895 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2896 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2897 _gtk_boolean_handled_accumulator, NULL,
2898 _gtk_marshal_BOOLEAN__ENUM,
2900 GTK_TYPE_WIDGET_HELP_TYPE);
2903 * GtkWidget::accel-closures-changed:
2904 * @widget: the object which received the signal.
2906 widget_signals[ACCEL_CLOSURES_CHANGED] =
2907 g_signal_new (I_("accel-closures-changed"),
2908 G_TYPE_FROM_CLASS (klass),
2912 _gtk_marshal_VOID__VOID,
2916 * GtkWidget::screen-changed:
2917 * @widget: the object on which the signal is emitted
2918 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2919 * widget was not associated with a screen before
2921 * The ::screen-changed signal gets emitted when the
2922 * screen of a widget has changed.
2924 widget_signals[SCREEN_CHANGED] =
2925 g_signal_new (I_("screen-changed"),
2926 G_TYPE_FROM_CLASS (klass),
2928 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2930 _gtk_marshal_VOID__OBJECT,
2935 * GtkWidget::can-activate-accel:
2936 * @widget: the object which received the signal
2937 * @signal_id: the ID of a signal installed on @widget
2939 * Determines whether an accelerator that activates the signal
2940 * identified by @signal_id can currently be activated.
2941 * This signal is present to allow applications and derived
2942 * widgets to override the default #GtkWidget handling
2943 * for determining whether an accelerator can be activated.
2945 * Returns: %TRUE if the signal can be activated.
2947 widget_signals[CAN_ACTIVATE_ACCEL] =
2948 g_signal_new (I_("can-activate-accel"),
2949 G_TYPE_FROM_CLASS (klass),
2951 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2952 _gtk_boolean_handled_accumulator, NULL,
2953 _gtk_marshal_BOOLEAN__UINT,
2954 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2956 binding_set = gtk_binding_set_by_class (klass);
2957 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
2959 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
2962 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
2964 GTK_TYPE_WIDGET_HELP_TYPE,
2965 GTK_WIDGET_HELP_TOOLTIP);
2966 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
2968 GTK_TYPE_WIDGET_HELP_TYPE,
2969 GTK_WIDGET_HELP_TOOLTIP);
2970 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
2972 GTK_TYPE_WIDGET_HELP_TYPE,
2973 GTK_WIDGET_HELP_WHATS_THIS);
2974 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
2976 GTK_TYPE_WIDGET_HELP_TYPE,
2977 GTK_WIDGET_HELP_WHATS_THIS);
2979 gtk_widget_class_install_style_property (klass,
2980 g_param_spec_boolean ("interior-focus",
2981 P_("Interior Focus"),
2982 P_("Whether to draw the focus indicator inside widgets"),
2984 GTK_PARAM_READABLE));
2986 gtk_widget_class_install_style_property (klass,
2987 g_param_spec_int ("focus-line-width",
2988 P_("Focus linewidth"),
2989 P_("Width, in pixels, of the focus indicator line"),
2991 GTK_PARAM_READABLE));
2993 gtk_widget_class_install_style_property (klass,
2994 g_param_spec_string ("focus-line-pattern",
2995 P_("Focus line dash pattern"),
2996 P_("Dash pattern used to draw the focus indicator"),
2998 GTK_PARAM_READABLE));
2999 gtk_widget_class_install_style_property (klass,
3000 g_param_spec_int ("focus-padding",
3001 P_("Focus padding"),
3002 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3004 GTK_PARAM_READABLE));
3005 gtk_widget_class_install_style_property (klass,
3006 g_param_spec_boxed ("cursor-color",
3008 P_("Color with which to draw insertion cursor"),
3010 GTK_PARAM_READABLE));
3011 gtk_widget_class_install_style_property (klass,
3012 g_param_spec_boxed ("secondary-cursor-color",
3013 P_("Secondary cursor color"),
3014 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3016 GTK_PARAM_READABLE));
3017 gtk_widget_class_install_style_property (klass,
3018 g_param_spec_float ("cursor-aspect-ratio",
3019 P_("Cursor line aspect ratio"),
3020 P_("Aspect ratio with which to draw insertion cursor"),
3022 GTK_PARAM_READABLE));
3024 gtk_widget_class_install_style_property (klass,
3025 g_param_spec_boolean ("window-dragging",
3026 P_("Window dragging"),
3027 P_("Whether windows can be dragged by clicking on empty areas"),
3029 GTK_PARAM_READABLE));
3032 * GtkWidget:link-color:
3034 * The "link-color" style property defines the color of unvisited links.
3038 gtk_widget_class_install_style_property (klass,
3039 g_param_spec_boxed ("link-color",
3040 P_("Unvisited Link Color"),
3041 P_("Color of unvisited links"),
3043 GTK_PARAM_READABLE));
3046 * GtkWidget:visited-link-color:
3048 * The "visited-link-color" style property defines the color of visited links.
3052 gtk_widget_class_install_style_property (klass,
3053 g_param_spec_boxed ("visited-link-color",
3054 P_("Visited Link Color"),
3055 P_("Color of visited links"),
3057 GTK_PARAM_READABLE));
3060 * GtkWidget:wide-separators:
3062 * The "wide-separators" style property defines whether separators have
3063 * configurable width and should be drawn using a box instead of a line.
3067 gtk_widget_class_install_style_property (klass,
3068 g_param_spec_boolean ("wide-separators",
3069 P_("Wide Separators"),
3070 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3072 GTK_PARAM_READABLE));
3075 * GtkWidget:separator-width:
3077 * The "separator-width" style property defines the width of separators.
3078 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3082 gtk_widget_class_install_style_property (klass,
3083 g_param_spec_int ("separator-width",
3084 P_("Separator Width"),
3085 P_("The width of separators if wide-separators is TRUE"),
3087 GTK_PARAM_READABLE));
3090 * GtkWidget:separator-height:
3092 * The "separator-height" style property defines the height of separators.
3093 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3097 gtk_widget_class_install_style_property (klass,
3098 g_param_spec_int ("separator-height",
3099 P_("Separator Height"),
3100 P_("The height of separators if \"wide-separators\" is TRUE"),
3102 GTK_PARAM_READABLE));
3105 * GtkWidget:scroll-arrow-hlength:
3107 * The "scroll-arrow-hlength" style property defines the length of
3108 * horizontal scroll arrows.
3112 gtk_widget_class_install_style_property (klass,
3113 g_param_spec_int ("scroll-arrow-hlength",
3114 P_("Horizontal Scroll Arrow Length"),
3115 P_("The length of horizontal scroll arrows"),
3117 GTK_PARAM_READABLE));
3120 * GtkWidget:scroll-arrow-vlength:
3122 * The "scroll-arrow-vlength" style property defines the length of
3123 * vertical scroll arrows.
3127 gtk_widget_class_install_style_property (klass,
3128 g_param_spec_int ("scroll-arrow-vlength",
3129 P_("Vertical Scroll Arrow Length"),
3130 P_("The length of vertical scroll arrows"),
3132 GTK_PARAM_READABLE));
3134 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3138 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3142 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3143 for (node = list; node; node = node->next)
3145 GParamSpec *pspec = node->data;
3147 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3148 g_param_spec_unref (pspec);
3154 gtk_widget_set_property (GObject *object,
3156 const GValue *value,
3159 GtkWidget *widget = GTK_WIDGET (object);
3164 gchar *tooltip_markup;
3165 const gchar *tooltip_text;
3166 GtkWindow *tooltip_window;
3169 gtk_widget_set_name (widget, g_value_get_string (value));
3172 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3174 case PROP_WIDTH_REQUEST:
3175 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3177 case PROP_HEIGHT_REQUEST:
3178 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3181 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3183 case PROP_SENSITIVE:
3184 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3186 case PROP_APP_PAINTABLE:
3187 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3189 case PROP_CAN_FOCUS:
3190 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3192 case PROP_HAS_FOCUS:
3193 if (g_value_get_boolean (value))
3194 gtk_widget_grab_focus (widget);
3197 if (g_value_get_boolean (value))
3198 gtk_widget_grab_focus (widget);
3200 case PROP_CAN_DEFAULT:
3201 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3203 case PROP_HAS_DEFAULT:
3204 if (g_value_get_boolean (value))
3205 gtk_widget_grab_default (widget);
3207 case PROP_RECEIVES_DEFAULT:
3208 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3211 gtk_widget_set_style (widget, g_value_get_object (value));
3214 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3215 gtk_widget_set_events (widget, g_value_get_flags (value));
3217 case PROP_NO_SHOW_ALL:
3218 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3220 case PROP_HAS_TOOLTIP:
3221 gtk_widget_real_set_has_tooltip (widget,
3222 g_value_get_boolean (value), FALSE);
3224 case PROP_TOOLTIP_MARKUP:
3225 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3226 tooltip_markup = g_value_dup_string (value);
3228 /* Treat an empty string as a NULL string,
3229 * because an empty string would be useless for a tooltip:
3231 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3233 g_free (tooltip_markup);
3234 tooltip_markup = NULL;
3237 g_object_set_qdata_full (object, quark_tooltip_markup,
3238 tooltip_markup, g_free);
3240 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3241 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3242 if (gtk_widget_get_visible (widget))
3243 gtk_widget_queue_tooltip_query (widget);
3245 case PROP_TOOLTIP_TEXT:
3246 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3248 tooltip_text = g_value_get_string (value);
3250 /* Treat an empty string as a NULL string,
3251 * because an empty string would be useless for a tooltip:
3253 if (tooltip_text && (strlen (tooltip_text) == 0))
3254 tooltip_text = NULL;
3256 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3258 g_object_set_qdata_full (object, quark_tooltip_markup,
3259 tooltip_markup, g_free);
3261 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3262 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3263 if (gtk_widget_get_visible (widget))
3264 gtk_widget_queue_tooltip_query (widget);
3266 case PROP_DOUBLE_BUFFERED:
3267 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3270 gtk_widget_set_halign (widget, g_value_get_enum (value));
3273 gtk_widget_set_valign (widget, g_value_get_enum (value));
3275 case PROP_MARGIN_LEFT:
3276 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3278 case PROP_MARGIN_RIGHT:
3279 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3281 case PROP_MARGIN_TOP:
3282 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3284 case PROP_MARGIN_BOTTOM:
3285 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3288 g_object_freeze_notify (G_OBJECT (widget));
3289 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3290 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3291 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3292 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3293 g_object_thaw_notify (G_OBJECT (widget));
3296 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3298 case PROP_HEXPAND_SET:
3299 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3302 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3304 case PROP_VEXPAND_SET:
3305 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3308 g_object_freeze_notify (G_OBJECT (widget));
3309 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3310 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3311 g_object_thaw_notify (G_OBJECT (widget));
3314 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3320 gtk_widget_get_property (GObject *object,
3325 GtkWidget *widget = GTK_WIDGET (object);
3326 GtkWidgetPrivate *priv = widget->priv;
3334 g_value_set_string (value, priv->name);
3336 g_value_set_static_string (value, "");
3339 g_value_set_object (value, priv->parent);
3341 case PROP_WIDTH_REQUEST:
3344 gtk_widget_get_size_request (widget, &w, NULL);
3345 g_value_set_int (value, w);
3348 case PROP_HEIGHT_REQUEST:
3351 gtk_widget_get_size_request (widget, NULL, &h);
3352 g_value_set_int (value, h);
3356 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3358 case PROP_SENSITIVE:
3359 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3361 case PROP_APP_PAINTABLE:
3362 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3364 case PROP_CAN_FOCUS:
3365 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3367 case PROP_HAS_FOCUS:
3368 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3371 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3373 case PROP_CAN_DEFAULT:
3374 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3376 case PROP_HAS_DEFAULT:
3377 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3379 case PROP_RECEIVES_DEFAULT:
3380 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3382 case PROP_COMPOSITE_CHILD:
3383 g_value_set_boolean (value, widget->priv->composite_child);
3386 g_value_set_object (value, gtk_widget_get_style (widget));
3389 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3390 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3392 case PROP_NO_SHOW_ALL:
3393 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3395 case PROP_HAS_TOOLTIP:
3396 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3398 case PROP_TOOLTIP_TEXT:
3400 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3403 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3404 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3406 g_value_take_string (value, text);
3409 case PROP_TOOLTIP_MARKUP:
3410 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3413 g_value_set_object (value, gtk_widget_get_window (widget));
3415 case PROP_DOUBLE_BUFFERED:
3416 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3419 g_value_set_enum (value, gtk_widget_get_halign (widget));
3422 g_value_set_enum (value, gtk_widget_get_valign (widget));
3424 case PROP_MARGIN_LEFT:
3425 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3427 case PROP_MARGIN_RIGHT:
3428 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3430 case PROP_MARGIN_TOP:
3431 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3433 case PROP_MARGIN_BOTTOM:
3434 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3438 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3439 if (aux_info == NULL)
3441 g_value_set_int (value, 0);
3445 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3446 aux_info->margin.right),
3447 MAX (aux_info->margin.top,
3448 aux_info->margin.bottom)));
3453 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3455 case PROP_HEXPAND_SET:
3456 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3459 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3461 case PROP_VEXPAND_SET:
3462 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3465 g_value_set_boolean (value,
3466 gtk_widget_get_hexpand (widget) &&
3467 gtk_widget_get_vexpand (widget));
3470 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3476 gtk_widget_init (GtkWidget *widget)
3478 GtkWidgetPrivate *priv;
3480 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3483 priv = widget->priv;
3485 priv->child_visible = TRUE;
3487 priv->allocation.x = -1;
3488 priv->allocation.y = -1;
3489 priv->allocation.width = 1;
3490 priv->allocation.height = 1;
3491 priv->window = NULL;
3492 priv->parent = NULL;
3494 priv->sensitive = TRUE;
3495 priv->parent_sensitive = TRUE;
3496 priv->composite_child = composite_child_stack != 0;
3497 priv->double_buffered = TRUE;
3498 priv->redraw_on_alloc = TRUE;
3499 priv->width_request_needed = TRUE;
3500 priv->height_request_needed = TRUE;
3501 priv->alloc_needed = TRUE;
3503 /* this will be set to TRUE if the widget gets a child or if the
3504 * expand flag is set on the widget, but until one of those happen
3505 * we know the expand is already properly FALSE.
3507 * We really want to default FALSE here to avoid computing expand
3508 * all over the place while initially building a widget tree.
3510 priv->need_compute_expand = FALSE;
3512 priv->style = gtk_widget_get_default_style ();
3513 g_object_ref (priv->style);
3518 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3520 GParamSpec **pspecs)
3522 GtkWidgetPrivate *priv = widget->priv;
3523 GtkWidget *container = priv->parent;
3526 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3527 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3531 * gtk_widget_freeze_child_notify:
3532 * @widget: a #GtkWidget
3534 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3535 * signals are queued until gtk_widget_thaw_child_notify() is called
3538 * This is the analogue of g_object_freeze_notify() for child properties.
3541 gtk_widget_freeze_child_notify (GtkWidget *widget)
3543 g_return_if_fail (GTK_IS_WIDGET (widget));
3545 if (!G_OBJECT (widget)->ref_count)
3548 g_object_ref (widget);
3549 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3550 g_object_unref (widget);
3554 * gtk_widget_child_notify:
3555 * @widget: a #GtkWidget
3556 * @child_property: the name of a child property installed on the
3557 * class of @widget<!-- -->'s parent
3559 * Emits a #GtkWidget::child-notify signal for the
3560 * <link linkend="child-properties">child property</link> @child_property
3563 * This is the analogue of g_object_notify() for child properties.
3566 gtk_widget_child_notify (GtkWidget *widget,
3567 const gchar *child_property)
3569 GtkWidgetPrivate *priv = widget->priv;
3572 g_return_if_fail (GTK_IS_WIDGET (widget));
3573 g_return_if_fail (child_property != NULL);
3574 if (!G_OBJECT (widget)->ref_count || !priv->parent)
3577 g_object_ref (widget);
3578 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3580 G_OBJECT_TYPE (priv->parent),
3583 g_warning ("%s: container class `%s' has no child property named `%s'",
3585 G_OBJECT_TYPE_NAME (priv->parent),
3589 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3591 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3592 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3594 g_object_unref (widget);
3598 * gtk_widget_thaw_child_notify:
3599 * @widget: a #GtkWidget
3601 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3602 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3606 gtk_widget_thaw_child_notify (GtkWidget *widget)
3608 GObjectNotifyQueue *nqueue;
3610 g_return_if_fail (GTK_IS_WIDGET (widget));
3612 if (!G_OBJECT (widget)->ref_count)
3615 g_object_ref (widget);
3616 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3617 if (!nqueue || !nqueue->freeze_count)
3618 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3619 G_OBJECT_TYPE_NAME (widget), widget);
3621 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3622 g_object_unref (widget);
3628 * @type: type ID of the widget to create
3629 * @first_property_name: name of first property to set
3630 * @Varargs: value of first property, followed by more properties,
3633 * This is a convenience function for creating a widget and setting
3634 * its properties in one go. For example you might write:
3635 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3636 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3637 * g_object_new(), but returns a widget so you don't have to
3638 * cast the object yourself.
3640 * Return value: a new #GtkWidget of type @widget_type
3643 gtk_widget_new (GType type,
3644 const gchar *first_property_name,
3650 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3652 va_start (var_args, first_property_name);
3653 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3660 gtk_widget_queue_draw_child (GtkWidget *widget)
3662 GtkWidgetPrivate *priv = widget->priv;
3665 parent = priv->parent;
3666 if (parent && gtk_widget_is_drawable (parent))
3667 gtk_widget_queue_draw_area (parent,
3670 priv->allocation.width,
3671 priv->allocation.height);
3675 * gtk_widget_unparent:
3676 * @widget: a #GtkWidget
3678 * This function is only for use in widget implementations.
3679 * Should be called by implementations of the remove method
3680 * on #GtkContainer, to dissociate a child from the container.
3683 gtk_widget_unparent (GtkWidget *widget)
3685 GtkWidgetPrivate *priv;
3686 GObjectNotifyQueue *nqueue;
3687 GtkWidget *toplevel;
3688 GtkWidget *old_parent;
3690 g_return_if_fail (GTK_IS_WIDGET (widget));
3692 priv = widget->priv;
3694 if (priv->parent == NULL)
3697 /* keep this function in sync with gtk_menu_detach()
3700 g_object_freeze_notify (G_OBJECT (widget));
3701 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3703 toplevel = gtk_widget_get_toplevel (widget);
3704 if (gtk_widget_is_toplevel (toplevel))
3705 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3707 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3708 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3710 /* If we are unanchoring the child, we save around the toplevel
3711 * to emit hierarchy changed
3713 if (priv->parent->priv->anchored)
3714 g_object_ref (toplevel);
3718 gtk_widget_queue_draw_child (widget);
3720 /* Reset the width and height here, to force reallocation if we
3721 * get added back to a new parent. This won't work if our new
3722 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3723 * (would 0x0 be OK here?)
3725 priv->allocation.width = 1;
3726 priv->allocation.height = 1;
3728 if (gtk_widget_get_realized (widget))
3730 if (priv->in_reparent)
3731 gtk_widget_unmap (widget);
3733 gtk_widget_unrealize (widget);
3736 /* Removing a widget from a container restores the child visible
3737 * flag to the default state, so it doesn't affect the child
3738 * in the next parent.
3740 priv->child_visible = TRUE;
3742 old_parent = priv->parent;
3743 priv->parent = NULL;
3744 gtk_widget_set_parent_window (widget, NULL);
3746 /* parent may no longer expand if the removed
3747 * child was expand=TRUE and could therefore
3750 if (gtk_widget_get_visible (widget) &&
3751 (priv->need_compute_expand ||
3752 priv->computed_hexpand ||
3753 priv->computed_vexpand))
3755 gtk_widget_queue_compute_expand (old_parent);
3758 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3761 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3762 g_object_unref (toplevel);
3765 g_object_notify (G_OBJECT (widget), "parent");
3766 g_object_thaw_notify (G_OBJECT (widget));
3768 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3769 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3770 g_object_unref (widget);
3774 * gtk_widget_destroy:
3775 * @widget: a #GtkWidget
3777 * Destroys a widget.
3780 * destroyed, it will break any references it holds to other objects.
3781 * If the widget is inside a container, the widget will be removed
3782 * from the container. If the widget is a toplevel (derived from
3783 * #GtkWindow), it will be removed from the list of toplevels, and the
3784 * reference GTK+ holds to it will be removed. Removing a
3785 * widget from its container or the list of toplevels results in the
3786 * widget being finalized, unless you've added additional references
3787 * to the widget with g_object_ref().
3789 * In most cases, only toplevel widgets (windows) require explicit
3790 * destruction, because when you destroy a toplevel its children will
3791 * be destroyed as well.
3794 gtk_widget_destroy (GtkWidget *widget)
3796 g_return_if_fail (GTK_IS_WIDGET (widget));
3798 if (!widget->priv->in_destruction)
3799 g_object_run_dispose (G_OBJECT (widget));
3803 * gtk_widget_destroyed:
3804 * @widget: a #GtkWidget
3805 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3807 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3808 * %NULL. It's intended to be used as a callback connected to the
3809 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3810 * as a signal handler, and pass the address of your widget variable
3811 * as user data. Then when the widget is destroyed, the variable will
3812 * be set to %NULL. Useful for example to avoid multiple copies
3813 * of the same dialog.
3816 gtk_widget_destroyed (GtkWidget *widget,
3817 GtkWidget **widget_pointer)
3819 /* Don't make any assumptions about the
3821 * Even check widget_pointer.
3824 *widget_pointer = NULL;
3829 * @widget: a #GtkWidget
3831 * Flags a widget to be displayed. Any widget that isn't shown will
3832 * not appear on the screen. If you want to show all the widgets in a
3833 * container, it's easier to call gtk_widget_show_all() on the
3834 * container, instead of individually showing the widgets.
3836 * Remember that you have to show the containers containing a widget,
3837 * in addition to the widget itself, before it will appear onscreen.
3839 * When a toplevel container is shown, it is immediately realized and
3840 * mapped; other shown widgets are realized and mapped when their
3841 * toplevel container is realized and mapped.
3844 gtk_widget_show (GtkWidget *widget)
3846 g_return_if_fail (GTK_IS_WIDGET (widget));
3848 if (!gtk_widget_get_visible (widget))
3850 g_object_ref (widget);
3851 if (!gtk_widget_is_toplevel (widget))
3852 gtk_widget_queue_resize (widget);
3854 /* see comment in set_parent() for why this should and can be
3857 if (widget->priv->need_compute_expand ||
3858 widget->priv->computed_hexpand ||
3859 widget->priv->computed_vexpand)
3861 if (widget->priv->parent != NULL)
3862 gtk_widget_queue_compute_expand (widget->priv->parent);
3865 g_signal_emit (widget, widget_signals[SHOW], 0);
3866 g_object_notify (G_OBJECT (widget), "visible");
3867 g_object_unref (widget);
3872 gtk_widget_real_show (GtkWidget *widget)
3874 GtkWidgetPrivate *priv = widget->priv;
3876 if (!gtk_widget_get_visible (widget))
3878 priv->visible = TRUE;
3881 gtk_widget_get_mapped (priv->parent) &&
3882 gtk_widget_get_child_visible (widget) &&
3883 !gtk_widget_get_mapped (widget))
3884 gtk_widget_map (widget);
3889 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3892 g_signal_handlers_disconnect_by_func (widget,
3893 gtk_widget_show_map_callback,
3898 * gtk_widget_show_now:
3899 * @widget: a #GtkWidget
3901 * Shows a widget. If the widget is an unmapped toplevel widget
3902 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3903 * loop and wait for the window to actually be mapped. Be careful;
3904 * because the main loop is running, anything can happen during
3908 gtk_widget_show_now (GtkWidget *widget)
3912 g_return_if_fail (GTK_IS_WIDGET (widget));
3914 /* make sure we will get event */
3915 if (!gtk_widget_get_mapped (widget) &&
3916 gtk_widget_is_toplevel (widget))
3918 gtk_widget_show (widget);
3920 g_signal_connect (widget, "map-event",
3921 G_CALLBACK (gtk_widget_show_map_callback),
3925 gtk_main_iteration ();
3928 gtk_widget_show (widget);
3933 * @widget: a #GtkWidget
3935 * Reverses the effects of gtk_widget_show(), causing the widget to be
3936 * hidden (invisible to the user).
3939 gtk_widget_hide (GtkWidget *widget)
3941 g_return_if_fail (GTK_IS_WIDGET (widget));
3943 if (gtk_widget_get_visible (widget))
3945 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3947 g_object_ref (widget);
3948 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3949 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3951 /* a parent may now be expand=FALSE since we're hidden. */
3952 if (widget->priv->need_compute_expand ||
3953 widget->priv->computed_hexpand ||
3954 widget->priv->computed_vexpand)
3956 gtk_widget_queue_compute_expand (widget);
3959 g_signal_emit (widget, widget_signals[HIDE], 0);
3960 if (!gtk_widget_is_toplevel (widget))
3961 gtk_widget_queue_resize (widget);
3962 g_object_notify (G_OBJECT (widget), "visible");
3963 g_object_unref (widget);
3968 gtk_widget_real_hide (GtkWidget *widget)
3970 if (gtk_widget_get_visible (widget))
3972 widget->priv->visible = FALSE;
3974 if (gtk_widget_get_mapped (widget))
3975 gtk_widget_unmap (widget);
3980 * gtk_widget_hide_on_delete:
3981 * @widget: a #GtkWidget
3983 * Utility function; intended to be connected to the #GtkWidget::delete-event
3984 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3985 * argument, then returns %TRUE. If connected to ::delete-event, the
3986 * result is that clicking the close button for a window (on the
3987 * window frame, top right corner usually) will hide but not destroy
3988 * the window. By default, GTK+ destroys windows when ::delete-event
3991 * Return value: %TRUE
3994 gtk_widget_hide_on_delete (GtkWidget *widget)
3996 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3998 gtk_widget_hide (widget);
4004 * gtk_widget_show_all:
4005 * @widget: a #GtkWidget
4007 * Recursively shows a widget, and any child widgets (if the widget is
4011 gtk_widget_show_all (GtkWidget *widget)
4013 GtkWidgetClass *class;
4015 g_return_if_fail (GTK_IS_WIDGET (widget));
4017 if (gtk_widget_get_no_show_all (widget))
4020 class = GTK_WIDGET_GET_CLASS (widget);
4022 if (class->show_all)
4023 class->show_all (widget);
4027 _gtk_widget_notify_state_change (GtkWidget *widget,
4035 case GTK_STATE_FLAG_ACTIVE:
4036 state = GTK_STATE_ACTIVE;
4038 case GTK_STATE_FLAG_PRELIGHT:
4039 state = GTK_STATE_PRELIGHT;
4041 case GTK_STATE_FLAG_SELECTED:
4042 state = GTK_STATE_SELECTED;
4044 case GTK_STATE_FLAG_INSENSITIVE:
4045 state = GTK_STATE_INSENSITIVE;
4047 case GTK_STATE_FLAG_INCONSISTENT:
4048 state = GTK_STATE_INCONSISTENT;
4050 case GTK_STATE_FLAG_FOCUSED:
4051 state = GTK_STATE_FOCUSED;
4057 gtk_style_context_notify_state_change (widget->priv->context,
4058 gtk_widget_get_window (widget),
4059 NULL, state, target);
4062 /* Initializes state transitions for those states that
4063 * were enabled before mapping and have a looping animation.
4066 _gtk_widget_start_state_transitions (GtkWidget *widget)
4068 GtkStateFlags state, flag;
4070 if (!widget->priv->context)
4073 state = gtk_widget_get_state_flags (widget);
4074 flag = GTK_STATE_FLAG_FOCUSED;
4078 GtkAnimationDescription *animation_desc;
4080 if ((state & flag) == 0)
4086 gtk_style_context_get (widget->priv->context, state,
4087 "transition", &animation_desc,
4092 if (_gtk_animation_description_get_loop (animation_desc))
4093 _gtk_widget_notify_state_change (widget, flag, TRUE);
4095 _gtk_animation_description_unref (animation_desc);
4104 * @widget: a #GtkWidget
4106 * This function is only for use in widget implementations. Causes
4107 * a widget to be mapped if it isn't already.
4110 gtk_widget_map (GtkWidget *widget)
4112 GtkWidgetPrivate *priv;
4114 g_return_if_fail (GTK_IS_WIDGET (widget));
4115 g_return_if_fail (gtk_widget_get_visible (widget));
4116 g_return_if_fail (gtk_widget_get_child_visible (widget));
4118 priv = widget->priv;
4120 if (!gtk_widget_get_mapped (widget))
4122 if (!gtk_widget_get_realized (widget))
4123 gtk_widget_realize (widget);
4125 g_signal_emit (widget, widget_signals[MAP], 0);
4127 if (!gtk_widget_get_has_window (widget))
4128 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4130 _gtk_widget_start_state_transitions (widget);
4136 * @widget: a #GtkWidget
4138 * This function is only for use in widget implementations. Causes
4139 * a widget to be unmapped if it's currently mapped.
4142 gtk_widget_unmap (GtkWidget *widget)
4144 GtkWidgetPrivate *priv;
4146 g_return_if_fail (GTK_IS_WIDGET (widget));
4148 priv = widget->priv;
4150 if (gtk_widget_get_mapped (widget))
4152 if (!gtk_widget_get_has_window (widget))
4153 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4154 _gtk_tooltip_hide (widget);
4155 g_signal_emit (widget, widget_signals[UNMAP], 0);
4160 _gtk_widget_enable_device_events (GtkWidget *widget)
4162 GHashTable *device_events;
4163 GHashTableIter iter;
4164 gpointer key, value;
4166 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4171 g_hash_table_iter_init (&iter, device_events);
4173 while (g_hash_table_iter_next (&iter, &key, &value))
4176 GdkEventMask event_mask;
4179 event_mask = GPOINTER_TO_UINT (value);
4180 gtk_widget_add_events_internal (widget, device, event_mask);
4185 * gtk_widget_realize:
4186 * @widget: a #GtkWidget
4188 * Creates the GDK (windowing system) resources associated with a
4189 * widget. For example, @widget->window will be created when a widget
4190 * is realized. Normally realization happens implicitly; if you show
4191 * a widget and all its parent containers, then the widget will be
4192 * realized and mapped automatically.
4194 * Realizing a widget requires all
4195 * the widget's parent widgets to be realized; calling
4196 * gtk_widget_realize() realizes the widget's parents in addition to
4197 * @widget itself. If a widget is not yet inside a toplevel window
4198 * when you realize it, bad things will happen.
4200 * This function is primarily used in widget implementations, and
4201 * isn't very useful otherwise. Many times when you think you might
4202 * need it, a better approach is to connect to a signal that will be
4203 * called after the widget is realized automatically, such as
4204 * #GtkWidget::expose-event. Or simply g_signal_connect () to the
4205 * #GtkWidget::realize signal.
4208 gtk_widget_realize (GtkWidget *widget)
4210 GtkWidgetPrivate *priv;
4211 cairo_region_t *region;
4213 g_return_if_fail (GTK_IS_WIDGET (widget));
4214 g_return_if_fail (widget->priv->anchored ||
4215 GTK_IS_INVISIBLE (widget));
4217 priv = widget->priv;
4219 if (!gtk_widget_get_realized (widget))
4222 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4223 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4226 if (priv->parent == NULL &&
4227 !gtk_widget_is_toplevel (widget))
4228 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4229 "inside a toplevel window is not going to work very well. "
4230 "Widgets must be inside a toplevel container before realizing them.");
4232 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4233 gtk_widget_realize (priv->parent);
4235 gtk_widget_ensure_style (widget);
4237 g_signal_emit (widget, widget_signals[REALIZE], 0);
4239 gtk_widget_real_set_has_tooltip (widget,
4240 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4243 if (priv->has_shape_mask)
4245 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4246 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4249 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4251 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4253 if (priv->multidevice)
4254 gdk_window_set_support_multidevice (priv->window, TRUE);
4256 _gtk_widget_enable_device_events (widget);
4261 * gtk_widget_unrealize:
4262 * @widget: a #GtkWidget
4264 * This function is only useful in widget implementations.
4265 * Causes a widget to be unrealized (frees all GDK resources
4266 * associated with the widget, such as @widget->window).
4269 gtk_widget_unrealize (GtkWidget *widget)
4271 g_return_if_fail (GTK_IS_WIDGET (widget));
4273 if (widget->priv->has_shape_mask)
4274 gtk_widget_shape_combine_region (widget, NULL);
4276 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4277 gtk_widget_input_shape_combine_region (widget, NULL);
4279 if (gtk_widget_get_realized (widget))
4281 g_object_ref (widget);
4282 _gtk_tooltip_hide (widget);
4283 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4284 gtk_widget_set_realized (widget, FALSE);
4285 gtk_widget_set_mapped (widget, FALSE);
4286 g_object_unref (widget);
4290 /*****************************************
4292 *****************************************/
4295 * gtk_widget_queue_draw_region:
4296 * @widget: a #GtkWidget
4297 * @region: region to draw
4299 * Invalidates the rectangular area of @widget defined by @region by
4300 * calling gdk_window_invalidate_region() on the widget's window and
4301 * all its child windows. Once the main loop becomes idle (after the
4302 * current batch of events has been processed, roughly), the window
4303 * will receive expose events for the union of all regions that have
4306 * Normally you would only use this function in widget
4307 * implementations. You might also use it to schedule a redraw of a
4308 * #GtkDrawingArea or some portion thereof.
4311 gtk_widget_queue_draw_region (GtkWidget *widget,
4312 cairo_region_t *region)
4314 GtkWidgetPrivate *priv;
4317 g_return_if_fail (GTK_IS_WIDGET (widget));
4319 priv = widget->priv;
4321 if (!gtk_widget_get_realized (widget))
4324 /* Just return if the widget or one of its ancestors isn't mapped */
4325 for (w = widget; w != NULL; w = w->priv->parent)
4326 if (!gtk_widget_get_mapped (w))
4329 gdk_window_invalidate_region (priv->window, region, TRUE);
4333 * gtk_widget_queue_draw_area:
4334 * @widget: a #GtkWidget
4335 * @x: x coordinate of upper-left corner of rectangle to redraw
4336 * @y: y coordinate of upper-left corner of rectangle to redraw
4337 * @width: width of region to draw
4338 * @height: height of region to draw
4340 * Convenience function that calls gtk_widget_queue_draw_region() on
4341 * the region created from the given coordinates.
4344 gtk_widget_queue_draw_area (GtkWidget *widget,
4351 cairo_region_t *region;
4353 g_return_if_fail (GTK_IS_WIDGET (widget));
4358 rect.height = height;
4360 region = cairo_region_create_rectangle (&rect);
4361 gtk_widget_queue_draw_region (widget, region);
4362 cairo_region_destroy (region);
4366 * gtk_widget_queue_draw:
4367 * @widget: a #GtkWidget
4369 * Equivalent to calling gtk_widget_queue_draw_area() for the
4370 * entire area of a widget.
4373 gtk_widget_queue_draw (GtkWidget *widget)
4377 g_return_if_fail (GTK_IS_WIDGET (widget));
4379 gtk_widget_get_allocation (widget, &rect);
4381 if (!gtk_widget_get_has_window (widget))
4382 gtk_widget_queue_draw_area (widget,
4383 rect.x, rect.y, rect.width, rect.height);
4385 gtk_widget_queue_draw_area (widget,
4386 0, 0, rect.width, rect.height);
4390 * gtk_widget_queue_resize:
4391 * @widget: a #GtkWidget
4393 * This function is only for use in widget implementations.
4394 * Flags a widget to have its size renegotiated; should
4395 * be called when a widget for some reason has a new size request.
4396 * For example, when you change the text in a #GtkLabel, #GtkLabel
4397 * queues a resize to ensure there's enough space for the new text.
4399 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4400 * from inside it's implementation of the GtkWidgetClass::size_allocate
4401 * virtual method. Calls to gtk_widget_queue_resize() from inside
4402 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4405 gtk_widget_queue_resize (GtkWidget *widget)
4407 g_return_if_fail (GTK_IS_WIDGET (widget));
4409 if (gtk_widget_get_realized (widget))
4410 gtk_widget_queue_shallow_draw (widget);
4412 _gtk_size_group_queue_resize (widget, 0);
4416 * gtk_widget_queue_resize_no_redraw:
4417 * @widget: a #GtkWidget
4419 * This function works like gtk_widget_queue_resize(),
4420 * except that the widget is not invalidated.
4425 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4427 g_return_if_fail (GTK_IS_WIDGET (widget));
4429 _gtk_size_group_queue_resize (widget, 0);
4433 * gtk_widget_size_request:
4434 * @widget: a #GtkWidget
4435 * @requisition: (out): a #GtkRequisition to be filled in
4437 * This function is typically used when implementing a #GtkContainer
4438 * subclass. Obtains the preferred size of a widget. The container
4439 * uses this information to arrange its child widgets and decide what
4440 * size allocations to give them with gtk_widget_size_allocate().
4442 * You can also call this function from an application, with some
4443 * caveats. Most notably, getting a size request requires the widget
4444 * to be associated with a screen, because font information may be
4445 * needed. Multihead-aware applications should keep this in mind.
4447 * Also remember that the size request is not necessarily the size
4448 * a widget will actually be allocated.
4450 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4453 gtk_widget_size_request (GtkWidget *widget,
4454 GtkRequisition *requisition)
4456 g_return_if_fail (GTK_IS_WIDGET (widget));
4458 gtk_widget_get_preferred_size (widget, requisition, NULL);
4462 * gtk_widget_get_child_requisition:
4463 * @widget: a #GtkWidget
4464 * @requisition: (out): a #GtkRequisition to be filled in
4466 * This function is only for use in widget implementations. Obtains
4467 * @widget->requisition, unless someone has forced a particular
4468 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4469 * in which case it returns that geometry instead of the widget's
4472 * This function differs from gtk_widget_size_request() in that
4473 * it retrieves the last size request value from @widget->requisition,
4474 * while gtk_widget_size_request() actually calls the "size_request" method
4475 * on @widget to compute the size request and fill in @widget->requisition,
4476 * and only then returns @widget->requisition.
4478 * Because this function does not call the "size_request" method, it
4479 * can only be used when you know that @widget->requisition is
4480 * up-to-date, that is, gtk_widget_size_request() has been called
4481 * since the last time a resize was queued. In general, only container
4482 * implementations have this information; applications should use
4483 * gtk_widget_size_request().
4486 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4489 gtk_widget_get_child_requisition (GtkWidget *widget,
4490 GtkRequisition *requisition)
4492 gtk_widget_get_preferred_size (widget, requisition, NULL);
4496 invalidate_predicate (GdkWindow *window,
4501 gdk_window_get_user_data (window, &user_data);
4503 return (user_data == data);
4506 /* Invalidate @region in widget->window and all children
4507 * of widget->window owned by widget. @region is in the
4508 * same coordinates as widget->allocation and will be
4509 * modified by this call.
4512 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4513 cairo_region_t *region)
4515 GtkWidgetPrivate *priv = widget->priv;
4517 if (!gtk_widget_get_realized (widget))
4520 if (gtk_widget_get_has_window (widget) && priv->parent)
4524 gdk_window_get_position (priv->window, &x, &y);
4525 cairo_region_translate (region, -x, -y);
4528 gdk_window_invalidate_maybe_recurse (priv->window, region,
4529 invalidate_predicate, widget);
4533 * gtk_widget_queue_shallow_draw:
4534 * @widget: a #GtkWidget
4536 * Like gtk_widget_queue_draw(), but only windows owned
4537 * by @widget are invalidated.
4540 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4543 cairo_region_t *region;
4545 if (!gtk_widget_get_realized (widget))
4548 gtk_widget_get_allocation (widget, &rect);
4550 region = cairo_region_create_rectangle (&rect);
4551 gtk_widget_invalidate_widget_windows (widget, region);
4552 cairo_region_destroy (region);
4556 * gtk_widget_size_allocate:
4557 * @widget: a #GtkWidget
4558 * @allocation: (inout): position and size to be allocated to @widget
4560 * This function is only used by #GtkContainer subclasses, to assign a size
4561 * and position to their child widgets.
4563 * In this function, the allocation may be adjusted. It will be forced
4564 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4565 * method on the child will be used to adjust the allocation. Standard
4566 * adjustments include removing the widget's margins, and applying the
4567 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4570 gtk_widget_size_allocate (GtkWidget *widget,
4571 GtkAllocation *allocation)
4573 GtkWidgetPrivate *priv;
4574 GdkRectangle real_allocation;
4575 GdkRectangle old_allocation;
4576 GdkRectangle adjusted_allocation;
4577 gboolean alloc_needed;
4578 gboolean size_changed;
4579 gboolean position_changed;
4580 gint natural_width, natural_height, dummy;
4581 gint min_width, min_height;
4583 priv = widget->priv;
4585 g_return_if_fail (GTK_IS_WIDGET (widget));
4587 #ifdef G_ENABLE_DEBUG
4588 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4599 parent = gtk_widget_get_parent (parent);
4602 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4603 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4604 2 * depth, " ", name,
4605 allocation->width, allocation->height);
4607 #endif /* G_ENABLE_DEBUG */
4609 alloc_needed = priv->alloc_needed;
4610 if (!priv->width_request_needed && !priv->height_request_needed)
4611 /* Preserve request/allocate ordering */
4612 priv->alloc_needed = FALSE;
4614 old_allocation = priv->allocation;
4615 real_allocation = *allocation;
4617 adjusted_allocation = real_allocation;
4618 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4620 /* Go ahead and request the height for allocated width, note that the internals
4621 * of get_height_for_width will internally limit the for_size to natural size
4622 * when aligning implicitly.
4624 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4625 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &dummy, &natural_height);
4629 /* Go ahead and request the width for allocated height, note that the internals
4630 * of get_width_for_height will internally limit the for_size to natural size
4631 * when aligning implicitly.
4633 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4634 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &dummy, &natural_width);
4637 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4638 * allocated sizes and possibly limit them to the natural sizes */
4639 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4640 GTK_ORIENTATION_HORIZONTAL,
4643 &adjusted_allocation.x,
4644 &adjusted_allocation.width);
4645 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4646 GTK_ORIENTATION_VERTICAL,
4649 &adjusted_allocation.y,
4650 &adjusted_allocation.height);
4652 if (adjusted_allocation.x < real_allocation.x ||
4653 adjusted_allocation.y < real_allocation.y ||
4654 (adjusted_allocation.x + adjusted_allocation.width) >
4655 (real_allocation.x + real_allocation.width) ||
4656 (adjusted_allocation.y + adjusted_allocation.height >
4657 real_allocation.y + real_allocation.height))
4659 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",
4660 G_OBJECT_TYPE_NAME (widget), widget,
4661 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4662 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4663 adjusted_allocation = real_allocation; /* veto it */
4667 real_allocation = adjusted_allocation;
4670 if (real_allocation.width < 0 || real_allocation.height < 0)
4672 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4673 real_allocation.width,
4674 real_allocation.height);
4677 real_allocation.width = MAX (real_allocation.width, 1);
4678 real_allocation.height = MAX (real_allocation.height, 1);
4680 size_changed = (old_allocation.width != real_allocation.width ||
4681 old_allocation.height != real_allocation.height);
4682 position_changed = (old_allocation.x != real_allocation.x ||
4683 old_allocation.y != real_allocation.y);
4685 if (!alloc_needed && !size_changed && !position_changed)
4688 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4690 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4691 priv->width_request_needed = FALSE;
4692 priv->height_request_needed = FALSE;
4693 priv->alloc_needed = FALSE;
4695 if (gtk_widget_get_mapped (widget))
4697 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4699 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4701 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4702 cairo_region_union_rectangle (invalidate, &old_allocation);
4704 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4705 cairo_region_destroy (invalidate);
4710 if (priv->redraw_on_alloc)
4712 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4714 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4715 cairo_region_union_rectangle (invalidate, &old_allocation);
4717 gtk_widget_invalidate_widget_windows (widget, invalidate);
4718 cairo_region_destroy (invalidate);
4722 if (size_changed || position_changed)
4724 GtkStyleContext *context;
4726 context = gtk_widget_get_style_context (widget);
4727 _gtk_style_context_invalidate_animation_areas (context);
4731 if ((size_changed || position_changed) && priv->parent &&
4732 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4734 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4735 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4736 cairo_region_destroy (invalidate);
4741 * gtk_widget_common_ancestor:
4742 * @widget_a: a #GtkWidget
4743 * @widget_b: a #GtkWidget
4745 * Find the common ancestor of @widget_a and @widget_b that
4746 * is closest to the two widgets.
4748 * Return value: the closest common ancestor of @widget_a and
4749 * @widget_b or %NULL if @widget_a and @widget_b do not
4750 * share a common ancestor.
4753 gtk_widget_common_ancestor (GtkWidget *widget_a,
4754 GtkWidget *widget_b)
4756 GtkWidget *parent_a;
4757 GtkWidget *parent_b;
4761 parent_a = widget_a;
4762 while (parent_a->priv->parent)
4764 parent_a = parent_a->priv->parent;
4768 parent_b = widget_b;
4769 while (parent_b->priv->parent)
4771 parent_b = parent_b->priv->parent;
4775 if (parent_a != parent_b)
4778 while (depth_a > depth_b)
4780 widget_a = widget_a->priv->parent;
4784 while (depth_b > depth_a)
4786 widget_b = widget_b->priv->parent;
4790 while (widget_a != widget_b)
4792 widget_a = widget_a->priv->parent;
4793 widget_b = widget_b->priv->parent;
4800 * gtk_widget_translate_coordinates:
4801 * @src_widget: a #GtkWidget
4802 * @dest_widget: a #GtkWidget
4803 * @src_x: X position relative to @src_widget
4804 * @src_y: Y position relative to @src_widget
4805 * @dest_x: (out): location to store X position relative to @dest_widget
4806 * @dest_y: (out): location to store Y position relative to @dest_widget
4808 * Translate coordinates relative to @src_widget's allocation to coordinates
4809 * relative to @dest_widget's allocations. In order to perform this
4810 * operation, both widgets must be realized, and must share a common
4813 * Return value: %FALSE if either widget was not realized, or there
4814 * was no common ancestor. In this case, nothing is stored in
4815 * *@dest_x and *@dest_y. Otherwise %TRUE.
4818 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4819 GtkWidget *dest_widget,
4825 GtkWidgetPrivate *src_priv = src_widget->priv;
4826 GtkWidgetPrivate *dest_priv = dest_widget->priv;
4827 GtkWidget *ancestor;
4829 GList *dest_list = NULL;
4831 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4832 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4834 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4835 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4838 /* Translate from allocation relative to window relative */
4839 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
4842 gdk_window_get_position (src_priv->window, &wx, &wy);
4844 src_x -= wx - src_priv->allocation.x;
4845 src_y -= wy - src_priv->allocation.y;
4849 src_x += src_priv->allocation.x;
4850 src_y += src_priv->allocation.y;
4853 /* Translate to the common ancestor */
4854 window = src_priv->window;
4855 while (window != ancestor->priv->window)
4859 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4864 window = gdk_window_get_effective_parent (window);
4866 if (!window) /* Handle GtkHandleBox */
4871 window = dest_priv->window;
4872 while (window != ancestor->priv->window)
4874 dest_list = g_list_prepend (dest_list, window);
4876 window = gdk_window_get_effective_parent (window);
4878 if (!window) /* Handle GtkHandleBox */
4880 g_list_free (dest_list);
4889 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4894 dest_list = g_list_remove (dest_list, dest_list->data);
4897 /* Translate from window relative to allocation relative */
4898 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
4901 gdk_window_get_position (dest_priv->window, &wx, &wy);
4903 src_x += wx - dest_priv->allocation.x;
4904 src_y += wy - dest_priv->allocation.y;
4908 src_x -= dest_priv->allocation.x;
4909 src_y -= dest_priv->allocation.y;
4921 gtk_widget_real_size_allocate (GtkWidget *widget,
4922 GtkAllocation *allocation)
4924 GtkWidgetPrivate *priv = widget->priv;
4926 priv->allocation = *allocation;
4928 if (gtk_widget_get_realized (widget) &&
4929 gtk_widget_get_has_window (widget))
4931 gdk_window_move_resize (priv->window,
4932 allocation->x, allocation->y,
4933 allocation->width, allocation->height);
4938 adjust_for_align(GtkAlign align,
4940 gint *allocated_pos,
4941 gint *allocated_size)
4945 case GTK_ALIGN_FILL:
4946 /* change nothing */
4948 case GTK_ALIGN_START:
4949 /* keep *allocated_pos where it is */
4950 *allocated_size = MIN (*allocated_size, *natural_size);
4953 if (*allocated_size > *natural_size)
4955 *allocated_pos += (*allocated_size - *natural_size);
4956 *allocated_size = *natural_size;
4959 case GTK_ALIGN_CENTER:
4960 if (*allocated_size > *natural_size)
4962 *allocated_pos += (*allocated_size - *natural_size) / 2;
4963 *allocated_size = MIN (*allocated_size, *natural_size);
4970 adjust_for_margin(gint start_margin,
4974 gint *allocated_pos,
4975 gint *allocated_size)
4977 *minimum_size -= (start_margin + end_margin);
4978 *natural_size -= (start_margin + end_margin);
4979 *allocated_pos += start_margin;
4980 *allocated_size -= (start_margin + end_margin);
4984 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
4985 GtkOrientation orientation,
4988 gint *allocated_pos,
4989 gint *allocated_size)
4991 const GtkWidgetAuxInfo *aux_info;
4993 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
4995 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4997 adjust_for_margin (aux_info->margin.left,
4998 aux_info->margin.right,
4999 minimum_size, natural_size,
5000 allocated_pos, allocated_size);
5001 adjust_for_align (aux_info->halign,
5002 natural_size, allocated_pos, allocated_size);
5006 adjust_for_margin (aux_info->margin.top,
5007 aux_info->margin.bottom,
5008 minimum_size, natural_size,
5009 allocated_pos, allocated_size);
5010 adjust_for_align (aux_info->valign,
5011 natural_size, allocated_pos, allocated_size);
5016 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5019 GtkWidgetPrivate *priv = widget->priv;
5021 /* widgets must be onscreen for accels to take effect */
5022 return gtk_widget_is_sensitive (widget) &&
5023 gtk_widget_is_drawable (widget) &&
5024 gdk_window_is_viewable (priv->window);
5028 * gtk_widget_can_activate_accel:
5029 * @widget: a #GtkWidget
5030 * @signal_id: the ID of a signal installed on @widget
5032 * Determines whether an accelerator that activates the signal
5033 * identified by @signal_id can currently be activated.
5034 * This is done by emitting the #GtkWidget::can-activate-accel
5035 * signal on @widget; if the signal isn't overridden by a
5036 * handler or in a derived widget, then the default check is
5037 * that the widget must be sensitive, and the widget and all
5038 * its ancestors mapped.
5040 * Return value: %TRUE if the accelerator can be activated.
5045 gtk_widget_can_activate_accel (GtkWidget *widget,
5048 gboolean can_activate = FALSE;
5049 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5050 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5051 return can_activate;
5060 closure_accel_activate (GClosure *closure,
5061 GValue *return_value,
5062 guint n_param_values,
5063 const GValue *param_values,
5064 gpointer invocation_hint,
5065 gpointer marshal_data)
5067 AccelClosure *aclosure = (AccelClosure*) closure;
5068 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5071 g_signal_emit (closure->data, aclosure->signal_id, 0);
5073 /* whether accelerator was handled */
5074 g_value_set_boolean (return_value, can_activate);
5078 closures_destroy (gpointer data)
5080 GSList *slist, *closures = data;
5082 for (slist = closures; slist; slist = slist->next)
5084 g_closure_invalidate (slist->data);
5085 g_closure_unref (slist->data);
5087 g_slist_free (closures);
5091 widget_new_accel_closure (GtkWidget *widget,
5094 AccelClosure *aclosure;
5095 GClosure *closure = NULL;
5096 GSList *slist, *closures;
5098 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5099 for (slist = closures; slist; slist = slist->next)
5100 if (!gtk_accel_group_from_accel_closure (slist->data))
5102 /* reuse this closure */
5103 closure = slist->data;
5108 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5109 closures = g_slist_prepend (closures, g_closure_ref (closure));
5110 g_closure_sink (closure);
5111 g_closure_set_marshal (closure, closure_accel_activate);
5113 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5115 aclosure = (AccelClosure*) closure;
5116 g_assert (closure->data == widget);
5117 g_assert (closure->marshal == closure_accel_activate);
5118 aclosure->signal_id = signal_id;
5124 * gtk_widget_add_accelerator
5125 * @widget: widget to install an accelerator on
5126 * @accel_signal: widget signal to emit on accelerator activation
5127 * @accel_group: accel group for this widget, added to its toplevel
5128 * @accel_key: GDK keyval of the accelerator
5129 * @accel_mods: modifier key combination of the accelerator
5130 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5132 * Installs an accelerator for this @widget in @accel_group that causes
5133 * @accel_signal to be emitted if the accelerator is activated.
5134 * The @accel_group needs to be added to the widget's toplevel via
5135 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5136 * Accelerators added through this function are not user changeable during
5137 * runtime. If you want to support accelerators that can be changed by the
5138 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5139 * gtk_menu_item_set_accel_path() instead.
5142 gtk_widget_add_accelerator (GtkWidget *widget,
5143 const gchar *accel_signal,
5144 GtkAccelGroup *accel_group,
5146 GdkModifierType accel_mods,
5147 GtkAccelFlags accel_flags)
5152 g_return_if_fail (GTK_IS_WIDGET (widget));
5153 g_return_if_fail (accel_signal != NULL);
5154 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5156 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5157 if (!query.signal_id ||
5158 !(query.signal_flags & G_SIGNAL_ACTION) ||
5159 query.return_type != G_TYPE_NONE ||
5162 /* hmm, should be elaborate enough */
5163 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5164 G_OBJECT_TYPE_NAME (widget), accel_signal);
5168 closure = widget_new_accel_closure (widget, query.signal_id);
5170 g_object_ref (widget);
5172 /* install the accelerator. since we don't map this onto an accel_path,
5173 * the accelerator will automatically be locked.
5175 gtk_accel_group_connect (accel_group,
5178 accel_flags | GTK_ACCEL_LOCKED,
5181 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5183 g_object_unref (widget);
5187 * gtk_widget_remove_accelerator:
5188 * @widget: widget to install an accelerator on
5189 * @accel_group: accel group for this widget
5190 * @accel_key: GDK keyval of the accelerator
5191 * @accel_mods: modifier key combination of the accelerator
5192 * @returns: whether an accelerator was installed and could be removed
5194 * Removes an accelerator from @widget, previously installed with
5195 * gtk_widget_add_accelerator().
5198 gtk_widget_remove_accelerator (GtkWidget *widget,
5199 GtkAccelGroup *accel_group,
5201 GdkModifierType accel_mods)
5203 GtkAccelGroupEntry *ag_entry;
5204 GList *slist, *clist;
5207 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5208 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5210 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5211 clist = gtk_widget_list_accel_closures (widget);
5212 for (slist = clist; slist; slist = slist->next)
5216 for (i = 0; i < n; i++)
5217 if (slist->data == (gpointer) ag_entry[i].closure)
5219 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5221 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5223 g_list_free (clist);
5228 g_list_free (clist);
5230 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5231 accel_key, accel_mods, accel_group,
5232 G_OBJECT_TYPE_NAME (widget), widget);
5238 * gtk_widget_list_accel_closures:
5239 * @widget: widget to list accelerator closures for
5241 * Lists the closures used by @widget for accelerator group connections
5242 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5243 * The closures can be used to monitor accelerator changes on @widget,
5244 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5245 * #GtkAccelGroup of a closure which can be found out with
5246 * gtk_accel_group_from_accel_closure().
5248 * Return value: (transfer container) (element-type GClosure):
5249 * a newly allocated #GList of closures
5252 gtk_widget_list_accel_closures (GtkWidget *widget)
5255 GList *clist = NULL;
5257 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5259 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5260 if (gtk_accel_group_from_accel_closure (slist->data))
5261 clist = g_list_prepend (clist, slist->data);
5267 GtkAccelGroup *accel_group;
5272 destroy_accel_path (gpointer data)
5274 AccelPath *apath = data;
5276 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5278 /* closures_destroy takes care of unrefing the closure */
5279 g_object_unref (apath->accel_group);
5281 g_slice_free (AccelPath, apath);
5286 * gtk_widget_set_accel_path:
5287 * @widget: a #GtkWidget
5288 * @accel_path: (allow-none): path used to look up the accelerator
5289 * @accel_group: (allow-none): a #GtkAccelGroup.
5291 * Given an accelerator group, @accel_group, and an accelerator path,
5292 * @accel_path, sets up an accelerator in @accel_group so whenever the
5293 * key binding that is defined for @accel_path is pressed, @widget
5294 * will be activated. This removes any accelerators (for any
5295 * accelerator group) installed by previous calls to
5296 * gtk_widget_set_accel_path(). Associating accelerators with
5297 * paths allows them to be modified by the user and the modifications
5298 * to be saved for future use. (See gtk_accel_map_save().)
5300 * This function is a low level function that would most likely
5301 * be used by a menu creation system like #GtkUIManager. If you
5302 * use #GtkUIManager, setting up accelerator paths will be done
5305 * Even when you you aren't using #GtkUIManager, if you only want to
5306 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5307 * provides a somewhat more convenient interface.
5309 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5310 * pass a static string, you can save some memory by interning it first with
5311 * g_intern_static_string().
5314 gtk_widget_set_accel_path (GtkWidget *widget,
5315 const gchar *accel_path,
5316 GtkAccelGroup *accel_group)
5320 g_return_if_fail (GTK_IS_WIDGET (widget));
5321 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5325 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5326 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5328 gtk_accel_map_add_entry (accel_path, 0, 0);
5329 apath = g_slice_new (AccelPath);
5330 apath->accel_group = g_object_ref (accel_group);
5331 apath->path_quark = g_quark_from_string (accel_path);
5332 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5337 /* also removes possible old settings */
5338 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5341 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5343 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5347 _gtk_widget_get_accel_path (GtkWidget *widget,
5352 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5354 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5356 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5357 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5361 * gtk_widget_mnemonic_activate:
5362 * @widget: a #GtkWidget
5363 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5365 * Emits the #GtkWidget::mnemonic-activate signal.
5367 * The default handler for this signal activates the @widget if
5368 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5371 * Returns: %TRUE if the signal has been handled
5374 gtk_widget_mnemonic_activate (GtkWidget *widget,
5375 gboolean group_cycling)
5379 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5381 group_cycling = group_cycling != FALSE;
5382 if (!gtk_widget_is_sensitive (widget))
5385 g_signal_emit (widget,
5386 widget_signals[MNEMONIC_ACTIVATE],
5394 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5395 gboolean group_cycling)
5397 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5398 gtk_widget_activate (widget);
5399 else if (gtk_widget_get_can_focus (widget))
5400 gtk_widget_grab_focus (widget);
5403 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5404 G_OBJECT_TYPE_NAME (widget));
5405 gtk_widget_error_bell (widget);
5410 static const cairo_user_data_key_t event_key;
5413 _gtk_cairo_get_event (cairo_t *cr)
5415 g_return_val_if_fail (cr != NULL, NULL);
5417 return cairo_get_user_data (cr, &event_key);
5421 gtk_cairo_set_event (cairo_t *cr,
5422 GdkEventExpose *event)
5424 cairo_set_user_data (cr, &event_key, event, NULL);
5428 * gtk_cairo_should_draw_window:
5429 * @cr: a cairo context
5430 * @window: the window to check
5432 * This function is supposed to be called in #GtkWidget::draw
5433 * implementations for widgets that support multiple windows.
5434 * @cr must be untransformed from invoking of the draw function.
5435 * This function will return %TRUE if the contents of the given
5436 * @window are supposed to be drawn and %FALSE otherwise. Note
5437 * that when the drawing was not initiated by the windowing
5438 * system this function will return %TRUE for all windows, so
5439 * you need to draw the bottommost window first. Also, do not
5440 * use "else if" statements to check which window should be drawn.
5442 * Returns: %TRUE if @window should be drawn
5445 gtk_cairo_should_draw_window (cairo_t *cr,
5448 GdkEventExpose *event;
5450 g_return_val_if_fail (cr != NULL, FALSE);
5451 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5453 event = _gtk_cairo_get_event (cr);
5455 return event == NULL ||
5456 event->window == window;
5459 /* code shared by gtk_container_propagate_draw() and
5463 _gtk_widget_draw_internal (GtkWidget *widget,
5465 gboolean clip_to_size)
5467 GtkStyleContext *context;
5469 if (!gtk_widget_is_drawable (widget))
5474 cairo_rectangle (cr,
5476 widget->priv->allocation.width,
5477 widget->priv->allocation.height);
5481 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5485 g_signal_emit (widget, widget_signals[DRAW],
5490 context = gtk_widget_get_style_context (widget);
5491 _gtk_style_context_coalesce_animation_areas (context, widget);
5496 * @widget: the widget to draw. It must be drawable (see
5497 * gtk_widget_is_drawable()) and a size must have been allocated.
5498 * @cr: a cairo context to draw to
5500 * Draws @widget to @cr. The top left corner of the widget will be
5501 * drawn to the currently set origin point of @cr.
5503 * You should pass a cairo context as @cr argument that is in an
5504 * original state. Otherwise the resulting drawing is undefined. For
5505 * example changing the operator using cairo_set_operator() or the
5506 * line width using cairo_set_line_width() might have unwanted side
5508 * You may however change the context's transform matrix - like with
5509 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5510 * region with cairo_clip() prior to calling this function. Also, it
5511 * is fine to modify the context with cairo_save() and
5512 * cairo_push_group() prior to calling this function.
5514 * <note><para>Special purpose widgets may contain special code for
5515 * rendering to the screen and might appear differently on screen
5516 * and when rendered using gtk_widget_draw().</para></note>
5519 gtk_widget_draw (GtkWidget *widget,
5522 GdkEventExpose *tmp_event;
5524 g_return_if_fail (GTK_IS_WIDGET (widget));
5525 g_return_if_fail (!widget->priv->alloc_needed);
5526 g_return_if_fail (cr != NULL);
5529 /* We have to reset the event here so that draw functions can call
5530 * gtk_widget_draw() on random other widgets and get the desired
5531 * effect: Drawing all contents, not just the current window.
5533 tmp_event = _gtk_cairo_get_event (cr);
5534 gtk_cairo_set_event (cr, NULL);
5536 _gtk_widget_draw_internal (widget, cr, TRUE);
5538 gtk_cairo_set_event (cr, tmp_event);
5543 gtk_widget_real_key_press_event (GtkWidget *widget,
5546 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5550 gtk_widget_real_key_release_event (GtkWidget *widget,
5553 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5557 gtk_widget_real_focus_in_event (GtkWidget *widget,
5558 GdkEventFocus *event)
5560 gtk_widget_queue_shallow_draw (widget);
5566 gtk_widget_real_focus_out_event (GtkWidget *widget,
5567 GdkEventFocus *event)
5569 gtk_widget_queue_shallow_draw (widget);
5574 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5575 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5579 * @widget: a #GtkWidget
5580 * @event: a #GdkEvent
5582 * Rarely-used function. This function is used to emit
5583 * the event signals on a widget (those signals should never
5584 * be emitted without using this function to do so).
5585 * If you want to synthesize an event though, don't use this function;
5586 * instead, use gtk_main_do_event() so the event will behave as if
5587 * it were in the event queue. Don't synthesize expose events; instead,
5588 * use gdk_window_invalidate_rect() to invalidate a region of the
5591 * Return value: return from the event signal emission (%TRUE if
5592 * the event was handled)
5595 gtk_widget_event (GtkWidget *widget,
5598 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5599 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5601 if (event->type == GDK_EXPOSE)
5603 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5604 "the same effect, call gdk_window_invalidate_rect/region(), "
5605 "followed by gdk_window_process_updates().");
5609 return gtk_widget_event_internal (widget, event);
5612 /* Returns TRUE if a translation should be done */
5614 _gtk_widget_get_translation_to_window (GtkWidget *widget,
5619 GdkWindow *w, *widget_window;
5621 if (!gtk_widget_get_has_window (widget))
5623 *x = -widget->priv->allocation.x;
5624 *y = -widget->priv->allocation.y;
5632 widget_window = gtk_widget_get_window (widget);
5634 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5637 gdk_window_get_position (w, &wx, &wy);
5654 * gtk_cairo_transform_to_window:
5655 * @cr: the cairo context to transform
5656 * @widget: the widget the context is currently centered for
5657 * @window: the window to transform the context to
5659 * Transforms the given cairo context @cr that from @widget-relative
5660 * coordinates to @window-relative coordinates.
5661 * If the @widget's window is not an ancestor of @window, no
5662 * modification will be applied.
5664 * This is the inverse to the transformation GTK applies when
5665 * preparing an expose event to be emitted with the #GtkWidget::draw
5666 * signal. It is intended to help porting multiwindow widgets from
5667 * GTK+ 2 to the rendering architecture of GTK+ 3.
5670 gtk_cairo_transform_to_window (cairo_t *cr,
5676 g_return_if_fail (cr != NULL);
5677 g_return_if_fail (GTK_IS_WIDGET (widget));
5678 g_return_if_fail (GDK_IS_WINDOW (window));
5680 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
5681 cairo_translate (cr, x, y);
5685 * gtk_widget_send_expose:
5686 * @widget: a #GtkWidget
5687 * @event: a expose #GdkEvent
5689 * Very rarely-used function. This function is used to emit
5690 * an expose event on a widget. This function is not normally used
5691 * directly. The only time it is used is when propagating an expose
5692 * event to a child %NO_WINDOW widget, and that is normally done
5693 * using gtk_container_propagate_draw().
5695 * If you want to force an area of a window to be redrawn,
5696 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5697 * To cause the redraw to be done immediately, follow that call
5698 * with a call to gdk_window_process_updates().
5700 * Return value: return from the event signal emission (%TRUE if
5701 * the event was handled)
5704 gtk_widget_send_expose (GtkWidget *widget,
5707 gboolean result = FALSE;
5712 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5713 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5714 g_return_val_if_fail (event != NULL, TRUE);
5715 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5717 cr = gdk_cairo_create (event->expose.window);
5718 gtk_cairo_set_event (cr, &event->expose);
5720 gdk_cairo_region (cr, event->expose.region);
5723 do_clip = _gtk_widget_get_translation_to_window (widget,
5724 event->expose.window,
5726 cairo_translate (cr, -x, -y);
5728 _gtk_widget_draw_internal (widget, cr, do_clip);
5730 /* unset here, so if someone keeps a reference to cr we
5731 * don't leak the window. */
5732 gtk_cairo_set_event (cr, NULL);
5739 event_window_is_still_viewable (GdkEvent *event)
5741 /* Check that we think the event's window is viewable before
5742 * delivering the event, to prevent suprises. We do this here
5743 * at the last moment, since the event may have been queued
5744 * up behind other events, held over a recursive main loop, etc.
5746 switch (event->type)
5749 case GDK_MOTION_NOTIFY:
5750 case GDK_BUTTON_PRESS:
5751 case GDK_2BUTTON_PRESS:
5752 case GDK_3BUTTON_PRESS:
5754 case GDK_ENTER_NOTIFY:
5755 case GDK_PROXIMITY_IN:
5757 return event->any.window && gdk_window_is_viewable (event->any.window);
5760 /* The following events are the second half of paired events;
5761 * we always deliver them to deal with widgets that clean up
5762 * on the second half.
5764 case GDK_BUTTON_RELEASE:
5765 case GDK_KEY_RELEASE:
5766 case GDK_LEAVE_NOTIFY:
5767 case GDK_PROXIMITY_OUT:
5771 /* Remaining events would make sense on an not-viewable window,
5772 * or don't have an associated window.
5779 gtk_widget_event_internal (GtkWidget *widget,
5782 gboolean return_val = FALSE;
5784 /* We check only once for is-still-visible; if someone
5785 * hides the window in on of the signals on the widget,
5786 * they are responsible for returning TRUE to terminate
5789 if (!event_window_is_still_viewable (event))
5792 g_object_ref (widget);
5794 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5795 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5800 switch (event->type)
5805 case GDK_BUTTON_PRESS:
5806 case GDK_2BUTTON_PRESS:
5807 case GDK_3BUTTON_PRESS:
5808 signal_num = BUTTON_PRESS_EVENT;
5811 signal_num = SCROLL_EVENT;
5813 case GDK_BUTTON_RELEASE:
5814 signal_num = BUTTON_RELEASE_EVENT;
5816 case GDK_MOTION_NOTIFY:
5817 signal_num = MOTION_NOTIFY_EVENT;
5820 signal_num = DELETE_EVENT;
5823 signal_num = DESTROY_EVENT;
5824 _gtk_tooltip_hide (widget);
5827 signal_num = KEY_PRESS_EVENT;
5829 case GDK_KEY_RELEASE:
5830 signal_num = KEY_RELEASE_EVENT;
5832 case GDK_ENTER_NOTIFY:
5833 signal_num = ENTER_NOTIFY_EVENT;
5835 case GDK_LEAVE_NOTIFY:
5836 signal_num = LEAVE_NOTIFY_EVENT;
5838 case GDK_FOCUS_CHANGE:
5839 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
5840 if (event->focus_change.in)
5841 _gtk_tooltip_focus_in (widget);
5843 _gtk_tooltip_focus_out (widget);
5846 signal_num = CONFIGURE_EVENT;
5849 signal_num = MAP_EVENT;
5852 signal_num = UNMAP_EVENT;
5854 case GDK_WINDOW_STATE:
5855 signal_num = WINDOW_STATE_EVENT;
5857 case GDK_PROPERTY_NOTIFY:
5858 signal_num = PROPERTY_NOTIFY_EVENT;
5860 case GDK_SELECTION_CLEAR:
5861 signal_num = SELECTION_CLEAR_EVENT;
5863 case GDK_SELECTION_REQUEST:
5864 signal_num = SELECTION_REQUEST_EVENT;
5866 case GDK_SELECTION_NOTIFY:
5867 signal_num = SELECTION_NOTIFY_EVENT;
5869 case GDK_PROXIMITY_IN:
5870 signal_num = PROXIMITY_IN_EVENT;
5872 case GDK_PROXIMITY_OUT:
5873 signal_num = PROXIMITY_OUT_EVENT;
5875 case GDK_CLIENT_EVENT:
5876 signal_num = CLIENT_EVENT;
5879 signal_num = EXPOSE_EVENT;
5881 case GDK_VISIBILITY_NOTIFY:
5882 signal_num = VISIBILITY_NOTIFY_EVENT;
5884 case GDK_GRAB_BROKEN:
5885 signal_num = GRAB_BROKEN_EVENT;
5888 signal_num = DAMAGE_EVENT;
5891 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
5895 if (signal_num != -1)
5896 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
5898 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
5899 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
5903 g_object_unref (widget);
5909 * gtk_widget_activate:
5910 * @widget: a #GtkWidget that's activatable
5912 * For widgets that can be "activated" (buttons, menu items, etc.)
5913 * this function activates them. Activation is what happens when you
5914 * press Enter on a widget during key navigation. If @widget isn't
5915 * activatable, the function returns %FALSE.
5917 * Return value: %TRUE if the widget was activatable
5920 gtk_widget_activate (GtkWidget *widget)
5922 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5924 if (WIDGET_CLASS (widget)->activate_signal)
5926 /* FIXME: we should eventually check the signals signature here */
5927 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5936 gtk_widget_reparent_subwindows (GtkWidget *widget,
5937 GdkWindow *new_window)
5939 GtkWidgetPrivate *priv = widget->priv;
5941 if (!gtk_widget_get_has_window (widget))
5943 GList *children = gdk_window_get_children (priv->window);
5946 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5948 GdkWindow *window = tmp_list->data;
5951 gdk_window_get_user_data (window, &child);
5952 while (child && child != widget)
5953 child = ((GtkWidget*) child)->priv->parent;
5956 gdk_window_reparent (window, new_window, 0, 0);
5959 g_list_free (children);
5964 GList *tmp_list, *children;
5966 parent = gdk_window_get_parent (priv->window);
5969 gdk_window_reparent (priv->window, new_window, 0, 0);
5972 children = gdk_window_get_children (parent);
5974 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5976 GdkWindow *window = tmp_list->data;
5979 gdk_window_get_user_data (window, &child);
5981 if (child == widget)
5982 gdk_window_reparent (window, new_window, 0, 0);
5985 g_list_free (children);
5991 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5992 gpointer client_data)
5994 GtkWidgetPrivate *priv = widget->priv;
5996 g_assert (client_data != NULL);
5998 if (!gtk_widget_get_has_window (widget))
6001 g_object_unref (priv->window);
6002 priv->window = (GdkWindow*) client_data;
6004 g_object_ref (priv->window);
6006 if (GTK_IS_CONTAINER (widget))
6007 gtk_container_forall (GTK_CONTAINER (widget),
6008 gtk_widget_reparent_fixup_child,
6014 * gtk_widget_reparent:
6015 * @widget: a #GtkWidget
6016 * @new_parent: a #GtkContainer to move the widget into
6018 * Moves a widget from one #GtkContainer to another, handling reference
6019 * count issues to avoid destroying the widget.
6022 gtk_widget_reparent (GtkWidget *widget,
6023 GtkWidget *new_parent)
6025 GtkWidgetPrivate *priv;
6027 g_return_if_fail (GTK_IS_WIDGET (widget));
6028 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6029 priv = widget->priv;
6030 g_return_if_fail (priv->parent != NULL);
6032 if (priv->parent != new_parent)
6034 /* First try to see if we can get away without unrealizing
6035 * the widget as we reparent it. if so we set a flag so
6036 * that gtk_widget_unparent doesn't unrealize widget
6038 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6039 priv->in_reparent = TRUE;
6041 g_object_ref (widget);
6042 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6043 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6044 g_object_unref (widget);
6046 if (priv->in_reparent)
6048 priv->in_reparent = FALSE;
6050 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6051 gtk_widget_reparent_fixup_child (widget,
6052 gtk_widget_get_parent_window (widget));
6055 g_object_notify (G_OBJECT (widget), "parent");
6060 * gtk_widget_intersect:
6061 * @widget: a #GtkWidget
6062 * @area: a rectangle
6063 * @intersection: rectangle to store intersection of @widget and @area
6065 * Computes the intersection of a @widget's area and @area, storing
6066 * the intersection in @intersection, and returns %TRUE if there was
6067 * an intersection. @intersection may be %NULL if you're only
6068 * interested in whether there was an intersection.
6070 * Return value: %TRUE if there was an intersection
6073 gtk_widget_intersect (GtkWidget *widget,
6074 const GdkRectangle *area,
6075 GdkRectangle *intersection)
6077 GtkWidgetPrivate *priv;
6082 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6083 g_return_val_if_fail (area != NULL, FALSE);
6085 priv = widget->priv;
6088 dest = intersection;
6092 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6094 if (return_val && intersection && gtk_widget_get_has_window (widget))
6096 intersection->x -= priv->allocation.x;
6097 intersection->y -= priv->allocation.y;
6104 * gtk_widget_region_intersect:
6105 * @widget: a #GtkWidget
6106 * @region: a #cairo_region_t, in the same coordinate system as
6107 * @widget->allocation. That is, relative to @widget->window
6108 * for %NO_WINDOW widgets; relative to the parent window
6109 * of @widget->window for widgets with their own window.
6110 * @returns: A newly allocated region holding the intersection of @widget
6111 * and @region. The coordinates of the return value are
6112 * relative to @widget->window for %NO_WINDOW widgets, and
6113 * relative to the parent window of @widget->window for
6114 * widgets with their own window.
6116 * Computes the intersection of a @widget's area and @region, returning
6117 * the intersection. The result may be empty, use cairo_region_is_empty() to
6121 gtk_widget_region_intersect (GtkWidget *widget,
6122 const cairo_region_t *region)
6125 cairo_region_t *dest;
6127 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6128 g_return_val_if_fail (region != NULL, NULL);
6130 gtk_widget_get_allocation (widget, &rect);
6132 dest = cairo_region_create_rectangle (&rect);
6134 cairo_region_intersect (dest, region);
6140 * _gtk_widget_grab_notify:
6141 * @widget: a #GtkWidget
6142 * @was_grabbed: whether a grab is now in effect
6144 * Emits the #GtkWidget::grab-notify signal on @widget.
6149 _gtk_widget_grab_notify (GtkWidget *widget,
6150 gboolean was_grabbed)
6152 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6156 * gtk_widget_grab_focus:
6157 * @widget: a #GtkWidget
6159 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6160 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6161 * something like #GtkFrame won't work.
6163 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6164 * gtk_widget_set_can_focus() to modify that flag.
6166 * The widget also needs to be realized and mapped. This is indicated by the
6167 * related signals. Grabbing the focus immediately after creating the widget
6168 * will likely fail and cause critical warnings.
6171 gtk_widget_grab_focus (GtkWidget *widget)
6173 g_return_if_fail (GTK_IS_WIDGET (widget));
6175 if (!gtk_widget_is_sensitive (widget))
6178 g_object_ref (widget);
6179 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6180 g_object_notify (G_OBJECT (widget), "has-focus");
6181 g_object_unref (widget);
6185 reset_focus_recurse (GtkWidget *widget,
6188 if (GTK_IS_CONTAINER (widget))
6190 GtkContainer *container;
6192 container = GTK_CONTAINER (widget);
6193 gtk_container_set_focus_child (container, NULL);
6195 gtk_container_foreach (container,
6196 reset_focus_recurse,
6202 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6204 if (gtk_widget_get_can_focus (focus_widget))
6206 GtkWidget *toplevel;
6209 /* clear the current focus setting, break if the current widget
6210 * is the focus widget's parent, since containers above that will
6211 * be set by the next loop.
6213 toplevel = gtk_widget_get_toplevel (focus_widget);
6214 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6216 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6218 if (widget == focus_widget)
6220 /* We call _gtk_window_internal_set_focus() here so that the
6221 * toplevel window can request the focus if necessary.
6222 * This is needed when the toplevel is a GtkPlug
6224 if (!gtk_widget_has_focus (widget))
6225 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6232 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
6234 widget = widget->priv->parent;
6235 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6239 else if (toplevel != focus_widget)
6241 /* gtk_widget_grab_focus() operates on a tree without window...
6242 * actually, this is very questionable behaviour.
6245 gtk_container_foreach (GTK_CONTAINER (toplevel),
6246 reset_focus_recurse,
6250 /* now propagate the new focus up the widget tree and finally
6251 * set it on the window
6253 widget = focus_widget;
6254 while (widget->priv->parent)
6256 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6257 widget = widget->priv->parent;
6259 if (GTK_IS_WINDOW (widget))
6260 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6265 gtk_widget_real_query_tooltip (GtkWidget *widget,
6268 gboolean keyboard_tip,
6269 GtkTooltip *tooltip)
6271 gchar *tooltip_markup;
6272 gboolean has_tooltip;
6274 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6275 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6277 if (has_tooltip && tooltip_markup)
6279 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6287 gtk_widget_real_style_updated (GtkWidget *widget)
6289 if (gtk_widget_get_realized (widget))
6291 /* Trigger ::style-set for old
6292 * widgets not listening to this
6294 g_signal_emit (widget,
6295 widget_signals[STYLE_SET],
6297 widget->priv->style);
6300 if (widget->priv->context)
6302 gtk_style_context_invalidate (widget->priv->context);
6304 if (gtk_widget_get_realized (widget) &&
6305 gtk_widget_get_has_window (widget))
6306 gtk_style_context_set_background (widget->priv->context,
6307 widget->priv->window);
6310 if (widget->priv->anchored)
6311 gtk_widget_queue_resize (widget);
6315 gtk_widget_real_show_help (GtkWidget *widget,
6316 GtkWidgetHelpType help_type)
6318 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6320 _gtk_tooltip_toggle_keyboard_mode (widget);
6329 gtk_widget_real_focus (GtkWidget *widget,
6330 GtkDirectionType direction)
6332 if (!gtk_widget_get_can_focus (widget))
6335 if (!gtk_widget_is_focus (widget))
6337 gtk_widget_grab_focus (widget);
6345 gtk_widget_real_move_focus (GtkWidget *widget,
6346 GtkDirectionType direction)
6348 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6350 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6352 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6358 gtk_widget_real_keynav_failed (GtkWidget *widget,
6359 GtkDirectionType direction)
6361 gboolean cursor_only;
6365 case GTK_DIR_TAB_FORWARD:
6366 case GTK_DIR_TAB_BACKWARD:
6373 g_object_get (gtk_widget_get_settings (widget),
6374 "gtk-keynav-cursor-only", &cursor_only,
6381 gtk_widget_error_bell (widget);
6387 * gtk_widget_set_can_focus:
6388 * @widget: a #GtkWidget
6389 * @can_focus: whether or not @widget can own the input focus.
6391 * Specifies whether @widget can own the input focus. See
6392 * gtk_widget_grab_focus() for actually setting the input focus on a
6398 gtk_widget_set_can_focus (GtkWidget *widget,
6401 g_return_if_fail (GTK_IS_WIDGET (widget));
6403 if (widget->priv->can_focus != can_focus)
6405 widget->priv->can_focus = can_focus;
6407 gtk_widget_queue_resize (widget);
6408 g_object_notify (G_OBJECT (widget), "can-focus");
6413 * gtk_widget_get_can_focus:
6414 * @widget: a #GtkWidget
6416 * Determines whether @widget can own the input focus. See
6417 * gtk_widget_set_can_focus().
6419 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6424 gtk_widget_get_can_focus (GtkWidget *widget)
6426 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6428 return widget->priv->can_focus;
6432 * gtk_widget_has_focus:
6433 * @widget: a #GtkWidget
6435 * Determines if the widget has the global input focus. See
6436 * gtk_widget_is_focus() for the difference between having the global
6437 * input focus, and only having the focus within a toplevel.
6439 * Return value: %TRUE if the widget has the global input focus.
6444 gtk_widget_has_focus (GtkWidget *widget)
6446 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6448 return widget->priv->has_focus;
6452 * gtk_widget_is_focus:
6453 * @widget: a #GtkWidget
6455 * Determines if the widget is the focus widget within its
6456 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6457 * necessarily set; %HAS_FOCUS will only be set if the
6458 * toplevel widget additionally has the global input focus.)
6460 * Return value: %TRUE if the widget is the focus widget.
6463 gtk_widget_is_focus (GtkWidget *widget)
6465 GtkWidget *toplevel;
6467 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6469 toplevel = gtk_widget_get_toplevel (widget);
6471 if (GTK_IS_WINDOW (toplevel))
6472 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6478 * gtk_widget_set_can_default:
6479 * @widget: a #GtkWidget
6480 * @can_default: whether or not @widget can be a default widget.
6482 * Specifies whether @widget can be a default widget. See
6483 * gtk_widget_grab_default() for details about the meaning of
6489 gtk_widget_set_can_default (GtkWidget *widget,
6490 gboolean can_default)
6492 g_return_if_fail (GTK_IS_WIDGET (widget));
6494 if (widget->priv->can_default != can_default)
6496 widget->priv->can_default = can_default;
6498 gtk_widget_queue_resize (widget);
6499 g_object_notify (G_OBJECT (widget), "can-default");
6504 * gtk_widget_get_can_default:
6505 * @widget: a #GtkWidget
6507 * Determines whether @widget can be a default widget. See
6508 * gtk_widget_set_can_default().
6510 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6515 gtk_widget_get_can_default (GtkWidget *widget)
6517 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6519 return widget->priv->can_default;
6523 * gtk_widget_has_default:
6524 * @widget: a #GtkWidget
6526 * Determines whether @widget is the current default widget within its
6527 * toplevel. See gtk_widget_set_can_default().
6529 * Return value: %TRUE if @widget is the current default widget within
6530 * its toplevel, %FALSE otherwise
6535 gtk_widget_has_default (GtkWidget *widget)
6537 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6539 return widget->priv->has_default;
6543 _gtk_widget_set_has_default (GtkWidget *widget,
6544 gboolean has_default)
6546 widget->priv->has_default = has_default;
6550 * gtk_widget_grab_default:
6551 * @widget: a #GtkWidget
6553 * Causes @widget to become the default widget. @widget must have the
6554 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6555 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6556 * %TRUE)</literal>. The default widget is activated when
6557 * the user presses Enter in a window. Default widgets must be
6558 * activatable, that is, gtk_widget_activate() should affect them. Note
6559 * that #GtkEntry widgets require the "activates-default" property
6560 * set to %TRUE before they activate the default widget when Enter
6561 * is pressed and the #GtkEntry is focused.
6564 gtk_widget_grab_default (GtkWidget *widget)
6568 g_return_if_fail (GTK_IS_WIDGET (widget));
6569 g_return_if_fail (gtk_widget_get_can_default (widget));
6571 window = gtk_widget_get_toplevel (widget);
6573 if (window && gtk_widget_is_toplevel (window))
6574 gtk_window_set_default (GTK_WINDOW (window), widget);
6576 g_warning (G_STRLOC ": widget not within a GtkWindow");
6580 * gtk_widget_set_receives_default:
6581 * @widget: a #GtkWidget
6582 * @receives_default: whether or not @widget can be a default widget.
6584 * Specifies whether @widget will be treated as the default widget
6585 * within its toplevel when it has the focus, even if another widget
6588 * See gtk_widget_grab_default() for details about the meaning of
6594 gtk_widget_set_receives_default (GtkWidget *widget,
6595 gboolean receives_default)
6597 g_return_if_fail (GTK_IS_WIDGET (widget));
6599 if (widget->priv->receives_default != receives_default)
6601 widget->priv->receives_default = receives_default;
6603 g_object_notify (G_OBJECT (widget), "receives-default");
6608 * gtk_widget_get_receives_default:
6609 * @widget: a #GtkWidget
6611 * Determines whether @widget is alyways treated as default widget
6612 * withing its toplevel when it has the focus, even if another widget
6615 * See gtk_widget_set_receives_default().
6617 * Return value: %TRUE if @widget acts as default widget when focussed,
6623 gtk_widget_get_receives_default (GtkWidget *widget)
6625 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6627 return widget->priv->receives_default;
6631 * gtk_widget_has_grab:
6632 * @widget: a #GtkWidget
6634 * Determines whether the widget is currently grabbing events, so it
6635 * is the only widget receiving input events (keyboard and mouse).
6637 * See also gtk_grab_add().
6639 * Return value: %TRUE if the widget is in the grab_widgets stack
6644 gtk_widget_has_grab (GtkWidget *widget)
6646 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6648 return widget->priv->has_grab;
6652 _gtk_widget_set_has_grab (GtkWidget *widget,
6655 widget->priv->has_grab = has_grab;
6659 * gtk_widget_device_is_shadowed:
6660 * @widget: a #GtkWidget
6661 * @device: a #GdkDevice
6663 * Returns %TRUE if @device has been shadowed by a GTK+
6664 * device grab on another widget, so it would stop sending
6665 * events to @widget. This may be used in the
6666 * #GtkWidget::grab-notify signal to check for specific
6667 * devices. See gtk_device_grab_add().
6669 * Returns: %TRUE if there is an ongoing grab on @device
6670 * by another #GtkWidget than @widget.
6675 gtk_widget_device_is_shadowed (GtkWidget *widget,
6678 GtkWindowGroup *group;
6679 GtkWidget *grab_widget, *toplevel;
6681 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6682 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6684 if (!gtk_widget_get_realized (widget))
6687 toplevel = gtk_widget_get_toplevel (widget);
6689 if (GTK_IS_WINDOW (toplevel))
6690 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6692 group = gtk_window_get_group (NULL);
6694 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6696 /* Widget not inside the hierarchy of grab_widget */
6698 widget != grab_widget &&
6699 !gtk_widget_is_ancestor (widget, grab_widget))
6702 grab_widget = gtk_window_group_get_current_grab (group);
6703 if (grab_widget && widget != grab_widget &&
6704 !gtk_widget_is_ancestor (widget, grab_widget))
6711 * gtk_widget_set_name:
6712 * @widget: a #GtkWidget
6713 * @name: name for the widget
6715 * Widgets can be named, which allows you to refer to them from a
6716 * CSS file. You can apply a style to widgets with a particular name
6717 * in the CSS file. See the documentation for the CSS syntax (on the
6718 * same page as the docs for #GtkStyleContext).
6720 * Note that the CSS syntax has certain special characters to delimit
6721 * and represent elements in a selector (period, #, >, *...),
6722 * so using these will make your widget impossible to match by name.
6723 * Any combination of alphanumeric symbols, dashes and underscores will
6727 gtk_widget_set_name (GtkWidget *widget,
6730 GtkWidgetPrivate *priv;
6733 g_return_if_fail (GTK_IS_WIDGET (widget));
6735 priv = widget->priv;
6737 new_name = g_strdup (name);
6738 g_free (priv->name);
6739 priv->name = new_name;
6745 pos = gtk_widget_path_length (priv->path) - 1;
6746 gtk_widget_path_iter_set_name (priv->path, pos,
6751 gtk_style_context_set_path (priv->context, priv->path);
6753 g_object_notify (G_OBJECT (widget), "name");
6757 * gtk_widget_get_name:
6758 * @widget: a #GtkWidget
6760 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6761 * significance of widget names.
6763 * Return value: name of the widget. This string is owned by GTK+ and
6764 * should not be modified or freed
6766 G_CONST_RETURN gchar*
6767 gtk_widget_get_name (GtkWidget *widget)
6769 GtkWidgetPrivate *priv;
6771 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6773 priv = widget->priv;
6777 return G_OBJECT_TYPE_NAME (widget);
6781 _gtk_widget_update_state_flags (GtkWidget *widget,
6782 GtkStateFlags flags,
6785 GtkWidgetPrivate *priv;
6787 priv = widget->priv;
6789 /* Handle insensitive first, since it is propagated
6790 * differently throughout the widget hierarchy.
6792 if ((flags & GTK_STATE_FLAG_INSENSITIVE) !=
6793 (priv->state_flags & GTK_STATE_FLAG_INSENSITIVE))
6794 gtk_widget_set_sensitive (widget,
6795 operation != STATE_CHANGE_UNSET);
6797 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
6800 operation == STATE_CHANGE_REPLACE)
6805 data.operation = operation;
6806 data.use_forall = FALSE;
6809 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6811 data.parent_sensitive = TRUE;
6813 gtk_widget_propagate_state (widget, &data);
6815 if (gtk_widget_is_drawable (widget))
6816 gtk_widget_queue_draw (widget);
6821 * gtk_widget_set_state_flags:
6822 * @widget: a #GtkWidget
6823 * @flags: State flags to turn on
6824 * @clear: Whether to clear state before turning on @flags
6826 * This function is for use in widget implementations. Turns on flag
6827 * values in the current widget state (insensitive, prelighted, etc.).
6829 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
6830 * will be propagated down to all non-internal children if @widget is a
6831 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
6832 * down to all #GtkContainer children by different means than turning on the
6833 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
6834 * gtk_widget_is_sensitive() will make use of these.
6839 gtk_widget_set_state_flags (GtkWidget *widget,
6840 GtkStateFlags flags,
6843 g_return_if_fail (GTK_IS_WIDGET (widget));
6845 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
6846 (clear && widget->priv->state_flags == flags))
6850 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
6852 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
6856 * gtk_widget_unset_state_flags:
6857 * @widget: a #GtkWidget
6858 * @flags: State flags to turn off
6860 * This function is for use in widget implementations. Turns off flag
6861 * values for the current widget state (insensitive, prelighted, etc.).
6862 * See gtk_widget_set_state_flags().
6867 gtk_widget_unset_state_flags (GtkWidget *widget,
6868 GtkStateFlags flags)
6870 g_return_if_fail (GTK_IS_WIDGET (widget));
6872 if ((widget->priv->state_flags & flags) == 0)
6875 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
6879 * gtk_widget_get_state_flags:
6880 * @widget: a #GtkWidget
6882 * Returns the widget state as a flag set. It is worth mentioning
6883 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
6884 * returned, that is, also based on parent insensitivity, even if
6885 * @widget itself is sensitive.
6887 * Returns: The state flags for widget
6892 gtk_widget_get_state_flags (GtkWidget *widget)
6894 GtkStateFlags flags;
6896 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
6898 flags = widget->priv->state_flags;
6900 if (!gtk_widget_is_sensitive (widget))
6901 flags |= GTK_STATE_FLAG_INSENSITIVE;
6907 * gtk_widget_set_state:
6908 * @widget: a #GtkWidget
6909 * @state: new state for @widget
6911 * This function is for use in widget implementations. Sets the state
6912 * of a widget (insensitive, prelighted, etc.) Usually you should set
6913 * the state using wrapper functions such as gtk_widget_set_sensitive().
6915 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
6918 gtk_widget_set_state (GtkWidget *widget,
6921 GtkStateFlags flags;
6923 if (state == gtk_widget_get_state (widget))
6928 case GTK_STATE_ACTIVE:
6929 flags = GTK_STATE_FLAG_ACTIVE;
6931 case GTK_STATE_PRELIGHT:
6932 flags = GTK_STATE_FLAG_PRELIGHT;
6934 case GTK_STATE_SELECTED:
6935 flags = GTK_STATE_FLAG_SELECTED;
6937 case GTK_STATE_INSENSITIVE:
6938 flags = GTK_STATE_FLAG_INSENSITIVE;
6940 case GTK_STATE_INCONSISTENT:
6941 flags = GTK_STATE_FLAG_INCONSISTENT;
6943 case GTK_STATE_FOCUSED:
6944 flags = GTK_STATE_FLAG_FOCUSED;
6946 case GTK_STATE_NORMAL:
6952 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
6956 * gtk_widget_get_state:
6957 * @widget: a #GtkWidget
6959 * Returns the widget's state. See gtk_widget_set_state().
6961 * Returns: the state of @widget.
6965 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
6968 gtk_widget_get_state (GtkWidget *widget)
6970 GtkStateFlags flags;
6972 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
6974 flags = gtk_widget_get_state_flags (widget);
6976 if (flags & GTK_STATE_FLAG_INSENSITIVE)
6977 return GTK_STATE_INSENSITIVE;
6978 else if (flags & GTK_STATE_FLAG_INCONSISTENT)
6979 return GTK_STATE_INCONSISTENT;
6980 else if (flags & GTK_STATE_FLAG_ACTIVE)
6981 return GTK_STATE_ACTIVE;
6982 else if (flags & GTK_STATE_FLAG_SELECTED)
6983 return GTK_STATE_SELECTED;
6984 else if (flags & GTK_STATE_FLAG_FOCUSED)
6985 return GTK_STATE_FOCUSED;
6986 else if (flags & GTK_STATE_FLAG_PRELIGHT)
6987 return GTK_STATE_PRELIGHT;
6989 return GTK_STATE_NORMAL;
6993 * gtk_widget_set_visible:
6994 * @widget: a #GtkWidget
6995 * @visible: whether the widget should be shown or not
6997 * Sets the visibility state of @widget. Note that setting this to
6998 * %TRUE doesn't mean the widget is actually viewable, see
6999 * gtk_widget_get_visible().
7001 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7002 * but is nicer to use when the visibility of the widget depends on
7008 gtk_widget_set_visible (GtkWidget *widget,
7011 g_return_if_fail (GTK_IS_WIDGET (widget));
7013 if (visible != gtk_widget_get_visible (widget))
7016 gtk_widget_show (widget);
7018 gtk_widget_hide (widget);
7023 _gtk_widget_set_visible_flag (GtkWidget *widget,
7026 widget->priv->visible = visible;
7030 * gtk_widget_get_visible:
7031 * @widget: a #GtkWidget
7033 * Determines whether the widget is visible. Note that this doesn't
7034 * take into account whether the widget's parent is also visible
7035 * or the widget is obscured in any way.
7037 * See gtk_widget_set_visible().
7039 * Return value: %TRUE if the widget is visible
7044 gtk_widget_get_visible (GtkWidget *widget)
7046 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7048 return widget->priv->visible;
7052 * gtk_widget_set_has_window:
7053 * @widget: a #GtkWidget
7054 * @has_window: whether or not @widget has a window.
7056 * Specifies whether @widget has a #GdkWindow of its own. Note that
7057 * all realized widgets have a non-%NULL "window" pointer
7058 * (gtk_widget_get_window() never returns a %NULL window when a widget
7059 * is realized), but for many of them it's actually the #GdkWindow of
7060 * one of its parent widgets. Widgets that do not create a %window for
7061 * themselves in #GtkWidget::realize must announce this by
7062 * calling this function with @has_window = %FALSE.
7064 * This function should only be called by widget implementations,
7065 * and they should call it in their init() function.
7070 gtk_widget_set_has_window (GtkWidget *widget,
7071 gboolean has_window)
7073 g_return_if_fail (GTK_IS_WIDGET (widget));
7075 widget->priv->no_window = !has_window;
7079 * gtk_widget_get_has_window:
7080 * @widget: a #GtkWidget
7082 * Determines whether @widget has a #GdkWindow of its own. See
7083 * gtk_widget_set_has_window().
7085 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7090 gtk_widget_get_has_window (GtkWidget *widget)
7092 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7094 return ! widget->priv->no_window;
7098 * gtk_widget_is_toplevel:
7099 * @widget: a #GtkWidget
7101 * Determines whether @widget is a toplevel widget. Currently only
7102 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
7103 * widgets have no parent widget.
7105 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7110 gtk_widget_is_toplevel (GtkWidget *widget)
7112 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7114 return widget->priv->toplevel;
7118 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7119 gboolean is_toplevel)
7121 widget->priv->toplevel = is_toplevel;
7125 * gtk_widget_is_drawable:
7126 * @widget: a #GtkWidget
7128 * Determines whether @widget can be drawn to. A widget can be drawn
7129 * to if it is mapped and visible.
7131 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7136 gtk_widget_is_drawable (GtkWidget *widget)
7138 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7140 return (gtk_widget_get_visible (widget) &&
7141 gtk_widget_get_mapped (widget));
7145 * gtk_widget_get_realized:
7146 * @widget: a #GtkWidget
7148 * Determines whether @widget is realized.
7150 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7155 gtk_widget_get_realized (GtkWidget *widget)
7157 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7159 return widget->priv->realized;
7163 * gtk_widget_set_realized:
7164 * @widget: a #GtkWidget
7165 * @realized: %TRUE to mark the widget as realized
7167 * Marks the widget as being realized.
7169 * This function should only ever be called in a derived widget's
7170 * "realize" or "unrealize" implementation.
7175 gtk_widget_set_realized (GtkWidget *widget,
7178 g_return_if_fail (GTK_IS_WIDGET (widget));
7180 widget->priv->realized = realized;
7184 * gtk_widget_get_mapped:
7185 * @widget: a #GtkWidget
7187 * Whether the widget is mapped.
7189 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7194 gtk_widget_get_mapped (GtkWidget *widget)
7196 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7198 return widget->priv->mapped;
7202 * gtk_widget_set_mapped:
7203 * @widget: a #GtkWidget
7204 * @mapped: %TRUE to mark the widget as mapped
7206 * Marks the widget as being realized.
7208 * This function should only ever be called in a derived widget's
7209 * "map" or "unmap" implementation.
7214 gtk_widget_set_mapped (GtkWidget *widget,
7217 g_return_if_fail (GTK_IS_WIDGET (widget));
7219 widget->priv->mapped = mapped;
7223 * gtk_widget_set_app_paintable:
7224 * @widget: a #GtkWidget
7225 * @app_paintable: %TRUE if the application will paint on the widget
7227 * Sets whether the application intends to draw on the widget in
7228 * an #GtkWidget::draw handler.
7230 * This is a hint to the widget and does not affect the behavior of
7231 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7232 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7233 * the effect is to suppress default themed drawing of the widget's
7234 * background. (Children of the widget will still be drawn.) The application
7235 * is then entirely responsible for drawing the widget background.
7237 * Note that the background is still drawn when the widget is mapped.
7240 gtk_widget_set_app_paintable (GtkWidget *widget,
7241 gboolean app_paintable)
7243 g_return_if_fail (GTK_IS_WIDGET (widget));
7245 app_paintable = (app_paintable != FALSE);
7247 if (widget->priv->app_paintable != app_paintable)
7249 widget->priv->app_paintable = app_paintable;
7251 if (gtk_widget_is_drawable (widget))
7252 gtk_widget_queue_draw (widget);
7254 g_object_notify (G_OBJECT (widget), "app-paintable");
7259 * gtk_widget_get_app_paintable:
7260 * @widget: a #GtkWidget
7262 * Determines whether the application intends to draw on the widget in
7263 * an #GtkWidget::draw handler.
7265 * See gtk_widget_set_app_paintable()
7267 * Return value: %TRUE if the widget is app paintable
7272 gtk_widget_get_app_paintable (GtkWidget *widget)
7274 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7276 return widget->priv->app_paintable;
7280 * gtk_widget_set_double_buffered:
7281 * @widget: a #GtkWidget
7282 * @double_buffered: %TRUE to double-buffer a widget
7284 * Widgets are double buffered by default; you can use this function
7285 * to turn off the buffering. "Double buffered" simply means that
7286 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7287 * automatically around expose events sent to the
7288 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7289 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7290 * buffer to the screen. The result is that users see the window
7291 * update in one smooth step, and don't see individual graphics
7292 * primitives being rendered.
7294 * In very simple terms, double buffered widgets don't flicker,
7295 * so you would only use this function to turn off double buffering
7296 * if you had special needs and really knew what you were doing.
7298 * Note: if you turn off double-buffering, you have to handle
7299 * expose events, since even the clearing to the background color or
7300 * pixmap will not happen automatically (as it is done in
7301 * gdk_window_begin_paint()).
7304 gtk_widget_set_double_buffered (GtkWidget *widget,
7305 gboolean double_buffered)
7307 g_return_if_fail (GTK_IS_WIDGET (widget));
7309 double_buffered = (double_buffered != FALSE);
7311 if (widget->priv->double_buffered != double_buffered)
7313 widget->priv->double_buffered = double_buffered;
7315 g_object_notify (G_OBJECT (widget), "double-buffered");
7320 * gtk_widget_get_double_buffered:
7321 * @widget: a #GtkWidget
7323 * Determines whether the widget is double buffered.
7325 * See gtk_widget_set_double_buffered()
7327 * Return value: %TRUE if the widget is double buffered
7332 gtk_widget_get_double_buffered (GtkWidget *widget)
7334 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7336 return widget->priv->double_buffered;
7340 * gtk_widget_set_redraw_on_allocate:
7341 * @widget: a #GtkWidget
7342 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7343 * when it is allocated to a new size. Otherwise, only the
7344 * new portion of the widget will be redrawn.
7346 * Sets whether the entire widget is queued for drawing when its size
7347 * allocation changes. By default, this setting is %TRUE and
7348 * the entire widget is redrawn on every size change. If your widget
7349 * leaves the upper left unchanged when made bigger, turning this
7350 * setting off will improve performance.
7352 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7353 * off all allocation on resizing: the widget will not even redraw if
7354 * its position changes; this is to allow containers that don't draw
7355 * anything to avoid excess invalidations. If you set this flag on a
7356 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7357 * you are responsible for invalidating both the old and new allocation
7358 * of the widget when the widget is moved and responsible for invalidating
7359 * regions newly when the widget increases size.
7362 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7363 gboolean redraw_on_allocate)
7365 g_return_if_fail (GTK_IS_WIDGET (widget));
7367 widget->priv->redraw_on_alloc = redraw_on_allocate;
7371 * gtk_widget_set_sensitive:
7372 * @widget: a #GtkWidget
7373 * @sensitive: %TRUE to make the widget sensitive
7375 * Sets the sensitivity of a widget. A widget is sensitive if the user
7376 * can interact with it. Insensitive widgets are "grayed out" and the
7377 * user can't interact with them. Insensitive widgets are known as
7378 * "inactive", "disabled", or "ghosted" in some other toolkits.
7381 gtk_widget_set_sensitive (GtkWidget *widget,
7384 GtkWidgetPrivate *priv;
7387 g_return_if_fail (GTK_IS_WIDGET (widget));
7389 priv = widget->priv;
7391 sensitive = (sensitive != FALSE);
7393 if (widget->priv->sensitive == sensitive)
7396 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7400 widget->priv->sensitive = TRUE;
7401 data.operation = STATE_CHANGE_UNSET;
7405 widget->priv->sensitive = FALSE;
7406 data.operation = STATE_CHANGE_SET;
7409 data.use_forall = TRUE;
7412 data.parent_sensitive = gtk_widget_is_sensitive (priv->parent);
7414 data.parent_sensitive = TRUE;
7416 gtk_widget_propagate_state (widget, &data);
7418 if (gtk_widget_is_drawable (widget))
7419 gtk_widget_queue_draw (widget);
7421 g_object_notify (G_OBJECT (widget), "sensitive");
7425 * gtk_widget_get_sensitive:
7426 * @widget: a #GtkWidget
7428 * Returns the widget's sensitivity (in the sense of returning
7429 * the value that has been set using gtk_widget_set_sensitive()).
7431 * The effective sensitivity of a widget is however determined by both its
7432 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7434 * Returns: %TRUE if the widget is sensitive
7439 gtk_widget_get_sensitive (GtkWidget *widget)
7441 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7443 return widget->priv->sensitive;
7447 * gtk_widget_is_sensitive:
7448 * @widget: a #GtkWidget
7450 * Returns the widget's effective sensitivity, which means
7451 * it is sensitive itself and also its parent widget is sensntive
7453 * Returns: %TRUE if the widget is effectively sensitive
7458 gtk_widget_is_sensitive (GtkWidget *widget)
7460 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7462 return widget->priv->sensitive && widget->priv->parent_sensitive;
7466 _gtk_widget_update_path (GtkWidget *widget)
7468 if (widget->priv->path)
7470 gtk_widget_path_free (widget->priv->path);
7471 widget->priv->path = NULL;
7474 gtk_widget_get_path (widget);
7478 * gtk_widget_set_parent:
7479 * @widget: a #GtkWidget
7480 * @parent: parent container
7482 * This function is useful only when implementing subclasses of
7484 * Sets the container as the parent of @widget, and takes care of
7485 * some details such as updating the state and style of the child
7486 * to reflect its new location. The opposite function is
7487 * gtk_widget_unparent().
7490 gtk_widget_set_parent (GtkWidget *widget,
7493 GtkStateFlags parent_flags;
7494 GtkWidgetPrivate *priv;
7497 g_return_if_fail (GTK_IS_WIDGET (widget));
7498 g_return_if_fail (GTK_IS_WIDGET (parent));
7499 g_return_if_fail (widget != parent);
7501 priv = widget->priv;
7503 if (priv->parent != NULL)
7505 g_warning ("Can't set a parent on widget which has a parent\n");
7508 if (gtk_widget_is_toplevel (widget))
7510 g_warning ("Can't set a parent on a toplevel widget\n");
7514 /* keep this function in sync with gtk_menu_attach_to_widget()
7517 g_object_ref_sink (widget);
7518 priv->parent = parent;
7520 parent_flags = gtk_widget_get_state_flags (parent);
7522 /* Merge both old state and current parent state,
7523 * We don't want the insensitive flag to propagate
7524 * to the new child though */
7525 data.flags = parent_flags & ~GTK_STATE_FLAG_INSENSITIVE;
7526 data.flags |= priv->state_flags;
7528 data.operation = STATE_CHANGE_REPLACE;
7529 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
7530 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7531 gtk_widget_propagate_state (widget, &data);
7533 gtk_widget_reset_rc_styles (widget);
7535 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7536 if (priv->parent->priv->anchored)
7537 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7538 g_object_notify (G_OBJECT (widget), "parent");
7540 /* Enforce realized/mapped invariants
7542 if (gtk_widget_get_realized (priv->parent))
7543 gtk_widget_realize (widget);
7545 if (gtk_widget_get_visible (priv->parent) &&
7546 gtk_widget_get_visible (widget))
7548 if (gtk_widget_get_child_visible (widget) &&
7549 gtk_widget_get_mapped (priv->parent))
7550 gtk_widget_map (widget);
7552 gtk_widget_queue_resize (widget);
7555 /* child may cause parent's expand to change, if the child is
7556 * expanded. If child is not expanded, then it can't modify the
7557 * parent's expand. If the child becomes expanded later then it will
7558 * queue compute_expand then. This optimization plus defaulting
7559 * newly-constructed widgets to need_compute_expand=FALSE should
7560 * mean that initially building a widget tree doesn't have to keep
7561 * walking up setting need_compute_expand on parents over and over.
7563 * We can't change a parent to need to expand unless we're visible.
7565 if (gtk_widget_get_visible (widget) &&
7566 (priv->need_compute_expand ||
7567 priv->computed_hexpand ||
7568 priv->computed_vexpand))
7570 gtk_widget_queue_compute_expand (parent);
7573 if (widget->priv->context)
7575 _gtk_widget_update_path (widget);
7576 gtk_style_context_set_path (widget->priv->context, widget->priv->path);
7578 gtk_style_context_set_screen (widget->priv->context,
7579 gtk_widget_get_screen (widget));
7584 * gtk_widget_get_parent:
7585 * @widget: a #GtkWidget
7587 * Returns the parent container of @widget.
7589 * Return value: (transfer none): the parent container of @widget, or %NULL
7592 gtk_widget_get_parent (GtkWidget *widget)
7594 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7596 return widget->priv->parent;
7599 /*****************************************
7601 * see docs/styles.txt
7602 *****************************************/
7605 * gtk_widget_style_attach:
7606 * @widget: a #GtkWidget
7608 * This function attaches the widget's #GtkStyle to the widget's
7609 * #GdkWindow. It is a replacement for
7612 * widget->style = gtk_style_attach (widget->style, widget->window);
7615 * and should only ever be called in a derived widget's "realize"
7616 * implementation which does not chain up to its parent class'
7617 * "realize" implementation, because one of the parent classes
7618 * (finally #GtkWidget) would attach the style itself.
7623 gtk_widget_style_attach (GtkWidget *widget)
7625 GtkWidgetPrivate *priv;
7627 g_return_if_fail (GTK_IS_WIDGET (widget));
7628 g_return_if_fail (gtk_widget_get_realized (widget));
7630 priv = widget->priv;
7632 priv->style = gtk_style_attach (priv->style, priv->window);
7636 * gtk_widget_has_rc_style:
7637 * @widget: a #GtkWidget
7639 * Determines if the widget style has been looked up through the rc mechanism.
7641 * Returns: %TRUE if the widget has been looked up through the rc
7642 * mechanism, %FALSE otherwise.
7646 * Deprecated:3.0: Use #GtkStyleContext instead
7649 gtk_widget_has_rc_style (GtkWidget *widget)
7651 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7653 return widget->priv->rc_style;
7657 * gtk_widget_set_style:
7658 * @widget: a #GtkWidget
7659 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
7660 * gtk_widget_set_style() and go back to the default style
7662 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
7663 * want to use this function; it interacts badly with themes, because
7664 * themes work by replacing the #GtkStyle. Instead, use
7665 * gtk_widget_modify_style().
7667 * Deprecated:3.0: Use #GtkStyleContext instead
7670 gtk_widget_set_style (GtkWidget *widget,
7673 g_return_if_fail (GTK_IS_WIDGET (widget));
7677 * gtk_widget_ensure_style:
7678 * @widget: a #GtkWidget
7680 * Ensures that @widget has a style (@widget->style). Not a very useful
7681 * function; most of the time, if you want the style, the widget is
7682 * realized, and realized widgets are guaranteed to have a style
7685 * Deprecated:3.0: Use #GtkStyleContext instead
7688 gtk_widget_ensure_style (GtkWidget *widget)
7690 g_return_if_fail (GTK_IS_WIDGET (widget));
7692 if (!widget->priv->style ||
7693 !gtk_style_has_context (widget->priv->style))
7697 if (widget->priv->style)
7698 g_object_unref (widget->priv->style);
7700 style = g_object_new (GTK_TYPE_STYLE,
7701 "context", gtk_widget_get_style_context (widget),
7704 widget->priv->style = g_object_ref (style);
7706 g_signal_emit (widget,
7707 widget_signals[STYLE_SET],
7710 g_object_unref (style);
7715 * gtk_widget_get_style:
7716 * @widget: a #GtkWidget
7718 * Simply an accessor function that returns @widget->style.
7720 * Return value: (transfer none): the widget's #GtkStyle
7722 * Deprecated:3.0: Use #GtkStyleContext instead
7725 gtk_widget_get_style (GtkWidget *widget)
7727 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7729 return widget->priv->style;
7733 * gtk_widget_modify_style:
7734 * @widget: a #GtkWidget
7735 * @style: the #GtkRcStyle holding the style modifications
7737 * Modifies style values on the widget. Modifications made using this
7738 * technique take precedence over style values set via an RC file,
7739 * however, they will be overriden if a style is explicitely set on
7740 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
7741 * is designed so each field can either be set or unset, so it is
7742 * possible, using this function, to modify some style values and
7743 * leave the others unchanged.
7745 * Note that modifications made with this function are not cumulative
7746 * with previous calls to gtk_widget_modify_style() or with such
7747 * functions as gtk_widget_modify_fg(). If you wish to retain
7748 * previous values, you must first call gtk_widget_get_modifier_style(),
7749 * make your modifications to the returned style, then call
7750 * gtk_widget_modify_style() with that style. On the other hand,
7751 * if you first call gtk_widget_modify_style(), subsequent calls
7752 * to such functions gtk_widget_modify_fg() will have a cumulative
7753 * effect with the initial modifications.
7755 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7758 gtk_widget_modify_style (GtkWidget *widget,
7761 g_return_if_fail (GTK_IS_WIDGET (widget));
7762 g_return_if_fail (GTK_IS_RC_STYLE (style));
7764 g_object_set_qdata_full (G_OBJECT (widget),
7766 gtk_rc_style_copy (style),
7767 (GDestroyNotify) g_object_unref);
7771 * gtk_widget_get_modifier_style:
7772 * @widget: a #GtkWidget
7774 * Returns the current modifier style for the widget. (As set by
7775 * gtk_widget_modify_style().) If no style has previously set, a new
7776 * #GtkRcStyle will be created with all values unset, and set as the
7777 * modifier style for the widget. If you make changes to this rc
7778 * style, you must call gtk_widget_modify_style(), passing in the
7779 * returned rc style, to make sure that your changes take effect.
7781 * Caution: passing the style back to gtk_widget_modify_style() will
7782 * normally end up destroying it, because gtk_widget_modify_style() copies
7783 * the passed-in style and sets the copy as the new modifier style,
7784 * thus dropping any reference to the old modifier style. Add a reference
7785 * to the modifier style if you want to keep it alive.
7787 * Return value: (transfer none): the modifier style for the widget.
7788 * This rc style is owned by the widget. If you want to keep a
7789 * pointer to value this around, you must add a refcount using
7792 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7795 gtk_widget_get_modifier_style (GtkWidget *widget)
7797 GtkRcStyle *rc_style;
7799 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7801 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7805 rc_style = gtk_rc_style_new ();
7806 g_object_set_qdata_full (G_OBJECT (widget),
7809 (GDestroyNotify) g_object_unref);
7816 gtk_widget_modify_color_component (GtkWidget *widget,
7817 GtkRcFlags component,
7819 const GdkColor *color)
7821 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7828 rc_style->fg[state] = *color;
7831 rc_style->bg[state] = *color;
7834 rc_style->text[state] = *color;
7837 rc_style->base[state] = *color;
7840 g_assert_not_reached();
7843 rc_style->color_flags[state] |= component;
7846 rc_style->color_flags[state] &= ~component;
7848 gtk_widget_modify_style (widget, rc_style);
7852 modifier_style_changed (GtkModifierStyle *style,
7855 GtkStyleContext *context;
7857 context = gtk_widget_get_style_context (widget);
7858 gtk_style_context_invalidate (context);
7861 static GtkModifierStyle *
7862 _gtk_widget_get_modifier_properties (GtkWidget *widget)
7864 GtkModifierStyle *style;
7866 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
7868 if (G_UNLIKELY (!style))
7870 GtkStyleContext *context;
7872 style = gtk_modifier_style_new ();
7873 g_object_set_qdata_full (G_OBJECT (widget),
7874 quark_modifier_style,
7876 (GDestroyNotify) g_object_unref);
7878 g_signal_connect (style, "changed",
7879 G_CALLBACK (modifier_style_changed), widget);
7881 context = gtk_widget_get_style_context (widget);
7883 gtk_style_context_add_provider (context,
7884 GTK_STYLE_PROVIDER (style),
7885 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
7892 * gtk_widget_override_color:
7893 * @widget: a #GtkWidget
7894 * @state: the state for which to set the color
7895 * @color: the color to assign, or %NULL to undo the effect
7896 * of previous calls to gtk_widget_override_color()
7898 * Sets the color to use for a widget. All other style values are left
7903 * This API is mostly meant as a quick way for applications to change a
7904 * widget appearance. If you are developing a widgets library and intend
7905 * this change to be themeable, it is better done by setting meaningful
7906 * CSS classes and regions in your widget/container implementation through
7907 * gtk_style_context_add_class() and gtk_style_context_add_region().
7910 * This way, your widget library can install a #GtkCssProvider with the
7911 * %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order to provide a
7912 * default styling for those widgets that need so, and this theming may
7913 * fully overridden by the user's theme.
7919 * Note that for complex widgets this may bring in
7920 * undesired results (such as uniform background color everywhere),
7921 * in these cases it is better to fully style such widgets through a
7922 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
7930 gtk_widget_override_color (GtkWidget *widget,
7931 GtkStateFlags state,
7932 const GdkRGBA *color)
7934 GtkModifierStyle *style;
7936 g_return_if_fail (GTK_IS_WIDGET (widget));
7938 style = _gtk_widget_get_modifier_properties (widget);
7939 gtk_modifier_style_set_color (style, state, color);
7943 * gtk_widget_override_background_color:
7944 * @widget: a #GtkWidget
7945 * @state: the state for which to set the background color
7946 * @color: the color to assign, or %NULL to undo the effect
7947 * of previous calls to gtk_widget_override_background_color()
7949 * Sets the background color to use for a widget. All other style values
7950 * are left untouched. See gtk_widget_override_color().
7955 gtk_widget_override_background_color (GtkWidget *widget,
7956 GtkStateFlags state,
7957 const GdkRGBA *color)
7959 GtkModifierStyle *style;
7961 g_return_if_fail (GTK_IS_WIDGET (widget));
7963 style = _gtk_widget_get_modifier_properties (widget);
7964 gtk_modifier_style_set_background_color (style, state, color);
7968 * gtk_widget_override_font:
7969 * @widget: a #GtkWidget
7970 * @font_desc: the font descriptiong to use, or %NULL to undo
7971 * the effect of previous calls to
7972 * gtk_widget_override_font().
7974 * Sets the font to use for a widget. All other style values are
7975 * left untouched. See gtk_widget_override_color().
7980 gtk_widget_override_font (GtkWidget *widget,
7981 const PangoFontDescription *font_desc)
7983 GtkModifierStyle *style;
7985 g_return_if_fail (GTK_IS_WIDGET (widget));
7987 style = _gtk_widget_get_modifier_properties (widget);
7988 gtk_modifier_style_set_font (style, font_desc);
7992 * gtk_widget_override_symbolic_color:
7993 * @widget: a #GtkWidget
7994 * @name: the name of the symbolic color to modify
7995 * @color: (allow-none): the color to assign (does not need to be allocated),
7996 * or %NULL to undo the effect of previous calls to
7997 * gtk_widget_override_symbolic_color().
7999 * Sets a symbolic color for a widget, All other style values are left
8000 * untouched. See gtk_widget_override_color() for overriding the foreground
8001 * or background color.
8006 gtk_widget_override_symbolic_color (GtkWidget *widget,
8008 const GdkRGBA *color)
8010 GtkModifierStyle *style;
8012 g_return_if_fail (GTK_IS_WIDGET (widget));
8014 style = _gtk_widget_get_modifier_properties (widget);
8015 gtk_modifier_style_map_color (style, name, color);
8019 * gtk_widget_override_cursor:
8020 * @widget: a #GtkWidget
8021 * @cursor: the color to use for primary cursor (does not need to be
8022 * allocated), or %NULL to undo the effect of previous calls to
8023 * of gtk_widget_override_cursor().
8024 * @secondary_cursor: the color to use for secondary cursor (does not
8025 * need to be allocated), or %NULL to undo the effect of previous
8026 * calls to of gtk_widget_override_cursor().
8028 * Sets the cursor color to use in a widget, overriding the
8029 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8030 * style properties. All other style values are left untouched.
8031 * See also gtk_widget_modify_style().
8033 * Note that the underlying properties have the #GdkColor type,
8034 * so the alpha value in @primary and @secondary will be ignored.
8039 gtk_widget_override_cursor (GtkWidget *widget,
8040 const GdkRGBA *cursor,
8041 const GdkRGBA *secondary_cursor)
8043 GtkModifierStyle *style;
8045 g_return_if_fail (GTK_IS_WIDGET (widget));
8047 style = _gtk_widget_get_modifier_properties (widget);
8048 gtk_modifier_style_set_color_property (style,
8050 "cursor-color", cursor);
8051 gtk_modifier_style_set_color_property (style,
8053 "secondary-cursor-color",
8058 * gtk_widget_modify_fg:
8059 * @widget: a #GtkWidget
8060 * @state: the state for which to set the foreground color
8061 * @color: (allow-none): the color to assign (does not need to be allocated),
8062 * or %NULL to undo the effect of previous calls to
8063 * of gtk_widget_modify_fg().
8065 * Sets the foreground color for a widget in a particular state.
8066 * All other style values are left untouched. See also
8067 * gtk_widget_modify_style().
8069 * Deprecated:3.0: Use gtk_widget_override_color() instead
8072 gtk_widget_modify_fg (GtkWidget *widget,
8074 const GdkColor *color)
8076 GtkStateFlags flags;
8079 g_return_if_fail (GTK_IS_WIDGET (widget));
8080 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8084 case GTK_STATE_ACTIVE:
8085 flags = GTK_STATE_FLAG_ACTIVE;
8087 case GTK_STATE_PRELIGHT:
8088 flags = GTK_STATE_FLAG_PRELIGHT;
8090 case GTK_STATE_SELECTED:
8091 flags = GTK_STATE_FLAG_SELECTED;
8093 case GTK_STATE_INSENSITIVE:
8094 flags = GTK_STATE_FLAG_INSENSITIVE;
8096 case GTK_STATE_NORMAL:
8103 rgba.red = color->red / 65535.;
8104 rgba.green = color->green / 65535.;
8105 rgba.blue = color->blue / 65535.;
8108 gtk_widget_override_color (widget, state, &rgba);
8111 gtk_widget_override_color (widget, state, NULL);
8115 * gtk_widget_modify_bg:
8116 * @widget: a #GtkWidget
8117 * @state: the state for which to set the background color
8118 * @color: (allow-none): the color to assign (does not need to be allocated),
8119 * or %NULL to undo the effect of previous calls to
8120 * of gtk_widget_modify_bg().
8122 * Sets the background color for a widget in a particular state.
8123 * All other style values are left untouched. See also
8124 * gtk_widget_modify_style().
8126 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
8127 * draw on their parent container's window and thus may not draw any
8128 * background themselves. This is the case for e.g. #GtkLabel. To modify
8129 * the background of such widgets, you have to set the background color
8130 * on their parent; if you want to set the background of a rectangular
8131 * area around a label, try placing the label in a #GtkEventBox widget
8132 * and setting the background color on that.
8134 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8137 gtk_widget_modify_bg (GtkWidget *widget,
8139 const GdkColor *color)
8141 GtkStateFlags flags;
8144 g_return_if_fail (GTK_IS_WIDGET (widget));
8145 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8149 case GTK_STATE_ACTIVE:
8150 flags = GTK_STATE_FLAG_ACTIVE;
8152 case GTK_STATE_PRELIGHT:
8153 flags = GTK_STATE_FLAG_PRELIGHT;
8155 case GTK_STATE_SELECTED:
8156 flags = GTK_STATE_FLAG_SELECTED;
8158 case GTK_STATE_INSENSITIVE:
8159 flags = GTK_STATE_FLAG_INSENSITIVE;
8161 case GTK_STATE_NORMAL:
8168 rgba.red = color->red / 65535.;
8169 rgba.green = color->green / 65535.;
8170 rgba.blue = color->blue / 65535.;
8173 gtk_widget_override_background_color (widget, state, &rgba);
8176 gtk_widget_override_background_color (widget, state, NULL);
8180 * gtk_widget_modify_text:
8181 * @widget: a #GtkWidget
8182 * @state: the state for which to set the text color
8183 * @color: (allow-none): the color to assign (does not need to be allocated),
8184 * or %NULL to undo the effect of previous calls to
8185 * of gtk_widget_modify_text().
8187 * Sets the text color for a widget in a particular state. All other
8188 * style values are left untouched. The text color is the foreground
8189 * color used along with the base color (see gtk_widget_modify_base())
8190 * for widgets such as #GtkEntry and #GtkTextView. See also
8191 * gtk_widget_modify_style().
8193 * Deprecated:3.0: Use gtk_widget_override_color() instead
8196 gtk_widget_modify_text (GtkWidget *widget,
8198 const GdkColor *color)
8200 g_return_if_fail (GTK_IS_WIDGET (widget));
8201 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8203 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
8207 * gtk_widget_modify_base:
8208 * @widget: a #GtkWidget
8209 * @state: the state for which to set the base color
8210 * @color: (allow-none): the color to assign (does not need to be allocated),
8211 * or %NULL to undo the effect of previous calls to
8212 * of gtk_widget_modify_base().
8214 * Sets the base color for a widget in a particular state.
8215 * All other style values are left untouched. The base color
8216 * is the background color used along with the text color
8217 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
8218 * and #GtkTextView. See also gtk_widget_modify_style().
8220 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
8221 * draw on their parent container's window and thus may not draw any
8222 * background themselves. This is the case for e.g. #GtkLabel. To modify
8223 * the background of such widgets, you have to set the base color on their
8224 * parent; if you want to set the background of a rectangular area around
8225 * a label, try placing the label in a #GtkEventBox widget and setting
8226 * the base color on that.
8228 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8231 gtk_widget_modify_base (GtkWidget *widget,
8233 const GdkColor *color)
8235 g_return_if_fail (GTK_IS_WIDGET (widget));
8236 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8238 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
8242 * gtk_widget_modify_cursor:
8243 * @widget: a #GtkWidget
8244 * @primary: the color to use for primary cursor (does not need to be
8245 * allocated), or %NULL to undo the effect of previous calls to
8246 * of gtk_widget_modify_cursor().
8247 * @secondary: the color to use for secondary cursor (does not need to be
8248 * allocated), or %NULL to undo the effect of previous calls to
8249 * of gtk_widget_modify_cursor().
8251 * Sets the cursor color to use in a widget, overriding the
8252 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8253 * style properties. All other style values are left untouched.
8254 * See also gtk_widget_modify_style().
8258 * Deprecated: 3.0. Use gtk_widget_override_cursor() instead.
8261 gtk_widget_modify_cursor (GtkWidget *widget,
8262 const GdkColor *primary,
8263 const GdkColor *secondary)
8265 GdkRGBA primary_rgba, secondary_rgba;
8267 g_return_if_fail (GTK_IS_WIDGET (widget));
8269 primary_rgba.red = primary->red / 65535.;
8270 primary_rgba.green = primary->green / 65535.;
8271 primary_rgba.blue = primary->blue / 65535.;
8272 primary_rgba.alpha = 1;
8274 secondary_rgba.red = secondary->red / 65535.;
8275 secondary_rgba.green = secondary->green / 65535.;
8276 secondary_rgba.blue = secondary->blue / 65535.;
8277 secondary_rgba.alpha = 1;
8279 gtk_widget_override_cursor (widget, &primary_rgba, &secondary_rgba);
8283 * gtk_widget_modify_font:
8284 * @widget: a #GtkWidget
8285 * @font_desc: (allow-none): the font description to use, or %NULL to undo
8286 * the effect of previous calls to gtk_widget_modify_font().
8288 * Sets the font to use for a widget. All other style values are left
8289 * untouched. See also gtk_widget_modify_style().
8291 * Deprecated:3.0: Use gtk_widget_override_font() instead
8294 gtk_widget_modify_font (GtkWidget *widget,
8295 PangoFontDescription *font_desc)
8297 g_return_if_fail (GTK_IS_WIDGET (widget));
8299 gtk_widget_override_font (widget, font_desc);
8303 gtk_widget_real_direction_changed (GtkWidget *widget,
8304 GtkTextDirection previous_direction)
8306 gtk_widget_queue_resize (widget);
8310 gtk_widget_real_style_set (GtkWidget *widget,
8311 GtkStyle *previous_style)
8316 GtkWidget *previous_toplevel;
8317 GdkScreen *previous_screen;
8318 GdkScreen *new_screen;
8319 } HierarchyChangedInfo;
8322 do_screen_change (GtkWidget *widget,
8323 GdkScreen *old_screen,
8324 GdkScreen *new_screen)
8326 if (old_screen != new_screen)
8328 GtkStyleContext *context;
8332 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8334 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8337 _gtk_tooltip_hide (widget);
8339 context = gtk_widget_get_style_context (widget);
8340 gtk_style_context_set_screen (context, gtk_widget_get_screen (widget));
8342 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8347 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8348 gpointer client_data)
8350 GtkWidgetPrivate *priv = widget->priv;
8351 HierarchyChangedInfo *info = client_data;
8352 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8353 (priv->parent && priv->parent->priv->anchored);
8355 if (priv->anchored != new_anchored)
8357 g_object_ref (widget);
8359 priv->anchored = new_anchored;
8361 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8362 do_screen_change (widget, info->previous_screen, info->new_screen);
8364 if (GTK_IS_CONTAINER (widget))
8365 gtk_container_forall (GTK_CONTAINER (widget),
8366 gtk_widget_propagate_hierarchy_changed_recurse,
8369 g_object_unref (widget);
8374 * _gtk_widget_propagate_hierarchy_changed:
8375 * @widget: a #GtkWidget
8376 * @previous_toplevel: Previous toplevel
8378 * Propagates changes in the anchored state to a widget and all
8379 * children, unsetting or setting the %ANCHORED flag, and
8380 * emitting #GtkWidget::hierarchy-changed.
8383 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8384 GtkWidget *previous_toplevel)
8386 GtkWidgetPrivate *priv = widget->priv;
8387 HierarchyChangedInfo info;
8389 info.previous_toplevel = previous_toplevel;
8390 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8392 if (gtk_widget_is_toplevel (widget) ||
8393 (priv->parent && priv->parent->priv->anchored))
8394 info.new_screen = gtk_widget_get_screen (widget);
8396 info.new_screen = NULL;
8398 if (info.previous_screen)
8399 g_object_ref (info.previous_screen);
8400 if (previous_toplevel)
8401 g_object_ref (previous_toplevel);
8403 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8405 if (previous_toplevel)
8406 g_object_unref (previous_toplevel);
8407 if (info.previous_screen)
8408 g_object_unref (info.previous_screen);
8412 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8413 gpointer client_data)
8415 HierarchyChangedInfo *info = client_data;
8417 g_object_ref (widget);
8419 do_screen_change (widget, info->previous_screen, info->new_screen);
8421 if (GTK_IS_CONTAINER (widget))
8422 gtk_container_forall (GTK_CONTAINER (widget),
8423 gtk_widget_propagate_screen_changed_recurse,
8426 g_object_unref (widget);
8430 * gtk_widget_is_composited:
8431 * @widget: a #GtkWidget
8433 * Whether @widget can rely on having its alpha channel
8434 * drawn correctly. On X11 this function returns whether a
8435 * compositing manager is running for @widget's screen.
8437 * Please note that the semantics of this call will change
8438 * in the future if used on a widget that has a composited
8439 * window in its hierarchy (as set by gdk_window_set_composited()).
8441 * Return value: %TRUE if the widget can rely on its alpha
8442 * channel being drawn correctly.
8447 gtk_widget_is_composited (GtkWidget *widget)
8451 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8453 screen = gtk_widget_get_screen (widget);
8455 return gdk_screen_is_composited (screen);
8459 propagate_composited_changed (GtkWidget *widget,
8462 if (GTK_IS_CONTAINER (widget))
8464 gtk_container_forall (GTK_CONTAINER (widget),
8465 propagate_composited_changed,
8469 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8473 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8475 propagate_composited_changed (widget, NULL);
8479 * _gtk_widget_propagate_screen_changed:
8480 * @widget: a #GtkWidget
8481 * @previous_screen: Previous screen
8483 * Propagates changes in the screen for a widget to all
8484 * children, emitting #GtkWidget::screen-changed.
8487 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8488 GdkScreen *previous_screen)
8490 HierarchyChangedInfo info;
8492 info.previous_screen = previous_screen;
8493 info.new_screen = gtk_widget_get_screen (widget);
8495 if (previous_screen)
8496 g_object_ref (previous_screen);
8498 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8500 if (previous_screen)
8501 g_object_unref (previous_screen);
8505 reset_style_recurse (GtkWidget *widget, gpointer data)
8507 if (widget->priv->context)
8509 _gtk_widget_update_path (widget);
8510 gtk_style_context_set_path (widget->priv->context,
8511 widget->priv->path);
8514 if (GTK_IS_CONTAINER (widget))
8515 gtk_container_forall (GTK_CONTAINER (widget),
8516 reset_style_recurse,
8521 * gtk_widget_reset_style:
8522 * @widget: a #GtkWidget
8524 * Updates the style context of @widget and all descendents
8525 * by updating its widget path. #GtkContainer<!-- -->s may want
8526 * to use this on a child when reordering it in a way that a different
8527 * style might apply to it. See also gtk_container_get_path_for_child().
8532 gtk_widget_reset_style (GtkWidget *widget)
8534 g_return_if_fail (GTK_IS_WIDGET (widget));
8536 reset_style_recurse (widget, NULL);
8540 * gtk_widget_reset_rc_styles:
8541 * @widget: a #GtkWidget.
8543 * Reset the styles of @widget and all descendents, so when
8544 * they are looked up again, they get the correct values
8545 * for the currently loaded RC file settings.
8547 * This function is not useful for applications.
8549 * Deprecated:3.0: Use #GtkStyleContext instead
8552 gtk_widget_reset_rc_styles (GtkWidget *widget)
8554 g_return_if_fail (GTK_IS_WIDGET (widget));
8556 reset_style_recurse (widget, NULL);
8560 * gtk_widget_get_default_style:
8562 * Returns the default style used by all widgets initially.
8564 * Returns: (transfer none): the default style. This #GtkStyle
8565 * object is owned by GTK+ and should not be modified or freed.
8567 * Deprecated:3.0: Use #GtkStyleContext instead
8570 gtk_widget_get_default_style (void)
8572 if (!gtk_default_style)
8574 gtk_default_style = gtk_style_new ();
8575 g_object_ref (gtk_default_style);
8578 return gtk_default_style;
8581 static PangoContext *
8582 gtk_widget_peek_pango_context (GtkWidget *widget)
8584 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8588 * gtk_widget_get_pango_context:
8589 * @widget: a #GtkWidget
8591 * Gets a #PangoContext with the appropriate font map, font description,
8592 * and base direction for this widget. Unlike the context returned
8593 * by gtk_widget_create_pango_context(), this context is owned by
8594 * the widget (it can be used until the screen for the widget changes
8595 * or the widget is removed from its toplevel), and will be updated to
8596 * match any changes to the widget's attributes.
8598 * If you create and keep a #PangoLayout using this context, you must
8599 * deal with changes to the context by calling pango_layout_context_changed()
8600 * on the layout in response to the #GtkWidget::style-updated and
8601 * #GtkWidget::direction-changed signals for the widget.
8603 * Return value: (transfer none): the #PangoContext for the widget.
8606 gtk_widget_get_pango_context (GtkWidget *widget)
8608 PangoContext *context;
8610 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8612 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8615 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8616 g_object_set_qdata_full (G_OBJECT (widget),
8617 quark_pango_context,
8626 update_pango_context (GtkWidget *widget,
8627 PangoContext *context)
8629 PangoFontDescription *font_desc;
8630 GtkStyleContext *style_context;
8632 style_context = gtk_widget_get_style_context (widget);
8634 gtk_style_context_get (style_context,
8635 gtk_widget_get_state_flags (widget),
8639 pango_context_set_font_description (context, font_desc);
8640 pango_context_set_base_dir (context,
8641 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8642 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8644 pango_font_description_free (font_desc);
8648 gtk_widget_update_pango_context (GtkWidget *widget)
8650 PangoContext *context = gtk_widget_peek_pango_context (widget);
8656 update_pango_context (widget, context);
8658 screen = gtk_widget_get_screen_unchecked (widget);
8661 pango_cairo_context_set_resolution (context,
8662 gdk_screen_get_resolution (screen));
8663 pango_cairo_context_set_font_options (context,
8664 gdk_screen_get_font_options (screen));
8670 * gtk_widget_create_pango_context:
8671 * @widget: a #GtkWidget
8673 * Creates a new #PangoContext with the appropriate font map,
8674 * font description, and base direction for drawing text for
8675 * this widget. See also gtk_widget_get_pango_context().
8677 * Return value: (transfer full): the new #PangoContext
8680 gtk_widget_create_pango_context (GtkWidget *widget)
8683 PangoContext *context;
8685 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8687 screen = gtk_widget_get_screen_unchecked (widget);
8690 GTK_NOTE (MULTIHEAD,
8691 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8693 screen = gdk_screen_get_default ();
8696 context = gdk_pango_context_get_for_screen (screen);
8698 update_pango_context (widget, context);
8699 pango_context_set_language (context, gtk_get_default_language ());
8705 * gtk_widget_create_pango_layout:
8706 * @widget: a #GtkWidget
8707 * @text: text to set on the layout (can be %NULL)
8709 * Creates a new #PangoLayout with the appropriate font map,
8710 * font description, and base direction for drawing text for
8713 * If you keep a #PangoLayout created in this way around, in order to
8714 * notify the layout of changes to the base direction or font of this
8715 * widget, you must call pango_layout_context_changed() in response to
8716 * the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
8719 * Return value: (transfer full): the new #PangoLayout
8722 gtk_widget_create_pango_layout (GtkWidget *widget,
8725 PangoLayout *layout;
8726 PangoContext *context;
8728 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8730 context = gtk_widget_get_pango_context (widget);
8731 layout = pango_layout_new (context);
8734 pango_layout_set_text (layout, text, -1);
8740 * gtk_widget_render_icon_pixbuf:
8741 * @widget: a #GtkWidget
8742 * @stock_id: a stock ID
8743 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8744 * render at the size of the source and don't scale (if there are
8745 * multiple source sizes, GTK+ picks one of the available sizes).
8747 * A convenience function that uses the theme engine and style
8748 * settings for @widget to look up @stock_id and render it to
8749 * a pixbuf. @stock_id should be a stock icon ID such as
8750 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8751 * such as #GTK_ICON_SIZE_MENU.
8753 * The pixels in the returned #GdkPixbuf are shared with the rest of
8754 * the application and should not be modified. The pixbuf should be freed
8755 * after use with g_object_unref().
8757 * Return value: (transfer full): a new pixbuf, or %NULL if the
8758 * stock ID wasn't known
8763 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
8764 const gchar *stock_id,
8767 GtkWidgetPrivate *priv;
8768 GtkIconSet *icon_set;
8770 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8771 g_return_val_if_fail (stock_id != NULL, NULL);
8772 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8774 priv = widget->priv;
8776 gtk_widget_ensure_style (widget);
8778 icon_set = gtk_style_context_lookup_icon_set (priv->context, stock_id);
8780 if (icon_set == NULL)
8783 return gtk_icon_set_render_icon_pixbuf (icon_set, priv->context, size);
8787 * gtk_widget_render_icon:
8788 * @widget: a #GtkWidget
8789 * @stock_id: a stock ID
8790 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8791 * render at the size of the source and don't scale (if there are
8792 * multiple source sizes, GTK+ picks one of the available sizes).
8793 * @detail: (allow-none): render detail to pass to theme engine
8795 * A convenience function that uses the theme engine and RC file
8796 * settings for @widget to look up @stock_id and render it to
8797 * a pixbuf. @stock_id should be a stock icon ID such as
8798 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8799 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
8800 * identifies the widget or code doing the rendering, so that
8801 * theme engines can special-case rendering for that widget or code.
8803 * The pixels in the returned #GdkPixbuf are shared with the rest of
8804 * the application and should not be modified. The pixbuf should be freed
8805 * after use with g_object_unref().
8807 * Return value: (transfer full): a new pixbuf, or %NULL if the
8808 * stock ID wasn't known
8810 * Deprecated: 3.0: Use gtk_widget_render_icon_pixbuf() instead.
8813 gtk_widget_render_icon (GtkWidget *widget,
8814 const gchar *stock_id,
8816 const gchar *detail)
8818 return gtk_widget_render_icon_pixbuf (widget, stock_id, size);
8822 * gtk_widget_set_parent_window:
8823 * @widget: a #GtkWidget.
8824 * @parent_window: the new parent window.
8826 * Sets a non default parent window for @widget.
8829 gtk_widget_set_parent_window (GtkWidget *widget,
8830 GdkWindow *parent_window)
8832 GdkWindow *old_parent_window;
8834 g_return_if_fail (GTK_IS_WIDGET (widget));
8836 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8837 quark_parent_window);
8839 if (parent_window != old_parent_window)
8841 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8843 if (old_parent_window)
8844 g_object_unref (old_parent_window);
8846 g_object_ref (parent_window);
8851 * gtk_widget_get_parent_window:
8852 * @widget: a #GtkWidget.
8854 * Gets @widget's parent window.
8856 * Returns: (transfer none): the parent window of @widget.
8859 gtk_widget_get_parent_window (GtkWidget *widget)
8861 GtkWidgetPrivate *priv;
8862 GdkWindow *parent_window;
8864 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8866 priv = widget->priv;
8868 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8870 return (parent_window != NULL) ? parent_window :
8871 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8876 * gtk_widget_set_child_visible:
8877 * @widget: a #GtkWidget
8878 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8880 * Sets whether @widget should be mapped along with its when its parent
8881 * is mapped and @widget has been shown with gtk_widget_show().
8883 * The child visibility can be set for widget before it is added to
8884 * a container with gtk_widget_set_parent(), to avoid mapping
8885 * children unnecessary before immediately unmapping them. However
8886 * it will be reset to its default state of %TRUE when the widget
8887 * is removed from a container.
8889 * Note that changing the child visibility of a widget does not
8890 * queue a resize on the widget. Most of the time, the size of
8891 * a widget is computed from all visible children, whether or
8892 * not they are mapped. If this is not the case, the container
8893 * can queue a resize itself.
8895 * This function is only useful for container implementations and
8896 * never should be called by an application.
8899 gtk_widget_set_child_visible (GtkWidget *widget,
8900 gboolean is_visible)
8902 GtkWidgetPrivate *priv;
8904 g_return_if_fail (GTK_IS_WIDGET (widget));
8905 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8907 priv = widget->priv;
8909 g_object_ref (widget);
8912 priv->child_visible = TRUE;
8915 GtkWidget *toplevel;
8917 priv->child_visible = FALSE;
8919 toplevel = gtk_widget_get_toplevel (widget);
8920 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8921 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8924 if (priv->parent && gtk_widget_get_realized (priv->parent))
8926 if (gtk_widget_get_mapped (priv->parent) &&
8927 priv->child_visible &&
8928 gtk_widget_get_visible (widget))
8929 gtk_widget_map (widget);
8931 gtk_widget_unmap (widget);
8934 g_object_unref (widget);
8938 * gtk_widget_get_child_visible:
8939 * @widget: a #GtkWidget
8941 * Gets the value set with gtk_widget_set_child_visible().
8942 * If you feel a need to use this function, your code probably
8943 * needs reorganization.
8945 * This function is only useful for container implementations and
8946 * never should be called by an application.
8948 * Return value: %TRUE if the widget is mapped with the parent.
8951 gtk_widget_get_child_visible (GtkWidget *widget)
8953 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8955 return widget->priv->child_visible;
8959 gtk_widget_get_screen_unchecked (GtkWidget *widget)
8961 GtkWidget *toplevel;
8963 toplevel = gtk_widget_get_toplevel (widget);
8965 if (gtk_widget_is_toplevel (toplevel))
8967 if (GTK_IS_WINDOW (toplevel))
8968 return gtk_window_get_screen (GTK_WINDOW (toplevel));
8969 else if (GTK_IS_INVISIBLE (toplevel))
8970 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
8977 * gtk_widget_get_screen:
8978 * @widget: a #GtkWidget
8980 * Get the #GdkScreen from the toplevel window associated with
8981 * this widget. This function can only be called after the widget
8982 * has been added to a widget hierarchy with a #GtkWindow
8985 * In general, you should only create screen specific
8986 * resources when a widget has been realized, and you should
8987 * free those resources when the widget is unrealized.
8989 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
8994 gtk_widget_get_screen (GtkWidget *widget)
8998 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9000 screen = gtk_widget_get_screen_unchecked (widget);
9007 g_warning (G_STRLOC ": Can't get associated screen"
9008 " for a widget unless it is inside a toplevel GtkWindow\n"
9009 " widget type is %s associated top level type is %s",
9010 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9011 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9013 return gdk_screen_get_default ();
9018 * gtk_widget_has_screen:
9019 * @widget: a #GtkWidget
9021 * Checks whether there is a #GdkScreen is associated with
9022 * this widget. All toplevel widgets have an associated
9023 * screen, and all widgets added into a hierarchy with a toplevel
9024 * window at the top.
9026 * Return value: %TRUE if there is a #GdkScreen associcated
9032 gtk_widget_has_screen (GtkWidget *widget)
9034 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9036 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9040 * gtk_widget_get_display:
9041 * @widget: a #GtkWidget
9043 * Get the #GdkDisplay for the toplevel window associated with
9044 * this widget. This function can only be called after the widget
9045 * has been added to a widget hierarchy with a #GtkWindow at the top.
9047 * In general, you should only create display specific
9048 * resources when a widget has been realized, and you should
9049 * free those resources when the widget is unrealized.
9051 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9056 gtk_widget_get_display (GtkWidget *widget)
9058 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9060 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9064 * gtk_widget_get_root_window:
9065 * @widget: a #GtkWidget
9067 * Get the root window where this widget is located. This function can
9068 * only be called after the widget has been added to a widget
9069 * hierarchy with #GtkWindow at the top.
9071 * The root window is useful for such purposes as creating a popup
9072 * #GdkWindow associated with the window. In general, you should only
9073 * create display specific resources when a widget has been realized,
9074 * and you should free those resources when the widget is unrealized.
9076 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9081 gtk_widget_get_root_window (GtkWidget *widget)
9083 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9085 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9089 * gtk_widget_child_focus:
9090 * @widget: a #GtkWidget
9091 * @direction: direction of focus movement
9093 * This function is used by custom widget implementations; if you're
9094 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9095 * to a particular widget, and gtk_container_set_focus_chain() to
9096 * change the focus tab order. So you may want to investigate those
9097 * functions instead.
9099 * gtk_widget_child_focus() is called by containers as the user moves
9100 * around the window using keyboard shortcuts. @direction indicates
9101 * what kind of motion is taking place (up, down, left, right, tab
9102 * forward, tab backward). gtk_widget_child_focus() emits the
9103 * #GtkWidget::focus signal; widgets override the default handler
9104 * for this signal in order to implement appropriate focus behavior.
9106 * The default ::focus handler for a widget should return %TRUE if
9107 * moving in @direction left the focus on a focusable location inside
9108 * that widget, and %FALSE if moving in @direction moved the focus
9109 * outside the widget. If returning %TRUE, widgets normally
9110 * call gtk_widget_grab_focus() to place the focus accordingly;
9111 * if returning %FALSE, they don't modify the current focus location.
9113 * Return value: %TRUE if focus ended up inside @widget
9116 gtk_widget_child_focus (GtkWidget *widget,
9117 GtkDirectionType direction)
9119 gboolean return_val;
9121 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9123 if (!gtk_widget_get_visible (widget) ||
9124 !gtk_widget_is_sensitive (widget))
9127 /* child widgets must set CAN_FOCUS, containers
9128 * don't have to though.
9130 if (!GTK_IS_CONTAINER (widget) &&
9131 !gtk_widget_get_can_focus (widget))
9134 g_signal_emit (widget,
9135 widget_signals[FOCUS],
9137 direction, &return_val);
9143 * gtk_widget_keynav_failed:
9144 * @widget: a #GtkWidget
9145 * @direction: direction of focus movement
9147 * This function should be called whenever keyboard navigation within
9148 * a single widget hits a boundary. The function emits the
9149 * #GtkWidget::keynav-failed signal on the widget and its return
9150 * value should be interpreted in a way similar to the return value of
9151 * gtk_widget_child_focus():
9153 * When %TRUE is returned, stay in the widget, the failed keyboard
9154 * navigation is Ok and/or there is nowhere we can/should move the
9157 * When %FALSE is returned, the caller should continue with keyboard
9158 * navigation outside the widget, e.g. by calling
9159 * gtk_widget_child_focus() on the widget's toplevel.
9161 * The default ::keynav-failed handler returns %TRUE for
9162 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9163 * values of #GtkDirectionType, it looks at the
9164 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9165 * if the setting is %TRUE. This way the entire user interface
9166 * becomes cursor-navigatable on input devices such as mobile phones
9167 * which only have cursor keys but no tab key.
9169 * Whenever the default handler returns %TRUE, it also calls
9170 * gtk_widget_error_bell() to notify the user of the failed keyboard
9173 * A use case for providing an own implementation of ::keynav-failed
9174 * (either by connecting to it or by overriding it) would be a row of
9175 * #GtkEntry widgets where the user should be able to navigate the
9176 * entire row with the cursor keys, as e.g. known from user interfaces
9177 * that require entering license keys.
9179 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9180 * if the emitting widget should try to handle the keyboard
9181 * navigation attempt in its parent container(s).
9186 gtk_widget_keynav_failed (GtkWidget *widget,
9187 GtkDirectionType direction)
9189 gboolean return_val;
9191 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9193 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9194 direction, &return_val);
9200 * gtk_widget_error_bell:
9201 * @widget: a #GtkWidget
9203 * Notifies the user about an input-related error on this widget.
9204 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9205 * gdk_window_beep(), otherwise it does nothing.
9207 * Note that the effect of gdk_window_beep() can be configured in many
9208 * ways, depending on the windowing backend and the desktop environment
9209 * or window manager that is used.
9214 gtk_widget_error_bell (GtkWidget *widget)
9216 GtkWidgetPrivate *priv;
9217 GtkSettings* settings;
9220 g_return_if_fail (GTK_IS_WIDGET (widget));
9222 priv = widget->priv;
9224 settings = gtk_widget_get_settings (widget);
9228 g_object_get (settings,
9229 "gtk-error-bell", &beep,
9232 if (beep && priv->window)
9233 gdk_window_beep (priv->window);
9237 gtk_widget_set_usize_internal (GtkWidget *widget,
9240 GtkQueueResizeFlags flags)
9242 GtkWidgetAuxInfo *aux_info;
9243 gboolean changed = FALSE;
9245 g_object_freeze_notify (G_OBJECT (widget));
9247 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
9249 if (width > -2 && aux_info->width != width)
9251 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9252 g_object_notify (G_OBJECT (widget), "width-request");
9253 aux_info->width = width;
9256 if (height > -2 && aux_info->height != height)
9258 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9259 g_object_notify (G_OBJECT (widget), "height-request");
9260 aux_info->height = height;
9264 if (gtk_widget_get_visible (widget) && changed)
9266 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9267 gtk_widget_queue_resize (widget);
9269 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9272 g_object_thaw_notify (G_OBJECT (widget));
9276 * gtk_widget_set_size_request:
9277 * @widget: a #GtkWidget
9278 * @width: width @widget should request, or -1 to unset
9279 * @height: height @widget should request, or -1 to unset
9281 * Sets the minimum size of a widget; that is, the widget's size
9282 * request will be @width by @height. You can use this function to
9283 * force a widget to be either larger or smaller than it normally
9286 * In most cases, gtk_window_set_default_size() is a better choice for
9287 * toplevel windows than this function; setting the default size will
9288 * still allow users to shrink the window. Setting the size request
9289 * will force them to leave the window at least as large as the size
9290 * request. When dealing with window sizes,
9291 * gtk_window_set_geometry_hints() can be a useful function as well.
9293 * Note the inherent danger of setting any fixed size - themes,
9294 * translations into other languages, different fonts, and user action
9295 * can all change the appropriate size for a given widget. So, it's
9296 * basically impossible to hardcode a size that will always be
9299 * The size request of a widget is the smallest size a widget can
9300 * accept while still functioning well and drawing itself correctly.
9301 * However in some strange cases a widget may be allocated less than
9302 * its requested size, and in many cases a widget may be allocated more
9303 * space than it requested.
9305 * If the size request in a given direction is -1 (unset), then
9306 * the "natural" size request of the widget will be used instead.
9308 * Widgets can't actually be allocated a size less than 1 by 1, but
9309 * you can pass 0,0 to this function to mean "as small as possible."
9311 * The size request set here does not include any margin from the
9312 * #GtkWidget properties margin-left, margin-right, margin-top, and
9313 * margin-bottom, but it does include pretty much all other padding
9314 * or border properties set by any subclass of #GtkWidget.
9317 gtk_widget_set_size_request (GtkWidget *widget,
9321 g_return_if_fail (GTK_IS_WIDGET (widget));
9322 g_return_if_fail (width >= -1);
9323 g_return_if_fail (height >= -1);
9330 gtk_widget_set_usize_internal (widget, width, height, 0);
9335 * gtk_widget_get_size_request:
9336 * @widget: a #GtkWidget
9337 * @width: (out) (allow-none): return location for width, or %NULL
9338 * @height: (out) (allow-none): return location for height, or %NULL
9340 * Gets the size request that was explicitly set for the widget using
9341 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9342 * @height indicates that that dimension has not been set explicitly
9343 * and the natural requisition of the widget will be used intead. See
9344 * gtk_widget_set_size_request(). To get the size a widget will
9345 * actually request, call gtk_widget_get_preferred_size() instead of
9349 gtk_widget_get_size_request (GtkWidget *widget,
9353 const GtkWidgetAuxInfo *aux_info;
9355 g_return_if_fail (GTK_IS_WIDGET (widget));
9357 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9360 *width = aux_info->width;
9363 *height = aux_info->height;
9367 * _gtk_widget_override_size_request:
9368 * @widget: a #GtkWidget
9369 * @width: new forced minimum width
9370 * @height: new forced minimum height
9371 * @old_width: location to store previous forced minimum width
9372 * @old_width: location to store previous forced minumum height
9374 * Temporarily establishes a forced minimum size for a widget; this
9375 * is used by GtkWindow when calculating the size to add to the
9376 * window's geometry widget. Cached sizes for the widget and its
9377 * parents are invalidated, so that subsequent calls to the size
9378 * negotiation machinery produce the overriden result, but the
9379 * widget is not queued for relayout or redraw. The old size must
9380 * be restored with _gtk_widget_restore_size_request() or things
9384 _gtk_widget_override_size_request (GtkWidget *widget,
9390 gtk_widget_get_size_request (widget, old_width, old_height);
9391 gtk_widget_set_usize_internal (widget, width, height,
9392 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9396 * _gtk_widget_restore_size_request:
9397 * @widget: a #GtkWidget
9398 * @old_width: saved forced minimum size
9399 * @old_height: saved forced minimum size
9401 * Undoes the operation of_gtk_widget_override_size_request().
9404 _gtk_widget_restore_size_request (GtkWidget *widget,
9408 gtk_widget_set_usize_internal (widget, old_width, old_height,
9409 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9413 * gtk_widget_set_events:
9414 * @widget: a #GtkWidget
9415 * @events: event mask
9417 * Sets the event mask (see #GdkEventMask) for a widget. The event
9418 * mask determines which events a widget will receive. Keep in mind
9419 * that different widgets have different default event masks, and by
9420 * changing the event mask you may disrupt a widget's functionality,
9421 * so be careful. This function must be called while a widget is
9422 * unrealized. Consider gtk_widget_add_events() for widgets that are
9423 * already realized, or if you want to preserve the existing event
9424 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9425 * to get events on those widgets, place them inside a #GtkEventBox
9426 * and receive events on the event box.
9429 gtk_widget_set_events (GtkWidget *widget,
9432 g_return_if_fail (GTK_IS_WIDGET (widget));
9433 g_return_if_fail (!gtk_widget_get_realized (widget));
9435 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9436 GINT_TO_POINTER (events));
9437 g_object_notify (G_OBJECT (widget), "events");
9441 * gtk_widget_set_device_events:
9442 * @widget: a #GtkWidget
9443 * @device: a #GdkDevice
9444 * @events: event mask
9446 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9447 * mask determines which events a widget will receive from @device. Keep
9448 * in mind that different widgets have different default event masks, and by
9449 * changing the event mask you may disrupt a widget's functionality,
9450 * so be careful. This function must be called while a widget is
9451 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9452 * already realized, or if you want to preserve the existing event
9453 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9454 * to get events on those widgets, place them inside a #GtkEventBox
9455 * and receive events on the event box.
9460 gtk_widget_set_device_events (GtkWidget *widget,
9462 GdkEventMask events)
9464 GHashTable *device_events;
9466 g_return_if_fail (GTK_IS_WIDGET (widget));
9467 g_return_if_fail (GDK_IS_DEVICE (device));
9468 g_return_if_fail (!gtk_widget_get_realized (widget));
9470 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9472 if (G_UNLIKELY (!device_events))
9474 device_events = g_hash_table_new (NULL, NULL);
9475 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9476 (GDestroyNotify) g_hash_table_unref);
9479 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9483 gtk_widget_add_events_internal_list (GtkWidget *widget,
9490 for (l = window_list; l != NULL; l = l->next)
9492 GdkWindow *window = l->data;
9495 gdk_window_get_user_data (window, &user_data);
9496 if (user_data == widget)
9501 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9503 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9505 children = gdk_window_get_children (window);
9506 gtk_widget_add_events_internal_list (widget, device, events, children);
9507 g_list_free (children);
9513 gtk_widget_add_events_internal (GtkWidget *widget,
9517 GtkWidgetPrivate *priv = widget->priv;
9520 if (!gtk_widget_get_has_window (widget))
9521 window_list = gdk_window_get_children (priv->window);
9523 window_list = g_list_prepend (NULL, priv->window);
9525 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9527 g_list_free (window_list);
9531 * gtk_widget_add_events:
9532 * @widget: a #GtkWidget
9533 * @events: an event mask, see #GdkEventMask
9535 * Adds the events in the bitfield @events to the event mask for
9536 * @widget. See gtk_widget_set_events() for details.
9539 gtk_widget_add_events (GtkWidget *widget,
9544 g_return_if_fail (GTK_IS_WIDGET (widget));
9546 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9547 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9548 GINT_TO_POINTER (old_events | events));
9550 if (gtk_widget_get_realized (widget))
9551 gtk_widget_add_events_internal (widget, NULL, events);
9553 g_object_notify (G_OBJECT (widget), "events");
9557 * gtk_widget_add_device_events:
9558 * @widget: a #GtkWidget
9559 * @device: a #GdkDevice
9560 * @events: an event mask, see #GdkEventMask
9562 * Adds the device events in the bitfield @events to the event mask for
9563 * @widget. See gtk_widget_set_device_events() for details.
9568 gtk_widget_add_device_events (GtkWidget *widget,
9570 GdkEventMask events)
9572 GdkEventMask old_events;
9573 GHashTable *device_events;
9575 g_return_if_fail (GTK_IS_WIDGET (widget));
9576 g_return_if_fail (GDK_IS_DEVICE (device));
9578 old_events = gtk_widget_get_device_events (widget, device);
9580 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9582 if (G_UNLIKELY (!device_events))
9584 device_events = g_hash_table_new (NULL, NULL);
9585 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9586 (GDestroyNotify) g_hash_table_unref);
9589 g_hash_table_insert (device_events, device,
9590 GUINT_TO_POINTER (old_events | events));
9592 if (gtk_widget_get_realized (widget))
9593 gtk_widget_add_events_internal (widget, device, events);
9595 g_object_notify (G_OBJECT (widget), "events");
9599 * gtk_widget_get_toplevel:
9600 * @widget: a #GtkWidget
9602 * This function returns the topmost widget in the container hierarchy
9603 * @widget is a part of. If @widget has no parent widgets, it will be
9604 * returned as the topmost widget. No reference will be added to the
9605 * returned widget; it should not be unreferenced.
9607 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9608 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9610 * %NULL if @widget wasn't inside a toplevel window, and if the
9611 * window was inside a #GtkWindow-derived widget which was in turn
9612 * inside the toplevel #GtkWindow. While the second case may
9613 * seem unlikely, it actually happens when a #GtkPlug is embedded
9614 * inside a #GtkSocket within the same application.
9616 * To reliably find the toplevel #GtkWindow, use
9617 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9618 * is set on the result.
9620 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9621 * if (gtk_widget_is_toplevel (toplevel))
9623 * /* Perform action on toplevel. */
9627 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9628 * if there's no ancestor.
9631 gtk_widget_get_toplevel (GtkWidget *widget)
9633 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9635 while (widget->priv->parent)
9636 widget = widget->priv->parent;
9642 * gtk_widget_get_ancestor:
9643 * @widget: a #GtkWidget
9644 * @widget_type: ancestor type
9646 * Gets the first ancestor of @widget with type @widget_type. For example,
9647 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9648 * the first #GtkBox that's an ancestor of @widget. No reference will be
9649 * added to the returned widget; it should not be unreferenced. See note
9650 * about checking for a toplevel #GtkWindow in the docs for
9651 * gtk_widget_get_toplevel().
9653 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9654 * considers @widget to be an ancestor of itself.
9656 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9659 gtk_widget_get_ancestor (GtkWidget *widget,
9662 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9664 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9665 widget = widget->priv->parent;
9667 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9674 * gtk_widget_set_visual:
9675 * @widget: a #GtkWidget
9676 * @visual: visual to be used or %NULL to unset a previous one
9678 * Sets the visual that should be used for by widget and its children for
9679 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9680 * returned by gdk_widget_get_screen(), so handling the
9681 * #GtkWidget::screen-changed signal is necessary.
9683 * Setting a new @visual will not cause @widget to recreate its windows,
9684 * so you should call this function before @widget is realized.
9687 gtk_widget_set_visual (GtkWidget *widget,
9690 g_return_if_fail (GTK_IS_WIDGET (widget));
9691 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9694 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9697 g_object_set_qdata_full (G_OBJECT (widget),
9699 g_object_ref (visual),
9704 * gtk_widget_get_visual:
9705 * @widget: a #GtkWidget
9707 * Gets the visual that will be used to render @widget.
9709 * Return value: (transfer none): the visual for @widget
9712 gtk_widget_get_visual (GtkWidget *widget)
9718 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9720 if (gtk_widget_get_has_window (widget) &&
9721 widget->priv->window)
9722 return gdk_window_get_visual (widget->priv->window);
9724 screen = gtk_widget_get_screen (widget);
9726 for (w = widget; w != NULL; w = w->priv->parent)
9728 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9731 if (gdk_visual_get_screen (visual) == screen)
9734 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9735 gtk_widget_get_name (widget));
9739 return gdk_screen_get_system_visual (screen);
9743 * gtk_widget_get_settings:
9744 * @widget: a #GtkWidget
9746 * Gets the settings object holding the settings (global property
9747 * settings, RC file information, etc) used for this widget.
9749 * Note that this function can only be called when the #GtkWidget
9750 * is attached to a toplevel, since the settings object is specific
9751 * to a particular #GdkScreen.
9753 * Return value: (transfer none): the relevant #GtkSettings object
9756 gtk_widget_get_settings (GtkWidget *widget)
9758 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9760 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9764 * gtk_widget_get_events:
9765 * @widget: a #GtkWidget
9767 * Returns the event mask for the widget (a bitfield containing flags
9768 * from the #GdkEventMask enumeration). These are the events that the widget
9771 * Return value: event mask for @widget
9774 gtk_widget_get_events (GtkWidget *widget)
9776 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9778 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9782 * gtk_widget_get_device_events:
9783 * @widget: a #GtkWidget
9784 * @device: a #GdkDevice
9786 * Returns the events mask for the widget corresponding to an specific device. These
9787 * are the events that the widget will receive when @device operates on it.
9789 * Returns: device event mask for @widget
9794 gtk_widget_get_device_events (GtkWidget *widget,
9797 GHashTable *device_events;
9799 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9800 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9802 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9807 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9811 * gtk_widget_get_pointer:
9812 * @widget: a #GtkWidget
9813 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9814 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9816 * Obtains the location of the mouse pointer in widget coordinates.
9817 * Widget coordinates are a bit odd; for historical reasons, they are
9818 * defined as @widget->window coordinates for widgets that are not
9819 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9820 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9823 gtk_widget_get_pointer (GtkWidget *widget,
9827 GtkWidgetPrivate *priv;
9829 g_return_if_fail (GTK_IS_WIDGET (widget));
9831 priv = widget->priv;
9838 if (gtk_widget_get_realized (widget))
9840 gdk_window_get_pointer (priv->window, x, y, NULL);
9842 if (!gtk_widget_get_has_window (widget))
9845 *x -= priv->allocation.x;
9847 *y -= priv->allocation.y;
9853 * gtk_widget_is_ancestor:
9854 * @widget: a #GtkWidget
9855 * @ancestor: another #GtkWidget
9857 * Determines whether @widget is somewhere inside @ancestor, possibly with
9858 * intermediate containers.
9860 * Return value: %TRUE if @ancestor contains @widget as a child,
9861 * grandchild, great grandchild, etc.
9864 gtk_widget_is_ancestor (GtkWidget *widget,
9865 GtkWidget *ancestor)
9867 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9868 g_return_val_if_fail (ancestor != NULL, FALSE);
9872 if (widget->priv->parent == ancestor)
9874 widget = widget->priv->parent;
9880 static GQuark quark_composite_name = 0;
9883 * gtk_widget_set_composite_name:
9884 * @widget: a #GtkWidget.
9885 * @name: the name to set
9887 * Sets a widgets composite name. The widget must be
9888 * a composite child of its parent; see gtk_widget_push_composite_child().
9891 gtk_widget_set_composite_name (GtkWidget *widget,
9894 g_return_if_fail (GTK_IS_WIDGET (widget));
9895 g_return_if_fail (widget->priv->composite_child);
9896 g_return_if_fail (name != NULL);
9898 if (!quark_composite_name)
9899 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
9901 g_object_set_qdata_full (G_OBJECT (widget),
9902 quark_composite_name,
9908 * gtk_widget_get_composite_name:
9909 * @widget: a #GtkWidget
9911 * Obtains the composite name of a widget.
9913 * Returns: the composite name of @widget, or %NULL if @widget is not
9914 * a composite child. The string should be freed when it is no
9918 gtk_widget_get_composite_name (GtkWidget *widget)
9920 GtkWidgetPrivate *priv;
9922 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9924 priv = widget->priv;
9926 if (widget->priv->composite_child && priv->parent)
9927 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
9934 * gtk_widget_push_composite_child:
9936 * Makes all newly-created widgets as composite children until
9937 * the corresponding gtk_widget_pop_composite_child() call.
9939 * A composite child is a child that's an implementation detail of the
9940 * container it's inside and should not be visible to people using the
9941 * container. Composite children aren't treated differently by GTK (but
9942 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
9943 * builders might want to treat them in a different way.
9945 * Here is a simple example:
9947 * gtk_widget_push_composite_child ();
9948 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
9949 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
9950 * gtk_widget_pop_composite_child ();
9951 * gtk_widget_set_parent (scrolled_window->hscrollbar,
9952 * GTK_WIDGET (scrolled_window));
9953 * g_object_ref (scrolled_window->hscrollbar);
9957 gtk_widget_push_composite_child (void)
9959 composite_child_stack++;
9963 * gtk_widget_pop_composite_child:
9965 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
9968 gtk_widget_pop_composite_child (void)
9970 if (composite_child_stack)
9971 composite_child_stack--;
9975 gtk_widget_emit_direction_changed (GtkWidget *widget,
9976 GtkTextDirection old_dir)
9978 gtk_widget_update_pango_context (widget);
9980 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
9984 * gtk_widget_set_direction:
9985 * @widget: a #GtkWidget
9986 * @dir: the new direction
9988 * Sets the reading direction on a particular widget. This direction
9989 * controls the primary direction for widgets containing text,
9990 * and also the direction in which the children of a container are
9991 * packed. The ability to set the direction is present in order
9992 * so that correct localization into languages with right-to-left
9993 * reading directions can be done. Generally, applications will
9994 * let the default reading direction present, except for containers
9995 * where the containers are arranged in an order that is explicitely
9996 * visual rather than logical (such as buttons for text justification).
9998 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
9999 * set by gtk_widget_set_default_direction() will be used.
10002 gtk_widget_set_direction (GtkWidget *widget,
10003 GtkTextDirection dir)
10005 GtkTextDirection old_dir;
10007 g_return_if_fail (GTK_IS_WIDGET (widget));
10008 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10010 old_dir = gtk_widget_get_direction (widget);
10012 widget->priv->direction = dir;
10014 if (old_dir != gtk_widget_get_direction (widget))
10016 if (widget->priv->context)
10017 gtk_style_context_set_direction (widget->priv->context,
10018 gtk_widget_get_direction (widget));
10020 gtk_widget_emit_direction_changed (widget, old_dir);
10025 * gtk_widget_get_direction:
10026 * @widget: a #GtkWidget
10028 * Gets the reading direction for a particular widget. See
10029 * gtk_widget_set_direction().
10031 * Return value: the reading direction for the widget.
10034 gtk_widget_get_direction (GtkWidget *widget)
10036 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10038 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10039 return gtk_default_direction;
10041 return widget->priv->direction;
10045 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10047 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10049 g_object_ref (widget);
10051 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10052 gtk_widget_emit_direction_changed (widget, old_dir);
10054 if (GTK_IS_CONTAINER (widget))
10055 gtk_container_forall (GTK_CONTAINER (widget),
10056 gtk_widget_set_default_direction_recurse,
10059 g_object_unref (widget);
10063 * gtk_widget_set_default_direction:
10064 * @dir: the new default direction. This cannot be
10065 * %GTK_TEXT_DIR_NONE.
10067 * Sets the default reading direction for widgets where the
10068 * direction has not been explicitly set by gtk_widget_set_direction().
10071 gtk_widget_set_default_direction (GtkTextDirection dir)
10073 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10075 if (dir != gtk_default_direction)
10077 GList *toplevels, *tmp_list;
10078 GtkTextDirection old_dir = gtk_default_direction;
10080 gtk_default_direction = dir;
10082 tmp_list = toplevels = gtk_window_list_toplevels ();
10083 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10087 gtk_widget_set_default_direction_recurse (tmp_list->data,
10088 GUINT_TO_POINTER (old_dir));
10089 g_object_unref (tmp_list->data);
10090 tmp_list = tmp_list->next;
10093 g_list_free (toplevels);
10098 * gtk_widget_get_default_direction:
10100 * Obtains the current default reading direction. See
10101 * gtk_widget_set_default_direction().
10103 * Return value: the current default direction.
10106 gtk_widget_get_default_direction (void)
10108 return gtk_default_direction;
10112 gtk_widget_dispose (GObject *object)
10114 GtkWidget *widget = GTK_WIDGET (object);
10115 GtkWidgetPrivate *priv = widget->priv;
10118 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10119 else if (gtk_widget_get_visible (widget))
10120 gtk_widget_hide (widget);
10122 priv->visible = FALSE;
10123 if (gtk_widget_get_realized (widget))
10124 gtk_widget_unrealize (widget);
10126 if (!priv->in_destruction)
10128 priv->in_destruction = TRUE;
10129 g_signal_emit (object, widget_signals[DESTROY], 0);
10130 priv->in_destruction = FALSE;
10133 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10137 gtk_widget_real_destroy (GtkWidget *object)
10139 /* gtk_object_destroy() will already hold a refcount on object */
10140 GtkWidget *widget = GTK_WIDGET (object);
10141 GtkWidgetPrivate *priv = widget->priv;
10143 /* wipe accelerator closures (keep order) */
10144 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10145 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10147 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10148 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10150 gtk_grab_remove (widget);
10152 g_object_unref (priv->style);
10153 priv->style = gtk_widget_get_default_style ();
10154 g_object_ref (priv->style);
10158 gtk_widget_finalize (GObject *object)
10160 GtkWidget *widget = GTK_WIDGET (object);
10161 GtkWidgetPrivate *priv = widget->priv;
10162 GtkWidgetAuxInfo *aux_info;
10163 GtkAccessible *accessible;
10165 gtk_grab_remove (widget);
10167 g_object_unref (priv->style);
10168 priv->style = NULL;
10170 g_free (priv->name);
10172 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
10174 gtk_widget_aux_info_destroy (aux_info);
10176 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10178 g_object_unref (accessible);
10181 gtk_widget_path_free (priv->path);
10184 g_object_unref (priv->context);
10186 if (g_object_is_floating (object))
10187 g_warning ("A floating object was finalized. This means that someone\n"
10188 "called g_object_unref() on an object that had only a floating\n"
10189 "reference; the initial floating reference is not owned by anyone\n"
10190 "and must be removed with g_object_ref_sink().");
10192 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10195 /*****************************************
10196 * gtk_widget_real_map:
10201 *****************************************/
10204 gtk_widget_real_map (GtkWidget *widget)
10206 GtkWidgetPrivate *priv = widget->priv;
10208 g_assert (gtk_widget_get_realized (widget));
10210 if (!gtk_widget_get_mapped (widget))
10212 gtk_widget_set_mapped (widget, TRUE);
10214 if (gtk_widget_get_has_window (widget))
10215 gdk_window_show (priv->window);
10219 /*****************************************
10220 * gtk_widget_real_unmap:
10225 *****************************************/
10228 gtk_widget_real_unmap (GtkWidget *widget)
10230 GtkWidgetPrivate *priv = widget->priv;
10232 if (gtk_widget_get_mapped (widget))
10234 gtk_widget_set_mapped (widget, FALSE);
10236 if (gtk_widget_get_has_window (widget))
10237 gdk_window_hide (priv->window);
10241 /*****************************************
10242 * gtk_widget_real_realize:
10247 *****************************************/
10250 gtk_widget_real_realize (GtkWidget *widget)
10252 GtkWidgetPrivate *priv = widget->priv;
10254 g_assert (!gtk_widget_get_has_window (widget));
10256 gtk_widget_set_realized (widget, TRUE);
10259 priv->window = gtk_widget_get_parent_window (widget);
10260 g_object_ref (priv->window);
10262 priv->style = gtk_style_attach (priv->style, priv->window);
10265 /*****************************************
10266 * gtk_widget_real_unrealize:
10271 *****************************************/
10274 gtk_widget_real_unrealize (GtkWidget *widget)
10276 GtkWidgetPrivate *priv = widget->priv;
10278 if (gtk_widget_get_mapped (widget))
10279 gtk_widget_real_unmap (widget);
10281 gtk_widget_set_mapped (widget, FALSE);
10283 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10286 /* We must do unrealize child widget BEFORE container widget.
10287 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10288 * So, unrealizing container widget bofore its children causes the problem
10289 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10292 if (GTK_IS_CONTAINER (widget))
10293 gtk_container_forall (GTK_CONTAINER (widget),
10294 (GtkCallback) gtk_widget_unrealize,
10297 gtk_style_detach (priv->style);
10298 if (gtk_widget_get_has_window (widget))
10300 gdk_window_set_user_data (priv->window, NULL);
10301 gdk_window_destroy (priv->window);
10302 priv->window = NULL;
10306 g_object_unref (priv->window);
10307 priv->window = NULL;
10310 gtk_selection_remove_all (widget);
10312 gtk_widget_set_realized (widget, FALSE);
10316 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10317 GtkOrientation orientation,
10318 gint *minimum_size,
10319 gint *natural_size)
10321 const GtkWidgetAuxInfo *aux_info;
10323 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10325 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10326 aux_info->width > 0)
10328 *minimum_size = MAX (*minimum_size, aux_info->width);
10330 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10331 aux_info->height > 0)
10333 *minimum_size = MAX (*minimum_size, aux_info->height);
10336 /* Fix it if set_size_request made natural size smaller than min size.
10337 * This would also silently fix broken widgets, but we warn about them
10338 * in gtksizerequest.c when calling their size request vfuncs.
10340 *natural_size = MAX (*natural_size, *minimum_size);
10342 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10344 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10345 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10349 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10350 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10355 * _gtk_widget_peek_request_cache:
10357 * Returns the address of the widget's request cache (strictly for
10358 * internal use in gtksizerequest.c)
10360 * Return value: the address of @widget's size request cache.
10363 _gtk_widget_peek_request_cache (GtkWidget *widget)
10365 /* Don't bother slowing things down with the return_if_fail guards here */
10366 return &widget->priv->requests;
10370 * _gtk_widget_set_device_window:
10371 * @widget: a #GtkWidget.
10372 * @device: a #GdkDevice.
10373 * @window: the new device window.
10375 * Sets pointer window for @widget and @device. Does not ref @window.
10376 * Actually stores it on the #GdkScreen, but you don't need to know that.
10379 _gtk_widget_set_device_window (GtkWidget *widget,
10383 GtkWidgetPrivate *priv;
10385 GHashTable *device_window;
10387 g_return_if_fail (GTK_IS_WIDGET (widget));
10388 g_return_if_fail (GDK_IS_DEVICE (device));
10389 g_return_if_fail (!window || GDK_IS_WINDOW (window));
10391 priv = widget->priv;
10393 if (!gtk_widget_get_realized (widget))
10396 screen = gdk_window_get_screen (priv->window);
10397 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10399 if (G_UNLIKELY (!device_window))
10401 device_window = g_hash_table_new (NULL, NULL);
10402 g_object_set_qdata_full (G_OBJECT (screen),
10403 quark_pointer_window,
10405 (GDestroyNotify) g_hash_table_destroy);
10409 g_hash_table_insert (device_window, device, window);
10411 g_hash_table_remove (device_window, device);
10415 * _gtk_widget_get_device_window:
10416 * @widget: a #GtkWidget.
10417 * @device: a #GdkDevice.
10419 * Return value: the device window set on the #GdkScreen @widget is attached
10423 _gtk_widget_get_device_window (GtkWidget *widget,
10426 GtkWidgetPrivate *priv;
10428 GHashTable *device_window;
10432 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10433 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10435 priv = widget->priv;
10437 if (!gtk_widget_get_realized (widget))
10440 screen = gdk_window_get_screen (priv->window);
10441 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10443 if (G_UNLIKELY (!device_window))
10446 window = g_hash_table_lookup (device_window, device);
10451 gdk_window_get_user_data (window, (gpointer *) &w);
10460 * _gtk_widget_list_devices:
10461 * @widget: a #GtkWidget.
10463 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
10464 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
10468 _gtk_widget_list_devices (GtkWidget *widget)
10470 GtkWidgetPrivate *priv;
10472 GHashTableIter iter;
10473 GHashTable *device_window;
10474 GList *devices = NULL;
10475 gpointer key, value;
10477 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10479 priv = widget->priv;
10481 if (!gtk_widget_get_realized (widget))
10484 screen = gdk_window_get_screen (priv->window);
10485 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10487 if (G_UNLIKELY (!device_window))
10490 g_hash_table_iter_init (&iter, device_window);
10492 while (g_hash_table_iter_next (&iter, &key, &value))
10494 GdkDevice *device = key;
10495 GdkWindow *window = value;
10500 gdk_window_get_user_data (window, (gpointer *) &w);
10503 devices = g_list_prepend (devices, device);
10511 synth_crossing (GtkWidget *widget,
10515 GdkCrossingMode mode,
10516 GdkNotifyType detail)
10520 event = gdk_event_new (type);
10522 event->crossing.window = g_object_ref (window);
10523 event->crossing.send_event = TRUE;
10524 event->crossing.subwindow = g_object_ref (window);
10525 event->crossing.time = GDK_CURRENT_TIME;
10526 event->crossing.x = event->crossing.y = 0;
10527 event->crossing.x_root = event->crossing.y_root = 0;
10528 event->crossing.mode = mode;
10529 event->crossing.detail = detail;
10530 event->crossing.focus = FALSE;
10531 event->crossing.state = 0;
10532 gdk_event_set_device (event, device);
10535 widget = gtk_get_event_widget (event);
10538 gtk_widget_event_internal (widget, event);
10540 gdk_event_free (event);
10544 * _gtk_widget_synthesize_crossing:
10545 * @from: the #GtkWidget the virtual pointer is leaving.
10546 * @to: the #GtkWidget the virtual pointer is moving to.
10547 * @mode: the #GdkCrossingMode to place on the synthesized events.
10549 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10551 * The real pointer window is the window that most recently received an enter notify
10552 * event. Windows that don't select for crossing events can't become the real
10553 * poiner window. The real pointer widget that owns the real pointer window. The
10554 * effective pointer window is the same as the real pointer window unless the real
10555 * pointer widget is either insensitive or there is a grab on a widget that is not
10556 * an ancestor of the real pointer widget (in which case the effective pointer
10557 * window should be the root window).
10559 * When the effective pointer window is the same as the real poiner window, we
10560 * receive crossing events from the windowing system. When the effective pointer
10561 * window changes to become different from the real pointer window we synthesize
10562 * crossing events, attempting to follow X protocol rules:
10564 * When the root window becomes the effective pointer window:
10565 * - leave notify on real pointer window, detail Ancestor
10566 * - leave notify on all of its ancestors, detail Virtual
10567 * - enter notify on root window, detail Inferior
10569 * When the root window ceases to be the effective pointer window:
10570 * - leave notify on root window, detail Inferior
10571 * - enter notify on all ancestors of real pointer window, detail Virtual
10572 * - enter notify on real pointer window, detail Ancestor
10575 _gtk_widget_synthesize_crossing (GtkWidget *from,
10578 GdkCrossingMode mode)
10580 GdkWindow *from_window = NULL, *to_window = NULL;
10582 g_return_if_fail (from != NULL || to != NULL);
10586 from_window = _gtk_widget_get_device_window (from, device);
10589 from_window = from->priv->window;
10594 to_window = _gtk_widget_get_device_window (to, device);
10597 to_window = to->priv->window;
10600 if (from_window == NULL && to_window == NULL)
10602 else if (from_window != NULL && to_window == NULL)
10604 GList *from_ancestors = NULL, *list;
10605 GdkWindow *from_ancestor = from_window;
10607 while (from_ancestor != NULL)
10609 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10610 if (from_ancestor == NULL)
10612 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10615 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10616 device, mode, GDK_NOTIFY_ANCESTOR);
10617 for (list = g_list_last (from_ancestors); list; list = list->prev)
10619 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10620 device, mode, GDK_NOTIFY_VIRTUAL);
10623 /* XXX: enter/inferior on root window? */
10625 g_list_free (from_ancestors);
10627 else if (from_window == NULL && to_window != NULL)
10629 GList *to_ancestors = NULL, *list;
10630 GdkWindow *to_ancestor = to_window;
10632 while (to_ancestor != NULL)
10634 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10635 if (to_ancestor == NULL)
10637 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10640 /* XXX: leave/inferior on root window? */
10642 for (list = to_ancestors; list; list = list->next)
10644 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10645 device, mode, GDK_NOTIFY_VIRTUAL);
10647 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10648 device, mode, GDK_NOTIFY_ANCESTOR);
10650 g_list_free (to_ancestors);
10652 else if (from_window == to_window)
10656 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10657 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10659 while (from_ancestor != NULL || to_ancestor != NULL)
10661 if (from_ancestor != NULL)
10663 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10664 if (from_ancestor == to_window)
10667 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10669 if (to_ancestor != NULL)
10671 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10672 if (to_ancestor == from_window)
10675 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10678 if (to_ancestor == from_window)
10680 if (mode != GDK_CROSSING_GTK_UNGRAB)
10681 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10682 device, mode, GDK_NOTIFY_INFERIOR);
10683 for (list = to_ancestors; list; list = list->next)
10684 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10685 device, mode, GDK_NOTIFY_VIRTUAL);
10686 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10687 device, mode, GDK_NOTIFY_ANCESTOR);
10689 else if (from_ancestor == to_window)
10691 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10692 device, mode, GDK_NOTIFY_ANCESTOR);
10693 for (list = g_list_last (from_ancestors); list; list = list->prev)
10695 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10696 device, mode, GDK_NOTIFY_VIRTUAL);
10698 if (mode != GDK_CROSSING_GTK_GRAB)
10699 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10700 device, mode, GDK_NOTIFY_INFERIOR);
10704 while (from_ancestors != NULL && to_ancestors != NULL
10705 && from_ancestors->data == to_ancestors->data)
10707 from_ancestors = g_list_delete_link (from_ancestors,
10709 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10712 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10713 device, mode, GDK_NOTIFY_NONLINEAR);
10715 for (list = g_list_last (from_ancestors); list; list = list->prev)
10717 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10718 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10720 for (list = to_ancestors; list; list = list->next)
10722 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10723 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10725 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10726 device, mode, GDK_NOTIFY_NONLINEAR);
10728 g_list_free (from_ancestors);
10729 g_list_free (to_ancestors);
10734 gtk_widget_propagate_state (GtkWidget *widget,
10735 GtkStateData *data)
10737 GtkWidgetPrivate *priv = widget->priv;
10738 GtkStateFlags new_flags, old_flags = priv->state_flags;
10739 GtkStateType old_state;
10741 old_state = gtk_widget_get_state (widget);
10743 if (!priv->parent_sensitive)
10744 old_flags |= GTK_STATE_FLAG_INSENSITIVE;
10746 priv->parent_sensitive = data->parent_sensitive;
10748 switch (data->operation)
10750 case STATE_CHANGE_REPLACE:
10751 priv->state_flags = data->flags;
10753 case STATE_CHANGE_SET:
10754 priv->state_flags |= data->flags;
10756 case STATE_CHANGE_UNSET:
10757 priv->state_flags &= ~(data->flags);
10761 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10765 window = gtk_widget_get_toplevel (widget);
10767 if (window && gtk_widget_is_toplevel (window))
10768 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10771 new_flags = gtk_widget_get_state_flags (widget);
10773 if (old_flags != new_flags)
10775 g_object_ref (widget);
10777 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10778 gtk_grab_remove (widget);
10780 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10781 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
10783 if (!priv->shadowed)
10785 GList *event_windows = NULL;
10786 GList *devices, *d;
10788 devices = _gtk_widget_list_devices (widget);
10790 for (d = devices; d; d = d->next)
10796 window = _gtk_widget_get_device_window (widget, device);
10798 /* Do not propagate more than once to the
10799 * same window if non-multidevice aware.
10801 if (!gdk_window_get_support_multidevice (window) &&
10802 g_list_find (event_windows, window))
10805 if (!gtk_widget_is_sensitive (widget))
10806 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10807 GDK_CROSSING_STATE_CHANGED);
10808 else if (old_flags & GTK_STATE_FLAG_INSENSITIVE)
10809 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10810 GDK_CROSSING_STATE_CHANGED);
10812 event_windows = g_list_prepend (event_windows, window);
10815 g_list_free (event_windows);
10816 g_list_free (devices);
10819 if (GTK_IS_CONTAINER (widget))
10821 data->parent_sensitive = gtk_widget_is_sensitive (widget);
10823 /* Do not propagate insensitive state further */
10824 data->flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
10826 if (data->use_forall)
10827 gtk_container_forall (GTK_CONTAINER (widget),
10828 (GtkCallback) gtk_widget_propagate_state,
10831 gtk_container_foreach (GTK_CONTAINER (widget),
10832 (GtkCallback) gtk_widget_propagate_state,
10836 /* Trigger state change transitions for the widget */
10837 if (priv->context &&
10838 gtk_widget_get_mapped (widget))
10840 gint diff, flag = 1;
10843 diff = old_flags ^ new_flags;
10844 window = gtk_widget_get_window (widget);
10848 if ((diff & flag) != 0)
10852 target = ((new_flags & flag) != 0);
10853 _gtk_widget_notify_state_change (widget, flag, target);
10862 g_object_unref (widget);
10866 static const GtkWidgetAuxInfo default_aux_info = {
10874 * _gtk_widget_get_aux_info:
10875 * @widget: a #GtkWidget
10876 * @create: if %TRUE, create the structure if it doesn't exist
10878 * Get the #GtkWidgetAuxInfo structure for the widget.
10880 * Return value: the #GtkAuxInfo structure for the widget, or
10881 * %NULL if @create is %FALSE and one doesn't already exist.
10884 _gtk_widget_get_aux_info (GtkWidget *widget,
10887 GtkWidgetAuxInfo *aux_info;
10889 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
10890 if (!aux_info && create)
10892 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
10894 *aux_info = default_aux_info;
10896 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
10902 static const GtkWidgetAuxInfo*
10903 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
10905 GtkWidgetAuxInfo *aux_info;
10907 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
10908 if (aux_info == NULL)
10910 return &default_aux_info;
10918 /*****************************************
10919 * gtk_widget_aux_info_destroy:
10924 *****************************************/
10927 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
10929 g_slice_free (GtkWidgetAuxInfo, aux_info);
10933 * gtk_widget_shape_combine_region:
10934 * @widget: a #GtkWidget
10935 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10937 * Sets a shape for this widget's GDK window. This allows for
10938 * transparent windows etc., see gdk_window_shape_combine_region()
10939 * for more information.
10944 gtk_widget_shape_combine_region (GtkWidget *widget,
10945 cairo_region_t *region)
10947 GtkWidgetPrivate *priv;
10949 g_return_if_fail (GTK_IS_WIDGET (widget));
10950 /* set_shape doesn't work on widgets without gdk window */
10951 g_return_if_fail (gtk_widget_get_has_window (widget));
10953 priv = widget->priv;
10955 if (region == NULL)
10957 priv->has_shape_mask = FALSE;
10960 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
10962 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
10966 priv->has_shape_mask = TRUE;
10968 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
10969 cairo_region_copy (region),
10970 (GDestroyNotify) cairo_region_destroy);
10972 /* set shape if widget has a gdk window already.
10973 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10976 gdk_window_shape_combine_region (priv->window, region, 0, 0);
10981 * gtk_widget_input_shape_combine_region:
10982 * @widget: a #GtkWidget
10983 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10985 * Sets an input shape for this widget's GDK window. This allows for
10986 * windows which react to mouse click in a nonrectangular region, see
10987 * gdk_window_input_shape_combine_region() for more information.
10992 gtk_widget_input_shape_combine_region (GtkWidget *widget,
10993 cairo_region_t *region)
10995 GtkWidgetPrivate *priv;
10997 g_return_if_fail (GTK_IS_WIDGET (widget));
10998 /* set_shape doesn't work on widgets without gdk window */
10999 g_return_if_fail (gtk_widget_get_has_window (widget));
11001 priv = widget->priv;
11003 if (region == NULL)
11006 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11008 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11012 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11013 cairo_region_copy (region),
11014 (GDestroyNotify) cairo_region_destroy);
11016 /* set shape if widget has a gdk window already.
11017 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11020 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11025 /* style properties
11029 * gtk_widget_class_install_style_property_parser:
11030 * @klass: a #GtkWidgetClass
11031 * @pspec: the #GParamSpec for the style property
11032 * @parser: the parser for the style property
11034 * Installs a style property on a widget class.
11037 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11039 GtkRcPropertyParser parser)
11041 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11042 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11043 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11044 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11046 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11048 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11049 G_OBJECT_CLASS_NAME (klass),
11054 g_param_spec_ref_sink (pspec);
11055 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11056 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11060 * gtk_widget_class_install_style_property:
11061 * @klass: a #GtkWidgetClass
11062 * @pspec: the #GParamSpec for the property
11064 * Installs a style property on a widget class. The parser for the
11065 * style property is determined by the value type of @pspec.
11068 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11071 GtkRcPropertyParser parser;
11073 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11074 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11076 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11078 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11082 * gtk_widget_class_find_style_property:
11083 * @klass: a #GtkWidgetClass
11084 * @property_name: the name of the style property to find
11085 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
11086 * style property with that name.
11088 * Finds a style property of a widget class by name.
11093 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11094 const gchar *property_name)
11096 g_return_val_if_fail (property_name != NULL, NULL);
11098 return g_param_spec_pool_lookup (style_property_spec_pool,
11100 G_OBJECT_CLASS_TYPE (klass),
11105 * gtk_widget_class_list_style_properties:
11106 * @klass: a #GtkWidgetClass
11107 * @n_properties: location to return the number of style properties found
11108 * @returns: an newly allocated array of #GParamSpec*. The array must
11109 * be freed with g_free().
11111 * Returns all style properties of a widget class.
11116 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11117 guint *n_properties)
11119 GParamSpec **pspecs;
11122 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11123 G_OBJECT_CLASS_TYPE (klass),
11132 * gtk_widget_style_get_property:
11133 * @widget: a #GtkWidget
11134 * @property_name: the name of a style property
11135 * @value: location to return the property value
11137 * Gets the value of a style property of @widget.
11140 gtk_widget_style_get_property (GtkWidget *widget,
11141 const gchar *property_name,
11146 g_return_if_fail (GTK_IS_WIDGET (widget));
11147 g_return_if_fail (property_name != NULL);
11148 g_return_if_fail (G_IS_VALUE (value));
11150 g_object_ref (widget);
11151 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11153 G_OBJECT_TYPE (widget),
11156 g_warning ("%s: widget class `%s' has no property named `%s'",
11158 G_OBJECT_TYPE_NAME (widget),
11162 GtkStyleContext *context;
11163 const GValue *peek_value;
11164 GtkStateFlags state;
11166 context = gtk_widget_get_style_context (widget);
11167 state = gtk_widget_get_state_flags (widget);
11169 peek_value = _gtk_style_context_peek_style_property (context,
11170 G_OBJECT_TYPE (widget),
11173 /* auto-conversion of the caller's value type
11175 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11176 g_value_copy (peek_value, value);
11177 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11178 g_value_transform (peek_value, value);
11180 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11182 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11183 G_VALUE_TYPE_NAME (value));
11185 g_object_unref (widget);
11189 * gtk_widget_style_get_valist:
11190 * @widget: a #GtkWidget
11191 * @first_property_name: the name of the first property to get
11192 * @var_args: a <type>va_list</type> of pairs of property names and
11193 * locations to return the property values, starting with the location
11194 * for @first_property_name.
11196 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11200 gtk_widget_style_get_valist (GtkWidget *widget,
11201 const gchar *first_property_name,
11204 GtkStyleContext *context;
11205 GtkStateFlags state;
11208 g_return_if_fail (GTK_IS_WIDGET (widget));
11210 g_object_ref (widget);
11211 context = gtk_widget_get_style_context (widget);
11212 state = gtk_widget_get_state_flags (widget);
11214 name = first_property_name;
11217 const GValue *peek_value;
11221 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11223 G_OBJECT_TYPE (widget),
11227 g_warning ("%s: widget class `%s' has no property named `%s'",
11229 G_OBJECT_TYPE_NAME (widget),
11233 /* style pspecs are always readable so we can spare that check here */
11235 peek_value = _gtk_style_context_peek_style_property (context,
11236 G_OBJECT_TYPE (widget),
11239 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11242 g_warning ("%s: %s", G_STRLOC, error);
11247 name = va_arg (var_args, gchar*);
11250 g_object_unref (widget);
11254 * gtk_widget_style_get:
11255 * @widget: a #GtkWidget
11256 * @first_property_name: the name of the first property to get
11257 * @Varargs: pairs of property names and locations to
11258 * return the property values, starting with the location for
11259 * @first_property_name, terminated by %NULL.
11261 * Gets the values of a multiple style properties of @widget.
11264 gtk_widget_style_get (GtkWidget *widget,
11265 const gchar *first_property_name,
11270 g_return_if_fail (GTK_IS_WIDGET (widget));
11272 va_start (var_args, first_property_name);
11273 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11279 * @widget: a #GtkWidget
11280 * @path_length: (out) (allow-none): location to store length of the path,
11282 * @path: (out) (allow-none): location to store allocated path string,
11284 * @path_reversed: (out) (allow-none): location to store allocated reverse
11285 * path string, or %NULL
11287 * Obtains the full path to @widget. The path is simply the name of a
11288 * widget and all its parents in the container hierarchy, separated by
11289 * periods. The name of a widget comes from
11290 * gtk_widget_get_name(). Paths are used to apply styles to a widget
11291 * in gtkrc configuration files. Widget names are the type of the
11292 * widget by default (e.g. "GtkButton") or can be set to an
11293 * application-specific value with gtk_widget_set_name(). By setting
11294 * the name of a widget, you allow users or theme authors to apply
11295 * styles to that specific widget in their gtkrc
11296 * file. @path_reversed_p fills in the path in reverse order,
11297 * i.e. starting with @widget's name instead of starting with the name
11298 * of @widget's outermost ancestor.
11300 * Deprecated:3.0: Use gtk_widget_get_path() instead
11303 gtk_widget_path (GtkWidget *widget,
11304 guint *path_length,
11306 gchar **path_reversed)
11308 static gchar *rev_path = NULL;
11309 static guint tmp_path_len = 0;
11312 g_return_if_fail (GTK_IS_WIDGET (widget));
11317 const gchar *string;
11322 string = gtk_widget_get_name (widget);
11323 l = strlen (string);
11324 while (tmp_path_len <= len + l + 1)
11326 tmp_path_len += INIT_PATH_SIZE;
11327 rev_path = g_realloc (rev_path, tmp_path_len);
11329 s = string + l - 1;
11330 d = rev_path + len;
11331 while (s >= string)
11335 widget = widget->priv->parent;
11338 rev_path[len++] = '.';
11340 rev_path[len++] = 0;
11345 *path_length = len - 1;
11347 *path_reversed = g_strdup (rev_path);
11350 *path = g_strdup (rev_path);
11351 g_strreverse (*path);
11356 * gtk_widget_class_path:
11357 * @widget: a #GtkWidget
11358 * @path_length: (out) (allow-none): location to store the length of the
11359 * class path, or %NULL
11360 * @path: (out) (allow-none): location to store the class path as an
11361 * allocated string, or %NULL
11362 * @path_reversed: (out) (allow-none): location to store the reverse
11363 * class path as an allocated string, or %NULL
11365 * Same as gtk_widget_path(), but always uses the name of a widget's type,
11366 * never uses a custom name set with gtk_widget_set_name().
11368 * Deprecated:3.0: Use gtk_widget_get_path() instead
11371 gtk_widget_class_path (GtkWidget *widget,
11372 guint *path_length,
11374 gchar **path_reversed)
11376 static gchar *rev_path = NULL;
11377 static guint tmp_path_len = 0;
11380 g_return_if_fail (GTK_IS_WIDGET (widget));
11385 const gchar *string;
11390 string = g_type_name (G_OBJECT_TYPE (widget));
11391 l = strlen (string);
11392 while (tmp_path_len <= len + l + 1)
11394 tmp_path_len += INIT_PATH_SIZE;
11395 rev_path = g_realloc (rev_path, tmp_path_len);
11397 s = string + l - 1;
11398 d = rev_path + len;
11399 while (s >= string)
11403 widget = widget->priv->parent;
11406 rev_path[len++] = '.';
11408 rev_path[len++] = 0;
11413 *path_length = len - 1;
11415 *path_reversed = g_strdup (rev_path);
11418 *path = g_strdup (rev_path);
11419 g_strreverse (*path);
11424 * gtk_requisition_new:
11426 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11428 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11429 * be freed with gtk_requisition_free().
11434 gtk_requisition_new (void)
11436 return g_slice_new0 (GtkRequisition);
11440 * gtk_requisition_copy:
11441 * @requisition: a #GtkRequisition
11443 * Copies a #GtkRequisition.
11445 * Returns: a copy of @requisition
11448 gtk_requisition_copy (const GtkRequisition *requisition)
11450 return g_slice_dup (GtkRequisition, requisition);
11454 * gtk_requisition_free:
11455 * @requisition: a #GtkRequisition
11457 * Frees a #GtkRequisition.
11460 gtk_requisition_free (GtkRequisition *requisition)
11462 g_slice_free (GtkRequisition, requisition);
11465 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11466 gtk_requisition_copy,
11467 gtk_requisition_free)
11470 * gtk_widget_get_accessible:
11471 * @widget: a #GtkWidget
11473 * Returns the accessible object that describes the widget to an
11474 * assistive technology.
11476 * If no accessibility library is loaded (i.e. no ATK implementation library is
11477 * loaded via <envar>GTK_MODULES</envar> or via another application library,
11478 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
11479 * if no class-specific #AtkObject implementation is available for the widget
11480 * instance in question, it will inherit an #AtkObject implementation from the
11481 * first ancestor class for which such an implementation is defined.
11483 * The documentation of the
11484 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
11485 * library contains more information about accessible objects and their uses.
11487 * Returns: (transfer none): the #AtkObject associated with @widget
11490 gtk_widget_get_accessible (GtkWidget *widget)
11492 GtkWidgetClass *klass;
11494 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11496 klass = GTK_WIDGET_GET_CLASS (widget);
11498 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11500 return klass->get_accessible (widget);
11504 gtk_widget_real_get_accessible (GtkWidget *widget)
11506 AtkObject* accessible;
11508 accessible = g_object_get_qdata (G_OBJECT (widget),
11509 quark_accessible_object);
11512 AtkObjectFactory *factory;
11513 AtkRegistry *default_registry;
11515 default_registry = atk_get_default_registry ();
11516 factory = atk_registry_get_factory (default_registry,
11517 G_TYPE_FROM_INSTANCE (widget));
11519 atk_object_factory_create_accessible (factory,
11520 G_OBJECT (widget));
11521 g_object_set_qdata (G_OBJECT (widget),
11522 quark_accessible_object,
11529 * Initialize a AtkImplementorIface instance's virtual pointers as
11530 * appropriate to this implementor's class (GtkWidget).
11533 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11535 iface->ref_accessible = gtk_widget_ref_accessible;
11539 gtk_widget_ref_accessible (AtkImplementor *implementor)
11541 AtkObject *accessible;
11543 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11545 g_object_ref (accessible);
11550 * Expand flag management
11554 gtk_widget_update_computed_expand (GtkWidget *widget)
11556 GtkWidgetPrivate *priv;
11558 priv = widget->priv;
11560 if (priv->need_compute_expand)
11564 if (priv->hexpand_set)
11569 if (priv->vexpand_set)
11574 /* we don't need to use compute_expand if both expands are
11575 * forced by the app
11577 if (!(priv->hexpand_set && priv->vexpand_set))
11579 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11583 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11584 priv->hexpand_set ? &ignored : &h,
11585 priv->vexpand_set ? &ignored : &v);
11589 priv->need_compute_expand = FALSE;
11590 priv->computed_hexpand = h != FALSE;
11591 priv->computed_vexpand = v != FALSE;
11596 * gtk_widget_queue_compute_expand:
11597 * @widget: a #GtkWidget
11599 * Mark @widget as needing to recompute its expand flags. Call
11600 * this function when setting legacy expand child properties
11601 * on the child of a container.
11603 * See gtk_widget_compute_expand().
11606 gtk_widget_queue_compute_expand (GtkWidget *widget)
11609 gboolean changed_anything;
11611 if (widget->priv->need_compute_expand)
11614 changed_anything = FALSE;
11616 while (parent != NULL)
11618 if (!parent->priv->need_compute_expand)
11620 parent->priv->need_compute_expand = TRUE;
11621 changed_anything = TRUE;
11624 /* Note: if we had an invariant that "if a child needs to
11625 * compute expand, its parents also do" then we could stop going
11626 * up when we got to a parent that already needed to
11627 * compute. However, in general we compute expand lazily (as
11628 * soon as we see something in a subtree that is expand, we know
11629 * we're expanding) and so this invariant does not hold and we
11630 * have to always walk all the way up in case some ancestor
11631 * is not currently need_compute_expand.
11634 parent = parent->priv->parent;
11637 /* recomputing expand always requires
11638 * a relayout as well
11640 if (changed_anything)
11641 gtk_widget_queue_resize (widget);
11645 * gtk_widget_compute_expand:
11646 * @widget: the widget
11647 * @orientation: expand direction
11649 * Computes whether a container should give this widget extra space
11650 * when possible. Containers should check this, rather than
11651 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11653 * This function already checks whether the widget is visible, so
11654 * visibility does not need to be checked separately. Non-visible
11655 * widgets are not expanded.
11657 * The computed expand value uses either the expand setting explicitly
11658 * set on the widget itself, or, if none has been explicitly set,
11659 * the widget may expand if some of its children do.
11661 * Return value: whether widget tree rooted here should be expanded
11664 gtk_widget_compute_expand (GtkWidget *widget,
11665 GtkOrientation orientation)
11667 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11669 /* We never make a widget expand if not even showing. */
11670 if (!gtk_widget_get_visible (widget))
11673 gtk_widget_update_computed_expand (widget);
11675 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11677 return widget->priv->computed_hexpand;
11681 return widget->priv->computed_vexpand;
11686 gtk_widget_set_expand (GtkWidget *widget,
11687 GtkOrientation orientation,
11690 const char *expand_prop;
11691 const char *expand_set_prop;
11693 GtkWidgetPrivate *priv;
11695 g_return_if_fail (GTK_IS_WIDGET (widget));
11697 priv = widget->priv;
11699 expand = expand != FALSE;
11701 was_both = priv->hexpand && priv->vexpand;
11703 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11705 if (priv->hexpand_set &&
11706 priv->hexpand == expand)
11709 priv->hexpand_set = TRUE;
11710 priv->hexpand = expand;
11712 expand_prop = "hexpand";
11713 expand_set_prop = "hexpand-set";
11717 if (priv->vexpand_set &&
11718 priv->vexpand == expand)
11721 priv->vexpand_set = TRUE;
11722 priv->vexpand = expand;
11724 expand_prop = "vexpand";
11725 expand_set_prop = "vexpand-set";
11728 gtk_widget_queue_compute_expand (widget);
11730 g_object_freeze_notify (G_OBJECT (widget));
11731 g_object_notify (G_OBJECT (widget), expand_prop);
11732 g_object_notify (G_OBJECT (widget), expand_set_prop);
11733 if (was_both != (priv->hexpand && priv->vexpand))
11734 g_object_notify (G_OBJECT (widget), "expand");
11735 g_object_thaw_notify (G_OBJECT (widget));
11739 gtk_widget_set_expand_set (GtkWidget *widget,
11740 GtkOrientation orientation,
11743 GtkWidgetPrivate *priv;
11746 priv = widget->priv;
11748 set = set != FALSE;
11750 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11752 if (set == priv->hexpand_set)
11755 priv->hexpand_set = set;
11756 prop = "hexpand-set";
11760 if (set == priv->vexpand_set)
11763 priv->vexpand_set = set;
11764 prop = "vexpand-set";
11767 gtk_widget_queue_compute_expand (widget);
11769 g_object_notify (G_OBJECT (widget), prop);
11773 * gtk_widget_get_hexpand:
11774 * @widget: the widget
11776 * Gets whether the widget would like any available extra horizontal
11777 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11778 * generally receive the extra space. For example, a list or
11779 * scrollable area or document in your window would often be set to
11782 * Containers should use gtk_widget_compute_expand() rather than
11783 * this function, to see whether a widget, or any of its children,
11784 * has the expand flag set. If any child of a widget wants to
11785 * expand, the parent may ask to expand also.
11787 * This function only looks at the widget's own hexpand flag, rather
11788 * than computing whether the entire widget tree rooted at this widget
11791 * Return value: whether hexpand flag is set
11794 gtk_widget_get_hexpand (GtkWidget *widget)
11796 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11798 return widget->priv->hexpand;
11802 * gtk_widget_set_hexpand:
11803 * @widget: the widget
11804 * @expand: whether to expand
11806 * Sets whether the widget would like any available extra horizontal
11807 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11808 * generally receive the extra space. For example, a list or
11809 * scrollable area or document in your window would often be set to
11812 * Call this function to set the expand flag if you would like your
11813 * widget to become larger horizontally when the window has extra
11816 * By default, widgets automatically expand if any of their children
11817 * want to expand. (To see if a widget will automatically expand given
11818 * its current children and state, call gtk_widget_compute_expand(). A
11819 * container can decide how the expandability of children affects the
11820 * expansion of the container by overriding the compute_expand virtual
11821 * method on #GtkWidget.).
11823 * Setting hexpand explicitly with this function will override the
11824 * automatic expand behavior.
11826 * This function forces the widget to expand or not to expand,
11827 * regardless of children. The override occurs because
11828 * gtk_widget_set_hexpand() sets the hexpand-set property (see
11829 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
11830 * value to be used, rather than looking at children and widget state.
11833 gtk_widget_set_hexpand (GtkWidget *widget,
11836 g_return_if_fail (GTK_IS_WIDGET (widget));
11838 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
11842 * gtk_widget_get_hexpand_set:
11843 * @widget: the widget
11845 * Gets whether gtk_widget_set_hexpand() has been used to
11846 * explicitly set the expand flag on this widget.
11848 * If hexpand is set, then it overrides any computed
11849 * expand value based on child widgets. If hexpand is not
11850 * set, then the expand value depends on whether any
11851 * children of the widget would like to expand.
11853 * There are few reasons to use this function, but it's here
11854 * for completeness and consistency.
11856 * Return value: whether hexpand has been explicitly set
11859 gtk_widget_get_hexpand_set (GtkWidget *widget)
11861 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11863 return widget->priv->hexpand_set;
11867 * gtk_widget_set_hexpand_set:
11868 * @widget: the widget
11869 * @set: value for hexpand-set property
11871 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
11874 * The hexpand-set property will be set automatically when you call
11875 * gtk_widget_set_hexpand() to set hexpand, so the most likely
11876 * reason to use this function would be to unset an explicit expand
11879 * If hexpand is set, then it overrides any computed
11880 * expand value based on child widgets. If hexpand is not
11881 * set, then the expand value depends on whether any
11882 * children of the widget would like to expand.
11884 * There are few reasons to use this function, but it's here
11885 * for completeness and consistency.
11888 gtk_widget_set_hexpand_set (GtkWidget *widget,
11891 g_return_if_fail (GTK_IS_WIDGET (widget));
11893 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
11898 * gtk_widget_get_vexpand:
11899 * @widget: the widget
11901 * Gets whether the widget would like any available extra vertical
11904 * See gtk_widget_get_hexpand() for more detail.
11906 * Return value: whether vexpand flag is set
11909 gtk_widget_get_vexpand (GtkWidget *widget)
11911 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11913 return widget->priv->vexpand;
11917 * gtk_widget_set_vexpand:
11918 * @widget: the widget
11919 * @expand: whether to expand
11921 * Sets whether the widget would like any available extra vertical
11924 * See gtk_widget_set_hexpand() for more detail.
11927 gtk_widget_set_vexpand (GtkWidget *widget,
11930 g_return_if_fail (GTK_IS_WIDGET (widget));
11932 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
11936 * gtk_widget_get_vexpand_set:
11937 * @widget: the widget
11939 * Gets whether gtk_widget_set_vexpand() has been used to
11940 * explicitly set the expand flag on this widget.
11942 * See gtk_widget_get_hexpand_set() for more detail.
11944 * Return value: whether vexpand has been explicitly set
11947 gtk_widget_get_vexpand_set (GtkWidget *widget)
11949 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11951 return widget->priv->vexpand_set;
11955 * gtk_widget_set_vexpand_set:
11956 * @widget: the widget
11957 * @set: value for vexpand-set property
11959 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
11962 * See gtk_widget_set_hexpand_set() for more detail.
11965 gtk_widget_set_vexpand_set (GtkWidget *widget,
11968 g_return_if_fail (GTK_IS_WIDGET (widget));
11970 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
11974 * GtkBuildable implementation
11976 static GQuark quark_builder_has_default = 0;
11977 static GQuark quark_builder_has_focus = 0;
11978 static GQuark quark_builder_atk_relations = 0;
11979 static GQuark quark_builder_set_name = 0;
11982 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
11984 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
11985 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
11986 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
11987 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
11989 iface->set_name = gtk_widget_buildable_set_name;
11990 iface->get_name = gtk_widget_buildable_get_name;
11991 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
11992 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
11993 iface->parser_finished = gtk_widget_buildable_parser_finished;
11994 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
11995 iface->custom_finished = gtk_widget_buildable_custom_finished;
11999 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12002 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12003 g_strdup (name), g_free);
12006 static const gchar *
12007 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12009 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12013 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12014 GtkBuilder *builder,
12015 const gchar *childname)
12017 if (strcmp (childname, "accessible") == 0)
12018 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12024 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12025 GtkBuilder *builder,
12027 const GValue *value)
12029 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12030 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12031 GINT_TO_POINTER (TRUE));
12032 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12033 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12034 GINT_TO_POINTER (TRUE));
12036 g_object_set_property (G_OBJECT (buildable), name, value);
12041 gchar *action_name;
12042 GString *description;
12044 gboolean translatable;
12054 free_action (AtkActionData *data, gpointer user_data)
12056 g_free (data->action_name);
12057 g_string_free (data->description, TRUE);
12058 g_free (data->context);
12059 g_slice_free (AtkActionData, data);
12063 free_relation (AtkRelationData *data, gpointer user_data)
12065 g_free (data->target);
12066 g_free (data->type);
12067 g_slice_free (AtkRelationData, data);
12071 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12072 GtkBuilder *builder)
12074 GSList *atk_relations;
12076 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12077 gtk_widget_grab_default (GTK_WIDGET (buildable));
12078 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12079 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12081 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12082 quark_builder_atk_relations);
12085 AtkObject *accessible;
12086 AtkRelationSet *relation_set;
12089 AtkRelationType relation_type;
12090 AtkObject *target_accessible;
12092 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12093 relation_set = atk_object_ref_relation_set (accessible);
12095 for (l = atk_relations; l; l = l->next)
12097 AtkRelationData *relation = (AtkRelationData*)l->data;
12099 target = gtk_builder_get_object (builder, relation->target);
12102 g_warning ("Target object %s in <relation> does not exist",
12106 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12107 g_assert (target_accessible != NULL);
12109 relation_type = atk_relation_type_for_name (relation->type);
12110 if (relation_type == ATK_RELATION_NULL)
12112 g_warning ("<relation> type %s not found",
12116 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12117 target_accessible);
12119 g_object_unref (relation_set);
12121 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
12122 g_slist_free (atk_relations);
12123 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12132 } AccessibilitySubParserData;
12135 accessibility_start_element (GMarkupParseContext *context,
12136 const gchar *element_name,
12137 const gchar **names,
12138 const gchar **values,
12139 gpointer user_data,
12142 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12144 gint line_number, char_number;
12146 if (strcmp (element_name, "relation") == 0)
12148 gchar *target = NULL;
12149 gchar *type = NULL;
12150 AtkRelationData *relation;
12152 for (i = 0; names[i]; i++)
12154 if (strcmp (names[i], "target") == 0)
12155 target = g_strdup (values[i]);
12156 else if (strcmp (names[i], "type") == 0)
12157 type = g_strdup (values[i]);
12160 g_markup_parse_context_get_position (context,
12163 g_set_error (error,
12165 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12166 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12168 line_number, char_number, names[i], "relation");
12175 if (!target || !type)
12177 g_markup_parse_context_get_position (context,
12180 g_set_error (error,
12182 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12183 "%s:%d:%d <%s> requires attribute \"%s\"",
12185 line_number, char_number, "relation",
12186 type ? "target" : "type");
12192 relation = g_slice_new (AtkRelationData);
12193 relation->target = target;
12194 relation->type = type;
12196 data->relations = g_slist_prepend (data->relations, relation);
12198 else if (strcmp (element_name, "action") == 0)
12200 const gchar *action_name = NULL;
12201 const gchar *description = NULL;
12202 const gchar *msg_context = NULL;
12203 gboolean translatable = FALSE;
12204 AtkActionData *action;
12206 for (i = 0; names[i]; i++)
12208 if (strcmp (names[i], "action_name") == 0)
12209 action_name = values[i];
12210 else if (strcmp (names[i], "description") == 0)
12211 description = values[i];
12212 else if (strcmp (names[i], "translatable") == 0)
12214 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12217 else if (strcmp (names[i], "comments") == 0)
12219 /* do nothing, comments are for translators */
12221 else if (strcmp (names[i], "context") == 0)
12222 msg_context = values[i];
12225 g_markup_parse_context_get_position (context,
12228 g_set_error (error,
12230 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12231 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12233 line_number, char_number, names[i], "action");
12240 g_markup_parse_context_get_position (context,
12243 g_set_error (error,
12245 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12246 "%s:%d:%d <%s> requires attribute \"%s\"",
12248 line_number, char_number, "action",
12253 action = g_slice_new (AtkActionData);
12254 action->action_name = g_strdup (action_name);
12255 action->description = g_string_new (description);
12256 action->context = g_strdup (msg_context);
12257 action->translatable = translatable;
12259 data->actions = g_slist_prepend (data->actions, action);
12261 else if (strcmp (element_name, "accessibility") == 0)
12264 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12268 accessibility_text (GMarkupParseContext *context,
12271 gpointer user_data,
12274 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12276 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12278 AtkActionData *action = data->actions->data;
12280 g_string_append_len (action->description, text, text_len);
12284 static const GMarkupParser accessibility_parser =
12286 accessibility_start_element,
12288 accessibility_text,
12297 } AccelGroupParserData;
12300 accel_group_start_element (GMarkupParseContext *context,
12301 const gchar *element_name,
12302 const gchar **names,
12303 const gchar **values,
12304 gpointer user_data,
12309 guint modifiers = 0;
12310 gchar *signal = NULL;
12311 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12313 for (i = 0; names[i]; i++)
12315 if (strcmp (names[i], "key") == 0)
12316 key = gdk_keyval_from_name (values[i]);
12317 else if (strcmp (names[i], "modifiers") == 0)
12319 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12325 else if (strcmp (names[i], "signal") == 0)
12326 signal = g_strdup (values[i]);
12329 if (key == 0 || signal == NULL)
12331 g_warning ("<accelerator> requires key and signal attributes");
12334 parser_data->key = key;
12335 parser_data->modifiers = modifiers;
12336 parser_data->signal = signal;
12339 static const GMarkupParser accel_group_parser =
12341 accel_group_start_element,
12345 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12346 GtkBuilder *builder,
12348 const gchar *tagname,
12349 GMarkupParser *parser,
12352 g_assert (buildable);
12354 if (strcmp (tagname, "accelerator") == 0)
12356 AccelGroupParserData *parser_data;
12358 parser_data = g_slice_new0 (AccelGroupParserData);
12359 parser_data->object = g_object_ref (buildable);
12360 *parser = accel_group_parser;
12361 *data = parser_data;
12364 if (strcmp (tagname, "accessibility") == 0)
12366 AccessibilitySubParserData *parser_data;
12368 parser_data = g_slice_new0 (AccessibilitySubParserData);
12369 *parser = accessibility_parser;
12370 *data = parser_data;
12377 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12378 GtkWidget *toplevel,
12379 gpointer user_data)
12381 AccelGroupParserData *accel_data;
12382 GSList *accel_groups;
12383 GtkAccelGroup *accel_group;
12385 g_return_if_fail (GTK_IS_WIDGET (widget));
12386 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12387 g_return_if_fail (user_data != NULL);
12389 accel_data = (AccelGroupParserData*)user_data;
12390 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12391 if (g_slist_length (accel_groups) == 0)
12393 accel_group = gtk_accel_group_new ();
12394 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12398 g_assert (g_slist_length (accel_groups) == 1);
12399 accel_group = g_slist_nth_data (accel_groups, 0);
12402 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12403 accel_data->signal,
12406 accel_data->modifiers,
12407 GTK_ACCEL_VISIBLE);
12409 g_object_unref (accel_data->object);
12410 g_free (accel_data->signal);
12411 g_slice_free (AccelGroupParserData, accel_data);
12415 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12416 GtkBuilder *builder,
12418 const gchar *tagname,
12419 gpointer user_data)
12421 AccelGroupParserData *accel_data;
12422 AccessibilitySubParserData *a11y_data;
12423 GtkWidget *toplevel;
12425 if (strcmp (tagname, "accelerator") == 0)
12427 accel_data = (AccelGroupParserData*)user_data;
12428 g_assert (accel_data->object);
12430 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12432 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12434 else if (strcmp (tagname, "accessibility") == 0)
12436 a11y_data = (AccessibilitySubParserData*)user_data;
12438 if (a11y_data->actions)
12440 AtkObject *accessible;
12445 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12447 action = ATK_ACTION (accessible);
12448 n_actions = atk_action_get_n_actions (action);
12450 for (l = a11y_data->actions; l; l = l->next)
12452 AtkActionData *action_data = (AtkActionData*)l->data;
12454 for (i = 0; i < n_actions; i++)
12455 if (strcmp (atk_action_get_name (action, i),
12456 action_data->action_name) == 0)
12461 gchar *description;
12463 if (action_data->translatable && action_data->description->len)
12464 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12465 action_data->context,
12466 action_data->description->str);
12468 description = action_data->description->str;
12470 atk_action_set_description (action, i, description);
12474 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
12475 g_slist_free (a11y_data->actions);
12478 if (a11y_data->relations)
12479 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12480 a11y_data->relations);
12482 g_slice_free (AccessibilitySubParserData, a11y_data);
12487 gtk_widget_real_get_width (GtkWidget *widget,
12488 gint *minimum_size,
12489 gint *natural_size)
12499 gtk_widget_real_get_height (GtkWidget *widget,
12500 gint *minimum_size,
12501 gint *natural_size)
12511 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12513 gint *minimum_height,
12514 gint *natural_height)
12516 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12520 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12522 gint *minimum_width,
12523 gint *natural_width)
12525 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12529 * gtk_widget_get_halign:
12530 * @widget: a #GtkWidget
12532 * Gets the value of the #GtkWidget:halign property.
12534 * Returns: the horizontal alignment of @widget
12537 gtk_widget_get_halign (GtkWidget *widget)
12539 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12540 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12544 * gtk_widget_set_halign:
12545 * @widget: a #GtkWidget
12546 * @align: the horizontal alignment
12548 * Sets the horizontal alignment of @widget.
12549 * See the #GtkWidget:halign property.
12552 gtk_widget_set_halign (GtkWidget *widget,
12555 GtkWidgetAuxInfo *aux_info;
12557 g_return_if_fail (GTK_IS_WIDGET (widget));
12559 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12561 if (aux_info->halign == align)
12564 aux_info->halign = align;
12565 gtk_widget_queue_resize (widget);
12566 g_object_notify (G_OBJECT (widget), "halign");
12570 * gtk_widget_get_valign:
12571 * @widget: a #GtkWidget
12573 * Gets the value of the #GtkWidget:valign property.
12575 * Returns: the vertical alignment of @widget
12578 gtk_widget_get_valign (GtkWidget *widget)
12580 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12581 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12585 * gtk_widget_set_valign:
12586 * @widget: a #GtkWidget
12587 * @align: the vertical alignment
12589 * Sets the vertical alignment of @widget.
12590 * See the #GtkWidget:valign property.
12593 gtk_widget_set_valign (GtkWidget *widget,
12596 GtkWidgetAuxInfo *aux_info;
12598 g_return_if_fail (GTK_IS_WIDGET (widget));
12600 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12602 if (aux_info->valign == align)
12605 aux_info->valign = align;
12606 gtk_widget_queue_resize (widget);
12607 g_object_notify (G_OBJECT (widget), "valign");
12611 * gtk_widget_get_margin_left:
12612 * @widget: a #GtkWidget
12614 * Gets the value of the #GtkWidget:margin-left property.
12616 * Returns: The left margin of @widget
12619 gtk_widget_get_margin_left (GtkWidget *widget)
12621 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12623 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12627 * gtk_widget_set_margin_left:
12628 * @widget: a #GtkWidget
12629 * @margin: the left margin
12631 * Sets the left margin of @widget.
12632 * See the #GtkWidget:margin-left property.
12635 gtk_widget_set_margin_left (GtkWidget *widget,
12638 GtkWidgetAuxInfo *aux_info;
12640 g_return_if_fail (GTK_IS_WIDGET (widget));
12641 g_return_if_fail (margin <= G_MAXINT16);
12643 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12645 if (aux_info->margin.left == margin)
12648 aux_info->margin.left = margin;
12649 gtk_widget_queue_resize (widget);
12650 g_object_notify (G_OBJECT (widget), "margin-left");
12654 * gtk_widget_get_margin_right:
12655 * @widget: a #GtkWidget
12657 * Gets the value of the #GtkWidget:margin-right property.
12659 * Returns: The left margin of @widget
12662 gtk_widget_get_margin_right (GtkWidget *widget)
12664 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12666 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12670 * gtk_widget_set_margin_right:
12671 * @widget: a #GtkWidget
12672 * @margin: the right margin
12674 * Sets the right margin of @widget.
12675 * See the #GtkWidget:margin-right property.
12678 gtk_widget_set_margin_right (GtkWidget *widget,
12681 GtkWidgetAuxInfo *aux_info;
12683 g_return_if_fail (GTK_IS_WIDGET (widget));
12684 g_return_if_fail (margin <= G_MAXINT16);
12686 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12688 if (aux_info->margin.right == margin)
12691 aux_info->margin.right = margin;
12692 gtk_widget_queue_resize (widget);
12693 g_object_notify (G_OBJECT (widget), "margin-right");
12697 * gtk_widget_get_margin_top:
12698 * @widget: a #GtkWidget
12700 * Gets the value of the #GtkWidget:margin-top property.
12702 * Returns: The top margin of @widget
12705 gtk_widget_get_margin_top (GtkWidget *widget)
12707 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12709 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12713 * gtk_widget_set_margin_top:
12714 * @widget: a #GtkWidget
12715 * @margin: the top margin
12717 * Sets the top margin of @widget.
12718 * See the #GtkWidget:margin-top property.
12721 gtk_widget_set_margin_top (GtkWidget *widget,
12724 GtkWidgetAuxInfo *aux_info;
12726 g_return_if_fail (GTK_IS_WIDGET (widget));
12727 g_return_if_fail (margin <= G_MAXINT16);
12729 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12731 if (aux_info->margin.top == margin)
12734 aux_info->margin.top = margin;
12735 gtk_widget_queue_resize (widget);
12736 g_object_notify (G_OBJECT (widget), "margin-top");
12740 * gtk_widget_get_margin_bottom:
12741 * @widget: a #GtkWidget
12743 * Gets the value of the #GtkWidget:margin-bottom property.
12745 * Returns: The bottom margin of @widget
12748 gtk_widget_get_margin_bottom (GtkWidget *widget)
12750 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12752 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
12756 * gtk_widget_set_margin_bottom:
12757 * @widget: a #GtkWidget
12758 * @margin: the bottom margin
12760 * Sets the bottom margin of @widget.
12761 * See the #GtkWidget:margin-bottom property.
12764 gtk_widget_set_margin_bottom (GtkWidget *widget,
12767 GtkWidgetAuxInfo *aux_info;
12769 g_return_if_fail (GTK_IS_WIDGET (widget));
12770 g_return_if_fail (margin <= G_MAXINT16);
12772 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12774 if (aux_info->margin.bottom == margin)
12777 aux_info->margin.bottom = margin;
12778 gtk_widget_queue_resize (widget);
12779 g_object_notify (G_OBJECT (widget), "margin-bottom");
12783 * gtk_widget_get_clipboard:
12784 * @widget: a #GtkWidget
12785 * @selection: a #GdkAtom which identifies the clipboard
12786 * to use. %GDK_SELECTION_CLIPBOARD gives the
12787 * default clipboard. Another common value
12788 * is %GDK_SELECTION_PRIMARY, which gives
12789 * the primary X selection.
12791 * Returns the clipboard object for the given selection to
12792 * be used with @widget. @widget must have a #GdkDisplay
12793 * associated with it, so must be attached to a toplevel
12796 * Return value: (transfer none): the appropriate clipboard object. If no
12797 * clipboard already exists, a new one will
12798 * be created. Once a clipboard object has
12799 * been created, it is persistent for all time.
12804 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
12806 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12807 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
12809 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
12814 * gtk_widget_list_mnemonic_labels:
12815 * @widget: a #GtkWidget
12817 * Returns a newly allocated list of the widgets, normally labels, for
12818 * which this widget is the target of a mnemonic (see for example,
12819 * gtk_label_set_mnemonic_widget()).
12821 * The widgets in the list are not individually referenced. If you
12822 * want to iterate through the list and perform actions involving
12823 * callbacks that might destroy the widgets, you
12824 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
12825 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
12826 * widgets afterwards.
12828 * Return value: (element-type GtkWidget) (transfer container): the list of
12829 * mnemonic labels; free this list
12830 * with g_list_free() when you are done with it.
12835 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
12837 GList *list = NULL;
12840 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12842 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
12843 list = g_list_prepend (list, l->data);
12849 * gtk_widget_add_mnemonic_label:
12850 * @widget: a #GtkWidget
12851 * @label: a #GtkWidget that acts as a mnemonic label for @widget
12853 * Adds a widget to the list of mnemonic labels for
12854 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
12855 * list of mnemonic labels for the widget is cleared when the
12856 * widget is destroyed, so the caller must make sure to update
12857 * its internal state at this point as well, by using a connection
12858 * to the #GtkWidget::destroy signal or a weak notifier.
12863 gtk_widget_add_mnemonic_label (GtkWidget *widget,
12866 GSList *old_list, *new_list;
12868 g_return_if_fail (GTK_IS_WIDGET (widget));
12869 g_return_if_fail (GTK_IS_WIDGET (label));
12871 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12872 new_list = g_slist_prepend (old_list, label);
12874 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12875 new_list, (GDestroyNotify) g_slist_free);
12879 * gtk_widget_remove_mnemonic_label:
12880 * @widget: a #GtkWidget
12881 * @label: a #GtkWidget that was previously set as a mnemnic label for
12882 * @widget with gtk_widget_add_mnemonic_label().
12884 * Removes a widget from the list of mnemonic labels for
12885 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
12886 * must have previously been added to the list with
12887 * gtk_widget_add_mnemonic_label().
12892 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
12895 GSList *old_list, *new_list;
12897 g_return_if_fail (GTK_IS_WIDGET (widget));
12898 g_return_if_fail (GTK_IS_WIDGET (label));
12900 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12901 new_list = g_slist_remove (old_list, label);
12904 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12905 new_list, (GDestroyNotify) g_slist_free);
12909 * gtk_widget_get_no_show_all:
12910 * @widget: a #GtkWidget
12912 * Returns the current value of the #GtkWidget:no-show-all property,
12913 * which determines whether calls to gtk_widget_show_all()
12914 * will affect this widget.
12916 * Return value: the current value of the "no-show-all" property.
12921 gtk_widget_get_no_show_all (GtkWidget *widget)
12923 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12925 return widget->priv->no_show_all;
12929 * gtk_widget_set_no_show_all:
12930 * @widget: a #GtkWidget
12931 * @no_show_all: the new value for the "no-show-all" property
12933 * Sets the #GtkWidget:no-show-all property, which determines whether
12934 * calls to gtk_widget_show_all() will affect this widget.
12936 * This is mostly for use in constructing widget hierarchies with externally
12937 * controlled visibility, see #GtkUIManager.
12942 gtk_widget_set_no_show_all (GtkWidget *widget,
12943 gboolean no_show_all)
12945 g_return_if_fail (GTK_IS_WIDGET (widget));
12947 no_show_all = (no_show_all != FALSE);
12949 if (widget->priv->no_show_all != no_show_all)
12951 widget->priv->no_show_all = no_show_all;
12953 g_object_notify (G_OBJECT (widget), "no-show-all");
12959 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
12960 gboolean has_tooltip,
12963 GtkWidgetPrivate *priv = widget->priv;
12964 gboolean priv_has_tooltip;
12966 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
12967 quark_has_tooltip));
12969 if (priv_has_tooltip != has_tooltip || force)
12971 priv_has_tooltip = has_tooltip;
12973 if (priv_has_tooltip)
12975 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
12976 gdk_window_set_events (priv->window,
12977 gdk_window_get_events (priv->window) |
12978 GDK_LEAVE_NOTIFY_MASK |
12979 GDK_POINTER_MOTION_MASK |
12980 GDK_POINTER_MOTION_HINT_MASK);
12982 if (gtk_widget_get_has_window (widget))
12983 gtk_widget_add_events (widget,
12984 GDK_LEAVE_NOTIFY_MASK |
12985 GDK_POINTER_MOTION_MASK |
12986 GDK_POINTER_MOTION_HINT_MASK);
12989 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
12990 GUINT_TO_POINTER (priv_has_tooltip));
12995 * gtk_widget_set_tooltip_window:
12996 * @widget: a #GtkWidget
12997 * @custom_window: (allow-none): a #GtkWindow, or %NULL
12999 * Replaces the default, usually yellow, window used for displaying
13000 * tooltips with @custom_window. GTK+ will take care of showing and
13001 * hiding @custom_window at the right moment, to behave likewise as
13002 * the default tooltip window. If @custom_window is %NULL, the default
13003 * tooltip window will be used.
13005 * If the custom window should have the default theming it needs to
13006 * have the name "gtk-tooltip", see gtk_widget_set_name().
13011 gtk_widget_set_tooltip_window (GtkWidget *widget,
13012 GtkWindow *custom_window)
13014 gboolean has_tooltip;
13015 gchar *tooltip_markup;
13017 g_return_if_fail (GTK_IS_WIDGET (widget));
13018 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13020 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13023 g_object_ref (custom_window);
13025 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13026 custom_window, g_object_unref);
13028 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13029 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13031 if (has_tooltip && gtk_widget_get_visible (widget))
13032 gtk_widget_queue_tooltip_query (widget);
13036 * gtk_widget_get_tooltip_window:
13037 * @widget: a #GtkWidget
13039 * Returns the #GtkWindow of the current tooltip. This can be the
13040 * GtkWindow created by default, or the custom tooltip window set
13041 * using gtk_widget_set_tooltip_window().
13043 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13048 gtk_widget_get_tooltip_window (GtkWidget *widget)
13050 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13052 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13056 * gtk_widget_trigger_tooltip_query:
13057 * @widget: a #GtkWidget
13059 * Triggers a tooltip query on the display where the toplevel of @widget
13060 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13066 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13068 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13071 static guint tooltip_query_id;
13072 static GSList *tooltip_query_displays;
13075 tooltip_query_idle (gpointer data)
13077 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13078 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13079 g_slist_free (tooltip_query_displays);
13081 tooltip_query_displays = NULL;
13082 tooltip_query_id = 0;
13088 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13090 GdkDisplay *display;
13092 display = gtk_widget_get_display (widget);
13094 if (!g_slist_find (tooltip_query_displays, display))
13095 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13097 if (tooltip_query_id == 0)
13098 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13102 * gtk_widget_set_tooltip_text:
13103 * @widget: a #GtkWidget
13104 * @text: the contents of the tooltip for @widget
13106 * Sets @text as the contents of the tooltip. This function will take
13107 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13108 * handler for the #GtkWidget::query-tooltip signal.
13110 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13115 gtk_widget_set_tooltip_text (GtkWidget *widget,
13118 g_return_if_fail (GTK_IS_WIDGET (widget));
13120 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13124 * gtk_widget_get_tooltip_text:
13125 * @widget: a #GtkWidget
13127 * Gets the contents of the tooltip for @widget.
13129 * Return value: the tooltip text, or %NULL. You should free the
13130 * returned string with g_free() when done.
13135 gtk_widget_get_tooltip_text (GtkWidget *widget)
13137 gchar *text = NULL;
13139 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13141 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13147 * gtk_widget_set_tooltip_markup:
13148 * @widget: a #GtkWidget
13149 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13151 * Sets @markup as the contents of the tooltip, which is marked up with
13152 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13154 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13155 * and of the default handler for the #GtkWidget::query-tooltip signal.
13157 * See also the #GtkWidget:tooltip-markup property and
13158 * gtk_tooltip_set_markup().
13163 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13164 const gchar *markup)
13166 g_return_if_fail (GTK_IS_WIDGET (widget));
13168 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13172 * gtk_widget_get_tooltip_markup:
13173 * @widget: a #GtkWidget
13175 * Gets the contents of the tooltip for @widget.
13177 * Return value: the tooltip text, or %NULL. You should free the
13178 * returned string with g_free() when done.
13183 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13185 gchar *text = NULL;
13187 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13189 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13195 * gtk_widget_set_has_tooltip:
13196 * @widget: a #GtkWidget
13197 * @has_tooltip: whether or not @widget has a tooltip.
13199 * Sets the has-tooltip property on @widget to @has_tooltip. See
13200 * #GtkWidget:has-tooltip for more information.
13205 gtk_widget_set_has_tooltip (GtkWidget *widget,
13206 gboolean has_tooltip)
13208 g_return_if_fail (GTK_IS_WIDGET (widget));
13210 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13214 * gtk_widget_get_has_tooltip:
13215 * @widget: a #GtkWidget
13217 * Returns the current value of the has-tooltip property. See
13218 * #GtkWidget:has-tooltip for more information.
13220 * Return value: current value of has-tooltip on @widget.
13225 gtk_widget_get_has_tooltip (GtkWidget *widget)
13227 gboolean has_tooltip = FALSE;
13229 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13231 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13233 return has_tooltip;
13237 * gtk_widget_get_allocation:
13238 * @widget: a #GtkWidget
13239 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13241 * Retrieves the widget's allocation.
13243 * Note, when implementing a #GtkContainer: a widget's allocation will
13244 * be its "adjusted" allocation, that is, the widget's parent
13245 * container typically calls gtk_widget_size_allocate() with an
13246 * allocation, and that allocation is then adjusted (to handle margin
13247 * and alignment for example) before assignment to the widget.
13248 * gtk_widget_get_allocation() returns the adjusted allocation that
13249 * was actually assigned to the widget. The adjusted allocation is
13250 * guaranteed to be completely contained within the
13251 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13252 * is guaranteed that its children stay inside the assigned bounds,
13253 * but not that they have exactly the bounds the container assigned.
13254 * There is no way to get the original allocation assigned by
13255 * gtk_widget_size_allocate(), since it isn't stored; if a container
13256 * implementation needs that information it will have to track it itself.
13261 gtk_widget_get_allocation (GtkWidget *widget,
13262 GtkAllocation *allocation)
13264 GtkWidgetPrivate *priv;
13266 g_return_if_fail (GTK_IS_WIDGET (widget));
13267 g_return_if_fail (allocation != NULL);
13269 priv = widget->priv;
13271 *allocation = priv->allocation;
13275 * gtk_widget_set_allocation:
13276 * @widget: a #GtkWidget
13277 * @allocation: a pointer to a #GtkAllocation to copy from
13279 * Sets the widget's allocation. This should not be used
13280 * directly, but from within a widget's size_allocate method.
13282 * The allocation set should be the "adjusted" or actual
13283 * allocation. If you're implementing a #GtkContainer, you want to use
13284 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13285 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13286 * allocation inside gtk_widget_size_allocate() to create an adjusted
13292 gtk_widget_set_allocation (GtkWidget *widget,
13293 const GtkAllocation *allocation)
13295 GtkWidgetPrivate *priv;
13297 g_return_if_fail (GTK_IS_WIDGET (widget));
13298 g_return_if_fail (allocation != NULL);
13300 priv = widget->priv;
13302 priv->allocation = *allocation;
13306 * gtk_widget_get_allocated_width:
13307 * @widget: the widget to query
13309 * Returns the width that has currently been allocated to @widget.
13310 * This function is intended to be used when implementing handlers
13311 * for the #GtkWidget::draw function.
13313 * Returns: the width of the @widget
13316 gtk_widget_get_allocated_width (GtkWidget *widget)
13318 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13320 return widget->priv->allocation.width;
13324 * gtk_widget_get_allocated_height:
13325 * @widget: the widget to query
13327 * Returns the height that has currently been allocated to @widget.
13328 * This function is intended to be used when implementing handlers
13329 * for the #GtkWidget::draw function.
13331 * Returns: the height of the @widget
13334 gtk_widget_get_allocated_height (GtkWidget *widget)
13336 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13338 return widget->priv->allocation.height;
13342 * gtk_widget_get_requisition:
13343 * @widget: a #GtkWidget
13344 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13346 * Retrieves the widget's requisition.
13348 * This function should only be used by widget implementations in
13349 * order to figure whether the widget's requisition has actually
13350 * changed after some internal state change (so that they can call
13351 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13353 * Normally, gtk_widget_size_request() should be used.
13357 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13358 * removed, If you need to cache sizes across requests and allocations,
13359 * add an explicit cache to the widget in question instead.
13362 gtk_widget_get_requisition (GtkWidget *widget,
13363 GtkRequisition *requisition)
13365 g_return_if_fail (GTK_IS_WIDGET (widget));
13366 g_return_if_fail (requisition != NULL);
13368 gtk_widget_get_preferred_size (widget, requisition, NULL);
13372 * gtk_widget_set_window:
13373 * @widget: a #GtkWidget
13374 * @window: a #GdkWindow
13376 * Sets a widget's window. This function should only be used in a
13377 * widget's #GtkWidget::realize implementation. The %window passed is
13378 * usually either new window created with gdk_window_new(), or the
13379 * window of its parent widget as returned by
13380 * gtk_widget_get_parent_window().
13382 * Widgets must indicate whether they will create their own #GdkWindow
13383 * by calling gtk_widget_set_has_window(). This is usually done in the
13384 * widget's init() function.
13386 * <note><para>This function does not add any reference to @window.</para></note>
13391 gtk_widget_set_window (GtkWidget *widget,
13394 GtkWidgetPrivate *priv;
13396 g_return_if_fail (GTK_IS_WIDGET (widget));
13397 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13399 priv = widget->priv;
13401 if (priv->window != window)
13403 priv->window = window;
13404 g_object_notify (G_OBJECT (widget), "window");
13409 * gtk_widget_get_window:
13410 * @widget: a #GtkWidget
13412 * Returns the widget's window if it is realized, %NULL otherwise
13414 * Return value: (transfer none): @widget's window.
13419 gtk_widget_get_window (GtkWidget *widget)
13421 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13423 return widget->priv->window;
13427 * gtk_widget_get_support_multidevice:
13428 * @widget: a #GtkWidget
13430 * Returns %TRUE if @widget is multiple pointer aware. See
13431 * gtk_widget_set_support_multidevice() for more information.
13433 * Returns: %TRUE if @widget is multidevice aware.
13436 gtk_widget_get_support_multidevice (GtkWidget *widget)
13438 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13440 return widget->priv->multidevice;
13444 * gtk_widget_set_support_multidevice:
13445 * @widget: a #GtkWidget
13446 * @support_multidevice: %TRUE to support input from multiple devices.
13448 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13449 * @widget will start receiving multiple, per device enter/leave events. Note
13450 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13451 * gdk_window_set_support_multidevice() will have to be called manually on them.
13456 gtk_widget_set_support_multidevice (GtkWidget *widget,
13457 gboolean support_multidevice)
13459 GtkWidgetPrivate *priv;
13461 g_return_if_fail (GTK_IS_WIDGET (widget));
13463 priv = widget->priv;
13464 priv->multidevice = (support_multidevice == TRUE);
13466 if (gtk_widget_get_realized (widget))
13467 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13471 _gtk_widget_set_has_focus (GtkWidget *widget,
13472 gboolean has_focus)
13474 widget->priv->has_focus = has_focus;
13478 * gtk_widget_send_focus_change:
13479 * @widget: a #GtkWidget
13480 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13482 * Sends the focus change @event to @widget
13484 * This function is not meant to be used by applications. The only time it
13485 * should be used is when it is necessary for a #GtkWidget to assign focus
13486 * to a widget that is semantically owned by the first widget even though
13487 * it's not a direct child - for instance, a search entry in a floating
13488 * window similar to the quick search in #GtkTreeView.
13490 * An example of its usage is:
13493 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13495 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13496 * fevent->focus_change.in = TRUE;
13497 * fevent->focus_change.window = gtk_widget_get_window (widget);
13498 * if (fevent->focus_change.window != NULL)
13499 * g_object_ref (fevent->focus_change.window);
13501 * gtk_widget_send_focus_change (widget, fevent);
13503 * gdk_event_free (event);
13506 * Return value: the return value from the event signal emission: %TRUE
13507 * if the event was handled, and %FALSE otherwise
13512 gtk_widget_send_focus_change (GtkWidget *widget,
13517 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13518 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13520 g_object_ref (widget);
13522 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13524 res = gtk_widget_event (widget, event);
13526 g_object_notify (G_OBJECT (widget), "has-focus");
13528 g_object_unref (widget);
13534 * gtk_widget_in_destruction:
13535 * @widget: a #GtkWidget
13537 * Returns whether the widget is currently being destroyed.
13538 * This information can sometimes be used to avoid doing
13539 * unnecessary work.
13541 * Returns: %TRUE if @widget is being destroyed
13544 gtk_widget_in_destruction (GtkWidget *widget)
13546 return widget->priv->in_destruction;
13550 _gtk_widget_get_resize_pending (GtkWidget *widget)
13552 return widget->priv->resize_pending;
13556 _gtk_widget_set_resize_pending (GtkWidget *widget,
13557 gboolean resize_pending)
13559 widget->priv->resize_pending = resize_pending;
13563 _gtk_widget_get_in_reparent (GtkWidget *widget)
13565 return widget->priv->in_reparent;
13569 _gtk_widget_set_in_reparent (GtkWidget *widget,
13570 gboolean in_reparent)
13572 widget->priv->in_reparent = in_reparent;
13576 _gtk_widget_get_anchored (GtkWidget *widget)
13578 return widget->priv->anchored;
13582 _gtk_widget_set_anchored (GtkWidget *widget,
13585 widget->priv->anchored = anchored;
13589 _gtk_widget_get_shadowed (GtkWidget *widget)
13591 return widget->priv->shadowed;
13595 _gtk_widget_set_shadowed (GtkWidget *widget,
13598 widget->priv->shadowed = shadowed;
13602 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13604 return widget->priv->alloc_needed;
13608 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13609 gboolean alloc_needed)
13611 widget->priv->alloc_needed = alloc_needed;
13615 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13617 return widget->priv->width_request_needed;
13621 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13622 gboolean width_request_needed)
13624 widget->priv->width_request_needed = width_request_needed;
13628 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13630 return widget->priv->height_request_needed;
13634 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13635 gboolean height_request_needed)
13637 widget->priv->height_request_needed = height_request_needed;
13641 * gtk_widget_get_path:
13642 * @widget: a #GtkWidget
13644 * Returns the #GtkWidgetPath representing @widget, if the widget
13645 * is not connected to a toplevel widget, a partial path will be
13648 * Returns: (transfer none): The #GtkWidgetPath representing @widget
13651 gtk_widget_get_path (GtkWidget *widget)
13653 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13655 /* As strange as it may seem, this may happen on object construction.
13656 * init() implementations of parent types may eventually call this function,
13657 * each with its corresponding GType, which could leave a child
13658 * implementation with a wrong widget type in the widget path
13660 if (widget->priv->path &&
13661 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (widget->priv->path))
13663 gtk_widget_path_free (widget->priv->path);
13664 widget->priv->path = NULL;
13667 if (!widget->priv->path)
13672 parent = widget->priv->parent;
13675 widget->priv->path = gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
13678 /* Widget is either toplevel or unparented, treat both
13679 * as toplevels style wise, since there are situations
13680 * where style properties might be retrieved on that
13683 widget->priv->path = gtk_widget_path_new ();
13686 pos = gtk_widget_path_append_type (widget->priv->path, G_OBJECT_TYPE (widget));
13688 if (widget->priv->name)
13689 gtk_widget_path_iter_set_name (widget->priv->path, pos, widget->priv->name);
13691 if (widget->priv->context)
13692 gtk_style_context_set_path (widget->priv->context,
13693 widget->priv->path);
13696 return widget->priv->path;
13700 style_context_changed (GtkStyleContext *context,
13701 gpointer user_data)
13703 GtkWidget *widget = user_data;
13705 gtk_widget_update_pango_context (widget);
13706 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
13708 if (widget->priv->anchored)
13709 gtk_widget_queue_resize (widget);
13713 * gtk_widget_get_style_context:
13714 * @widget: a #GtkWidget
13716 * Returns the style context associated to @widget.
13718 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
13719 * must not be freed.
13722 gtk_widget_get_style_context (GtkWidget *widget)
13724 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13726 if (G_UNLIKELY (!widget->priv->context))
13728 widget->priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
13729 "direction", gtk_widget_get_direction (widget),
13732 g_signal_connect (widget->priv->context, "changed",
13733 G_CALLBACK (style_context_changed), widget);
13735 gtk_style_context_set_screen (widget->priv->context,
13736 gtk_widget_get_screen (widget));
13738 _gtk_widget_update_path (widget);
13739 gtk_style_context_set_path (widget->priv->context,
13740 widget->priv->path);
13744 /* Force widget path regeneration if needed, the
13745 * context will be updated within this function.
13747 gtk_widget_get_path (widget);
13750 return widget->priv->context;