1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #undef GDK_DISABLE_DEPRECATED /* gdk_input_set_extension_events() */
33 #include "gtkcontainer.h"
34 #include "gtkaccelmap.h"
35 #include "gtkclipboard.h"
36 #include "gtkiconfactory.h"
39 #include "gtkmarshalers.h"
41 #include "gtkselection.h"
42 #include "gtksettings.h"
43 #include "gtksizegroup-private.h"
44 #include "gtkwidget.h"
45 #include "gtkwidgetprivate.h"
46 #include "gtkwindow.h"
47 #include "gtkbindings.h"
48 #include "gtkprivate.h"
50 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
51 #include <gobject/gvaluecollector.h>
52 #include <gobject/gobjectnotifyqueue.c>
53 #include <cairo-gobject.h>
54 #include "gdk/gdkkeysyms.h"
55 #include "gtkaccessible.h"
56 #include "gtktooltip.h"
57 #include "gtkinvisible.h"
58 #include "gtkbuildable.h"
59 #include "gtkbuilderprivate.h"
60 #include "gtksizerequest.h"
61 #include "gtkstylecontext.h"
62 #include "gtksymboliccolor.h"
63 #include "gtkcssprovider.h"
64 #include "gtkanimationdescription.h"
65 #include "gtkmodifierstyle.h"
66 #include "gtkversion.h"
72 * @Short_description: Base class for all widgets
75 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
76 * widget lifecycle, states and style.
78 * <refsect2 id="geometry-management">
79 * <title>Height-for-width Geometry Management</title>
81 * GTK+ uses a height-for-width (and width-for-height) geometry management
82 * system. Height-for-width means that a widget can change how much
83 * vertical space it needs, depending on the amount of horizontal space
84 * that it is given (and similar for width-for-height). The most common
85 * example is a label that reflows to fill up the available width, wraps
86 * to fewer lines, and therefore needs less height.
88 * Height-for-width geometry management is implemented in GTK+ by way
89 * of five virtual methods:
91 * <listitem>#GtkWidgetClass.get_request_mode()</listitem>
92 * <listitem>#GtkWidgetClass.get_preferred_width()</listitem>
93 * <listitem>#GtkWidgetClass.get_preferred_height()</listitem>
94 * <listitem>#GtkWidgetClass.get_preferred_height_for_width()</listitem>
95 * <listitem>#GtkWidgetClass.get_preferred_width_for_height()</listitem>
98 * There are some important things to keep in mind when implementing
99 * height-for-width and when using it in container implementations.
101 * The geometry management system will query a widget hierarchy in
102 * only one orientation at a time. When widgets are initially queried
103 * for their minimum sizes it is generally done in two initial passes
104 * in the #GtkSizeRequestMode chosen by the toplevel.
106 * For example, when queried in the normal
107 * %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode:
108 * First, the default minimum and natural width for each widget
109 * in the interface will be computed using gtk_width_get_preferred_width().
110 * Because the preferred widths for each container depend on the preferred
111 * widths of their children, this information propagates up the hierarchy,
112 * and finally a minimum and natural width is determined for the entire
113 * toplevel. Next, the toplevel will use the minimum width to query for the
114 * minimum height contextual to that width using
115 * gtk_widget_get_preferred_height_for_width(), which will also be a highly
116 * recursive operation. The minimum height for the minimum width is normally
117 * used to set the minimum size constraint on the toplevel
118 * (unless gtk_window_set_geometry_hints() is explicitly used instead).
120 * After the toplevel window has initially requested its size in both
121 * dimensions it can go on to allocate itself a reasonable size (or a size
122 * previously specified with gtk_window_set_default_size()). During the
123 * recursive allocation process it's important to note that request cycles
124 * will be recursively executed while container widgets allocate their children.
125 * Each container widget, once allocated a size, will go on to first share the
126 * space in one orientation among its children and then request each child's
127 * height for its target allocated width or its width for allocated height,
128 * depending. In this way a #GtkWidget will typically be requested its size
129 * a number of times before actually being allocated a size. The size a
130 * widget is finally allocated can of course differ from the size it has
131 * requested. For this reason, #GtkWidget caches a small number of results
132 * to avoid re-querying for the same sizes in one allocation cycle.
134 * See <link linkend="container-geometry-management">GtkContainer's
135 * geometry management section</link>
136 * to learn more about how height-for-width allocations are performed
137 * by container widgets.
139 * If a widget does move content around to intelligently use up the
140 * allocated size then it must support the request in both
141 * #GtkSizeRequestModes even if the widget in question only
142 * trades sizes in a single orientation.
144 * For instance, a #GtkLabel that does height-for-width word wrapping
145 * will not expect to have #GtkWidgetClass.get_preferred_height() called
146 * because that call is specific to a width-for-height request. In this
147 * case the label must return the height required for its own minimum
148 * possible width. By following this rule any widget that handles
149 * height-for-width or width-for-height requests will always be allocated
150 * at least enough space to fit its own content.
152 * Here are some examples of how a %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH widget
153 * generally deals with width-for-height requests, for #GtkWidgetClass.get_preferred_height()
155 * <programlisting><![CDATA[
157 * foo_widget_get_preferred_height (GtkWidget *widget, gint *min_height, gint *nat_height)
159 * if (i_am_in_height_for_width_mode)
163 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
164 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width,
165 * min_height, nat_height);
169 * ... some widgets do both. For instance, if a GtkLabel is rotated to 90 degrees
170 * it will return the minimum and natural height for the rotated label here.
173 * ]]></programlisting>
175 * And in #GtkWidgetClass.get_preferred_width_for_height() it will simply return
176 * the minimum and natural width:
178 * <programlisting><![CDATA[
180 * foo_widget_get_preferred_width_for_height (GtkWidget *widget, gint for_height,
181 * gint *min_width, gint *nat_width)
183 * if (i_am_in_height_for_width_mode)
185 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, min_width, nat_width);
189 * ... again if a widget is sometimes operating in width-for-height mode
190 * (like a rotated GtkLabel) it can go ahead and do its real width for
191 * height calculation here.
194 * ]]></programlisting>
196 * Often a widget needs to get its own request during size request or
197 * allocation. For example, when computing height it may need to also
198 * compute width. Or when deciding how to use an allocation, the widget
199 * may need to know its natural size. In these cases, the widget should
200 * be careful to call its virtual methods directly, like this:
202 * <title>Widget calling its own size request method.</title>
204 * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget),
209 * It will not work to use the wrapper functions, such as
210 * gtk_widget_get_preferred_width() inside your own size request
211 * implementation. These return a request adjusted by #GtkSizeGroup
212 * and by the #GtkWidgetClass.adjust_size_request() virtual method. If a
213 * widget used the wrappers inside its virtual method implementations,
214 * then the adjustments (such as widget margins) would be applied
215 * twice. GTK+ therefore does not allow this and will warn if you try
218 * Of course if you are getting the size request for
219 * <emphasis>another</emphasis> widget, such as a child of a
220 * container, you <emphasis>must</emphasis> use the wrapper APIs.
221 * Otherwise, you would not properly consider widget margins,
222 * #GtkSizeGroup, and so forth.
225 * <refsect2 id="style-properties">
226 * <title>Style Properties</title>
228 * <structname>GtkWidget</structname> introduces <firstterm>style
229 * properties</firstterm> - these are basically object properties that are stored
230 * not on the object, but in the style object associated to the widget. Style
231 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
232 * This mechanism is used for configuring such things as the location of the
233 * scrollbar arrows through the theme, giving theme authors more control over the
234 * look of applications without the need to write a theme engine in C.
237 * Use gtk_widget_class_install_style_property() to install style properties for
238 * a widget class, gtk_widget_class_find_style_property() or
239 * gtk_widget_class_list_style_properties() to get information about existing
240 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
241 * gtk_widget_style_get_valist() to obtain the value of a style property.
244 * <refsect2 id="GtkWidget-BUILDER-UI">
245 * <title>GtkWidget as GtkBuildable</title>
247 * The GtkWidget implementation of the GtkBuildable interface supports a
248 * custom <accelerator> element, which has attributes named key,
249 * modifiers and signal and allows to specify accelerators.
252 * <title>A UI definition fragment specifying an accelerator</title>
253 * <programlisting><![CDATA[
254 * <object class="GtkButton">
255 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
257 * ]]></programlisting>
260 * In addition to accelerators, <structname>GtkWidget</structname> also support a
261 * custom <accessible> element, which supports actions and relations.
262 * Properties on the accessible implementation of an object can be set by accessing the
263 * internal child "accessible" of a <structname>GtkWidget</structname>.
266 * <title>A UI definition fragment specifying an accessible</title>
267 * <programlisting><![CDATA[
268 * <object class="GtkButton" id="label1"/>
269 * <property name="label">I am a Label for a Button</property>
271 * <object class="GtkButton" id="button1">
273 * <action action_name="click" translatable="yes">Click the button.</action>
274 * <relation target="label1" type="labelled-by"/>
276 * <child internal-child="accessible">
277 * <object class="AtkObject" id="a11y-button1">
278 * <property name="AtkObject::name">Clickable Button</property>
282 * ]]></programlisting>
287 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
288 #define INIT_PATH_SIZE (512)
290 struct _GtkWidgetPrivate
292 /* The state of the widget. There are actually only
293 * 5 widget states (defined in "gtkenums.h")
296 guint state_flags : 6;
300 guint in_destruction : 1;
303 guint composite_child : 1;
309 guint parent_sensitive : 1;
312 guint can_default : 1;
313 guint has_default : 1;
314 guint receives_default : 1;
318 guint user_style : 1;
319 guint app_paintable : 1;
320 guint double_buffered : 1;
321 guint redraw_on_alloc : 1;
322 guint no_show_all : 1;
323 guint child_visible : 1;
324 guint multidevice : 1;
325 guint has_shape_mask : 1;
326 guint in_reparent : 1;
327 guint resize_pending : 1;
328 guint alloc_needed : 1;
329 guint width_request_needed : 1;
330 guint height_request_needed : 1;
332 /* Expand-related flags */
333 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
334 guint computed_hexpand : 1; /* computed results (composite of child flags) */
335 guint computed_vexpand : 1;
336 guint hexpand : 1; /* application-forced expand */
338 guint hexpand_set : 1; /* whether to use application-forced */
339 guint vexpand_set : 1; /* instead of computing from children */
341 /* The widget's name. If the widget does not have a name
342 * (the name is NULL), then its name (as returned by
343 * "gtk_widget_get_name") is its class's name.
344 * Among other things, the widget name is used to determine
345 * the style to use for a widget.
349 /* The style for the widget. The style contains the
350 * colors the widget should be drawn in for each state
351 * along with graphics contexts used to draw with and
352 * the font to use for text.
355 GtkStyleContext *context;
357 /* The widget's allocated size.
359 GtkAllocation allocation;
361 /* The widget's requested sizes */
362 SizeRequestCache requests;
364 /* The widget's window or its parent window if it does
365 * not have a window. (Which will be indicated by the
366 * GTK_NO_WINDOW flag being set).
370 /* The widget's parent.
374 /* Widget's path for styling */
404 BUTTON_RELEASE_EVENT,
419 PROPERTY_NOTIFY_EVENT,
420 SELECTION_CLEAR_EVENT,
421 SELECTION_REQUEST_EVENT,
422 SELECTION_NOTIFY_EVENT,
428 VISIBILITY_NOTIFY_EVENT,
442 ACCEL_CLOSURES_CHANGED,
466 PROP_RECEIVES_DEFAULT,
467 PROP_COMPOSITE_CHILD,
470 PROP_EXTENSION_EVENTS,
476 PROP_DOUBLE_BUFFERED,
491 typedef struct _GtkStateData GtkStateData;
494 STATE_CHANGE_REPLACE,
503 guint parent_sensitive : 1;
504 guint use_forall : 1;
507 /* --- prototypes --- */
508 static void gtk_widget_class_init (GtkWidgetClass *klass);
509 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
510 static void gtk_widget_init (GtkWidget *widget);
511 static void gtk_widget_set_property (GObject *object,
515 static void gtk_widget_get_property (GObject *object,
519 static void gtk_widget_dispose (GObject *object);
520 static void gtk_widget_real_destroy (GtkWidget *object);
521 static void gtk_widget_finalize (GObject *object);
522 static void gtk_widget_real_show (GtkWidget *widget);
523 static void gtk_widget_real_hide (GtkWidget *widget);
524 static void gtk_widget_real_map (GtkWidget *widget);
525 static void gtk_widget_real_unmap (GtkWidget *widget);
526 static void gtk_widget_real_realize (GtkWidget *widget);
527 static void gtk_widget_real_unrealize (GtkWidget *widget);
528 static void gtk_widget_real_size_allocate (GtkWidget *widget,
529 GtkAllocation *allocation);
530 static void gtk_widget_real_style_set (GtkWidget *widget,
531 GtkStyle *previous_style);
532 static void gtk_widget_real_direction_changed(GtkWidget *widget,
533 GtkTextDirection previous_direction);
535 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
536 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
539 gboolean keyboard_tip,
540 GtkTooltip *tooltip);
541 static void gtk_widget_real_style_updated (GtkWidget *widget);
542 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
543 GtkWidgetHelpType help_type);
545 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
547 GParamSpec **pspecs);
548 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
550 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
552 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
553 GdkEventFocus *event);
554 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
555 GdkEventFocus *event);
556 static gboolean gtk_widget_real_focus (GtkWidget *widget,
557 GtkDirectionType direction);
558 static void gtk_widget_real_move_focus (GtkWidget *widget,
559 GtkDirectionType direction);
560 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
561 GtkDirectionType direction);
562 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
563 static void gtk_widget_update_pango_context (GtkWidget *widget);
564 static void gtk_widget_propagate_state (GtkWidget *widget,
566 static void gtk_widget_reset_rc_style (GtkWidget *widget);
567 static void gtk_widget_set_style_internal (GtkWidget *widget,
569 gboolean initial_emission);
570 static gint gtk_widget_event_internal (GtkWidget *widget,
572 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
573 gboolean group_cycling);
574 static void gtk_widget_real_get_width (GtkWidget *widget,
577 static void gtk_widget_real_get_height (GtkWidget *widget,
580 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
582 gint *minimum_height,
583 gint *natural_height);
584 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
587 gint *natural_width);
588 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
589 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
590 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
591 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
592 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
593 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
594 cairo_region_t *region);
595 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
596 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
597 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
600 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
601 gboolean has_tooltip,
603 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
604 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
606 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
607 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
609 const gchar *childname);
610 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
613 const GValue *value);
614 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
617 const gchar *tagname,
618 GMarkupParser *parser,
620 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
623 const gchar *tagname,
625 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
626 GtkBuilder *builder);
628 static void gtk_widget_real_get_width (GtkWidget *widget,
631 static void gtk_widget_real_get_height (GtkWidget *widget,
635 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
638 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
639 GtkOrientation orientation,
642 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
643 GtkOrientation orientation,
647 gint *allocated_size);
649 static void gtk_widget_set_usize_internal (GtkWidget *widget,
652 GtkQueueResizeFlags flags);
654 static void gtk_widget_add_events_internal (GtkWidget *widget,
658 /* --- variables --- */
659 static gpointer gtk_widget_parent_class = NULL;
660 static guint widget_signals[LAST_SIGNAL] = { 0 };
661 static GtkStyle *gtk_default_style = NULL;
662 static guint composite_child_stack = 0;
663 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
664 static GParamSpecPool *style_property_spec_pool = NULL;
666 static GQuark quark_property_parser = 0;
667 static GQuark quark_aux_info = 0;
668 static GQuark quark_accel_path = 0;
669 static GQuark quark_accel_closures = 0;
670 static GQuark quark_event_mask = 0;
671 static GQuark quark_device_event_mask = 0;
672 static GQuark quark_extension_event_mode = 0;
673 static GQuark quark_parent_window = 0;
674 static GQuark quark_pointer_window = 0;
675 static GQuark quark_shape_info = 0;
676 static GQuark quark_input_shape_info = 0;
677 static GQuark quark_pango_context = 0;
678 static GQuark quark_rc_style = 0;
679 static GQuark quark_accessible_object = 0;
680 static GQuark quark_mnemonic_labels = 0;
681 static GQuark quark_tooltip_markup = 0;
682 static GQuark quark_has_tooltip = 0;
683 static GQuark quark_tooltip_window = 0;
684 static GQuark quark_visual = 0;
685 static GQuark quark_modifier_style = 0;
686 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
687 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
689 /* --- functions --- */
691 gtk_widget_get_type (void)
693 static GType widget_type = 0;
695 if (G_UNLIKELY (widget_type == 0))
697 const GTypeInfo widget_info =
699 sizeof (GtkWidgetClass),
700 NULL, /* base_init */
701 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
702 (GClassInitFunc) gtk_widget_class_init,
703 NULL, /* class_finalize */
704 NULL, /* class_init */
707 (GInstanceInitFunc) gtk_widget_init,
708 NULL, /* value_table */
711 const GInterfaceInfo accessibility_info =
713 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
714 (GInterfaceFinalizeFunc) NULL,
715 NULL /* interface data */
718 const GInterfaceInfo buildable_info =
720 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
721 (GInterfaceFinalizeFunc) NULL,
722 NULL /* interface data */
725 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
726 &widget_info, G_TYPE_FLAG_ABSTRACT);
728 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
729 &accessibility_info) ;
730 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
738 child_property_notify_dispatcher (GObject *object,
742 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
745 /* We guard against the draw signal callbacks modifying the state of the
746 * cairo context by surounding it with save/restore.
747 * Maybe we should also cairo_new_path() just to be sure?
750 gtk_widget_draw_marshaller (GClosure *closure,
751 GValue *return_value,
752 guint n_param_values,
753 const GValue *param_values,
754 gpointer invocation_hint,
755 gpointer marshal_data)
757 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
761 _gtk_marshal_BOOLEAN__BOXED (closure,
772 gtk_widget_class_init (GtkWidgetClass *klass)
774 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
775 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
776 GtkBindingSet *binding_set;
778 gtk_widget_parent_class = g_type_class_peek_parent (klass);
780 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
781 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
782 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
783 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
784 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
785 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
786 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
787 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
788 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
789 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
790 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
791 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
792 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
793 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
794 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
795 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
796 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
797 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
798 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
799 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
801 style_property_spec_pool = g_param_spec_pool_new (FALSE);
802 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
803 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
804 cpn_context.dispatcher = child_property_notify_dispatcher;
805 _gtk_widget_child_property_notify_context = &cpn_context;
807 gobject_class->dispose = gtk_widget_dispose;
808 gobject_class->finalize = gtk_widget_finalize;
809 gobject_class->set_property = gtk_widget_set_property;
810 gobject_class->get_property = gtk_widget_get_property;
812 klass->destroy = gtk_widget_real_destroy;
814 klass->activate_signal = 0;
815 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
816 klass->show = gtk_widget_real_show;
817 klass->show_all = gtk_widget_show;
818 klass->hide = gtk_widget_real_hide;
819 klass->map = gtk_widget_real_map;
820 klass->unmap = gtk_widget_real_unmap;
821 klass->realize = gtk_widget_real_realize;
822 klass->unrealize = gtk_widget_real_unrealize;
823 klass->size_allocate = gtk_widget_real_size_allocate;
824 klass->get_preferred_width = gtk_widget_real_get_width;
825 klass->get_preferred_height = gtk_widget_real_get_height;
826 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
827 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
828 klass->state_changed = NULL;
829 klass->parent_set = NULL;
830 klass->hierarchy_changed = NULL;
831 klass->style_set = gtk_widget_real_style_set;
832 klass->direction_changed = gtk_widget_real_direction_changed;
833 klass->grab_notify = NULL;
834 klass->child_notify = NULL;
836 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
837 klass->grab_focus = gtk_widget_real_grab_focus;
838 klass->focus = gtk_widget_real_focus;
839 klass->move_focus = gtk_widget_real_move_focus;
840 klass->keynav_failed = gtk_widget_real_keynav_failed;
842 klass->button_press_event = NULL;
843 klass->button_release_event = NULL;
844 klass->motion_notify_event = NULL;
845 klass->delete_event = NULL;
846 klass->destroy_event = NULL;
847 klass->key_press_event = gtk_widget_real_key_press_event;
848 klass->key_release_event = gtk_widget_real_key_release_event;
849 klass->enter_notify_event = NULL;
850 klass->leave_notify_event = NULL;
851 klass->configure_event = NULL;
852 klass->focus_in_event = gtk_widget_real_focus_in_event;
853 klass->focus_out_event = gtk_widget_real_focus_out_event;
854 klass->map_event = NULL;
855 klass->unmap_event = NULL;
856 klass->window_state_event = NULL;
857 klass->property_notify_event = _gtk_selection_property_notify;
858 klass->selection_clear_event = _gtk_selection_clear;
859 klass->selection_request_event = _gtk_selection_request;
860 klass->selection_notify_event = _gtk_selection_notify;
861 klass->selection_received = NULL;
862 klass->proximity_in_event = NULL;
863 klass->proximity_out_event = NULL;
864 klass->drag_begin = NULL;
865 klass->drag_end = NULL;
866 klass->drag_data_delete = NULL;
867 klass->drag_leave = NULL;
868 klass->drag_motion = NULL;
869 klass->drag_drop = NULL;
870 klass->drag_data_received = NULL;
871 klass->screen_changed = NULL;
872 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
873 klass->grab_broken_event = NULL;
874 klass->query_tooltip = gtk_widget_real_query_tooltip;
875 klass->style_updated = gtk_widget_real_style_updated;
877 klass->show_help = gtk_widget_real_show_help;
879 /* Accessibility support */
880 klass->get_accessible = gtk_widget_real_get_accessible;
882 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
883 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
885 g_object_class_install_property (gobject_class,
887 g_param_spec_string ("name",
889 P_("The name of the widget"),
891 GTK_PARAM_READWRITE));
892 g_object_class_install_property (gobject_class,
894 g_param_spec_object ("parent",
896 P_("The parent widget of this widget. Must be a Container widget"),
898 GTK_PARAM_READWRITE));
900 g_object_class_install_property (gobject_class,
902 g_param_spec_int ("width-request",
904 P_("Override for width 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_int ("height-request",
912 P_("Height request"),
913 P_("Override for height request of the widget, or -1 if natural request should be used"),
917 GTK_PARAM_READWRITE));
918 g_object_class_install_property (gobject_class,
920 g_param_spec_boolean ("visible",
922 P_("Whether the widget is visible"),
924 GTK_PARAM_READWRITE));
925 g_object_class_install_property (gobject_class,
927 g_param_spec_boolean ("sensitive",
929 P_("Whether the widget responds to input"),
931 GTK_PARAM_READWRITE));
932 g_object_class_install_property (gobject_class,
934 g_param_spec_boolean ("app-paintable",
935 P_("Application paintable"),
936 P_("Whether the application will paint directly on the widget"),
938 GTK_PARAM_READWRITE));
939 g_object_class_install_property (gobject_class,
941 g_param_spec_boolean ("can-focus",
943 P_("Whether the widget can accept the input focus"),
945 GTK_PARAM_READWRITE));
946 g_object_class_install_property (gobject_class,
948 g_param_spec_boolean ("has-focus",
950 P_("Whether the widget has the input focus"),
952 GTK_PARAM_READWRITE));
953 g_object_class_install_property (gobject_class,
955 g_param_spec_boolean ("is-focus",
957 P_("Whether the widget is the focus widget within the toplevel"),
959 GTK_PARAM_READWRITE));
960 g_object_class_install_property (gobject_class,
962 g_param_spec_boolean ("can-default",
964 P_("Whether the widget can be the default widget"),
966 GTK_PARAM_READWRITE));
967 g_object_class_install_property (gobject_class,
969 g_param_spec_boolean ("has-default",
971 P_("Whether the widget is the default widget"),
973 GTK_PARAM_READWRITE));
974 g_object_class_install_property (gobject_class,
975 PROP_RECEIVES_DEFAULT,
976 g_param_spec_boolean ("receives-default",
977 P_("Receives default"),
978 P_("If TRUE, the widget will receive the default action when it is focused"),
980 GTK_PARAM_READWRITE));
981 g_object_class_install_property (gobject_class,
982 PROP_COMPOSITE_CHILD,
983 g_param_spec_boolean ("composite-child",
984 P_("Composite child"),
985 P_("Whether the widget is part of a composite widget"),
987 GTK_PARAM_READABLE));
988 g_object_class_install_property (gobject_class,
990 g_param_spec_object ("style",
992 P_("The style of the widget, which contains information about how it will look (colors etc)"),
994 GTK_PARAM_READWRITE));
995 g_object_class_install_property (gobject_class,
997 g_param_spec_flags ("events",
999 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1000 GDK_TYPE_EVENT_MASK,
1002 GTK_PARAM_READWRITE));
1003 g_object_class_install_property (gobject_class,
1004 PROP_EXTENSION_EVENTS,
1005 g_param_spec_enum ("extension-events",
1006 P_("Extension events"),
1007 P_("The mask that decides what kind of extension events this widget gets"),
1008 GDK_TYPE_EXTENSION_MODE,
1009 GDK_EXTENSION_EVENTS_NONE,
1010 GTK_PARAM_READWRITE));
1011 g_object_class_install_property (gobject_class,
1013 g_param_spec_boolean ("no-show-all",
1015 P_("Whether gtk_widget_show_all() should not affect this widget"),
1017 GTK_PARAM_READWRITE));
1020 * GtkWidget:has-tooltip:
1022 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1023 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1024 * the widget will be queried using #GtkWidget::query-tooltip to determine
1025 * whether it will provide a tooltip or not.
1027 * Note that setting this property to %TRUE for the first time will change
1028 * the event masks of the GdkWindows of this widget to include leave-notify
1029 * and motion-notify events. This cannot and will not be undone when the
1030 * property is set to %FALSE again.
1034 g_object_class_install_property (gobject_class,
1036 g_param_spec_boolean ("has-tooltip",
1038 P_("Whether this widget has a tooltip"),
1040 GTK_PARAM_READWRITE));
1042 * GtkWidget:tooltip-text:
1044 * Sets the text of tooltip to be the given string.
1046 * Also see gtk_tooltip_set_text().
1048 * This is a convenience property which will take care of getting the
1049 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1050 * will automatically be set to %TRUE and there will be taken care of
1051 * #GtkWidget::query-tooltip in the default signal handler.
1055 g_object_class_install_property (gobject_class,
1057 g_param_spec_string ("tooltip-text",
1059 P_("The contents of the tooltip for this widget"),
1061 GTK_PARAM_READWRITE));
1063 * GtkWidget:tooltip-markup:
1065 * Sets the text of tooltip to be the given string, which is marked up
1066 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1067 * Also see gtk_tooltip_set_markup().
1069 * This is a convenience property which will take care of getting the
1070 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1071 * will automatically be set to %TRUE and there will be taken care of
1072 * #GtkWidget::query-tooltip in the default signal handler.
1076 g_object_class_install_property (gobject_class,
1077 PROP_TOOLTIP_MARKUP,
1078 g_param_spec_string ("tooltip-markup",
1079 P_("Tooltip markup"),
1080 P_("The contents of the tooltip for this widget"),
1082 GTK_PARAM_READWRITE));
1087 * The widget's window if it is realized, %NULL otherwise.
1091 g_object_class_install_property (gobject_class,
1093 g_param_spec_object ("window",
1095 P_("The widget's window if it is realized"),
1097 GTK_PARAM_READABLE));
1100 * GtkWidget:double-buffered
1102 * Whether the widget is double buffered.
1106 g_object_class_install_property (gobject_class,
1107 PROP_DOUBLE_BUFFERED,
1108 g_param_spec_boolean ("double-buffered",
1109 P_("Double Buffered"),
1110 P_("Whether the widget is double buffered"),
1112 GTK_PARAM_READWRITE));
1117 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1121 g_object_class_install_property (gobject_class,
1123 g_param_spec_enum ("halign",
1124 P_("Horizontal Alignment"),
1125 P_("How to position in extra horizontal space"),
1128 GTK_PARAM_READWRITE));
1133 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1137 g_object_class_install_property (gobject_class,
1139 g_param_spec_enum ("valign",
1140 P_("Vertical Alignment"),
1141 P_("How to position in extra vertical space"),
1144 GTK_PARAM_READWRITE));
1147 * GtkWidget:margin-left
1149 * Margin on left side of widget.
1151 * This property adds margin outside of the widget's normal size
1152 * request, the margin will be added in addition to the size from
1153 * gtk_widget_set_size_request() for example.
1157 g_object_class_install_property (gobject_class,
1159 g_param_spec_int ("margin-left",
1160 P_("Margin on Left"),
1161 P_("Pixels of extra space on the left side"),
1165 GTK_PARAM_READWRITE));
1168 * GtkWidget:margin-right
1170 * Margin on right side of widget.
1172 * This property adds margin outside of the widget's normal size
1173 * request, the margin will be added in addition to the size from
1174 * gtk_widget_set_size_request() for example.
1178 g_object_class_install_property (gobject_class,
1180 g_param_spec_int ("margin-right",
1181 P_("Margin on Right"),
1182 P_("Pixels of extra space on the right side"),
1186 GTK_PARAM_READWRITE));
1189 * GtkWidget:margin-top
1191 * Margin on top side of widget.
1193 * This property adds margin outside of the widget's normal size
1194 * request, the margin will be added in addition to the size from
1195 * gtk_widget_set_size_request() for example.
1199 g_object_class_install_property (gobject_class,
1201 g_param_spec_int ("margin-top",
1202 P_("Margin on Top"),
1203 P_("Pixels of extra space on the top side"),
1207 GTK_PARAM_READWRITE));
1210 * GtkWidget:margin-bottom
1212 * Margin on bottom side of widget.
1214 * This property adds margin outside of the widget's normal size
1215 * request, the margin will be added in addition to the size from
1216 * gtk_widget_set_size_request() for example.
1220 g_object_class_install_property (gobject_class,
1222 g_param_spec_int ("margin-bottom",
1223 P_("Margin on Bottom"),
1224 P_("Pixels of extra space on the bottom side"),
1228 GTK_PARAM_READWRITE));
1233 * Sets all four sides' margin at once. If read, returns max
1234 * margin on any side.
1238 g_object_class_install_property (gobject_class,
1240 g_param_spec_int ("margin",
1242 P_("Pixels of extra space on all four sides"),
1246 GTK_PARAM_READWRITE));
1249 * GtkWidget::destroy:
1250 * @object: the object which received the signal
1252 * Signals that all holders of a reference to the widget should release
1253 * the reference that they hold. May result in finalization of the widget
1254 * if all references are released.
1256 widget_signals[DESTROY] =
1257 g_signal_new (I_("destroy"),
1258 G_TYPE_FROM_CLASS (gobject_class),
1259 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1260 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1262 _gtk_marshal_VOID__VOID,
1268 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1272 g_object_class_install_property (gobject_class,
1274 g_param_spec_boolean ("hexpand",
1275 P_("Horizontal Expand"),
1276 P_("Whether widget wants more horizontal space"),
1278 GTK_PARAM_READWRITE));
1281 * GtkWidget:hexpand-set
1283 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1287 g_object_class_install_property (gobject_class,
1289 g_param_spec_boolean ("hexpand-set",
1290 P_("Horizontal Expand Set"),
1291 P_("Whether to use the hexpand property"),
1293 GTK_PARAM_READWRITE));
1298 * Whether to expand vertically. See gtk_widget_set_vexpand().
1302 g_object_class_install_property (gobject_class,
1304 g_param_spec_boolean ("vexpand",
1305 P_("Vertical Expand"),
1306 P_("Whether widget wants more vertical space"),
1308 GTK_PARAM_READWRITE));
1311 * GtkWidget:vexpand-set
1313 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1317 g_object_class_install_property (gobject_class,
1319 g_param_spec_boolean ("vexpand-set",
1320 P_("Vertical Expand Set"),
1321 P_("Whether to use the vexpand property"),
1323 GTK_PARAM_READWRITE));
1328 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1332 g_object_class_install_property (gobject_class,
1334 g_param_spec_boolean ("expand",
1336 P_("Whether widget wants to expand in both directions"),
1338 GTK_PARAM_READWRITE));
1342 * @widget: the object which received the signal.
1344 widget_signals[SHOW] =
1345 g_signal_new (I_("show"),
1346 G_TYPE_FROM_CLASS (gobject_class),
1348 G_STRUCT_OFFSET (GtkWidgetClass, show),
1350 _gtk_marshal_VOID__VOID,
1355 * @widget: the object which received the signal.
1357 widget_signals[HIDE] =
1358 g_signal_new (I_("hide"),
1359 G_TYPE_FROM_CLASS (gobject_class),
1361 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1363 _gtk_marshal_VOID__VOID,
1368 * @widget: the object which received the signal.
1370 widget_signals[MAP] =
1371 g_signal_new (I_("map"),
1372 G_TYPE_FROM_CLASS (gobject_class),
1374 G_STRUCT_OFFSET (GtkWidgetClass, map),
1376 _gtk_marshal_VOID__VOID,
1381 * @widget: the object which received the signal.
1383 widget_signals[UNMAP] =
1384 g_signal_new (I_("unmap"),
1385 G_TYPE_FROM_CLASS (gobject_class),
1387 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1389 _gtk_marshal_VOID__VOID,
1393 * GtkWidget::realize:
1394 * @widget: the object which received the signal.
1396 widget_signals[REALIZE] =
1397 g_signal_new (I_("realize"),
1398 G_TYPE_FROM_CLASS (gobject_class),
1400 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1402 _gtk_marshal_VOID__VOID,
1406 * GtkWidget::unrealize:
1407 * @widget: the object which received the signal.
1409 widget_signals[UNREALIZE] =
1410 g_signal_new (I_("unrealize"),
1411 G_TYPE_FROM_CLASS (gobject_class),
1413 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1415 _gtk_marshal_VOID__VOID,
1419 * GtkWidget::size-allocate:
1420 * @widget: the object which received the signal.
1423 widget_signals[SIZE_ALLOCATE] =
1424 g_signal_new (I_("size-allocate"),
1425 G_TYPE_FROM_CLASS (gobject_class),
1427 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1429 _gtk_marshal_VOID__BOXED,
1431 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1434 * GtkWidget::state-changed:
1435 * @widget: the object which received the signal.
1436 * @state: the previous state
1438 * The ::state-changed signal is emitted when the widget state changes.
1439 * See gtk_widget_get_state().
1441 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1443 widget_signals[STATE_CHANGED] =
1444 g_signal_new (I_("state-changed"),
1445 G_TYPE_FROM_CLASS (gobject_class),
1447 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1449 _gtk_marshal_VOID__ENUM,
1451 GTK_TYPE_STATE_TYPE);
1454 * GtkWidget::state-flags-changed:
1455 * @widget: the object which received the signal.
1456 * @flags: The previous state flags.
1458 * The ::state-flags-changed signal is emitted when the widget state
1459 * changes, see gtk_widget_get_state_flags().
1463 widget_signals[STATE_FLAGS_CHANGED] =
1464 g_signal_new (I_("state-flags-changed"),
1465 G_TYPE_FROM_CLASS (gobject_class),
1467 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1469 _gtk_marshal_VOID__FLAGS,
1471 GTK_TYPE_STATE_FLAGS);
1474 * GtkWidget::parent-set:
1475 * @widget: the object on which the signal is emitted
1476 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1477 * just got its initial parent.
1479 * The ::parent-set signal is emitted when a new parent
1480 * has been set on a widget.
1482 widget_signals[PARENT_SET] =
1483 g_signal_new (I_("parent-set"),
1484 G_TYPE_FROM_CLASS (gobject_class),
1486 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1488 _gtk_marshal_VOID__OBJECT,
1493 * GtkWidget::hierarchy-changed:
1494 * @widget: the object on which the signal is emitted
1495 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1496 * if the widget was previously unanchored
1498 * The ::hierarchy-changed signal is emitted when the
1499 * anchored state of a widget changes. A widget is
1500 * <firstterm>anchored</firstterm> when its toplevel
1501 * ancestor is a #GtkWindow. This signal is emitted when
1502 * a widget changes from un-anchored to anchored or vice-versa.
1504 widget_signals[HIERARCHY_CHANGED] =
1505 g_signal_new (I_("hierarchy-changed"),
1506 G_TYPE_FROM_CLASS (gobject_class),
1508 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1510 _gtk_marshal_VOID__OBJECT,
1515 * GtkWidget::style-set:
1516 * @widget: the object on which the signal is emitted
1517 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1518 * just got its initial style
1520 * The ::style-set signal is emitted when a new style has been set
1521 * on a widget. Note that style-modifying functions like
1522 * gtk_widget_modify_base() also cause this signal to be emitted.
1524 widget_signals[STYLE_SET] =
1525 g_signal_new (I_("style-set"),
1526 G_TYPE_FROM_CLASS (gobject_class),
1528 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1530 _gtk_marshal_VOID__OBJECT,
1534 widget_signals[STYLE_UPDATED] =
1535 g_signal_new (I_("style-updated"),
1536 G_TYPE_FROM_CLASS (gobject_class),
1538 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1540 g_cclosure_marshal_VOID__VOID,
1544 * GtkWidget::direction-changed:
1545 * @widget: the object on which the signal is emitted
1546 * @previous_direction: the previous text direction of @widget
1548 * The ::direction-changed signal is emitted when the text direction
1549 * of a widget changes.
1551 widget_signals[DIRECTION_CHANGED] =
1552 g_signal_new (I_("direction-changed"),
1553 G_TYPE_FROM_CLASS (gobject_class),
1555 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1557 _gtk_marshal_VOID__ENUM,
1559 GTK_TYPE_TEXT_DIRECTION);
1562 * GtkWidget::grab-notify:
1563 * @widget: the object which received the signal
1564 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1565 * if it becomes unshadowed
1567 * The ::grab-notify signal is emitted when a widget becomes
1568 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1569 * another widget, or when it becomes unshadowed due to a grab
1572 * A widget is shadowed by a gtk_grab_add() when the topmost
1573 * grab widget in the grab stack of its window group is not
1576 widget_signals[GRAB_NOTIFY] =
1577 g_signal_new (I_("grab-notify"),
1578 G_TYPE_FROM_CLASS (gobject_class),
1580 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1582 _gtk_marshal_VOID__BOOLEAN,
1587 * GtkWidget::child-notify:
1588 * @widget: the object which received the signal
1589 * @pspec: the #GParamSpec of the changed child property
1591 * The ::child-notify signal is emitted for each
1592 * <link linkend="child-properties">child property</link> that has
1593 * changed on an object. The signal's detail holds the property name.
1595 widget_signals[CHILD_NOTIFY] =
1596 g_signal_new (I_("child-notify"),
1597 G_TYPE_FROM_CLASS (gobject_class),
1598 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1599 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1601 g_cclosure_marshal_VOID__PARAM,
1607 * @widget: the object which received the signal
1608 * @cr: the cairo context to draw to
1610 * This signal is emitted when a widget is supposed to render itself.
1611 * The @widget's top left corner must be painted at the origin of
1612 * the passed in context and be sized to the values returned by
1613 * gtk_widget_get_allocated_width() and
1614 * gtk_widget_get_allocated_height().
1616 * Signal handlers connected to this signal can modify the cairo
1617 * context passed as @cr in any way they like and don't need to
1618 * restore it. The signal emission takes care of calling cairo_save()
1619 * before and cairo_restore() after invoking the handler.
1621 widget_signals[DRAW] =
1622 g_signal_new (I_("draw"),
1623 G_TYPE_FROM_CLASS (gobject_class),
1625 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1626 _gtk_boolean_handled_accumulator, NULL,
1627 gtk_widget_draw_marshaller,
1629 CAIRO_GOBJECT_TYPE_CONTEXT);
1632 * GtkWidget::mnemonic-activate:
1633 * @widget: the object which received the signal.
1636 widget_signals[MNEMONIC_ACTIVATE] =
1637 g_signal_new (I_("mnemonic-activate"),
1638 G_TYPE_FROM_CLASS (gobject_class),
1640 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1641 _gtk_boolean_handled_accumulator, NULL,
1642 _gtk_marshal_BOOLEAN__BOOLEAN,
1647 * GtkWidget::grab-focus:
1648 * @widget: the object which received the signal.
1650 widget_signals[GRAB_FOCUS] =
1651 g_signal_new (I_("grab-focus"),
1652 G_TYPE_FROM_CLASS (gobject_class),
1653 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1654 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1656 _gtk_marshal_VOID__VOID,
1661 * @widget: the object which received the signal.
1664 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1666 widget_signals[FOCUS] =
1667 g_signal_new (I_("focus"),
1668 G_TYPE_FROM_CLASS (klass),
1670 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1671 _gtk_boolean_handled_accumulator, NULL,
1672 _gtk_marshal_BOOLEAN__ENUM,
1674 GTK_TYPE_DIRECTION_TYPE);
1677 * GtkWidget::move-focus:
1678 * @widget: the object which received the signal.
1681 widget_signals[MOVE_FOCUS] =
1682 g_signal_new (I_("move-focus"),
1683 G_TYPE_FROM_CLASS (klass),
1684 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1685 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1687 _gtk_marshal_VOID__ENUM,
1690 GTK_TYPE_DIRECTION_TYPE);
1693 * GtkWidget::keynav-failed:
1694 * @widget: the object which received the signal
1695 * @direction: the direction of movement
1697 * Gets emitted if keyboard navigation fails.
1698 * See gtk_widget_keynav_failed() for details.
1700 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1701 * if the emitting widget should try to handle the keyboard
1702 * navigation attempt in its parent container(s).
1706 widget_signals[KEYNAV_FAILED] =
1707 g_signal_new (I_("keynav-failed"),
1708 G_TYPE_FROM_CLASS (klass),
1710 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1711 _gtk_boolean_handled_accumulator, NULL,
1712 _gtk_marshal_BOOLEAN__ENUM,
1714 GTK_TYPE_DIRECTION_TYPE);
1718 * @widget: the object which received the signal.
1719 * @event: the #GdkEvent which triggered this signal
1721 * The GTK+ main loop will emit three signals for each GDK event delivered
1722 * to a widget: one generic ::event signal, another, more specific,
1723 * signal that matches the type of event delivered (e.g.
1724 * #GtkWidget::key-press-event) and finally a generic
1725 * #GtkWidget::event-after signal.
1727 * Returns: %TRUE to stop other handlers from being invoked for the event
1728 * and to cancel the emission of the second specific ::event signal.
1729 * %FALSE to propagate the event further and to allow the emission of
1730 * the second signal. The ::event-after signal is emitted regardless of
1733 widget_signals[EVENT] =
1734 g_signal_new (I_("event"),
1735 G_TYPE_FROM_CLASS (klass),
1737 G_STRUCT_OFFSET (GtkWidgetClass, event),
1738 _gtk_boolean_handled_accumulator, NULL,
1739 _gtk_marshal_BOOLEAN__BOXED,
1741 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1744 * GtkWidget::event-after:
1745 * @widget: the object which received the signal.
1746 * @event: the #GdkEvent which triggered this signal
1748 * After the emission of the #GtkWidget::event signal and (optionally)
1749 * the second more specific signal, ::event-after will be emitted
1750 * regardless of the previous two signals handlers return values.
1753 widget_signals[EVENT_AFTER] =
1754 g_signal_new (I_("event-after"),
1755 G_TYPE_FROM_CLASS (klass),
1759 _gtk_marshal_VOID__BOXED,
1761 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1764 * GtkWidget::button-press-event:
1765 * @widget: the object which received the signal.
1766 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1769 * The ::button-press-event signal will be emitted when a button
1770 * (typically from a mouse) is pressed.
1772 * To receive this signal, the #GdkWindow associated to the
1773 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1775 * This signal will be sent to the grab widget if there is one.
1777 * Returns: %TRUE to stop other handlers from being invoked for the event.
1778 * %FALSE to propagate the event further.
1780 widget_signals[BUTTON_PRESS_EVENT] =
1781 g_signal_new (I_("button-press-event"),
1782 G_TYPE_FROM_CLASS (klass),
1784 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1785 _gtk_boolean_handled_accumulator, NULL,
1786 _gtk_marshal_BOOLEAN__BOXED,
1788 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1791 * GtkWidget::button-release-event:
1792 * @widget: the object which received the signal.
1793 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1796 * The ::button-release-event signal will be emitted when a button
1797 * (typically from a mouse) is released.
1799 * To receive this signal, the #GdkWindow associated to the
1800 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1802 * This signal will be sent to the grab widget if there is one.
1804 * Returns: %TRUE to stop other handlers from being invoked for the event.
1805 * %FALSE to propagate the event further.
1807 widget_signals[BUTTON_RELEASE_EVENT] =
1808 g_signal_new (I_("button-release-event"),
1809 G_TYPE_FROM_CLASS (klass),
1811 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1812 _gtk_boolean_handled_accumulator, NULL,
1813 _gtk_marshal_BOOLEAN__BOXED,
1815 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1818 * GtkWidget::scroll-event:
1819 * @widget: the object which received the signal.
1820 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1823 * The ::scroll-event signal is emitted when a button in the 4 to 7
1824 * range is pressed. Wheel mice are usually configured to generate
1825 * button press events for buttons 4 and 5 when the wheel is turned.
1827 * To receive this signal, the #GdkWindow associated to the widget needs
1828 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1830 * This signal will be sent to the grab widget if there is one.
1832 * Returns: %TRUE to stop other handlers from being invoked for the event.
1833 * %FALSE to propagate the event further.
1835 widget_signals[SCROLL_EVENT] =
1836 g_signal_new (I_("scroll-event"),
1837 G_TYPE_FROM_CLASS (klass),
1839 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1840 _gtk_boolean_handled_accumulator, NULL,
1841 _gtk_marshal_BOOLEAN__BOXED,
1843 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1846 * GtkWidget::motion-notify-event:
1847 * @widget: the object which received the signal.
1848 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1851 * The ::motion-notify-event signal is emitted when the pointer moves
1852 * over the widget's #GdkWindow.
1854 * To receive this signal, the #GdkWindow associated to the widget
1855 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1857 * This signal will be sent to the grab widget if there is one.
1859 * Returns: %TRUE to stop other handlers from being invoked for the event.
1860 * %FALSE to propagate the event further.
1862 widget_signals[MOTION_NOTIFY_EVENT] =
1863 g_signal_new (I_("motion-notify-event"),
1864 G_TYPE_FROM_CLASS (klass),
1866 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1867 _gtk_boolean_handled_accumulator, NULL,
1868 _gtk_marshal_BOOLEAN__BOXED,
1870 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1873 * GtkWidget::composited-changed:
1874 * @widget: the object on which the signal is emitted
1876 * The ::composited-changed signal is emitted when the composited
1877 * status of @widget<!-- -->s screen changes.
1878 * See gdk_screen_is_composited().
1880 widget_signals[COMPOSITED_CHANGED] =
1881 g_signal_new (I_("composited-changed"),
1882 G_TYPE_FROM_CLASS (klass),
1883 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1884 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1886 _gtk_marshal_VOID__VOID,
1890 * GtkWidget::delete-event:
1891 * @widget: the object which received the signal
1892 * @event: the event which triggered this signal
1894 * The ::delete-event signal is emitted if a user requests that
1895 * a toplevel window is closed. The default handler for this signal
1896 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1897 * this signal will cause the window to be hidden instead, so that
1898 * it can later be shown again without reconstructing it.
1900 * Returns: %TRUE to stop other handlers from being invoked for the event.
1901 * %FALSE to propagate the event further.
1903 widget_signals[DELETE_EVENT] =
1904 g_signal_new (I_("delete-event"),
1905 G_TYPE_FROM_CLASS (klass),
1907 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1908 _gtk_boolean_handled_accumulator, NULL,
1909 _gtk_marshal_BOOLEAN__BOXED,
1911 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1914 * GtkWidget::destroy-event:
1915 * @widget: the object which received the signal.
1916 * @event: the event which triggered this signal
1918 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1919 * You rarely get this signal, because most widgets disconnect themselves
1920 * from their window before they destroy it, so no widget owns the
1921 * window at destroy time.
1923 * To receive this signal, the #GdkWindow associated to the widget needs
1924 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1925 * automatically for all new windows.
1927 * Returns: %TRUE to stop other handlers from being invoked for the event.
1928 * %FALSE to propagate the event further.
1930 widget_signals[DESTROY_EVENT] =
1931 g_signal_new (I_("destroy-event"),
1932 G_TYPE_FROM_CLASS (klass),
1934 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1935 _gtk_boolean_handled_accumulator, NULL,
1936 _gtk_marshal_BOOLEAN__BOXED,
1938 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1941 * GtkWidget::key-press-event:
1942 * @widget: the object which received the signal
1943 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1945 * The ::key-press-event signal is emitted when a key is pressed.
1947 * To receive this signal, the #GdkWindow associated to the widget needs
1948 * to enable the #GDK_KEY_PRESS_MASK mask.
1950 * This signal will be sent to the grab widget if there is one.
1952 * Returns: %TRUE to stop other handlers from being invoked for the event.
1953 * %FALSE to propagate the event further.
1955 widget_signals[KEY_PRESS_EVENT] =
1956 g_signal_new (I_("key-press-event"),
1957 G_TYPE_FROM_CLASS (klass),
1959 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1960 _gtk_boolean_handled_accumulator, NULL,
1961 _gtk_marshal_BOOLEAN__BOXED,
1963 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1966 * GtkWidget::key-release-event:
1967 * @widget: the object which received the signal
1968 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1970 * The ::key-release-event signal is emitted when a key is pressed.
1972 * To receive this signal, the #GdkWindow associated to the widget needs
1973 * to enable the #GDK_KEY_RELEASE_MASK mask.
1975 * This signal will be sent to the grab widget if there is one.
1977 * Returns: %TRUE to stop other handlers from being invoked for the event.
1978 * %FALSE to propagate the event further.
1980 widget_signals[KEY_RELEASE_EVENT] =
1981 g_signal_new (I_("key-release-event"),
1982 G_TYPE_FROM_CLASS (klass),
1984 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1985 _gtk_boolean_handled_accumulator, NULL,
1986 _gtk_marshal_BOOLEAN__BOXED,
1988 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1991 * GtkWidget::enter-notify-event:
1992 * @widget: the object which received the signal
1993 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1996 * The ::enter-notify-event will be emitted when the pointer enters
1997 * the @widget's window.
1999 * To receive this signal, the #GdkWindow associated to the widget needs
2000 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2002 * This signal will be sent to the grab widget if there is one.
2004 * Returns: %TRUE to stop other handlers from being invoked for the event.
2005 * %FALSE to propagate the event further.
2007 widget_signals[ENTER_NOTIFY_EVENT] =
2008 g_signal_new (I_("enter-notify-event"),
2009 G_TYPE_FROM_CLASS (klass),
2011 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2012 _gtk_boolean_handled_accumulator, NULL,
2013 _gtk_marshal_BOOLEAN__BOXED,
2015 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2018 * GtkWidget::leave-notify-event:
2019 * @widget: the object which received the signal
2020 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2023 * The ::leave-notify-event will be emitted when the pointer leaves
2024 * the @widget's window.
2026 * To receive this signal, the #GdkWindow associated to the widget needs
2027 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2029 * This signal will be sent to the grab widget if there is one.
2031 * Returns: %TRUE to stop other handlers from being invoked for the event.
2032 * %FALSE to propagate the event further.
2034 widget_signals[LEAVE_NOTIFY_EVENT] =
2035 g_signal_new (I_("leave-notify-event"),
2036 G_TYPE_FROM_CLASS (klass),
2038 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2039 _gtk_boolean_handled_accumulator, NULL,
2040 _gtk_marshal_BOOLEAN__BOXED,
2042 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2045 * GtkWidget::configure-event:
2046 * @widget: the object which received the signal
2047 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2050 * The ::configure-event signal will be emitted when the size, position or
2051 * stacking of the @widget's window has changed.
2053 * To receive this signal, the #GdkWindow associated to the widget needs
2054 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2055 * automatically for all new windows.
2057 * Returns: %TRUE to stop other handlers from being invoked for the event.
2058 * %FALSE to propagate the event further.
2060 widget_signals[CONFIGURE_EVENT] =
2061 g_signal_new (I_("configure-event"),
2062 G_TYPE_FROM_CLASS (klass),
2064 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2065 _gtk_boolean_handled_accumulator, NULL,
2066 _gtk_marshal_BOOLEAN__BOXED,
2068 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2071 * GtkWidget::focus-in-event:
2072 * @widget: the object which received the signal
2073 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2076 * The ::focus-in-event signal will be emitted when the keyboard focus
2077 * enters the @widget's window.
2079 * To receive this signal, the #GdkWindow associated to the widget needs
2080 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2082 * Returns: %TRUE to stop other handlers from being invoked for the event.
2083 * %FALSE to propagate the event further.
2085 widget_signals[FOCUS_IN_EVENT] =
2086 g_signal_new (I_("focus-in-event"),
2087 G_TYPE_FROM_CLASS (klass),
2089 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2090 _gtk_boolean_handled_accumulator, NULL,
2091 _gtk_marshal_BOOLEAN__BOXED,
2093 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2096 * GtkWidget::focus-out-event:
2097 * @widget: the object which received the signal
2098 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2101 * The ::focus-out-event signal will be emitted when the keyboard focus
2102 * leaves the @widget's window.
2104 * To receive this signal, the #GdkWindow associated to the widget needs
2105 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2107 * Returns: %TRUE to stop other handlers from being invoked for the event.
2108 * %FALSE to propagate the event further.
2110 widget_signals[FOCUS_OUT_EVENT] =
2111 g_signal_new (I_("focus-out-event"),
2112 G_TYPE_FROM_CLASS (klass),
2114 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2115 _gtk_boolean_handled_accumulator, NULL,
2116 _gtk_marshal_BOOLEAN__BOXED,
2118 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2121 * GtkWidget::map-event:
2122 * @widget: the object which received the signal
2123 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2125 * The ::map-event signal will be emitted when the @widget's window is
2126 * mapped. A window is mapped when it becomes visible on the screen.
2128 * To receive this signal, the #GdkWindow associated to the widget needs
2129 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2130 * automatically for all new windows.
2132 * Returns: %TRUE to stop other handlers from being invoked for the event.
2133 * %FALSE to propagate the event further.
2135 widget_signals[MAP_EVENT] =
2136 g_signal_new (I_("map-event"),
2137 G_TYPE_FROM_CLASS (klass),
2139 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2140 _gtk_boolean_handled_accumulator, NULL,
2141 _gtk_marshal_BOOLEAN__BOXED,
2143 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2146 * GtkWidget::unmap-event:
2147 * @widget: the object which received the signal
2148 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2150 * The ::unmap-event signal may be emitted when the @widget's window is
2151 * unmapped. A window is unmapped when it becomes invisible on the screen.
2153 * For performance reasons GTK+ may not emit ::unmap-event, so one
2154 * should always also implement ::unrealize in order to release
2155 * resources and disconnect signal handlers.
2157 * To receive this signal, the #GdkWindow associated to the widget needs
2158 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2159 * automatically for all new windows.
2161 * Returns: %TRUE to stop other handlers from being invoked for the event.
2162 * %FALSE to propagate the event further.
2164 widget_signals[UNMAP_EVENT] =
2165 g_signal_new (I_("unmap-event"),
2166 G_TYPE_FROM_CLASS (klass),
2168 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2169 _gtk_boolean_handled_accumulator, NULL,
2170 _gtk_marshal_BOOLEAN__BOXED,
2172 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2175 * GtkWidget::property-notify-event:
2176 * @widget: the object which received the signal
2177 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2180 * The ::property-notify-event signal will be emitted when a property on
2181 * the @widget's window has been changed or deleted.
2183 * To receive this signal, the #GdkWindow associated to the widget needs
2184 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2186 * Returns: %TRUE to stop other handlers from being invoked for the event.
2187 * %FALSE to propagate the event further.
2189 widget_signals[PROPERTY_NOTIFY_EVENT] =
2190 g_signal_new (I_("property-notify-event"),
2191 G_TYPE_FROM_CLASS (klass),
2193 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2194 _gtk_boolean_handled_accumulator, NULL,
2195 _gtk_marshal_BOOLEAN__BOXED,
2197 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2200 * GtkWidget::selection-clear-event:
2201 * @widget: the object which received the signal
2202 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2205 * The ::selection-clear-event signal will be emitted when the
2206 * the @widget's window has lost ownership of a selection.
2208 * Returns: %TRUE to stop other handlers from being invoked for the event.
2209 * %FALSE to propagate the event further.
2211 widget_signals[SELECTION_CLEAR_EVENT] =
2212 g_signal_new (I_("selection-clear-event"),
2213 G_TYPE_FROM_CLASS (klass),
2215 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2216 _gtk_boolean_handled_accumulator, NULL,
2217 _gtk_marshal_BOOLEAN__BOXED,
2219 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2222 * GtkWidget::selection-request-event:
2223 * @widget: the object which received the signal
2224 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2227 * The ::selection-request-event signal will be emitted when
2228 * another client requests ownership of the selection owned by
2229 * the @widget's window.
2231 * Returns: %TRUE to stop other handlers from being invoked for the event.
2232 * %FALSE to propagate the event further.
2234 widget_signals[SELECTION_REQUEST_EVENT] =
2235 g_signal_new (I_("selection-request-event"),
2236 G_TYPE_FROM_CLASS (klass),
2238 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2239 _gtk_boolean_handled_accumulator, NULL,
2240 _gtk_marshal_BOOLEAN__BOXED,
2242 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2245 * GtkWidget::selection-notify-event:
2246 * @widget: the object which received the signal.
2249 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2251 widget_signals[SELECTION_NOTIFY_EVENT] =
2252 g_signal_new (I_("selection-notify-event"),
2253 G_TYPE_FROM_CLASS (klass),
2255 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2256 _gtk_boolean_handled_accumulator, NULL,
2257 _gtk_marshal_BOOLEAN__BOXED,
2259 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2262 * GtkWidget::selection-received:
2263 * @widget: the object which received the signal.
2267 widget_signals[SELECTION_RECEIVED] =
2268 g_signal_new (I_("selection-received"),
2269 G_TYPE_FROM_CLASS (klass),
2271 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2273 _gtk_marshal_VOID__BOXED_UINT,
2275 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2279 * GtkWidget::selection-get:
2280 * @widget: the object which received the signal.
2285 widget_signals[SELECTION_GET] =
2286 g_signal_new (I_("selection-get"),
2287 G_TYPE_FROM_CLASS (klass),
2289 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2291 _gtk_marshal_VOID__BOXED_UINT_UINT,
2293 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2298 * GtkWidget::proximity-in-event:
2299 * @widget: the object which received the signal
2300 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2303 * To receive this signal the #GdkWindow associated to the widget needs
2304 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2306 * This signal will be sent to the grab widget if there is one.
2308 * Returns: %TRUE to stop other handlers from being invoked for the event.
2309 * %FALSE to propagate the event further.
2311 widget_signals[PROXIMITY_IN_EVENT] =
2312 g_signal_new (I_("proximity-in-event"),
2313 G_TYPE_FROM_CLASS (klass),
2315 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2316 _gtk_boolean_handled_accumulator, NULL,
2317 _gtk_marshal_BOOLEAN__BOXED,
2319 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2322 * GtkWidget::proximity-out-event:
2323 * @widget: the object which received the signal
2324 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2327 * To receive this signal the #GdkWindow associated to the widget needs
2328 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2330 * This signal will be sent to the grab widget if there is one.
2332 * Returns: %TRUE to stop other handlers from being invoked for the event.
2333 * %FALSE to propagate the event further.
2335 widget_signals[PROXIMITY_OUT_EVENT] =
2336 g_signal_new (I_("proximity-out-event"),
2337 G_TYPE_FROM_CLASS (klass),
2339 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2340 _gtk_boolean_handled_accumulator, NULL,
2341 _gtk_marshal_BOOLEAN__BOXED,
2343 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2346 * GtkWidget::drag-leave:
2347 * @widget: the object which received the signal.
2348 * @drag_context: the drag context
2349 * @time: the timestamp of the motion event
2351 * The ::drag-leave signal is emitted on the drop site when the cursor
2352 * leaves the widget. A typical reason to connect to this signal is to
2353 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2354 * with gtk_drag_unhighlight()
2356 widget_signals[DRAG_LEAVE] =
2357 g_signal_new (I_("drag-leave"),
2358 G_TYPE_FROM_CLASS (klass),
2360 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2362 _gtk_marshal_VOID__OBJECT_UINT,
2364 GDK_TYPE_DRAG_CONTEXT,
2368 * GtkWidget::drag-begin:
2369 * @widget: the object which received the signal
2370 * @drag_context: the drag context
2372 * The ::drag-begin signal is emitted on the drag source when a drag is
2373 * started. A typical reason to connect to this signal is to set up a
2374 * custom drag icon with gtk_drag_source_set_icon().
2376 * Note that some widgets set up a drag icon in the default handler of
2377 * this signal, so you may have to use g_signal_connect_after() to
2378 * override what the default handler did.
2380 widget_signals[DRAG_BEGIN] =
2381 g_signal_new (I_("drag-begin"),
2382 G_TYPE_FROM_CLASS (klass),
2384 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2386 _gtk_marshal_VOID__OBJECT,
2388 GDK_TYPE_DRAG_CONTEXT);
2391 * GtkWidget::drag-end:
2392 * @widget: the object which received the signal
2393 * @drag_context: the drag context
2395 * The ::drag-end signal is emitted on the drag source when a drag is
2396 * finished. A typical reason to connect to this signal is to undo
2397 * things done in #GtkWidget::drag-begin.
2399 widget_signals[DRAG_END] =
2400 g_signal_new (I_("drag-end"),
2401 G_TYPE_FROM_CLASS (klass),
2403 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2405 _gtk_marshal_VOID__OBJECT,
2407 GDK_TYPE_DRAG_CONTEXT);
2410 * GtkWidget::drag-data-delete:
2411 * @widget: the object which received the signal
2412 * @drag_context: the drag context
2414 * The ::drag-data-delete signal is emitted on the drag source when a drag
2415 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2416 * handler is responsible for deleting the data that has been dropped. What
2417 * "delete" means depends on the context of the drag operation.
2419 widget_signals[DRAG_DATA_DELETE] =
2420 g_signal_new (I_("drag-data-delete"),
2421 G_TYPE_FROM_CLASS (klass),
2423 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2425 _gtk_marshal_VOID__OBJECT,
2427 GDK_TYPE_DRAG_CONTEXT);
2430 * GtkWidget::drag-failed:
2431 * @widget: the object which received the signal
2432 * @drag_context: the drag context
2433 * @result: the result of the drag operation
2435 * The ::drag-failed signal is emitted on the drag source when a drag has
2436 * failed. The signal handler may hook custom code to handle a failed DND
2437 * operation based on the type of error, it returns %TRUE is the failure has
2438 * been already handled (not showing the default "drag operation failed"
2439 * animation), otherwise it returns %FALSE.
2441 * Return value: %TRUE if the failed drag operation has been already handled.
2445 widget_signals[DRAG_FAILED] =
2446 g_signal_new (I_("drag-failed"),
2447 G_TYPE_FROM_CLASS (klass),
2449 0, _gtk_boolean_handled_accumulator, NULL,
2450 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2452 GDK_TYPE_DRAG_CONTEXT,
2453 GTK_TYPE_DRAG_RESULT);
2456 * GtkWidget::drag-motion:
2457 * @widget: the object which received the signal
2458 * @drag_context: the drag context
2459 * @x: the x coordinate of the current cursor position
2460 * @y: the y coordinate of the current cursor position
2461 * @time: the timestamp of the motion event
2462 * @returns: whether the cursor position is in a drop zone
2464 * The drag-motion signal is emitted on the drop site when the user
2465 * moves the cursor over the widget during a drag. The signal handler
2466 * must determine whether the cursor position is in a drop zone or not.
2467 * If it is not in a drop zone, it returns %FALSE and no further processing
2468 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2469 * handler is responsible for providing the necessary information for
2470 * displaying feedback to the user, by calling gdk_drag_status().
2472 * If the decision whether the drop will be accepted or rejected can't be
2473 * made based solely on the cursor position and the type of the data, the
2474 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2475 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2476 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2477 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2478 * when using the drag-motion signal that way.
2480 * Also note that there is no drag-enter signal. The drag receiver has to
2481 * keep track of whether he has received any drag-motion signals since the
2482 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2483 * an "enter" signal. Upon an "enter", the handler will typically highlight
2484 * the drop site with gtk_drag_highlight().
2487 * drag_motion (GtkWidget *widget,
2488 * GdkDragContext *context,
2495 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2497 * if (!private_data->drag_highlight)
2499 * private_data->drag_highlight = 1;
2500 * gtk_drag_highlight (widget);
2503 * target = gtk_drag_dest_find_target (widget, context, NULL);
2504 * if (target == GDK_NONE)
2505 * gdk_drag_status (context, 0, time);
2508 * private_data->pending_status = context->suggested_action;
2509 * gtk_drag_get_data (widget, context, target, time);
2516 * drag_data_received (GtkWidget *widget,
2517 * GdkDragContext *context,
2520 * GtkSelectionData *selection_data,
2524 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2526 * if (private_data->suggested_action)
2528 * private_data->suggested_action = 0;
2530 * /* We are getting this data due to a request in drag_motion,
2531 * * rather than due to a request in drag_drop, so we are just
2532 * * supposed to call gdk_drag_status (), not actually paste in
2535 * str = gtk_selection_data_get_text (selection_data);
2536 * if (!data_is_acceptable (str))
2537 * gdk_drag_status (context, 0, time);
2539 * gdk_drag_status (context, private_data->suggested_action, time);
2543 * /* accept the drop */
2548 widget_signals[DRAG_MOTION] =
2549 g_signal_new (I_("drag-motion"),
2550 G_TYPE_FROM_CLASS (klass),
2552 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2553 _gtk_boolean_handled_accumulator, NULL,
2554 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2556 GDK_TYPE_DRAG_CONTEXT,
2562 * GtkWidget::drag-drop:
2563 * @widget: the object which received the signal
2564 * @drag_context: the drag context
2565 * @x: the x coordinate of the current cursor position
2566 * @y: the y coordinate of the current cursor position
2567 * @time: the timestamp of the motion event
2568 * @returns: whether the cursor position is in a drop zone
2570 * The ::drag-drop signal is emitted on the drop site when the user drops
2571 * the data onto the widget. The signal handler must determine whether
2572 * the cursor position is in a drop zone or not. If it is not in a drop
2573 * zone, it returns %FALSE and no further processing is necessary.
2574 * Otherwise, the handler returns %TRUE. In this case, the handler must
2575 * ensure that gtk_drag_finish() is called to let the source know that
2576 * the drop is done. The call to gtk_drag_finish() can be done either
2577 * directly or in a #GtkWidget::drag-data-received handler which gets
2578 * triggered by calling gtk_drag_get_data() to receive the data for one
2579 * or more of the supported targets.
2581 widget_signals[DRAG_DROP] =
2582 g_signal_new (I_("drag-drop"),
2583 G_TYPE_FROM_CLASS (klass),
2585 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2586 _gtk_boolean_handled_accumulator, NULL,
2587 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2589 GDK_TYPE_DRAG_CONTEXT,
2595 * GtkWidget::drag-data-get:
2596 * @widget: the object which received the signal
2597 * @drag_context: the drag context
2598 * @data: the #GtkSelectionData to be filled with the dragged data
2599 * @info: the info that has been registered with the target in the
2601 * @time: the timestamp at which the data was requested
2603 * The ::drag-data-get signal is emitted on the drag source when the drop
2604 * site requests the data which is dragged. It is the responsibility of
2605 * the signal handler to fill @data with the data in the format which
2606 * is indicated by @info. See gtk_selection_data_set() and
2607 * gtk_selection_data_set_text().
2609 widget_signals[DRAG_DATA_GET] =
2610 g_signal_new (I_("drag-data-get"),
2611 G_TYPE_FROM_CLASS (klass),
2613 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2615 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2617 GDK_TYPE_DRAG_CONTEXT,
2618 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2623 * GtkWidget::drag-data-received:
2624 * @widget: the object which received the signal
2625 * @drag_context: the drag context
2626 * @x: where the drop happened
2627 * @y: where the drop happened
2628 * @data: the received data
2629 * @info: the info that has been registered with the target in the
2631 * @time: the timestamp at which the data was received
2633 * The ::drag-data-received signal is emitted on the drop site when the
2634 * dragged data has been received. If the data was received in order to
2635 * determine whether the drop will be accepted, the handler is expected
2636 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2637 * If the data was received in response to a #GtkWidget::drag-drop signal
2638 * (and this is the last target to be received), the handler for this
2639 * signal is expected to process the received data and then call
2640 * gtk_drag_finish(), setting the @success parameter depending on whether
2641 * the data was processed successfully.
2643 * The handler may inspect and modify @drag_context->action before calling
2644 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2645 * following example:
2648 * drag_data_received (GtkWidget *widget,
2649 * GdkDragContext *drag_context,
2652 * GtkSelectionData *data,
2656 * if ((data->length >= 0) && (data->format == 8))
2658 * if (drag_context->action == GDK_ACTION_ASK)
2660 * GtkWidget *dialog;
2663 * dialog = gtk_message_dialog_new (NULL,
2664 * GTK_DIALOG_MODAL |
2665 * GTK_DIALOG_DESTROY_WITH_PARENT,
2667 * GTK_BUTTONS_YES_NO,
2668 * "Move the data ?\n");
2669 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2670 * gtk_widget_destroy (dialog);
2672 * if (response == GTK_RESPONSE_YES)
2673 * drag_context->action = GDK_ACTION_MOVE;
2675 * drag_context->action = GDK_ACTION_COPY;
2678 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2682 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2686 widget_signals[DRAG_DATA_RECEIVED] =
2687 g_signal_new (I_("drag-data-received"),
2688 G_TYPE_FROM_CLASS (klass),
2690 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2692 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2694 GDK_TYPE_DRAG_CONTEXT,
2697 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2702 * GtkWidget::visibility-notify-event:
2703 * @widget: the object which received the signal
2704 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2705 * triggered this signal.
2707 * The ::visibility-notify-event will be emitted when the @widget's window
2708 * is obscured or unobscured.
2710 * To receive this signal the #GdkWindow associated to the widget needs
2711 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2713 * Returns: %TRUE to stop other handlers from being invoked for the event.
2714 * %FALSE to propagate the event further.
2716 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2717 g_signal_new (I_("visibility-notify-event"),
2718 G_TYPE_FROM_CLASS (klass),
2720 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2721 _gtk_boolean_handled_accumulator, NULL,
2722 _gtk_marshal_BOOLEAN__BOXED,
2724 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2727 * GtkWidget::client-event:
2728 * @widget: the object which received the signal
2729 * @event: (type Gdk.EventClient): the #GdkEventClient which triggered
2732 * The ::client-event will be emitted when the @widget's window
2733 * receives a message (via a ClientMessage event) from another
2736 * Returns: %TRUE to stop other handlers from being invoked for
2737 * the event. %FALSE to propagate the event further.
2739 widget_signals[CLIENT_EVENT] =
2740 g_signal_new (I_("client-event"),
2741 G_TYPE_FROM_CLASS (klass),
2743 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2744 _gtk_boolean_handled_accumulator, NULL,
2745 _gtk_marshal_BOOLEAN__BOXED,
2747 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2750 * GtkWidget::window-state-event:
2751 * @widget: the object which received the signal
2752 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2753 * triggered this signal.
2755 * The ::window-state-event will be emitted when the state of the
2756 * toplevel window associated to the @widget changes.
2758 * To receive this signal the #GdkWindow associated to the widget
2759 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2760 * this mask automatically for all new windows.
2762 * Returns: %TRUE to stop other handlers from being invoked for the
2763 * event. %FALSE to propagate the event further.
2765 widget_signals[WINDOW_STATE_EVENT] =
2766 g_signal_new (I_("window-state-event"),
2767 G_TYPE_FROM_CLASS (klass),
2769 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2770 _gtk_boolean_handled_accumulator, NULL,
2771 _gtk_marshal_BOOLEAN__BOXED,
2773 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2776 * GtkWidget::damage-event:
2777 * @widget: the object which received the signal
2778 * @event: the #GdkEventExpose event
2780 * Emitted when a redirected window belonging to @widget gets drawn into.
2781 * The region/area members of the event shows what area of the redirected
2782 * drawable was drawn into.
2784 * Returns: %TRUE to stop other handlers from being invoked for the event.
2785 * %FALSE to propagate the event further.
2789 widget_signals[DAMAGE_EVENT] =
2790 g_signal_new (I_("damage-event"),
2791 G_TYPE_FROM_CLASS (klass),
2793 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2794 _gtk_boolean_handled_accumulator, NULL,
2795 _gtk_marshal_BOOLEAN__BOXED,
2797 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2800 * GtkWidget::grab-broken-event:
2801 * @widget: the object which received the signal
2802 * @event: the #GdkEventGrabBroken event
2804 * Emitted when a pointer or keyboard grab on a window belonging
2805 * to @widget gets broken.
2807 * On X11, this happens when the grab window becomes unviewable
2808 * (i.e. it or one of its ancestors is unmapped), or if the same
2809 * application grabs the pointer or keyboard again.
2811 * Returns: %TRUE to stop other handlers from being invoked for
2812 * the event. %FALSE to propagate the event further.
2816 widget_signals[GRAB_BROKEN_EVENT] =
2817 g_signal_new (I_("grab-broken-event"),
2818 G_TYPE_FROM_CLASS (klass),
2820 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2821 _gtk_boolean_handled_accumulator, NULL,
2822 _gtk_marshal_BOOLEAN__BOXED,
2824 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2827 * GtkWidget::query-tooltip:
2828 * @widget: the object which received the signal
2829 * @x: the x coordinate of the cursor position where the request has
2830 * been emitted, relative to @widget->window
2831 * @y: the y coordinate of the cursor position where the request has
2832 * been emitted, relative to @widget->window
2833 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2834 * @tooltip: a #GtkTooltip
2836 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2837 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2838 * focus in keyboard mode.
2840 * Using the given coordinates, the signal handler should determine
2841 * whether a tooltip should be shown for @widget. If this is the case
2842 * %TRUE should be returned, %FALSE otherwise. Note that if
2843 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2844 * should not be used.
2846 * The signal handler is free to manipulate @tooltip with the therefore
2847 * destined function calls.
2849 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2853 widget_signals[QUERY_TOOLTIP] =
2854 g_signal_new (I_("query-tooltip"),
2855 G_TYPE_FROM_CLASS (klass),
2857 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2858 _gtk_boolean_handled_accumulator, NULL,
2859 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2867 * GtkWidget::popup-menu
2868 * @widget: the object which received the signal
2870 * This signal gets emitted whenever a widget should pop up a context
2871 * menu. This usually happens through the standard key binding mechanism;
2872 * by pressing a certain key while a widget is focused, the user can cause
2873 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2874 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2875 * for an example of how to use this signal.
2877 * Returns: %TRUE if a menu was activated
2879 widget_signals[POPUP_MENU] =
2880 g_signal_new (I_("popup-menu"),
2881 G_TYPE_FROM_CLASS (klass),
2882 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2883 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2884 _gtk_boolean_handled_accumulator, NULL,
2885 _gtk_marshal_BOOLEAN__VOID,
2889 * GtkWidget::show-help:
2890 * @widget: the object which received the signal.
2893 widget_signals[SHOW_HELP] =
2894 g_signal_new (I_("show-help"),
2895 G_TYPE_FROM_CLASS (klass),
2896 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2897 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2898 _gtk_boolean_handled_accumulator, NULL,
2899 _gtk_marshal_BOOLEAN__ENUM,
2901 GTK_TYPE_WIDGET_HELP_TYPE);
2904 * GtkWidget::accel-closures-changed:
2905 * @widget: the object which received the signal.
2907 widget_signals[ACCEL_CLOSURES_CHANGED] =
2908 g_signal_new (I_("accel-closures-changed"),
2909 G_TYPE_FROM_CLASS (klass),
2913 _gtk_marshal_VOID__VOID,
2917 * GtkWidget::screen-changed:
2918 * @widget: the object on which the signal is emitted
2919 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2920 * widget was not associated with a screen before
2922 * The ::screen-changed signal gets emitted when the
2923 * screen of a widget has changed.
2925 widget_signals[SCREEN_CHANGED] =
2926 g_signal_new (I_("screen-changed"),
2927 G_TYPE_FROM_CLASS (klass),
2929 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2931 _gtk_marshal_VOID__OBJECT,
2936 * GtkWidget::can-activate-accel:
2937 * @widget: the object which received the signal
2938 * @signal_id: the ID of a signal installed on @widget
2940 * Determines whether an accelerator that activates the signal
2941 * identified by @signal_id can currently be activated.
2942 * This signal is present to allow applications and derived
2943 * widgets to override the default #GtkWidget handling
2944 * for determining whether an accelerator can be activated.
2946 * Returns: %TRUE if the signal can be activated.
2948 widget_signals[CAN_ACTIVATE_ACCEL] =
2949 g_signal_new (I_("can-activate-accel"),
2950 G_TYPE_FROM_CLASS (klass),
2952 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2953 _gtk_boolean_handled_accumulator, NULL,
2954 _gtk_marshal_BOOLEAN__UINT,
2955 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2957 binding_set = gtk_binding_set_by_class (klass);
2958 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
2960 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
2963 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
2965 GTK_TYPE_WIDGET_HELP_TYPE,
2966 GTK_WIDGET_HELP_TOOLTIP);
2967 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
2969 GTK_TYPE_WIDGET_HELP_TYPE,
2970 GTK_WIDGET_HELP_TOOLTIP);
2971 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
2973 GTK_TYPE_WIDGET_HELP_TYPE,
2974 GTK_WIDGET_HELP_WHATS_THIS);
2975 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
2977 GTK_TYPE_WIDGET_HELP_TYPE,
2978 GTK_WIDGET_HELP_WHATS_THIS);
2980 gtk_widget_class_install_style_property (klass,
2981 g_param_spec_boolean ("interior-focus",
2982 P_("Interior Focus"),
2983 P_("Whether to draw the focus indicator inside widgets"),
2985 GTK_PARAM_READABLE));
2987 gtk_widget_class_install_style_property (klass,
2988 g_param_spec_int ("focus-line-width",
2989 P_("Focus linewidth"),
2990 P_("Width, in pixels, of the focus indicator line"),
2992 GTK_PARAM_READABLE));
2994 gtk_widget_class_install_style_property (klass,
2995 g_param_spec_string ("focus-line-pattern",
2996 P_("Focus line dash pattern"),
2997 P_("Dash pattern used to draw the focus indicator"),
2999 GTK_PARAM_READABLE));
3000 gtk_widget_class_install_style_property (klass,
3001 g_param_spec_int ("focus-padding",
3002 P_("Focus padding"),
3003 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3005 GTK_PARAM_READABLE));
3006 gtk_widget_class_install_style_property (klass,
3007 g_param_spec_boxed ("cursor-color",
3009 P_("Color with which to draw insertion cursor"),
3011 GTK_PARAM_READABLE));
3012 gtk_widget_class_install_style_property (klass,
3013 g_param_spec_boxed ("secondary-cursor-color",
3014 P_("Secondary cursor color"),
3015 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3017 GTK_PARAM_READABLE));
3018 gtk_widget_class_install_style_property (klass,
3019 g_param_spec_float ("cursor-aspect-ratio",
3020 P_("Cursor line aspect ratio"),
3021 P_("Aspect ratio with which to draw insertion cursor"),
3023 GTK_PARAM_READABLE));
3025 gtk_widget_class_install_style_property (klass,
3026 g_param_spec_boolean ("window-dragging",
3027 P_("Window dragging"),
3028 P_("Whether windows can be dragged by clicking on empty areas"),
3030 GTK_PARAM_READABLE));
3033 * GtkWidget:link-color:
3035 * The "link-color" style property defines the color of unvisited links.
3039 gtk_widget_class_install_style_property (klass,
3040 g_param_spec_boxed ("link-color",
3041 P_("Unvisited Link Color"),
3042 P_("Color of unvisited links"),
3044 GTK_PARAM_READABLE));
3047 * GtkWidget:visited-link-color:
3049 * The "visited-link-color" style property defines the color of visited links.
3053 gtk_widget_class_install_style_property (klass,
3054 g_param_spec_boxed ("visited-link-color",
3055 P_("Visited Link Color"),
3056 P_("Color of visited links"),
3058 GTK_PARAM_READABLE));
3061 * GtkWidget:wide-separators:
3063 * The "wide-separators" style property defines whether separators have
3064 * configurable width and should be drawn using a box instead of a line.
3068 gtk_widget_class_install_style_property (klass,
3069 g_param_spec_boolean ("wide-separators",
3070 P_("Wide Separators"),
3071 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3073 GTK_PARAM_READABLE));
3076 * GtkWidget:separator-width:
3078 * The "separator-width" style property defines the width of separators.
3079 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3083 gtk_widget_class_install_style_property (klass,
3084 g_param_spec_int ("separator-width",
3085 P_("Separator Width"),
3086 P_("The width of separators if wide-separators is TRUE"),
3088 GTK_PARAM_READABLE));
3091 * GtkWidget:separator-height:
3093 * The "separator-height" style property defines the height of separators.
3094 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3098 gtk_widget_class_install_style_property (klass,
3099 g_param_spec_int ("separator-height",
3100 P_("Separator Height"),
3101 P_("The height of separators if \"wide-separators\" is TRUE"),
3103 GTK_PARAM_READABLE));
3106 * GtkWidget:scroll-arrow-hlength:
3108 * The "scroll-arrow-hlength" style property defines the length of
3109 * horizontal scroll arrows.
3113 gtk_widget_class_install_style_property (klass,
3114 g_param_spec_int ("scroll-arrow-hlength",
3115 P_("Horizontal Scroll Arrow Length"),
3116 P_("The length of horizontal scroll arrows"),
3118 GTK_PARAM_READABLE));
3121 * GtkWidget:scroll-arrow-vlength:
3123 * The "scroll-arrow-vlength" style property defines the length of
3124 * vertical scroll arrows.
3128 gtk_widget_class_install_style_property (klass,
3129 g_param_spec_int ("scroll-arrow-vlength",
3130 P_("Vertical Scroll Arrow Length"),
3131 P_("The length of vertical scroll arrows"),
3133 GTK_PARAM_READABLE));
3135 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3139 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3143 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3144 for (node = list; node; node = node->next)
3146 GParamSpec *pspec = node->data;
3148 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3149 g_param_spec_unref (pspec);
3155 gtk_widget_set_property (GObject *object,
3157 const GValue *value,
3160 GtkWidget *widget = GTK_WIDGET (object);
3165 gchar *tooltip_markup;
3166 const gchar *tooltip_text;
3167 GtkWindow *tooltip_window;
3170 gtk_widget_set_name (widget, g_value_get_string (value));
3173 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3175 case PROP_WIDTH_REQUEST:
3176 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3178 case PROP_HEIGHT_REQUEST:
3179 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3182 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3184 case PROP_SENSITIVE:
3185 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3187 case PROP_APP_PAINTABLE:
3188 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3190 case PROP_CAN_FOCUS:
3191 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3193 case PROP_HAS_FOCUS:
3194 if (g_value_get_boolean (value))
3195 gtk_widget_grab_focus (widget);
3198 if (g_value_get_boolean (value))
3199 gtk_widget_grab_focus (widget);
3201 case PROP_CAN_DEFAULT:
3202 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3204 case PROP_HAS_DEFAULT:
3205 if (g_value_get_boolean (value))
3206 gtk_widget_grab_default (widget);
3208 case PROP_RECEIVES_DEFAULT:
3209 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3212 gtk_widget_set_style (widget, g_value_get_object (value));
3215 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3216 gtk_widget_set_events (widget, g_value_get_flags (value));
3218 case PROP_EXTENSION_EVENTS:
3219 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
3221 case PROP_NO_SHOW_ALL:
3222 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3224 case PROP_HAS_TOOLTIP:
3225 gtk_widget_real_set_has_tooltip (widget,
3226 g_value_get_boolean (value), FALSE);
3228 case PROP_TOOLTIP_MARKUP:
3229 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3230 tooltip_markup = g_value_dup_string (value);
3232 /* Treat an empty string as a NULL string,
3233 * because an empty string would be useless for a tooltip:
3235 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3237 g_free (tooltip_markup);
3238 tooltip_markup = NULL;
3241 g_object_set_qdata_full (object, quark_tooltip_markup,
3242 tooltip_markup, g_free);
3244 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3245 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3246 if (gtk_widget_get_visible (widget))
3247 gtk_widget_queue_tooltip_query (widget);
3249 case PROP_TOOLTIP_TEXT:
3250 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3252 tooltip_text = g_value_get_string (value);
3254 /* Treat an empty string as a NULL string,
3255 * because an empty string would be useless for a tooltip:
3257 if (tooltip_text && (strlen (tooltip_text) == 0))
3258 tooltip_text = NULL;
3260 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3262 g_object_set_qdata_full (object, quark_tooltip_markup,
3263 tooltip_markup, g_free);
3265 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3266 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3267 if (gtk_widget_get_visible (widget))
3268 gtk_widget_queue_tooltip_query (widget);
3270 case PROP_DOUBLE_BUFFERED:
3271 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3274 gtk_widget_set_halign (widget, g_value_get_enum (value));
3277 gtk_widget_set_valign (widget, g_value_get_enum (value));
3279 case PROP_MARGIN_LEFT:
3280 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3282 case PROP_MARGIN_RIGHT:
3283 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3285 case PROP_MARGIN_TOP:
3286 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3288 case PROP_MARGIN_BOTTOM:
3289 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3292 g_object_freeze_notify (G_OBJECT (widget));
3293 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3294 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3295 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3296 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3297 g_object_thaw_notify (G_OBJECT (widget));
3300 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3302 case PROP_HEXPAND_SET:
3303 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3306 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3308 case PROP_VEXPAND_SET:
3309 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3312 g_object_freeze_notify (G_OBJECT (widget));
3313 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3314 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3315 g_object_thaw_notify (G_OBJECT (widget));
3318 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3324 gtk_widget_get_property (GObject *object,
3329 GtkWidget *widget = GTK_WIDGET (object);
3330 GtkWidgetPrivate *priv = widget->priv;
3339 g_value_set_string (value, priv->name);
3341 g_value_set_static_string (value, "");
3344 g_value_set_object (value, priv->parent);
3346 case PROP_WIDTH_REQUEST:
3349 gtk_widget_get_size_request (widget, &w, NULL);
3350 g_value_set_int (value, w);
3353 case PROP_HEIGHT_REQUEST:
3356 gtk_widget_get_size_request (widget, NULL, &h);
3357 g_value_set_int (value, h);
3361 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3363 case PROP_SENSITIVE:
3364 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3366 case PROP_APP_PAINTABLE:
3367 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3369 case PROP_CAN_FOCUS:
3370 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3372 case PROP_HAS_FOCUS:
3373 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3376 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3378 case PROP_CAN_DEFAULT:
3379 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3381 case PROP_HAS_DEFAULT:
3382 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3384 case PROP_RECEIVES_DEFAULT:
3385 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3387 case PROP_COMPOSITE_CHILD:
3388 g_value_set_boolean (value, widget->priv->composite_child);
3391 g_value_set_object (value, gtk_widget_get_style (widget));
3394 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3395 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3397 case PROP_EXTENSION_EVENTS:
3398 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
3399 g_value_set_enum (value, GPOINTER_TO_INT (modep));
3401 case PROP_NO_SHOW_ALL:
3402 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3404 case PROP_HAS_TOOLTIP:
3405 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3407 case PROP_TOOLTIP_TEXT:
3409 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3412 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3413 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3415 g_value_take_string (value, text);
3418 case PROP_TOOLTIP_MARKUP:
3419 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3422 g_value_set_object (value, gtk_widget_get_window (widget));
3424 case PROP_DOUBLE_BUFFERED:
3425 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3428 g_value_set_enum (value, gtk_widget_get_halign (widget));
3431 g_value_set_enum (value, gtk_widget_get_valign (widget));
3433 case PROP_MARGIN_LEFT:
3434 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3436 case PROP_MARGIN_RIGHT:
3437 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3439 case PROP_MARGIN_TOP:
3440 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3442 case PROP_MARGIN_BOTTOM:
3443 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3447 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3448 if (aux_info == NULL)
3450 g_value_set_int (value, 0);
3454 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3455 aux_info->margin.right),
3456 MAX (aux_info->margin.top,
3457 aux_info->margin.bottom)));
3462 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3464 case PROP_HEXPAND_SET:
3465 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3468 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3470 case PROP_VEXPAND_SET:
3471 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3474 g_value_set_boolean (value,
3475 gtk_widget_get_hexpand (widget) &&
3476 gtk_widget_get_vexpand (widget));
3479 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3485 gtk_widget_init (GtkWidget *widget)
3487 GtkWidgetPrivate *priv;
3489 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3492 priv = widget->priv;
3494 priv->child_visible = TRUE;
3496 priv->allocation.x = -1;
3497 priv->allocation.y = -1;
3498 priv->allocation.width = 1;
3499 priv->allocation.height = 1;
3500 priv->window = NULL;
3501 priv->parent = NULL;
3503 priv->sensitive = TRUE;
3504 priv->parent_sensitive = TRUE;
3505 priv->composite_child = composite_child_stack != 0;
3506 priv->double_buffered = TRUE;
3507 priv->redraw_on_alloc = TRUE;
3508 priv->width_request_needed = TRUE;
3509 priv->height_request_needed = TRUE;
3510 priv->alloc_needed = TRUE;
3512 /* this will be set to TRUE if the widget gets a child or if the
3513 * expand flag is set on the widget, but until one of those happen
3514 * we know the expand is already properly FALSE.
3516 * We really want to default FALSE here to avoid computing expand
3517 * all over the place while initially building a widget tree.
3519 priv->need_compute_expand = FALSE;
3521 priv->style = gtk_widget_get_default_style ();
3522 g_object_ref (priv->style);
3527 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3529 GParamSpec **pspecs)
3531 GtkWidgetPrivate *priv = widget->priv;
3532 GtkWidget *container = priv->parent;
3535 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3536 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3540 * gtk_widget_freeze_child_notify:
3541 * @widget: a #GtkWidget
3543 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3544 * signals are queued until gtk_widget_thaw_child_notify() is called
3547 * This is the analogue of g_object_freeze_notify() for child properties.
3550 gtk_widget_freeze_child_notify (GtkWidget *widget)
3552 g_return_if_fail (GTK_IS_WIDGET (widget));
3554 if (!G_OBJECT (widget)->ref_count)
3557 g_object_ref (widget);
3558 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3559 g_object_unref (widget);
3563 * gtk_widget_child_notify:
3564 * @widget: a #GtkWidget
3565 * @child_property: the name of a child property installed on the
3566 * class of @widget<!-- -->'s parent
3568 * Emits a #GtkWidget::child-notify signal for the
3569 * <link linkend="child-properties">child property</link> @child_property
3572 * This is the analogue of g_object_notify() for child properties.
3575 gtk_widget_child_notify (GtkWidget *widget,
3576 const gchar *child_property)
3578 GtkWidgetPrivate *priv = widget->priv;
3581 g_return_if_fail (GTK_IS_WIDGET (widget));
3582 g_return_if_fail (child_property != NULL);
3583 if (!G_OBJECT (widget)->ref_count || !priv->parent)
3586 g_object_ref (widget);
3587 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3589 G_OBJECT_TYPE (priv->parent),
3592 g_warning ("%s: container class `%s' has no child property named `%s'",
3594 G_OBJECT_TYPE_NAME (priv->parent),
3598 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3600 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3601 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3603 g_object_unref (widget);
3607 * gtk_widget_thaw_child_notify:
3608 * @widget: a #GtkWidget
3610 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3611 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3615 gtk_widget_thaw_child_notify (GtkWidget *widget)
3617 GObjectNotifyQueue *nqueue;
3619 g_return_if_fail (GTK_IS_WIDGET (widget));
3621 if (!G_OBJECT (widget)->ref_count)
3624 g_object_ref (widget);
3625 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3626 if (!nqueue || !nqueue->freeze_count)
3627 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3628 G_OBJECT_TYPE_NAME (widget), widget);
3630 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3631 g_object_unref (widget);
3637 * @type: type ID of the widget to create
3638 * @first_property_name: name of first property to set
3639 * @Varargs: value of first property, followed by more properties,
3642 * This is a convenience function for creating a widget and setting
3643 * its properties in one go. For example you might write:
3644 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3645 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3646 * g_object_new(), but returns a widget so you don't have to
3647 * cast the object yourself.
3649 * Return value: a new #GtkWidget of type @widget_type
3652 gtk_widget_new (GType type,
3653 const gchar *first_property_name,
3659 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3661 va_start (var_args, first_property_name);
3662 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3669 gtk_widget_queue_draw_child (GtkWidget *widget)
3671 GtkWidgetPrivate *priv = widget->priv;
3674 parent = priv->parent;
3675 if (parent && gtk_widget_is_drawable (parent))
3676 gtk_widget_queue_draw_area (parent,
3679 priv->allocation.width,
3680 priv->allocation.height);
3684 * gtk_widget_unparent:
3685 * @widget: a #GtkWidget
3687 * This function is only for use in widget implementations.
3688 * Should be called by implementations of the remove method
3689 * on #GtkContainer, to dissociate a child from the container.
3692 gtk_widget_unparent (GtkWidget *widget)
3694 GtkWidgetPrivate *priv;
3695 GObjectNotifyQueue *nqueue;
3696 GtkWidget *toplevel;
3697 GtkWidget *old_parent;
3699 g_return_if_fail (GTK_IS_WIDGET (widget));
3701 priv = widget->priv;
3703 if (priv->parent == NULL)
3706 /* keep this function in sync with gtk_menu_detach()
3709 g_object_freeze_notify (G_OBJECT (widget));
3710 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3712 toplevel = gtk_widget_get_toplevel (widget);
3713 if (gtk_widget_is_toplevel (toplevel))
3714 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3716 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3717 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3719 /* If we are unanchoring the child, we save around the toplevel
3720 * to emit hierarchy changed
3722 if (priv->parent->priv->anchored)
3723 g_object_ref (toplevel);
3727 gtk_widget_queue_draw_child (widget);
3729 /* Reset the width and height here, to force reallocation if we
3730 * get added back to a new parent. This won't work if our new
3731 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3732 * (would 0x0 be OK here?)
3734 priv->allocation.width = 1;
3735 priv->allocation.height = 1;
3737 if (gtk_widget_get_realized (widget))
3739 if (priv->in_reparent)
3740 gtk_widget_unmap (widget);
3742 gtk_widget_unrealize (widget);
3745 /* Removing a widget from a container restores the child visible
3746 * flag to the default state, so it doesn't affect the child
3747 * in the next parent.
3749 priv->child_visible = TRUE;
3751 old_parent = priv->parent;
3752 priv->parent = NULL;
3753 gtk_widget_set_parent_window (widget, NULL);
3755 /* parent may no longer expand if the removed
3756 * child was expand=TRUE and could therefore
3759 if (gtk_widget_get_visible (widget) &&
3760 (priv->need_compute_expand ||
3761 priv->computed_hexpand ||
3762 priv->computed_vexpand))
3764 gtk_widget_queue_compute_expand (old_parent);
3767 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3770 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3771 g_object_unref (toplevel);
3774 g_object_notify (G_OBJECT (widget), "parent");
3775 g_object_thaw_notify (G_OBJECT (widget));
3777 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3778 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3779 g_object_unref (widget);
3783 * gtk_widget_destroy:
3784 * @widget: a #GtkWidget
3786 * Destroys a widget.
3789 * destroyed, it will break any references it holds to other objects.
3790 * If the widget is inside a container, the widget will be removed
3791 * from the container. If the widget is a toplevel (derived from
3792 * #GtkWindow), it will be removed from the list of toplevels, and the
3793 * reference GTK+ holds to it will be removed. Removing a
3794 * widget from its container or the list of toplevels results in the
3795 * widget being finalized, unless you've added additional references
3796 * to the widget with g_object_ref().
3798 * In most cases, only toplevel widgets (windows) require explicit
3799 * destruction, because when you destroy a toplevel its children will
3800 * be destroyed as well.
3803 gtk_widget_destroy (GtkWidget *widget)
3805 g_return_if_fail (GTK_IS_WIDGET (widget));
3807 if (!widget->priv->in_destruction)
3808 g_object_run_dispose (G_OBJECT (widget));
3812 * gtk_widget_destroyed:
3813 * @widget: a #GtkWidget
3814 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3816 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3817 * %NULL. It's intended to be used as a callback connected to the
3818 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3819 * as a signal handler, and pass the address of your widget variable
3820 * as user data. Then when the widget is destroyed, the variable will
3821 * be set to %NULL. Useful for example to avoid multiple copies
3822 * of the same dialog.
3825 gtk_widget_destroyed (GtkWidget *widget,
3826 GtkWidget **widget_pointer)
3828 /* Don't make any assumptions about the
3830 * Even check widget_pointer.
3833 *widget_pointer = NULL;
3838 * @widget: a #GtkWidget
3840 * Flags a widget to be displayed. Any widget that isn't shown will
3841 * not appear on the screen. If you want to show all the widgets in a
3842 * container, it's easier to call gtk_widget_show_all() on the
3843 * container, instead of individually showing the widgets.
3845 * Remember that you have to show the containers containing a widget,
3846 * in addition to the widget itself, before it will appear onscreen.
3848 * When a toplevel container is shown, it is immediately realized and
3849 * mapped; other shown widgets are realized and mapped when their
3850 * toplevel container is realized and mapped.
3853 gtk_widget_show (GtkWidget *widget)
3855 g_return_if_fail (GTK_IS_WIDGET (widget));
3857 if (!gtk_widget_get_visible (widget))
3859 g_object_ref (widget);
3860 if (!gtk_widget_is_toplevel (widget))
3861 gtk_widget_queue_resize (widget);
3863 /* see comment in set_parent() for why this should and can be
3866 if (widget->priv->need_compute_expand ||
3867 widget->priv->computed_hexpand ||
3868 widget->priv->computed_vexpand)
3870 if (widget->priv->parent != NULL)
3871 gtk_widget_queue_compute_expand (widget->priv->parent);
3874 g_signal_emit (widget, widget_signals[SHOW], 0);
3875 g_object_notify (G_OBJECT (widget), "visible");
3876 g_object_unref (widget);
3881 gtk_widget_real_show (GtkWidget *widget)
3883 GtkWidgetPrivate *priv = widget->priv;
3885 if (!gtk_widget_get_visible (widget))
3887 priv->visible = TRUE;
3890 gtk_widget_get_mapped (priv->parent) &&
3891 gtk_widget_get_child_visible (widget) &&
3892 !gtk_widget_get_mapped (widget))
3893 gtk_widget_map (widget);
3898 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3901 g_signal_handlers_disconnect_by_func (widget,
3902 gtk_widget_show_map_callback,
3907 * gtk_widget_show_now:
3908 * @widget: a #GtkWidget
3910 * Shows a widget. If the widget is an unmapped toplevel widget
3911 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3912 * loop and wait for the window to actually be mapped. Be careful;
3913 * because the main loop is running, anything can happen during
3917 gtk_widget_show_now (GtkWidget *widget)
3921 g_return_if_fail (GTK_IS_WIDGET (widget));
3923 /* make sure we will get event */
3924 if (!gtk_widget_get_mapped (widget) &&
3925 gtk_widget_is_toplevel (widget))
3927 gtk_widget_show (widget);
3929 g_signal_connect (widget, "map-event",
3930 G_CALLBACK (gtk_widget_show_map_callback),
3934 gtk_main_iteration ();
3937 gtk_widget_show (widget);
3942 * @widget: a #GtkWidget
3944 * Reverses the effects of gtk_widget_show(), causing the widget to be
3945 * hidden (invisible to the user).
3948 gtk_widget_hide (GtkWidget *widget)
3950 g_return_if_fail (GTK_IS_WIDGET (widget));
3952 if (gtk_widget_get_visible (widget))
3954 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3956 g_object_ref (widget);
3957 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3958 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3960 /* a parent may now be expand=FALSE since we're hidden. */
3961 if (widget->priv->need_compute_expand ||
3962 widget->priv->computed_hexpand ||
3963 widget->priv->computed_vexpand)
3965 gtk_widget_queue_compute_expand (widget);
3968 g_signal_emit (widget, widget_signals[HIDE], 0);
3969 if (!gtk_widget_is_toplevel (widget))
3970 gtk_widget_queue_resize (widget);
3971 g_object_notify (G_OBJECT (widget), "visible");
3972 g_object_unref (widget);
3977 gtk_widget_real_hide (GtkWidget *widget)
3979 if (gtk_widget_get_visible (widget))
3981 widget->priv->visible = FALSE;
3983 if (gtk_widget_get_mapped (widget))
3984 gtk_widget_unmap (widget);
3989 * gtk_widget_hide_on_delete:
3990 * @widget: a #GtkWidget
3992 * Utility function; intended to be connected to the #GtkWidget::delete-event
3993 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3994 * argument, then returns %TRUE. If connected to ::delete-event, the
3995 * result is that clicking the close button for a window (on the
3996 * window frame, top right corner usually) will hide but not destroy
3997 * the window. By default, GTK+ destroys windows when ::delete-event
4000 * Return value: %TRUE
4003 gtk_widget_hide_on_delete (GtkWidget *widget)
4005 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4007 gtk_widget_hide (widget);
4013 * gtk_widget_show_all:
4014 * @widget: a #GtkWidget
4016 * Recursively shows a widget, and any child widgets (if the widget is
4020 gtk_widget_show_all (GtkWidget *widget)
4022 GtkWidgetClass *class;
4024 g_return_if_fail (GTK_IS_WIDGET (widget));
4026 if (gtk_widget_get_no_show_all (widget))
4029 class = GTK_WIDGET_GET_CLASS (widget);
4031 if (class->show_all)
4032 class->show_all (widget);
4036 _gtk_widget_notify_state_change (GtkWidget *widget,
4044 case GTK_STATE_FLAG_ACTIVE:
4045 state = GTK_STATE_ACTIVE;
4047 case GTK_STATE_FLAG_PRELIGHT:
4048 state = GTK_STATE_PRELIGHT;
4050 case GTK_STATE_FLAG_SELECTED:
4051 state = GTK_STATE_SELECTED;
4053 case GTK_STATE_FLAG_INSENSITIVE:
4054 state = GTK_STATE_INSENSITIVE;
4056 case GTK_STATE_FLAG_INCONSISTENT:
4057 state = GTK_STATE_INCONSISTENT;
4059 case GTK_STATE_FLAG_FOCUSED:
4060 state = GTK_STATE_FOCUSED;
4066 gtk_style_context_notify_state_change (widget->priv->context,
4067 gtk_widget_get_window (widget),
4068 NULL, state, target);
4071 /* Initializes state transitions for those states that
4072 * were enabled before mapping and have a looping animation.
4075 _gtk_widget_start_state_transitions (GtkWidget *widget)
4077 GtkStateFlags state, flag;
4079 if (!widget->priv->context)
4082 state = gtk_widget_get_state_flags (widget);
4083 flag = GTK_STATE_FLAG_FOCUSED;
4087 GtkAnimationDescription *animation_desc;
4089 if ((state & flag) == 0)
4095 gtk_style_context_get (widget->priv->context, state,
4096 "transition", &animation_desc,
4101 if (_gtk_animation_description_get_loop (animation_desc))
4102 _gtk_widget_notify_state_change (widget, flag, TRUE);
4104 _gtk_animation_description_unref (animation_desc);
4113 * @widget: a #GtkWidget
4115 * This function is only for use in widget implementations. Causes
4116 * a widget to be mapped if it isn't already.
4119 gtk_widget_map (GtkWidget *widget)
4121 GtkWidgetPrivate *priv;
4123 g_return_if_fail (GTK_IS_WIDGET (widget));
4124 g_return_if_fail (gtk_widget_get_visible (widget));
4125 g_return_if_fail (gtk_widget_get_child_visible (widget));
4127 priv = widget->priv;
4129 if (!gtk_widget_get_mapped (widget))
4131 if (!gtk_widget_get_realized (widget))
4132 gtk_widget_realize (widget);
4134 g_signal_emit (widget, widget_signals[MAP], 0);
4136 if (!gtk_widget_get_has_window (widget))
4137 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4139 _gtk_widget_start_state_transitions (widget);
4145 * @widget: a #GtkWidget
4147 * This function is only for use in widget implementations. Causes
4148 * a widget to be unmapped if it's currently mapped.
4151 gtk_widget_unmap (GtkWidget *widget)
4153 GtkWidgetPrivate *priv;
4155 g_return_if_fail (GTK_IS_WIDGET (widget));
4157 priv = widget->priv;
4159 if (gtk_widget_get_mapped (widget))
4161 if (!gtk_widget_get_has_window (widget))
4162 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4163 _gtk_tooltip_hide (widget);
4164 g_signal_emit (widget, widget_signals[UNMAP], 0);
4169 gtk_widget_set_extension_events_internal (GtkWidget *widget,
4170 GdkExtensionMode mode,
4173 GtkWidgetPrivate *priv = widget->priv;
4174 GList *free_list = NULL;
4177 if (window_list == NULL)
4179 if (gtk_widget_get_has_window (widget))
4180 window_list = g_list_prepend (NULL, priv->window);
4182 window_list = gdk_window_get_children (priv->window);
4184 free_list = window_list;
4187 for (l = window_list; l != NULL; l = l->next)
4189 GdkWindow *window = l->data;
4192 gdk_window_get_user_data (window, &user_data);
4193 if (user_data == widget)
4197 gdk_input_set_extension_events (window,
4198 gdk_window_get_events (window),
4201 children = gdk_window_get_children (window);
4204 gtk_widget_set_extension_events_internal (widget, mode, children);
4205 g_list_free (children);
4211 g_list_free (free_list);
4215 _gtk_widget_enable_device_events (GtkWidget *widget)
4217 GHashTable *device_events;
4218 GHashTableIter iter;
4219 gpointer key, value;
4221 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4226 g_hash_table_iter_init (&iter, device_events);
4228 while (g_hash_table_iter_next (&iter, &key, &value))
4231 GdkEventMask event_mask;
4234 event_mask = GPOINTER_TO_UINT (value);
4235 gtk_widget_add_events_internal (widget, device, event_mask);
4240 * gtk_widget_realize:
4241 * @widget: a #GtkWidget
4243 * Creates the GDK (windowing system) resources associated with a
4244 * widget. For example, @widget->window will be created when a widget
4245 * is realized. Normally realization happens implicitly; if you show
4246 * a widget and all its parent containers, then the widget will be
4247 * realized and mapped automatically.
4249 * Realizing a widget requires all
4250 * the widget's parent widgets to be realized; calling
4251 * gtk_widget_realize() realizes the widget's parents in addition to
4252 * @widget itself. If a widget is not yet inside a toplevel window
4253 * when you realize it, bad things will happen.
4255 * This function is primarily used in widget implementations, and
4256 * isn't very useful otherwise. Many times when you think you might
4257 * need it, a better approach is to connect to a signal that will be
4258 * called after the widget is realized automatically, such as
4259 * #GtkWidget::expose-event. Or simply g_signal_connect () to the
4260 * #GtkWidget::realize signal.
4263 gtk_widget_realize (GtkWidget *widget)
4265 GtkWidgetPrivate *priv;
4266 GdkExtensionMode mode;
4267 cairo_region_t *region;
4269 g_return_if_fail (GTK_IS_WIDGET (widget));
4270 g_return_if_fail (widget->priv->anchored ||
4271 GTK_IS_INVISIBLE (widget));
4273 priv = widget->priv;
4275 if (!gtk_widget_get_realized (widget))
4278 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4279 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4282 if (priv->parent == NULL &&
4283 !gtk_widget_is_toplevel (widget))
4284 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4285 "inside a toplevel window is not going to work very well. "
4286 "Widgets must be inside a toplevel container before realizing them.");
4288 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4289 gtk_widget_realize (priv->parent);
4291 gtk_widget_ensure_style (widget);
4293 g_signal_emit (widget, widget_signals[REALIZE], 0);
4295 gtk_widget_real_set_has_tooltip (widget,
4296 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4299 if (priv->has_shape_mask)
4301 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4302 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4305 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4307 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4309 mode = gtk_widget_get_extension_events (widget);
4310 if (mode != GDK_EXTENSION_EVENTS_NONE)
4311 gtk_widget_set_extension_events_internal (widget, mode, NULL);
4313 if (priv->multidevice)
4314 gdk_window_set_support_multidevice (priv->window, TRUE);
4316 _gtk_widget_enable_device_events (widget);
4321 * gtk_widget_unrealize:
4322 * @widget: a #GtkWidget
4324 * This function is only useful in widget implementations.
4325 * Causes a widget to be unrealized (frees all GDK resources
4326 * associated with the widget, such as @widget->window).
4329 gtk_widget_unrealize (GtkWidget *widget)
4331 g_return_if_fail (GTK_IS_WIDGET (widget));
4333 if (widget->priv->has_shape_mask)
4334 gtk_widget_shape_combine_region (widget, NULL);
4336 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4337 gtk_widget_input_shape_combine_region (widget, NULL);
4339 if (gtk_widget_get_realized (widget))
4341 g_object_ref (widget);
4342 _gtk_tooltip_hide (widget);
4343 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4344 gtk_widget_set_realized (widget, FALSE);
4345 gtk_widget_set_mapped (widget, FALSE);
4346 g_object_unref (widget);
4350 /*****************************************
4352 *****************************************/
4355 * gtk_widget_queue_draw_region:
4356 * @widget: a #GtkWidget
4357 * @region: region to draw
4359 * Invalidates the rectangular area of @widget defined by @region by
4360 * calling gdk_window_invalidate_region() on the widget's window and
4361 * all its child windows. Once the main loop becomes idle (after the
4362 * current batch of events has been processed, roughly), the window
4363 * will receive expose events for the union of all regions that have
4366 * Normally you would only use this function in widget
4367 * implementations. You might also use it to schedule a redraw of a
4368 * #GtkDrawingArea or some portion thereof.
4371 gtk_widget_queue_draw_region (GtkWidget *widget,
4372 cairo_region_t *region)
4374 GtkWidgetPrivate *priv;
4377 g_return_if_fail (GTK_IS_WIDGET (widget));
4379 priv = widget->priv;
4381 if (!gtk_widget_get_realized (widget))
4384 /* Just return if the widget or one of its ancestors isn't mapped */
4385 for (w = widget; w != NULL; w = w->priv->parent)
4386 if (!gtk_widget_get_mapped (w))
4389 gdk_window_invalidate_region (priv->window, region, TRUE);
4393 * gtk_widget_queue_draw_area:
4394 * @widget: a #GtkWidget
4395 * @x: x coordinate of upper-left corner of rectangle to redraw
4396 * @y: y coordinate of upper-left corner of rectangle to redraw
4397 * @width: width of region to draw
4398 * @height: height of region to draw
4400 * Convenience function that calls gtk_widget_queue_draw_region() on
4401 * the region created from the given coordinates.
4404 gtk_widget_queue_draw_area (GtkWidget *widget,
4411 cairo_region_t *region;
4413 g_return_if_fail (GTK_IS_WIDGET (widget));
4418 rect.height = height;
4420 region = cairo_region_create_rectangle (&rect);
4421 gtk_widget_queue_draw_region (widget, region);
4422 cairo_region_destroy (region);
4426 * gtk_widget_queue_draw:
4427 * @widget: a #GtkWidget
4429 * Equivalent to calling gtk_widget_queue_draw_area() for the
4430 * entire area of a widget.
4433 gtk_widget_queue_draw (GtkWidget *widget)
4437 g_return_if_fail (GTK_IS_WIDGET (widget));
4439 gtk_widget_get_allocation (widget, &rect);
4441 if (!gtk_widget_get_has_window (widget))
4442 gtk_widget_queue_draw_area (widget,
4443 rect.x, rect.y, rect.width, rect.height);
4445 gtk_widget_queue_draw_area (widget,
4446 0, 0, rect.width, rect.height);
4450 * gtk_widget_queue_resize:
4451 * @widget: a #GtkWidget
4453 * This function is only for use in widget implementations.
4454 * Flags a widget to have its size renegotiated; should
4455 * be called when a widget for some reason has a new size request.
4456 * For example, when you change the text in a #GtkLabel, #GtkLabel
4457 * queues a resize to ensure there's enough space for the new text.
4459 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4460 * from inside it's implementation of the GtkWidgetClass::size_allocate
4461 * virtual method. Calls to gtk_widget_queue_resize() from inside
4462 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4465 gtk_widget_queue_resize (GtkWidget *widget)
4467 g_return_if_fail (GTK_IS_WIDGET (widget));
4469 if (gtk_widget_get_realized (widget))
4470 gtk_widget_queue_shallow_draw (widget);
4472 _gtk_size_group_queue_resize (widget, 0);
4476 * gtk_widget_queue_resize_no_redraw:
4477 * @widget: a #GtkWidget
4479 * This function works like gtk_widget_queue_resize(),
4480 * except that the widget is not invalidated.
4485 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4487 g_return_if_fail (GTK_IS_WIDGET (widget));
4489 _gtk_size_group_queue_resize (widget, 0);
4493 * gtk_widget_size_request:
4494 * @widget: a #GtkWidget
4495 * @requisition: (out): a #GtkRequisition to be filled in
4497 * This function is typically used when implementing a #GtkContainer
4498 * subclass. Obtains the preferred size of a widget. The container
4499 * uses this information to arrange its child widgets and decide what
4500 * size allocations to give them with gtk_widget_size_allocate().
4502 * You can also call this function from an application, with some
4503 * caveats. Most notably, getting a size request requires the widget
4504 * to be associated with a screen, because font information may be
4505 * needed. Multihead-aware applications should keep this in mind.
4507 * Also remember that the size request is not necessarily the size
4508 * a widget will actually be allocated.
4510 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4513 gtk_widget_size_request (GtkWidget *widget,
4514 GtkRequisition *requisition)
4516 g_return_if_fail (GTK_IS_WIDGET (widget));
4518 gtk_widget_get_preferred_size (widget, requisition, NULL);
4522 * gtk_widget_get_child_requisition:
4523 * @widget: a #GtkWidget
4524 * @requisition: (out): a #GtkRequisition to be filled in
4526 * This function is only for use in widget implementations. Obtains
4527 * @widget->requisition, unless someone has forced a particular
4528 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4529 * in which case it returns that geometry instead of the widget's
4532 * This function differs from gtk_widget_size_request() in that
4533 * it retrieves the last size request value from @widget->requisition,
4534 * while gtk_widget_size_request() actually calls the "size_request" method
4535 * on @widget to compute the size request and fill in @widget->requisition,
4536 * and only then returns @widget->requisition.
4538 * Because this function does not call the "size_request" method, it
4539 * can only be used when you know that @widget->requisition is
4540 * up-to-date, that is, gtk_widget_size_request() has been called
4541 * since the last time a resize was queued. In general, only container
4542 * implementations have this information; applications should use
4543 * gtk_widget_size_request().
4546 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4549 gtk_widget_get_child_requisition (GtkWidget *widget,
4550 GtkRequisition *requisition)
4552 gtk_widget_get_preferred_size (widget, requisition, NULL);
4556 invalidate_predicate (GdkWindow *window,
4561 gdk_window_get_user_data (window, &user_data);
4563 return (user_data == data);
4566 /* Invalidate @region in widget->window and all children
4567 * of widget->window owned by widget. @region is in the
4568 * same coordinates as widget->allocation and will be
4569 * modified by this call.
4572 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4573 cairo_region_t *region)
4575 GtkWidgetPrivate *priv = widget->priv;
4577 if (!gtk_widget_get_realized (widget))
4580 if (gtk_widget_get_has_window (widget) && priv->parent)
4584 gdk_window_get_position (priv->window, &x, &y);
4585 cairo_region_translate (region, -x, -y);
4588 gdk_window_invalidate_maybe_recurse (priv->window, region,
4589 invalidate_predicate, widget);
4593 * gtk_widget_queue_shallow_draw:
4594 * @widget: a #GtkWidget
4596 * Like gtk_widget_queue_draw(), but only windows owned
4597 * by @widget are invalidated.
4600 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4603 cairo_region_t *region;
4605 if (!gtk_widget_get_realized (widget))
4608 gtk_widget_get_allocation (widget, &rect);
4610 region = cairo_region_create_rectangle (&rect);
4611 gtk_widget_invalidate_widget_windows (widget, region);
4612 cairo_region_destroy (region);
4616 * gtk_widget_size_allocate:
4617 * @widget: a #GtkWidget
4618 * @allocation: (inout): position and size to be allocated to @widget
4620 * This function is only used by #GtkContainer subclasses, to assign a size
4621 * and position to their child widgets.
4623 * In this function, the allocation may be adjusted. It will be forced
4624 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4625 * method on the child will be used to adjust the allocation. Standard
4626 * adjustments include removing the widget's margins, and applying the
4627 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4630 gtk_widget_size_allocate (GtkWidget *widget,
4631 GtkAllocation *allocation)
4633 GtkWidgetPrivate *priv;
4634 GdkRectangle real_allocation;
4635 GdkRectangle old_allocation;
4636 GdkRectangle adjusted_allocation;
4637 gboolean alloc_needed;
4638 gboolean size_changed;
4639 gboolean position_changed;
4640 gint natural_width, natural_height, dummy;
4641 gint min_width, min_height;
4643 priv = widget->priv;
4645 g_return_if_fail (GTK_IS_WIDGET (widget));
4647 #ifdef G_ENABLE_DEBUG
4648 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4659 parent = gtk_widget_get_parent (parent);
4662 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4663 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4664 2 * depth, " ", name,
4665 allocation->width, allocation->height);
4667 #endif /* G_ENABLE_DEBUG */
4669 alloc_needed = priv->alloc_needed;
4670 if (!priv->width_request_needed && !priv->height_request_needed)
4671 /* Preserve request/allocate ordering */
4672 priv->alloc_needed = FALSE;
4674 old_allocation = priv->allocation;
4675 real_allocation = *allocation;
4677 adjusted_allocation = real_allocation;
4678 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4680 /* Go ahead and request the height for allocated width, note that the internals
4681 * of get_height_for_width will internally limit the for_size to natural size
4682 * when aligning implicitly.
4684 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4685 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &dummy, &natural_height);
4689 /* Go ahead and request the width for allocated height, note that the internals
4690 * of get_width_for_height will internally limit the for_size to natural size
4691 * when aligning implicitly.
4693 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4694 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &dummy, &natural_width);
4697 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4698 * allocated sizes and possibly limit them to the natural sizes */
4699 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4700 GTK_ORIENTATION_HORIZONTAL,
4703 &adjusted_allocation.x,
4704 &adjusted_allocation.width);
4705 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4706 GTK_ORIENTATION_VERTICAL,
4709 &adjusted_allocation.y,
4710 &adjusted_allocation.height);
4712 if (adjusted_allocation.x < real_allocation.x ||
4713 adjusted_allocation.y < real_allocation.y ||
4714 (adjusted_allocation.x + adjusted_allocation.width) >
4715 (real_allocation.x + real_allocation.width) ||
4716 (adjusted_allocation.y + adjusted_allocation.height >
4717 real_allocation.y + real_allocation.height))
4719 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",
4720 G_OBJECT_TYPE_NAME (widget), widget,
4721 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4722 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4723 adjusted_allocation = real_allocation; /* veto it */
4727 real_allocation = adjusted_allocation;
4730 if (real_allocation.width < 0 || real_allocation.height < 0)
4732 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4733 real_allocation.width,
4734 real_allocation.height);
4737 real_allocation.width = MAX (real_allocation.width, 1);
4738 real_allocation.height = MAX (real_allocation.height, 1);
4740 size_changed = (old_allocation.width != real_allocation.width ||
4741 old_allocation.height != real_allocation.height);
4742 position_changed = (old_allocation.x != real_allocation.x ||
4743 old_allocation.y != real_allocation.y);
4745 if (!alloc_needed && !size_changed && !position_changed)
4748 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4750 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4751 priv->width_request_needed = FALSE;
4752 priv->height_request_needed = FALSE;
4753 priv->alloc_needed = FALSE;
4755 if (gtk_widget_get_mapped (widget))
4757 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4759 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4761 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4762 cairo_region_union_rectangle (invalidate, &old_allocation);
4764 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4765 cairo_region_destroy (invalidate);
4770 if (priv->redraw_on_alloc)
4772 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4774 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4775 cairo_region_union_rectangle (invalidate, &old_allocation);
4777 gtk_widget_invalidate_widget_windows (widget, invalidate);
4778 cairo_region_destroy (invalidate);
4782 if (size_changed || position_changed)
4784 GtkStyleContext *context;
4786 context = gtk_widget_get_style_context (widget);
4787 _gtk_style_context_invalidate_animation_areas (context);
4791 if ((size_changed || position_changed) && priv->parent &&
4792 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4794 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4795 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4796 cairo_region_destroy (invalidate);
4801 * gtk_widget_common_ancestor:
4802 * @widget_a: a #GtkWidget
4803 * @widget_b: a #GtkWidget
4805 * Find the common ancestor of @widget_a and @widget_b that
4806 * is closest to the two widgets.
4808 * Return value: the closest common ancestor of @widget_a and
4809 * @widget_b or %NULL if @widget_a and @widget_b do not
4810 * share a common ancestor.
4813 gtk_widget_common_ancestor (GtkWidget *widget_a,
4814 GtkWidget *widget_b)
4816 GtkWidget *parent_a;
4817 GtkWidget *parent_b;
4821 parent_a = widget_a;
4822 while (parent_a->priv->parent)
4824 parent_a = parent_a->priv->parent;
4828 parent_b = widget_b;
4829 while (parent_b->priv->parent)
4831 parent_b = parent_b->priv->parent;
4835 if (parent_a != parent_b)
4838 while (depth_a > depth_b)
4840 widget_a = widget_a->priv->parent;
4844 while (depth_b > depth_a)
4846 widget_b = widget_b->priv->parent;
4850 while (widget_a != widget_b)
4852 widget_a = widget_a->priv->parent;
4853 widget_b = widget_b->priv->parent;
4860 * gtk_widget_translate_coordinates:
4861 * @src_widget: a #GtkWidget
4862 * @dest_widget: a #GtkWidget
4863 * @src_x: X position relative to @src_widget
4864 * @src_y: Y position relative to @src_widget
4865 * @dest_x: (out): location to store X position relative to @dest_widget
4866 * @dest_y: (out): location to store Y position relative to @dest_widget
4868 * Translate coordinates relative to @src_widget's allocation to coordinates
4869 * relative to @dest_widget's allocations. In order to perform this
4870 * operation, both widgets must be realized, and must share a common
4873 * Return value: %FALSE if either widget was not realized, or there
4874 * was no common ancestor. In this case, nothing is stored in
4875 * *@dest_x and *@dest_y. Otherwise %TRUE.
4878 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4879 GtkWidget *dest_widget,
4885 GtkWidgetPrivate *src_priv = src_widget->priv;
4886 GtkWidgetPrivate *dest_priv = dest_widget->priv;
4887 GtkWidget *ancestor;
4889 GList *dest_list = NULL;
4891 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4892 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4894 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4895 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4898 /* Translate from allocation relative to window relative */
4899 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
4902 gdk_window_get_position (src_priv->window, &wx, &wy);
4904 src_x -= wx - src_priv->allocation.x;
4905 src_y -= wy - src_priv->allocation.y;
4909 src_x += src_priv->allocation.x;
4910 src_y += src_priv->allocation.y;
4913 /* Translate to the common ancestor */
4914 window = src_priv->window;
4915 while (window != ancestor->priv->window)
4919 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4924 window = gdk_window_get_effective_parent (window);
4926 if (!window) /* Handle GtkHandleBox */
4931 window = dest_priv->window;
4932 while (window != ancestor->priv->window)
4934 dest_list = g_list_prepend (dest_list, window);
4936 window = gdk_window_get_effective_parent (window);
4938 if (!window) /* Handle GtkHandleBox */
4940 g_list_free (dest_list);
4949 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4954 dest_list = g_list_remove (dest_list, dest_list->data);
4957 /* Translate from window relative to allocation relative */
4958 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
4961 gdk_window_get_position (dest_priv->window, &wx, &wy);
4963 src_x += wx - dest_priv->allocation.x;
4964 src_y += wy - dest_priv->allocation.y;
4968 src_x -= dest_priv->allocation.x;
4969 src_y -= dest_priv->allocation.y;
4981 gtk_widget_real_size_allocate (GtkWidget *widget,
4982 GtkAllocation *allocation)
4984 GtkWidgetPrivate *priv = widget->priv;
4986 priv->allocation = *allocation;
4988 if (gtk_widget_get_realized (widget) &&
4989 gtk_widget_get_has_window (widget))
4991 gdk_window_move_resize (priv->window,
4992 allocation->x, allocation->y,
4993 allocation->width, allocation->height);
4998 adjust_for_align(GtkAlign align,
5000 gint *allocated_pos,
5001 gint *allocated_size)
5005 case GTK_ALIGN_FILL:
5006 /* change nothing */
5008 case GTK_ALIGN_START:
5009 /* keep *allocated_pos where it is */
5010 *allocated_size = MIN (*allocated_size, *natural_size);
5013 if (*allocated_size > *natural_size)
5015 *allocated_pos += (*allocated_size - *natural_size);
5016 *allocated_size = *natural_size;
5019 case GTK_ALIGN_CENTER:
5020 if (*allocated_size > *natural_size)
5022 *allocated_pos += (*allocated_size - *natural_size) / 2;
5023 *allocated_size = MIN (*allocated_size, *natural_size);
5030 adjust_for_margin(gint start_margin,
5034 gint *allocated_pos,
5035 gint *allocated_size)
5037 *minimum_size -= (start_margin + end_margin);
5038 *natural_size -= (start_margin + end_margin);
5039 *allocated_pos += start_margin;
5040 *allocated_size -= (start_margin + end_margin);
5044 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5045 GtkOrientation orientation,
5048 gint *allocated_pos,
5049 gint *allocated_size)
5051 const GtkWidgetAuxInfo *aux_info;
5053 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5055 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5057 adjust_for_margin (aux_info->margin.left,
5058 aux_info->margin.right,
5059 minimum_size, natural_size,
5060 allocated_pos, allocated_size);
5061 adjust_for_align (aux_info->halign,
5062 natural_size, allocated_pos, allocated_size);
5066 adjust_for_margin (aux_info->margin.top,
5067 aux_info->margin.bottom,
5068 minimum_size, natural_size,
5069 allocated_pos, allocated_size);
5070 adjust_for_align (aux_info->valign,
5071 natural_size, allocated_pos, allocated_size);
5076 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5079 GtkWidgetPrivate *priv = widget->priv;
5081 /* widgets must be onscreen for accels to take effect */
5082 return gtk_widget_is_sensitive (widget) &&
5083 gtk_widget_is_drawable (widget) &&
5084 gdk_window_is_viewable (priv->window);
5088 * gtk_widget_can_activate_accel:
5089 * @widget: a #GtkWidget
5090 * @signal_id: the ID of a signal installed on @widget
5092 * Determines whether an accelerator that activates the signal
5093 * identified by @signal_id can currently be activated.
5094 * This is done by emitting the #GtkWidget::can-activate-accel
5095 * signal on @widget; if the signal isn't overridden by a
5096 * handler or in a derived widget, then the default check is
5097 * that the widget must be sensitive, and the widget and all
5098 * its ancestors mapped.
5100 * Return value: %TRUE if the accelerator can be activated.
5105 gtk_widget_can_activate_accel (GtkWidget *widget,
5108 gboolean can_activate = FALSE;
5109 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5110 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5111 return can_activate;
5120 closure_accel_activate (GClosure *closure,
5121 GValue *return_value,
5122 guint n_param_values,
5123 const GValue *param_values,
5124 gpointer invocation_hint,
5125 gpointer marshal_data)
5127 AccelClosure *aclosure = (AccelClosure*) closure;
5128 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5131 g_signal_emit (closure->data, aclosure->signal_id, 0);
5133 /* whether accelerator was handled */
5134 g_value_set_boolean (return_value, can_activate);
5138 closures_destroy (gpointer data)
5140 GSList *slist, *closures = data;
5142 for (slist = closures; slist; slist = slist->next)
5144 g_closure_invalidate (slist->data);
5145 g_closure_unref (slist->data);
5147 g_slist_free (closures);
5151 widget_new_accel_closure (GtkWidget *widget,
5154 AccelClosure *aclosure;
5155 GClosure *closure = NULL;
5156 GSList *slist, *closures;
5158 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5159 for (slist = closures; slist; slist = slist->next)
5160 if (!gtk_accel_group_from_accel_closure (slist->data))
5162 /* reuse this closure */
5163 closure = slist->data;
5168 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5169 closures = g_slist_prepend (closures, g_closure_ref (closure));
5170 g_closure_sink (closure);
5171 g_closure_set_marshal (closure, closure_accel_activate);
5173 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5175 aclosure = (AccelClosure*) closure;
5176 g_assert (closure->data == widget);
5177 g_assert (closure->marshal == closure_accel_activate);
5178 aclosure->signal_id = signal_id;
5184 * gtk_widget_add_accelerator
5185 * @widget: widget to install an accelerator on
5186 * @accel_signal: widget signal to emit on accelerator activation
5187 * @accel_group: accel group for this widget, added to its toplevel
5188 * @accel_key: GDK keyval of the accelerator
5189 * @accel_mods: modifier key combination of the accelerator
5190 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5192 * Installs an accelerator for this @widget in @accel_group that causes
5193 * @accel_signal to be emitted if the accelerator is activated.
5194 * The @accel_group needs to be added to the widget's toplevel via
5195 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5196 * Accelerators added through this function are not user changeable during
5197 * runtime. If you want to support accelerators that can be changed by the
5198 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5199 * gtk_menu_item_set_accel_path() instead.
5202 gtk_widget_add_accelerator (GtkWidget *widget,
5203 const gchar *accel_signal,
5204 GtkAccelGroup *accel_group,
5206 GdkModifierType accel_mods,
5207 GtkAccelFlags accel_flags)
5212 g_return_if_fail (GTK_IS_WIDGET (widget));
5213 g_return_if_fail (accel_signal != NULL);
5214 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5216 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5217 if (!query.signal_id ||
5218 !(query.signal_flags & G_SIGNAL_ACTION) ||
5219 query.return_type != G_TYPE_NONE ||
5222 /* hmm, should be elaborate enough */
5223 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5224 G_OBJECT_TYPE_NAME (widget), accel_signal);
5228 closure = widget_new_accel_closure (widget, query.signal_id);
5230 g_object_ref (widget);
5232 /* install the accelerator. since we don't map this onto an accel_path,
5233 * the accelerator will automatically be locked.
5235 gtk_accel_group_connect (accel_group,
5238 accel_flags | GTK_ACCEL_LOCKED,
5241 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5243 g_object_unref (widget);
5247 * gtk_widget_remove_accelerator:
5248 * @widget: widget to install an accelerator on
5249 * @accel_group: accel group for this widget
5250 * @accel_key: GDK keyval of the accelerator
5251 * @accel_mods: modifier key combination of the accelerator
5252 * @returns: whether an accelerator was installed and could be removed
5254 * Removes an accelerator from @widget, previously installed with
5255 * gtk_widget_add_accelerator().
5258 gtk_widget_remove_accelerator (GtkWidget *widget,
5259 GtkAccelGroup *accel_group,
5261 GdkModifierType accel_mods)
5263 GtkAccelGroupEntry *ag_entry;
5264 GList *slist, *clist;
5267 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5268 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5270 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5271 clist = gtk_widget_list_accel_closures (widget);
5272 for (slist = clist; slist; slist = slist->next)
5276 for (i = 0; i < n; i++)
5277 if (slist->data == (gpointer) ag_entry[i].closure)
5279 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5281 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5283 g_list_free (clist);
5288 g_list_free (clist);
5290 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5291 accel_key, accel_mods, accel_group,
5292 G_OBJECT_TYPE_NAME (widget), widget);
5298 * gtk_widget_list_accel_closures:
5299 * @widget: widget to list accelerator closures for
5301 * Lists the closures used by @widget for accelerator group connections
5302 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5303 * The closures can be used to monitor accelerator changes on @widget,
5304 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5305 * #GtkAccelGroup of a closure which can be found out with
5306 * gtk_accel_group_from_accel_closure().
5308 * Return value: (transfer container) (element-type GClosure):
5309 * a newly allocated #GList of closures
5312 gtk_widget_list_accel_closures (GtkWidget *widget)
5315 GList *clist = NULL;
5317 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5319 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5320 if (gtk_accel_group_from_accel_closure (slist->data))
5321 clist = g_list_prepend (clist, slist->data);
5327 GtkAccelGroup *accel_group;
5332 destroy_accel_path (gpointer data)
5334 AccelPath *apath = data;
5336 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5338 /* closures_destroy takes care of unrefing the closure */
5339 g_object_unref (apath->accel_group);
5341 g_slice_free (AccelPath, apath);
5346 * gtk_widget_set_accel_path:
5347 * @widget: a #GtkWidget
5348 * @accel_path: (allow-none): path used to look up the accelerator
5349 * @accel_group: (allow-none): a #GtkAccelGroup.
5351 * Given an accelerator group, @accel_group, and an accelerator path,
5352 * @accel_path, sets up an accelerator in @accel_group so whenever the
5353 * key binding that is defined for @accel_path is pressed, @widget
5354 * will be activated. This removes any accelerators (for any
5355 * accelerator group) installed by previous calls to
5356 * gtk_widget_set_accel_path(). Associating accelerators with
5357 * paths allows them to be modified by the user and the modifications
5358 * to be saved for future use. (See gtk_accel_map_save().)
5360 * This function is a low level function that would most likely
5361 * be used by a menu creation system like #GtkUIManager. If you
5362 * use #GtkUIManager, setting up accelerator paths will be done
5365 * Even when you you aren't using #GtkUIManager, if you only want to
5366 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5367 * provides a somewhat more convenient interface.
5369 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5370 * pass a static string, you can save some memory by interning it first with
5371 * g_intern_static_string().
5374 gtk_widget_set_accel_path (GtkWidget *widget,
5375 const gchar *accel_path,
5376 GtkAccelGroup *accel_group)
5380 g_return_if_fail (GTK_IS_WIDGET (widget));
5381 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5385 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5386 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5388 gtk_accel_map_add_entry (accel_path, 0, 0);
5389 apath = g_slice_new (AccelPath);
5390 apath->accel_group = g_object_ref (accel_group);
5391 apath->path_quark = g_quark_from_string (accel_path);
5392 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5397 /* also removes possible old settings */
5398 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5401 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5403 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5407 _gtk_widget_get_accel_path (GtkWidget *widget,
5412 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5414 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5416 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5417 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5421 * gtk_widget_mnemonic_activate:
5422 * @widget: a #GtkWidget
5423 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5425 * Emits the #GtkWidget::mnemonic-activate signal.
5427 * The default handler for this signal activates the @widget if
5428 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5431 * Returns: %TRUE if the signal has been handled
5434 gtk_widget_mnemonic_activate (GtkWidget *widget,
5435 gboolean group_cycling)
5439 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5441 group_cycling = group_cycling != FALSE;
5442 if (!gtk_widget_is_sensitive (widget))
5445 g_signal_emit (widget,
5446 widget_signals[MNEMONIC_ACTIVATE],
5454 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5455 gboolean group_cycling)
5457 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5458 gtk_widget_activate (widget);
5459 else if (gtk_widget_get_can_focus (widget))
5460 gtk_widget_grab_focus (widget);
5463 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5464 G_OBJECT_TYPE_NAME (widget));
5465 gtk_widget_error_bell (widget);
5470 static const cairo_user_data_key_t event_key;
5473 _gtk_cairo_get_event (cairo_t *cr)
5475 g_return_val_if_fail (cr != NULL, NULL);
5477 return cairo_get_user_data (cr, &event_key);
5481 gtk_cairo_set_event (cairo_t *cr,
5482 GdkEventExpose *event)
5484 cairo_set_user_data (cr, &event_key, event, NULL);
5488 * gtk_cairo_should_draw_window:
5489 * @cr: a cairo context
5490 * @window: the window to check
5492 * This function is supposed to be called in #GtkWidget::draw
5493 * implementations for widgets that support multiple windows.
5494 * @cr must be untransformed from invoking of the draw function.
5495 * This function will return %TRUE if the contents of the given
5496 * @window are supposed to be drawn and %FALSE otherwise. Note
5497 * that when the drawing was not initiated by the windowing
5498 * system this function will return %TRUE for all windows, so
5499 * you need to draw the bottommost window first. Also, do not
5500 * use "else if" statements to check which window should be drawn.
5502 * Returns: %TRUE if @window should be drawn
5505 gtk_cairo_should_draw_window (cairo_t *cr,
5508 GdkEventExpose *event;
5510 g_return_val_if_fail (cr != NULL, FALSE);
5511 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5513 event = _gtk_cairo_get_event (cr);
5515 return event == NULL ||
5516 event->window == window;
5519 /* code shared by gtk_container_propagate_draw() and
5523 _gtk_widget_draw_internal (GtkWidget *widget,
5525 gboolean clip_to_size)
5527 GtkStyleContext *context;
5529 if (!gtk_widget_is_drawable (widget))
5534 cairo_rectangle (cr,
5536 widget->priv->allocation.width,
5537 widget->priv->allocation.height);
5541 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5545 g_signal_emit (widget, widget_signals[DRAW],
5550 context = gtk_widget_get_style_context (widget);
5551 _gtk_style_context_coalesce_animation_areas (context,
5552 widget->priv->allocation.x,
5553 widget->priv->allocation.y);
5558 * @widget: the widget to draw. It must be drawable (see
5559 * gtk_widget_is_drawable()) and a size must have been allocated.
5560 * @cr: a cairo context to draw to
5562 * Draws @widget to @cr. The top left corner of the widget will be
5563 * drawn to the currently set origin point of @cr.
5565 * You should pass a cairo context as @cr argument that is in an
5566 * original state. Otherwise the resulting drawing is undefined. For
5567 * example changing the operator using cairo_set_operator() or the
5568 * line width using cairo_set_line_width() might have unwanted side
5570 * You may however change the context's transform matrix - like with
5571 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5572 * region with cairo_clip() prior to calling this function. Also, it
5573 * is fine to modify the context with cairo_save() and
5574 * cairo_push_group() prior to calling this function.
5576 * <note><para>Special purpose widgets may contain special code for
5577 * rendering to the screen and might appear differently on screen
5578 * and when rendered using gtk_widget_draw().</para></note>
5581 gtk_widget_draw (GtkWidget *widget,
5584 GdkEventExpose *tmp_event;
5586 g_return_if_fail (GTK_IS_WIDGET (widget));
5587 g_return_if_fail (!widget->priv->alloc_needed);
5588 g_return_if_fail (cr != NULL);
5591 /* We have to reset the event here so that draw functions can call
5592 * gtk_widget_draw() on random other widgets and get the desired
5593 * effect: Drawing all contents, not just the current window.
5595 tmp_event = _gtk_cairo_get_event (cr);
5596 gtk_cairo_set_event (cr, NULL);
5598 _gtk_widget_draw_internal (widget, cr, TRUE);
5600 gtk_cairo_set_event (cr, tmp_event);
5605 gtk_widget_real_key_press_event (GtkWidget *widget,
5608 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5612 gtk_widget_real_key_release_event (GtkWidget *widget,
5615 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5619 gtk_widget_real_focus_in_event (GtkWidget *widget,
5620 GdkEventFocus *event)
5622 gtk_widget_queue_shallow_draw (widget);
5628 gtk_widget_real_focus_out_event (GtkWidget *widget,
5629 GdkEventFocus *event)
5631 gtk_widget_queue_shallow_draw (widget);
5636 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5637 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5641 * @widget: a #GtkWidget
5642 * @event: a #GdkEvent
5644 * Rarely-used function. This function is used to emit
5645 * the event signals on a widget (those signals should never
5646 * be emitted without using this function to do so).
5647 * If you want to synthesize an event though, don't use this function;
5648 * instead, use gtk_main_do_event() so the event will behave as if
5649 * it were in the event queue. Don't synthesize expose events; instead,
5650 * use gdk_window_invalidate_rect() to invalidate a region of the
5653 * Return value: return from the event signal emission (%TRUE if
5654 * the event was handled)
5657 gtk_widget_event (GtkWidget *widget,
5660 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5661 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5663 if (event->type == GDK_EXPOSE)
5665 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5666 "the same effect, call gdk_window_invalidate_rect/region(), "
5667 "followed by gdk_window_process_updates().");
5671 return gtk_widget_event_internal (widget, event);
5674 /* Returns TRUE if a translation should be done */
5676 gtk_widget_get_translation_to_window (GtkWidget *widget,
5681 GdkWindow *w, *widget_window;
5683 if (!gtk_widget_get_has_window (widget))
5685 *x = -widget->priv->allocation.x;
5686 *y = -widget->priv->allocation.y;
5694 widget_window = gtk_widget_get_window (widget);
5696 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5699 gdk_window_get_position (w, &wx, &wy);
5716 * gtk_cairo_transform_to_window:
5717 * @cr: the cairo context to transform
5718 * @widget: the widget the context is currently centered for
5719 * @window: the window to transform the context to
5721 * Transforms the given cairo context @cr that from @widget-relative
5722 * coordinates to @window-relative coordinates.
5723 * If the @widget's window is not an ancestor of @window, no
5724 * modification will be applied.
5726 * This is the inverse to the transformation GTK applies when
5727 * preparing an expose event to be emitted with the #GtkWidget::draw
5728 * signal. It is intended to help porting multiwindow widgets from
5729 * GTK+ 2 to the rendering architecture of GTK+ 3.
5732 gtk_cairo_transform_to_window (cairo_t *cr,
5738 g_return_if_fail (cr != NULL);
5739 g_return_if_fail (GTK_IS_WIDGET (widget));
5740 g_return_if_fail (GDK_IS_WINDOW (window));
5742 if (gtk_widget_get_translation_to_window (widget, window, &x, &y))
5743 cairo_translate (cr, x, y);
5747 * gtk_widget_send_expose:
5748 * @widget: a #GtkWidget
5749 * @event: a expose #GdkEvent
5751 * Very rarely-used function. This function is used to emit
5752 * an expose event on a widget. This function is not normally used
5753 * directly. The only time it is used is when propagating an expose
5754 * event to a child %NO_WINDOW widget, and that is normally done
5755 * using gtk_container_propagate_draw().
5757 * If you want to force an area of a window to be redrawn,
5758 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5759 * To cause the redraw to be done immediately, follow that call
5760 * with a call to gdk_window_process_updates().
5762 * Return value: return from the event signal emission (%TRUE if
5763 * the event was handled)
5766 gtk_widget_send_expose (GtkWidget *widget,
5769 gboolean result = FALSE;
5774 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5775 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5776 g_return_val_if_fail (event != NULL, TRUE);
5777 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5779 cr = gdk_cairo_create (event->expose.window);
5780 gtk_cairo_set_event (cr, &event->expose);
5782 gdk_cairo_region (cr, event->expose.region);
5785 do_clip = gtk_widget_get_translation_to_window (widget,
5786 event->expose.window,
5788 cairo_translate (cr, -x, -y);
5790 _gtk_widget_draw_internal (widget, cr, do_clip);
5792 /* unset here, so if someone keeps a reference to cr we
5793 * don't leak the window. */
5794 gtk_cairo_set_event (cr, NULL);
5801 event_window_is_still_viewable (GdkEvent *event)
5803 /* Check that we think the event's window is viewable before
5804 * delivering the event, to prevent suprises. We do this here
5805 * at the last moment, since the event may have been queued
5806 * up behind other events, held over a recursive main loop, etc.
5808 switch (event->type)
5811 case GDK_MOTION_NOTIFY:
5812 case GDK_BUTTON_PRESS:
5813 case GDK_2BUTTON_PRESS:
5814 case GDK_3BUTTON_PRESS:
5816 case GDK_ENTER_NOTIFY:
5817 case GDK_PROXIMITY_IN:
5819 return event->any.window && gdk_window_is_viewable (event->any.window);
5822 /* The following events are the second half of paired events;
5823 * we always deliver them to deal with widgets that clean up
5824 * on the second half.
5826 case GDK_BUTTON_RELEASE:
5827 case GDK_KEY_RELEASE:
5828 case GDK_LEAVE_NOTIFY:
5829 case GDK_PROXIMITY_OUT:
5833 /* Remaining events would make sense on an not-viewable window,
5834 * or don't have an associated window.
5841 gtk_widget_event_internal (GtkWidget *widget,
5844 gboolean return_val = FALSE;
5846 /* We check only once for is-still-visible; if someone
5847 * hides the window in on of the signals on the widget,
5848 * they are responsible for returning TRUE to terminate
5851 if (!event_window_is_still_viewable (event))
5854 g_object_ref (widget);
5856 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5857 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5862 switch (event->type)
5867 case GDK_BUTTON_PRESS:
5868 case GDK_2BUTTON_PRESS:
5869 case GDK_3BUTTON_PRESS:
5870 signal_num = BUTTON_PRESS_EVENT;
5873 signal_num = SCROLL_EVENT;
5875 case GDK_BUTTON_RELEASE:
5876 signal_num = BUTTON_RELEASE_EVENT;
5878 case GDK_MOTION_NOTIFY:
5879 signal_num = MOTION_NOTIFY_EVENT;
5882 signal_num = DELETE_EVENT;
5885 signal_num = DESTROY_EVENT;
5886 _gtk_tooltip_hide (widget);
5889 signal_num = KEY_PRESS_EVENT;
5891 case GDK_KEY_RELEASE:
5892 signal_num = KEY_RELEASE_EVENT;
5894 case GDK_ENTER_NOTIFY:
5895 signal_num = ENTER_NOTIFY_EVENT;
5897 case GDK_LEAVE_NOTIFY:
5898 signal_num = LEAVE_NOTIFY_EVENT;
5900 case GDK_FOCUS_CHANGE:
5901 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
5902 if (event->focus_change.in)
5903 _gtk_tooltip_focus_in (widget);
5905 _gtk_tooltip_focus_out (widget);
5908 signal_num = CONFIGURE_EVENT;
5911 signal_num = MAP_EVENT;
5914 signal_num = UNMAP_EVENT;
5916 case GDK_WINDOW_STATE:
5917 signal_num = WINDOW_STATE_EVENT;
5919 case GDK_PROPERTY_NOTIFY:
5920 signal_num = PROPERTY_NOTIFY_EVENT;
5922 case GDK_SELECTION_CLEAR:
5923 signal_num = SELECTION_CLEAR_EVENT;
5925 case GDK_SELECTION_REQUEST:
5926 signal_num = SELECTION_REQUEST_EVENT;
5928 case GDK_SELECTION_NOTIFY:
5929 signal_num = SELECTION_NOTIFY_EVENT;
5931 case GDK_PROXIMITY_IN:
5932 signal_num = PROXIMITY_IN_EVENT;
5934 case GDK_PROXIMITY_OUT:
5935 signal_num = PROXIMITY_OUT_EVENT;
5937 case GDK_CLIENT_EVENT:
5938 signal_num = CLIENT_EVENT;
5941 signal_num = EXPOSE_EVENT;
5943 case GDK_VISIBILITY_NOTIFY:
5944 signal_num = VISIBILITY_NOTIFY_EVENT;
5946 case GDK_GRAB_BROKEN:
5947 signal_num = GRAB_BROKEN_EVENT;
5950 signal_num = DAMAGE_EVENT;
5953 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
5957 if (signal_num != -1)
5958 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
5960 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
5961 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
5965 g_object_unref (widget);
5971 * gtk_widget_activate:
5972 * @widget: a #GtkWidget that's activatable
5974 * For widgets that can be "activated" (buttons, menu items, etc.)
5975 * this function activates them. Activation is what happens when you
5976 * press Enter on a widget during key navigation. If @widget isn't
5977 * activatable, the function returns %FALSE.
5979 * Return value: %TRUE if the widget was activatable
5982 gtk_widget_activate (GtkWidget *widget)
5984 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5986 if (WIDGET_CLASS (widget)->activate_signal)
5988 /* FIXME: we should eventually check the signals signature here */
5989 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5998 gtk_widget_reparent_subwindows (GtkWidget *widget,
5999 GdkWindow *new_window)
6001 GtkWidgetPrivate *priv = widget->priv;
6003 if (!gtk_widget_get_has_window (widget))
6005 GList *children = gdk_window_get_children (priv->window);
6008 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6010 GdkWindow *window = tmp_list->data;
6013 gdk_window_get_user_data (window, &child);
6014 while (child && child != widget)
6015 child = ((GtkWidget*) child)->priv->parent;
6018 gdk_window_reparent (window, new_window, 0, 0);
6021 g_list_free (children);
6026 GList *tmp_list, *children;
6028 parent = gdk_window_get_parent (priv->window);
6031 gdk_window_reparent (priv->window, new_window, 0, 0);
6034 children = gdk_window_get_children (parent);
6036 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6038 GdkWindow *window = tmp_list->data;
6041 gdk_window_get_user_data (window, &child);
6043 if (child == widget)
6044 gdk_window_reparent (window, new_window, 0, 0);
6047 g_list_free (children);
6053 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6054 gpointer client_data)
6056 GtkWidgetPrivate *priv = widget->priv;
6058 g_assert (client_data != NULL);
6060 if (!gtk_widget_get_has_window (widget))
6063 g_object_unref (priv->window);
6064 priv->window = (GdkWindow*) client_data;
6066 g_object_ref (priv->window);
6068 if (GTK_IS_CONTAINER (widget))
6069 gtk_container_forall (GTK_CONTAINER (widget),
6070 gtk_widget_reparent_fixup_child,
6076 * gtk_widget_reparent:
6077 * @widget: a #GtkWidget
6078 * @new_parent: a #GtkContainer to move the widget into
6080 * Moves a widget from one #GtkContainer to another, handling reference
6081 * count issues to avoid destroying the widget.
6084 gtk_widget_reparent (GtkWidget *widget,
6085 GtkWidget *new_parent)
6087 GtkWidgetPrivate *priv;
6089 g_return_if_fail (GTK_IS_WIDGET (widget));
6090 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6091 priv = widget->priv;
6092 g_return_if_fail (priv->parent != NULL);
6094 if (priv->parent != new_parent)
6096 /* First try to see if we can get away without unrealizing
6097 * the widget as we reparent it. if so we set a flag so
6098 * that gtk_widget_unparent doesn't unrealize widget
6100 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6101 priv->in_reparent = TRUE;
6103 g_object_ref (widget);
6104 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6105 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6106 g_object_unref (widget);
6108 if (priv->in_reparent)
6110 priv->in_reparent = FALSE;
6112 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6113 gtk_widget_reparent_fixup_child (widget,
6114 gtk_widget_get_parent_window (widget));
6117 g_object_notify (G_OBJECT (widget), "parent");
6122 * gtk_widget_intersect:
6123 * @widget: a #GtkWidget
6124 * @area: a rectangle
6125 * @intersection: rectangle to store intersection of @widget and @area
6127 * Computes the intersection of a @widget's area and @area, storing
6128 * the intersection in @intersection, and returns %TRUE if there was
6129 * an intersection. @intersection may be %NULL if you're only
6130 * interested in whether there was an intersection.
6132 * Return value: %TRUE if there was an intersection
6135 gtk_widget_intersect (GtkWidget *widget,
6136 const GdkRectangle *area,
6137 GdkRectangle *intersection)
6139 GtkWidgetPrivate *priv;
6144 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6145 g_return_val_if_fail (area != NULL, FALSE);
6147 priv = widget->priv;
6150 dest = intersection;
6154 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6156 if (return_val && intersection && gtk_widget_get_has_window (widget))
6158 intersection->x -= priv->allocation.x;
6159 intersection->y -= priv->allocation.y;
6166 * gtk_widget_region_intersect:
6167 * @widget: a #GtkWidget
6168 * @region: a #cairo_region_t, in the same coordinate system as
6169 * @widget->allocation. That is, relative to @widget->window
6170 * for %NO_WINDOW widgets; relative to the parent window
6171 * of @widget->window for widgets with their own window.
6172 * @returns: A newly allocated region holding the intersection of @widget
6173 * and @region. The coordinates of the return value are
6174 * relative to @widget->window for %NO_WINDOW widgets, and
6175 * relative to the parent window of @widget->window for
6176 * widgets with their own window.
6178 * Computes the intersection of a @widget's area and @region, returning
6179 * the intersection. The result may be empty, use cairo_region_is_empty() to
6183 gtk_widget_region_intersect (GtkWidget *widget,
6184 const cairo_region_t *region)
6187 cairo_region_t *dest;
6189 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6190 g_return_val_if_fail (region != NULL, NULL);
6192 gtk_widget_get_allocation (widget, &rect);
6194 dest = cairo_region_create_rectangle (&rect);
6196 cairo_region_intersect (dest, region);
6202 * _gtk_widget_grab_notify:
6203 * @widget: a #GtkWidget
6204 * @was_grabbed: whether a grab is now in effect
6206 * Emits the #GtkWidget::grab-notify signal on @widget.
6211 _gtk_widget_grab_notify (GtkWidget *widget,
6212 gboolean was_grabbed)
6214 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6218 * gtk_widget_grab_focus:
6219 * @widget: a #GtkWidget
6221 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6222 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6223 * something like #GtkFrame won't work.
6225 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6226 * gtk_widget_set_can_focus() to modify that flag.
6228 * The widget also needs to be realized and mapped. This is indicated by the
6229 * related signals. Grabbing the focus immediately after creating the widget
6230 * will likely fail and cause critical warnings.
6233 gtk_widget_grab_focus (GtkWidget *widget)
6235 g_return_if_fail (GTK_IS_WIDGET (widget));
6237 if (!gtk_widget_is_sensitive (widget))
6240 g_object_ref (widget);
6241 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6242 g_object_notify (G_OBJECT (widget), "has-focus");
6243 g_object_unref (widget);
6247 reset_focus_recurse (GtkWidget *widget,
6250 if (GTK_IS_CONTAINER (widget))
6252 GtkContainer *container;
6254 container = GTK_CONTAINER (widget);
6255 gtk_container_set_focus_child (container, NULL);
6257 gtk_container_foreach (container,
6258 reset_focus_recurse,
6264 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6266 if (gtk_widget_get_can_focus (focus_widget))
6268 GtkWidget *toplevel;
6271 /* clear the current focus setting, break if the current widget
6272 * is the focus widget's parent, since containers above that will
6273 * be set by the next loop.
6275 toplevel = gtk_widget_get_toplevel (focus_widget);
6276 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6278 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6280 if (widget == focus_widget)
6282 /* We call _gtk_window_internal_set_focus() here so that the
6283 * toplevel window can request the focus if necessary.
6284 * This is needed when the toplevel is a GtkPlug
6286 if (!gtk_widget_has_focus (widget))
6287 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6294 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
6296 widget = widget->priv->parent;
6297 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6301 else if (toplevel != focus_widget)
6303 /* gtk_widget_grab_focus() operates on a tree without window...
6304 * actually, this is very questionable behaviour.
6307 gtk_container_foreach (GTK_CONTAINER (toplevel),
6308 reset_focus_recurse,
6312 /* now propagate the new focus up the widget tree and finally
6313 * set it on the window
6315 widget = focus_widget;
6316 while (widget->priv->parent)
6318 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6319 widget = widget->priv->parent;
6321 if (GTK_IS_WINDOW (widget))
6322 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6327 gtk_widget_real_query_tooltip (GtkWidget *widget,
6330 gboolean keyboard_tip,
6331 GtkTooltip *tooltip)
6333 gchar *tooltip_markup;
6334 gboolean has_tooltip;
6336 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6337 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6339 if (has_tooltip && tooltip_markup)
6341 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6349 gtk_widget_real_style_updated (GtkWidget *widget)
6351 if (widget->priv->context)
6352 gtk_style_context_invalidate (widget->priv->context);
6353 gtk_widget_queue_resize (widget);
6357 gtk_widget_real_show_help (GtkWidget *widget,
6358 GtkWidgetHelpType help_type)
6360 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6362 _gtk_tooltip_toggle_keyboard_mode (widget);
6371 gtk_widget_real_focus (GtkWidget *widget,
6372 GtkDirectionType direction)
6374 if (!gtk_widget_get_can_focus (widget))
6377 if (!gtk_widget_is_focus (widget))
6379 gtk_widget_grab_focus (widget);
6387 gtk_widget_real_move_focus (GtkWidget *widget,
6388 GtkDirectionType direction)
6390 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6392 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6394 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6400 gtk_widget_real_keynav_failed (GtkWidget *widget,
6401 GtkDirectionType direction)
6403 gboolean cursor_only;
6407 case GTK_DIR_TAB_FORWARD:
6408 case GTK_DIR_TAB_BACKWARD:
6415 g_object_get (gtk_widget_get_settings (widget),
6416 "gtk-keynav-cursor-only", &cursor_only,
6423 gtk_widget_error_bell (widget);
6429 * gtk_widget_set_can_focus:
6430 * @widget: a #GtkWidget
6431 * @can_focus: whether or not @widget can own the input focus.
6433 * Specifies whether @widget can own the input focus. See
6434 * gtk_widget_grab_focus() for actually setting the input focus on a
6440 gtk_widget_set_can_focus (GtkWidget *widget,
6443 g_return_if_fail (GTK_IS_WIDGET (widget));
6445 if (widget->priv->can_focus != can_focus)
6447 widget->priv->can_focus = can_focus;
6449 gtk_widget_queue_resize (widget);
6450 g_object_notify (G_OBJECT (widget), "can-focus");
6455 * gtk_widget_get_can_focus:
6456 * @widget: a #GtkWidget
6458 * Determines whether @widget can own the input focus. See
6459 * gtk_widget_set_can_focus().
6461 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6466 gtk_widget_get_can_focus (GtkWidget *widget)
6468 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6470 return widget->priv->can_focus;
6474 * gtk_widget_has_focus:
6475 * @widget: a #GtkWidget
6477 * Determines if the widget has the global input focus. See
6478 * gtk_widget_is_focus() for the difference between having the global
6479 * input focus, and only having the focus within a toplevel.
6481 * Return value: %TRUE if the widget has the global input focus.
6486 gtk_widget_has_focus (GtkWidget *widget)
6488 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6490 return widget->priv->has_focus;
6494 * gtk_widget_is_focus:
6495 * @widget: a #GtkWidget
6497 * Determines if the widget is the focus widget within its
6498 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6499 * necessarily set; %HAS_FOCUS will only be set if the
6500 * toplevel widget additionally has the global input focus.)
6502 * Return value: %TRUE if the widget is the focus widget.
6505 gtk_widget_is_focus (GtkWidget *widget)
6507 GtkWidget *toplevel;
6509 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6511 toplevel = gtk_widget_get_toplevel (widget);
6513 if (GTK_IS_WINDOW (toplevel))
6514 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6520 * gtk_widget_set_can_default:
6521 * @widget: a #GtkWidget
6522 * @can_default: whether or not @widget can be a default widget.
6524 * Specifies whether @widget can be a default widget. See
6525 * gtk_widget_grab_default() for details about the meaning of
6531 gtk_widget_set_can_default (GtkWidget *widget,
6532 gboolean can_default)
6534 g_return_if_fail (GTK_IS_WIDGET (widget));
6536 if (widget->priv->can_default != can_default)
6538 widget->priv->can_default = can_default;
6540 gtk_widget_queue_resize (widget);
6541 g_object_notify (G_OBJECT (widget), "can-default");
6546 * gtk_widget_get_can_default:
6547 * @widget: a #GtkWidget
6549 * Determines whether @widget can be a default widget. See
6550 * gtk_widget_set_can_default().
6552 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6557 gtk_widget_get_can_default (GtkWidget *widget)
6559 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6561 return widget->priv->can_default;
6565 * gtk_widget_has_default:
6566 * @widget: a #GtkWidget
6568 * Determines whether @widget is the current default widget within its
6569 * toplevel. See gtk_widget_set_can_default().
6571 * Return value: %TRUE if @widget is the current default widget within
6572 * its toplevel, %FALSE otherwise
6577 gtk_widget_has_default (GtkWidget *widget)
6579 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6581 return widget->priv->has_default;
6585 _gtk_widget_set_has_default (GtkWidget *widget,
6586 gboolean has_default)
6588 widget->priv->has_default = has_default;
6592 * gtk_widget_grab_default:
6593 * @widget: a #GtkWidget
6595 * Causes @widget to become the default widget. @widget must have the
6596 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6597 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6598 * %TRUE)</literal>. The default widget is activated when
6599 * the user presses Enter in a window. Default widgets must be
6600 * activatable, that is, gtk_widget_activate() should affect them. Note
6601 * that #GtkEntry widgets require the "activates-default" property
6602 * set to %TRUE before they activate the default widget when Enter
6603 * is pressed and the #GtkEntry is focused.
6606 gtk_widget_grab_default (GtkWidget *widget)
6610 g_return_if_fail (GTK_IS_WIDGET (widget));
6611 g_return_if_fail (gtk_widget_get_can_default (widget));
6613 window = gtk_widget_get_toplevel (widget);
6615 if (window && gtk_widget_is_toplevel (window))
6616 gtk_window_set_default (GTK_WINDOW (window), widget);
6618 g_warning (G_STRLOC ": widget not within a GtkWindow");
6622 * gtk_widget_set_receives_default:
6623 * @widget: a #GtkWidget
6624 * @receives_default: whether or not @widget can be a default widget.
6626 * Specifies whether @widget will be treated as the default widget
6627 * within its toplevel when it has the focus, even if another widget
6630 * See gtk_widget_grab_default() for details about the meaning of
6636 gtk_widget_set_receives_default (GtkWidget *widget,
6637 gboolean receives_default)
6639 g_return_if_fail (GTK_IS_WIDGET (widget));
6641 if (widget->priv->receives_default != receives_default)
6643 widget->priv->receives_default = receives_default;
6645 g_object_notify (G_OBJECT (widget), "receives-default");
6650 * gtk_widget_get_receives_default:
6651 * @widget: a #GtkWidget
6653 * Determines whether @widget is alyways treated as default widget
6654 * withing its toplevel when it has the focus, even if another widget
6657 * See gtk_widget_set_receives_default().
6659 * Return value: %TRUE if @widget acts as default widget when focussed,
6665 gtk_widget_get_receives_default (GtkWidget *widget)
6667 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6669 return widget->priv->receives_default;
6673 * gtk_widget_has_grab:
6674 * @widget: a #GtkWidget
6676 * Determines whether the widget is currently grabbing events, so it
6677 * is the only widget receiving input events (keyboard and mouse).
6679 * See also gtk_grab_add().
6681 * Return value: %TRUE if the widget is in the grab_widgets stack
6686 gtk_widget_has_grab (GtkWidget *widget)
6688 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6690 return widget->priv->has_grab;
6694 _gtk_widget_set_has_grab (GtkWidget *widget,
6697 widget->priv->has_grab = has_grab;
6701 * gtk_widget_device_is_shadowed:
6702 * @widget: a #GtkWidget
6703 * @device: a #GdkDevice
6705 * Returns %TRUE if @device has been shadowed by a GTK+
6706 * device grab on another widget, so it would stop sending
6707 * events to @widget. This may be used in the
6708 * #GtkWidget::grab-notify signal to check for specific
6709 * devices. See gtk_device_grab_add().
6711 * Returns: %TRUE if there is an ongoing grab on @device
6712 * by another #GtkWidget than @widget.
6717 gtk_widget_device_is_shadowed (GtkWidget *widget,
6720 GtkWindowGroup *group;
6721 GtkWidget *grab_widget, *toplevel;
6723 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6724 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6726 if (!gtk_widget_get_realized (widget))
6729 toplevel = gtk_widget_get_toplevel (widget);
6731 if (GTK_IS_WINDOW (toplevel))
6732 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6734 group = gtk_window_get_group (NULL);
6736 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6738 /* Widget not inside the hierarchy of grab_widget */
6740 widget != grab_widget &&
6741 !gtk_widget_is_ancestor (widget, grab_widget))
6744 grab_widget = gtk_window_group_get_current_grab (group);
6745 if (grab_widget && widget != grab_widget &&
6746 !gtk_widget_is_ancestor (widget, grab_widget))
6753 * gtk_widget_set_name:
6754 * @widget: a #GtkWidget
6755 * @name: name for the widget
6757 * Widgets can be named, which allows you to refer to them from a
6758 * gtkrc file. You can apply a style to widgets with a particular name
6759 * in the gtkrc file. See the documentation for gtkrc files (on the
6760 * same page as the docs for #GtkRcStyle).
6762 * Note that widget names are separated by periods in paths (see
6763 * gtk_widget_path()), so names with embedded periods may cause confusion.
6766 gtk_widget_set_name (GtkWidget *widget,
6769 GtkWidgetPrivate *priv;
6772 g_return_if_fail (GTK_IS_WIDGET (widget));
6774 priv = widget->priv;
6776 new_name = g_strdup (name);
6777 g_free (priv->name);
6778 priv->name = new_name;
6784 pos = gtk_widget_path_length (priv->path) - 1;
6785 gtk_widget_path_iter_set_name (priv->path, pos,
6790 gtk_style_context_set_path (priv->context, priv->path);
6793 gtk_widget_reset_rc_style (widget);
6795 g_object_notify (G_OBJECT (widget), "name");
6799 * gtk_widget_get_name:
6800 * @widget: a #GtkWidget
6802 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6803 * significance of widget names.
6805 * Return value: name of the widget. This string is owned by GTK+ and
6806 * should not be modified or freed
6808 G_CONST_RETURN gchar*
6809 gtk_widget_get_name (GtkWidget *widget)
6811 GtkWidgetPrivate *priv;
6813 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6815 priv = widget->priv;
6819 return G_OBJECT_TYPE_NAME (widget);
6823 _gtk_widget_update_state_flags (GtkWidget *widget,
6824 GtkStateFlags flags,
6827 GtkWidgetPrivate *priv;
6829 priv = widget->priv;
6831 /* Handle insensitive first, since it is propagated
6832 * differently throughout the widget hierarchy.
6834 if ((flags & GTK_STATE_FLAG_INSENSITIVE) !=
6835 (priv->state_flags & GTK_STATE_FLAG_INSENSITIVE))
6836 gtk_widget_set_sensitive (widget,
6837 operation != STATE_CHANGE_UNSET);
6839 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
6842 operation == STATE_CHANGE_REPLACE)
6847 data.operation = operation;
6848 data.use_forall = FALSE;
6851 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6853 data.parent_sensitive = TRUE;
6855 gtk_widget_propagate_state (widget, &data);
6857 if (gtk_widget_is_drawable (widget))
6858 gtk_widget_queue_draw (widget);
6863 * gtk_widget_set_state_flags:
6864 * @widget: a #GtkWidget
6865 * @flags: State flags to turn on
6866 * @clear: Whether to clear state before turning on @flags
6868 * This function is for use in widget implementations. Turns on flag
6869 * values in the current widget state (insensitive, prelighted, etc.).
6871 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
6872 * will be propagated down to all non-internal children if @widget is a
6873 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
6874 * down to all #GtkContainer children by different means than turning on the
6875 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
6876 * gtk_widget_is_sensitive() will make use of these.
6881 gtk_widget_set_state_flags (GtkWidget *widget,
6882 GtkStateFlags flags,
6885 g_return_if_fail (GTK_IS_WIDGET (widget));
6887 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
6888 (clear && widget->priv->state_flags == flags))
6892 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
6894 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
6898 * gtk_widget_unset_state_flags:
6899 * @widget: a #GtkWidget
6900 * @flags: State flags to turn off
6902 * This function is for use in widget implementations. Turns off flag
6903 * values for the current widget state (insensitive, prelighted, etc.).
6904 * See gtk_widget_set_state_flags().
6909 gtk_widget_unset_state_flags (GtkWidget *widget,
6910 GtkStateFlags flags)
6912 g_return_if_fail (GTK_IS_WIDGET (widget));
6914 if ((widget->priv->state_flags & flags) == 0)
6917 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
6921 * gtk_widget_get_state_flags:
6922 * @widget: a #GtkWidget
6924 * Returns the widget state as a flag set. It is worth mentioning
6925 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
6926 * returned, that is, also based on parent insensitivity, even if
6927 * @widget itself is sensitive.
6929 * Returns: The state flags for widget
6934 gtk_widget_get_state_flags (GtkWidget *widget)
6936 GtkStateFlags flags;
6938 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
6940 flags = widget->priv->state_flags;
6942 if (!gtk_widget_is_sensitive (widget))
6943 flags |= GTK_STATE_FLAG_INSENSITIVE;
6949 * gtk_widget_set_state:
6950 * @widget: a #GtkWidget
6951 * @state: new state for @widget
6953 * This function is for use in widget implementations. Sets the state
6954 * of a widget (insensitive, prelighted, etc.) Usually you should set
6955 * the state using wrapper functions such as gtk_widget_set_sensitive().
6957 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
6960 gtk_widget_set_state (GtkWidget *widget,
6963 GtkStateFlags flags;
6965 if (state == gtk_widget_get_state (widget))
6970 case GTK_STATE_ACTIVE:
6971 flags = GTK_STATE_FLAG_ACTIVE;
6973 case GTK_STATE_PRELIGHT:
6974 flags = GTK_STATE_FLAG_PRELIGHT;
6976 case GTK_STATE_SELECTED:
6977 flags = GTK_STATE_FLAG_SELECTED;
6979 case GTK_STATE_INSENSITIVE:
6980 flags = GTK_STATE_FLAG_INSENSITIVE;
6982 case GTK_STATE_INCONSISTENT:
6983 flags = GTK_STATE_FLAG_INCONSISTENT;
6985 case GTK_STATE_FOCUSED:
6986 flags = GTK_STATE_FLAG_FOCUSED;
6988 case GTK_STATE_NORMAL:
6994 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
6998 * gtk_widget_get_state:
6999 * @widget: a #GtkWidget
7001 * Returns the widget's state. See gtk_widget_set_state().
7003 * Returns: the state of @widget.
7007 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7010 gtk_widget_get_state (GtkWidget *widget)
7012 GtkStateFlags flags;
7014 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7016 flags = gtk_widget_get_state_flags (widget);
7018 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7019 return GTK_STATE_INSENSITIVE;
7020 else if (flags & GTK_STATE_FLAG_INCONSISTENT)
7021 return GTK_STATE_INCONSISTENT;
7022 else if (flags & GTK_STATE_FLAG_ACTIVE)
7023 return GTK_STATE_ACTIVE;
7024 else if (flags & GTK_STATE_FLAG_SELECTED)
7025 return GTK_STATE_SELECTED;
7026 else if (flags & GTK_STATE_FLAG_FOCUSED)
7027 return GTK_STATE_FOCUSED;
7028 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7029 return GTK_STATE_PRELIGHT;
7031 return GTK_STATE_NORMAL;
7035 * gtk_widget_set_visible:
7036 * @widget: a #GtkWidget
7037 * @visible: whether the widget should be shown or not
7039 * Sets the visibility state of @widget. Note that setting this to
7040 * %TRUE doesn't mean the widget is actually viewable, see
7041 * gtk_widget_get_visible().
7043 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7044 * but is nicer to use when the visibility of the widget depends on
7050 gtk_widget_set_visible (GtkWidget *widget,
7053 g_return_if_fail (GTK_IS_WIDGET (widget));
7055 if (visible != gtk_widget_get_visible (widget))
7058 gtk_widget_show (widget);
7060 gtk_widget_hide (widget);
7065 _gtk_widget_set_visible_flag (GtkWidget *widget,
7068 widget->priv->visible = visible;
7072 * gtk_widget_get_visible:
7073 * @widget: a #GtkWidget
7075 * Determines whether the widget is visible. Note that this doesn't
7076 * take into account whether the widget's parent is also visible
7077 * or the widget is obscured in any way.
7079 * See gtk_widget_set_visible().
7081 * Return value: %TRUE if the widget is visible
7086 gtk_widget_get_visible (GtkWidget *widget)
7088 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7090 return widget->priv->visible;
7094 * gtk_widget_set_has_window:
7095 * @widget: a #GtkWidget
7096 * @has_window: whether or not @widget has a window.
7098 * Specifies whether @widget has a #GdkWindow of its own. Note that
7099 * all realized widgets have a non-%NULL "window" pointer
7100 * (gtk_widget_get_window() never returns a %NULL window when a widget
7101 * is realized), but for many of them it's actually the #GdkWindow of
7102 * one of its parent widgets. Widgets that do not create a %window for
7103 * themselves in #GtkWidget::realize must announce this by
7104 * calling this function with @has_window = %FALSE.
7106 * This function should only be called by widget implementations,
7107 * and they should call it in their init() function.
7112 gtk_widget_set_has_window (GtkWidget *widget,
7113 gboolean has_window)
7115 g_return_if_fail (GTK_IS_WIDGET (widget));
7117 widget->priv->no_window = !has_window;
7121 * gtk_widget_get_has_window:
7122 * @widget: a #GtkWidget
7124 * Determines whether @widget has a #GdkWindow of its own. See
7125 * gtk_widget_set_has_window().
7127 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7132 gtk_widget_get_has_window (GtkWidget *widget)
7134 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7136 return ! widget->priv->no_window;
7140 * gtk_widget_is_toplevel:
7141 * @widget: a #GtkWidget
7143 * Determines whether @widget is a toplevel widget. Currently only
7144 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
7145 * widgets have no parent widget.
7147 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7152 gtk_widget_is_toplevel (GtkWidget *widget)
7154 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7156 return widget->priv->toplevel;
7160 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7161 gboolean is_toplevel)
7163 widget->priv->toplevel = is_toplevel;
7167 * gtk_widget_is_drawable:
7168 * @widget: a #GtkWidget
7170 * Determines whether @widget can be drawn to. A widget can be drawn
7171 * to if it is mapped and visible.
7173 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7178 gtk_widget_is_drawable (GtkWidget *widget)
7180 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7182 return (gtk_widget_get_visible (widget) &&
7183 gtk_widget_get_mapped (widget));
7187 * gtk_widget_get_realized:
7188 * @widget: a #GtkWidget
7190 * Determines whether @widget is realized.
7192 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7197 gtk_widget_get_realized (GtkWidget *widget)
7199 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7201 return widget->priv->realized;
7205 * gtk_widget_set_realized:
7206 * @widget: a #GtkWidget
7207 * @realized: %TRUE to mark the widget as realized
7209 * Marks the widget as being realized.
7211 * This function should only ever be called in a derived widget's
7212 * "realize" or "unrealize" implementation.
7217 gtk_widget_set_realized (GtkWidget *widget,
7220 g_return_if_fail (GTK_IS_WIDGET (widget));
7222 widget->priv->realized = realized;
7226 * gtk_widget_get_mapped:
7227 * @widget: a #GtkWidget
7229 * Whether the widget is mapped.
7231 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7236 gtk_widget_get_mapped (GtkWidget *widget)
7238 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7240 return widget->priv->mapped;
7244 * gtk_widget_set_mapped:
7245 * @widget: a #GtkWidget
7246 * @mapped: %TRUE to mark the widget as mapped
7248 * Marks the widget as being realized.
7250 * This function should only ever be called in a derived widget's
7251 * "map" or "unmap" implementation.
7256 gtk_widget_set_mapped (GtkWidget *widget,
7259 g_return_if_fail (GTK_IS_WIDGET (widget));
7261 widget->priv->mapped = mapped;
7265 * gtk_widget_set_app_paintable:
7266 * @widget: a #GtkWidget
7267 * @app_paintable: %TRUE if the application will paint on the widget
7269 * Sets whether the application intends to draw on the widget in
7270 * an #GtkWidget::draw handler.
7272 * This is a hint to the widget and does not affect the behavior of
7273 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7274 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7275 * the effect is to suppress default themed drawing of the widget's
7276 * background. (Children of the widget will still be drawn.) The application
7277 * is then entirely responsible for drawing the widget background.
7279 * Note that the background is still drawn when the widget is mapped.
7282 gtk_widget_set_app_paintable (GtkWidget *widget,
7283 gboolean app_paintable)
7285 g_return_if_fail (GTK_IS_WIDGET (widget));
7287 app_paintable = (app_paintable != FALSE);
7289 if (widget->priv->app_paintable != app_paintable)
7291 widget->priv->app_paintable = app_paintable;
7293 if (gtk_widget_is_drawable (widget))
7294 gtk_widget_queue_draw (widget);
7296 g_object_notify (G_OBJECT (widget), "app-paintable");
7301 * gtk_widget_get_app_paintable:
7302 * @widget: a #GtkWidget
7304 * Determines whether the application intends to draw on the widget in
7305 * an #GtkWidget::draw handler.
7307 * See gtk_widget_set_app_paintable()
7309 * Return value: %TRUE if the widget is app paintable
7314 gtk_widget_get_app_paintable (GtkWidget *widget)
7316 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7318 return widget->priv->app_paintable;
7322 * gtk_widget_set_double_buffered:
7323 * @widget: a #GtkWidget
7324 * @double_buffered: %TRUE to double-buffer a widget
7326 * Widgets are double buffered by default; you can use this function
7327 * to turn off the buffering. "Double buffered" simply means that
7328 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7329 * automatically around expose events sent to the
7330 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7331 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7332 * buffer to the screen. The result is that users see the window
7333 * update in one smooth step, and don't see individual graphics
7334 * primitives being rendered.
7336 * In very simple terms, double buffered widgets don't flicker,
7337 * so you would only use this function to turn off double buffering
7338 * if you had special needs and really knew what you were doing.
7340 * Note: if you turn off double-buffering, you have to handle
7341 * expose events, since even the clearing to the background color or
7342 * pixmap will not happen automatically (as it is done in
7343 * gdk_window_begin_paint()).
7346 gtk_widget_set_double_buffered (GtkWidget *widget,
7347 gboolean double_buffered)
7349 g_return_if_fail (GTK_IS_WIDGET (widget));
7351 double_buffered = (double_buffered != FALSE);
7353 if (widget->priv->double_buffered != double_buffered)
7355 widget->priv->double_buffered = double_buffered;
7357 g_object_notify (G_OBJECT (widget), "double-buffered");
7362 * gtk_widget_get_double_buffered:
7363 * @widget: a #GtkWidget
7365 * Determines whether the widget is double buffered.
7367 * See gtk_widget_set_double_buffered()
7369 * Return value: %TRUE if the widget is double buffered
7374 gtk_widget_get_double_buffered (GtkWidget *widget)
7376 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7378 return widget->priv->double_buffered;
7382 * gtk_widget_set_redraw_on_allocate:
7383 * @widget: a #GtkWidget
7384 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7385 * when it is allocated to a new size. Otherwise, only the
7386 * new portion of the widget will be redrawn.
7388 * Sets whether the entire widget is queued for drawing when its size
7389 * allocation changes. By default, this setting is %TRUE and
7390 * the entire widget is redrawn on every size change. If your widget
7391 * leaves the upper left unchanged when made bigger, turning this
7392 * setting off will improve performance.
7394 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7395 * off all allocation on resizing: the widget will not even redraw if
7396 * its position changes; this is to allow containers that don't draw
7397 * anything to avoid excess invalidations. If you set this flag on a
7398 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7399 * you are responsible for invalidating both the old and new allocation
7400 * of the widget when the widget is moved and responsible for invalidating
7401 * regions newly when the widget increases size.
7404 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7405 gboolean redraw_on_allocate)
7407 g_return_if_fail (GTK_IS_WIDGET (widget));
7409 widget->priv->redraw_on_alloc = redraw_on_allocate;
7413 * gtk_widget_set_sensitive:
7414 * @widget: a #GtkWidget
7415 * @sensitive: %TRUE to make the widget sensitive
7417 * Sets the sensitivity of a widget. A widget is sensitive if the user
7418 * can interact with it. Insensitive widgets are "grayed out" and the
7419 * user can't interact with them. Insensitive widgets are known as
7420 * "inactive", "disabled", or "ghosted" in some other toolkits.
7423 gtk_widget_set_sensitive (GtkWidget *widget,
7426 GtkWidgetPrivate *priv;
7429 g_return_if_fail (GTK_IS_WIDGET (widget));
7431 priv = widget->priv;
7433 sensitive = (sensitive != FALSE);
7435 if (widget->priv->sensitive == sensitive)
7438 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7442 widget->priv->sensitive = TRUE;
7443 data.operation = STATE_CHANGE_UNSET;
7447 widget->priv->sensitive = FALSE;
7448 data.operation = STATE_CHANGE_SET;
7451 data.use_forall = TRUE;
7454 data.parent_sensitive = gtk_widget_is_sensitive (priv->parent);
7456 data.parent_sensitive = TRUE;
7458 gtk_widget_propagate_state (widget, &data);
7460 if (gtk_widget_is_drawable (widget))
7461 gtk_widget_queue_draw (widget);
7463 g_object_notify (G_OBJECT (widget), "sensitive");
7467 * gtk_widget_get_sensitive:
7468 * @widget: a #GtkWidget
7470 * Returns the widget's sensitivity (in the sense of returning
7471 * the value that has been set using gtk_widget_set_sensitive()).
7473 * The effective sensitivity of a widget is however determined by both its
7474 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7476 * Returns: %TRUE if the widget is sensitive
7481 gtk_widget_get_sensitive (GtkWidget *widget)
7483 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7485 return widget->priv->sensitive;
7489 * gtk_widget_is_sensitive:
7490 * @widget: a #GtkWidget
7492 * Returns the widget's effective sensitivity, which means
7493 * it is sensitive itself and also its parent widget is sensntive
7495 * Returns: %TRUE if the widget is effectively sensitive
7500 gtk_widget_is_sensitive (GtkWidget *widget)
7502 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7504 return widget->priv->sensitive && widget->priv->parent_sensitive;
7508 _gtk_widget_update_path (GtkWidget *widget)
7510 if (widget->priv->path)
7512 gtk_widget_path_free (widget->priv->path);
7513 widget->priv->path = NULL;
7516 gtk_widget_get_path (widget);
7520 * gtk_widget_set_parent:
7521 * @widget: a #GtkWidget
7522 * @parent: parent container
7524 * This function is useful only when implementing subclasses of
7526 * Sets the container as the parent of @widget, and takes care of
7527 * some details such as updating the state and style of the child
7528 * to reflect its new location. The opposite function is
7529 * gtk_widget_unparent().
7532 gtk_widget_set_parent (GtkWidget *widget,
7535 GtkStateFlags parent_flags;
7536 GtkWidgetPrivate *priv;
7539 g_return_if_fail (GTK_IS_WIDGET (widget));
7540 g_return_if_fail (GTK_IS_WIDGET (parent));
7541 g_return_if_fail (widget != parent);
7543 priv = widget->priv;
7545 if (priv->parent != NULL)
7547 g_warning ("Can't set a parent on widget which has a parent\n");
7550 if (gtk_widget_is_toplevel (widget))
7552 g_warning ("Can't set a parent on a toplevel widget\n");
7556 /* keep this function in sync with gtk_menu_attach_to_widget()
7559 g_object_ref_sink (widget);
7560 priv->parent = parent;
7562 parent_flags = gtk_widget_get_state_flags (parent);
7564 /* Merge both old state and current parent state,
7565 * We don't want the insensitive flag to propagate
7566 * to the new child though */
7567 data.flags = parent_flags & ~GTK_STATE_FLAG_INSENSITIVE;
7568 data.flags |= priv->state_flags;
7570 data.operation = STATE_CHANGE_REPLACE;
7571 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
7572 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7573 gtk_widget_propagate_state (widget, &data);
7575 gtk_widget_reset_rc_styles (widget);
7577 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7578 if (priv->parent->priv->anchored)
7579 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7580 g_object_notify (G_OBJECT (widget), "parent");
7582 /* Enforce realized/mapped invariants
7584 if (gtk_widget_get_realized (priv->parent))
7585 gtk_widget_realize (widget);
7587 if (gtk_widget_get_visible (priv->parent) &&
7588 gtk_widget_get_visible (widget))
7590 if (gtk_widget_get_child_visible (widget) &&
7591 gtk_widget_get_mapped (priv->parent))
7592 gtk_widget_map (widget);
7594 gtk_widget_queue_resize (widget);
7597 /* child may cause parent's expand to change, if the child is
7598 * expanded. If child is not expanded, then it can't modify the
7599 * parent's expand. If the child becomes expanded later then it will
7600 * queue compute_expand then. This optimization plus defaulting
7601 * newly-constructed widgets to need_compute_expand=FALSE should
7602 * mean that initially building a widget tree doesn't have to keep
7603 * walking up setting need_compute_expand on parents over and over.
7605 * We can't change a parent to need to expand unless we're visible.
7607 if (gtk_widget_get_visible (widget) &&
7608 (priv->need_compute_expand ||
7609 priv->computed_hexpand ||
7610 priv->computed_vexpand))
7612 gtk_widget_queue_compute_expand (parent);
7615 if (widget->priv->context)
7617 _gtk_widget_update_path (widget);
7618 gtk_style_context_set_path (widget->priv->context, widget->priv->path);
7620 gtk_style_context_set_screen (widget->priv->context,
7621 gtk_widget_get_screen (widget));
7626 * gtk_widget_get_parent:
7627 * @widget: a #GtkWidget
7629 * Returns the parent container of @widget.
7631 * Return value: (transfer none): the parent container of @widget, or %NULL
7634 gtk_widget_get_parent (GtkWidget *widget)
7636 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7638 return widget->priv->parent;
7641 /*****************************************
7643 * see docs/styles.txt
7644 *****************************************/
7647 * gtk_widget_style_attach:
7648 * @widget: a #GtkWidget
7650 * This function attaches the widget's #GtkStyle to the widget's
7651 * #GdkWindow. It is a replacement for
7654 * widget->style = gtk_style_attach (widget->style, widget->window);
7657 * and should only ever be called in a derived widget's "realize"
7658 * implementation which does not chain up to its parent class'
7659 * "realize" implementation, because one of the parent classes
7660 * (finally #GtkWidget) would attach the style itself.
7665 gtk_widget_style_attach (GtkWidget *widget)
7667 GtkWidgetPrivate *priv;
7669 g_return_if_fail (GTK_IS_WIDGET (widget));
7670 g_return_if_fail (gtk_widget_get_realized (widget));
7672 priv = widget->priv;
7674 priv->style = gtk_style_attach (priv->style, priv->window);
7678 * gtk_widget_has_rc_style:
7679 * @widget: a #GtkWidget
7681 * Determines if the widget style has been looked up through the rc mechanism.
7683 * Returns: %TRUE if the widget has been looked up through the rc
7684 * mechanism, %FALSE otherwise.
7688 * Deprecated:3.0: Use #GtkStyleContext instead
7691 gtk_widget_has_rc_style (GtkWidget *widget)
7693 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7695 return widget->priv->rc_style;
7699 * gtk_widget_set_style:
7700 * @widget: a #GtkWidget
7701 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
7702 * gtk_widget_set_style() and go back to the default style
7704 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
7705 * want to use this function; it interacts badly with themes, because
7706 * themes work by replacing the #GtkStyle. Instead, use
7707 * gtk_widget_modify_style().
7709 * Deprecated:3.0: Use #GtkStyleContext instead
7712 gtk_widget_set_style (GtkWidget *widget,
7715 g_return_if_fail (GTK_IS_WIDGET (widget));
7719 gboolean initial_emission;
7721 initial_emission = !widget->priv->rc_style && !widget->priv->user_style;
7723 widget->priv->rc_style = FALSE;
7724 widget->priv->user_style = TRUE;
7726 gtk_widget_set_style_internal (widget, style, initial_emission);
7730 if (widget->priv->user_style)
7731 gtk_widget_reset_rc_style (widget);
7736 * gtk_widget_ensure_style:
7737 * @widget: a #GtkWidget
7739 * Ensures that @widget has a style (@widget->style). Not a very useful
7740 * function; most of the time, if you want the style, the widget is
7741 * realized, and realized widgets are guaranteed to have a style
7744 * Deprecated:3.0: Use #GtkStyleContext instead
7747 gtk_widget_ensure_style (GtkWidget *widget)
7749 g_return_if_fail (GTK_IS_WIDGET (widget));
7751 if (!widget->priv->style ||
7752 !gtk_style_has_context (widget->priv->style))
7756 style = g_object_new (GTK_TYPE_STYLE,
7757 "context", gtk_widget_get_style_context (widget),
7760 gtk_widget_set_style_internal (widget, style, TRUE);
7761 g_object_unref (style);
7765 if (!widget->priv->rc_style && !widget->priv->user_style)
7766 gtk_widget_reset_rc_style (widget);
7770 /* Look up the RC style for this widget, unsetting any user style that
7771 * may be in effect currently
7774 gtk_widget_reset_rc_style (GtkWidget *widget)
7776 GtkWidgetPrivate *priv = widget->priv;
7777 GtkStyle *new_style = NULL;
7778 gboolean initial_emission;
7780 initial_emission = !priv->rc_style && !priv->user_style;
7782 priv->user_style = FALSE;
7783 priv->rc_style = TRUE;
7785 if (gtk_widget_has_screen (widget))
7786 new_style = gtk_rc_get_style (widget);
7788 new_style = gtk_widget_get_default_style ();
7790 if (initial_emission || new_style != priv->style)
7791 gtk_widget_set_style_internal (widget, new_style, initial_emission);
7795 * gtk_widget_get_style:
7796 * @widget: a #GtkWidget
7798 * Simply an accessor function that returns @widget->style.
7800 * Return value: (transfer none): the widget's #GtkStyle
7802 * Deprecated:3.0: Use #GtkStyleContext instead
7805 gtk_widget_get_style (GtkWidget *widget)
7807 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7809 return widget->priv->style;
7813 * gtk_widget_modify_style:
7814 * @widget: a #GtkWidget
7815 * @style: the #GtkRcStyle holding the style modifications
7817 * Modifies style values on the widget. Modifications made using this
7818 * technique take precedence over style values set via an RC file,
7819 * however, they will be overriden if a style is explicitely set on
7820 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
7821 * is designed so each field can either be set or unset, so it is
7822 * possible, using this function, to modify some style values and
7823 * leave the others unchanged.
7825 * Note that modifications made with this function are not cumulative
7826 * with previous calls to gtk_widget_modify_style() or with such
7827 * functions as gtk_widget_modify_fg(). If you wish to retain
7828 * previous values, you must first call gtk_widget_get_modifier_style(),
7829 * make your modifications to the returned style, then call
7830 * gtk_widget_modify_style() with that style. On the other hand,
7831 * if you first call gtk_widget_modify_style(), subsequent calls
7832 * to such functions gtk_widget_modify_fg() will have a cumulative
7833 * effect with the initial modifications.
7835 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7838 gtk_widget_modify_style (GtkWidget *widget,
7841 g_return_if_fail (GTK_IS_WIDGET (widget));
7842 g_return_if_fail (GTK_IS_RC_STYLE (style));
7844 g_object_set_qdata_full (G_OBJECT (widget),
7846 gtk_rc_style_copy (style),
7847 (GDestroyNotify) g_object_unref);
7849 /* note that "style" may be invalid here if it was the old
7850 * modifier style and the only reference was our own.
7853 if (widget->priv->rc_style)
7854 gtk_widget_reset_rc_style (widget);
7858 * gtk_widget_get_modifier_style:
7859 * @widget: a #GtkWidget
7861 * Returns the current modifier style for the widget. (As set by
7862 * gtk_widget_modify_style().) If no style has previously set, a new
7863 * #GtkRcStyle will be created with all values unset, and set as the
7864 * modifier style for the widget. If you make changes to this rc
7865 * style, you must call gtk_widget_modify_style(), passing in the
7866 * returned rc style, to make sure that your changes take effect.
7868 * Caution: passing the style back to gtk_widget_modify_style() will
7869 * normally end up destroying it, because gtk_widget_modify_style() copies
7870 * the passed-in style and sets the copy as the new modifier style,
7871 * thus dropping any reference to the old modifier style. Add a reference
7872 * to the modifier style if you want to keep it alive.
7874 * Return value: (transfer none): the modifier style for the widget.
7875 * This rc style is owned by the widget. If you want to keep a
7876 * pointer to value this around, you must add a refcount using
7879 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7882 gtk_widget_get_modifier_style (GtkWidget *widget)
7884 GtkRcStyle *rc_style;
7886 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7888 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7892 rc_style = gtk_rc_style_new ();
7893 g_object_set_qdata_full (G_OBJECT (widget),
7896 (GDestroyNotify) g_object_unref);
7903 gtk_widget_modify_color_component (GtkWidget *widget,
7904 GtkRcFlags component,
7906 const GdkColor *color)
7908 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7915 rc_style->fg[state] = *color;
7918 rc_style->bg[state] = *color;
7921 rc_style->text[state] = *color;
7924 rc_style->base[state] = *color;
7927 g_assert_not_reached();
7930 rc_style->color_flags[state] |= component;
7933 rc_style->color_flags[state] &= ~component;
7935 gtk_widget_modify_style (widget, rc_style);
7939 modifier_style_changed (GtkModifierStyle *style,
7942 GtkStyleContext *context;
7944 context = gtk_widget_get_style_context (widget);
7945 gtk_style_context_invalidate (context);
7947 g_signal_emit (widget,
7948 widget_signals[STYLE_SET],
7950 widget->priv->style);
7953 static GtkModifierStyle *
7954 _gtk_widget_get_modifier_properties (GtkWidget *widget)
7956 GtkModifierStyle *style;
7958 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
7960 if (G_UNLIKELY (!style))
7962 GtkStyleContext *context;
7964 style = gtk_modifier_style_new ();
7965 g_object_set_qdata_full (G_OBJECT (widget),
7966 quark_modifier_style,
7968 (GDestroyNotify) g_object_unref);
7970 g_signal_connect (style, "changed",
7971 G_CALLBACK (modifier_style_changed), widget);
7973 context = gtk_widget_get_style_context (widget);
7975 gtk_style_context_add_provider (context,
7976 GTK_STYLE_PROVIDER (style),
7977 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
7984 * gtk_widget_override_color:
7985 * @widget: a #GtkWidget
7986 * @state: the state for which to set the color
7987 * @color: the color to assign, or %NULL to undo the effect
7988 * of previous calls to gtk_widget_override_color()
7990 * Sets the color to use for a widget. All other style values are left
7995 * This API is mostly meant as a quick way for applications to change a
7996 * widget appearance. If you are developing a widgets library and intend
7997 * this change to be themeable, it is better done by setting meaningful
7998 * CSS classes and regions in your widget/container implementation through
7999 * gtk_style_context_add_class() and gtk_style_context_add_region().
8002 * This way, your widget library can install a #GtkCssProvider with the
8003 * %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order to provide a
8004 * default styling for those widgets that need so, and this theming may
8005 * fully overridden by the user's theme.
8011 * Note that for complex widgets this may bring in
8012 * undesired results (such as uniform background color everywhere),
8013 * in these cases it is better to fully style such widgets through a
8014 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8022 gtk_widget_override_color (GtkWidget *widget,
8023 GtkStateFlags state,
8024 const GdkRGBA *color)
8026 GtkModifierStyle *style;
8028 g_return_if_fail (GTK_IS_WIDGET (widget));
8030 style = _gtk_widget_get_modifier_properties (widget);
8031 gtk_modifier_style_set_color (style, state, color);
8035 * gtk_widget_override_background_color:
8036 * @widget: a #GtkWidget
8037 * @state: the state for which to set the background color
8038 * @color: the color to assign, or %NULL to undo the effect
8039 * of previous calls to gtk_widget_override_background_color()
8041 * Sets the background color to use for a widget. All other style values
8042 * are left untouched. See gtk_widget_override_color().
8047 gtk_widget_override_background_color (GtkWidget *widget,
8048 GtkStateFlags state,
8049 const GdkRGBA *color)
8051 GtkModifierStyle *style;
8053 g_return_if_fail (GTK_IS_WIDGET (widget));
8055 style = _gtk_widget_get_modifier_properties (widget);
8056 gtk_modifier_style_set_background_color (style, state, color);
8060 * gtk_widget_override_font:
8061 * @widget: a #GtkWidget
8062 * @font_desc: the font descriptiong to use, or %NULL to undo
8063 * the effect of previous calls to
8064 * gtk_widget_override_font().
8066 * Sets the font to use for a widget. All other style values are
8067 * left untouched. See gtk_widget_override_color().
8072 gtk_widget_override_font (GtkWidget *widget,
8073 const PangoFontDescription *font_desc)
8075 GtkModifierStyle *style;
8077 g_return_if_fail (GTK_IS_WIDGET (widget));
8079 style = _gtk_widget_get_modifier_properties (widget);
8080 gtk_modifier_style_set_font (style, font_desc);
8084 * gtk_widget_override_symbolic_color:
8085 * @widget: a #GtkWidget
8086 * @name: the name of the symbolic color to modify
8087 * @color: (allow-none): the color to assign (does not need to be allocated),
8088 * or %NULL to undo the effect of previous calls to
8089 * gtk_widget_override_symbolic_color().
8091 * Sets a symbolic color for a widget, All other style values are left
8092 * untouched. See gtk_widget_override_color() for overriding the foreground
8093 * or background color.
8098 gtk_widget_override_symbolic_color (GtkWidget *widget,
8100 const GdkRGBA *color)
8102 GtkModifierStyle *style;
8104 g_return_if_fail (GTK_IS_WIDGET (widget));
8106 style = _gtk_widget_get_modifier_properties (widget);
8107 gtk_modifier_style_map_color (style, name, color);
8111 * gtk_widget_override_cursor:
8112 * @widget: a #GtkWidget
8113 * @primary: the color to use for primary cursor (does not need to be
8114 * allocated), or %NULL to undo the effect of previous calls to
8115 * of gtk_widget_override_cursor().
8116 * @secondary: the color to use for secondary cursor (does not need to be
8117 * allocated), or %NULL to undo the effect of previous calls to
8118 * of gtk_widget_override_cursor().
8120 * Sets the cursor color to use in a widget, overriding the
8121 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8122 * style properties. All other style values are left untouched.
8123 * See also gtk_widget_modify_style().
8125 * Note that the underlying properties have the #GdkColor type,
8126 * so the alpha value in @primary and @secondary will be ignored.
8131 gtk_widget_override_cursor (GtkWidget *widget,
8132 const GdkRGBA *cursor,
8133 const GdkRGBA *secondary_cursor)
8135 GtkModifierStyle *style;
8137 g_return_if_fail (GTK_IS_WIDGET (widget));
8139 style = _gtk_widget_get_modifier_properties (widget);
8140 gtk_modifier_style_set_color_property (style,
8142 "cursor-color", cursor);
8143 gtk_modifier_style_set_color_property (style,
8145 "secondary-cursor-color",
8150 * gtk_widget_modify_fg:
8151 * @widget: a #GtkWidget
8152 * @state: the state for which to set the foreground color
8153 * @color: (allow-none): the color to assign (does not need to be allocated),
8154 * or %NULL to undo the effect of previous calls to
8155 * of gtk_widget_modify_fg().
8157 * Sets the foreground color for a widget in a particular state.
8158 * All other style values are left untouched. See also
8159 * gtk_widget_modify_style().
8161 * Deprecated:3.0: Use gtk_widget_override_color() instead
8164 gtk_widget_modify_fg (GtkWidget *widget,
8166 const GdkColor *color)
8168 GtkStateFlags flags;
8171 g_return_if_fail (GTK_IS_WIDGET (widget));
8172 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8176 case GTK_STATE_ACTIVE:
8177 flags = GTK_STATE_FLAG_ACTIVE;
8179 case GTK_STATE_PRELIGHT:
8180 flags = GTK_STATE_FLAG_PRELIGHT;
8182 case GTK_STATE_SELECTED:
8183 flags = GTK_STATE_FLAG_SELECTED;
8185 case GTK_STATE_INSENSITIVE:
8186 flags = GTK_STATE_FLAG_INSENSITIVE;
8188 case GTK_STATE_NORMAL:
8195 rgba.red = color->red / 65535.;
8196 rgba.green = color->green / 65535.;
8197 rgba.blue = color->blue / 65535.;
8200 gtk_widget_override_color (widget, state, &rgba);
8203 gtk_widget_override_color (widget, state, NULL);
8207 * gtk_widget_modify_bg:
8208 * @widget: a #GtkWidget
8209 * @state: the state for which to set the background 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_bg().
8214 * Sets the background color for a widget in a particular state.
8215 * All other style values are left untouched. See also
8216 * gtk_widget_modify_style().
8218 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
8219 * draw on their parent container's window and thus may not draw any
8220 * background themselves. This is the case for e.g. #GtkLabel. To modify
8221 * the background of such widgets, you have to set the background color
8222 * on their parent; if you want to set the background of a rectangular
8223 * area around a label, try placing the label in a #GtkEventBox widget
8224 * and setting the background color on that.
8226 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8229 gtk_widget_modify_bg (GtkWidget *widget,
8231 const GdkColor *color)
8233 GtkStateFlags flags;
8236 g_return_if_fail (GTK_IS_WIDGET (widget));
8237 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8241 case GTK_STATE_ACTIVE:
8242 flags = GTK_STATE_FLAG_ACTIVE;
8244 case GTK_STATE_PRELIGHT:
8245 flags = GTK_STATE_FLAG_PRELIGHT;
8247 case GTK_STATE_SELECTED:
8248 flags = GTK_STATE_FLAG_SELECTED;
8250 case GTK_STATE_INSENSITIVE:
8251 flags = GTK_STATE_FLAG_INSENSITIVE;
8253 case GTK_STATE_NORMAL:
8260 rgba.red = color->red / 65535.;
8261 rgba.green = color->green / 65535.;
8262 rgba.blue = color->blue / 65535.;
8265 gtk_widget_override_background_color (widget, state, &rgba);
8268 gtk_widget_override_background_color (widget, state, NULL);
8272 * gtk_widget_modify_text:
8273 * @widget: a #GtkWidget
8274 * @state: the state for which to set the text color
8275 * @color: (allow-none): the color to assign (does not need to be allocated),
8276 * or %NULL to undo the effect of previous calls to
8277 * of gtk_widget_modify_text().
8279 * Sets the text color for a widget in a particular state. All other
8280 * style values are left untouched. The text color is the foreground
8281 * color used along with the base color (see gtk_widget_modify_base())
8282 * for widgets such as #GtkEntry and #GtkTextView. See also
8283 * gtk_widget_modify_style().
8285 * Deprecated:3.0: Use gtk_widget_override_color() instead
8288 gtk_widget_modify_text (GtkWidget *widget,
8290 const GdkColor *color)
8292 g_return_if_fail (GTK_IS_WIDGET (widget));
8293 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8295 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
8299 * gtk_widget_modify_base:
8300 * @widget: a #GtkWidget
8301 * @state: the state for which to set the base color
8302 * @color: (allow-none): the color to assign (does not need to be allocated),
8303 * or %NULL to undo the effect of previous calls to
8304 * of gtk_widget_modify_base().
8306 * Sets the base color for a widget in a particular state.
8307 * All other style values are left untouched. The base color
8308 * is the background color used along with the text color
8309 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
8310 * and #GtkTextView. See also gtk_widget_modify_style().
8312 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
8313 * draw on their parent container's window and thus may not draw any
8314 * background themselves. This is the case for e.g. #GtkLabel. To modify
8315 * the background of such widgets, you have to set the base color on their
8316 * parent; if you want to set the background of a rectangular area around
8317 * a label, try placing the label in a #GtkEventBox widget and setting
8318 * the base color on that.
8320 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8323 gtk_widget_modify_base (GtkWidget *widget,
8325 const GdkColor *color)
8327 g_return_if_fail (GTK_IS_WIDGET (widget));
8328 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8330 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
8334 * gtk_widget_modify_cursor:
8335 * @widget: a #GtkWidget
8336 * @primary: the color to use for primary cursor (does not need to be
8337 * allocated), or %NULL to undo the effect of previous calls to
8338 * of gtk_widget_modify_cursor().
8339 * @secondary: the color to use for secondary cursor (does not need to be
8340 * allocated), or %NULL to undo the effect of previous calls to
8341 * of gtk_widget_modify_cursor().
8343 * Sets the cursor color to use in a widget, overriding the
8344 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8345 * style properties. All other style values are left untouched.
8346 * See also gtk_widget_modify_style().
8350 * Deprecated: 3.0. Use gtk_widget_override_cursor() instead.
8353 gtk_widget_modify_cursor (GtkWidget *widget,
8354 const GdkColor *primary,
8355 const GdkColor *secondary)
8357 GdkRGBA primary_rgba, secondary_rgba;
8359 g_return_if_fail (GTK_IS_WIDGET (widget));
8361 primary_rgba.red = primary->red / 65535.;
8362 primary_rgba.green = primary->green / 65535.;
8363 primary_rgba.blue = primary->blue / 65535.;
8364 primary_rgba.alpha = 1;
8366 secondary_rgba.red = secondary->red / 65535.;
8367 secondary_rgba.green = secondary->green / 65535.;
8368 secondary_rgba.blue = secondary->blue / 65535.;
8369 secondary_rgba.alpha = 1;
8371 gtk_widget_override_cursor (widget, &primary_rgba, &secondary_rgba);
8375 * gtk_widget_modify_font:
8376 * @widget: a #GtkWidget
8377 * @font_desc: (allow-none): the font description to use, or %NULL to undo
8378 * the effect of previous calls to gtk_widget_modify_font().
8380 * Sets the font to use for a widget. All other style values are left
8381 * untouched. See also gtk_widget_modify_style().
8383 * Deprecated:3.0: Use gtk_widget_override_font() instead
8386 gtk_widget_modify_font (GtkWidget *widget,
8387 PangoFontDescription *font_desc)
8389 g_return_if_fail (GTK_IS_WIDGET (widget));
8391 gtk_widget_override_font (widget, font_desc);
8395 gtk_widget_real_direction_changed (GtkWidget *widget,
8396 GtkTextDirection previous_direction)
8398 gtk_widget_queue_resize (widget);
8402 gtk_widget_real_style_set (GtkWidget *widget,
8403 GtkStyle *previous_style)
8405 GtkWidgetPrivate *priv = widget->priv;
8407 if (gtk_widget_get_realized (widget) &&
8408 gtk_widget_get_has_window (widget))
8409 gtk_style_set_background (priv->style, priv->window,
8410 gtk_widget_get_state (widget));
8414 gtk_widget_set_style_internal (GtkWidget *widget,
8416 gboolean initial_emission)
8418 GtkWidgetPrivate *priv = widget->priv;
8420 g_object_ref (widget);
8421 g_object_freeze_notify (G_OBJECT (widget));
8423 if (priv->style != style)
8425 GtkStyle *previous_style;
8427 if (gtk_widget_get_realized (widget))
8429 gtk_widget_reset_shapes (widget);
8430 gtk_style_detach (priv->style);
8433 previous_style = priv->style;
8434 priv->style = style;
8435 g_object_ref (priv->style);
8437 if (gtk_widget_get_realized (widget))
8438 priv->style = gtk_style_attach (priv->style, priv->window);
8440 gtk_widget_update_pango_context (widget);
8441 g_signal_emit (widget,
8442 widget_signals[STYLE_SET],
8444 initial_emission ? NULL : previous_style);
8445 g_object_unref (previous_style);
8447 if (priv->anchored && !initial_emission)
8448 gtk_widget_queue_resize (widget);
8450 else if (initial_emission)
8452 gtk_widget_update_pango_context (widget);
8453 g_signal_emit (widget,
8454 widget_signals[STYLE_SET],
8458 g_object_notify (G_OBJECT (widget), "style");
8459 g_object_thaw_notify (G_OBJECT (widget));
8460 g_object_unref (widget);
8464 GtkWidget *previous_toplevel;
8465 GdkScreen *previous_screen;
8466 GdkScreen *new_screen;
8467 } HierarchyChangedInfo;
8470 do_screen_change (GtkWidget *widget,
8471 GdkScreen *old_screen,
8472 GdkScreen *new_screen)
8474 if (old_screen != new_screen)
8476 GtkStyleContext *context;
8480 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8482 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8485 _gtk_tooltip_hide (widget);
8487 context = gtk_widget_get_style_context (widget);
8488 gtk_style_context_set_screen (context, gtk_widget_get_screen (widget));
8490 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8495 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8496 gpointer client_data)
8498 GtkWidgetPrivate *priv = widget->priv;
8499 HierarchyChangedInfo *info = client_data;
8500 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8501 (priv->parent && priv->parent->priv->anchored);
8503 if (priv->anchored != new_anchored)
8505 g_object_ref (widget);
8507 priv->anchored = new_anchored;
8509 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8510 do_screen_change (widget, info->previous_screen, info->new_screen);
8512 if (GTK_IS_CONTAINER (widget))
8513 gtk_container_forall (GTK_CONTAINER (widget),
8514 gtk_widget_propagate_hierarchy_changed_recurse,
8517 g_object_unref (widget);
8522 * _gtk_widget_propagate_hierarchy_changed:
8523 * @widget: a #GtkWidget
8524 * @previous_toplevel: Previous toplevel
8526 * Propagates changes in the anchored state to a widget and all
8527 * children, unsetting or setting the %ANCHORED flag, and
8528 * emitting #GtkWidget::hierarchy-changed.
8531 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8532 GtkWidget *previous_toplevel)
8534 GtkWidgetPrivate *priv = widget->priv;
8535 HierarchyChangedInfo info;
8537 info.previous_toplevel = previous_toplevel;
8538 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8540 if (gtk_widget_is_toplevel (widget) ||
8541 (priv->parent && priv->parent->priv->anchored))
8542 info.new_screen = gtk_widget_get_screen (widget);
8544 info.new_screen = NULL;
8546 if (info.previous_screen)
8547 g_object_ref (info.previous_screen);
8548 if (previous_toplevel)
8549 g_object_ref (previous_toplevel);
8551 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8553 if (previous_toplevel)
8554 g_object_unref (previous_toplevel);
8555 if (info.previous_screen)
8556 g_object_unref (info.previous_screen);
8560 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8561 gpointer client_data)
8563 HierarchyChangedInfo *info = client_data;
8565 g_object_ref (widget);
8567 do_screen_change (widget, info->previous_screen, info->new_screen);
8569 if (GTK_IS_CONTAINER (widget))
8570 gtk_container_forall (GTK_CONTAINER (widget),
8571 gtk_widget_propagate_screen_changed_recurse,
8574 g_object_unref (widget);
8578 * gtk_widget_is_composited:
8579 * @widget: a #GtkWidget
8581 * Whether @widget can rely on having its alpha channel
8582 * drawn correctly. On X11 this function returns whether a
8583 * compositing manager is running for @widget's screen.
8585 * Please note that the semantics of this call will change
8586 * in the future if used on a widget that has a composited
8587 * window in its hierarchy (as set by gdk_window_set_composited()).
8589 * Return value: %TRUE if the widget can rely on its alpha
8590 * channel being drawn correctly.
8595 gtk_widget_is_composited (GtkWidget *widget)
8599 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8601 screen = gtk_widget_get_screen (widget);
8603 return gdk_screen_is_composited (screen);
8607 propagate_composited_changed (GtkWidget *widget,
8610 if (GTK_IS_CONTAINER (widget))
8612 gtk_container_forall (GTK_CONTAINER (widget),
8613 propagate_composited_changed,
8617 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8621 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8623 propagate_composited_changed (widget, NULL);
8627 * _gtk_widget_propagate_screen_changed:
8628 * @widget: a #GtkWidget
8629 * @previous_screen: Previous screen
8631 * Propagates changes in the screen for a widget to all
8632 * children, emitting #GtkWidget::screen-changed.
8635 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8636 GdkScreen *previous_screen)
8638 HierarchyChangedInfo info;
8640 info.previous_screen = previous_screen;
8641 info.new_screen = gtk_widget_get_screen (widget);
8643 if (previous_screen)
8644 g_object_ref (previous_screen);
8646 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8648 if (previous_screen)
8649 g_object_unref (previous_screen);
8653 reset_style_recurse (GtkWidget *widget, gpointer data)
8656 if (widget->priv->rc_style)
8657 gtk_widget_reset_rc_style (widget);
8660 if (widget->priv->context)
8662 _gtk_widget_update_path (widget);
8663 gtk_style_context_set_path (widget->priv->context,
8664 widget->priv->path);
8667 if (GTK_IS_CONTAINER (widget))
8668 gtk_container_forall (GTK_CONTAINER (widget),
8669 reset_style_recurse,
8674 gtk_widget_reset_style (GtkWidget *widget)
8676 g_return_if_fail (GTK_IS_WIDGET (widget));
8678 reset_style_recurse (widget, NULL);
8682 * gtk_widget_reset_rc_styles:
8683 * @widget: a #GtkWidget.
8685 * Reset the styles of @widget and all descendents, so when
8686 * they are looked up again, they get the correct values
8687 * for the currently loaded RC file settings.
8689 * This function is not useful for applications.
8691 * Deprecated:3.0: Use #GtkStyleContext instead
8694 gtk_widget_reset_rc_styles (GtkWidget *widget)
8696 g_return_if_fail (GTK_IS_WIDGET (widget));
8698 reset_style_recurse (widget, NULL);
8702 * gtk_widget_get_default_style:
8704 * Returns the default style used by all widgets initially.
8706 * Returns: (transfer none): the default style. This #GtkStyle
8707 * object is owned by GTK+ and should not be modified or freed.
8709 * Deprecated:3.0: Use #GtkStyleContext instead
8712 gtk_widget_get_default_style (void)
8714 if (!gtk_default_style)
8716 gtk_default_style = gtk_style_new ();
8717 g_object_ref (gtk_default_style);
8720 return gtk_default_style;
8723 static PangoContext *
8724 gtk_widget_peek_pango_context (GtkWidget *widget)
8726 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8730 * gtk_widget_get_pango_context:
8731 * @widget: a #GtkWidget
8733 * Gets a #PangoContext with the appropriate font map, font description,
8734 * and base direction for this widget. Unlike the context returned
8735 * by gtk_widget_create_pango_context(), this context is owned by
8736 * the widget (it can be used until the screen for the widget changes
8737 * or the widget is removed from its toplevel), and will be updated to
8738 * match any changes to the widget's attributes.
8740 * If you create and keep a #PangoLayout using this context, you must
8741 * deal with changes to the context by calling pango_layout_context_changed()
8742 * on the layout in response to the #GtkWidget::style-set and
8743 * #GtkWidget::direction-changed signals for the widget.
8745 * Return value: (transfer none): the #PangoContext for the widget.
8748 gtk_widget_get_pango_context (GtkWidget *widget)
8750 PangoContext *context;
8752 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8754 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8757 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8758 g_object_set_qdata_full (G_OBJECT (widget),
8759 quark_pango_context,
8768 update_pango_context (GtkWidget *widget,
8769 PangoContext *context)
8771 PangoFontDescription *font_desc;
8772 GtkStyleContext *style_context;
8774 style_context = gtk_widget_get_style_context (widget);
8776 gtk_style_context_get (style_context,
8777 gtk_widget_get_state_flags (widget),
8781 pango_context_set_font_description (context, font_desc);
8782 pango_context_set_base_dir (context,
8783 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8784 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8786 pango_font_description_free (font_desc);
8790 gtk_widget_update_pango_context (GtkWidget *widget)
8792 PangoContext *context = gtk_widget_peek_pango_context (widget);
8798 update_pango_context (widget, context);
8800 screen = gtk_widget_get_screen_unchecked (widget);
8803 pango_cairo_context_set_resolution (context,
8804 gdk_screen_get_resolution (screen));
8805 pango_cairo_context_set_font_options (context,
8806 gdk_screen_get_font_options (screen));
8812 * gtk_widget_create_pango_context:
8813 * @widget: a #GtkWidget
8815 * Creates a new #PangoContext with the appropriate font map,
8816 * font description, and base direction for drawing text for
8817 * this widget. See also gtk_widget_get_pango_context().
8819 * Return value: (transfer full): the new #PangoContext
8822 gtk_widget_create_pango_context (GtkWidget *widget)
8825 PangoContext *context;
8827 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8829 screen = gtk_widget_get_screen_unchecked (widget);
8832 GTK_NOTE (MULTIHEAD,
8833 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8835 screen = gdk_screen_get_default ();
8838 context = gdk_pango_context_get_for_screen (screen);
8840 update_pango_context (widget, context);
8841 pango_context_set_language (context, gtk_get_default_language ());
8847 * gtk_widget_create_pango_layout:
8848 * @widget: a #GtkWidget
8849 * @text: text to set on the layout (can be %NULL)
8851 * Creates a new #PangoLayout with the appropriate font map,
8852 * font description, and base direction for drawing text for
8855 * If you keep a #PangoLayout created in this way around, in order to
8856 * notify the layout of changes to the base direction or font of this
8857 * widget, you must call pango_layout_context_changed() in response to
8858 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
8861 * Return value: (transfer full): the new #PangoLayout
8864 gtk_widget_create_pango_layout (GtkWidget *widget,
8867 PangoLayout *layout;
8868 PangoContext *context;
8870 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8872 context = gtk_widget_get_pango_context (widget);
8873 layout = pango_layout_new (context);
8876 pango_layout_set_text (layout, text, -1);
8882 * gtk_widget_render_icon_pixbuf:
8883 * @widget: a #GtkWidget
8884 * @stock_id: a stock ID
8885 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8886 * render at the size of the source and don't scale (if there are
8887 * multiple source sizes, GTK+ picks one of the available sizes).
8889 * A convenience function that uses the theme engine and style
8890 * settings for @widget to look up @stock_id and render it to
8891 * a pixbuf. @stock_id should be a stock icon ID such as
8892 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8893 * such as #GTK_ICON_SIZE_MENU.
8895 * The pixels in the returned #GdkPixbuf are shared with the rest of
8896 * the application and should not be modified. The pixbuf should be freed
8897 * after use with g_object_unref().
8899 * Return value: (transfer full): a new pixbuf, or %NULL if the
8900 * stock ID wasn't known
8905 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
8906 const gchar *stock_id,
8909 GtkWidgetPrivate *priv;
8910 GtkIconSet *icon_set;
8912 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8913 g_return_val_if_fail (stock_id != NULL, NULL);
8914 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8916 priv = widget->priv;
8918 gtk_widget_ensure_style (widget);
8920 icon_set = gtk_style_context_lookup_icon_set (priv->context, stock_id);
8922 if (icon_set == NULL)
8925 return gtk_icon_set_render_icon_pixbuf (icon_set, priv->context, size);
8929 * gtk_widget_render_icon:
8930 * @widget: a #GtkWidget
8931 * @stock_id: a stock ID
8932 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8933 * render at the size of the source and don't scale (if there are
8934 * multiple source sizes, GTK+ picks one of the available sizes).
8935 * @detail: (allow-none): render detail to pass to theme engine
8937 * A convenience function that uses the theme engine and RC file
8938 * settings for @widget to look up @stock_id and render it to
8939 * a pixbuf. @stock_id should be a stock icon ID such as
8940 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8941 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
8942 * identifies the widget or code doing the rendering, so that
8943 * theme engines can special-case rendering for that widget or code.
8945 * The pixels in the returned #GdkPixbuf are shared with the rest of
8946 * the application and should not be modified. The pixbuf should be freed
8947 * after use with g_object_unref().
8949 * Return value: (transfer full): a new pixbuf, or %NULL if the
8950 * stock ID wasn't known
8952 * Deprecated: 3.0: Use gtk_widget_render_icon_pixbuf() instead.
8955 gtk_widget_render_icon (GtkWidget *widget,
8956 const gchar *stock_id,
8958 const gchar *detail)
8960 return gtk_widget_render_icon_pixbuf (widget, stock_id, size);
8964 * gtk_widget_set_parent_window:
8965 * @widget: a #GtkWidget.
8966 * @parent_window: the new parent window.
8968 * Sets a non default parent window for @widget.
8971 gtk_widget_set_parent_window (GtkWidget *widget,
8972 GdkWindow *parent_window)
8974 GdkWindow *old_parent_window;
8976 g_return_if_fail (GTK_IS_WIDGET (widget));
8978 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8979 quark_parent_window);
8981 if (parent_window != old_parent_window)
8983 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8985 if (old_parent_window)
8986 g_object_unref (old_parent_window);
8988 g_object_ref (parent_window);
8993 * gtk_widget_get_parent_window:
8994 * @widget: a #GtkWidget.
8996 * Gets @widget's parent window.
8998 * Returns: (transfer none): the parent window of @widget.
9001 gtk_widget_get_parent_window (GtkWidget *widget)
9003 GtkWidgetPrivate *priv;
9004 GdkWindow *parent_window;
9006 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9008 priv = widget->priv;
9010 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
9012 return (parent_window != NULL) ? parent_window :
9013 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
9018 * gtk_widget_set_child_visible:
9019 * @widget: a #GtkWidget
9020 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
9022 * Sets whether @widget should be mapped along with its when its parent
9023 * is mapped and @widget has been shown with gtk_widget_show().
9025 * The child visibility can be set for widget before it is added to
9026 * a container with gtk_widget_set_parent(), to avoid mapping
9027 * children unnecessary before immediately unmapping them. However
9028 * it will be reset to its default state of %TRUE when the widget
9029 * is removed from a container.
9031 * Note that changing the child visibility of a widget does not
9032 * queue a resize on the widget. Most of the time, the size of
9033 * a widget is computed from all visible children, whether or
9034 * not they are mapped. If this is not the case, the container
9035 * can queue a resize itself.
9037 * This function is only useful for container implementations and
9038 * never should be called by an application.
9041 gtk_widget_set_child_visible (GtkWidget *widget,
9042 gboolean is_visible)
9044 GtkWidgetPrivate *priv;
9046 g_return_if_fail (GTK_IS_WIDGET (widget));
9047 g_return_if_fail (!gtk_widget_is_toplevel (widget));
9049 priv = widget->priv;
9051 g_object_ref (widget);
9054 priv->child_visible = TRUE;
9057 GtkWidget *toplevel;
9059 priv->child_visible = FALSE;
9061 toplevel = gtk_widget_get_toplevel (widget);
9062 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
9063 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
9066 if (priv->parent && gtk_widget_get_realized (priv->parent))
9068 if (gtk_widget_get_mapped (priv->parent) &&
9069 priv->child_visible &&
9070 gtk_widget_get_visible (widget))
9071 gtk_widget_map (widget);
9073 gtk_widget_unmap (widget);
9076 g_object_unref (widget);
9080 * gtk_widget_get_child_visible:
9081 * @widget: a #GtkWidget
9083 * Gets the value set with gtk_widget_set_child_visible().
9084 * If you feel a need to use this function, your code probably
9085 * needs reorganization.
9087 * This function is only useful for container implementations and
9088 * never should be called by an application.
9090 * Return value: %TRUE if the widget is mapped with the parent.
9093 gtk_widget_get_child_visible (GtkWidget *widget)
9095 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9097 return widget->priv->child_visible;
9101 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9103 GtkWidget *toplevel;
9105 toplevel = gtk_widget_get_toplevel (widget);
9107 if (gtk_widget_is_toplevel (toplevel))
9109 if (GTK_IS_WINDOW (toplevel))
9110 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9111 else if (GTK_IS_INVISIBLE (toplevel))
9112 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9119 * gtk_widget_get_screen:
9120 * @widget: a #GtkWidget
9122 * Get the #GdkScreen from the toplevel window associated with
9123 * this widget. This function can only be called after the widget
9124 * has been added to a widget hierarchy with a #GtkWindow
9127 * In general, you should only create screen specific
9128 * resources when a widget has been realized, and you should
9129 * free those resources when the widget is unrealized.
9131 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9136 gtk_widget_get_screen (GtkWidget *widget)
9140 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9142 screen = gtk_widget_get_screen_unchecked (widget);
9149 g_warning (G_STRLOC ": Can't get associated screen"
9150 " for a widget unless it is inside a toplevel GtkWindow\n"
9151 " widget type is %s associated top level type is %s",
9152 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9153 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9155 return gdk_screen_get_default ();
9160 * gtk_widget_has_screen:
9161 * @widget: a #GtkWidget
9163 * Checks whether there is a #GdkScreen is associated with
9164 * this widget. All toplevel widgets have an associated
9165 * screen, and all widgets added into a hierarchy with a toplevel
9166 * window at the top.
9168 * Return value: %TRUE if there is a #GdkScreen associcated
9174 gtk_widget_has_screen (GtkWidget *widget)
9176 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9178 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9182 * gtk_widget_get_display:
9183 * @widget: a #GtkWidget
9185 * Get the #GdkDisplay for the toplevel window associated with
9186 * this widget. This function can only be called after the widget
9187 * has been added to a widget hierarchy with a #GtkWindow at the top.
9189 * In general, you should only create display specific
9190 * resources when a widget has been realized, and you should
9191 * free those resources when the widget is unrealized.
9193 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9198 gtk_widget_get_display (GtkWidget *widget)
9200 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9202 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9206 * gtk_widget_get_root_window:
9207 * @widget: a #GtkWidget
9209 * Get the root window where this widget is located. This function can
9210 * only be called after the widget has been added to a widget
9211 * hierarchy with #GtkWindow at the top.
9213 * The root window is useful for such purposes as creating a popup
9214 * #GdkWindow associated with the window. In general, you should only
9215 * create display specific resources when a widget has been realized,
9216 * and you should free those resources when the widget is unrealized.
9218 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9223 gtk_widget_get_root_window (GtkWidget *widget)
9225 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9227 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9231 * gtk_widget_child_focus:
9232 * @widget: a #GtkWidget
9233 * @direction: direction of focus movement
9235 * This function is used by custom widget implementations; if you're
9236 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9237 * to a particular widget, and gtk_container_set_focus_chain() to
9238 * change the focus tab order. So you may want to investigate those
9239 * functions instead.
9241 * gtk_widget_child_focus() is called by containers as the user moves
9242 * around the window using keyboard shortcuts. @direction indicates
9243 * what kind of motion is taking place (up, down, left, right, tab
9244 * forward, tab backward). gtk_widget_child_focus() emits the
9245 * #GtkWidget::focus signal; widgets override the default handler
9246 * for this signal in order to implement appropriate focus behavior.
9248 * The default ::focus handler for a widget should return %TRUE if
9249 * moving in @direction left the focus on a focusable location inside
9250 * that widget, and %FALSE if moving in @direction moved the focus
9251 * outside the widget. If returning %TRUE, widgets normally
9252 * call gtk_widget_grab_focus() to place the focus accordingly;
9253 * if returning %FALSE, they don't modify the current focus location.
9255 * Return value: %TRUE if focus ended up inside @widget
9258 gtk_widget_child_focus (GtkWidget *widget,
9259 GtkDirectionType direction)
9261 gboolean return_val;
9263 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9265 if (!gtk_widget_get_visible (widget) ||
9266 !gtk_widget_is_sensitive (widget))
9269 /* child widgets must set CAN_FOCUS, containers
9270 * don't have to though.
9272 if (!GTK_IS_CONTAINER (widget) &&
9273 !gtk_widget_get_can_focus (widget))
9276 g_signal_emit (widget,
9277 widget_signals[FOCUS],
9279 direction, &return_val);
9285 * gtk_widget_keynav_failed:
9286 * @widget: a #GtkWidget
9287 * @direction: direction of focus movement
9289 * This function should be called whenever keyboard navigation within
9290 * a single widget hits a boundary. The function emits the
9291 * #GtkWidget::keynav-failed signal on the widget and its return
9292 * value should be interpreted in a way similar to the return value of
9293 * gtk_widget_child_focus():
9295 * When %TRUE is returned, stay in the widget, the failed keyboard
9296 * navigation is Ok and/or there is nowhere we can/should move the
9299 * When %FALSE is returned, the caller should continue with keyboard
9300 * navigation outside the widget, e.g. by calling
9301 * gtk_widget_child_focus() on the widget's toplevel.
9303 * The default ::keynav-failed handler returns %TRUE for
9304 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9305 * values of #GtkDirectionType, it looks at the
9306 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9307 * if the setting is %TRUE. This way the entire user interface
9308 * becomes cursor-navigatable on input devices such as mobile phones
9309 * which only have cursor keys but no tab key.
9311 * Whenever the default handler returns %TRUE, it also calls
9312 * gtk_widget_error_bell() to notify the user of the failed keyboard
9315 * A use case for providing an own implementation of ::keynav-failed
9316 * (either by connecting to it or by overriding it) would be a row of
9317 * #GtkEntry widgets where the user should be able to navigate the
9318 * entire row with the cursor keys, as e.g. known from user interfaces
9319 * that require entering license keys.
9321 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9322 * if the emitting widget should try to handle the keyboard
9323 * navigation attempt in its parent container(s).
9328 gtk_widget_keynav_failed (GtkWidget *widget,
9329 GtkDirectionType direction)
9331 gboolean return_val;
9333 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9335 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9336 direction, &return_val);
9342 * gtk_widget_error_bell:
9343 * @widget: a #GtkWidget
9345 * Notifies the user about an input-related error on this widget.
9346 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9347 * gdk_window_beep(), otherwise it does nothing.
9349 * Note that the effect of gdk_window_beep() can be configured in many
9350 * ways, depending on the windowing backend and the desktop environment
9351 * or window manager that is used.
9356 gtk_widget_error_bell (GtkWidget *widget)
9358 GtkWidgetPrivate *priv;
9359 GtkSettings* settings;
9362 g_return_if_fail (GTK_IS_WIDGET (widget));
9364 priv = widget->priv;
9366 settings = gtk_widget_get_settings (widget);
9370 g_object_get (settings,
9371 "gtk-error-bell", &beep,
9374 if (beep && priv->window)
9375 gdk_window_beep (priv->window);
9379 gtk_widget_set_usize_internal (GtkWidget *widget,
9382 GtkQueueResizeFlags flags)
9384 GtkWidgetAuxInfo *aux_info;
9385 gboolean changed = FALSE;
9387 g_object_freeze_notify (G_OBJECT (widget));
9389 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
9391 if (width > -2 && aux_info->width != width)
9393 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9394 g_object_notify (G_OBJECT (widget), "width-request");
9395 aux_info->width = width;
9398 if (height > -2 && aux_info->height != height)
9400 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9401 g_object_notify (G_OBJECT (widget), "height-request");
9402 aux_info->height = height;
9406 if (gtk_widget_get_visible (widget) && changed)
9408 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9409 gtk_widget_queue_resize (widget);
9411 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9414 g_object_thaw_notify (G_OBJECT (widget));
9418 * gtk_widget_set_size_request:
9419 * @widget: a #GtkWidget
9420 * @width: width @widget should request, or -1 to unset
9421 * @height: height @widget should request, or -1 to unset
9423 * Sets the minimum size of a widget; that is, the widget's size
9424 * request will be @width by @height. You can use this function to
9425 * force a widget to be either larger or smaller than it normally
9428 * In most cases, gtk_window_set_default_size() is a better choice for
9429 * toplevel windows than this function; setting the default size will
9430 * still allow users to shrink the window. Setting the size request
9431 * will force them to leave the window at least as large as the size
9432 * request. When dealing with window sizes,
9433 * gtk_window_set_geometry_hints() can be a useful function as well.
9435 * Note the inherent danger of setting any fixed size - themes,
9436 * translations into other languages, different fonts, and user action
9437 * can all change the appropriate size for a given widget. So, it's
9438 * basically impossible to hardcode a size that will always be
9441 * The size request of a widget is the smallest size a widget can
9442 * accept while still functioning well and drawing itself correctly.
9443 * However in some strange cases a widget may be allocated less than
9444 * its requested size, and in many cases a widget may be allocated more
9445 * space than it requested.
9447 * If the size request in a given direction is -1 (unset), then
9448 * the "natural" size request of the widget will be used instead.
9450 * Widgets can't actually be allocated a size less than 1 by 1, but
9451 * you can pass 0,0 to this function to mean "as small as possible."
9453 * The size request set here does not include any margin from the
9454 * #GtkWidget properties margin-left, margin-right, margin-top, and
9455 * margin-bottom, but it does include pretty much all other padding
9456 * or border properties set by any subclass of #GtkWidget.
9459 gtk_widget_set_size_request (GtkWidget *widget,
9463 g_return_if_fail (GTK_IS_WIDGET (widget));
9464 g_return_if_fail (width >= -1);
9465 g_return_if_fail (height >= -1);
9472 gtk_widget_set_usize_internal (widget, width, height, 0);
9477 * gtk_widget_get_size_request:
9478 * @widget: a #GtkWidget
9479 * @width: (out) (allow-none): return location for width, or %NULL
9480 * @height: (out) (allow-none): return location for height, or %NULL
9482 * Gets the size request that was explicitly set for the widget using
9483 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9484 * @height indicates that that dimension has not been set explicitly
9485 * and the natural requisition of the widget will be used intead. See
9486 * gtk_widget_set_size_request(). To get the size a widget will
9487 * actually request, call gtk_widget_get_preferred_size() instead of
9491 gtk_widget_get_size_request (GtkWidget *widget,
9495 const GtkWidgetAuxInfo *aux_info;
9497 g_return_if_fail (GTK_IS_WIDGET (widget));
9499 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9502 *width = aux_info->width;
9505 *height = aux_info->height;
9509 * _gtk_widget_override_size_request:
9510 * @widget: a #GtkWidget
9511 * @width: new forced minimum width
9512 * @height: new forced minimum height
9513 * @old_width: location to store previous forced minimum width
9514 * @old_width: location to store previous forced minumum height
9516 * Temporarily establishes a forced minimum size for a widget; this
9517 * is used by GtkWindow when calculating the size to add to the
9518 * window's geometry widget. Cached sizes for the widget and its
9519 * parents are invalidated, so that subsequent calls to the size
9520 * negotiation machinery produce the overriden result, but the
9521 * widget is not queued for relayout or redraw. The old size must
9522 * be restored with _gtk_widget_restore_size_request() or things
9526 _gtk_widget_override_size_request (GtkWidget *widget,
9532 gtk_widget_get_size_request (widget, old_width, old_height);
9533 gtk_widget_set_usize_internal (widget, width, height,
9534 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9538 * _gtk_widget_restore_size_request:
9539 * @widget: a #GtkWidget
9540 * @old_width: saved forced minimum size
9541 * @old_height: saved forced minimum size
9543 * Undoes the operation of_gtk_widget_override_size_request().
9546 _gtk_widget_restore_size_request (GtkWidget *widget,
9550 gtk_widget_set_usize_internal (widget, old_width, old_height,
9551 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9555 * gtk_widget_set_events:
9556 * @widget: a #GtkWidget
9557 * @events: event mask
9559 * Sets the event mask (see #GdkEventMask) for a widget. The event
9560 * mask determines which events a widget will receive. Keep in mind
9561 * that different widgets have different default event masks, and by
9562 * changing the event mask you may disrupt a widget's functionality,
9563 * so be careful. This function must be called while a widget is
9564 * unrealized. Consider gtk_widget_add_events() for widgets that are
9565 * already realized, or if you want to preserve the existing event
9566 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9567 * to get events on those widgets, place them inside a #GtkEventBox
9568 * and receive events on the event box.
9571 gtk_widget_set_events (GtkWidget *widget,
9574 g_return_if_fail (GTK_IS_WIDGET (widget));
9575 g_return_if_fail (!gtk_widget_get_realized (widget));
9577 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9578 GINT_TO_POINTER (events));
9579 g_object_notify (G_OBJECT (widget), "events");
9583 * gtk_widget_set_device_events:
9584 * @widget: a #GtkWidget
9585 * @device: a #GdkDevice
9586 * @events: event mask
9588 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9589 * mask determines which events a widget will receive from @device. Keep
9590 * in mind that different widgets have different default event masks, and by
9591 * changing the event mask you may disrupt a widget's functionality,
9592 * so be careful. This function must be called while a widget is
9593 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9594 * already realized, or if you want to preserve the existing event
9595 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9596 * to get events on those widgets, place them inside a #GtkEventBox
9597 * and receive events on the event box.
9602 gtk_widget_set_device_events (GtkWidget *widget,
9604 GdkEventMask events)
9606 GHashTable *device_events;
9608 g_return_if_fail (GTK_IS_WIDGET (widget));
9609 g_return_if_fail (GDK_IS_DEVICE (device));
9610 g_return_if_fail (!gtk_widget_get_realized (widget));
9612 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9614 if (G_UNLIKELY (!device_events))
9616 device_events = g_hash_table_new (NULL, NULL);
9617 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9618 (GDestroyNotify) g_hash_table_unref);
9621 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9625 gtk_widget_add_events_internal_list (GtkWidget *widget,
9632 for (l = window_list; l != NULL; l = l->next)
9634 GdkWindow *window = l->data;
9637 gdk_window_get_user_data (window, &user_data);
9638 if (user_data == widget)
9643 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9645 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9647 children = gdk_window_get_children (window);
9648 gtk_widget_add_events_internal_list (widget, device, events, children);
9649 g_list_free (children);
9655 gtk_widget_add_events_internal (GtkWidget *widget,
9659 GtkWidgetPrivate *priv = widget->priv;
9662 if (!gtk_widget_get_has_window (widget))
9663 window_list = gdk_window_get_children (priv->window);
9665 window_list = g_list_prepend (NULL, priv->window);
9667 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9669 g_list_free (window_list);
9673 * gtk_widget_add_events:
9674 * @widget: a #GtkWidget
9675 * @events: an event mask, see #GdkEventMask
9677 * Adds the events in the bitfield @events to the event mask for
9678 * @widget. See gtk_widget_set_events() for details.
9681 gtk_widget_add_events (GtkWidget *widget,
9686 g_return_if_fail (GTK_IS_WIDGET (widget));
9688 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9689 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9690 GINT_TO_POINTER (old_events | events));
9692 if (gtk_widget_get_realized (widget))
9693 gtk_widget_add_events_internal (widget, NULL, events);
9695 g_object_notify (G_OBJECT (widget), "events");
9699 * gtk_widget_add_device_events:
9700 * @widget: a #GtkWidget
9701 * @device: a #GdkDevice
9702 * @events: an event mask, see #GdkEventMask
9704 * Adds the device events in the bitfield @events to the event mask for
9705 * @widget. See gtk_widget_set_device_events() for details.
9710 gtk_widget_add_device_events (GtkWidget *widget,
9712 GdkEventMask events)
9714 GdkEventMask old_events;
9715 GHashTable *device_events;
9717 g_return_if_fail (GTK_IS_WIDGET (widget));
9718 g_return_if_fail (GDK_IS_DEVICE (device));
9720 old_events = gtk_widget_get_device_events (widget, device);
9722 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9724 if (G_UNLIKELY (!device_events))
9726 device_events = g_hash_table_new (NULL, NULL);
9727 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9728 (GDestroyNotify) g_hash_table_unref);
9731 g_hash_table_insert (device_events, device,
9732 GUINT_TO_POINTER (old_events | events));
9734 if (gtk_widget_get_realized (widget))
9735 gtk_widget_add_events_internal (widget, device, events);
9737 g_object_notify (G_OBJECT (widget), "events");
9741 * gtk_widget_set_extension_events:
9742 * @widget: a #GtkWidget
9743 * @mode: bitfield of extension events to receive
9745 * Sets the extension events mask to @mode. See #GdkExtensionMode
9746 * and gdk_input_set_extension_events().
9749 gtk_widget_set_extension_events (GtkWidget *widget,
9750 GdkExtensionMode mode)
9752 g_return_if_fail (GTK_IS_WIDGET (widget));
9754 if (gtk_widget_get_realized (widget))
9755 gtk_widget_set_extension_events_internal (widget, mode, NULL);
9757 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
9758 GINT_TO_POINTER (mode));
9759 g_object_notify (G_OBJECT (widget), "extension-events");
9763 * gtk_widget_get_toplevel:
9764 * @widget: a #GtkWidget
9766 * This function returns the topmost widget in the container hierarchy
9767 * @widget is a part of. If @widget has no parent widgets, it will be
9768 * returned as the topmost widget. No reference will be added to the
9769 * returned widget; it should not be unreferenced.
9771 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9772 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9774 * %NULL if @widget wasn't inside a toplevel window, and if the
9775 * window was inside a #GtkWindow-derived widget which was in turn
9776 * inside the toplevel #GtkWindow. While the second case may
9777 * seem unlikely, it actually happens when a #GtkPlug is embedded
9778 * inside a #GtkSocket within the same application.
9780 * To reliably find the toplevel #GtkWindow, use
9781 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9782 * is set on the result.
9784 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9785 * if (gtk_widget_is_toplevel (toplevel))
9787 * /* Perform action on toplevel. */
9791 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9792 * if there's no ancestor.
9795 gtk_widget_get_toplevel (GtkWidget *widget)
9797 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9799 while (widget->priv->parent)
9800 widget = widget->priv->parent;
9806 * gtk_widget_get_ancestor:
9807 * @widget: a #GtkWidget
9808 * @widget_type: ancestor type
9810 * Gets the first ancestor of @widget with type @widget_type. For example,
9811 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9812 * the first #GtkBox that's an ancestor of @widget. No reference will be
9813 * added to the returned widget; it should not be unreferenced. See note
9814 * about checking for a toplevel #GtkWindow in the docs for
9815 * gtk_widget_get_toplevel().
9817 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9818 * considers @widget to be an ancestor of itself.
9820 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9823 gtk_widget_get_ancestor (GtkWidget *widget,
9826 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9828 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9829 widget = widget->priv->parent;
9831 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9838 * gtk_widget_set_visual:
9839 * @widget: a #GtkWidget
9840 * @visual: visual to be used or %NULL to unset a previous one
9842 * Sets the visual that should be used for by widget and its children for
9843 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9844 * returned by gdk_widget_get_screen(), so handling the
9845 * #GtkWidget::screen-changed signal is necessary.
9847 * Setting a new @visual will not cause @widget to recreate its windows,
9848 * so you should call this function before @widget is realized.
9851 gtk_widget_set_visual (GtkWidget *widget,
9854 g_return_if_fail (GTK_IS_WIDGET (widget));
9855 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9858 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9861 g_object_set_qdata_full (G_OBJECT (widget),
9863 g_object_ref (visual),
9868 * gtk_widget_get_visual:
9869 * @widget: a #GtkWidget
9871 * Gets the visual that will be used to render @widget.
9873 * Return value: (transfer none): the visual for @widget
9876 gtk_widget_get_visual (GtkWidget *widget)
9882 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9884 if (gtk_widget_get_has_window (widget) &&
9885 widget->priv->window)
9886 return gdk_window_get_visual (widget->priv->window);
9888 screen = gtk_widget_get_screen (widget);
9890 for (w = widget; w != NULL; w = w->priv->parent)
9892 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9895 if (gdk_visual_get_screen (visual) == screen)
9898 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9899 gtk_widget_get_name (widget));
9903 return gdk_screen_get_system_visual (screen);
9907 * gtk_widget_get_settings:
9908 * @widget: a #GtkWidget
9910 * Gets the settings object holding the settings (global property
9911 * settings, RC file information, etc) used for this widget.
9913 * Note that this function can only be called when the #GtkWidget
9914 * is attached to a toplevel, since the settings object is specific
9915 * to a particular #GdkScreen.
9917 * Return value: (transfer none): the relevant #GtkSettings object
9920 gtk_widget_get_settings (GtkWidget *widget)
9922 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9924 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9928 * gtk_widget_get_events:
9929 * @widget: a #GtkWidget
9931 * Returns the event mask for the widget (a bitfield containing flags
9932 * from the #GdkEventMask enumeration). These are the events that the widget
9935 * Return value: event mask for @widget
9938 gtk_widget_get_events (GtkWidget *widget)
9940 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9942 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9946 * gtk_widget_get_device_events:
9947 * @widget: a #GtkWidget
9948 * @device: a #GdkDevice
9950 * Returns the events mask for the widget corresponding to an specific device. These
9951 * are the events that the widget will receive when @device operates on it.
9953 * Returns: device event mask for @widget
9958 gtk_widget_get_device_events (GtkWidget *widget,
9961 GHashTable *device_events;
9963 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9964 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9966 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9971 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9975 * gtk_widget_get_extension_events:
9976 * @widget: a #GtkWidget
9978 * Retrieves the extension events the widget will receive; see
9979 * gdk_input_set_extension_events().
9981 * Return value: extension events for @widget
9984 gtk_widget_get_extension_events (GtkWidget *widget)
9986 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9988 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
9992 * gtk_widget_get_pointer:
9993 * @widget: a #GtkWidget
9994 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9995 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9997 * Obtains the location of the mouse pointer in widget coordinates.
9998 * Widget coordinates are a bit odd; for historical reasons, they are
9999 * defined as @widget->window coordinates for widgets that are not
10000 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
10001 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
10004 gtk_widget_get_pointer (GtkWidget *widget,
10008 GtkWidgetPrivate *priv;
10010 g_return_if_fail (GTK_IS_WIDGET (widget));
10012 priv = widget->priv;
10019 if (gtk_widget_get_realized (widget))
10021 gdk_window_get_pointer (priv->window, x, y, NULL);
10023 if (!gtk_widget_get_has_window (widget))
10026 *x -= priv->allocation.x;
10028 *y -= priv->allocation.y;
10034 * gtk_widget_is_ancestor:
10035 * @widget: a #GtkWidget
10036 * @ancestor: another #GtkWidget
10038 * Determines whether @widget is somewhere inside @ancestor, possibly with
10039 * intermediate containers.
10041 * Return value: %TRUE if @ancestor contains @widget as a child,
10042 * grandchild, great grandchild, etc.
10045 gtk_widget_is_ancestor (GtkWidget *widget,
10046 GtkWidget *ancestor)
10048 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10049 g_return_val_if_fail (ancestor != NULL, FALSE);
10053 if (widget->priv->parent == ancestor)
10055 widget = widget->priv->parent;
10061 static GQuark quark_composite_name = 0;
10064 * gtk_widget_set_composite_name:
10065 * @widget: a #GtkWidget.
10066 * @name: the name to set
10068 * Sets a widgets composite name. The widget must be
10069 * a composite child of its parent; see gtk_widget_push_composite_child().
10072 gtk_widget_set_composite_name (GtkWidget *widget,
10075 g_return_if_fail (GTK_IS_WIDGET (widget));
10076 g_return_if_fail (widget->priv->composite_child);
10077 g_return_if_fail (name != NULL);
10079 if (!quark_composite_name)
10080 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10082 g_object_set_qdata_full (G_OBJECT (widget),
10083 quark_composite_name,
10089 * gtk_widget_get_composite_name:
10090 * @widget: a #GtkWidget
10092 * Obtains the composite name of a widget.
10094 * Returns: the composite name of @widget, or %NULL if @widget is not
10095 * a composite child. The string should be freed when it is no
10099 gtk_widget_get_composite_name (GtkWidget *widget)
10101 GtkWidgetPrivate *priv;
10103 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10105 priv = widget->priv;
10107 if (widget->priv->composite_child && priv->parent)
10108 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10115 * gtk_widget_push_composite_child:
10117 * Makes all newly-created widgets as composite children until
10118 * the corresponding gtk_widget_pop_composite_child() call.
10120 * A composite child is a child that's an implementation detail of the
10121 * container it's inside and should not be visible to people using the
10122 * container. Composite children aren't treated differently by GTK (but
10123 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10124 * builders might want to treat them in a different way.
10126 * Here is a simple example:
10128 * gtk_widget_push_composite_child ();
10129 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10130 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10131 * gtk_widget_pop_composite_child ();
10132 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10133 * GTK_WIDGET (scrolled_window));
10134 * g_object_ref (scrolled_window->hscrollbar);
10138 gtk_widget_push_composite_child (void)
10140 composite_child_stack++;
10144 * gtk_widget_pop_composite_child:
10146 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10149 gtk_widget_pop_composite_child (void)
10151 if (composite_child_stack)
10152 composite_child_stack--;
10156 gtk_widget_emit_direction_changed (GtkWidget *widget,
10157 GtkTextDirection old_dir)
10159 gtk_widget_update_pango_context (widget);
10161 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10165 * gtk_widget_set_direction:
10166 * @widget: a #GtkWidget
10167 * @dir: the new direction
10169 * Sets the reading direction on a particular widget. This direction
10170 * controls the primary direction for widgets containing text,
10171 * and also the direction in which the children of a container are
10172 * packed. The ability to set the direction is present in order
10173 * so that correct localization into languages with right-to-left
10174 * reading directions can be done. Generally, applications will
10175 * let the default reading direction present, except for containers
10176 * where the containers are arranged in an order that is explicitely
10177 * visual rather than logical (such as buttons for text justification).
10179 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10180 * set by gtk_widget_set_default_direction() will be used.
10183 gtk_widget_set_direction (GtkWidget *widget,
10184 GtkTextDirection dir)
10186 GtkTextDirection old_dir;
10188 g_return_if_fail (GTK_IS_WIDGET (widget));
10189 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10191 old_dir = gtk_widget_get_direction (widget);
10193 widget->priv->direction = dir;
10195 if (old_dir != gtk_widget_get_direction (widget))
10197 if (widget->priv->context)
10198 gtk_style_context_set_direction (widget->priv->context,
10199 gtk_widget_get_direction (widget));
10201 gtk_widget_emit_direction_changed (widget, old_dir);
10206 * gtk_widget_get_direction:
10207 * @widget: a #GtkWidget
10209 * Gets the reading direction for a particular widget. See
10210 * gtk_widget_set_direction().
10212 * Return value: the reading direction for the widget.
10215 gtk_widget_get_direction (GtkWidget *widget)
10217 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10219 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10220 return gtk_default_direction;
10222 return widget->priv->direction;
10226 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10228 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10230 g_object_ref (widget);
10232 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10233 gtk_widget_emit_direction_changed (widget, old_dir);
10235 if (GTK_IS_CONTAINER (widget))
10236 gtk_container_forall (GTK_CONTAINER (widget),
10237 gtk_widget_set_default_direction_recurse,
10240 g_object_unref (widget);
10244 * gtk_widget_set_default_direction:
10245 * @dir: the new default direction. This cannot be
10246 * %GTK_TEXT_DIR_NONE.
10248 * Sets the default reading direction for widgets where the
10249 * direction has not been explicitly set by gtk_widget_set_direction().
10252 gtk_widget_set_default_direction (GtkTextDirection dir)
10254 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10256 if (dir != gtk_default_direction)
10258 GList *toplevels, *tmp_list;
10259 GtkTextDirection old_dir = gtk_default_direction;
10261 gtk_default_direction = dir;
10263 tmp_list = toplevels = gtk_window_list_toplevels ();
10264 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10268 gtk_widget_set_default_direction_recurse (tmp_list->data,
10269 GUINT_TO_POINTER (old_dir));
10270 g_object_unref (tmp_list->data);
10271 tmp_list = tmp_list->next;
10274 g_list_free (toplevels);
10279 * gtk_widget_get_default_direction:
10281 * Obtains the current default reading direction. See
10282 * gtk_widget_set_default_direction().
10284 * Return value: the current default direction.
10287 gtk_widget_get_default_direction (void)
10289 return gtk_default_direction;
10293 gtk_widget_dispose (GObject *object)
10295 GtkWidget *widget = GTK_WIDGET (object);
10296 GtkWidgetPrivate *priv = widget->priv;
10299 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10300 else if (gtk_widget_get_visible (widget))
10301 gtk_widget_hide (widget);
10303 priv->visible = FALSE;
10304 if (gtk_widget_get_realized (widget))
10305 gtk_widget_unrealize (widget);
10307 if (!priv->in_destruction)
10309 priv->in_destruction = TRUE;
10310 g_signal_emit (object, widget_signals[DESTROY], 0);
10311 priv->in_destruction = FALSE;
10314 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10318 gtk_widget_real_destroy (GtkWidget *object)
10320 /* gtk_object_destroy() will already hold a refcount on object */
10321 GtkWidget *widget = GTK_WIDGET (object);
10322 GtkWidgetPrivate *priv = widget->priv;
10324 /* wipe accelerator closures (keep order) */
10325 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10326 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10328 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10329 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10331 gtk_grab_remove (widget);
10333 g_object_unref (priv->style);
10334 priv->style = gtk_widget_get_default_style ();
10335 g_object_ref (priv->style);
10339 gtk_widget_finalize (GObject *object)
10341 GtkWidget *widget = GTK_WIDGET (object);
10342 GtkWidgetPrivate *priv = widget->priv;
10343 GtkWidgetAuxInfo *aux_info;
10344 GtkAccessible *accessible;
10346 gtk_grab_remove (widget);
10348 g_object_unref (priv->style);
10349 priv->style = NULL;
10351 g_free (priv->name);
10353 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
10355 gtk_widget_aux_info_destroy (aux_info);
10357 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10359 g_object_unref (accessible);
10362 gtk_widget_path_free (priv->path);
10365 g_object_unref (priv->context);
10367 if (g_object_is_floating (object))
10368 g_warning ("A floating object was finalized. This means that someone\n"
10369 "called g_object_unref() on an object that had only a floating\n"
10370 "reference; the initial floating reference is not owned by anyone\n"
10371 "and must be removed with g_object_ref_sink().");
10373 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10376 /*****************************************
10377 * gtk_widget_real_map:
10382 *****************************************/
10385 gtk_widget_real_map (GtkWidget *widget)
10387 GtkWidgetPrivate *priv = widget->priv;
10389 g_assert (gtk_widget_get_realized (widget));
10391 if (!gtk_widget_get_mapped (widget))
10393 gtk_widget_set_mapped (widget, TRUE);
10395 if (gtk_widget_get_has_window (widget))
10396 gdk_window_show (priv->window);
10400 /*****************************************
10401 * gtk_widget_real_unmap:
10406 *****************************************/
10409 gtk_widget_real_unmap (GtkWidget *widget)
10411 GtkWidgetPrivate *priv = widget->priv;
10413 if (gtk_widget_get_mapped (widget))
10415 gtk_widget_set_mapped (widget, FALSE);
10417 if (gtk_widget_get_has_window (widget))
10418 gdk_window_hide (priv->window);
10422 /*****************************************
10423 * gtk_widget_real_realize:
10428 *****************************************/
10431 gtk_widget_real_realize (GtkWidget *widget)
10433 GtkWidgetPrivate *priv = widget->priv;
10435 g_assert (!gtk_widget_get_has_window (widget));
10437 gtk_widget_set_realized (widget, TRUE);
10440 priv->window = gtk_widget_get_parent_window (widget);
10441 g_object_ref (priv->window);
10443 priv->style = gtk_style_attach (priv->style, priv->window);
10446 /*****************************************
10447 * gtk_widget_real_unrealize:
10452 *****************************************/
10455 gtk_widget_real_unrealize (GtkWidget *widget)
10457 GtkWidgetPrivate *priv = widget->priv;
10459 if (gtk_widget_get_mapped (widget))
10460 gtk_widget_real_unmap (widget);
10462 gtk_widget_set_mapped (widget, FALSE);
10464 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10467 /* We must do unrealize child widget BEFORE container widget.
10468 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10469 * So, unrealizing container widget bofore its children causes the problem
10470 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10473 if (GTK_IS_CONTAINER (widget))
10474 gtk_container_forall (GTK_CONTAINER (widget),
10475 (GtkCallback) gtk_widget_unrealize,
10478 gtk_style_detach (priv->style);
10479 if (gtk_widget_get_has_window (widget))
10481 gdk_window_set_user_data (priv->window, NULL);
10482 gdk_window_destroy (priv->window);
10483 priv->window = NULL;
10487 g_object_unref (priv->window);
10488 priv->window = NULL;
10491 gtk_selection_remove_all (widget);
10493 gtk_widget_set_realized (widget, FALSE);
10497 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10498 GtkOrientation orientation,
10499 gint *minimum_size,
10500 gint *natural_size)
10502 const GtkWidgetAuxInfo *aux_info;
10504 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10506 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10507 aux_info->width > 0)
10509 *minimum_size = MAX (*minimum_size, aux_info->width);
10511 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10512 aux_info->height > 0)
10514 *minimum_size = MAX (*minimum_size, aux_info->height);
10517 /* Fix it if set_size_request made natural size smaller than min size.
10518 * This would also silently fix broken widgets, but we warn about them
10519 * in gtksizerequest.c when calling their size request vfuncs.
10521 *natural_size = MAX (*natural_size, *minimum_size);
10523 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10525 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10526 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10530 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10531 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10536 * _gtk_widget_peek_request_cache:
10538 * Returns the address of the widget's request cache (strictly for
10539 * internal use in gtksizerequest.c)
10541 * Return value: the address of @widget's size request cache.
10544 _gtk_widget_peek_request_cache (GtkWidget *widget)
10546 /* Don't bother slowing things down with the return_if_fail guards here */
10547 return &widget->priv->requests;
10551 * _gtk_widget_set_device_window:
10552 * @widget: a #GtkWidget.
10553 * @device: a #GdkDevice.
10554 * @window: the new device window.
10556 * Sets pointer window for @widget and @device. Does not ref @window.
10557 * Actually stores it on the #GdkScreen, but you don't need to know that.
10560 _gtk_widget_set_device_window (GtkWidget *widget,
10564 GtkWidgetPrivate *priv;
10566 GHashTable *device_window;
10568 g_return_if_fail (GTK_IS_WIDGET (widget));
10569 g_return_if_fail (GDK_IS_DEVICE (device));
10570 g_return_if_fail (!window || GDK_IS_WINDOW (window));
10572 priv = widget->priv;
10574 if (!gtk_widget_get_realized (widget))
10577 screen = gdk_window_get_screen (priv->window);
10578 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10580 if (G_UNLIKELY (!device_window))
10582 device_window = g_hash_table_new (NULL, NULL);
10583 g_object_set_qdata_full (G_OBJECT (screen),
10584 quark_pointer_window,
10586 (GDestroyNotify) g_hash_table_destroy);
10590 g_hash_table_insert (device_window, device, window);
10592 g_hash_table_remove (device_window, device);
10596 * _gtk_widget_get_device_window:
10597 * @widget: a #GtkWidget.
10598 * @device: a #GdkDevice.
10600 * Return value: the device window set on the #GdkScreen @widget is attached
10604 _gtk_widget_get_device_window (GtkWidget *widget,
10607 GtkWidgetPrivate *priv;
10609 GHashTable *device_window;
10613 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10614 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10616 priv = widget->priv;
10618 if (!gtk_widget_get_realized (widget))
10621 screen = gdk_window_get_screen (priv->window);
10622 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10624 if (G_UNLIKELY (!device_window))
10627 window = g_hash_table_lookup (device_window, device);
10632 gdk_window_get_user_data (window, (gpointer *) &w);
10641 * _gtk_widget_list_devices:
10642 * @widget: a #GtkWidget.
10644 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
10645 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
10649 _gtk_widget_list_devices (GtkWidget *widget)
10651 GtkWidgetPrivate *priv;
10653 GHashTableIter iter;
10654 GHashTable *device_window;
10655 GList *devices = NULL;
10656 gpointer key, value;
10658 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10660 priv = widget->priv;
10662 if (!gtk_widget_get_realized (widget))
10665 screen = gdk_window_get_screen (priv->window);
10666 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10668 if (G_UNLIKELY (!device_window))
10671 g_hash_table_iter_init (&iter, device_window);
10673 while (g_hash_table_iter_next (&iter, &key, &value))
10675 GdkDevice *device = key;
10676 GdkWindow *window = value;
10681 gdk_window_get_user_data (window, (gpointer *) &w);
10684 devices = g_list_prepend (devices, device);
10692 synth_crossing (GtkWidget *widget,
10696 GdkCrossingMode mode,
10697 GdkNotifyType detail)
10701 event = gdk_event_new (type);
10703 event->crossing.window = g_object_ref (window);
10704 event->crossing.send_event = TRUE;
10705 event->crossing.subwindow = g_object_ref (window);
10706 event->crossing.time = GDK_CURRENT_TIME;
10707 event->crossing.x = event->crossing.y = 0;
10708 event->crossing.x_root = event->crossing.y_root = 0;
10709 event->crossing.mode = mode;
10710 event->crossing.detail = detail;
10711 event->crossing.focus = FALSE;
10712 event->crossing.state = 0;
10713 gdk_event_set_device (event, device);
10716 widget = gtk_get_event_widget (event);
10719 gtk_widget_event_internal (widget, event);
10721 gdk_event_free (event);
10725 * _gtk_widget_synthesize_crossing:
10726 * @from: the #GtkWidget the virtual pointer is leaving.
10727 * @to: the #GtkWidget the virtual pointer is moving to.
10728 * @mode: the #GdkCrossingMode to place on the synthesized events.
10730 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10732 * The real pointer window is the window that most recently received an enter notify
10733 * event. Windows that don't select for crossing events can't become the real
10734 * poiner window. The real pointer widget that owns the real pointer window. The
10735 * effective pointer window is the same as the real pointer window unless the real
10736 * pointer widget is either insensitive or there is a grab on a widget that is not
10737 * an ancestor of the real pointer widget (in which case the effective pointer
10738 * window should be the root window).
10740 * When the effective pointer window is the same as the real poiner window, we
10741 * receive crossing events from the windowing system. When the effective pointer
10742 * window changes to become different from the real pointer window we synthesize
10743 * crossing events, attempting to follow X protocol rules:
10745 * When the root window becomes the effective pointer window:
10746 * - leave notify on real pointer window, detail Ancestor
10747 * - leave notify on all of its ancestors, detail Virtual
10748 * - enter notify on root window, detail Inferior
10750 * When the root window ceases to be the effective pointer window:
10751 * - leave notify on root window, detail Inferior
10752 * - enter notify on all ancestors of real pointer window, detail Virtual
10753 * - enter notify on real pointer window, detail Ancestor
10756 _gtk_widget_synthesize_crossing (GtkWidget *from,
10759 GdkCrossingMode mode)
10761 GdkWindow *from_window = NULL, *to_window = NULL;
10763 g_return_if_fail (from != NULL || to != NULL);
10767 from_window = _gtk_widget_get_device_window (from, device);
10770 from_window = from->priv->window;
10775 to_window = _gtk_widget_get_device_window (to, device);
10778 to_window = to->priv->window;
10781 if (from_window == NULL && to_window == NULL)
10783 else if (from_window != NULL && to_window == NULL)
10785 GList *from_ancestors = NULL, *list;
10786 GdkWindow *from_ancestor = from_window;
10788 while (from_ancestor != NULL)
10790 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10791 if (from_ancestor == NULL)
10793 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10796 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10797 device, mode, GDK_NOTIFY_ANCESTOR);
10798 for (list = g_list_last (from_ancestors); list; list = list->prev)
10800 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10801 device, mode, GDK_NOTIFY_VIRTUAL);
10804 /* XXX: enter/inferior on root window? */
10806 g_list_free (from_ancestors);
10808 else if (from_window == NULL && to_window != NULL)
10810 GList *to_ancestors = NULL, *list;
10811 GdkWindow *to_ancestor = to_window;
10813 while (to_ancestor != NULL)
10815 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10816 if (to_ancestor == NULL)
10818 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10821 /* XXX: leave/inferior on root window? */
10823 for (list = to_ancestors; list; list = list->next)
10825 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10826 device, mode, GDK_NOTIFY_VIRTUAL);
10828 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10829 device, mode, GDK_NOTIFY_ANCESTOR);
10831 g_list_free (to_ancestors);
10833 else if (from_window == to_window)
10837 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10838 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10840 while (from_ancestor != NULL || to_ancestor != NULL)
10842 if (from_ancestor != NULL)
10844 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10845 if (from_ancestor == to_window)
10848 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10850 if (to_ancestor != NULL)
10852 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10853 if (to_ancestor == from_window)
10856 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10859 if (to_ancestor == from_window)
10861 if (mode != GDK_CROSSING_GTK_UNGRAB)
10862 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10863 device, mode, GDK_NOTIFY_INFERIOR);
10864 for (list = to_ancestors; list; list = list->next)
10865 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10866 device, mode, GDK_NOTIFY_VIRTUAL);
10867 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10868 device, mode, GDK_NOTIFY_ANCESTOR);
10870 else if (from_ancestor == to_window)
10872 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10873 device, mode, GDK_NOTIFY_ANCESTOR);
10874 for (list = g_list_last (from_ancestors); list; list = list->prev)
10876 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10877 device, mode, GDK_NOTIFY_VIRTUAL);
10879 if (mode != GDK_CROSSING_GTK_GRAB)
10880 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10881 device, mode, GDK_NOTIFY_INFERIOR);
10885 while (from_ancestors != NULL && to_ancestors != NULL
10886 && from_ancestors->data == to_ancestors->data)
10888 from_ancestors = g_list_delete_link (from_ancestors,
10890 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10893 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10894 device, mode, GDK_NOTIFY_NONLINEAR);
10896 for (list = g_list_last (from_ancestors); list; list = list->prev)
10898 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10899 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10901 for (list = to_ancestors; list; list = list->next)
10903 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10904 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10906 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10907 device, mode, GDK_NOTIFY_NONLINEAR);
10909 g_list_free (from_ancestors);
10910 g_list_free (to_ancestors);
10915 gtk_widget_propagate_state (GtkWidget *widget,
10916 GtkStateData *data)
10918 GtkWidgetPrivate *priv = widget->priv;
10919 GtkStateFlags new_flags, old_flags = priv->state_flags;
10920 GtkStateType old_state;
10922 old_state = gtk_widget_get_state (widget);
10924 if (!priv->parent_sensitive)
10925 old_flags |= GTK_STATE_FLAG_INSENSITIVE;
10927 priv->parent_sensitive = data->parent_sensitive;
10929 switch (data->operation)
10931 case STATE_CHANGE_REPLACE:
10932 priv->state_flags = data->flags;
10934 case STATE_CHANGE_SET:
10935 priv->state_flags |= data->flags;
10937 case STATE_CHANGE_UNSET:
10938 priv->state_flags &= ~(data->flags);
10942 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10946 window = gtk_widget_get_toplevel (widget);
10948 if (window && gtk_widget_is_toplevel (window))
10949 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10952 new_flags = gtk_widget_get_state_flags (widget);
10954 if (old_flags != new_flags)
10956 g_object_ref (widget);
10958 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10959 gtk_grab_remove (widget);
10961 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10962 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
10964 if (!priv->shadowed)
10966 GList *event_windows = NULL;
10967 GList *devices, *d;
10969 devices = _gtk_widget_list_devices (widget);
10971 for (d = devices; d; d = d->next)
10977 window = _gtk_widget_get_device_window (widget, device);
10979 /* Do not propagate more than once to the
10980 * same window if non-multidevice aware.
10982 if (!gdk_window_get_support_multidevice (window) &&
10983 g_list_find (event_windows, window))
10986 if (!gtk_widget_is_sensitive (widget))
10987 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10988 GDK_CROSSING_STATE_CHANGED);
10989 else if (old_flags & GTK_STATE_FLAG_INSENSITIVE)
10990 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10991 GDK_CROSSING_STATE_CHANGED);
10993 event_windows = g_list_prepend (event_windows, window);
10996 g_list_free (event_windows);
10997 g_list_free (devices);
11000 if (GTK_IS_CONTAINER (widget))
11002 data->parent_sensitive = gtk_widget_is_sensitive (widget);
11004 /* Do not propagate insensitive state further */
11005 data->flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
11007 if (data->use_forall)
11008 gtk_container_forall (GTK_CONTAINER (widget),
11009 (GtkCallback) gtk_widget_propagate_state,
11012 gtk_container_foreach (GTK_CONTAINER (widget),
11013 (GtkCallback) gtk_widget_propagate_state,
11017 /* Trigger state change transitions for the widget */
11018 if (priv->context &&
11019 gtk_widget_get_mapped (widget))
11021 gint diff, flag = 1;
11024 diff = old_flags ^ new_flags;
11025 window = gtk_widget_get_window (widget);
11029 if ((diff & flag) != 0)
11033 target = ((new_flags & flag) != 0);
11034 _gtk_widget_notify_state_change (widget, flag, target);
11043 g_object_unref (widget);
11047 static const GtkWidgetAuxInfo default_aux_info = {
11055 * _gtk_widget_get_aux_info:
11056 * @widget: a #GtkWidget
11057 * @create: if %TRUE, create the structure if it doesn't exist
11059 * Get the #GtkWidgetAuxInfo structure for the widget.
11061 * Return value: the #GtkAuxInfo structure for the widget, or
11062 * %NULL if @create is %FALSE and one doesn't already exist.
11065 _gtk_widget_get_aux_info (GtkWidget *widget,
11068 GtkWidgetAuxInfo *aux_info;
11070 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
11071 if (!aux_info && create)
11073 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
11075 *aux_info = default_aux_info;
11077 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
11083 static const GtkWidgetAuxInfo*
11084 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11086 GtkWidgetAuxInfo *aux_info;
11088 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
11089 if (aux_info == NULL)
11091 return &default_aux_info;
11099 /*****************************************
11100 * gtk_widget_aux_info_destroy:
11105 *****************************************/
11108 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11110 g_slice_free (GtkWidgetAuxInfo, aux_info);
11114 * gtk_widget_shape_combine_region:
11115 * @widget: a #GtkWidget
11116 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11118 * Sets a shape for this widget's GDK window. This allows for
11119 * transparent windows etc., see gdk_window_shape_combine_region()
11120 * for more information.
11125 gtk_widget_shape_combine_region (GtkWidget *widget,
11126 cairo_region_t *region)
11128 GtkWidgetPrivate *priv;
11130 g_return_if_fail (GTK_IS_WIDGET (widget));
11131 /* set_shape doesn't work on widgets without gdk window */
11132 g_return_if_fail (gtk_widget_get_has_window (widget));
11134 priv = widget->priv;
11136 if (region == NULL)
11138 priv->has_shape_mask = FALSE;
11141 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11143 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11147 priv->has_shape_mask = TRUE;
11149 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11150 cairo_region_copy (region),
11151 (GDestroyNotify) cairo_region_destroy);
11153 /* set shape if widget has a gdk window already.
11154 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11157 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11162 * gtk_widget_input_shape_combine_region:
11163 * @widget: a #GtkWidget
11164 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11166 * Sets an input shape for this widget's GDK window. This allows for
11167 * windows which react to mouse click in a nonrectangular region, see
11168 * gdk_window_input_shape_combine_region() for more information.
11173 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11174 cairo_region_t *region)
11176 GtkWidgetPrivate *priv;
11178 g_return_if_fail (GTK_IS_WIDGET (widget));
11179 /* set_shape doesn't work on widgets without gdk window */
11180 g_return_if_fail (gtk_widget_get_has_window (widget));
11182 priv = widget->priv;
11184 if (region == NULL)
11187 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11189 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11193 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11194 cairo_region_copy (region),
11195 (GDestroyNotify) cairo_region_destroy);
11197 /* set shape if widget has a gdk window already.
11198 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11201 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11207 gtk_reset_shapes_recurse (GtkWidget *widget,
11213 gdk_window_get_user_data (window, &data);
11214 if (data != widget)
11217 gdk_window_shape_combine_region (window, NULL, 0, 0);
11218 for (list = gdk_window_peek_children (window); list; list = list->next)
11219 gtk_reset_shapes_recurse (widget, list->data);
11223 * gtk_widget_reset_shapes:
11224 * @widget: a #GtkWidget
11226 * Recursively resets the shape on this widget and its descendants.
11229 gtk_widget_reset_shapes (GtkWidget *widget)
11231 GtkWidgetPrivate *priv;
11233 g_return_if_fail (GTK_IS_WIDGET (widget));
11234 g_return_if_fail (gtk_widget_get_realized (widget));
11236 priv = widget->priv;
11238 if (!priv->has_shape_mask)
11239 gtk_reset_shapes_recurse (widget, priv->window);
11242 /* style properties
11246 * gtk_widget_class_install_style_property_parser:
11247 * @klass: a #GtkWidgetClass
11248 * @pspec: the #GParamSpec for the style property
11249 * @parser: the parser for the style property
11251 * Installs a style property on a widget class.
11254 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11256 GtkRcPropertyParser parser)
11258 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11259 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11260 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11261 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11263 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11265 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11266 G_OBJECT_CLASS_NAME (klass),
11271 g_param_spec_ref_sink (pspec);
11272 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11273 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11277 * gtk_widget_class_install_style_property:
11278 * @klass: a #GtkWidgetClass
11279 * @pspec: the #GParamSpec for the property
11281 * Installs a style property on a widget class. The parser for the
11282 * style property is determined by the value type of @pspec.
11285 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11288 GtkRcPropertyParser parser;
11290 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11291 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11293 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11295 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11299 * gtk_widget_class_find_style_property:
11300 * @klass: a #GtkWidgetClass
11301 * @property_name: the name of the style property to find
11302 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
11303 * style property with that name.
11305 * Finds a style property of a widget class by name.
11310 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11311 const gchar *property_name)
11313 g_return_val_if_fail (property_name != NULL, NULL);
11315 return g_param_spec_pool_lookup (style_property_spec_pool,
11317 G_OBJECT_CLASS_TYPE (klass),
11322 * gtk_widget_class_list_style_properties:
11323 * @klass: a #GtkWidgetClass
11324 * @n_properties: location to return the number of style properties found
11325 * @returns: an newly allocated array of #GParamSpec*. The array must
11326 * be freed with g_free().
11328 * Returns all style properties of a widget class.
11333 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11334 guint *n_properties)
11336 GParamSpec **pspecs;
11339 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11340 G_OBJECT_CLASS_TYPE (klass),
11349 * gtk_widget_style_get_property:
11350 * @widget: a #GtkWidget
11351 * @property_name: the name of a style property
11352 * @value: location to return the property value
11354 * Gets the value of a style property of @widget.
11357 gtk_widget_style_get_property (GtkWidget *widget,
11358 const gchar *property_name,
11363 g_return_if_fail (GTK_IS_WIDGET (widget));
11364 g_return_if_fail (property_name != NULL);
11365 g_return_if_fail (G_IS_VALUE (value));
11367 g_object_ref (widget);
11368 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11370 G_OBJECT_TYPE (widget),
11373 g_warning ("%s: widget class `%s' has no property named `%s'",
11375 G_OBJECT_TYPE_NAME (widget),
11379 GtkStyleContext *context;
11380 const GValue *peek_value;
11381 GtkStateFlags state;
11383 context = gtk_widget_get_style_context (widget);
11384 state = gtk_widget_get_state_flags (widget);
11386 peek_value = _gtk_style_context_peek_style_property (context,
11387 G_OBJECT_TYPE (widget),
11390 /* auto-conversion of the caller's value type
11392 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11393 g_value_copy (peek_value, value);
11394 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11395 g_value_transform (peek_value, value);
11397 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11399 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11400 G_VALUE_TYPE_NAME (value));
11402 g_object_unref (widget);
11406 * gtk_widget_style_get_valist:
11407 * @widget: a #GtkWidget
11408 * @first_property_name: the name of the first property to get
11409 * @var_args: a <type>va_list</type> of pairs of property names and
11410 * locations to return the property values, starting with the location
11411 * for @first_property_name.
11413 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11417 gtk_widget_style_get_valist (GtkWidget *widget,
11418 const gchar *first_property_name,
11421 GtkStyleContext *context;
11422 GtkStateFlags state;
11425 g_return_if_fail (GTK_IS_WIDGET (widget));
11427 g_object_ref (widget);
11428 context = gtk_widget_get_style_context (widget);
11429 state = gtk_widget_get_state_flags (widget);
11431 name = first_property_name;
11434 const GValue *peek_value;
11438 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11440 G_OBJECT_TYPE (widget),
11444 g_warning ("%s: widget class `%s' has no property named `%s'",
11446 G_OBJECT_TYPE_NAME (widget),
11450 /* style pspecs are always readable so we can spare that check here */
11452 peek_value = _gtk_style_context_peek_style_property (context,
11453 G_OBJECT_TYPE (widget),
11456 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11459 g_warning ("%s: %s", G_STRLOC, error);
11464 name = va_arg (var_args, gchar*);
11467 g_object_unref (widget);
11471 * gtk_widget_style_get:
11472 * @widget: a #GtkWidget
11473 * @first_property_name: the name of the first property to get
11474 * @Varargs: pairs of property names and locations to
11475 * return the property values, starting with the location for
11476 * @first_property_name, terminated by %NULL.
11478 * Gets the values of a multiple style properties of @widget.
11481 gtk_widget_style_get (GtkWidget *widget,
11482 const gchar *first_property_name,
11487 g_return_if_fail (GTK_IS_WIDGET (widget));
11489 va_start (var_args, first_property_name);
11490 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11496 * @widget: a #GtkWidget
11497 * @path_length: (out) (allow-none): location to store length of the path,
11499 * @path: (out) (allow-none): location to store allocated path string,
11501 * @path_reversed: (out) (allow-none): location to store allocated reverse
11502 * path string, or %NULL
11504 * Obtains the full path to @widget. The path is simply the name of a
11505 * widget and all its parents in the container hierarchy, separated by
11506 * periods. The name of a widget comes from
11507 * gtk_widget_get_name(). Paths are used to apply styles to a widget
11508 * in gtkrc configuration files. Widget names are the type of the
11509 * widget by default (e.g. "GtkButton") or can be set to an
11510 * application-specific value with gtk_widget_set_name(). By setting
11511 * the name of a widget, you allow users or theme authors to apply
11512 * styles to that specific widget in their gtkrc
11513 * file. @path_reversed_p fills in the path in reverse order,
11514 * i.e. starting with @widget's name instead of starting with the name
11515 * of @widget's outermost ancestor.
11517 * Deprecated:3.0: Use gtk_widget_get_path() instead
11520 gtk_widget_path (GtkWidget *widget,
11521 guint *path_length,
11523 gchar **path_reversed)
11525 static gchar *rev_path = NULL;
11526 static guint tmp_path_len = 0;
11529 g_return_if_fail (GTK_IS_WIDGET (widget));
11534 const gchar *string;
11539 string = gtk_widget_get_name (widget);
11540 l = strlen (string);
11541 while (tmp_path_len <= len + l + 1)
11543 tmp_path_len += INIT_PATH_SIZE;
11544 rev_path = g_realloc (rev_path, tmp_path_len);
11546 s = string + l - 1;
11547 d = rev_path + len;
11548 while (s >= string)
11552 widget = widget->priv->parent;
11555 rev_path[len++] = '.';
11557 rev_path[len++] = 0;
11562 *path_length = len - 1;
11564 *path_reversed = g_strdup (rev_path);
11567 *path = g_strdup (rev_path);
11568 g_strreverse (*path);
11573 * gtk_widget_class_path:
11574 * @widget: a #GtkWidget
11575 * @path_length: (out) (allow-none): location to store the length of the
11576 * class path, or %NULL
11577 * @path: (out) (allow-none): location to store the class path as an
11578 * allocated string, or %NULL
11579 * @path_reversed: (out) (allow-none): location to store the reverse
11580 * class path as an allocated string, or %NULL
11582 * Same as gtk_widget_path(), but always uses the name of a widget's type,
11583 * never uses a custom name set with gtk_widget_set_name().
11585 * Deprecated:3.0: Use gtk_widget_get_path() instead
11588 gtk_widget_class_path (GtkWidget *widget,
11589 guint *path_length,
11591 gchar **path_reversed)
11593 static gchar *rev_path = NULL;
11594 static guint tmp_path_len = 0;
11597 g_return_if_fail (GTK_IS_WIDGET (widget));
11602 const gchar *string;
11607 string = g_type_name (G_OBJECT_TYPE (widget));
11608 l = strlen (string);
11609 while (tmp_path_len <= len + l + 1)
11611 tmp_path_len += INIT_PATH_SIZE;
11612 rev_path = g_realloc (rev_path, tmp_path_len);
11614 s = string + l - 1;
11615 d = rev_path + len;
11616 while (s >= string)
11620 widget = widget->priv->parent;
11623 rev_path[len++] = '.';
11625 rev_path[len++] = 0;
11630 *path_length = len - 1;
11632 *path_reversed = g_strdup (rev_path);
11635 *path = g_strdup (rev_path);
11636 g_strreverse (*path);
11641 * gtk_requisition_new:
11643 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11645 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11646 * be freed with gtk_requisition_free().
11651 gtk_requisition_new (void)
11653 return g_slice_new0 (GtkRequisition);
11657 * gtk_requisition_copy:
11658 * @requisition: a #GtkRequisition
11660 * Copies a #GtkRequisition.
11662 * Returns: a copy of @requisition
11665 gtk_requisition_copy (const GtkRequisition *requisition)
11667 return g_slice_dup (GtkRequisition, requisition);
11671 * gtk_requisition_free:
11672 * @requisition: a #GtkRequisition
11674 * Frees a #GtkRequisition.
11677 gtk_requisition_free (GtkRequisition *requisition)
11679 g_slice_free (GtkRequisition, requisition);
11682 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11683 gtk_requisition_copy,
11684 gtk_requisition_free)
11687 * gtk_widget_get_accessible:
11688 * @widget: a #GtkWidget
11690 * Returns the accessible object that describes the widget to an
11691 * assistive technology.
11693 * If no accessibility library is loaded (i.e. no ATK implementation library is
11694 * loaded via <envar>GTK_MODULES</envar> or via another application library,
11695 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
11696 * if no class-specific #AtkObject implementation is available for the widget
11697 * instance in question, it will inherit an #AtkObject implementation from the
11698 * first ancestor class for which such an implementation is defined.
11700 * The documentation of the
11701 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
11702 * library contains more information about accessible objects and their uses.
11704 * Returns: (transfer none): the #AtkObject associated with @widget
11707 gtk_widget_get_accessible (GtkWidget *widget)
11709 GtkWidgetClass *klass;
11711 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11713 klass = GTK_WIDGET_GET_CLASS (widget);
11715 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11717 return klass->get_accessible (widget);
11721 gtk_widget_real_get_accessible (GtkWidget *widget)
11723 AtkObject* accessible;
11725 accessible = g_object_get_qdata (G_OBJECT (widget),
11726 quark_accessible_object);
11729 AtkObjectFactory *factory;
11730 AtkRegistry *default_registry;
11732 default_registry = atk_get_default_registry ();
11733 factory = atk_registry_get_factory (default_registry,
11734 G_TYPE_FROM_INSTANCE (widget));
11736 atk_object_factory_create_accessible (factory,
11737 G_OBJECT (widget));
11738 g_object_set_qdata (G_OBJECT (widget),
11739 quark_accessible_object,
11746 * Initialize a AtkImplementorIface instance's virtual pointers as
11747 * appropriate to this implementor's class (GtkWidget).
11750 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11752 iface->ref_accessible = gtk_widget_ref_accessible;
11756 gtk_widget_ref_accessible (AtkImplementor *implementor)
11758 AtkObject *accessible;
11760 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11762 g_object_ref (accessible);
11767 * Expand flag management
11771 gtk_widget_update_computed_expand (GtkWidget *widget)
11773 GtkWidgetPrivate *priv;
11775 priv = widget->priv;
11777 if (priv->need_compute_expand)
11781 if (priv->hexpand_set)
11786 if (priv->vexpand_set)
11791 /* we don't need to use compute_expand if both expands are
11792 * forced by the app
11794 if (!(priv->hexpand_set && priv->vexpand_set))
11796 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11800 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11801 priv->hexpand_set ? &ignored : &h,
11802 priv->vexpand_set ? &ignored : &v);
11806 priv->need_compute_expand = FALSE;
11807 priv->computed_hexpand = h != FALSE;
11808 priv->computed_vexpand = v != FALSE;
11813 * gtk_widget_queue_compute_expand:
11814 * @widget: a #GtkWidget
11816 * Mark @widget as needing to recompute its expand flags. Call
11817 * this function when setting legacy expand child properties
11818 * on the child of a container.
11820 * See gtk_widget_compute_expand().
11823 gtk_widget_queue_compute_expand (GtkWidget *widget)
11826 gboolean changed_anything;
11828 if (widget->priv->need_compute_expand)
11831 changed_anything = FALSE;
11833 while (parent != NULL)
11835 if (!parent->priv->need_compute_expand)
11837 parent->priv->need_compute_expand = TRUE;
11838 changed_anything = TRUE;
11841 /* Note: if we had an invariant that "if a child needs to
11842 * compute expand, its parents also do" then we could stop going
11843 * up when we got to a parent that already needed to
11844 * compute. However, in general we compute expand lazily (as
11845 * soon as we see something in a subtree that is expand, we know
11846 * we're expanding) and so this invariant does not hold and we
11847 * have to always walk all the way up in case some ancestor
11848 * is not currently need_compute_expand.
11851 parent = parent->priv->parent;
11854 /* recomputing expand always requires
11855 * a relayout as well
11857 if (changed_anything)
11858 gtk_widget_queue_resize (widget);
11862 * gtk_widget_compute_expand:
11863 * @widget: the widget
11864 * @orientation: expand direction
11866 * Computes whether a container should give this widget extra space
11867 * when possible. Containers should check this, rather than
11868 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11870 * This function already checks whether the widget is visible, so
11871 * visibility does not need to be checked separately. Non-visible
11872 * widgets are not expanded.
11874 * The computed expand value uses either the expand setting explicitly
11875 * set on the widget itself, or, if none has been explicitly set,
11876 * the widget may expand if some of its children do.
11878 * Return value: whether widget tree rooted here should be expanded
11881 gtk_widget_compute_expand (GtkWidget *widget,
11882 GtkOrientation orientation)
11884 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11886 /* We never make a widget expand if not even showing. */
11887 if (!gtk_widget_get_visible (widget))
11890 gtk_widget_update_computed_expand (widget);
11892 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11894 return widget->priv->computed_hexpand;
11898 return widget->priv->computed_vexpand;
11903 gtk_widget_set_expand (GtkWidget *widget,
11904 GtkOrientation orientation,
11907 const char *expand_prop;
11908 const char *expand_set_prop;
11910 GtkWidgetPrivate *priv;
11912 g_return_if_fail (GTK_IS_WIDGET (widget));
11914 priv = widget->priv;
11916 expand = expand != FALSE;
11918 was_both = priv->hexpand && priv->vexpand;
11920 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11922 if (priv->hexpand_set &&
11923 priv->hexpand == expand)
11926 priv->hexpand_set = TRUE;
11927 priv->hexpand = expand;
11929 expand_prop = "hexpand";
11930 expand_set_prop = "hexpand-set";
11934 if (priv->vexpand_set &&
11935 priv->vexpand == expand)
11938 priv->vexpand_set = TRUE;
11939 priv->vexpand = expand;
11941 expand_prop = "vexpand";
11942 expand_set_prop = "vexpand-set";
11945 gtk_widget_queue_compute_expand (widget);
11947 g_object_freeze_notify (G_OBJECT (widget));
11948 g_object_notify (G_OBJECT (widget), expand_prop);
11949 g_object_notify (G_OBJECT (widget), expand_set_prop);
11950 if (was_both != (priv->hexpand && priv->vexpand))
11951 g_object_notify (G_OBJECT (widget), "expand");
11952 g_object_thaw_notify (G_OBJECT (widget));
11956 gtk_widget_set_expand_set (GtkWidget *widget,
11957 GtkOrientation orientation,
11960 GtkWidgetPrivate *priv;
11963 priv = widget->priv;
11965 set = set != FALSE;
11967 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11969 if (set == priv->hexpand_set)
11972 priv->hexpand_set = set;
11973 prop = "hexpand-set";
11977 if (set == priv->vexpand_set)
11980 priv->vexpand_set = set;
11981 prop = "vexpand-set";
11984 gtk_widget_queue_compute_expand (widget);
11986 g_object_notify (G_OBJECT (widget), prop);
11990 * gtk_widget_get_hexpand:
11991 * @widget: the widget
11993 * Gets whether the widget would like any available extra horizontal
11994 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11995 * generally receive the extra space. For example, a list or
11996 * scrollable area or document in your window would often be set to
11999 * Containers should use gtk_widget_compute_expand() rather than
12000 * this function, to see whether a widget, or any of its children,
12001 * has the expand flag set. If any child of a widget wants to
12002 * expand, the parent may ask to expand also.
12004 * This function only looks at the widget's own hexpand flag, rather
12005 * than computing whether the entire widget tree rooted at this widget
12008 * Return value: whether hexpand flag is set
12011 gtk_widget_get_hexpand (GtkWidget *widget)
12013 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12015 return widget->priv->hexpand;
12019 * gtk_widget_set_hexpand:
12020 * @widget: the widget
12021 * @expand: whether to expand
12023 * Sets whether the widget would like any available extra horizontal
12024 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12025 * generally receive the extra space. For example, a list or
12026 * scrollable area or document in your window would often be set to
12029 * Call this function to set the expand flag if you would like your
12030 * widget to become larger horizontally when the window has extra
12033 * By default, widgets automatically expand if any of their children
12034 * want to expand. (To see if a widget will automatically expand given
12035 * its current children and state, call gtk_widget_compute_expand(). A
12036 * container can decide how the expandability of children affects the
12037 * expansion of the container by overriding the compute_expand virtual
12038 * method on #GtkWidget.).
12040 * Setting hexpand explicitly with this function will override the
12041 * automatic expand behavior.
12043 * This function forces the widget to expand or not to expand,
12044 * regardless of children. The override occurs because
12045 * gtk_widget_set_hexpand() sets the hexpand-set property (see
12046 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
12047 * value to be used, rather than looking at children and widget state.
12050 gtk_widget_set_hexpand (GtkWidget *widget,
12053 g_return_if_fail (GTK_IS_WIDGET (widget));
12055 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
12059 * gtk_widget_get_hexpand_set:
12060 * @widget: the widget
12062 * Gets whether gtk_widget_set_hexpand() has been used to
12063 * explicitly set the expand flag on this widget.
12065 * If hexpand is set, then it overrides any computed
12066 * expand value based on child widgets. If hexpand is not
12067 * set, then the expand value depends on whether any
12068 * children of the widget would like to expand.
12070 * There are few reasons to use this function, but it's here
12071 * for completeness and consistency.
12073 * Return value: whether hexpand has been explicitly set
12076 gtk_widget_get_hexpand_set (GtkWidget *widget)
12078 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12080 return widget->priv->hexpand_set;
12084 * gtk_widget_set_hexpand_set:
12085 * @widget: the widget
12086 * @set: value for hexpand-set property
12088 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
12091 * The hexpand-set property will be set automatically when you call
12092 * gtk_widget_set_hexpand() to set hexpand, so the most likely
12093 * reason to use this function would be to unset an explicit expand
12096 * If hexpand is set, then it overrides any computed
12097 * expand value based on child widgets. If hexpand is not
12098 * set, then the expand value depends on whether any
12099 * children of the widget would like to expand.
12101 * There are few reasons to use this function, but it's here
12102 * for completeness and consistency.
12104 * Return value: whether hexpand has been explicitly set
12107 gtk_widget_set_hexpand_set (GtkWidget *widget,
12110 g_return_if_fail (GTK_IS_WIDGET (widget));
12112 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
12117 * gtk_widget_get_vexpand:
12118 * @widget: the widget
12120 * Gets whether the widget would like any available extra vertical
12123 * See gtk_widget_get_hexpand() for more detail.
12125 * Return value: whether vexpand flag is set
12128 gtk_widget_get_vexpand (GtkWidget *widget)
12130 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12132 return widget->priv->vexpand;
12136 * gtk_widget_set_vexpand:
12137 * @widget: the widget
12138 * @expand: whether to expand
12140 * Sets whether the widget would like any available extra vertical
12143 * See gtk_widget_set_hexpand() for more detail.
12146 gtk_widget_set_vexpand (GtkWidget *widget,
12149 g_return_if_fail (GTK_IS_WIDGET (widget));
12151 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12155 * gtk_widget_get_vexpand_set:
12156 * @widget: the widget
12158 * Gets whether gtk_widget_set_vexpand() has been used to
12159 * explicitly set the expand flag on this widget.
12161 * See gtk_widget_get_hexpand_set() for more detail.
12163 * Return value: whether vexpand has been explicitly set
12166 gtk_widget_get_vexpand_set (GtkWidget *widget)
12168 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12170 return widget->priv->vexpand_set;
12174 * gtk_widget_set_vexpand_set:
12175 * @widget: the widget
12176 * @set: value for vexpand-set property
12178 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12181 * See gtk_widget_set_hexpand_set() for more detail.
12183 * Return value: whether vexpand has been explicitly set
12186 gtk_widget_set_vexpand_set (GtkWidget *widget,
12189 g_return_if_fail (GTK_IS_WIDGET (widget));
12191 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12195 * GtkBuildable implementation
12197 static GQuark quark_builder_has_default = 0;
12198 static GQuark quark_builder_has_focus = 0;
12199 static GQuark quark_builder_atk_relations = 0;
12200 static GQuark quark_builder_set_name = 0;
12203 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12205 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12206 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12207 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12208 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12210 iface->set_name = gtk_widget_buildable_set_name;
12211 iface->get_name = gtk_widget_buildable_get_name;
12212 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12213 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12214 iface->parser_finished = gtk_widget_buildable_parser_finished;
12215 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12216 iface->custom_finished = gtk_widget_buildable_custom_finished;
12220 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12223 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12224 g_strdup (name), g_free);
12227 static const gchar *
12228 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12230 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12234 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12235 GtkBuilder *builder,
12236 const gchar *childname)
12238 if (strcmp (childname, "accessible") == 0)
12239 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12245 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12246 GtkBuilder *builder,
12248 const GValue *value)
12250 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12251 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12252 GINT_TO_POINTER (TRUE));
12253 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12254 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12255 GINT_TO_POINTER (TRUE));
12257 g_object_set_property (G_OBJECT (buildable), name, value);
12262 gchar *action_name;
12263 GString *description;
12265 gboolean translatable;
12275 free_action (AtkActionData *data, gpointer user_data)
12277 g_free (data->action_name);
12278 g_string_free (data->description, TRUE);
12279 g_free (data->context);
12280 g_slice_free (AtkActionData, data);
12284 free_relation (AtkRelationData *data, gpointer user_data)
12286 g_free (data->target);
12287 g_free (data->type);
12288 g_slice_free (AtkRelationData, data);
12292 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12293 GtkBuilder *builder)
12295 GSList *atk_relations;
12297 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12298 gtk_widget_grab_default (GTK_WIDGET (buildable));
12299 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12300 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12302 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12303 quark_builder_atk_relations);
12306 AtkObject *accessible;
12307 AtkRelationSet *relation_set;
12310 AtkRelationType relation_type;
12311 AtkObject *target_accessible;
12313 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12314 relation_set = atk_object_ref_relation_set (accessible);
12316 for (l = atk_relations; l; l = l->next)
12318 AtkRelationData *relation = (AtkRelationData*)l->data;
12320 target = gtk_builder_get_object (builder, relation->target);
12323 g_warning ("Target object %s in <relation> does not exist",
12327 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12328 g_assert (target_accessible != NULL);
12330 relation_type = atk_relation_type_for_name (relation->type);
12331 if (relation_type == ATK_RELATION_NULL)
12333 g_warning ("<relation> type %s not found",
12337 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12338 target_accessible);
12340 g_object_unref (relation_set);
12342 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
12343 g_slist_free (atk_relations);
12344 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12353 } AccessibilitySubParserData;
12356 accessibility_start_element (GMarkupParseContext *context,
12357 const gchar *element_name,
12358 const gchar **names,
12359 const gchar **values,
12360 gpointer user_data,
12363 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12365 gint line_number, char_number;
12367 if (strcmp (element_name, "relation") == 0)
12369 gchar *target = NULL;
12370 gchar *type = NULL;
12371 AtkRelationData *relation;
12373 for (i = 0; names[i]; i++)
12375 if (strcmp (names[i], "target") == 0)
12376 target = g_strdup (values[i]);
12377 else if (strcmp (names[i], "type") == 0)
12378 type = g_strdup (values[i]);
12381 g_markup_parse_context_get_position (context,
12384 g_set_error (error,
12386 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12387 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12389 line_number, char_number, names[i], "relation");
12396 if (!target || !type)
12398 g_markup_parse_context_get_position (context,
12401 g_set_error (error,
12403 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12404 "%s:%d:%d <%s> requires attribute \"%s\"",
12406 line_number, char_number, "relation",
12407 type ? "target" : "type");
12413 relation = g_slice_new (AtkRelationData);
12414 relation->target = target;
12415 relation->type = type;
12417 data->relations = g_slist_prepend (data->relations, relation);
12419 else if (strcmp (element_name, "action") == 0)
12421 const gchar *action_name = NULL;
12422 const gchar *description = NULL;
12423 const gchar *msg_context = NULL;
12424 gboolean translatable = FALSE;
12425 AtkActionData *action;
12427 for (i = 0; names[i]; i++)
12429 if (strcmp (names[i], "action_name") == 0)
12430 action_name = values[i];
12431 else if (strcmp (names[i], "description") == 0)
12432 description = values[i];
12433 else if (strcmp (names[i], "translatable") == 0)
12435 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12438 else if (strcmp (names[i], "comments") == 0)
12440 /* do nothing, comments are for translators */
12442 else if (strcmp (names[i], "context") == 0)
12443 msg_context = values[i];
12446 g_markup_parse_context_get_position (context,
12449 g_set_error (error,
12451 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12452 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12454 line_number, char_number, names[i], "action");
12461 g_markup_parse_context_get_position (context,
12464 g_set_error (error,
12466 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12467 "%s:%d:%d <%s> requires attribute \"%s\"",
12469 line_number, char_number, "action",
12474 action = g_slice_new (AtkActionData);
12475 action->action_name = g_strdup (action_name);
12476 action->description = g_string_new (description);
12477 action->context = g_strdup (msg_context);
12478 action->translatable = translatable;
12480 data->actions = g_slist_prepend (data->actions, action);
12482 else if (strcmp (element_name, "accessibility") == 0)
12485 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12489 accessibility_text (GMarkupParseContext *context,
12492 gpointer user_data,
12495 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12497 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12499 AtkActionData *action = data->actions->data;
12501 g_string_append_len (action->description, text, text_len);
12505 static const GMarkupParser accessibility_parser =
12507 accessibility_start_element,
12509 accessibility_text,
12518 } AccelGroupParserData;
12521 accel_group_start_element (GMarkupParseContext *context,
12522 const gchar *element_name,
12523 const gchar **names,
12524 const gchar **values,
12525 gpointer user_data,
12530 guint modifiers = 0;
12531 gchar *signal = NULL;
12532 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12534 for (i = 0; names[i]; i++)
12536 if (strcmp (names[i], "key") == 0)
12537 key = gdk_keyval_from_name (values[i]);
12538 else if (strcmp (names[i], "modifiers") == 0)
12540 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12546 else if (strcmp (names[i], "signal") == 0)
12547 signal = g_strdup (values[i]);
12550 if (key == 0 || signal == NULL)
12552 g_warning ("<accelerator> requires key and signal attributes");
12555 parser_data->key = key;
12556 parser_data->modifiers = modifiers;
12557 parser_data->signal = signal;
12560 static const GMarkupParser accel_group_parser =
12562 accel_group_start_element,
12566 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12567 GtkBuilder *builder,
12569 const gchar *tagname,
12570 GMarkupParser *parser,
12573 g_assert (buildable);
12575 if (strcmp (tagname, "accelerator") == 0)
12577 AccelGroupParserData *parser_data;
12579 parser_data = g_slice_new0 (AccelGroupParserData);
12580 parser_data->object = g_object_ref (buildable);
12581 *parser = accel_group_parser;
12582 *data = parser_data;
12585 if (strcmp (tagname, "accessibility") == 0)
12587 AccessibilitySubParserData *parser_data;
12589 parser_data = g_slice_new0 (AccessibilitySubParserData);
12590 *parser = accessibility_parser;
12591 *data = parser_data;
12598 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12599 GtkWidget *toplevel,
12600 gpointer user_data)
12602 AccelGroupParserData *accel_data;
12603 GSList *accel_groups;
12604 GtkAccelGroup *accel_group;
12606 g_return_if_fail (GTK_IS_WIDGET (widget));
12607 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12608 g_return_if_fail (user_data != NULL);
12610 accel_data = (AccelGroupParserData*)user_data;
12611 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12612 if (g_slist_length (accel_groups) == 0)
12614 accel_group = gtk_accel_group_new ();
12615 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12619 g_assert (g_slist_length (accel_groups) == 1);
12620 accel_group = g_slist_nth_data (accel_groups, 0);
12623 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12624 accel_data->signal,
12627 accel_data->modifiers,
12628 GTK_ACCEL_VISIBLE);
12630 g_object_unref (accel_data->object);
12631 g_free (accel_data->signal);
12632 g_slice_free (AccelGroupParserData, accel_data);
12636 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12637 GtkBuilder *builder,
12639 const gchar *tagname,
12640 gpointer user_data)
12642 AccelGroupParserData *accel_data;
12643 AccessibilitySubParserData *a11y_data;
12644 GtkWidget *toplevel;
12646 if (strcmp (tagname, "accelerator") == 0)
12648 accel_data = (AccelGroupParserData*)user_data;
12649 g_assert (accel_data->object);
12651 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12653 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12655 else if (strcmp (tagname, "accessibility") == 0)
12657 a11y_data = (AccessibilitySubParserData*)user_data;
12659 if (a11y_data->actions)
12661 AtkObject *accessible;
12666 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12668 action = ATK_ACTION (accessible);
12669 n_actions = atk_action_get_n_actions (action);
12671 for (l = a11y_data->actions; l; l = l->next)
12673 AtkActionData *action_data = (AtkActionData*)l->data;
12675 for (i = 0; i < n_actions; i++)
12676 if (strcmp (atk_action_get_name (action, i),
12677 action_data->action_name) == 0)
12682 gchar *description;
12684 if (action_data->translatable && action_data->description->len)
12685 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12686 action_data->context,
12687 action_data->description->str);
12689 description = action_data->description->str;
12691 atk_action_set_description (action, i, description);
12695 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
12696 g_slist_free (a11y_data->actions);
12699 if (a11y_data->relations)
12700 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12701 a11y_data->relations);
12703 g_slice_free (AccessibilitySubParserData, a11y_data);
12708 gtk_widget_real_get_width (GtkWidget *widget,
12709 gint *minimum_size,
12710 gint *natural_size)
12720 gtk_widget_real_get_height (GtkWidget *widget,
12721 gint *minimum_size,
12722 gint *natural_size)
12732 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12734 gint *minimum_height,
12735 gint *natural_height)
12737 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12741 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12743 gint *minimum_width,
12744 gint *natural_width)
12746 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12750 * gtk_widget_get_halign:
12751 * @widget: a #GtkWidget
12753 * Gets the value of the #GtkWidget:halign property.
12755 * Returns: the horizontal alignment of @widget
12758 gtk_widget_get_halign (GtkWidget *widget)
12760 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12761 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12765 * gtk_widget_set_halign:
12766 * @widget: a #GtkWidget
12767 * @align: the horizontal alignment
12769 * Sets the horizontal alignment of @widget.
12770 * See the #GtkWidget:halign property.
12773 gtk_widget_set_halign (GtkWidget *widget,
12776 GtkWidgetAuxInfo *aux_info;
12778 g_return_if_fail (GTK_IS_WIDGET (widget));
12780 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12782 if (aux_info->halign == align)
12785 aux_info->halign = align;
12786 gtk_widget_queue_resize (widget);
12787 g_object_notify (G_OBJECT (widget), "halign");
12791 * gtk_widget_get_valign:
12792 * @widget: a #GtkWidget
12794 * Gets the value of the #GtkWidget:valign property.
12796 * Returns: the vertical alignment of @widget
12799 gtk_widget_get_valign (GtkWidget *widget)
12801 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12802 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12806 * gtk_widget_set_valign:
12807 * @widget: a #GtkWidget
12808 * @align: the vertical alignment
12810 * Sets the vertical alignment of @widget.
12811 * See the #GtkWidget:valign property.
12814 gtk_widget_set_valign (GtkWidget *widget,
12817 GtkWidgetAuxInfo *aux_info;
12819 g_return_if_fail (GTK_IS_WIDGET (widget));
12821 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12823 if (aux_info->valign == align)
12826 aux_info->valign = align;
12827 gtk_widget_queue_resize (widget);
12828 g_object_notify (G_OBJECT (widget), "valign");
12832 * gtk_widget_get_margin_left:
12833 * @widget: a #GtkWidget
12835 * Gets the value of the #GtkWidget:margin-left property.
12837 * Returns: The left margin of @widget
12840 gtk_widget_get_margin_left (GtkWidget *widget)
12842 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12844 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12848 * gtk_widget_set_margin_left:
12849 * @widget: a #GtkWidget
12850 * @margin: the left margin
12852 * Sets the left margin of @widget.
12853 * See the #GtkWidget:margin-left property.
12856 gtk_widget_set_margin_left (GtkWidget *widget,
12859 GtkWidgetAuxInfo *aux_info;
12861 g_return_if_fail (GTK_IS_WIDGET (widget));
12862 g_return_if_fail (margin <= G_MAXINT16);
12864 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12866 if (aux_info->margin.left == margin)
12869 aux_info->margin.left = margin;
12870 gtk_widget_queue_resize (widget);
12871 g_object_notify (G_OBJECT (widget), "margin-left");
12875 * gtk_widget_get_margin_right:
12876 * @widget: a #GtkWidget
12878 * Gets the value of the #GtkWidget:margin-right property.
12880 * Returns: The left margin of @widget
12883 gtk_widget_get_margin_right (GtkWidget *widget)
12885 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12887 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12891 * gtk_widget_set_margin_right:
12892 * @widget: a #GtkWidget
12893 * @margin: the right margin
12895 * Sets the right margin of @widget.
12896 * See the #GtkWidget:margin-right property.
12899 gtk_widget_set_margin_right (GtkWidget *widget,
12902 GtkWidgetAuxInfo *aux_info;
12904 g_return_if_fail (GTK_IS_WIDGET (widget));
12905 g_return_if_fail (margin <= G_MAXINT16);
12907 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12909 if (aux_info->margin.right == margin)
12912 aux_info->margin.right = margin;
12913 gtk_widget_queue_resize (widget);
12914 g_object_notify (G_OBJECT (widget), "margin-right");
12918 * gtk_widget_get_margin_top:
12919 * @widget: a #GtkWidget
12921 * Gets the value of the #GtkWidget:margin-top property.
12923 * Returns: The top margin of @widget
12926 gtk_widget_get_margin_top (GtkWidget *widget)
12928 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12930 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12934 * gtk_widget_set_margin_top:
12935 * @widget: a #GtkWidget
12936 * @margin: the top margin
12938 * Sets the top margin of @widget.
12939 * See the #GtkWidget:margin-top property.
12942 gtk_widget_set_margin_top (GtkWidget *widget,
12945 GtkWidgetAuxInfo *aux_info;
12947 g_return_if_fail (GTK_IS_WIDGET (widget));
12948 g_return_if_fail (margin <= G_MAXINT16);
12950 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12952 if (aux_info->margin.top == margin)
12955 aux_info->margin.top = margin;
12956 gtk_widget_queue_resize (widget);
12957 g_object_notify (G_OBJECT (widget), "margin-top");
12961 * gtk_widget_get_margin_bottom:
12962 * @widget: a #GtkWidget
12964 * Gets the value of the #GtkWidget:margin-bottom property.
12966 * Returns: The bottom margin of @widget
12969 gtk_widget_get_margin_bottom (GtkWidget *widget)
12971 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12973 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
12977 * gtk_widget_set_margin_bottom:
12978 * @widget: a #GtkWidget
12979 * @margin: the bottom margin
12981 * Sets the bottom margin of @widget.
12982 * See the #GtkWidget:margin-bottom property.
12985 gtk_widget_set_margin_bottom (GtkWidget *widget,
12988 GtkWidgetAuxInfo *aux_info;
12990 g_return_if_fail (GTK_IS_WIDGET (widget));
12991 g_return_if_fail (margin <= G_MAXINT16);
12993 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12995 if (aux_info->margin.bottom == margin)
12998 aux_info->margin.bottom = margin;
12999 gtk_widget_queue_resize (widget);
13000 g_object_notify (G_OBJECT (widget), "margin-bottom");
13004 * gtk_widget_get_clipboard:
13005 * @widget: a #GtkWidget
13006 * @selection: a #GdkAtom which identifies the clipboard
13007 * to use. %GDK_SELECTION_CLIPBOARD gives the
13008 * default clipboard. Another common value
13009 * is %GDK_SELECTION_PRIMARY, which gives
13010 * the primary X selection.
13012 * Returns the clipboard object for the given selection to
13013 * be used with @widget. @widget must have a #GdkDisplay
13014 * associated with it, so must be attached to a toplevel
13017 * Return value: (transfer none): the appropriate clipboard object. If no
13018 * clipboard already exists, a new one will
13019 * be created. Once a clipboard object has
13020 * been created, it is persistent for all time.
13025 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
13027 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13028 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
13030 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
13035 * gtk_widget_list_mnemonic_labels:
13036 * @widget: a #GtkWidget
13038 * Returns a newly allocated list of the widgets, normally labels, for
13039 * which this widget is the target of a mnemonic (see for example,
13040 * gtk_label_set_mnemonic_widget()).
13042 * The widgets in the list are not individually referenced. If you
13043 * want to iterate through the list and perform actions involving
13044 * callbacks that might destroy the widgets, you
13045 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
13046 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
13047 * widgets afterwards.
13049 * Return value: (element-type GtkWidget) (transfer container): the list of
13050 * mnemonic labels; free this list
13051 * with g_list_free() when you are done with it.
13056 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
13058 GList *list = NULL;
13061 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13063 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13064 list = g_list_prepend (list, l->data);
13070 * gtk_widget_add_mnemonic_label:
13071 * @widget: a #GtkWidget
13072 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13074 * Adds a widget to the list of mnemonic labels for
13075 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13076 * list of mnemonic labels for the widget is cleared when the
13077 * widget is destroyed, so the caller must make sure to update
13078 * its internal state at this point as well, by using a connection
13079 * to the #GtkWidget::destroy signal or a weak notifier.
13084 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13087 GSList *old_list, *new_list;
13089 g_return_if_fail (GTK_IS_WIDGET (widget));
13090 g_return_if_fail (GTK_IS_WIDGET (label));
13092 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13093 new_list = g_slist_prepend (old_list, label);
13095 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13096 new_list, (GDestroyNotify) g_slist_free);
13100 * gtk_widget_remove_mnemonic_label:
13101 * @widget: a #GtkWidget
13102 * @label: a #GtkWidget that was previously set as a mnemnic label for
13103 * @widget with gtk_widget_add_mnemonic_label().
13105 * Removes a widget from the list of mnemonic labels for
13106 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13107 * must have previously been added to the list with
13108 * gtk_widget_add_mnemonic_label().
13113 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13116 GSList *old_list, *new_list;
13118 g_return_if_fail (GTK_IS_WIDGET (widget));
13119 g_return_if_fail (GTK_IS_WIDGET (label));
13121 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13122 new_list = g_slist_remove (old_list, label);
13125 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13126 new_list, (GDestroyNotify) g_slist_free);
13130 * gtk_widget_get_no_show_all:
13131 * @widget: a #GtkWidget
13133 * Returns the current value of the #GtkWidget:no-show-all property,
13134 * which determines whether calls to gtk_widget_show_all()
13135 * will affect this widget.
13137 * Return value: the current value of the "no-show-all" property.
13142 gtk_widget_get_no_show_all (GtkWidget *widget)
13144 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13146 return widget->priv->no_show_all;
13150 * gtk_widget_set_no_show_all:
13151 * @widget: a #GtkWidget
13152 * @no_show_all: the new value for the "no-show-all" property
13154 * Sets the #GtkWidget:no-show-all property, which determines whether
13155 * calls to gtk_widget_show_all() will affect this widget.
13157 * This is mostly for use in constructing widget hierarchies with externally
13158 * controlled visibility, see #GtkUIManager.
13163 gtk_widget_set_no_show_all (GtkWidget *widget,
13164 gboolean no_show_all)
13166 g_return_if_fail (GTK_IS_WIDGET (widget));
13168 no_show_all = (no_show_all != FALSE);
13170 if (widget->priv->no_show_all != no_show_all)
13172 widget->priv->no_show_all = no_show_all;
13174 g_object_notify (G_OBJECT (widget), "no-show-all");
13180 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13181 gboolean has_tooltip,
13184 GtkWidgetPrivate *priv = widget->priv;
13185 gboolean priv_has_tooltip;
13187 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13188 quark_has_tooltip));
13190 if (priv_has_tooltip != has_tooltip || force)
13192 priv_has_tooltip = has_tooltip;
13194 if (priv_has_tooltip)
13196 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13197 gdk_window_set_events (priv->window,
13198 gdk_window_get_events (priv->window) |
13199 GDK_LEAVE_NOTIFY_MASK |
13200 GDK_POINTER_MOTION_MASK |
13201 GDK_POINTER_MOTION_HINT_MASK);
13203 if (gtk_widget_get_has_window (widget))
13204 gtk_widget_add_events (widget,
13205 GDK_LEAVE_NOTIFY_MASK |
13206 GDK_POINTER_MOTION_MASK |
13207 GDK_POINTER_MOTION_HINT_MASK);
13210 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13211 GUINT_TO_POINTER (priv_has_tooltip));
13216 * gtk_widget_set_tooltip_window:
13217 * @widget: a #GtkWidget
13218 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13220 * Replaces the default, usually yellow, window used for displaying
13221 * tooltips with @custom_window. GTK+ will take care of showing and
13222 * hiding @custom_window at the right moment, to behave likewise as
13223 * the default tooltip window. If @custom_window is %NULL, the default
13224 * tooltip window will be used.
13226 * If the custom window should have the default theming it needs to
13227 * have the name "gtk-tooltip", see gtk_widget_set_name().
13232 gtk_widget_set_tooltip_window (GtkWidget *widget,
13233 GtkWindow *custom_window)
13235 gboolean has_tooltip;
13236 gchar *tooltip_markup;
13238 g_return_if_fail (GTK_IS_WIDGET (widget));
13239 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13241 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13244 g_object_ref (custom_window);
13246 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13247 custom_window, g_object_unref);
13249 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13250 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13252 if (has_tooltip && gtk_widget_get_visible (widget))
13253 gtk_widget_queue_tooltip_query (widget);
13257 * gtk_widget_get_tooltip_window:
13258 * @widget: a #GtkWidget
13260 * Returns the #GtkWindow of the current tooltip. This can be the
13261 * GtkWindow created by default, or the custom tooltip window set
13262 * using gtk_widget_set_tooltip_window().
13264 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13269 gtk_widget_get_tooltip_window (GtkWidget *widget)
13271 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13273 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13277 * gtk_widget_trigger_tooltip_query:
13278 * @widget: a #GtkWidget
13280 * Triggers a tooltip query on the display where the toplevel of @widget
13281 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13287 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13289 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13292 static guint tooltip_query_id;
13293 static GSList *tooltip_query_displays;
13296 tooltip_query_idle (gpointer data)
13298 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13299 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13300 g_slist_free (tooltip_query_displays);
13302 tooltip_query_displays = NULL;
13303 tooltip_query_id = 0;
13309 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13311 GdkDisplay *display;
13313 display = gtk_widget_get_display (widget);
13315 if (!g_slist_find (tooltip_query_displays, display))
13316 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13318 if (tooltip_query_id == 0)
13319 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13323 * gtk_widget_set_tooltip_text:
13324 * @widget: a #GtkWidget
13325 * @text: the contents of the tooltip for @widget
13327 * Sets @text as the contents of the tooltip. This function will take
13328 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13329 * handler for the #GtkWidget::query-tooltip signal.
13331 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13336 gtk_widget_set_tooltip_text (GtkWidget *widget,
13339 g_return_if_fail (GTK_IS_WIDGET (widget));
13341 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13345 * gtk_widget_get_tooltip_text:
13346 * @widget: a #GtkWidget
13348 * Gets the contents of the tooltip for @widget.
13350 * Return value: the tooltip text, or %NULL. You should free the
13351 * returned string with g_free() when done.
13356 gtk_widget_get_tooltip_text (GtkWidget *widget)
13358 gchar *text = NULL;
13360 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13362 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13368 * gtk_widget_set_tooltip_markup:
13369 * @widget: a #GtkWidget
13370 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13372 * Sets @markup as the contents of the tooltip, which is marked up with
13373 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13375 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13376 * and of the default handler for the #GtkWidget::query-tooltip signal.
13378 * See also the #GtkWidget:tooltip-markup property and
13379 * gtk_tooltip_set_markup().
13384 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13385 const gchar *markup)
13387 g_return_if_fail (GTK_IS_WIDGET (widget));
13389 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13393 * gtk_widget_get_tooltip_markup:
13394 * @widget: a #GtkWidget
13396 * Gets the contents of the tooltip for @widget.
13398 * Return value: the tooltip text, or %NULL. You should free the
13399 * returned string with g_free() when done.
13404 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13406 gchar *text = NULL;
13408 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13410 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13416 * gtk_widget_set_has_tooltip:
13417 * @widget: a #GtkWidget
13418 * @has_tooltip: whether or not @widget has a tooltip.
13420 * Sets the has-tooltip property on @widget to @has_tooltip. See
13421 * #GtkWidget:has-tooltip for more information.
13426 gtk_widget_set_has_tooltip (GtkWidget *widget,
13427 gboolean has_tooltip)
13429 g_return_if_fail (GTK_IS_WIDGET (widget));
13431 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13435 * gtk_widget_get_has_tooltip:
13436 * @widget: a #GtkWidget
13438 * Returns the current value of the has-tooltip property. See
13439 * #GtkWidget:has-tooltip for more information.
13441 * Return value: current value of has-tooltip on @widget.
13446 gtk_widget_get_has_tooltip (GtkWidget *widget)
13448 gboolean has_tooltip = FALSE;
13450 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13452 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13454 return has_tooltip;
13458 * gtk_widget_get_allocation:
13459 * @widget: a #GtkWidget
13460 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13462 * Retrieves the widget's allocation.
13464 * Note, when implementing a #GtkContainer: a widget's allocation will
13465 * be its "adjusted" allocation, that is, the widget's parent
13466 * container typically calls gtk_widget_size_allocate() with an
13467 * allocation, and that allocation is then adjusted (to handle margin
13468 * and alignment for example) before assignment to the widget.
13469 * gtk_widget_get_allocation() returns the adjusted allocation that
13470 * was actually assigned to the widget. The adjusted allocation is
13471 * guaranteed to be completely contained within the
13472 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13473 * is guaranteed that its children stay inside the assigned bounds,
13474 * but not that they have exactly the bounds the container assigned.
13475 * There is no way to get the original allocation assigned by
13476 * gtk_widget_size_allocate(), since it isn't stored; if a container
13477 * implementation needs that information it will have to track it itself.
13482 gtk_widget_get_allocation (GtkWidget *widget,
13483 GtkAllocation *allocation)
13485 GtkWidgetPrivate *priv;
13487 g_return_if_fail (GTK_IS_WIDGET (widget));
13488 g_return_if_fail (allocation != NULL);
13490 priv = widget->priv;
13492 *allocation = priv->allocation;
13496 * gtk_widget_set_allocation:
13497 * @widget: a #GtkWidget
13498 * @allocation: a pointer to a #GtkAllocation to copy from
13500 * Sets the widget's allocation. This should not be used
13501 * directly, but from within a widget's size_allocate method.
13503 * The allocation set should be the "adjusted" or actual
13504 * allocation. If you're implementing a #GtkContainer, you want to use
13505 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13506 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13507 * allocation inside gtk_widget_size_allocate() to create an adjusted
13513 gtk_widget_set_allocation (GtkWidget *widget,
13514 const GtkAllocation *allocation)
13516 GtkWidgetPrivate *priv;
13518 g_return_if_fail (GTK_IS_WIDGET (widget));
13519 g_return_if_fail (allocation != NULL);
13521 priv = widget->priv;
13523 priv->allocation = *allocation;
13527 * gtk_widget_get_allocated_width:
13528 * @widget: the widget to query
13530 * Returns the width that has currently been allocated to @widget.
13531 * This function is intended to be used when implementing handlers
13532 * for the #GtkWidget::draw function.
13534 * Returns: the width of the @widget
13537 gtk_widget_get_allocated_width (GtkWidget *widget)
13539 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13541 return widget->priv->allocation.width;
13545 * gtk_widget_get_allocated_height:
13546 * @widget: the widget to query
13548 * Returns the height that has currently been allocated to @widget.
13549 * This function is intended to be used when implementing handlers
13550 * for the #GtkWidget::draw function.
13552 * Returns: the height of the @widget
13555 gtk_widget_get_allocated_height (GtkWidget *widget)
13557 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13559 return widget->priv->allocation.height;
13563 * gtk_widget_get_requisition:
13564 * @widget: a #GtkWidget
13565 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13567 * Retrieves the widget's requisition.
13569 * This function should only be used by widget implementations in
13570 * order to figure whether the widget's requisition has actually
13571 * changed after some internal state change (so that they can call
13572 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13574 * Normally, gtk_widget_size_request() should be used.
13578 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13579 * removed, If you need to cache sizes across requests and allocations,
13580 * add an explicit cache to the widget in question instead.
13583 gtk_widget_get_requisition (GtkWidget *widget,
13584 GtkRequisition *requisition)
13586 g_return_if_fail (GTK_IS_WIDGET (widget));
13587 g_return_if_fail (requisition != NULL);
13589 gtk_widget_get_preferred_size (widget, requisition, NULL);
13593 * gtk_widget_set_window:
13594 * @widget: a #GtkWidget
13595 * @window: a #GdkWindow
13597 * Sets a widget's window. This function should only be used in a
13598 * widget's #GtkWidget::realize implementation. The %window passed is
13599 * usually either new window created with gdk_window_new(), or the
13600 * window of its parent widget as returned by
13601 * gtk_widget_get_parent_window().
13603 * Widgets must indicate whether they will create their own #GdkWindow
13604 * by calling gtk_widget_set_has_window(). This is usually done in the
13605 * widget's init() function.
13607 * <note><para>This function does not add any reference to @window.</para></note>
13612 gtk_widget_set_window (GtkWidget *widget,
13615 GtkWidgetPrivate *priv;
13617 g_return_if_fail (GTK_IS_WIDGET (widget));
13618 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13620 priv = widget->priv;
13622 if (priv->window != window)
13624 priv->window = window;
13625 g_object_notify (G_OBJECT (widget), "window");
13630 * gtk_widget_get_window:
13631 * @widget: a #GtkWidget
13633 * Returns the widget's window if it is realized, %NULL otherwise
13635 * Return value: (transfer none): @widget's window.
13640 gtk_widget_get_window (GtkWidget *widget)
13642 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13644 return widget->priv->window;
13648 * gtk_widget_get_support_multidevice:
13649 * @widget: a #GtkWidget
13651 * Returns %TRUE if @widget is multiple pointer aware. See
13652 * gtk_widget_set_support_multidevice() for more information.
13654 * Returns: %TRUE is @widget is multidevice aware.
13657 gtk_widget_get_support_multidevice (GtkWidget *widget)
13659 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13661 return widget->priv->multidevice;
13665 * gtk_widget_set_support_multidevice:
13666 * @widget: a #GtkWidget
13667 * @support_multidevice: %TRUE to support input from multiple devices.
13669 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13670 * @widget will start receiving multiple, per device enter/leave events. Note
13671 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13672 * gdk_window_set_support_multidevice() will have to be called manually on them.
13677 gtk_widget_set_support_multidevice (GtkWidget *widget,
13678 gboolean support_multidevice)
13680 GtkWidgetPrivate *priv;
13682 g_return_if_fail (GTK_IS_WIDGET (widget));
13684 priv = widget->priv;
13686 if (support_multidevice)
13688 priv->multidevice = TRUE;
13689 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
13693 priv->multidevice = FALSE;
13694 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
13697 if (gtk_widget_get_realized (widget))
13698 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13702 _gtk_widget_set_has_focus (GtkWidget *widget,
13703 gboolean has_focus)
13705 widget->priv->has_focus = has_focus;
13709 * gtk_widget_send_focus_change:
13710 * @widget: a #GtkWidget
13711 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13713 * Sends the focus change @event to @widget
13715 * This function is not meant to be used by applications. The only time it
13716 * should be used is when it is necessary for a #GtkWidget to assign focus
13717 * to a widget that is semantically owned by the first widget even though
13718 * it's not a direct child - for instance, a search entry in a floating
13719 * window similar to the quick search in #GtkTreeView.
13721 * An example of its usage is:
13724 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13726 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13727 * fevent->focus_change.in = TRUE;
13728 * fevent->focus_change.window = gtk_widget_get_window (widget);
13729 * if (fevent->focus_change.window != NULL)
13730 * g_object_ref (fevent->focus_change.window);
13732 * gtk_widget_send_focus_change (widget, fevent);
13734 * gdk_event_free (event);
13737 * Return value: the return value from the event signal emission: %TRUE
13738 * if the event was handled, and %FALSE otherwise
13743 gtk_widget_send_focus_change (GtkWidget *widget,
13748 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13749 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13751 g_object_ref (widget);
13753 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13755 res = gtk_widget_event (widget, event);
13757 g_object_notify (G_OBJECT (widget), "has-focus");
13759 g_object_unref (widget);
13765 * gtk_widget_in_destruction:
13766 * @widget: a #GtkWidget
13768 * Returns whether the widget is currently being destroyed.
13769 * This information can sometimes be used to avoid doing
13770 * unnecessary work.
13772 * Returns: %TRUE if @widget is being destroyed
13775 gtk_widget_in_destruction (GtkWidget *widget)
13777 return widget->priv->in_destruction;
13781 _gtk_widget_get_resize_pending (GtkWidget *widget)
13783 return widget->priv->resize_pending;
13787 _gtk_widget_set_resize_pending (GtkWidget *widget,
13788 gboolean resize_pending)
13790 widget->priv->resize_pending = resize_pending;
13794 _gtk_widget_get_in_reparent (GtkWidget *widget)
13796 return widget->priv->in_reparent;
13800 _gtk_widget_set_in_reparent (GtkWidget *widget,
13801 gboolean in_reparent)
13803 widget->priv->in_reparent = in_reparent;
13807 _gtk_widget_get_anchored (GtkWidget *widget)
13809 return widget->priv->anchored;
13813 _gtk_widget_set_anchored (GtkWidget *widget,
13816 widget->priv->anchored = anchored;
13820 _gtk_widget_get_shadowed (GtkWidget *widget)
13822 return widget->priv->shadowed;
13826 _gtk_widget_set_shadowed (GtkWidget *widget,
13829 widget->priv->shadowed = shadowed;
13833 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13835 return widget->priv->alloc_needed;
13839 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13840 gboolean alloc_needed)
13842 widget->priv->alloc_needed = alloc_needed;
13846 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13848 return widget->priv->width_request_needed;
13852 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13853 gboolean width_request_needed)
13855 widget->priv->width_request_needed = width_request_needed;
13859 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13861 return widget->priv->height_request_needed;
13865 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13866 gboolean height_request_needed)
13868 widget->priv->height_request_needed = height_request_needed;
13872 * gtk_widget_get_path:
13873 * @widget: a #GtkWidget
13875 * Returns the #GtkWidgetPath representing @widget, if the widget
13876 * is not connected to a toplevel widget, a partial path will be
13879 * Returns: (transfer none): The #GtkWidgetPath representing @widget
13882 gtk_widget_get_path (GtkWidget *widget)
13884 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13886 /* As strange as it may seem, this may happen on object construction.
13887 * init() implementations of parent types may eventually call this function,
13888 * each with its corresponding GType, which could leave a child
13889 * implementation with a wrong widget type in the widget path
13891 if (widget->priv->path &&
13892 G_OBJECT_TYPE (widget) != gtk_widget_path_get_widget_type (widget->priv->path))
13894 gtk_widget_path_free (widget->priv->path);
13895 widget->priv->path = NULL;
13898 if (!widget->priv->path)
13903 parent = widget->priv->parent;
13906 widget->priv->path = gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
13909 /* Widget is either toplevel or unparented, treat both
13910 * as toplevels style wise, since there are situations
13911 * where style properties might be retrieved on that
13914 widget->priv->path = gtk_widget_path_new ();
13917 pos = gtk_widget_path_append_type (widget->priv->path, G_OBJECT_TYPE (widget));
13919 if (widget->priv->name)
13920 gtk_widget_path_iter_set_name (widget->priv->path, pos, widget->priv->name);
13922 if (widget->priv->context)
13923 gtk_style_context_set_path (widget->priv->context,
13924 widget->priv->path);
13927 return widget->priv->path;
13931 style_context_changed (GtkStyleContext *context,
13932 gpointer user_data)
13934 GtkWidget *widget = user_data;
13936 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
13940 * gtk_widget_get_style_context:
13941 * @widget: a #GtkWidget
13943 * Returns the style context associated to @widget.
13945 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
13946 * must not be freed.
13949 gtk_widget_get_style_context (GtkWidget *widget)
13951 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13953 if (G_UNLIKELY (!widget->priv->context))
13955 widget->priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
13956 "direction", gtk_widget_get_direction (widget),
13959 g_signal_connect (widget->priv->context, "changed",
13960 G_CALLBACK (style_context_changed), widget);
13962 gtk_style_context_set_screen (widget->priv->context,
13963 gtk_widget_get_screen (widget));
13965 _gtk_widget_update_path (widget);
13966 gtk_style_context_set_path (widget->priv->context,
13967 widget->priv->path);
13971 /* Force widget path regeneration if needed, the
13972 * context will be updated within this function.
13974 gtk_widget_get_path (widget);
13977 return widget->priv->context;